1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #6253 from gebart/pr/newlib-nano-include-dir-fix

LLVM+newlib include path search fixes
This commit is contained in:
Oleg Hahm 2017-01-04 11:19:54 +01:00 committed by GitHub
commit 84b2910657
4 changed files with 36 additions and 20 deletions

View File

@ -70,7 +70,7 @@ $(OBJCXX): $(BINDIR)/$(MODULE)/%.o: %.cpp $(RIOTBUILD_CONFIG_HEADER_C)
$(AD)$(CCACHE) $(CXX) \
-DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$(abspath $<))\" \
-DRIOT_FILE_NOPATH=\"$(notdir $<)\" \
$(CXXFLAGS) $(INCLUDES) $(CXXINCLUDES) -MD -MP -c -o $@ $(abspath $<)
$(CXXFLAGS) $(CXXINCLUDES) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)
$(ASMOBJ): $(BINDIR)/$(MODULE)/%.o: %.s
$(AD)$(AS) $(ASFLAGS) -o $@ $(abspath $<)

View File

@ -175,9 +175,6 @@ export TOOLCHAIN
# will most likely not need to touch this.
export PREFIX ?= $(if $(TARGET_ARCH),$(TARGET_ARCH)-)
# Import all toolchain settings
include $(RIOTCPU)/Makefile.include.$(TOOLCHAIN)
# Add standard include directories
INCLUDES += -I$(RIOTBASE)/core/include -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/sys/include
INCLUDES += -I$(RIOTCPU)/$(CPU)/include
@ -189,6 +186,9 @@ include $(RIOTBASE)/Makefile.defaultmodules
include $(RIOTBOARD)/$(BOARD)/Makefile.include
include $(RIOTCPU)/$(CPU)/Makefile.include
# Import all toolchain settings
include $(RIOTCPU)/Makefile.include.$(TOOLCHAIN)
# get number of interfaces straight before resolving dependencies
GNRC_NETIF_NUMOF ?= 1

View File

@ -31,19 +31,24 @@ export DBG = $(GDBPREFIX)gdb
GCC_CXX_INCLUDE_PATTERNS ?= \
/etc/alternatives/gcc-$(TARGET_ARCH)-include/c++/*/ \
/usr/$(TARGET_ARCH)/include/c++/*/ \
/usr/lib/gcc/$(TARGET_ARCH)/*/include/g++-v8 \
/usr/lib/gcc/$(TARGET_ARCH)/*/include/g++-v7 \
/usr/lib/gcc/$(TARGET_ARCH)/*/include/g++-v6 \
/usr/lib/gcc/$(TARGET_ARCH)/*/include/g++-v5 \
#
# Try to find the proper multilib directory using GCC, this may fail if a cross-
# GCC is not installed.
ifeq ($(GCC_MULTI_DIR),)
GCC_MULTI_DIR := $(shell $(PREFIX)gcc -print-multi-directory $(CFLAGS) 2>/dev/null)
GCC_MULTI_DIR := $(shell $(PREFIX)gcc $(CFLAGS) -print-multi-directory 2>/dev/null)
endif
# Tell clang to cross compile
export CFLAGS += -target $(TARGET_ARCH)
export CXXFLAGS += -target $(TARGET_ARCH)
export LINKFLAGS += -target $(TARGET_ARCH)
ifneq (,$(TARGET_ARCH))
# Tell clang to cross compile
export CFLAGS += -target $(TARGET_ARCH)
export CXXFLAGS += -target $(TARGET_ARCH)
export LINKFLAGS += -target $(TARGET_ARCH)
endif
# Use the wildcard Makefile function to search for existing directories matching
# the patterns above. We use the -isystem gcc/clang argument to add the include
@ -54,8 +59,8 @@ export LINKFLAGS += -target $(TARGET_ARCH)
# previous tool chain installations.
GCC_CXX_INCLUDES ?= \
$(addprefix \
-isystem $(lastword $(sort \
$(foreach pat, $(GCC_CXX_INCLUDE_PATTERNS), $(wildcard $(pat))))), \
-isystem $(firstword \
$(foreach pat, $(GCC_CXX_INCLUDE_PATTERNS), $(lastword $(sort $(wildcard $(pat)))))), \
/. /$(TARGET_ARCH)/$(GCC_MULTI_DIR) /backward \
)

View File

@ -17,7 +17,6 @@ endif
export LINKFLAGS += -lc -lnosys
ifeq (1,$(USE_NEWLIB_NANO))
# Search for Newlib include directories
# Since Clang is not installed as a separate instance for each crossdev target
@ -49,13 +48,25 @@ 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_INCLUDE_DIR))
NEWLIB_INCLUDE_DIR := $(abspath $(wildcard $(dir $(shell which $(PREFIX)gcc))../$(TARGET_ARCH)/include))
endif
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_INCLUDE_DIR := $(abspath $(wildcard $(dir $(shell command -v $(PREFIX)gcc))../$(TARGET_ARCH)/include))
endif
# Newlib includes should go before GCC includes.
export INCLUDES := $(NEWLIB_INCLUDES) $(INCLUDES)
ifeq ($(TOOLCHAIN),llvm)
# A cross GCC already knows the target libc include path (build-in at compile time)
# but Clang, when cross-compiling, needs to be told where to find the headers
# for the system being built.
# We also add -nostdinc to avoid including the host system headers by mistake
# in case some header is missing from the cross tool chain
NEWLIB_INCLUDES := -isystem $(NEWLIB_INCLUDE_DIR) -nostdinc
NEWLIB_INCLUDES += $(addprefix -isystem ,$(abspath $(wildcard $(dir $(NEWLIB_INCLUDE_DIR))/usr/include)))
endif
ifeq (1,$(USE_NEWLIB_NANO))
NEWLIB_NANO_INCLUDE_DIR ?= $(NEWLIB_INCLUDE_DIR)/newlib-nano
# newlib-nano overrides newlib.h and its include dir should therefore go before
# the regular system include dirs.
INCLUDES := -isystem $(NEWLIB_NANO_INCLUDE_DIR) $(INCLUDES)
endif
# Newlib includes should go after GCC includes.
export INCLUDES += $(NEWLIB_INCLUDES)