2011-12-22 15:19:25 +00:00
|
|
|
##
|
|
|
|
## Rules for building a library target
|
|
|
|
##
|
|
|
|
## The following variables must be passed when calling this file:
|
|
|
|
##
|
|
|
|
## BASE_DIR - base directory of the build system
|
|
|
|
## REPOSITORIES - repositories providing libs and headers
|
|
|
|
## VERBOSE - build verboseness modifier
|
|
|
|
## VERBOSE_DIR - verboseness modifier for changing directories
|
|
|
|
## VERBOSE_MK - verboseness of make calls
|
|
|
|
## BUILD_BASE_DIR - base of build directory tree
|
|
|
|
## LIB_CACHE_DIR - library build cache location
|
2017-04-05 14:51:47 +00:00
|
|
|
## INSTALL_DIR - installation directory for stripped shared objects
|
|
|
|
## DEBUG_DIR - installation directory for unstripped shared objects
|
2016-12-29 17:27:45 +00:00
|
|
|
## SHARED_LIBS - shared-library dependencies of the library
|
|
|
|
## ARCHIVES - archive dependencies of the library
|
2011-12-22 15:19:25 +00:00
|
|
|
## REP_DIR - repository where the library resides
|
2014-05-08 14:42:38 +00:00
|
|
|
## CONTRIB_DIR - location of ported 3rd-party source codes
|
2011-12-22 15:19:25 +00:00
|
|
|
##
|
|
|
|
|
2014-01-08 14:01:26 +00:00
|
|
|
include $(BASE_DIR)/mk/base-libs.mk
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
|
|
|
# Prevent <libname>.mk rules to be executed as default rule
|
|
|
|
#
|
|
|
|
all:
|
|
|
|
|
|
|
|
#
|
2014-05-08 14:42:38 +00:00
|
|
|
# Include common utility functions
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
2014-05-08 14:42:38 +00:00
|
|
|
include $(BASE_DIR)/mk/util.inc
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Include specifics, for example platform, kernel-api etc.
|
|
|
|
#
|
|
|
|
include $(SPEC_FILES)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Include library build instructions
|
|
|
|
#
|
2014-05-08 14:42:38 +00:00
|
|
|
# We set the 'called_from_lib_mk' variable to allow the library description file
|
2011-12-22 15:19:25 +00:00
|
|
|
# to respond to the build pass.
|
|
|
|
#
|
|
|
|
BACKUP_INC_DIR := $(INC_DIR)
|
|
|
|
called_from_lib_mk = yes
|
|
|
|
include $(LIB_MK)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Sanity check for INC_DIR overrides
|
|
|
|
#
|
|
|
|
ifneq ($(filter-out $(INC_DIR),$(BACKUP_INC_DIR)),)
|
|
|
|
all: error_inc_dir_override
|
|
|
|
endif
|
|
|
|
|
|
|
|
error_inc_dir_override:
|
|
|
|
@$(ECHO) "Error: $(LIB_MK) overrides INC_DIR instead of appending" ; false
|
|
|
|
|
|
|
|
#
|
|
|
|
# Include lib-import descriptions of all used libraries and the target library
|
|
|
|
#
|
|
|
|
include $(foreach LIB,$(LIBS),$(call select_from_repositories,lib/import/import-$(LIB).mk))
|
|
|
|
|
|
|
|
#
|
|
|
|
# Include global definitions
|
|
|
|
#
|
|
|
|
include $(BASE_DIR)/mk/global.mk
|
|
|
|
|
2017-03-15 18:02:38 +00:00
|
|
|
ifneq ($(SYMBOLS),)
|
|
|
|
SHARED_LIB := yes
|
2011-12-22 15:19:25 +00:00
|
|
|
endif
|
|
|
|
|
2016-12-29 17:27:45 +00:00
|
|
|
#
|
|
|
|
# If a symbol list is provided, we create an ABI stub named '<lib>.abi.so'
|
|
|
|
#
|
|
|
|
# The ABI-stub library does not contain any code or data but only the symbol
|
|
|
|
# information of the binary interface (ABI) of the shared library.
|
|
|
|
#
|
|
|
|
# The ABI stub is linked by the users of the library (executables or shared
|
|
|
|
# objects) instead of the real library. This effectively decouples the library
|
|
|
|
# users from the concrete library instance but binds them merely to the
|
|
|
|
# library's binary interface. Note that the ABI stub is not used at runtime at
|
|
|
|
# all. At runtime, the real library that implements the ABI is loaded by the
|
|
|
|
# dynamic linker.
|
|
|
|
#
|
|
|
|
# The symbol information are incorporated into the ABI stub via an assembly
|
|
|
|
# file named '<lib>.symbols.s' that is generated from the library's symbol
|
|
|
|
# list. We create a symbolic link from the symbol file to the local directory.
|
|
|
|
# By using '.symbols' as file extension, the pattern rule '%.symbols.s:
|
|
|
|
# %.symbols' defined in 'generic.mk' is automatically applied for creating the
|
|
|
|
# assembly file from the symbols file.
|
|
|
|
#
|
|
|
|
# The '.PRECIOUS' special target prevents make to remove the intermediate
|
|
|
|
# assembler file. Otherwise make would spill the build log with messages
|
|
|
|
# like "rm libc.symbols.s".
|
|
|
|
#
|
|
|
|
ifneq ($(SYMBOLS),)
|
|
|
|
ABI_SO := $(addsuffix .abi.so,$(LIB))
|
|
|
|
|
|
|
|
$(LIB).symbols:
|
|
|
|
$(VERBOSE)ln -sf $(SYMBOLS) $@
|
|
|
|
|
|
|
|
.PRECIOUS: $(LIB).symbols.s
|
|
|
|
endif
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
|
|
|
# Link libgcc to shared libraries
|
|
|
|
#
|
|
|
|
# For static libraries, libgcc is not needed because it will be linked
|
|
|
|
# against the final target.
|
|
|
|
#
|
|
|
|
ifdef SHARED_LIB
|
|
|
|
LIBGCC = $(shell $(CC) $(CC_MARCH) -print-libgcc-file-name)
|
|
|
|
endif
|
|
|
|
|
|
|
|
#
|
|
|
|
# Print message for the currently built library
|
|
|
|
#
|
|
|
|
all: message
|
|
|
|
|
|
|
|
message:
|
|
|
|
$(MSG_LIB)$(LIB)
|
|
|
|
|
2017-03-15 18:02:38 +00:00
|
|
|
include $(BASE_DIR)/mk/generic.mk
|
|
|
|
|
|
|
|
#
|
|
|
|
# Name of <libname>.lib.a or <libname>.lib.so file to create
|
|
|
|
#
|
|
|
|
# Skip the creation and installation of an .so file if there are no
|
|
|
|
# ingredients. This is the case if the library is present as ABI only.
|
|
|
|
#
|
|
|
|
ifdef SHARED_LIB
|
|
|
|
ifneq ($(sort $(OBJECTS) $(LIBS)),)
|
|
|
|
LIB_SO := $(addsuffix .lib.so,$(LIB))
|
|
|
|
INSTALL_SO := $(INSTALL_DIR)/$(LIB_SO)
|
2017-04-05 14:51:47 +00:00
|
|
|
DEBUG_SO := $(DEBUG_DIR)/$(LIB_SO)
|
2017-03-15 18:02:38 +00:00
|
|
|
endif
|
|
|
|
else
|
|
|
|
LIB_A := $(addsuffix .lib.a,$(LIB))
|
|
|
|
endif
|
|
|
|
|
2018-01-10 13:29:23 +00:00
|
|
|
#
|
|
|
|
# Whenever an ABI is defined for a shared library, we check the consistency
|
|
|
|
# between both by invoking the 'check_abi' tool via the 'LIB_CHECKED'
|
|
|
|
# dependency.
|
|
|
|
#
|
|
|
|
ifneq ($(LIB_SO),)
|
|
|
|
ifneq ($(ABI_SO),)
|
|
|
|
LIB_CHECKED := $(addsuffix .lib.checked,$(LIB))
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
|
|
|
# Trigger the creation of the <libname>.lib.a or <libname>.lib.so file
|
|
|
|
#
|
2017-03-15 18:02:38 +00:00
|
|
|
LIB_TAG := $(addsuffix .lib.tag,$(LIB))
|
2011-12-22 15:19:25 +00:00
|
|
|
all: $(LIB_TAG)
|
|
|
|
|
2014-05-15 10:09:16 +00:00
|
|
|
#
|
|
|
|
# Trigger the build of host tools
|
|
|
|
#
|
|
|
|
# We make '$(LIB_TAG)' depend on the host tools to support building host tools
|
|
|
|
# from pseudo libraries with no actual source code. In this case '$(OBJECTS)'
|
|
|
|
# is empty.
|
|
|
|
#
|
|
|
|
$(LIB_TAG) $(OBJECTS): $(HOST_TOOLS)
|
|
|
|
|
2018-01-10 13:29:23 +00:00
|
|
|
$(LIB_TAG): $(LIB_A) $(LIB_SO) $(LIB_CHECKED) $(ABI_SO) $(INSTALL_SO) $(DEBUG_SO)
|
2011-12-22 15:19:25 +00:00
|
|
|
@touch $@
|
|
|
|
|
2016-12-29 17:27:45 +00:00
|
|
|
#
|
|
|
|
# Rust support
|
|
|
|
#
|
|
|
|
# For a rust library, we create both an actual library (lib.a or lib.so) that
|
|
|
|
# is used for linking the final binary, and an rlib file that is required for
|
|
|
|
# compiling rust source codes that use the library. As the rlib is created from
|
|
|
|
# the file specified at 'SRC_RS' via the pattern rule '%.rlib: %.rs', its name
|
|
|
|
# corresponds to the source file, not the library name. To enable rustc to find
|
|
|
|
# the library when compiling dependent compilation units, we create an
|
|
|
|
# appropriately named symlink that points to the rlib file.
|
|
|
|
#
|
|
|
|
ifneq ($(SRC_RS),)
|
|
|
|
ifneq ($(words $(SRC_RS)),1)
|
|
|
|
$(error 'SRC_RC' of library $(LIB) has more than one element: $(SRC_RC))
|
|
|
|
endif
|
|
|
|
$(LIB_A): $(LIB).rlib
|
|
|
|
endif
|
|
|
|
|
|
|
|
.PRECIOUS: $(SRC_RC:.rs=.rlib)
|
|
|
|
$(LIB).rlib: $(SRC_RS:.rs=.rlib)
|
|
|
|
$(VERBOSE)ln -s $< $@
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
|
|
|
# Rule to build the <libname>.lib.a file
|
|
|
|
#
|
|
|
|
# Use $(OBJECTS) instead of $^ for specifying the list of objects to include
|
|
|
|
# in the archive because $^ may also contain non-object phony targets, e.g.,
|
2015-03-16 14:37:47 +00:00
|
|
|
# used by the integration of Qt's meta-object compiler into the Genode
|
2011-12-22 15:19:25 +00:00
|
|
|
# build system.
|
|
|
|
#
|
|
|
|
$(LIB_A): $(OBJECTS)
|
|
|
|
$(MSG_MERGE)$(LIB_A)
|
2016-04-28 16:41:47 +00:00
|
|
|
$(VERBOSE)$(RM) -f $@
|
|
|
|
$(VERBOSE)$(AR) -rcs $@ $(OBJECTS)
|
2016-12-29 17:27:45 +00:00
|
|
|
|
2016-05-12 08:26:36 +00:00
|
|
|
#
|
2016-12-29 17:27:45 +00:00
|
|
|
# Link ldso-startup library to each shared library
|
2016-02-29 06:44:04 +00:00
|
|
|
#
|
2016-12-29 17:27:45 +00:00
|
|
|
ifdef SHARED_LIB
|
|
|
|
override ARCHIVES += ldso-startup.lib.a
|
|
|
|
endif
|
2016-02-29 06:44:04 +00:00
|
|
|
|
2014-01-28 13:30:36 +00:00
|
|
|
#
|
2014-02-11 17:15:34 +00:00
|
|
|
# Don't link base libraries against shared libraries except for ld.lib.so
|
2014-01-28 13:30:36 +00:00
|
|
|
#
|
2016-12-09 22:09:17 +00:00
|
|
|
ifneq ($(LIB_IS_DYNAMIC_LINKER),yes)
|
2016-12-29 17:27:45 +00:00
|
|
|
override ARCHIVES := $(filter-out $(BASE_LIBS:=.lib.a),$(ARCHIVES))
|
Merge base libraries into a single library
This patch simplifies the way of how Genode's base libraries are
organized. Originally, the base API was implemented in the form of many
small libraries such as 'thread', 'env', 'server', etc. Most of them
used to consist of only a small number of files. Because those libraries
are incorporated in any build, the checking of their inter-dependencies
made the build process more verbose than desired. Also, the number of
libraries and their roles (core only, non-core only, shared by both core
and non-core) were not easy to capture.
Hereby, the base libraries have been reduced to the following few
libraries:
- startup.mk contains the startup code for normal Genode processes.
On some platform, core is able to use the library as well.
- base-common.mk contains the parts of the base library that are
identical by core and non-core processes.
- base.mk contains the complete base API implementation for non-core
processes
Consequently, the 'LIBS' declaration in 'target.mk' files becomes
simpler as well. In the most simple case, only the 'base' library must
be mentioned.
Fixes #18
2013-02-14 11:39:51 +00:00
|
|
|
endif
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
|
|
|
# The 'sort' is needed to ensure the same link order regardless
|
|
|
|
# of the find order, which uses to vary among different systems.
|
|
|
|
#
|
2016-12-29 17:27:45 +00:00
|
|
|
STATIC_LIBS := $(sort $(foreach l,$(ARCHIVES:.lib.a=),$(LIB_CACHE_DIR)/$l/$l.lib.a))
|
2011-12-22 15:19:25 +00:00
|
|
|
STATIC_LIBS_BRIEF := $(subst $(LIB_CACHE_DIR),$$libs,$(STATIC_LIBS))
|
|
|
|
|
|
|
|
#
|
|
|
|
# Rule to build the <libname>.lib.so file
|
|
|
|
#
|
2016-12-29 17:27:45 +00:00
|
|
|
# When linking the shared library, we have to link all shared sub libraries
|
|
|
|
# (LIB_SO_DEPS) to the library to store the library-dependency information in
|
|
|
|
# the generated shared object.
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
|
|
|
# The 'ldso-startup/startup.o' object file, which contains the support code for
|
|
|
|
# constructing static objects must be specified as object file to prevent the
|
|
|
|
# linker from garbage-collecting it.
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# Default entry point of shared libraries
|
|
|
|
#
|
2016-12-29 17:27:45 +00:00
|
|
|
ENTRY_POINT ?= 0x0
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2016-12-29 17:27:45 +00:00
|
|
|
$(LIB_SO) $(ABI_SO): $(SHARED_LIBS)
|
|
|
|
|
|
|
|
$(LIB_SO): $(STATIC_LIBS) $(OBJECTS) $(wildcard $(LD_SCRIPT_SO)) $(LIB_SO_DEPS)
|
2011-12-22 15:19:25 +00:00
|
|
|
$(MSG_MERGE)$(LIB_SO)
|
|
|
|
$(VERBOSE)libs=$(LIB_CACHE_DIR); $(LD) -o $(LIB_SO) -shared --eh-frame-hdr \
|
2016-12-29 17:27:45 +00:00
|
|
|
$(LD_OPT) -T $(LD_SCRIPT_SO) --entry=$(ENTRY_POINT) \
|
|
|
|
--whole-archive --start-group \
|
|
|
|
$(SHARED_LIBS) $(STATIC_LIBS_BRIEF) $(OBJECTS) \
|
|
|
|
--end-group --no-whole-archive \
|
2011-12-22 15:19:25 +00:00
|
|
|
$(LIBGCC)
|
|
|
|
|
2016-12-29 17:27:45 +00:00
|
|
|
$(ABI_SO): $(LIB).symbols.o
|
|
|
|
$(MSG_MERGE)$(ABI_SO)
|
|
|
|
$(VERBOSE)$(LD) -o $(ABI_SO) -shared --eh-frame-hdr $(LD_OPT) \
|
|
|
|
-T $(LD_SCRIPT_SO) \
|
|
|
|
--whole-archive --start-group \
|
|
|
|
$(LIB_SO_DEPS) $< \
|
|
|
|
--end-group --no-whole-archive
|
|
|
|
|
2018-01-10 13:29:23 +00:00
|
|
|
$(LIB_CHECKED): $(LIB_SO)
|
|
|
|
$(VERBOSE)$(BASE_DIR)/../../tool/check_abi $(LIB_SO) $(SYMBOLS)
|
|
|
|
|
2017-04-05 14:51:47 +00:00
|
|
|
$(LIB_SO).stripped: $(LIB_SO)
|
|
|
|
$(VERBOSE)$(STRIP) -o $@ $<
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2017-04-05 14:51:47 +00:00
|
|
|
$(DEBUG_SO): $(LIB_SO)
|
|
|
|
$(VERBOSE)ln -sf $(CURDIR)/$< $@
|
|
|
|
|
|
|
|
$(INSTALL_SO): $(LIB_SO).stripped
|
|
|
|
$(VERBOSE)ln -sf $(CURDIR)/$< $@
|