Compiler Module


compiler is the standard MakeKit module which provides an interface to the system C compiler. It contains functions to check for available headers, libraries, functions, types, and system and compiler characteristics, and to build programs, libraries, and dynamically-loadable objects from C source code.

Most compiler functions support a set of common parameters which are listed here rather than duplicated in the references for every individual function.

DEPS=targets

Specifies additional arbitrary dependencies in MakeKit target notation. This is useful, for example, if one of your source files depends on a header file which you generate on the fly (e.g. from yacc or lex). Alternatively, you could specify dependencies for individual source files using mk_target with an empty command. Applicable to all functions.

INCLUDEDIRS=paths

A space-separated list of relative paths where the compiler should search for header files. Even if you only use header files in the same directory as MakeKitBuild, you must explicitly specify .. Applicable functions: mk_compile, mk_program, mk_group, mk_library, mk_dlo

HEADERDEPS=headers

A space-separated list of public header files (e.g. in /usr/local/include) that one or more source files depend on. You only need to specify header files installed by other MakeKit projects. If you are careful about specifying dependencies in this way, it allows you to structure your larger project as multiple subprojects which can be configured and built either individually or together. When building individually, HEADERDEPS ensures sure you are performing configure checks for the headers. When building together, HEADERDEPS ensures source files are compiled only once the header files they need have been installed. Applicable functions: mk_compile, mk_program, mk_group, mk_library, mk_dlo

LIBDEPS=libs

A space-separated list of library names to link into the resulting binary, without filename extensions or lib prefixed to the name. Applicable functions: mk_program, mk_group, mk_library, mk_prebuilt_library, mk_dlo

LIBDIRS=paths

A space-separated list of additional directories to look for libraries when linking. The paths should be absolute (e.g. /usr/foobar/lib), but they are taken to reference the staging directory. This is only useful if you need to install and link against a library in a location other than $MK_LIBDIR. To look for system libaries in non-standard locations, use LDFLAGS or MK_LDFLAGS, or a helper module like pkg-config when possible. Applicable functions: mk_program, mk_group, mk_library, mk_dlo

GROUPS=groups

A space-separated list of object file groups which should be merged into the resulting binary.

Applicable functions: mk_program, mk_library, mk_dlo

OBJECTS=objects

A space-separated list of additional object files to link into the resulting binary. This is useful if you use mk_compile to control compiler flags on a per-source-file basis and need to combine the resulting objects into a binary, or if you have object files without source code that you need to link. If this parameter is specified, you do not need to specify SOURCES, but you may.

Applicable functions: mk_program, mk_group, mk_library, mk_dlo

INSTALLDIR=path

If specified, changes the location where the resulting binary will be installed in the filesystem. Defaults to what you would expect for the kind of binary being produced, e.g. program executables go in $MK_BINDIR, usually /usr/local/bin.

Applicable functions: mk_program, mk_library, mk_prebuilt_library, mk_dlo

EXT=extension

Overrides the extension of the resulting file.

Applicable functions: mk_library, mk_prebuilt_library, mk_dlo

CPPFLAGS=flags, CFLAGS=flags, LDFLAGS=flags

Specifies additional flags passed to the compiler when preprocessing, compiling, and linking, respectively. These parameters are added to and do not override those in the MK_CPPFLAGS, MK_CFLAGS, and MK_LDFLAGS variables. All default to being empty.

PCH=header

Specifies a header to automatically precompile and include when building source files. Precompiled headers can speed up compilation of some projects. If the header is also included directly by the source code, it should use include guards to avoid being processed twice.

The result of an explict call to mk_pch may be used instead of a plain header. This allows sharing a single precompiled header across multiple build targets, but care must be taken to ensure that compiler flags match or the precompiled header may be rejected.

Applicable functions: mk_compile, mk_group, mk_program, mk_library, mk_dlo

COMPILER=compiler

Explicitly overrides the compiler used to build source files. Must be precisely c or c++.

Applicable functions: mk_compile, mk_pch, mk_group, mk_program, mk_library, mk_dlo