Skip to content

Commit

Permalink
newlib.mk: Windows/MSYS Bash support: use realpath instead of abspath
Browse files Browse the repository at this point in the history
Some versions of Mingw32 abspath implementation has trouble working with
windows formatted path.

    $(abspath "C:/A/B") returns "/C/CUR/DIR/C:/A/B" instead of "/C/A/B"

relpath does not have this problem, it does additional symlink resolution but is
not a problem.
Note: on windows it does not remove the trailing `/`.

zephyrproject-rtos/zephyr#2061 (comment)

Patched in

zephyrproject-rtos/zephyr@941059c
  • Loading branch information
cladmi committed Aug 2, 2018
1 parent 3a4538e commit 37a92c4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions makefiles/libc/newlib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ endif

export LINKFLAGS += -lc

# Note on `realpath` vs `abspath`
#
# `realpath` is used instead of `abspath` to support Mingw32
# It fixes issues when using windows formatted paths like in the gcc output
# It does leave the trailing `/` on windows though


# Search for Newlib include directories

# Try to search for newlib in the standard search path of the compiler for includes
Expand Down Expand Up @@ -62,7 +69,7 @@ endif
# 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 command -v $(PREFIX)gcc 2>/dev/null))/../$(TARGET_ARCH)/include))
NEWLIB_INCLUDE_DIR := $(realpath $(wildcard $(dir $(shell command -v $(PREFIX)gcc 2>/dev/null))/../$(TARGET_ARCH)/include))
endif

ifeq ($(TOOLCHAIN),llvm)
Expand All @@ -72,7 +79,7 @@ ifeq ($(TOOLCHAIN),llvm)
# 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)))
NEWLIB_INCLUDES += $(addprefix -isystem ,$(realpath $(wildcard $(dir $(NEWLIB_INCLUDE_DIR))/usr/include)))

# Newlib includes should go before GCC includes. This is especially important
# when using Clang, because Clang will yield compilation errors on some GCC-
Expand Down

0 comments on commit 37a92c4

Please sign in to comment.