1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
.Dd May 3, 2020
.Os zmk @VERSION@
.Dt zmk.Program 5 PRM
.Sh NAME
.Nm Program
.Nd template for compiling C/C++/ObjC programs
.Sh SYNOPSIS
.Bd -literal
include z.mk
# programName is any valid identifier.
programName.Sources = hello.c
$(eval $(call ZMK.Expand,Program,programName))
.Ed
.Sh DESCRIPTION
The template
.Nm Program
once
.Em expanded
with a
.Em program name
to creates rules for compiling, cleaning, installing and removing a single
program written in C, C++ or Objective C.
.Pp
Source files are compiled to object files prefixed with
.Em $(programName)- ,
so that a single source file can be compiled separately with
distinct preprocessor, compiler and linker options.
.Pp
When cross-compiling for
.Em Windows
or
.Em DOS ,
the
.Em $(exe)
variable expands to
.Em .exe
.Sh TARGETS
This module provides the following targets.
.Ss $(programName)$(exe)
This target represents the program executable.
.Ss all
This
.Em phony
target depends on
.Em $(programName)$(exe)
.Ss clean
This
.Em phony
target removes
.Em $(programName)$(exe)
as well as constituent
.Em object files
and
.Em dependency files .
.Ss install
This
.Em phony
target copies
.Em $(programName)
to
.Em $(programName.InstallDir) ,
with the name
.Em $(programName.InstallName)
and mode
.Em $(programName.InstallMode) .
The target directory is automatically created if required.
.Pp
The variables
.Nm Configure.ProgramPrefix ,
.Nm Configure.ProgramSuffix
and
.Nm Configure.ProgramTransformName
automatically impact the installed names of all the programs.
.Ss uninstall
This
.Em phony
target removes
.Em $(programName)$(exe)
as installed by the
.Em install
target.
.Sh VARIABLES
This module provides the following variables.
.Ss $(programName).Sources
List of source files to compile.
.Pp
There is no default value. This variable must be set before
.Em expanding
the template.
.Ss $(programName).Objects
List of object files to link.
.Pp
The default value is all the elements of
.Em $(programName).Sources
with the added prefix
.Em $(programName)-
and with the extension replaced by
.Em .o .
.Ss $(programName).Linker
Linker required to link object files together.
.Pp
The default value depends on the type of source files used, ensuring that C++
sources are linked with the C++ linker.
.Ss $(programName).InstallDir
The directory
.Em $(programName)$(exe)
is installed to.
.Pp
The default value is
.Em $(bindir)
but
.Em $(sbindir)
or
.Em $(libexecdir)
are commonly used as well. The special value
.Em noinst
disables the rules related to installation and uninstallation.
.Ss $(programName).InstallName
The name of the program after installation.
.Pp
The default value is
.Em $(programName)
.Ss $(programName).InstallMode
The UNIX mode
.Em $(programName)$(exe)
is installed with.
.Pp
The default value is
.Em 0755 .
.Ss DESTDIR
Path added to all installation targets.
.Pp
This variable is normally set externally, to install a compiled program
into a staging area during construction of a compiled binary package.
.Ss CFLAGS, CXXFLAGS, OBJCFLAGS
Options for the C, C++ and the Objective C compiler, respectively.
.Ss CPPFLAGS
Options for the preprocessor.
.Sh IMPLEMENTATION NOTES
.Nm
uses
.Nm InstallUninstall
to handle installation and removal.
The
.Nm exe
variable is automatically set to
.Em .exe
where appropriate.
.Sh EXAMPLES
With the following
.Em true_false.c
file:
.Bd -literal -offset indent-two
#include <stdlib.h>
int main(void) {
return EXIT_CODE;
}
.Ed
.Pp
The following
.Em Makefile
builds the classic programs
.Em true
and
.Em false .
.Bd -literal -offset indent-two
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
.Ed
.Sh HISTORY
The
.Nm
template first appeared in zmk 0.1
.Sh AUTHORS
.An "Zygmunt Krynicki" Aq Mt me@zygoon.pl
|