1zmk.Program(5)                Programmer's Manual               zmk.Program(5)
2

NAME

4     Program — template for compiling C/C++/ObjC programs
5

SYNOPSIS

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

DESCRIPTION

13     The template Program once expanded with a program name to creates rules
14     for compiling, cleaning, installing and removing a single program written
15     in C, C++ or Objective C.
16
17     Source files are compiled to object files prefixed with $(programName)-,
18     so that a single source file can be compiled separately with distinct
19     preprocessor, compiler and linker options.
20
21     When cross-compiling for Windows or DOS, the $(exe) variable expands to
22     .exe
23

TARGETS

25     This module provides the following targets.
26
27   $(programName)$(exe)
28     This target represents the program executable.
29
30   all
31     This phony target depends on $(programName)$(exe)
32
33   clean
34     This phony target removes $(programName)$(exe) as well as constituent
35     object files and dependency files.
36
37   install
38     This phony target copies $(programName) to $(programName.InstallDir),
39     with the name $(programName.InstallName) and mode
40     $(programName.InstallMode).  The target directory is automatically cre‐
41     ated if required.
42
43     The variables Configure.ProgramPrefix, Configure.ProgramSuffix and
44     Configure.ProgramTransformName automatically impact the installed names
45     of all the programs.
46
47   uninstall
48     This phony target removes $(programName)$(exe) as installed by the
49     install target.
50

VARIABLES

52     This module provides the following variables.
53
54   $(programName).Sources
55     List of source files to compile.
56
57     There is no default value. This variable must be set before expanding the
58     template.
59
60   $(programName).Objects
61     List of object files to link.
62
63     The default value is all the elements of $(programName).Sources with the
64     added prefix $(programName)- and with the extension replaced by .o.
65
66   $(programName).Linker
67     Linker required to link object files together.
68
69     The default value depends on the type of source files used, ensuring that
70     C++ sources are linked with the C++ linker.
71
72   $(programName).InstallDir
73     The directory $(programName)$(exe) is installed to.
74
75     The default value is $(bindir) but $(sbindir) or $(libexecdir) are com‐
76     monly used as well. The special value noinst disables the rules related
77     to installation and uninstallation.
78
79   $(programName).InstallName
80     The name of the program after installation.
81
82     The default value is $(programName)
83
84   $(programName).InstallMode
85     The UNIX mode $(programName)$(exe) is installed with.
86
87     The default value is 0755.
88
89   DESTDIR
90     Path added to all installation targets.
91
92     This variable is normally set externally, to install a compiled program
93     into a staging area during construction of a compiled binary package.
94
95   CFLAGS, CXXFLAGS, OBJCFLAGS
96     Options for the C, C++ and the Objective C compiler, respectively.
97
98   CPPFLAGS
99     Options for the preprocessor.
100

IMPLEMENTATION NOTES

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

EXAMPLES

106     With the following true_false.c file:
107
108                 #include <stdlib.h>
109
110                 int main(void) {
111                         return EXIT_CODE;
112                 }
113
114     The following Makefile builds the classic programs true and false.
115
116                 include z.mk
117
118                 true.Sources = true_false.c
119                 $(eval $(call ZMK.Expand,Program,true))
120                 true$(exe): CPPFLAGS += -DEXIT_CODE=EXIT_SUCCESS
121
122                 false.Sources = true_false.c
123                 $(eval $(call ZMK.Expand,Program,false))
124                 false$(exe): CPPFLAGS += -DEXIT_CODE=EXIT_FAILURE
125

HISTORY

127     The Program template first appeared in zmk 0.1
128

AUTHORS

130     Zygmunt Krynicki <me@zygoon.pl>
131
132zmk 0.5.1                         May 3, 2020                        zmk 0.5.1
Impressum