From 1077cf95fd99a673c00d743ffbf90f864e08e0be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20P=C3=B6chtrager?= Date: Tue, 7 Jan 2014 22:40:56 +0100 Subject: [PATCH] switch to libc++ 3.4 (works fine with clang < 3.4) get OSX_VERSION_MIN >= 10.9 working (defaults to libc++) simplify the wrapper scripts a bit --- build.sh | 7 +++++ build_libcxx.sh | 14 +++++++-- oclang/oclang | 75 ++++++++++++++++++++++++++++++++-------------- ogcc/ogcc | 16 +++++++--- tools/trap_exit.sh | 2 +- 5 files changed, 83 insertions(+), 31 deletions(-) diff --git a/build.sh b/build.sh index 95e1867..4f952cb 100755 --- a/build.sh +++ b/build.sh @@ -283,6 +283,13 @@ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:`cat $BUILD_DIR/cctools*/cctools/tmp/ld echo "" +if [ `echo "$SDK_VERSION>=10.9" | bc -l` -eq 1 ] && ( [ $OSX_VERSION_MIN == "default" ] || + [ `echo "$OSX_VERSION_MIN>=10.9" | bc -l` -eq 1 ] ); +then + export SCRIPT=`basename $0` + ./build_libcxx.sh || exit 0 +fi + test_compiler o32-clang $BASE_DIR/oclang/test.c test_compiler o64-clang $BASE_DIR/oclang/test.c diff --git a/build_libcxx.sh b/build_libcxx.sh index de86cd9..69aee32 100755 --- a/build_libcxx.sh +++ b/build_libcxx.sh @@ -11,7 +11,7 @@ if [ `echo "${OSXCROSS_SDK_VERSION}<10.7" | bc -l` -eq 1 ]; then fi # libc++ version to build -LIBCXX_VERSION=3.3 +LIBCXX_VERSION=3.4 set +e require wget @@ -30,7 +30,7 @@ source $BASE_DIR/tools/trap_exit.sh if [ ! -f "have_libcxx_${LIBCXX_VERSION}_${OSXCROSS_TARGET}" ]; then pushd $OSXCROSS_TARBALL_DIR &>/dev/null -wget -c "http://llvm.org/releases/3.3/libcxx-${LIBCXX_VERSION}.src.tar.gz" +wget -c "http://llvm.org/releases/${LIBCXX_VERSION}/libcxx-${LIBCXX_VERSION}.src.tar.gz" popd &>/dev/null tar xzfv "$OSXCROSS_TARBALL_DIR/libcxx-${LIBCXX_VERSION}.src.tar.gz" @@ -45,6 +45,8 @@ rm -rf $OSXCROSS_SDK/usr/include/c++/v1 rm -rf $OSXCROSS_SDK/usr/lib/libc++.dylib rm -rf $OSXCROSS_SDK/usr/lib/libc++.*.dylib +rm -rf $OSXCROSS_SDK/../libcxx_$OSXCROSS_SDK_VERSION + function cmake_error() { echo -e "\e[1m" @@ -54,7 +56,7 @@ function cmake_error() echo "CMake Error at /usr/share/cmake-2.8/Modules/Platform/Darwin.cmake: (list):" echo " list sub-command REMOVE_DUPLICATES requires list to be present." echo -e "\e[0m\e[1m" - echo "Then either remove this line (look for the LINE NUMBER) or comment it out (with #) in /usr/share/cmake-.../Modules/Platform/Darwin.cmake" + echo "Then either remove that line (look for the LINE NUMBER) or comment it out (with #) in /usr/share/cmake-.../Modules/Platform/Darwin.cmake" echo "It appears to be a bug in CMake." echo "" echo "Then re-run this script." @@ -62,6 +64,8 @@ function cmake_error() exit 1 } +export BUILD_LIBCXX=1 + cmake .. \ -DCMAKE_CXX_COMPILER=x86_64-apple-$OSXCROSS_TARGET-clang++ \ -DCMAKE_C_COMPILER=x86_64-apple-$OSXCROSS_TARGET-clang \ @@ -74,9 +78,13 @@ cmake .. \ -DCMAKE_RANLIB=$OSXCROSS_CCTOOLS_PATH/x86_64-apple-$OSXCROSS_TARGET-ranlib \ -DCMAKE_CXX_FLAGS="-arch i386 -arch x86_64" || cmake_error +export BUILD_LIBCXX=2 + make -j$JOBS make install -j$JOBS +unset BUILD_LIBCXX + popd &>/dev/null # build popd &>/dev/null # libcxx diff --git a/oclang/oclang b/oclang/oclang index bdd5304..8176444 100755 --- a/oclang/oclang +++ b/oclang/oclang @@ -7,11 +7,11 @@ popd &>/dev/null type=`basename $0` -if [ $type != "${type/o64/}" ] || [ $type != "${type/x86_64/}" ]; then +if [[ $type == *o64* ]] || [[ $type == *x86_64* ]]; then ARCH1="x86_64" ARCH2=$ARCH1 else - if [ $type != "${type/o32/}" ] || [ $type != "${type/i386/}" ]; then + if [[ $type == *o32* ]] || [[ $type == *i386* ]]; then ARCH1="i386" ARCH2="i686" else @@ -20,37 +20,43 @@ else fi fi -if [ $type != "${type/++/}" ]; then +if [[ $type == *++* ]]; then COMPILER="clang++" else COMPILER="clang" fi -if [ $COMPILER == "clang++" ] && [ "$type" != "${type/libc++/}" ]; then +if [ $COMPILER == "clang++" ] && [[ $type == *libc++* ]]; then USE_LIBCXX=1 else USE_LIBCXX=0 fi +TARGET=$ARCH1-apple-$OSXCROSS_TARGET +OSX_VERSION_MIN=$OSXCROSS_OSX_VERSION_MIN + if [ $# -gt 0 ]; then for p in "$@" do if [[ "$p" == -mmacosx-version-min=* ]]; then OSXCROSS_OSX_VERSION_MIN="default" - - MIN_TARGET_VERSION=`echo "$p" | tr '=' ' ' | tr '.' ' ' | awk '{printf "%d %d", $2, $3}'` - MIN_TARGET_VERSION_MAJOR=`echo $MIN_TARGET_VERSION | awk '{print $1}'` - MIN_TARGET_VERSION_MINOR=`echo $MIN_TARGET_VERSION | awk '{print $2}'` - - if [ $MIN_TARGET_VERSION_MAJOR -ge 10 ] && [ $MIN_TARGET_VERSION_MINOR -ge 9 ]; then - # default to libc++ on >= 10.9 - USE_LIBCXX=1 - fi + OSX_VERSION_MIN=`echo "$p" | tr '=' ' ' | awk '{print $2}'` + continue fi if [ "$p" == "-stdlib=libc++" ]; then USE_LIBCXX=2 + continue + fi + if [ "$p" == "-v" ] || [ "$p" == "--version" ]; then + if [ $# -eq 1 ]; then + $COMPILER $OSXCROSS_TARGET_OPTION $TARGET $p + exit $? + fi fi done +else + $COMPILER $OSXCROSS_TARGET_OPTION $TARGET + exit $? fi if [ $OSXCROSS_OSX_VERSION_MIN != "default" ]; then @@ -63,28 +69,51 @@ export COMPILER_PATH="$OSXCROSS_CCTOOLS_PATH:$COMPILER_PATH" STDINC=$OSXCROSS_SDK/usr/include +if [ -n "$BUILD_LIBCXX" ]; then + if [ $BUILD_LIBCXX -eq 1 ]; then + # TODO: Write a fake libc++ library (without any symbols) + # once libstdc++ disappears from the SDK. + # Newer versions of clang default to libc++ for >= 10.9, + # so configuring libc++ fails because of the hardcoded + # -lc++ ... (at least with cmake). + + OSXCROSS_OPT_ARGS="$OSXCROSS_OPT_ARGS -stdlib=libstdc++" + fi + + USE_LIBCXX=0 +else + if [ $USE_LIBCXX -eq 0 ]; then + MIN_TARGET_VERSION=`echo "$OSX_VERSION_MIN" | tr '=' ' ' | tr '.' ' ' | awk '{printf "%d %d", $1, $2}'` + MIN_TARGET_VERSION_MAJOR=`echo $MIN_TARGET_VERSION | awk '{print $1}'` + MIN_TARGET_VERSION_MINOR=`echo $MIN_TARGET_VERSION | awk '{print $2}'` + + if [ $MIN_TARGET_VERSION_MAJOR -ge 10 ] && [ $MIN_TARGET_VERSION_MINOR -ge 9 ]; then + # default to libc++ on >= 10.9 + USE_LIBCXX=1 + fi + fi +fi + if [ $USE_LIBCXX -ne 0 ]; then if [ ! -f "$OSXCROSS_SDK/../libcxx_$OSXCROSS_SDK_VERSION/lib/libc++.a" ]; then echo -e "\e[1mosxcross \e[31merror:\e[0m\e[1m you must build libc++ before you can use it (./build_libcxx.sh)\e[0m" 1>&2 exit 1 fi - CPLUSINC="-nostdinc++ -cxx-isystem $OSXCROSS_SDK/../libcxx_$OSXCROSS_SDK_VERSION/include/c++/v1" + CXXINC="-nostdinc++ -cxx-isystem $OSXCROSS_SDK/../libcxx_$OSXCROSS_SDK_VERSION/include/c++/v1" if [ $USE_LIBCXX -eq 1 ]; then - CPLUSINC="$CPLUSINC -stdlib=libc++" + CXXINC="$CXXINC -stdlib=libc++" fi - CPLUSINC="$CPLUSINC -Qunused-arguments -lc++abi" - CPLUSINC="$CPLUSINC -L$OSXCROSS_SDK/../libcxx_$OSXCROSS_SDK_VERSION/lib" + CXXINC="$CXXINC -Qunused-arguments -lc++abi" + CXXINC="$CXXINC -L$OSXCROSS_SDK/../libcxx_$OSXCROSS_SDK_VERSION/lib" else - CPLUSINC="-isystem $OSXCROSS_SDK/usr/lib/gcc/i686-apple-$OSXCROSS_TARGET/4.2.1/include" - CPLUSINC="$CPLUSINC -cxx-isystem $OSXCROSS_SDK/usr/include/c++/4.0.0 " - CPLUSINC="$CPLUSINC -cxx-isystem $OSXCROSS_SDK/usr/include/c++/4.0.0/$ARCH2-apple-darwin9 " + CXXINC="-cxx-isystem $OSXCROSS_SDK/usr/lib/gcc/i686-apple-$OSXCROSS_TARGET/4.2.1/include" + CXXINC="$CXXINC -cxx-isystem $OSXCROSS_SDK/usr/include/c++/4.0.0 " + CXXINC="$CXXINC -cxx-isystem $OSXCROSS_SDK/usr/include/c++/4.0.0/$ARCH2-apple-darwin9 " fi -TARGET=$ARCH1-apple-$OSXCROSS_TARGET - XMMINTRIN=`readlink "$STDINC/xmmintrin.h"` if [ $? -eq 0 ] && [ ! -f "$XMMINTRIN" ]; then pushd "${0%/*}" &>/dev/null @@ -100,7 +129,7 @@ fi $COMPILER \ $OSXCROSS_TARGET_OPTION $TARGET -isysroot $OSXCROSS_SDK \ - $CPLUSINC $OSX_VERSION_MIN_OPT -mlinker-version=$OSXCROSS_LINKER_VERSION \ + $CXXINC $OSX_VERSION_MIN_OPT -mlinker-version=$OSXCROSS_LINKER_VERSION \ $OSXCROSS_OPT_ARGS ${1+"$@"} exit $? diff --git a/ogcc/ogcc b/ogcc/ogcc index cb91fea..f491529 100755 --- a/ogcc/ogcc +++ b/ogcc/ogcc @@ -7,11 +7,11 @@ popd &>/dev/null type=`basename $0` -if [ $type != "${type/o64/}" ] || [ $type != "${type/x86_64/}" ]; then +if [[ $type == *o64* ]] || [[ $type == *x86_64* ]]; then ARCH="x86_64" ARCHFLAG="-m64" else - if [ $type != "${type/o32/}" ] || [ $type != "${type/i386/}" ]; then + if [[ $type == *o32* ]] || [[ $type == *i386* ]]; then ARCH="i386" ARCHFLAG="-m32" else @@ -20,13 +20,13 @@ else fi fi -if [ $type != "${type/++/}" ]; then +if [[ $type == *++* ]]; then COMPILER="$OSXCROSS_TARGET_DIR/bin/$ARCH-apple-$OSXCROSS_TARGET-base-g++" else COMPILER="$OSXCROSS_TARGET_DIR/bin/$ARCH-apple-$OSXCROSS_TARGET-base-gcc" fi -if [[ $COMPILER == *g++ ]] && [ "$type" != "${type/libc++/}" ]; then +if [[ $COMPILER == *g++ ]] && [[ $type == *libc++* ]]; then if [ ! -f "$OSXCROSS_SDK/../libcxx_$OSXCROSS_SDK_VERSION/lib/libc++.a" ]; then echo -e "\e[1mosxcross \e[31merror:\e[0m\e[1m you must build libc++ before you can use it (./build_libcxx.sh)\e[0m" 1>&2 exit 1 @@ -51,9 +51,17 @@ if [ $# -gt 0 ]; then do if [ "$p" == "-arch" ] || [ "$p" == "-m32" ] || [ "$p" == "-m64" ]; then ARCHGIVEN=1 + continue fi if [[ "$p" == -mmacosx-version-min=* ]]; then OSXCROSS_OSX_VERSION_MIN="default" + continue + fi + if [ "$p" == "-v" ] || [ "$p" == "--version" ]; then + if [ $# -eq 1 ]; then + $COMPILER $p + exit $? + fi fi done diff --git a/tools/trap_exit.sh b/tools/trap_exit.sh index 5e487d7..63ba829 100644 --- a/tools/trap_exit.sh +++ b/tools/trap_exit.sh @@ -4,7 +4,7 @@ function _exit() { EC=$? if [ $EC -ne 0 ]; then - SCRIPT=`basename $0` + test -z "$SCRIPT" && SCRIPT=`basename $0` echo "" echo "exiting with abnormal exit code ($EC)" test -n "$OCDEBUG" || echo "run 'OCDEBUG=1 ./$SCRIPT' to enable debug messages"