diff --git a/Makefile.dep b/Makefile.dep index 38b315f902092ef87e27a7589cc66c8a77ebd86f..6dafb9f0e139866ebcf53a826ecbb8a1530f8502 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -290,6 +290,10 @@ ifneq (,$(filter gnrc_pktdump,$(USEMODULE))) USEMODULE += od endif +ifneq (,$(filter newlib_nano,$(USEMODULE))) + USEMODULE += newlib +endif + ifneq (,$(filter newlib,$(USEMODULE))) # allow custom newlib syscalls implementations by adding # newlib_syscalls_XXX to USEMODULE diff --git a/Makefile.pseudomodules b/Makefile.pseudomodules index 52067be97b173e0f6aaa3855b8a5125a1870b51b..ae55500447e4e859359cfa9142d525dc33900dd3 100644 --- a/Makefile.pseudomodules +++ b/Makefile.pseudomodules @@ -17,6 +17,7 @@ PSEUDOMODULES += gnrc_pktbuf PSEUDOMODULES += log PSEUDOMODULES += log_printfnoformat PSEUDOMODULES += newlib +PSEUDOMODULES += newlib_nano PSEUDOMODULES += pktqueue PSEUDOMODULES += schedstatistics PSEUDOMODULES += netif diff --git a/boards/msba2-common/Makefile.include b/boards/msba2-common/Makefile.include index 087f664bf449c647ca2bfbdc265b79df79613641..5ea7992a93970c732f98ba93c7e5402b77330802 100644 --- a/boards/msba2-common/Makefile.include +++ b/boards/msba2-common/Makefile.include @@ -29,10 +29,7 @@ export LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) -static -lgcc -nos export LINKFLAGS += -Wl,--gc-sections # use the nano-specs of Newlib when available -ifeq ($(shell $(LINK) -specs=nano.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0) -export CFLAGS += -specs=nano.specs -export LINKFLAGS += -specs=nano.specs -lc -lnosys -endif +USEMODULE += newlib_nano ifeq ($(PORT),) export PORT = /dev/ttyUSB0 diff --git a/cpu/Makefile.include.cortexm_common b/cpu/Makefile.include.cortexm_common index 1c3fcc4ea1a2207136ed16ec62462d7cb7c9d690..6537e465ca2d9a9db14f745af21df7ccea56ac4d 100644 --- a/cpu/Makefile.include.cortexm_common +++ b/cpu/Makefile.include.cortexm_common @@ -94,10 +94,7 @@ endif include $(RIOTCPU)/cortexm_common/Makefile.include # use the nano-specs of Newlib when available -ifeq ($(shell $(LINK) -specs=nano.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0) -export CFLAGS += -specs=nano.specs -export LINKFLAGS += -specs=nano.specs -lc -lnosys -endif +USEMODULE += newlib_nano # Avoid overriding the default rule: all: diff --git a/sys/newlib/Makefile.include b/sys/newlib/Makefile.include index 7db4d395bdeb1ecc7b5c1634aacdabb5c5565035..a3a06196f6db0dd7c096507a29722d5d4fd7f4f1 100644 --- a/sys/newlib/Makefile.include +++ b/sys/newlib/Makefile.include @@ -1,5 +1,18 @@ UNDEF := $(BINDIR)newlib_syscalls_default/syscalls.o $(UNDEF) +ifneq (,$(filter newlib_nano,$(USEMODULE))) + # Test if nano.specs is available + ifeq ($(shell $(LINK) -specs=nano.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0) + USE_NEWLIB_NANO = 1 + endif +endif + +ifeq (1,$(USE_NEWLIB_NANO)) + export LINKFLAGS += -specs=nano.specs +endif + +export LINKFLAGS += -lc -lnosys + # Search for Newlib include directories # Since Clang is not installed as a separate instance for each crossdev target @@ -25,15 +38,21 @@ NEWLIB_INCLUDE_PATTERNS ?= \ # the patterns above. We use the -isystem gcc/clang argument to add the include # directories as system include directories, which means they will not be # searched until after all the project specific include directories (-I/path) -NEWLIB_INCLUDES ?= \ - $(foreach dir, \ - $(foreach pat, $(NEWLIB_INCLUDE_PATTERNS), $(wildcard $(pat))), \ - -isystem $(dir)) +NEWLIB_INCLUDE_DIR ?= $(firstword $(wildcard $(NEWLIB_INCLUDE_PATTERNS))) # If nothing was found we will try to fall back to searching for a cross-gcc in # the current PATH and use a relative path for the includes -ifeq (,$(NEWLIB_INCLUDES)) - NEWLIB_INCLUDES := $(addprefix -isystem ,$(wildcard $(dir $(shell which $(PREFIX)gcc))../$(TARGET_ARCH)/include)) +ifeq (,$(NEWLIB_INCLUDE_DIR)) + NEWLIB_INCLUDE_DIR := $(abspath $(wildcard $(dir $(shell which $(PREFIX)gcc))../$(TARGET_ARCH)/include)) +endif + +NEWLIB_INCLUDES := -isystem $(NEWLIB_INCLUDE_DIR) + +ifeq (1,$(USE_NEWLIB_NANO)) + NEWLIB_NANO_INCLUDE_DIR ?= $(NEWLIB_INCLUDE_DIR)/nano + # newlib-nano overrides newlib.h and its include dir should therefore go before + # the regular newlib include dir. + NEWLIB_INCLUDES := -isystem $(NEWLIB_NANO_INCLUDE_DIR) $(NEWLIB_INCLUDES) endif # Newlib includes should go before GCC includes.