DOKK / manpages / debian 12 / zmk-doc / zmk.Program.5.en
zmk.Program(5) File Formats Manual (prm) zmk.Program(5)

Programtemplate for compiling C/C++/ObjC programs

include z.mk
# programName is any valid identifier.
programName.Sources = hello.c
$(eval $(call ZMK.Expand,Program,programName))

The template Program once with a to creates rules for compiling, cleaning, installing and removing a single program written in C, C++ or Objective C.

Source files are compiled to object files prefixed with $(programName)-, so that a single source file can be compiled separately with distinct preprocessor, compiler and linker options.

When cross-compiling for or , the variable expands to .exe

This module provides the following targets.

This target represents the program executable.

This phony target depends on $(programName)$(exe)

This phony target removes $(programName)$(exe) as well as constituent and .

This phony target copies $(programName) to , with the name and mode . The target directory is automatically created if required.

The variables Configure.ProgramPrefix, Configure.ProgramSuffix and Configure.ProgramTransformName automatically impact the installed names of all the programs.

This phony target removes $(programName)$(exe) as installed by the install target.

This module provides the following variables.

List of source files to compile.

There is no default value. This variable must be set before the template.

List of object files to link.

The default value is all the elements of $(programName).Sources with the added prefix $(programName)- and with the extension replaced by .

Linker required to link object files together.

The default value depends on the type of source files used, ensuring that C++ sources are linked with the C++ linker.

The directory $(programName)$(exe) is installed to.

The default value is but or are commonly used as well. The special value disables the rules related to installation and uninstallation.

The name of the program after installation.

The default value is $(programName)

The UNIX mode $(programName)$(exe) is installed with.

The default value is .

Path added to all installation targets.

This variable is normally set externally, to install a compiled program into a staging area during construction of a compiled binary package.

Options for the C, C++ and the Objective C compiler, respectively.

Options for the preprocessor.

Program uses InstallUninstall to handle installation and removal. The exe variable is automatically set to .exe where appropriate.

With the following file:

#include <stdlib.h>

int main(void) {
	return EXIT_CODE;
}

The following builds the classic programs and .

include z.mk

true.Sources = true_false.c
$(eval $(call ZMK.Expand,Program,true))
true$(exe): CPPFLAGS += -DEXIT_CODE=EXIT_SUCCESS

false.Sources = true_false.c
$(eval $(call ZMK.Expand,Program,false))
false$(exe): CPPFLAGS += -DEXIT_CODE=EXIT_FAILURE

The Program template first appeared in zmk 0.1

Zygmunt Krynicki <me@zygoon.pl>

May 3, 2020 zmk 0.5.1