2011-12-22 15:19:25 +00:00
|
|
|
##
|
2023-11-20 13:53:05 +00:00
|
|
|
## Rules for building a shared object (.lib.so)
|
2011-12-22 15:19:25 +00:00
|
|
|
##
|
2023-11-20 13:53:05 +00:00
|
|
|
## The expected variables correspond to those documented in a.mk, with
|
|
|
|
## the following addition:
|
2011-12-22 15:19:25 +00:00
|
|
|
##
|
2023-11-20 13:53:05 +00:00
|
|
|
## SYMBOLS - path of symbols file
|
2011-12-22 15:19:25 +00:00
|
|
|
##
|
|
|
|
|
2023-11-20 13:53:05 +00:00
|
|
|
LIB_SO := $(addsuffix .lib.so,$(LIB))
|
|
|
|
|
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:
|
2023-11-20 13:53:05 +00:00
|
|
|
@true # prevent nothing-to-be-done message
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
#
|
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)
|
|
|
|
|
2023-11-20 13:53:05 +00:00
|
|
|
ORIG_INC_DIR := $(INC_DIR)
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
called_from_lib_mk = yes
|
|
|
|
include $(LIB_MK)
|
|
|
|
|
2023-11-20 13:53:05 +00:00
|
|
|
#
|
|
|
|
# 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))
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
|
|
|
# Sanity check for INC_DIR overrides
|
|
|
|
#
|
2023-11-20 13:53:05 +00:00
|
|
|
ifneq ($(filter-out $(INC_DIR),$(ORIG_INC_DIR)),)
|
2011-12-22 15:19:25 +00:00
|
|
|
all: error_inc_dir_override
|
|
|
|
endif
|
|
|
|
|
|
|
|
error_inc_dir_override:
|
2023-11-20 13:53:05 +00:00
|
|
|
@$(ECHO) "Error: INC_DIR overridden instead of appended" ; false
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Include global definitions
|
|
|
|
#
|
|
|
|
include $(BASE_DIR)/mk/global.mk
|
2023-11-20 13:53:05 +00:00
|
|
|
include $(BASE_DIR)/mk/generic.mk
|
2016-12-29 17:27:45 +00:00
|
|
|
|
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.
|
|
|
|
#
|
|
|
|
LIBGCC = $(shell $(CC) $(CC_MARCH) -print-libgcc-file-name)
|
2017-03-15 18:02:38 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2023-11-20 13:53:05 +00:00
|
|
|
ifneq ($(sort $(OBJECTS) $(LIBS)),)
|
|
|
|
ABI_SO := $(wildcard $(addsuffix .abi.so,$(LIB)))
|
|
|
|
INSTALL_SO := $(INSTALL_DIR)/$(LIB_SO)
|
|
|
|
DEBUG_SO := $(DEBUG_DIR)/$(LIB_SO)
|
|
|
|
LIB_SO_DEBUG := $(LIB_SO).debug
|
|
|
|
DEBUG_SO_DEBUG := $(DEBUG_SO).debug
|
2017-03-15 18:02:38 +00:00
|
|
|
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
|
|
|
#
|
2023-11-20 13:53:05 +00:00
|
|
|
# Trigger the creation of the <libname>.lib.so file
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
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)
|
|
|
|
|
2023-11-20 13:53:05 +00:00
|
|
|
$(LIB_TAG):
|
|
|
|
@touch $@
|
|
|
|
|
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)
|
|
|
|
|
2021-03-31 22:31:39 +00:00
|
|
|
#
|
|
|
|
# Trigger build of additional library specific targets
|
|
|
|
#
|
|
|
|
$(LIB_TAG): $(CUSTOM_TARGET_DEPS)
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
2023-11-20 13:53:05 +00:00
|
|
|
# Don't link shared object it BUILD_ARTIFACTS are declared as empty (ld.lib.so)
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
2023-11-20 13:53:05 +00:00
|
|
|
BUILD_ARTIFACTS ?= $(LIB).lib.so
|
|
|
|
|
|
|
|
ifneq ($(BUILD_ARTIFACTS),)
|
|
|
|
$(LIB_TAG): $(LIB_SO) $(LIB_CHECKED) $(INSTALL_SO) $(DEBUG_SO) $(DEBUG_SO_DEBUG)
|
|
|
|
endif
|
2016-12-29 17:27:45 +00:00
|
|
|
|
2016-05-12 08:26:36 +00:00
|
|
|
#
|
2020-04-02 06:19:34 +00:00
|
|
|
# Link ldso-support library to each shared library to provide local hook
|
|
|
|
# functions for constructors and ARM
|
2016-02-29 06:44:04 +00:00
|
|
|
#
|
2020-04-02 06:19:34 +00:00
|
|
|
override ARCHIVES += ldso_so_support.lib.a
|
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))
|
|
|
|
|
2016-12-29 17:27:45 +00:00
|
|
|
ENTRY_POINT ?= 0x0
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2022-02-16 13:05:27 +00:00
|
|
|
$(LIB_SO): $(SHARED_LIBS)
|
2016-12-29 17:27:45 +00:00
|
|
|
|
2023-12-01 08:40:00 +00:00
|
|
|
$(LIB_SO): $(STATIC_LIBS) $(OBJECTS) $(wildcard $(LD_SCRIPT_SO))
|
2011-12-22 15:19:25 +00:00
|
|
|
$(MSG_MERGE)$(LIB_SO)
|
2023-05-31 12:51:09 +00:00
|
|
|
$(VERBOSE)libs=$(LIB_CACHE_DIR); $(LD) -o $(LIB_SO) -soname=$(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)
|
|
|
|
|
2021-01-05 22:03:54 +00:00
|
|
|
$(LIB_CHECKED): $(LIB_SO) $(SYMBOLS)
|
|
|
|
$(VERBOSE)$(BASE_DIR)/../../tool/check_abi $(LIB_SO) $(SYMBOLS) && touch $@
|
2018-01-10 13:29:23 +00:00
|
|
|
|
2023-10-18 06:52:24 +00:00
|
|
|
$(LIB_SO_DEBUG): $(LIB_SO)
|
|
|
|
$(VERBOSE)$(OBJCOPY) --only-keep-debug $< $@
|
|
|
|
|
|
|
|
$(LIB_SO).stripped: $(LIB_SO) $(LIB_SO_DEBUG)
|
2017-04-05 14:51:47 +00:00
|
|
|
$(VERBOSE)$(STRIP) -o $@ $<
|
2023-10-18 06:52:24 +00:00
|
|
|
$(VERBOSE)$(OBJCOPY) --add-gnu-debuglink=$(LIB_SO_DEBUG) $@
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2023-10-18 06:52:24 +00:00
|
|
|
$(INSTALL_SO): $(LIB_SO).stripped
|
2017-04-05 14:51:47 +00:00
|
|
|
$(VERBOSE)ln -sf $(CURDIR)/$< $@
|
|
|
|
|
2023-10-18 06:52:24 +00:00
|
|
|
$(DEBUG_SO): $(LIB_SO).stripped
|
|
|
|
$(VERBOSE)ln -sf $(CURDIR)/$< $@
|
|
|
|
|
|
|
|
$(DEBUG_SO_DEBUG): $(LIB_SO_DEBUG)
|
2017-04-05 14:51:47 +00:00
|
|
|
$(VERBOSE)ln -sf $(CURDIR)/$< $@
|