2016-09-11 19:13:27 +00:00
|
|
|
#
|
|
|
|
# \brief Rules for building software that uses the GNU build tools
|
|
|
|
# \author Norman Feske
|
|
|
|
# \date 2011-02-02
|
|
|
|
#
|
|
|
|
# This file is meant to be included by 'target.mk' files. Instead of building
|
|
|
|
# a normal Genode target, the 'target.mk' file will then trigger the build
|
|
|
|
# of the contrib package specified with the 'PKG' variable. The build
|
|
|
|
# consists to the following steps
|
|
|
|
#
|
|
|
|
# 1. Configuring the package by invoking the package's 'configure' script
|
|
|
|
# with the arguments required for cross compiling the package for
|
|
|
|
# Genode.
|
|
|
|
# 2. Building the package by invoking the 'Makefile' generated by the
|
|
|
|
# 'configure' script.
|
|
|
|
#
|
|
|
|
# Limitations
|
|
|
|
# -----------
|
|
|
|
#
|
|
|
|
# In contrast to the Genode build system, library dependencies are not covered.
|
|
|
|
# So if a library used by a package is changed, the package gets not relinked
|
|
|
|
# automatically. In this case, 'make clean' must be invoked manually within the
|
|
|
|
# build subdirectory of the package.
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# Use name of the directory hosting the 'target.mk' file as 'TARGET'
|
|
|
|
# and 'PKG' by default.
|
|
|
|
#
|
|
|
|
TARGET ?= $(lastword $(subst /, ,$(PRG_DIR)))
|
|
|
|
PKG ?= $(TARGET)
|
|
|
|
|
2017-05-14 20:00:40 +00:00
|
|
|
#
|
|
|
|
# Select how to make the build result available at Genode's 'INSTALL_DIR'.
|
|
|
|
# By default, a single tar archive containing the results of the package's
|
|
|
|
# 'make install' rule is created. By setting the 'INSTALL_TREE' variable
|
|
|
|
# to a non-empty value, a symlink to the actual file tree is created.
|
|
|
|
#
|
2017-12-08 20:01:58 +00:00
|
|
|
# By default, the generated tar archive contains the entire content of the
|
|
|
|
# package's install directory. The 'INSTALL_TAR_CONTENT' variable may be
|
|
|
|
# overriden to manually specify only the parts of the content.
|
|
|
|
#
|
2017-05-14 20:00:40 +00:00
|
|
|
INSTALL_TREE ?=
|
|
|
|
INSTALL_TAR_ARCHIVE ?= yes
|
2017-12-08 20:01:58 +00:00
|
|
|
INSTALL_TAR_CONTENT ?= .
|
2017-05-14 20:00:40 +00:00
|
|
|
|
2016-12-22 14:01:19 +00:00
|
|
|
LIBS += posix
|
2016-09-11 19:13:27 +00:00
|
|
|
|
|
|
|
PWD = $(shell pwd)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Detect missing preparation ofpackage
|
|
|
|
#
|
|
|
|
ifeq ($(PKG_DIR),)
|
|
|
|
REQUIRES += prepare_$(PKG)
|
|
|
|
endif
|
|
|
|
|
|
|
|
#
|
|
|
|
# Verbose build
|
|
|
|
#
|
|
|
|
ifeq ($(VERBOSE),)
|
|
|
|
MAKE_VERBOSE = V=1
|
|
|
|
CONFIGURE_VERBOSE =
|
|
|
|
|
|
|
|
#
|
|
|
|
# Non-verbose build
|
|
|
|
#
|
|
|
|
else
|
|
|
|
MAKE_VERBOSE = -s
|
|
|
|
CONFIGURE_VERBOSE = --quiet
|
|
|
|
|
|
|
|
# filter for configure output of package
|
|
|
|
CONFIGURE_OUTPUT_FILTER = > stdout.log 2> stderr.log ||\
|
|
|
|
(echo "Error: configure script of $(PKG) failed" && \
|
|
|
|
cat stderr.log && false)
|
|
|
|
|
|
|
|
# filter for make output of package
|
|
|
|
BUILD_OUTPUT_FILTER = 2>&1 | sed "s/^/ [$(PKG)] /"
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(findstring arm, $(SPECS)), arm)
|
|
|
|
CONFIGURE_ARGS += --host arm-none-eabi
|
2019-08-21 14:53:59 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(findstring arm_v8, $(SPECS)), arm_v8)
|
|
|
|
CONFIGURE_ARGS += --host aarch64-none-elf
|
|
|
|
endif
|
2021-12-15 10:06:35 +00:00
|
|
|
ifeq ($(findstring riscv, $(SPECS)), riscv)
|
|
|
|
CONFIGURE_ARGS += --host riscv64-unknown-elf
|
|
|
|
endif
|
2016-09-11 19:13:27 +00:00
|
|
|
ifeq ($(findstring x86, $(SPECS)), x86)
|
|
|
|
CONFIGURE_ARGS += --host x86_64-pc-elf
|
|
|
|
endif
|
|
|
|
|
|
|
|
CONFIGURE_ARGS += --srcdir=$(PKG_DIR)
|
|
|
|
CONFIGURE_ARGS += --prefix /
|
|
|
|
|
|
|
|
CONFIG_GUESS_SCRIPT = $(PKG_DIR)/config.guess
|
|
|
|
ifneq ($(wildcard $(CONFIG_GUESS_SCRIPT)),)
|
|
|
|
CONFIGURE_ARGS += --build $(shell $(CONFIG_GUESS_SCRIPT))
|
|
|
|
else
|
|
|
|
CONFIGURE_ARGS += --build x86-linux
|
|
|
|
endif
|
|
|
|
|
|
|
|
CONFIGURE_ARGS += $(CONFIGURE_VERBOSE)
|
|
|
|
|
|
|
|
LDFLAGS += -nostdlib $(CXX_LINK_OPT) $(CC_MARCH) -Wl,-T$(LD_SCRIPT_DYN) \
|
2016-12-29 17:27:45 +00:00
|
|
|
-Wl,-rpath-link=$(PWD) \
|
|
|
|
-Wl,--dynamic-linker=$(DYNAMIC_LINKER).lib.so \
|
|
|
|
-Wl,--eh-frame-hdr
|
|
|
|
|
2016-09-11 19:13:27 +00:00
|
|
|
LIBTOOLFLAGS = --preserve-dup-deps
|
|
|
|
|
|
|
|
LIBGCC = $(shell $(CC) $(CC_MARCH) -print-libgcc-file-name)
|
|
|
|
|
|
|
|
CPPFLAGS += -nostdinc $(INCLUDES)
|
2019-08-21 14:53:59 +00:00
|
|
|
CPPFLAGS += -D_GNU_SOURCE=1 -fPIC
|
2016-09-11 19:13:27 +00:00
|
|
|
|
|
|
|
# flags to be used in both CFLAGS and CXXFLAGS
|
|
|
|
COMMON_CFLAGS_CXXFLAGS += -ffunction-sections $(CC_OLEVEL) $(CC_MARCH)
|
|
|
|
COMMON_CFLAGS_CXXFLAGS += -g
|
|
|
|
|
2016-12-29 17:27:45 +00:00
|
|
|
CFLAGS += $(COMMON_CFLAGS_CXXFLAGS)
|
2016-09-11 19:13:27 +00:00
|
|
|
CXXFLAGS += $(COMMON_CFLAGS_CXXFLAGS)
|
|
|
|
|
|
|
|
#
|
|
|
|
# We have to specify 'LINK_ITEMS' twice to resolve inter-library dependencies.
|
|
|
|
# Unfortunately, the use of '--start-group' and '--end-group' does not suffice
|
|
|
|
# in all cases because 'libtool' strips those arguments from the 'LIBS' variable.
|
|
|
|
#
|
2016-12-29 17:27:45 +00:00
|
|
|
LDLIBS_A = $(filter %.a, $(sort $(STATIC_LIBS)) $(EXT_OBJECTS) $(LIBGCC))
|
2019-09-23 10:17:12 +00:00
|
|
|
LDLIBS_SO = $(addprefix -l:,$(sort $(SHARED_LIBS)))
|
|
|
|
LDLIBS += -L$(PWD) $(LDLIBS_A) $(LDLIBS_SO) $(LDLIBS_A)
|
2016-09-11 19:13:27 +00:00
|
|
|
|
2018-01-18 12:54:03 +00:00
|
|
|
#
|
|
|
|
# By default, assume that there exists a 'configure' script in the top-level
|
|
|
|
# of the package.
|
|
|
|
#
|
|
|
|
CONFIGURE_SCRIPT ?= $(PKG_DIR)/configure
|
|
|
|
|
2016-09-11 19:13:27 +00:00
|
|
|
#
|
|
|
|
# Re-configure the Makefile if the Genode build environment changes
|
|
|
|
#
|
|
|
|
Makefile reconfigure: $(MAKEFILE_LIST)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Invoke configure script with the Genode environment
|
|
|
|
#
|
2016-12-29 17:27:45 +00:00
|
|
|
Makefile reconfigure: env.sh $(SHARED_LIBS)
|
2016-09-11 19:13:27 +00:00
|
|
|
@$(MSG_CONFIG)$(TARGET)
|
2019-03-04 01:24:10 +00:00
|
|
|
$(VERBOSE)source env.sh && $(CONFIGURE_SCRIPT) $(MKENV) $(CONFIGURE_ARGS) $(CONFIGURE_OUTPUT_FILTER)
|
2016-09-11 19:13:27 +00:00
|
|
|
|
|
|
|
env.sh:
|
|
|
|
$(VERBOSE)rm -f $@
|
|
|
|
$(VERBOSE)echo "export CC='$(CC)'" >> $@
|
|
|
|
$(VERBOSE)echo "export CXX='$(CXX)'" >> $@
|
|
|
|
$(VERBOSE)echo "export LD='$(LD)'" >> $@
|
|
|
|
$(VERBOSE)echo "export AR='$(AR)'" >> $@
|
|
|
|
$(VERBOSE)echo "export NM='$(NM)'" >> $@
|
|
|
|
$(VERBOSE)echo "export RANLIB='$(RANLIB)'" >> $@
|
|
|
|
$(VERBOSE)echo "export STRIP='$(STRIP)'" >> $@
|
|
|
|
$(VERBOSE)echo "export CPPFLAGS='$(CPPFLAGS)'" >> $@
|
|
|
|
$(VERBOSE)echo "export CFLAGS='$(CFLAGS)'" >> $@
|
|
|
|
$(VERBOSE)echo "export CXXFLAGS='$(CXXFLAGS)'" >> $@
|
|
|
|
$(VERBOSE)echo "export LDFLAGS='$(LDFLAGS)'" >> $@
|
|
|
|
$(VERBOSE)echo "export LIBS='$(LDLIBS)'" >> $@
|
|
|
|
$(VERBOSE)echo "export LIBTOOLFLAGS='$(LIBTOOLFLAGS)'" >> $@
|
|
|
|
$(VERBOSE)echo "export PS1='<gnu_build>'" >> $@
|
|
|
|
|
|
|
|
#
|
|
|
|
# Invoke the 'Makefile' generated by the configure script
|
|
|
|
#
|
|
|
|
# The 'MAN=' argument prevent manual pages from being created. This would
|
|
|
|
# produce an error when the package uses the 'help2man' tool. This tool
|
|
|
|
# tries to extract the man page of a program by executing it with the
|
|
|
|
# '--help' argument on the host. However, we cannot run Genode binaries
|
|
|
|
# this way.
|
|
|
|
#
|
|
|
|
built.tag: env.sh Makefile
|
|
|
|
@$(MSG_BUILD)$(TARGET)
|
2018-01-18 12:54:03 +00:00
|
|
|
$(VERBOSE)source env.sh &&\
|
|
|
|
$(MAKE) $(MAKE_ENV) $(MAKE_VERBOSE) $(MAKE_TARGET) MAN= \
|
|
|
|
$(BUILD_OUTPUT_FILTER)
|
2016-09-11 19:13:27 +00:00
|
|
|
@touch $@
|
|
|
|
|
|
|
|
INSTALL_TARGET ?= install-strip
|
|
|
|
|
2017-05-14 20:00:40 +00:00
|
|
|
#
|
|
|
|
# Install result of the build in an 'install/' directory local to the target's
|
2018-01-18 12:54:03 +00:00
|
|
|
# build directory. The default install step 'make install-strip' can be
|
|
|
|
# customized by setting 'INSTALL_TARGET' to be empty. This is useful to
|
|
|
|
# explicitly filter the installed content in the 'target.mk' file.
|
2017-05-14 20:00:40 +00:00
|
|
|
#
|
2016-09-11 19:13:27 +00:00
|
|
|
installed.tag: built.tag
|
2018-01-18 12:54:03 +00:00
|
|
|
|
|
|
|
ifneq ($(INSTALL_TARGET),)
|
|
|
|
installed.tag:
|
2016-09-11 19:13:27 +00:00
|
|
|
@$(MSG_INST)$(TARGET)
|
|
|
|
$(VERBOSE)source env.sh && $(MAKE) $(MAKE_ENV) $(MAKE_VERBOSE) $(INSTALL_TARGET) DESTDIR=$(PWD)/install MAN= >> stdout.log 2>> stderr.log
|
|
|
|
@touch $@
|
2018-01-18 12:54:03 +00:00
|
|
|
endif
|
2016-09-11 19:13:27 +00:00
|
|
|
|
|
|
|
$(TARGET): installed.tag
|
|
|
|
@touch $@
|
|
|
|
|
2017-05-14 20:00:40 +00:00
|
|
|
#
|
|
|
|
# Trigger creation of symlinks to the build results at '<build-dir>/bin/'
|
|
|
|
#
|
|
|
|
ifneq ($(INSTALL_TAR_ARCHIVE),)
|
|
|
|
$(TARGET): installed_tar.tag
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(INSTALL_TREE),)
|
|
|
|
$(TARGET): installed_tree.tag
|
|
|
|
endif
|
|
|
|
|
|
|
|
#
|
|
|
|
# Install symlink to the install directory
|
|
|
|
#
|
|
|
|
installed_tree.tag: installed.tag
|
|
|
|
$(VERBOSE)rm -f $(INSTALL_DIR)/$(TARGET)
|
|
|
|
$(VERBOSE)ln -sf $(PWD)/install $(INSTALL_DIR)/$(TARGET)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Install symlink to the archived install directory, ready to by mounted
|
|
|
|
# via the VFS tar file system
|
|
|
|
#
|
|
|
|
installed_tar.tag: installed.tag
|
2017-12-08 20:01:58 +00:00
|
|
|
$(VERBOSE)tar cf $(TARGET).tar -h -C $(PWD)/install $(INSTALL_TAR_CONTENT)
|
2017-05-14 20:00:40 +00:00
|
|
|
$(VERBOSE)rm -f $(INSTALL_DIR)/$(TARGET)
|
|
|
|
$(VERBOSE)ln -sf $(PWD)/$(TARGET).tar $(INSTALL_DIR)/$(TARGET).tar
|
|
|
|
|
2016-09-11 19:13:27 +00:00
|
|
|
#
|
|
|
|
# The clean rule is expected to be executed within the 3rd-party build
|
|
|
|
# directory. The check should prevent serious damage if this condition
|
|
|
|
# is violated (e.g., while working on the build system).
|
|
|
|
#
|
|
|
|
ifeq ($(notdir $(PWD)),$(notdir $(PRG_DIR)))
|
|
|
|
clean_dir:
|
2017-05-14 20:00:40 +00:00
|
|
|
$(VERBOSE)find $(PWD) -mindepth 1 -delete
|
2016-09-11 19:13:27 +00:00
|
|
|
|
|
|
|
clean_prg_objects: clean_dir
|
|
|
|
endif
|