Scroll to navigation

zmk.Program(5) File Formats Manual (prm) zmk.Program(5)

NAME

Programtemplate for compiling C/C++/ObjC programs

SYNOPSIS

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

DESCRIPTION

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

TARGETS

This module provides the following targets.

$(programName)$(exe)

This target represents the program executable.

all

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

clean

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

install

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.

uninstall

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

VARIABLES

This module provides the following variables.

$(programName).Sources

List of source files to compile.

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

$(programName).Objects

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 .

$(programName).Linker

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.

$(programName).InstallDir

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.

$(programName).InstallName

The name of the program after installation.

The default value is $(programName)

$(programName).InstallMode

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

The default value is .

DESTDIR

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.

CFLAGS, CXXFLAGS, OBJCFLAGS

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

CPPFLAGS

Options for the preprocessor.

IMPLEMENTATION NOTES

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

EXAMPLES

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

HISTORY

The Program template first appeared in zmk 0.1

AUTHORS

Zygmunt Krynicki <me@zygoon.pl>

May 3, 2020 zmk 0.5.1