From 37a92c4c5eee54f4622cc4f5315e1467ea216d48 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= <gaetan.harter@fu-berlin.de>
Date: Tue, 10 Jul 2018 14:05:52 +0200
Subject: [PATCH] newlib.mk: Windows/MSYS Bash support: use realpath instead of
 abspath

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 `/`.

https://github.com/zephyrproject-rtos/zephyr/issues/2061#issuecomment-331635063

Patched in

https://github.com/zephyrproject-rtos/zephyr/commit/941059c69f9488613775a1a8802a099447cdea4c
---
 makefiles/libc/newlib.mk | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/makefiles/libc/newlib.mk b/makefiles/libc/newlib.mk
index 191d4080a8..e35d223fde 100644
--- a/makefiles/libc/newlib.mk
+++ b/makefiles/libc/newlib.mk
@@ -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
@@ -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)
@@ -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-
-- 
GitLab