2011-12-22 15:19:25 +00:00
|
|
|
##
|
|
|
|
## Rules for building a program target
|
|
|
|
##
|
|
|
|
## The following variables must be passed when calling this file:
|
|
|
|
##
|
|
|
|
## BASE_DIR - base directory of the build system
|
|
|
|
## REP_DIR - source repository of the program
|
|
|
|
## PRG_REL_DIR - directory of the program relative to 'src/'
|
|
|
|
## REPOSITORIES - repositories providing libs and headers
|
|
|
|
## INSTALL_DIR - final install location
|
|
|
|
## VERBOSE - build verboseness modifier
|
|
|
|
## VERBOSE_DIR - verboseness modifier for changing directories
|
|
|
|
## VERBOSE_MK - verboseness of make calls
|
|
|
|
## LIB_CACHE_DIR - library build cache location
|
|
|
|
##
|
|
|
|
|
|
|
|
#
|
|
|
|
# Prevent target.mk rules to be executed as default rule
|
|
|
|
#
|
|
|
|
all:
|
|
|
|
|
|
|
|
#
|
|
|
|
# Function that searches for files in all repositories and returns the first match
|
|
|
|
#
|
|
|
|
select_from_repositories = $(firstword $(foreach REP,$(REPOSITORIES),$(wildcard $(REP)/$(1))))
|
|
|
|
|
|
|
|
#
|
|
|
|
# Include target build instructions
|
|
|
|
#
|
|
|
|
PRG_DIR := $(REP_DIR)/src/$(PRG_REL_DIR)
|
|
|
|
include $(PRG_DIR)/target.mk
|
|
|
|
|
2011-12-23 13:04:29 +00:00
|
|
|
#
|
|
|
|
# Enforce use of 'lx_hybrid' library for all targets when 'always_hybrid' is
|
|
|
|
# enabled
|
|
|
|
#
|
|
|
|
ifeq ($(filter-out $(SPECS),always_hybrid),)
|
|
|
|
LIBS += lx_hybrid
|
|
|
|
endif
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
|
|
|
# Include lib-import description files
|
|
|
|
#
|
|
|
|
include $(foreach LIB,$(LIBS),$(call select_from_repositories,lib/import/import-$(LIB).mk))
|
|
|
|
|
|
|
|
#
|
|
|
|
# Include specifics for platforms, kernel APIs, etc.
|
|
|
|
#
|
|
|
|
include $(SPEC_FILES)
|
|
|
|
|
|
|
|
vpath % $(PRG_DIR)
|
|
|
|
|
|
|
|
include $(BASE_DIR)/mk/global.mk
|
|
|
|
|
|
|
|
#
|
|
|
|
# Assemble linker options for static and dynamic linkage
|
|
|
|
#
|
|
|
|
ifneq ($(LD_TEXT_ADDR),)
|
|
|
|
CXX_LINK_OPT += -Wl,-Ttext=$(LD_TEXT_ADDR)
|
|
|
|
endif
|
|
|
|
|
|
|
|
#
|
|
|
|
# Supply machine-dependent arguments to the linker
|
|
|
|
#
|
|
|
|
CXX_LINK_OPT += $(CC_MARCH)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generic linker script for statically linked binaries
|
|
|
|
#
|
|
|
|
LD_SCRIPT_STATIC ?= $(call select_from_repositories,src/platform/genode.ld)
|
|
|
|
|
|
|
|
include $(BASE_DIR)/mk/generic.mk
|
|
|
|
include $(BASE_DIR)/mk/base-libs.mk
|
|
|
|
|
|
|
|
ifeq ($(INSTALL_DIR),)
|
|
|
|
all: message $(TARGET)
|
|
|
|
else
|
|
|
|
all: message $(INSTALL_DIR)/$(TARGET)
|
|
|
|
endif
|
|
|
|
@true # prevent nothing-to-be-done message
|
|
|
|
|
|
|
|
.PHONY: message
|
|
|
|
message:
|
|
|
|
$(MSG_PRG)$(PRG_REL_DIR)/$(TARGET)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Enforce unconditional call of gnatmake rule when compiling Ada sources
|
|
|
|
#
|
|
|
|
# Citation from texinfo manual for make:
|
|
|
|
#
|
|
|
|
# If a rule has no prerequisites or commands, and the target of the rule
|
|
|
|
# is a nonexistent file, then `make' imagines this target to have been
|
|
|
|
# updated whenever its rule is run. This implies that all targets
|
|
|
|
# depending on this one will always have their commands run.
|
|
|
|
#
|
|
|
|
FORCE:
|
|
|
|
$(SRC_ADA:.adb=.o): FORCE
|
|
|
|
|
|
|
|
#
|
|
|
|
# The 'sort' is needed to ensure the same link order regardless
|
|
|
|
# of the find order, which uses to vary among different systems.
|
|
|
|
#
|
|
|
|
SHARED_LIBS := $(foreach l,$(DEPS:.lib=),$(LIB_CACHE_DIR)/$l/$l.lib.so)
|
|
|
|
SHARED_LIBS := $(sort $(wildcard $(SHARED_LIBS)))
|
|
|
|
|
|
|
|
#
|
|
|
|
# Use CXX for linking
|
|
|
|
#
|
2013-02-03 01:47:01 +00:00
|
|
|
LD_CMD ?= $(CXX)
|
|
|
|
|
|
|
|
LD_CMD += $(CXX_LINK_OPT)
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
ifeq ($(SHARED_LIBS),)
|
|
|
|
LD_SCRIPTS := $(LD_SCRIPT_STATIC)
|
|
|
|
FILTER_DEPS := $(DEPS:.lib=)
|
|
|
|
else
|
|
|
|
LD_SCRIPTS := $(LD_SCRIPT_DYN)
|
|
|
|
LD_CMD += -Wl,--dynamic-linker=$(DYNAMIC_LINKER).lib.so \
|
|
|
|
-Wl,--eh-frame-hdr
|
|
|
|
|
|
|
|
#
|
|
|
|
# Filter out the base libraries since they will be provided by the ldso.library
|
|
|
|
#
|
|
|
|
FILTER_DEPS := $(filter-out $(BASE_LIBS),$(DEPS:.lib=))
|
|
|
|
SHARED_LIBS += $(LIB_CACHE_DIR)/$(DYNAMIC_LINKER)/$(DYNAMIC_LINKER).lib.so
|
|
|
|
endif
|
|
|
|
|
|
|
|
#
|
|
|
|
# LD_SCRIPT_PREFIX is needed as 'addprefix' chokes on prefixes containing
|
|
|
|
# commas othwerwise. For compatibilty with older tool chains, we use two -Wl
|
|
|
|
# parameters for both components of the linker command line.
|
|
|
|
#
|
|
|
|
LD_SCRIPT_PREFIX = -Wl,-T -Wl,
|
|
|
|
|
|
|
|
#
|
|
|
|
# LD_SCRIPTS may be a list of linker scripts (e.g., in base-linux). Further,
|
|
|
|
# we use the default linker script if none was specified - 'addprefix' expands
|
|
|
|
# to empty string on empty input.
|
|
|
|
#
|
|
|
|
LD_CMD += $(addprefix $(LD_SCRIPT_PREFIX), $(LD_SCRIPTS))
|
|
|
|
|
|
|
|
STATIC_LIBS := $(foreach l,$(FILTER_DEPS),$(LIB_CACHE_DIR)/$l/$l.lib.a)
|
|
|
|
STATIC_LIBS := $(sort $(wildcard $(STATIC_LIBS)))
|
|
|
|
|
2011-12-22 16:17:44 +00:00
|
|
|
#
|
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
|
|
|
# For hybrid Linux/Genode programs, prevent the linkage Genode's cxx, base,
|
|
|
|
# and startup libraries because these functionalities are covered by the glibc
|
|
|
|
# or by 'src/platform/lx_hybrid.cc'.
|
2011-12-22 16:17:44 +00:00
|
|
|
#
|
|
|
|
ifeq ($(USE_HOST_LD_SCRIPT),yes)
|
2011-12-23 13:04:29 +00:00
|
|
|
STATIC_LIBS := $(filter-out $(LIB_CACHE_DIR)/startup/startup.lib.a, $(STATIC_LIBS))
|
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
|
|
|
STATIC_LIBS := $(filter-out $(LIB_CACHE_DIR)/base/base.lib.a, $(STATIC_LIBS))
|
2011-12-23 13:04:29 +00:00
|
|
|
STATIC_LIBS := $(filter-out $(LIB_CACHE_DIR)/cxx/cxx.lib.a, $(STATIC_LIBS))
|
2011-12-22 16:17:44 +00:00
|
|
|
endif
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
|
|
|
# We need the linker option '--whole-archive' to make sure that all library
|
|
|
|
# constructors marked with '__attribute__((constructor))' end up int the
|
|
|
|
# binary. When not using this option, the linker goes through all libraries
|
|
|
|
# to resolve a symbol and, if it finds the symbol, stops searching. This way,
|
|
|
|
# object files that are never explicitly referenced (such as library
|
|
|
|
# constructors) would not be visited at all.
|
|
|
|
#
|
|
|
|
# Furthermore, the '--whole-archive' option reveals symbol ambiguities, which
|
|
|
|
# would go undetected if the search stops after the first match.
|
|
|
|
#
|
|
|
|
LINK_ITEMS := $(OBJECTS) $(STATIC_LIBS) $(SHARED_LIBS)
|
|
|
|
SHORT_LINK_ITEMS := $(subst $(LIB_CACHE_DIR),$$libs,$(LINK_ITEMS))
|
|
|
|
|
|
|
|
LD_CMD += -Wl,--whole-archive -Wl,--start-group
|
|
|
|
LD_CMD += $(SHORT_LINK_ITEMS)
|
|
|
|
LD_CMD += $(EXT_OBJECTS)
|
2012-11-23 17:16:52 +00:00
|
|
|
LD_CMD += -Wl,--end-group -Wl,--no-whole-archive
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Link libgcc to each program
|
|
|
|
#
|
|
|
|
LD_LIBGCC ?= $(shell $(CC) $(CC_MARCH) -print-libgcc-file-name)
|
|
|
|
LD_CMD += $(LD_LIBGCC)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Skip final linking if no objects are involved, i.e. no 'SRC' files are
|
|
|
|
# specified in the 'target.mk' file. This applies for pseudo 'target.mk'
|
|
|
|
# files that invoke a 3rd-party build system by providing local rule for
|
|
|
|
# $(TARGET).
|
|
|
|
#
|
|
|
|
ifneq ($(OBJECTS),)
|
|
|
|
$(TARGET): $(LINK_ITEMS) $(wildcard $(LD_SCRIPTS))
|
|
|
|
$(MSG_LINK)$(TARGET)
|
|
|
|
$(VERBOSE)libs=$(LIB_CACHE_DIR); $(LD_CMD) -o $@
|
|
|
|
|
|
|
|
$(INSTALL_DIR)/$(TARGET): $(TARGET)
|
2012-10-22 18:38:49 +00:00
|
|
|
$(VERBOSE)ln -sf $(CURDIR)/$(TARGET) $@
|
2011-12-22 15:19:25 +00:00
|
|
|
else
|
|
|
|
$(TARGET):
|
|
|
|
$(INSTALL_DIR)/$(TARGET): $(TARGET)
|
|
|
|
endif
|
|
|
|
|
|
|
|
clean_prg_objects:
|
|
|
|
$(MSG_CLEAN)$(PRG_REL_DIR)
|
|
|
|
$(VERBOSE)$(RM) -f $(OBJECTS) $(OBJECTS:.o=.d) $(TARGET)
|
|
|
|
$(VERBOSE)$(RM) -f *.d *.i *.ii *.s *.ali
|
|
|
|
|
|
|
|
clean: clean_prg_objects
|