Darwin: Use xcrun to get the path to the SDK

Recent versions of Xcode don't install headers in /usr/include but
in a directory like

  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include

So use that instead, falling back to /usr/include in case of an older
version of Xcode.
This commit is contained in:
Eelco Dolstra 2014-06-30 19:51:43 +02:00
parent 55e8e0ef9b
commit 89f8af55f1
2 changed files with 23 additions and 9 deletions

View File

@ -303,14 +303,21 @@ stdenv.mkDerivation ({
"\"--with-host-libstdcxx=-Wl,-rpath,\$prefix/lib/amd64 -lstdc++\"
\"--with-boot-ldflags=-L../prev-x86_64-pc-solaris2.11/libstdc++-v3/src/.libs\""}
);
${stdenv.lib.optionalString (stdenv.isSunOS && stdenv.is64bit)
''
export NIX_LDFLAGS=`echo $NIX_LDFLAGS | sed -e s~$prefix/lib~$prefix/lib/amd64~g`
export LDFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $LDFLAGS_FOR_TARGET"
export CXXFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $CXXFLAGS_FOR_TARGET"
export CFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $CFLAGS_FOR_TARGET"
''}
'';
'' + stdenv.lib.optionalString (stdenv.isSunOS && stdenv.is64bit) ''
export NIX_LDFLAGS=`echo $NIX_LDFLAGS | sed -e s~$prefix/lib~$prefix/lib/amd64~g`
export LDFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $LDFLAGS_FOR_TARGET"
export CXXFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $CXXFLAGS_FOR_TARGET"
export CFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $CFLAGS_FOR_TARGET"
'' + stdenv.lib.optionalString stdenv.isDarwin ''
if xcodePath=$(/usr/bin/xcrun --show-sdk-path); then
configureFlagsArray+=(--with-native-system-header-dir=$xcodePath/usr/include)
makeFlagsArray+=( \
CFLAGS_FOR_BUILD=-F$xcodePath/System/Library/Frameworks \
CFLAGS_FOR_TARGET=-F$xcodePath/System/Library/Frameworks \
FLAGS_FOR_TARGET=-F$xcodePath/System/Library/Frameworks \
)
fi
'';
dontDisableStatic = true;

View File

@ -16,7 +16,14 @@ import ../generic rec {
stripAllFlags=" " # the Darwin "strip" command doesn't know "-s"
xargsFlags=" "
fi
'';
'' + (if stdenv.isDarwin then ''
export NIX_CFLAGS_COMPILE="--sysroot=/var/empty"
if xcodePath=$(/usr/bin/xcrun --show-sdk-path 2> /dev/null); then
NIX_CFLAGS_COMPILE+=" -idirafter $xcodePath/usr/include -F$xcodePath/System/Library/Frameworks"
else
NIX_CFLAGS_COMPILE+=" -idirafter /usr/include -F/System/Library/Frameworks"
fi
'' else "");
initialPath = (import ../common-path.nix) {pkgs = pkgs;};