Subsections


8.3 Role-File lib.mk

8.3.1 Purpose

The purpose of the lib role is to build static and shared libraries for different systems. The libraries are the targets.

To build shared libraries, simply end the TARGET library name on .s.so. The additional ``.s'' later allows to explicitly specify linking against a shared library by specifying the different library base name to the linker. The use of BUILD_SHARED is deprecated.

To build libraries that can be used to build shared libraries later, set the BUILD_PIC option to nonempty. The resulting libraries can be linked into shared libraries then. They end on .p.a.

Both shared and pic-libraries use objects compiled with the PIC-option enabled. The corresponding object-files end on .s.o after compilation.

To build libraries with profiling support, set the BUILD_PROFILE to nonempty. Each generated .o-file will have an accompanying .pr.o-file, which is compiled using the options -pg -DPROFILE. Each target-lib is accompanied by an additional lib with the suffix .pr.a. These additional libs contain the profile code. See Section 8.2 on how to build profile executables.

If all BUILD_SHARED, BUILD_PIC and BUILD_PROFILE options are set, you end with not less than six libraries, and 4 object-files per source-file. Suffixes: .o, .pr.o, .s.o, .pr.s.o, .a, .pr.a, .p.a, .s.so, .pr.p.a, .pr.s.so.

Note, that prior to building libraries, the library files are deleted. This prevents old (obsolete) object-files to be within the libraries.

8.3.2 Make-Targets

all:
Phony target. Build all libraries and install them into the local install-tree then. The local install-tree is $(L4DIR)/lib. To install, ln -s is used.

relink:
Phony target. Relink and reinstall the libraries, in the case your dependencies are somehow wrong.

XXX_p.a:
This target is a library containing position-independent code only. The according object-files end on _p.o and are compiled using appropriate compiler-calls analogously to the other .o-Files.

XXX_s.a:
This target is a shared library. This difference in filenames allows to explicitly distinguish between linking of static versus shared libraries.

8.3.3 Provided Variables

The following variables are provided by the prog.mk role-file:

GCCINCDIR The path where the gcc-specific include-files, such as stdarg.h. Never (really, NEVER) try to include a stdarg.h from a C library!).
GCCLIB The name of the compiler's companion library (libgcc).

8.3.4 Required Parameters

TARGET The list of the target libraries.
Or:
TARGET_<system> The list of the target libraries for special system. Specify the system(s) in SYSTEMS.

8.3.5 Optional Parameters

ASFLAGS++ standard Makefile variable, used additionally for compiling assembler files. Default: empty.
BUILD_PROFILE++ If nonempty, additional profile-versions of the target-libs are built. These libraries end on .pr.a. Default: empty
BUILD_SHARED++ If nonempty, the target-libs are built as shared libraries too. These libs end on .s.so. Default: empty
BUILD_PIC++ If nonempty, target-libs containing position-independent code (PIC) are built too. These libs end on .p.a. Default: empty
CFLAGS++ standard Makefile variable, used additionally for the compiler. Default: adds $(OPTS) $(WARNINGS).
CLIENTIDL++ IDL client source files. The .c and .cc-files compiled from the given IDLs are added to SRC_C++ and SRC_CC++ respectively. Default: unset.
CPPFLAGS++ standard Makefile variables, used additionally for preprocessor. Default: adds $(DEFINES) -I{$(PRIVATE_INCDIR) $(IDL_PATH) $(GCCINCDIR) $(L4INCDIR)} $(LIBCINCDIR). $(IDL_PATH) is added if either $(CLIENTIDL) or $(SERVERIDL) are set. With $(MODE)=host, $(L4INCDIR) is not added.
CXXFLAGS++ standard Makefile variable, used additionally for compiling C++ files. Default: adds $(OPTS) $(WARNINGS).
DEBUG If set, adds -DDEBUG to $(DEFINES). See there for details.
DEFINES++ Container for additional defines for the preprocessor. Default: Adds $(ARCH), $(CPU) and $(L4API) as defines. See Section 6.3 for details.
IDL_PATH++ The path to IDL-files. This path is used to find the client and server idl-files. Default: $(PKG_DIR)/idl/OBJ-$(SYSTEM).
IDL_PKGDIR A list of package directories where IDL files are used from. This will eventually supercede $(IDL_PATH). Default: $(PKGDIR).
IDL_TYPE+ The type of the IDL-files. This type is used to determine the compiler to use. See Section 8.4 for details. Default: dice.

Note: The '+' refers to the different IDL-files, not to the values of $(TARGET).

INSTALL_TARGET+ The list of the targets that will be installed automatically or on make install. Default: The targets and the targets specific to the current system. Also see the NOTARGETSTOINSTALL parameter.
INSTALLFILE_LIB The command to install a library to the global install tree. Default: $(INSTALL) $(1) $(INSTALLDIR_LIB)/
INSTALLFILE_LIB_LOCAL The command to install a library to the local install tree.

Default: $(LN) -sf $(call absfilename, $(1)) $(INSTALLDIR_LIB_LOCAL)/$(1)

INSTALLDIR_LIB The directory in the global install tree to install a library to. Default: $(DROPS_STDDIR)/lib
INSTALLDIR_LIB_LOCAL The directory in the local install tree to install a library to. Default: $(L4DIR)/lib
CFLAGS++, CXXFLAGS++, ASFLAGS++, CPPFLAGS++ standard Makefile variables, used as additional flags for the compiler, c++-compiler, assembler and preprocessor. Default: unset.
KEEP_ON_CLEAN A list of files that should not be removed on a ``make clean''.

Default: empty.

L4INCDIR++ System-dependent list of include directories. Default:

$(L4DIR)/include/$(ARCH)_$(CPU)/$(L4API)

$(DROPS_STDDIR)/include/$(ARCH)_$(CPU)/$(L4API)

$(L4DIR)/include/$(ARCH)_$(CPU)

$(DROPS_STDDIR)/include/$(ARCH)_$(CPU)

$(L4DIR)/include

$(DROPS_STDDIR)/include

L4LIBDIR++ System-dependent list of library directories. Default:

$(L4DIR)/lib/$(ARCH)_$(CPU)/$(L4API)

$(DROPS_STDDIR)/lib/$(ARCH)_$(CPU)/$(L4API)

$(L4DIR)/lib/$(ARCH)_$(CPU)

$(DROPS_STDDIR)/lib/$(ARCH)_$(CPU)

$(L4DIR)/lib

$(DROPS_STDDIR)/lib

LIBS++ objects to be archived to the target libraries. Contains additional PATHS (with -L). Default: unset.
MODE++ specify, which target system a target has to be built for (see Section 6.5). Default: l4env
NOTARGETSTOINSTALL If nonempty, the libraries will not be installed, neither in the local $(L4DIR)/lib nor in the global $(DROPS_STDDIR)/lib. Default: empty
OPTS Optimization switches for the compiler. Default: -g -O2 plus arch-dependent switches
PRIVATE_INCDIR++ Additional list of include-directories. Will be prefixed with -I. Default: unset
PRIVATE_LIBDIR++ Additional list of library-directories. Will be prefixed with -L. Default: unset
SERVERIDL++ IDL server source files. The .c and .cc-files compiled from the given IDLs are added to SRC_C++ and SRC_CC++ respectively. Default: unset.
SRC_{C,CC,S}++ The list of source {.c, .cc, .S}-files which have to be compiled and archived into the libraries. Default: unset.
SYSTEMS The systems the target libraries have to be build for. If multiple systems are given, each system is built into a separate directory. Default: x86-l4v2.
WARNINGS++ Warning switches for the compiler. Default: -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations

8.3.6 Example

PKGDIR = ..
L4DIR ?= \$(PKGDIR)/../..

TARGET = libping.a
SRC_C  = ping.c
include \$(L4DIR)/mk/lib.mk

8.3.7 C++ programs

If you do not need exception support, you can use the l4env mode, which comes with a much smaller libc. You have to define some callbacks then. Please see the exec server as an example.

L4 Checker 2012-04-11