build: fix build on Mac OS X 10.9
authornbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Wed, 30 Oct 2013 21:47:01 +0000 (21:47 +0000)
committernbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Wed, 30 Oct 2013 21:47:01 +0000 (21:47 +0000)
Add a wrapper around the clang gcc emulation to fix -print-file-name=<lib>

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Backport of r38560

git-svn-id: svn://svn.openwrt.org/openwrt/branches/attitude_adjustment@38613 3c298f89-4303-0410-b956-a3cf2f4a3e73

include/toplevel.mk
scripts/clang-gcc-wrapper [new file with mode: 0755]

index 4bbc58e..bbda0bb 100644 (file)
@@ -42,6 +42,13 @@ unexport LPATH
 # make sure that a predefined CFLAGS variable does not disturb packages
 export CFLAGS=
 
+ifneq ($(shell $(HOSTCC) 2>&1 | grep clang),)
+  export HOSTCC_REAL?=$(HOSTCC)
+  export HOSTCC_WRAPPER:=$(TOPDIR)/scripts/clang-gcc-wrapper
+else
+  export HOSTCC_WRAPPER:=$(HOSTCC)
+endif
+
 ifeq ($(FORCE),)
   .config scripts/config/conf scripts/config/mconf: tmp/.prereq-build
 endif
@@ -71,12 +78,12 @@ prepare-tmpinfo: FORCE
        fi
 
 scripts/config/mconf:
-       @$(_SINGLE)$(SUBMAKE) -s -C scripts/config all CC="$(HOSTCC)"
+       @$(_SINGLE)$(SUBMAKE) -s -C scripts/config all CC="$(HOSTCC_WRAPPER)"
 
 $(eval $(call rdep,scripts/config,scripts/config/mconf))
 
 scripts/config/conf:
-       @$(_SINGLE)$(SUBMAKE) -s -C scripts/config conf CC="$(HOSTCC)"
+       @$(_SINGLE)$(SUBMAKE) -s -C scripts/config conf CC="$(HOSTCC_WRAPPER)"
 
 config: scripts/config/conf prepare-tmpinfo FORCE
        $< Config.in
diff --git a/scripts/clang-gcc-wrapper b/scripts/clang-gcc-wrapper
new file mode 100755 (executable)
index 0000000..9e66841
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+_cc="${HOSTCC_REAL:-gcc}"
+case "$1" in
+       -print-file-name=*)
+               dirs="$($_cc -print-search-dirs | grep -m1 libraries | sed -e 's,:, ,' -e 's,.* =,,')"
+               dirs="$dirs /usr/lib /usr/local/lib"
+               find $dirs -name "${1#*=}" | head -n1
+       ;;
+       *)
+               exec $_cc "$@"
+       ;;
+esac