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
7set -e
8
9if [ `basename $(pwd)` != "lib" ]
10then
11	echo "current directory must be lib"
12	exit 1
13fi
14
15if [ -z "$CXX" ]
16then
17	CXX=clang++
18fi
19
20if [ -z "$CC" ]
21then
22    CC=clang
23fi
24
25if [ -z "$AR" ]
26then
27    AR=ar
28fi
29
30if [ -z "$RANLIB" ]
31then
32    RANLIB=ranlib
33fi
34
35if [ -z "$AR" ]
36then
37    AR=ar
38fi
39
40if [ -z "$RANLIB" ]
41then
42    RANLIB=ranlib
43fi
44
45if [ -z $RC_ProjectSourceVersion ]
46then
47  RC_ProjectSourceVersion=1
48fi
49
50EXTRA_CC_FLAGS="-std=c11"
51EXTRA_CXX_FLAGS="-std=c++11 -stdlib=libc++"
52EXTRA_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
59case $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    ;;
102esac
103
104if [ -z $RC_XBS ]
105then
106    rm -f libc++abi.1.$SOEXT*
107fi
108
109set -x
110
111# Build the generic bits
112for FILE in ../src/*.cpp; do
113  $CXX -c -g -O0 $RC_CFLAGS $EXTRA_CXX_FLAGS $EXTRA_FLAGS -I../include $OPTIONS $FILE
114done
115case $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    ;;
128esac
129
130# Build the Unwinder
131case $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  ;;
143esac
144
145# Package everything up in a library (shared or static)
146case $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  ;;
154esac
155
156if [ -z $RC_XBS ]
157then
158    rm *.o
159fi
160