How To Create a Project Using Makefile Engine

Haiku helps developers in build process of their projects by providing so called Makefile engine. It's made of two files, that reside in /boot/develop/etc directory and are named 'makefile' and 'makefile-engine'. Together, these two files provide you with simple ready-to-be used build engine for your projects. This How To describes makefile-engine v2.5.1 and makefile template v2.5. Regardless of mentioning the 'makefiles' in this How To, the same technique can be used for creating Jamfile-driven projects. Corresponding Jamfile and Jamfile-engine template files are provided with Haiku. We made both, the makefile and Jamfile engines completely target-compatible for user's convenience.

Contents

Getting Started

To start a project, just copy makefile from /boot/develop/etc directory, into your project directory. Write few files, you want to add into project. Add either relative or full paths to them, into SRCS variable definition in makefile and run make. Example files for Hello World project:

hello.cpp:

#include <stdio.h>

int main(void)
{
    printf("Hello world!\n");
    return 0;
}

makefile:

NAME = hello
TYPE = APP
SRCS = hello.cpp
include $(BUILDHOME)/etc/makefile-engine

After adding both these files into same directory, just go there in Terminal, using 'cd' command and run 'make'. This will create a new directory, named in similar format: 'objects.x86-gcc2-release' (name depends on current compiler, that may be either "gcc2" or "gcc4", and defining DEBUG will force using "debug" instead of "release"), which will contain .o files (one for each source file), .d files with dependencies, generated automatically by the engine and a binary file, named 'hello' for the example case above.

Configuring a Project

In makefile, there are many variables, to configure builder helpers for your needs. Let's take a look at them:

Please also note, that if you're building your own makefile, that will use this engine, last line must contain:

include $(BUILDHOME)/etc/makefile-engine

Using Localization

Localization in Haiku programs is achieved simply, as following example shows.

localized_hello.cpp:

#include <stdio.h>
#include <Catalog.h>

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "hello"

int main(void)
{
    printf(B_TRANSLATE("Hello, world!\n"));
    return 0;
}

This file uses header file Catalog.h, that belongs to locale library. So to actually be able to use localization in your programs, you have to adjust few settings in your makefile.

  1. Adjust a value to your project's APP_MIME_SIG variable. Application's mime signature should also be set in the following format: x.vnd-<author>-<project_name>
  2. Add following two libraries into your LIBS variable: locale localestub
  3. Add every language, that you want to support, into LOCALES variable, e.g. 'LOCALES = en de fr' for English, German and French locale support.
  4. Add the Resource Definition script (also please specify it in RDEF variable) containing the following entries into project:

    resource app_signature "application/x-vnd.-";

    resource appnamecatalog_entry "-:System name:Terminal";

  5. Run 'make' to build binary file.

  6. Run either: 'make catkeys' to get locales/en.catkeys file.
  7. Copy this file to locales/<language_code>.catkeys and translate it, as needed.
  8. When you prepared all needed .catkeys files, run 'make catalogs' to create catalogs files from them.
  9. Run either 'make catalogsinstall' or 'make bindcatalogs' to make catalogs available for application. For more information about differences between these two commands, please see the next section.

Here is also example makefile for the localized_hello.cpp above:

makefile:

NAME = hello
TYPE = APP
APP_MIME_SIG = x.vnd-example-hello
SRCS = localized_hello.cpp
LIBS = locale localestub
LOCALES = en de fr
include $(BUILDHOME)/etc/makefile-engine

Target Reference

This is supposed to be the list of all non-file related targets.

This How To was created on November 28, 2011 by Peter Poláčik Copyright © 2011 Haiku Inc.