Home | History | Annotate | Download | only in lib
      1 #! /bin/sh
      2 #
      3 # Set the $TRIPLE environment variable to your system's triple before
      4 # running this script.  If you set $CXX, that will be used to compile
      5 # the library.  Otherwise we'll use clang++.
      6 
      7 set -e
      8 
      9 if [ `basename $(pwd)` != "lib" ]
     10 then
     11 	echo "current directory must be lib"
     12 	exit 1
     13 fi
     14 
     15 if [ -z "$CXX" ]
     16 then
     17 	CXX=clang++
     18 fi
     19 
     20 if [ -z "$CC" ]
     21 then
     22     CC=clang
     23 fi
     24 
     25 if [ -z "$AR" ]
     26 then
     27     AR=ar
     28 fi
     29 
     30 if [ -z "$RANLIB" ]
     31 then
     32     RANLIB=ranlib
     33 fi
     34 
     35 if [ -z "$AR" ]
     36 then
     37     AR=ar
     38 fi
     39 
     40 if [ -z "$RANLIB" ]
     41 then
     42     RANLIB=ranlib
     43 fi
     44 
     45 if [ -z $RC_ProjectSourceVersion ]
     46 then
     47   RC_ProjectSourceVersion=1
     48 fi
     49 
     50 EXTRA_CC_FLAGS="-std=c11"
     51 EXTRA_CXX_FLAGS="-std=c++11 -stdlib=libc++"
     52 EXTRA_FLAGS="-fstrict-aliasing -Wstrict-aliasing=2 \
     53              -Wsign-conversion -Wshadow -Wconversion -Wunused-variable \
     54              -Wmissing-field-initializers -Wchar-subscripts -Wmismatched-tags \
     55              -Wmissing-braces -Wshorten-64-to-32 -Wsign-compare \
     56              -Wstrict-aliasing=2 -Wstrict-overflow=4 -Wunused-parameter \
     57              -Wnewline-eof"
     58 
     59 case $TRIPLE in
     60   *-apple-*)
     61     if [ -z $RC_XBS ]
     62     then
     63       RC_CFLAGS="-arch i386 -arch x86_64"
     64     fi
     65     SOEXT=dylib
     66     if [ -n "$SDKROOT" ]
     67     then
     68         EXTRA_CXX_FLAGS+="-isysroot ${SDKROOT}"
     69         CXX=`xcrun -sdk "${SDKROOT}"  -find clang++`
     70         CC=`xcrun -sdk "${SDKROOT}"  -find clang`
     71     fi
     72     LDSHARED_FLAGS="-o libc++abi.dylib \
     73         -dynamiclib -nodefaultlibs  \
     74         -current_version ${RC_ProjectSourceVersion} \
     75         -compatibility_version 1 \
     76         -install_name /usr/lib/libc++abi.dylib \
     77         -lSystem"
     78 	if [ -f "${SDKROOT}/usr/local/lib/libCrashReporterClient.a" ]
     79 	then
     80 		LDSHARED_FLAGS+=" -lCrashReporterClient"
     81 	fi
     82     ;;
     83   *-*-mingw*)
     84     # FIXME: removing libgcc and libsupc++ dependencies means porting libcxxrt and LLVM/compiler-rt
     85     SOEXT=dll
     86     LDSHARED_FLAGS="-o libc++abi.dll \
     87         -shared -nodefaultlibs -Wl,--export-all-symbols -Wl,--allow-multiple-definition -Wl,--out-implib,libc++abi.dll.a \
     88         -lsupc++ -lpthread -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcr100 -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt"
     89 	;;
     90   *-none-eabi*)
     91     RC_CFLAGS="-fPIC"
     92     SOEXT=so
     93     EXTRA_FLAGS+=" -target $TRIPLE --sysroot=$SYSROOT -no-integrated-as -funwind-tables -DLIBCXXABI_BARE_METAL=1"
     94   ;;
     95   *)
     96     RC_CFLAGS="-fPIC"
     97     SOEXT=so
     98     LDSHARED_FLAGS="-o libc++abi.so.1.0 \
     99         -shared -nodefaultlibs -Wl,-soname,libc++abi.so.1 \
    100         -lpthread -lrt -lc -lstdc++"
    101     ;;
    102 esac
    103 
    104 if [ -z $RC_XBS ]
    105 then
    106     rm -f libc++abi.1.$SOEXT*
    107 fi
    108 
    109 set -x
    110 
    111 # Build the generic bits
    112 for FILE in ../src/*.cpp; do
    113   $CXX -c -g -O0 $RC_CFLAGS $EXTRA_CXX_FLAGS $EXTRA_FLAGS -I../include $OPTIONS $FILE
    114 done
    115 case $TRIPLE in
    116   *-*-mingw*)
    117     for FILE in ../src/support/win32/*.cpp; do
    118       $CXX -c -g -O0 $RC_CFLAGS $EXTRA_CXX_FLAGS $EXTRA_FLAGS -I../include $OPTIONS $FILE
    119     done
    120     ;;
    121   *-apple-*)
    122     for FILE in ../src/support/apple/*.cpp; do
    123       $CXX -c -g -O0 $RC_CFLAGS $EXTRA_CXX_FLAGS $EXTRA_FLAGS -I../include $OPTIONS $FILE
    124     done
    125     ;;
    126   *)
    127     ;;
    128 esac
    129 
    130 # Build the Unwinder
    131 case $TRIPLE in
    132   *-none-eabi*)
    133     for FILE in ../src/Unwind/*.S; do
    134       $CC -c -g -O0 $RC_CFLAGS $EXTRA_CC_FLAGS $EXTRA_FLAGS -I../include $OPTIONS $FILE
    135     done
    136     for FILE in ../src/Unwind/*.c; do
    137       $CC -c -g -O0 $RC_CFLAGS $EXTRA_CC_FLAGS $EXTRA_FLAGS -I../include $OPTIONS $FILE
    138     done
    139     for FILE in ../src/Unwind/*.cpp; do
    140       $CXX -c -g -O0 $RC_CFLAGS $EXTRA_CXX_FLAGS $EXTRA_FLAGS -I../include $OPTIONS $FILE
    141     done
    142   ;;
    143 esac
    144 
    145 # Package everything up in a library (shared or static)
    146 case $TRIPLE in
    147   *-none-eabi*)
    148     $AR rc libc++abi.a *.o
    149     $RANLIB libc++abi.a
    150   ;;
    151   *)
    152     $CC *.o $RC_CFLAGS $LDSHARED_FLAGS $EXTRA_CXX_FLAGS $EXTRA_FLAGS
    153   ;;
    154 esac
    155 
    156 if [ -z $RC_XBS ]
    157 then
    158     rm *.o
    159 fi
    160