From 17bae066c68fe375464f13962d746d98eba67d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Wed, 5 Sep 2018 08:32:27 +0200 Subject: [PATCH 01/18] pthread: Make pthread_tls into a submodule --- Makefile.dep | 4 ++++ makefiles/pseudomodules.inc.mk | 1 + sys/posix/pthread/Makefile | 5 +++++ tests/pthread_tls/Makefile | 1 + 4 files changed, 11 insertions(+) diff --git a/Makefile.dep b/Makefile.dep index f89090bbb578..652487e88bcb 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -562,6 +562,10 @@ ifneq (,$(filter pthread,$(USEMODULE))) USEMODULE += timex endif +ifneq (,$(filter pthread_tls,$(USEMODULE))) + USEMODULE += pthread +endif + ifneq (,$(filter schedstatistics,$(USEMODULE))) USEMODULE += xtimer endif diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 6132f5b16d82..98b4d21a601f 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -58,6 +58,7 @@ PSEUDOMODULES += pktqueue PSEUDOMODULES += printf_float PSEUDOMODULES += prng PSEUDOMODULES += prng_% +PSEUDOMODULES += pthread_tls PSEUDOMODULES += riotboot_% PSEUDOMODULES += saul_adc PSEUDOMODULES += saul_default diff --git a/sys/posix/pthread/Makefile b/sys/posix/pthread/Makefile index 48422e909a47..c9aaa08d00fe 100644 --- a/sys/posix/pthread/Makefile +++ b/sys/posix/pthread/Makefile @@ -1 +1,6 @@ +# exclude pthread_tls if not selected explicitly +ifeq (,$(filter pthread_tls,$(USEMODULE))) + SRC := $(filter-out pthread_tls.c,$(wildcard *.c)) +endif + include $(RIOTBASE)/Makefile.base diff --git a/tests/pthread_tls/Makefile b/tests/pthread_tls/Makefile index 728b0c10f015..97e550307314 100644 --- a/tests/pthread_tls/Makefile +++ b/tests/pthread_tls/Makefile @@ -8,6 +8,7 @@ BOARD_BLACKLIST := arduino-mega2560 waspmote-pro arduino-uno arduino-duemilanove USEMODULE += posix USEMODULE += pthread +USEMODULE += pthread_tls TEST_ON_CI_WHITELIST += all From a7befdbd23eaea2f2a55dd72f0f9c076fb4b002b Mon Sep 17 00:00:00 2001 From: cladmi Date: Wed, 5 Sep 2018 13:31:11 +0200 Subject: [PATCH 02/18] cortexm_common: fix panic_arch not being linked The default weak symbol was used instead ( w): arm-none-eabi-objdump -t bin/samr21-xpro/hello-world.elf | grep 'panic_arch' 000006a0 w F .text 00000002 panic_arch With this commit it is actually used (g ): arm-none-eabi-objdump -t bin/samr21-xpro/hello-world.elf | grep 'panic_arch' 000000b8 g F .text 0000001c panic_arch --- cpu/cortexm_common/Makefile.include | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cpu/cortexm_common/Makefile.include b/cpu/cortexm_common/Makefile.include index f024eb56bf23..e45f002573bf 100644 --- a/cpu/cortexm_common/Makefile.include +++ b/cpu/cortexm_common/Makefile.include @@ -2,6 +2,9 @@ INCLUDES += -I$(RIOTCPU)/cortexm_common/include INCLUDES += -I$(RIOTCPU)/cortexm_common/include/vendor +# Explicitely tell the linker to link 'panic_arch' +UNDEF += $(BINDIR)/cortexm_common/panic.o + # All variables must be defined in the CPU configuration when using the common # `ldscripts/cortexm.ld` ifneq (,$(ROM_START_ADDR)$(RAM_START_ADDR)$(ROM_LEN)$(RAM_LEN)) From c6991d7ebbca53dcbc4967d184abcbfc29aacd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Wed, 14 Mar 2018 07:31:40 +0100 Subject: [PATCH 03/18] MANY TODOS: makefiles: introduce 'LIBS' makefiles/modules.inc.mk must be cleaned. There is no need for special 'PKGS' handling. Just find all real modules and define both Add variables names for '$(sort $(USEMODULE) $(USEPKG))' and build from this. Or just add "USEPKG" to USEMODULE at that moment. Should be removed later anyway. REALLIBS and something to describe modules that are not 'LIBS' This needs proper names and refactoring. I will do it outside. --- makefiles/modules.inc.mk | 15 ++++++++++++--- makefiles/vars.inc.mk | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/makefiles/modules.inc.mk b/makefiles/modules.inc.mk index 7dd0575b37ee..a25f72924556 100644 --- a/makefiles/modules.inc.mk +++ b/makefiles/modules.inc.mk @@ -2,9 +2,18 @@ ED = $(addprefix MODULE_,$(sort $(USEMODULE) $(USEPKG))) EXTDEFINES = $(addprefix -D,$(shell echo '$(ED)' | tr 'a-z-' 'A-Z_')) # filter "pseudomodules" from "real modules", but not "no_pseudomodules" -NO_PSEUDOMODULES := $(filter $(NO_PSEUDOMODULES), $(sort $(USEMODULE) $(USEPKG))) -REALMODULES = $(filter-out $(PSEUDOMODULES), $(sort $(USEMODULE) $(USEPKG))) $(NO_PSEUDOMODULES) -export BASELIBS += $(REALMODULES:%=$(BINDIR)/%.a) +REALMODULES = $(filter-out $(LIBS), \ + $(filter-out $(PSEUDOMODULES), $(USEMODULE)) \ + $(filter $(NO_PSEUDOMODULES), $(USEMODULE))) +REALPKGS = $(filter-out $(LIBS), \ + $(filter-out $(PSEUDOMODULES), $(USEPKG)) \ + $(filter $(NO_PSEUDOMODULES), $(USEPKG))) +REALARCHIVES = $(filter $(LIBS),$(USEMODULE) $(USEPKG)) +# filter out any duplicate object file names +BASELIBS += \ + $(shell printf %s '$(REALMODULES:%=$(BINDIR)/%.a) $(REALPKGS:%=$(BINDIR)/%.a)' | \ + tr ' ' '\n' | awk '!a[$$0]++') +BASELIBS += $(REALARCHIVES:%=$(BINDIR)/%.a) CFLAGS += $(EXTDEFINES) diff --git a/makefiles/vars.inc.mk b/makefiles/vars.inc.mk index bff4d74f52a1..36ab23a981b4 100644 --- a/makefiles/vars.inc.mk +++ b/makefiles/vars.inc.mk @@ -16,6 +16,7 @@ export CXXINCLUDES # The extra include paths for c++, set by the vario export USEMODULE # Sys Module dependencies of the application. Set in the application's Makefile. export USEPKG # Pkg dependencies (third party modules) of the application. Set in the application's Makefile. +# LIBS # Build a static archive instead of a single object file for the given modules. Set by the package's Makefile.include when necessary export DISABLE_MODULE # Used in the application's Makefile to suppress DEFAULT_MODULEs. export APPDEPS # Files / Makefile targets that need to be created before the application can be build. Set in the application's Makefile. # BUILDDEPS # Files / Makefile targets that need to be created before starting to build. From c0c9288b7a0c3251d76e9500d9f97971d72409e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Tue, 13 Mar 2018 13:27:17 +0100 Subject: [PATCH 04/18] pkg/nordic_softdevice_ble: define 'ble_6lowpan' as LIBS This will allow special handling as a library. --- pkg/nordic_softdevice_ble/Makefile.include | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/nordic_softdevice_ble/Makefile.include b/pkg/nordic_softdevice_ble/Makefile.include index a06b35192af6..4341b83be56b 100644 --- a/pkg/nordic_softdevice_ble/Makefile.include +++ b/pkg/nordic_softdevice_ble/Makefile.include @@ -26,6 +26,9 @@ CFLAGS += -Wno-pedantic -Wno-unused-parameter -Wno-sign-compare # so set this, otherwise linking fails CFLAGS_FPU := -mfloat-abi=hard -mfpu=fpv4-sp-d16 +# ble_6lowpan.a is provided as a binary-only library within the softdevice package +LIBS += ble_6lowpan + DIRS += \ $(RIOTBASE)/pkg/nordic_softdevice_ble/src \ $(NORDIC_SRCS)/components/softdevice/common/softdevice_handler \ From ddb5d87522bb0bdafe7d289d9e813357edefbf73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Wed, 14 Mar 2018 08:54:16 +0100 Subject: [PATCH 05/18] pkg/jerryscript: define jerryscript modules as LIBS This will allow special handling as a library. --- pkg/jerryscript/Makefile.include | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/jerryscript/Makefile.include b/pkg/jerryscript/Makefile.include index fdf28101d478..87411b9e9d02 100644 --- a/pkg/jerryscript/Makefile.include +++ b/pkg/jerryscript/Makefile.include @@ -1,2 +1,7 @@ INCLUDES += -I$(PKGDIRBASE)/jerryscript/jerry-core/include INCLUDES += -I$(PKGDIRBASE)/jerryscript/jerry-ext/include + +# the jerryscript build produces static archives +LIBS += jerryscript +LIBS += jerryscript-ext +LIBS += jerryport-minimal From 2ee9d0b851598d4cc81a14ef6656a1f104384d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Wed, 14 Mar 2018 09:20:55 +0100 Subject: [PATCH 06/18] pkg/ccn-lite: define 'ccn-lite' as LIBS This will allow special handling as a library. --- pkg/ccn-lite/Makefile.include | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/ccn-lite/Makefile.include b/pkg/ccn-lite/Makefile.include index a91eba997aa0..e0ac5b0a8aa4 100644 --- a/pkg/ccn-lite/Makefile.include +++ b/pkg/ccn-lite/Makefile.include @@ -5,3 +5,4 @@ INCLUDES += -I$(PKGDIRBASE)/ccn-lite/src/ccnl-fwd/include INCLUDES += -I$(RIOTBASE)/sys/posix/include CFLAGS += -DCCNL_RIOT +LIBS += ccn-lite From 4eaf7cd3cabea1e61c739e0fbbcf187c79699565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Tue, 15 May 2018 13:26:40 +0200 Subject: [PATCH 07/18] pkg/relic: define 'relic' module as LIBS This will allow special handling as a library. --- pkg/relic/Makefile.include | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/relic/Makefile.include b/pkg/relic/Makefile.include index 5dc828d0ec28..80c149464ef9 100644 --- a/pkg/relic/Makefile.include +++ b/pkg/relic/Makefile.include @@ -1,5 +1,7 @@ INCLUDES += -I$(PKGDIRBASE)/relic/include +LIBS += relic + ifneq (,$(filter cortex-m%,$(CPU_ARCH))) # relic package package is not using system includes right now, so # many newlib headers (not even stdio.h) are not found. From b4afd667b9505afc242d978d47305bbadfc5ecfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Wed, 16 May 2018 01:23:44 +0200 Subject: [PATCH 08/18] pkg/openthread: define openthread modules as LIBS This will allow special handling as a library. --- pkg/openthread/Makefile.include | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/openthread/Makefile.include b/pkg/openthread/Makefile.include index d399a8f90253..8cdbc7610078 100644 --- a/pkg/openthread/Makefile.include +++ b/pkg/openthread/Makefile.include @@ -8,6 +8,10 @@ ifneq (,$(filter openthread_contrib,$(USEMODULE))) DIRS += $(OPENTHREAD_DIR)/contrib/netdev endif +LIBS += libmbedcrypto +LIBS += libopenthread +LIBS += libopenthread-cli + ifneq (,$(filter cortex-m0% cortex-m3%,$(CPU_ARCH))) # There are problem with unused `-mcpu...` arguments in clang and with # ranlib + LLVM/clang in this package with Cortex-M0 and M3 From 86d5f31bc42f3128a9a4da5ffd012ea4bbbe22ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Wed, 14 Mar 2018 07:09:46 +0100 Subject: [PATCH 09/18] TODO I DO NOT KNOW WHY THIS IS REQUIRED APART FROM 'LIBS += oonf_api' pkg/oonf_api: Update build to use ld -r for submodules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also using '$(BINDIR)/oonf_*.a as a dependency' is wrong… This commit should be this at the end with a commit with prerequisites to fix issues. pkg/oonf_api: define 'oonf_api' as LIBS This will allow special handling as a library. --- makefiles/pseudomodules.inc.mk | 4 ++++ pkg/oonf_api/Makefile | 4 ---- pkg/oonf_api/Makefile.include | 2 ++ .../patches/0001-add-RIOT-support.patch | 19 +++++++++---------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 98b4d21a601f..bea8e8a403f5 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -140,4 +140,8 @@ PSEUDOMODULES += crypto_aes_precalculated # This pseudomodule causes a loop in AES to be unrolled (more flash, less CPU) PSEUDOMODULES += crypto_aes_unroll +# declare oonf submodules as pseudomodules, but exclude oonf_api +PSEUDOMODULES += oonf_% +NO_PSEUDOMODULES += oonf_api + # Packages may also add modules to PSEUDOMODULES in their `Makefile.include`. diff --git a/pkg/oonf_api/Makefile b/pkg/oonf_api/Makefile index 09e0bcca5e4c..3d978a055dfa 100644 --- a/pkg/oonf_api/Makefile +++ b/pkg/oonf_api/Makefile @@ -12,10 +12,6 @@ CFLAGS += -Wno-implicit-fallthrough all: git-download "$(MAKE)" -C $(PKG_BUILDDIR) - "$(MAKE)" $(BINDIR)/$(MODULE).a - -$(BINDIR)/$(MODULE).a: $(BINDIR)/oonf_*.a - mkdir -p $(BINDIR)/$(MODULE); cd $(BINDIR)/$(MODULE); for var in $?; do ar -x $$var; done; ar -r -c -s $(BINDIR)/$(MODULE).a *.o include $(RIOTBASE)/pkg/pkg.mk ifneq (,$(filter -Wformat-nonliteral -Wformat=2, $(CFLAGS))) diff --git a/pkg/oonf_api/Makefile.include b/pkg/oonf_api/Makefile.include index ec6be727f0ef..5ee0c0ec0609 100644 --- a/pkg/oonf_api/Makefile.include +++ b/pkg/oonf_api/Makefile.include @@ -3,3 +3,5 @@ INCLUDES += -I$(PKGDIRBASE)/oonf_api/src-api ifeq ($(TOOLCHAIN), llvm) CFLAGS += -Wno-keyword-macro -Wno-parentheses-equality endif + +LIBS += oonf_api diff --git a/pkg/oonf_api/patches/0001-add-RIOT-support.patch b/pkg/oonf_api/patches/0001-add-RIOT-support.patch index e8ec40831b77..572a8250aece 100644 --- a/pkg/oonf_api/patches/0001-add-RIOT-support.patch +++ b/pkg/oonf_api/patches/0001-add-RIOT-support.patch @@ -26,7 +26,7 @@ new file mode 100644 index 0000000..1f1cd9c --- /dev/null +++ b/Makefile -@@ -0,0 +1,29 @@ +@@ -0,0 +1,28 @@ +# +# to use oonf_api in your RIOT project, +# add the following to your Makefile: @@ -50,19 +50,18 @@ index 0000000..1f1cd9c +ifneq (,$(filter oonf_regex,$(USEMODULE))) + DIRS += external/regex +endif -+ -+all: -+ mkdir -p $(BINDIR) -+ @for i in $(DIRS) ; do $(MAKE) -C $$i || exit 1; done ; -+ -+clean: ++include $(RIOTBASE)/Makefile.base ++# Build static archive from the submodule objects ++all: $(BINDIR)/$(MODULE).a ++$(patsubst %,$(BINDIR)/%.o,$(filter oonf_%,$(USEMODULE))): | ${DIRS:%=ALL--%} ++$(BINDIR)/$(MODULE).a: $(patsubst %,$(BINDIR)/%.o,$(filter oonf_%,$(USEMODULE))) | ${DIRS:%=ALL--%} diff --git a/external/regex/Makefile b/external/regex/Makefile new file mode 100644 index 0000000..3bc1ce1 --- /dev/null +++ b/external/regex/Makefile @@ -0,0 +1,4 @@ -+MODULE:=oonf_$(shell basename $(CURDIR)) ++MODULE:=oonf_$(notdir $(CURDIR)) +INCLUDES += $(CURDIR)/.. + +include $(RIOTBASE)/Makefile.base @@ -72,7 +71,7 @@ index 0000000..5e0046d --- /dev/null +++ b/src-api/common/Makefile @@ -0,0 +1,3 @@ -+MODULE:=oonf_$(shell basename $(CURDIR)) ++MODULE:=oonf_$(notdir $(CURDIR)) + +include $(RIOTBASE)/Makefile.base diff --git a/src-api/common/autobuf.c b/src-api/common/autobuf.c @@ -188,7 +187,7 @@ index 0000000..5e0046d --- /dev/null +++ b/src-api/rfc5444/Makefile @@ -0,0 +1,3 @@ -+MODULE:=oonf_$(shell basename $(CURDIR)) ++MODULE:=oonf_$(notdir $(CURDIR)) + +include $(RIOTBASE)/Makefile.base diff --git a/src-api/rfc5444/rfc5444_api_config.h b/src-api/rfc5444/rfc5444_api_config.h From 43f9a43914e4870a829bde7b2ba908a8c764b6a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Wed, 16 May 2018 01:23:44 +0200 Subject: [PATCH 10/18] pkg/openthread: do not pass RIOT 'LIBS' to openthread build It is only needed to overwrite it if `LIBS` is exported in the build system. But resetting it anyway does not hurt. Could be removed if `LIBS` is not exported. --- pkg/openthread/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/openthread/Makefile b/pkg/openthread/Makefile index 863c1af35915..aa741a36533d 100644 --- a/pkg/openthread/Makefile +++ b/pkg/openthread/Makefile @@ -22,7 +22,7 @@ OPENTHREAD_COMMON_FLAGS += -Wno-implicit-fallthrough -Wno-unused-parameter all: git-download cd $(PKG_BUILDDIR) && PREFIX="/" ./bootstrap - cd $(PKG_BUILDDIR) && CPP="$(CPP)" CC="$(CC)" CXX="$(CXX)"\ + cd $(PKG_BUILDDIR) && LIBS="" CPP="$(CPP)" CC="$(CC)" CXX="$(CXX)"\ OBJC="" OBJCXX="" AR="$(AR)" RANLIB="$(RANLIB)" NM="$(NM)" \ STRIP="$(STRIP)" \ CPPFLAGS="$(OPENTHREAD_COMMON_FLAGS) $(CFLAGS_CPU) -D$(CONFIG_FILE)" \ @@ -31,7 +31,7 @@ all: git-download LDFLAGS="$(OPENTHREAD_COMMON_FLAGS) $(CFLAGS_CPU) -nostartfiles -specs=nano.specs \ -specs=nosys.specs -Wl,--gc-sections -Wl,-Map=map.map " \ ./configure --disable-docs --host=$(TARGET_ARCH) --target=$(TARGET_ARCH) \ - --prefix=/ --enable-default-logging $(OPENTHREAD_ARGS) + --prefix=/ $(OPENTHREAD_ARGS) cd $(PKG_BUILDDIR) && DESTDIR=$(PKG_BUILDDIR)/output PREFIX=/ make -j4 --no-print-directory install cp $(PKG_BUILDDIR)/output/lib/libmbedcrypto.a ${BINDIR}/mbedcrypto.a From 95e8559bd286892a47baabb18dcb0f4acaacb8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Tue, 5 Mar 2019 14:49:20 +0100 Subject: [PATCH 11/18] make: Use incremental link for modules --- Makefile.base | 11 +++++++++++ Makefile.include | 16 ++++++++-------- makefiles/bindist.inc.mk | 2 +- makefiles/modules.inc.mk | 3 ++- makefiles/toolchain/gnu.inc.mk | 1 + makefiles/toolchain/llvm.inc.mk | 1 + makefiles/vars.inc.mk | 2 +- tests/unittests/Makefile | 2 +- 8 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Makefile.base b/Makefile.base index 5174119c0978..7712656680e8 100644 --- a/Makefile.base +++ b/Makefile.base @@ -9,7 +9,13 @@ MODULE ?= $(shell basename $(CURDIR)) .PHONY: all clean $(DIRS:%=ALL--%) $(DIRS:%=CLEAN--%) +# Build a static library if the current module is listed in LIBS +ifneq (,$(filter $(MODULE),$(LIBS))) all: $(BINDIR)/$(MODULE).a ..nothing +else +# .. otherwise, build a monolithic object file +all: $(BINDIR)/$(MODULE).o ..nothing +endif ..nothing: @: @@ -65,6 +71,11 @@ DEP := $(OBJC:.o=.d) $(OBJCXX:.o=.d) $(ASSMOBJ:.o=.d) $(BINDIR)/$(MODULE)/: $(Q)mkdir -p $@ +$(BINDIR)/$(MODULE).o $(OBJ): | $(BINDIR)/$(MODULE)/ + +$(BINDIR)/$(MODULE).o: $(OBJ) | ${DIRS:%=ALL--%} + $(Q)[ -z '$^' ] || $(LD) -r -o $@ $^ + $(BINDIR)/$(MODULE).a $(OBJ): | $(BINDIR)/$(MODULE)/ $(BINDIR)/$(MODULE).a: $(OBJ) | $(DIRS:%=ALL--%) diff --git a/Makefile.include b/Makefile.include index 9c45a7440fd0..163ad617b287 100644 --- a/Makefile.include +++ b/Makefile.include @@ -348,7 +348,7 @@ endif APPLICATION_MODULE ?= application_$(APPLICATION) # the binaries to link -BASELIBS += $(BINDIR)/$(APPLICATION_MODULE).a +BASELIBS += $(BINDIR)/$(APPLICATION_MODULE).o BASELIBS += $(APPDEPS) @@ -437,9 +437,9 @@ _BASELIBS_VALUE_BEFORE_USAGE := $(BASELIBS) # Linker rule $(ELFFILE): FORCE ifeq ($(BUILDOSXNATIVE),1) - _LINK = $(if $(CPPMIX),$(LINKXX),$(LINK)) $(UNDEF) $$(find $(BASELIBS) -size +8c) $(LINKFLAGS) $(LINKFLAGPREFIX)-no_pie + _LINK = $(if $(CPPMIX),$(LINKXX),$(LINK)) $$(find $(BASELIBS) -size +8c) $(LINKFLAGS) $(LINKFLAGPREFIX)-no_pie else - _LINK = $(if $(CPPMIX),$(LINKXX),$(LINK)) $(UNDEF) $(LINKFLAGPREFIX)--start-group $(BASELIBS) -lm $(LINKFLAGPREFIX)--end-group $(LINKFLAGS) $(LINKFLAGPREFIX)-Map=$(BINDIR)/$(APPLICATION).map + _LINK = $(if $(CPPMIX),$(LINKXX),$(LINK)) $(LINKFLAGPREFIX)--start-group $(BASELIBS) -lm $(LINKFLAGPREFIX)--end-group $(LINKFLAGS) $(LINKFLAGPREFIX)-Map=$(BINDIR)/$(APPLICATION).map endif # BUILDOSXNATIVE # include bootloaders support. When trying to overwrite one variable @@ -459,13 +459,13 @@ endif # RIOTNOLINK $(ELFFILE): $(BASELIBS) $(Q)$(_LINK) -o $@ -$(BINDIR)/$(APPLICATION_MODULE).a: pkg-build $(BUILDDEPS) +$(BINDIR)/$(APPLICATION_MODULE).o: pkg-build $(BUILDDEPS) $(Q)DIRS="$(DIRS)" "$(MAKE)" -C $(APPDIR) -f $(RIOTMAKE)/application.inc.mk -$(BINDIR)/$(APPLICATION_MODULE).a: FORCE +$(BINDIR)/$(APPLICATION_MODULE).o: FORCE # Other modules are built by application.inc.mk and packages building -_SUBMAKE_LIBS = $(filter-out $(BINDIR)/$(APPLICATION_MODULE).a $(APPDEPS), $(BASELIBS)) -$(_SUBMAKE_LIBS): $(BINDIR)/$(APPLICATION_MODULE).a pkg-build +_SUBMAKE_LIBS = $(filter-out $(BINDIR)/$(APPLICATION_MODULE).o $(APPDEPS), $(BASELIBS)) +$(_SUBMAKE_LIBS): $(BINDIR)/$(APPLICATION_MODULE).o pkg-build # 'print-size' triggers a rebuild. Use 'info-buildsize' if you do not need to rebuild. print-size: $(ELFFILE) @@ -516,7 +516,7 @@ clean: # Remove intermediates, but keep the .elf, .hex and .map etc. clean-intermediates: -@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTPKG)/$$i distclean ; done - -@rm -rf $(BINDIR)/*.a $(BINDIR)/*/ + -@rm -rf $(BINDIR)/*.o $(BINDIR)/*.a $(BINDIR)/*/ clean-pkg: -@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTPKG)/$$i distclean ; done diff --git a/makefiles/bindist.inc.mk b/makefiles/bindist.inc.mk index b8b8510e61bf..b695b06e4f45 100644 --- a/makefiles/bindist.inc.mk +++ b/makefiles/bindist.inc.mk @@ -1,7 +1,7 @@ # Avoid including APPLICATION_MODULE twice to prevent multiple definition errors USEMODULE += $(filter-out $(APPLICATION_MODULE),$(BIN_USEMODULE)) -DIST_FILES += $(BIN_USEMODULE:%=bin/$(BOARD)/%.a) +DIST_FILES += $(BIN_USEMODULE:%=bin/$(BOARD)/%.o) # if the file Makefile.distcheck exists, we're executing from within a folder # generated by "make bindist". diff --git a/makefiles/modules.inc.mk b/makefiles/modules.inc.mk index a25f72924556..ba713f82005b 100644 --- a/makefiles/modules.inc.mk +++ b/makefiles/modules.inc.mk @@ -2,6 +2,7 @@ ED = $(addprefix MODULE_,$(sort $(USEMODULE) $(USEPKG))) EXTDEFINES = $(addprefix -D,$(shell echo '$(ED)' | tr 'a-z-' 'A-Z_')) # filter "pseudomodules" from "real modules", but not "no_pseudomodules" +# any module listed in LIBS will be used as a .a file instead of .o REALMODULES = $(filter-out $(LIBS), \ $(filter-out $(PSEUDOMODULES), $(USEMODULE)) \ $(filter $(NO_PSEUDOMODULES), $(USEMODULE))) @@ -11,7 +12,7 @@ REALPKGS = $(filter-out $(LIBS), \ REALARCHIVES = $(filter $(LIBS),$(USEMODULE) $(USEPKG)) # filter out any duplicate object file names BASELIBS += \ - $(shell printf %s '$(REALMODULES:%=$(BINDIR)/%.a) $(REALPKGS:%=$(BINDIR)/%.a)' | \ + $(shell printf %s '$(REALMODULES:%=$(BINDIR)/%.o) $(REALPKGS:%=$(BINDIR)/%.o)' | \ tr ' ' '\n' | awk '!a[$$0]++') BASELIBS += $(REALARCHIVES:%=$(BINDIR)/%.a) diff --git a/makefiles/toolchain/gnu.inc.mk b/makefiles/toolchain/gnu.inc.mk index a65d433c7da7..16d495c0dbcb 100644 --- a/makefiles/toolchain/gnu.inc.mk +++ b/makefiles/toolchain/gnu.inc.mk @@ -10,6 +10,7 @@ export RANLIB = $(PREFIX)ranlib endif export AS = $(PREFIX)as export NM = $(PREFIX)nm +export LD = $(PREFIX)ld export LINK = $(PREFIX)gcc export LINKXX = $(PREFIX)g++ export SIZE = $(PREFIX)size diff --git a/makefiles/toolchain/llvm.inc.mk b/makefiles/toolchain/llvm.inc.mk index f005ca7092ad..c39964bf1173 100644 --- a/makefiles/toolchain/llvm.inc.mk +++ b/makefiles/toolchain/llvm.inc.mk @@ -16,6 +16,7 @@ export NM = $(LLVMPREFIX)nm # compatible with GCC. For instance spec files as used in # `makefiles/libc/newlib.mk` are not supported. Therefore # we just use GCC for now. +export LD = $(PREFIX)ld export LINK = $(PREFIX)gcc export LINKXX = $(PREFIX)g++ # objcopy does not have a clear substitute in LLVM, use GNU binutils diff --git a/makefiles/vars.inc.mk b/makefiles/vars.inc.mk index 36ab23a981b4..c2cb43a133f8 100644 --- a/makefiles/vars.inc.mk +++ b/makefiles/vars.inc.mk @@ -16,7 +16,7 @@ export CXXINCLUDES # The extra include paths for c++, set by the vario export USEMODULE # Sys Module dependencies of the application. Set in the application's Makefile. export USEPKG # Pkg dependencies (third party modules) of the application. Set in the application's Makefile. -# LIBS # Build a static archive instead of a single object file for the given modules. Set by the package's Makefile.include when necessary +export LIBS # Build a static archive instead of a single object file for the given modules. Set by the package's Makefile.include when necessary export DISABLE_MODULE # Used in the application's Makefile to suppress DEFAULT_MODULEs. export APPDEPS # Files / Makefile targets that need to be created before the application can be build. Set in the application's Makefile. # BUILDDEPS # Files / Makefile targets that need to be created before starting to build. diff --git a/tests/unittests/Makefile b/tests/unittests/Makefile index 87ce8102c85d..33fb2c9c3c10 100644 --- a/tests/unittests/Makefile +++ b/tests/unittests/Makefile @@ -249,7 +249,7 @@ DISABLE_MODULE += auto_init -include $(UNIT_TESTS:%=$(RIOTBASE)/tests/unittests/%/Makefile.include) DIRS += $(UNIT_TESTS) -BASELIBS += $(UNIT_TESTS:%=$(BINDIR)/%.a) +BASELIBS += $(UNIT_TESTS:%=$(BINDIR)/%.o) INCLUDES += -I$(RIOTBASE)/tests/unittests/common From b61ecae1b54b08cc404d0c9086fb704b074cfa39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Thu, 1 Mar 2018 14:07:41 +0100 Subject: [PATCH 12/18] make: Remove UNDEF --- boards/common/msba2/Makefile.include | 2 -- boards/native/Makefile.include | 2 -- cpu/cortexm_common/Makefile.include | 3 --- cpu/efm32/Makefile.include | 3 --- cpu/kinetis/Makefile.include | 3 --- cpu/msp430_common/Makefile.include | 1 - makefiles/arch/atmega.inc.mk | 4 ---- makefiles/arch/cortexm.inc.mk | 7 ------- makefiles/docker.inc.mk | 1 - makefiles/scan-build.inc.mk | 1 - makefiles/vars.inc.mk | 1 - sys/Makefile.include | 7 ------- sys/newlib_syscalls_default/Makefile.include | 1 - 13 files changed, 36 deletions(-) delete mode 100644 sys/newlib_syscalls_default/Makefile.include diff --git a/boards/common/msba2/Makefile.include b/boards/common/msba2/Makefile.include index db624de2b4ed..a3515e739df2 100644 --- a/boards/common/msba2/Makefile.include +++ b/boards/common/msba2/Makefile.include @@ -28,5 +28,3 @@ USEMODULE += newlib_nano FFLAGS = $(PORT) $(HEXFILE) INCLUDES += -I$(RIOTBOARD)/common/msba2/include - -export UNDEF += $(BINDIR)/cpu/startup.o diff --git a/boards/native/Makefile.include b/boards/native/Makefile.include index 974effb34116..43908d8158b9 100644 --- a/boards/native/Makefile.include +++ b/boards/native/Makefile.include @@ -187,5 +187,3 @@ eval-gprof: eval-cachegrind: $(CGANNOTATE) $(shell ls -rt cachegrind.out* | tail -1) - -export UNDEF += $(BINDIR)/cpu/startup.o diff --git a/cpu/cortexm_common/Makefile.include b/cpu/cortexm_common/Makefile.include index e45f002573bf..f024eb56bf23 100644 --- a/cpu/cortexm_common/Makefile.include +++ b/cpu/cortexm_common/Makefile.include @@ -2,9 +2,6 @@ INCLUDES += -I$(RIOTCPU)/cortexm_common/include INCLUDES += -I$(RIOTCPU)/cortexm_common/include/vendor -# Explicitely tell the linker to link 'panic_arch' -UNDEF += $(BINDIR)/cortexm_common/panic.o - # All variables must be defined in the CPU configuration when using the common # `ldscripts/cortexm.ld` ifneq (,$(ROM_START_ADDR)$(RAM_START_ADDR)$(ROM_LEN)$(RAM_LEN)) diff --git a/cpu/efm32/Makefile.include b/cpu/efm32/Makefile.include index de69fa6fb721..1616f6fbd684 100644 --- a/cpu/efm32/Makefile.include +++ b/cpu/efm32/Makefile.include @@ -17,9 +17,6 @@ endif # include CPU family module USEMODULE += cpu_$(EFM32_FAMILY) -# vectors.o is provided by 'cpu_$(EFM32_FAMILY)' and not by 'cpu' -VECTORS_O := $(BINDIR)/cpu_$(EFM32_FAMILY)/vectors.o - # include common periph module USEMODULE += periph_common diff --git a/cpu/kinetis/Makefile.include b/cpu/kinetis/Makefile.include index a5f36b4ed0b3..de390d39e432 100644 --- a/cpu/kinetis/Makefile.include +++ b/cpu/kinetis/Makefile.include @@ -30,9 +30,6 @@ LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_ram_start_addr=$(RAM_START_ADDR) LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_rom_length=$(ROM_LEN) LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_ram_length=$(RAM_LEN) -# add the CPU specific flash configuration field for the linker -export UNDEF += $(BINDIR)/cpu/fcfield.o - # include common periph drivers USEMODULE += periph_common diff --git a/cpu/msp430_common/Makefile.include b/cpu/msp430_common/Makefile.include index ab6e0cf8c0d3..472b3b41e4b5 100644 --- a/cpu/msp430_common/Makefile.include +++ b/cpu/msp430_common/Makefile.include @@ -4,7 +4,6 @@ INCLUDES += -I$(RIOTCPU)/msp430_common/include/ MODEL = $(shell echo $(CPU_MODEL) | tr 'a-z' 'A-Z') export CFLAGS += -DCPU_MODEL_$(MODEL) -export UNDEF += $(BINDIR)/msp430_common/startup.o export USEMODULE += msp430_common msp430_common_periph periph_common DEFAULT_MODULE += oneway_malloc diff --git a/makefiles/arch/atmega.inc.mk b/makefiles/arch/atmega.inc.mk index b45178e3016b..86fadfaf5f29 100644 --- a/makefiles/arch/atmega.inc.mk +++ b/makefiles/arch/atmega.inc.mk @@ -27,10 +27,6 @@ endif # the atmel port uses stdio_uart USEMODULE += stdio_uart -# explicitly tell the linker to link the syscalls and startup code. -# without this the interrupt vectors will not be linked correctly! -UNDEF += $(BINDIR)/atmega_common/startup.o - # Use ROM_LEN and RAM_LEN during link $(if $(ROM_LEN),,$(error ROM_LEN is not defined)) $(if $(RAM_LEN),,$(error RAM_LEN is not defined)) diff --git a/makefiles/arch/cortexm.inc.mk b/makefiles/arch/cortexm.inc.mk index 0416869b9086..8418844bb0eb 100644 --- a/makefiles/arch/cortexm.inc.mk +++ b/makefiles/arch/cortexm.inc.mk @@ -133,13 +133,6 @@ export CFLAGS += -DARM_MATH_CM23 endif endif -# Explicitly tell the linker to link the startup code. -# Without this the interrupt vectors will not be linked correctly! -VECTORS_O ?= $(BINDIR)/cpu/vectors.o -ifeq ($(COMMON_STARTUP),) -export UNDEF += $(VECTORS_O) -endif - # CPU depends on the cortex-m common module, so include it: include $(RIOTCPU)/cortexm_common/Makefile.include diff --git a/makefiles/docker.inc.mk b/makefiles/docker.inc.mk index 058e62363286..222684eee398 100644 --- a/makefiles/docker.inc.mk +++ b/makefiles/docker.inc.mk @@ -60,7 +60,6 @@ export DOCKER_ENV_VARS = \ SCANBUILD_OUTPUTDIR \ SIZE \ TOOLCHAIN \ - UNDEF \ # # Find which variables were set using the command line or the environment and diff --git a/makefiles/scan-build.inc.mk b/makefiles/scan-build.inc.mk index 9fcf881b0d18..2566240b4b9a 100644 --- a/makefiles/scan-build.inc.mk +++ b/makefiles/scan-build.inc.mk @@ -32,7 +32,6 @@ SCANBUILD_ENV_VARS := \ RIOT_CI_BUILD \ SIZE \ TOOLCHAIN \ - UNDEF \ USER \ # diff --git a/makefiles/vars.inc.mk b/makefiles/vars.inc.mk index c2cb43a133f8..062256efe9a8 100644 --- a/makefiles/vars.inc.mk +++ b/makefiles/vars.inc.mk @@ -65,7 +65,6 @@ export OBJDUMP # The command used to create the assembly listing. export OBJDUMPFLAGS # The parameter for OBJDUMP. export SIZE # The command to read to size of the ELF sections. export SIZEFLAGS # The optional size flags. -export UNDEF # Object files that the linker must include in the ELFFILE even if no call to the functions or symbols (ex: interrupt vectors). export WERROR # Treat all compiler warnings as errors if set to 1 (see -Werror flag in GCC manual) export GITCACHE # path to git-cache executable diff --git a/sys/Makefile.include b/sys/Makefile.include index b87126c5388f..7f86d90d5311 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -37,9 +37,6 @@ endif ifneq (,$(filter cpp11-compat,$(USEMODULE))) USEMODULE_INCLUDES += $(RIOTBASE)/sys/cpp11-compat/include - # make sure cppsupport.o is linked explicitly because __dso_handle is not - # found if it is hidden away inside a static object. - export UNDEF += $(BINDIR)/cpp11-compat/cppsupport.o endif ifneq (,$(filter embunit,$(USEMODULE))) @@ -64,10 +61,6 @@ ifneq (,$(filter newlib,$(USEMODULE))) include $(RIOTMAKE)/libc/newlib.mk endif -ifneq (,$(filter newlib_syscalls_default,$(USEMODULE))) - include $(RIOTBASE)/sys/newlib_syscalls_default/Makefile.include -endif - ifneq (,$(filter arduino,$(USEMODULE))) include $(RIOTBASE)/sys/arduino/Makefile.include endif diff --git a/sys/newlib_syscalls_default/Makefile.include b/sys/newlib_syscalls_default/Makefile.include deleted file mode 100644 index 419a6feddc87..000000000000 --- a/sys/newlib_syscalls_default/Makefile.include +++ /dev/null @@ -1 +0,0 @@ -UNDEF += $(BINDIR)/newlib_syscalls_default/syscalls.o From b30509464e5eb1cb4dcb00b5a4f3746151264f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Thu, 1 Mar 2018 14:08:21 +0100 Subject: [PATCH 13/18] squash introduce ILINK, ILINKFLAGS --- Makefile.base | 11 +++++++++-- boards/native/Makefile.include | 1 + cpu/atmega1281/Makefile.include | 3 +++ cpu/atmega1284p/Makefile.include | 3 +++ cpu/atmega2560/Makefile.include | 3 +++ cpu/atmega256rfr2/Makefile.include | 3 +++ cpu/atmega328p/Makefile.include | 3 +++ makefiles/arch/atmega.inc.mk | 3 +++ makefiles/toolchain/gnu.inc.mk | 2 ++ makefiles/toolchain/llvm.inc.mk | 2 ++ makefiles/vars.inc.mk | 2 ++ 11 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Makefile.base b/Makefile.base index 7712656680e8..e70ea91852a7 100644 --- a/Makefile.base +++ b/Makefile.base @@ -73,8 +73,15 @@ $(BINDIR)/$(MODULE)/: $(BINDIR)/$(MODULE).o $(OBJ): | $(BINDIR)/$(MODULE)/ -$(BINDIR)/$(MODULE).o: $(OBJ) | ${DIRS:%=ALL--%} - $(Q)[ -z '$^' ] || $(LD) -r -o $@ $^ +# An empty object file is included in the link to avoid situations where modules +# do not provide any code (e.g. sys, some boards), causing the build to fail +# with a missing object file. +EMPTYOBJ = $(BINDIR)/$(MODULE)/.empty.o +$(EMPTYOBJ): | $(BINDIR)/$(MODULE)/ + $(Q)$(CC) $(CFLAGS) -Wno-pedantic -xc -o $@ -c - < /dev/null + +$(BINDIR)/$(MODULE).o: $(OBJ) $(EMPTYOBJ) | ${DIRS:%=ALL--%} + $(Q)$(ILINK) $(ILINKFLAGS) -o $@ $^ $(BINDIR)/$(MODULE).a $(OBJ): | $(BINDIR)/$(MODULE)/ diff --git a/boards/native/Makefile.include b/boards/native/Makefile.include index 43908d8158b9..767cd55cb029 100644 --- a/boards/native/Makefile.include +++ b/boards/native/Makefile.include @@ -74,6 +74,7 @@ export CXXEXFLAGS += ifeq ($(shell uname -m),x86_64) export LINKFLAGS += -m32 + export ILINKFLAGS += -r -m elf_i386 --unique endif ifeq ($(shell uname -s),FreeBSD) ifeq ($(shell uname -m),amd64) diff --git a/cpu/atmega1281/Makefile.include b/cpu/atmega1281/Makefile.include index 66add33aaaf2..a945a0f33aae 100644 --- a/cpu/atmega1281/Makefile.include +++ b/cpu/atmega1281/Makefile.include @@ -1,6 +1,9 @@ # tell the build system that the CPU depends on the atmega common files USEMODULE += atmega_common +# CPU family, see https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html +export CPU_FAM = avr51 + RAM_LEN = 8K ROM_LEN = 128K diff --git a/cpu/atmega1284p/Makefile.include b/cpu/atmega1284p/Makefile.include index 985d14cf9e42..d7ea3fddcf71 100644 --- a/cpu/atmega1284p/Makefile.include +++ b/cpu/atmega1284p/Makefile.include @@ -1,6 +1,9 @@ # tell the build system that the CPU depends on the atmega common files USEMODULE += atmega_common +# CPU family, see https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html +export CPU_FAM = avr51 + RAM_LEN = 16K ROM_LEN = 128K diff --git a/cpu/atmega2560/Makefile.include b/cpu/atmega2560/Makefile.include index 16c500d37cc6..59e62f9214c0 100644 --- a/cpu/atmega2560/Makefile.include +++ b/cpu/atmega2560/Makefile.include @@ -1,6 +1,9 @@ # tell the build system that the CPU depends on the atmega common files USEMODULE += atmega_common +# CPU family, see https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html +export CPU_FAM = avr6 + RAM_LEN = 8K ROM_LEN = 256K diff --git a/cpu/atmega256rfr2/Makefile.include b/cpu/atmega256rfr2/Makefile.include index c7e4d680eaeb..376cfac9d403 100644 --- a/cpu/atmega256rfr2/Makefile.include +++ b/cpu/atmega256rfr2/Makefile.include @@ -1,6 +1,9 @@ # tell the build system that the CPU depends on the atmega common files USEMODULE += atmega_common +# CPU family, see https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html +export CPU_FAM = avr6 + #include periph module USEMODULE += periph diff --git a/cpu/atmega328p/Makefile.include b/cpu/atmega328p/Makefile.include index 20119203dd60..736b3713de5b 100644 --- a/cpu/atmega328p/Makefile.include +++ b/cpu/atmega328p/Makefile.include @@ -1,6 +1,9 @@ # tell the build system that the CPU depends on the atmega common files USEMODULE += atmega_common +# CPU family, see https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html +export CPU_FAM = avr5 + RAM_LEN = 2K ROM_LEN = 32K diff --git a/makefiles/arch/atmega.inc.mk b/makefiles/arch/atmega.inc.mk index 86fadfaf5f29..dea44ad1d348 100644 --- a/makefiles/arch/atmega.inc.mk +++ b/makefiles/arch/atmega.inc.mk @@ -8,6 +8,9 @@ CFLAGS_OPT ?= -Os CFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT) ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) +# See https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html for information on +# which CPU_FAM corresponds to your CPU +ILINKFLAGS += -r -m $(CPU_FAM) --unique LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) -static -lgcc -e reset_handler -Wl,--gc-sections OFLAGS += -j .text -j .data diff --git a/makefiles/toolchain/gnu.inc.mk b/makefiles/toolchain/gnu.inc.mk index 16d495c0dbcb..f2ec89bfa7f5 100644 --- a/makefiles/toolchain/gnu.inc.mk +++ b/makefiles/toolchain/gnu.inc.mk @@ -11,6 +11,8 @@ endif export AS = $(PREFIX)as export NM = $(PREFIX)nm export LD = $(PREFIX)ld +export ILINK = $(LD) +export ILINKFLAGS ?= -r --unique export LINK = $(PREFIX)gcc export LINKXX = $(PREFIX)g++ export SIZE = $(PREFIX)size diff --git a/makefiles/toolchain/llvm.inc.mk b/makefiles/toolchain/llvm.inc.mk index c39964bf1173..b266befe1536 100644 --- a/makefiles/toolchain/llvm.inc.mk +++ b/makefiles/toolchain/llvm.inc.mk @@ -17,6 +17,8 @@ export NM = $(LLVMPREFIX)nm # `makefiles/libc/newlib.mk` are not supported. Therefore # we just use GCC for now. export LD = $(PREFIX)ld +export ILINK = $(LD) +export ILINKFLAGS ?= -r --unique export LINK = $(PREFIX)gcc export LINKXX = $(PREFIX)g++ # objcopy does not have a clear substitute in LLVM, use GNU binutils diff --git a/makefiles/vars.inc.mk b/makefiles/vars.inc.mk index 062256efe9a8..b5f2343d481d 100644 --- a/makefiles/vars.inc.mk +++ b/makefiles/vars.inc.mk @@ -56,6 +56,8 @@ export AR # The command to create the object file archives. export ARFLAGS # Command-line options to pass to AR, default `rcs`. export AS # The assembler. export ASFLAGS # Flags for the assembler. +export ILINK # Command used to perform incremental linking to create intermediate object files. Usually "ld" +export ILINKFLAGS # Incremental link command line options. export LINK # The command used to link the files. Must take the same parameters as GCC, i.e. "ld" won't work. # LINKFLAGS # Flags to supply in the linking step. export LTOFLAGS # extra CFLAGS for compiling with link time optimization From abb13742a7f48668173c96f6f78c4681dd420a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Tue, 13 Mar 2018 13:40:48 +0100 Subject: [PATCH 14/18] squash mips fix --- cpu/mips32r2_common/Makefile.include | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cpu/mips32r2_common/Makefile.include b/cpu/mips32r2_common/Makefile.include index 8924ee503721..25529c6345af 100644 --- a/cpu/mips32r2_common/Makefile.include +++ b/cpu/mips32r2_common/Makefile.include @@ -8,6 +8,9 @@ export USEMODULE += newlib # mips32 needs periph_timer for its gettimeofday() implementation export USEMODULE += periph_timer +# Need to tell the linker about the CPU endianness +export ILINKFLAGS += -r -EL --unique + ifeq ($(USE_UHI_SYSCALLS),1) #Use UHI to handle syscalls export LINKFLAGS += -luhi From 79c666f4b1ffb4baea7635d465d3d2492424d542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Tue, 13 Mar 2018 14:10:28 +0100 Subject: [PATCH 15/18] squash MIPS newlib UHI fix --- cpu/mips32r2_common/newlib_syscalls_mips_uhi/syscalls.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cpu/mips32r2_common/newlib_syscalls_mips_uhi/syscalls.c b/cpu/mips32r2_common/newlib_syscalls_mips_uhi/syscalls.c index 87efbb0c5750..f21a7e729184 100644 --- a/cpu/mips32r2_common/newlib_syscalls_mips_uhi/syscalls.c +++ b/cpu/mips32r2_common/newlib_syscalls_mips_uhi/syscalls.c @@ -46,6 +46,8 @@ extern char _sheap; /* start of the heap */ extern char _eheap; /* end of the heap */ char *heap_top = &_sheap + 4; +/* MIPS newlib crt implements _init,_fini and _exit and manages the heap */ +#ifndef __mips__ /** * @brief Free resources on NewLib de-initialization, not used for RIOT */ @@ -98,6 +100,8 @@ void *_sbrk_r(struct _reent *r, ptrdiff_t incr) return res; } +#endif /*__mips__*/ + /** * @brief Get the process-ID of the current thread * From cc4e6dd6bb80ebd7387d11a4c22118f7bedeca2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Tue, 13 Mar 2018 14:15:08 +0100 Subject: [PATCH 16/18] Makefile.dep: Special case newlib_syscalls_mips_uhi Add an exception to not depend on periph_uart when using MIPS UHI syscalls for newlib syscalls. --- Makefile.dep | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile.dep b/Makefile.dep index 652487e88bcb..b916005ff984 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -398,7 +398,14 @@ endif ifneq (,$(filter stdio_uart,$(USEMODULE))) USEMODULE += isrpipe - FEATURES_REQUIRED += periph_uart + ifneq (,$(filter newlib_syscalls_mips_uhi,$(USEMODULE))) + # The periph_uart driver is optional when using MIPS UHI syscalls (debug + # UART is used on PIC32 boards, but not on mips-malta) + FEATURES_OPTIONAL += periph_uart + else + # All other UART implementations require the periph_uart driver. + FEATURES_REQUIRED += periph_uart + endif endif ifneq (,$(filter isrpipe,$(USEMODULE))) From 1886161386b7063a368314c594195a62dce9147a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Fri, 15 Jun 2018 08:19:11 +0200 Subject: [PATCH 17/18] squash riscv fix --- makefiles/arch/riscv.inc.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/makefiles/arch/riscv.inc.mk b/makefiles/arch/riscv.inc.mk index 549e3d87f3a0..76b693de283a 100644 --- a/makefiles/arch/riscv.inc.mk +++ b/makefiles/arch/riscv.inc.mk @@ -17,3 +17,5 @@ export CFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) $(CFLAGS_LINK) export ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) # export linker flags export LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT) -Wl,--gc-sections -static -lgcc +# ld defaults to elf64-littleriscv, tell it to use elf32 in incremental links +ILINKFLAGS += -m elf32lriscv -r --unique From 976b014992e8432b071c312a749aede53b6cdbf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Wed, 14 Mar 2018 07:09:46 +0100 Subject: [PATCH 18/18] SQUASHME pkg/oonf_api: Update build to use ld -r for submodules Do not make 'oonf_api' group all oonf_* objects. I find it strange to merge modules there. --- makefiles/pseudomodules.inc.mk | 4 ---- pkg/oonf_api/patches/0001-add-RIOT-support.patch | 6 +----- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index bea8e8a403f5..98b4d21a601f 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -140,8 +140,4 @@ PSEUDOMODULES += crypto_aes_precalculated # This pseudomodule causes a loop in AES to be unrolled (more flash, less CPU) PSEUDOMODULES += crypto_aes_unroll -# declare oonf submodules as pseudomodules, but exclude oonf_api -PSEUDOMODULES += oonf_% -NO_PSEUDOMODULES += oonf_api - # Packages may also add modules to PSEUDOMODULES in their `Makefile.include`. diff --git a/pkg/oonf_api/patches/0001-add-RIOT-support.patch b/pkg/oonf_api/patches/0001-add-RIOT-support.patch index 572a8250aece..91b5597daa2e 100644 --- a/pkg/oonf_api/patches/0001-add-RIOT-support.patch +++ b/pkg/oonf_api/patches/0001-add-RIOT-support.patch @@ -26,7 +26,7 @@ new file mode 100644 index 0000000..1f1cd9c --- /dev/null +++ b/Makefile -@@ -0,0 +1,28 @@ +@@ -0,0 +1,24 @@ +# +# to use oonf_api in your RIOT project, +# add the following to your Makefile: @@ -51,10 +51,6 @@ index 0000000..1f1cd9c + DIRS += external/regex +endif +include $(RIOTBASE)/Makefile.base -+# Build static archive from the submodule objects -+all: $(BINDIR)/$(MODULE).a -+$(patsubst %,$(BINDIR)/%.o,$(filter oonf_%,$(USEMODULE))): | ${DIRS:%=ALL--%} -+$(BINDIR)/$(MODULE).a: $(patsubst %,$(BINDIR)/%.o,$(filter oonf_%,$(USEMODULE))) | ${DIRS:%=ALL--%} diff --git a/external/regex/Makefile b/external/regex/Makefile new file mode 100644 index 0000000..3bc1ce1