Howard Hinnant | adff489 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 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 |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 5 | # the library. Otherwise we'll use clang++. |
Howard Hinnant | adff489 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 6 | |
| 7 | set -e |
| 8 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 9 | if [ `basename $(pwd)` != "lib" ] |
| 10 | then |
Daniel Dunbar | fd329a4 | 2013-02-07 00:24:17 +0000 | [diff] [blame] | 11 | echo "current directory must be lib" |
| 12 | exit 1 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 13 | fi |
| 14 | |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 15 | if [ -z "$CXX" ] |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 16 | then |
Daniel Dunbar | fd329a4 | 2013-02-07 00:24:17 +0000 | [diff] [blame] | 17 | CXX=clang++ |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 18 | fi |
| 19 | |
Nick Kledzik | c6e08d6 | 2011-05-04 21:50:46 +0000 | [diff] [blame] | 20 | if [ -z "$CC" ] |
| 21 | then |
| 22 | CC=clang |
| 23 | fi |
| 24 | |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 25 | if [ -z "$MACOSX_DEPLOYMENT_TARGET" ] |
Nick Kledzik | c7e4d82 | 2010-09-10 20:42:36 +0000 | [diff] [blame] | 26 | then |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 27 | if [ -z "$IPHONEOS_DEPLOYMENT_TARGET" ] |
Daniel Dunbar | fd329a4 | 2013-02-07 00:24:17 +0000 | [diff] [blame] | 28 | then |
| 29 | MACOSX_DEPLOYMENT_TARGET=10.7 |
| 30 | fi |
Nick Kledzik | c7e4d82 | 2010-09-10 20:42:36 +0000 | [diff] [blame] | 31 | fi |
| 32 | |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 33 | if [ -z "$RC_ProjectSourceVersion" ] |
Nick Kledzik | c7e4d82 | 2010-09-10 20:42:36 +0000 | [diff] [blame] | 34 | then |
| 35 | RC_ProjectSourceVersion=1 |
| 36 | fi |
| 37 | |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 38 | EXTRA_FLAGS="-nostdinc++ -std=c++11 -fstrict-aliasing -Wall -Wextra -Wshadow -Wconversion \ |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 39 | -Wnewline-eof -Wpadded -Wmissing-prototypes -Wstrict-aliasing=2 \ |
Howard Hinnant | 61fe0ac | 2013-04-16 17:34:20 +0000 | [diff] [blame] | 40 | -Wstrict-overflow=4 " |
Howard Hinnant | d5fed03 | 2011-05-29 13:57:49 +0000 | [diff] [blame] | 41 | |
Howard Hinnant | adff489 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 42 | case $TRIPLE in |
| 43 | *-apple-*) |
Nick Kledzik | d982028 | 2011-05-06 01:13:20 +0000 | [diff] [blame] | 44 | if [ -z $RC_XBS ] |
Howard Hinnant | adff489 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 45 | then |
Howard Hinnant | 0e353f2 | 2010-08-11 18:11:36 +0000 | [diff] [blame] | 46 | RC_CFLAGS="-arch i386 -arch x86_64" |
Howard Hinnant | adff489 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 47 | fi |
| 48 | SOEXT=dylib |
Daniel Dunbar | fd329a4 | 2013-02-07 00:24:17 +0000 | [diff] [blame] | 49 | if [ "$MACOSX_DEPLOYMENT_TARGET" == "10.6" ] |
| 50 | then |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 51 | EXTRA_FLAGS="-nostdinc++ -std=c++11 -U__STRICT_ANSI__" |
Daniel Dunbar | fd329a4 | 2013-02-07 00:24:17 +0000 | [diff] [blame] | 52 | LDSHARED_FLAGS="-o libc++.1.dylib \ |
| 53 | -dynamiclib -nodefaultlibs -current_version 1 \ |
| 54 | -compatibility_version 1 \ |
| 55 | -install_name /usr/lib/libc++.1.dylib \ |
| 56 | -Wl,-reexport_library,/usr/lib/libc++abi.dylib \ |
| 57 | -Wl,-unexported_symbols_list,libc++unexp.exp \ |
| 58 | /usr/lib/libSystem.B.dylib" |
| 59 | else |
Daniel Dunbar | fd329a4 | 2013-02-07 00:24:17 +0000 | [diff] [blame] | 60 | if [ -n "$SDKROOT" ] |
| 61 | then |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 62 | EXTRA_FLAGS+="-nostdinc++ -isysroot ${SDKROOT}" |
Daniel Dunbar | fd329a4 | 2013-02-07 00:24:17 +0000 | [diff] [blame] | 63 | if echo "${RC_ARCHS}" | grep -q "armv7" |
| 64 | then |
| 65 | RE_EXPORT_LINE="${SDKROOT}/usr/lib/libc++abi.dylib -Wl,-reexported_symbols_list,libc++sjlj-abi.exp" |
| 66 | else |
| 67 | RE_EXPORT_LINE="-Wl,-reexport_library,${SDKROOT}/usr/lib/libc++abi.dylib" |
| 68 | fi |
| 69 | CXX=`xcrun -sdk "${SDKROOT}" -find clang++` |
| 70 | CC=`xcrun -sdk "${SDKROOT}" -find clang` |
Daniel Dunbar | 6afc7ad | 2013-02-07 00:24:19 +0000 | [diff] [blame] | 71 | else |
| 72 | # Check if we have _LIBCPPABI_VERSION, to determine the reexport list to use. |
| 73 | if (echo "#include <cxxabi.h>" | $CXX -E -dM -x c++ - | \ |
| 74 | grep _LIBCPPABI_VERSION > /dev/null) |
| 75 | then |
| 76 | RE_EXPORT_LINE="/usr/lib/libc++abi.dylib -Wl,-reexported_symbols_list,libc++abi2.exp" |
| 77 | else |
| 78 | RE_EXPORT_LINE="/usr/lib/libc++abi.dylib -Wl,-reexported_symbols_list,libc++abi.exp" |
| 79 | fi |
Daniel Dunbar | fd329a4 | 2013-02-07 00:24:17 +0000 | [diff] [blame] | 80 | fi |
| 81 | LDSHARED_FLAGS="-o libc++.1.dylib \ |
| 82 | -dynamiclib -nodefaultlibs \ |
| 83 | -current_version ${RC_ProjectSourceVersion} \ |
| 84 | -compatibility_version 1 \ |
| 85 | -install_name /usr/lib/libc++.1.dylib \ |
| 86 | -lSystem \ |
| 87 | -Wl,-unexported_symbols_list,libc++unexp.exp \ |
| 88 | ${RE_EXPORT_LINE} \ |
| 89 | -Wl,-force_symbols_not_weak_list,notweak.exp \ |
| 90 | -Wl,-force_symbols_weak_list,weak.exp" |
| 91 | fi |
Howard Hinnant | adff489 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 92 | ;; |
Howard Hinnant | efbe406 | 2011-09-28 21:39:20 +0000 | [diff] [blame] | 93 | *-*-mingw*) |
| 94 | # FIXME: removing libgcc and libsupc++ dependencies means porting libcxxrt and LLVM/compiler-rt |
| 95 | SOEXT=dll |
| 96 | LDSHARED_FLAGS="-o libc++.dll \ |
| 97 | -shared -nodefaultlibs -Wl,--export-all-symbols -Wl,--allow-multiple-definition -Wl,--out-implib,libc++.dll.a \ |
| 98 | -lsupc++ -lpthread -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcr100 -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt" |
Daniel Dunbar | fd329a4 | 2013-02-07 00:24:17 +0000 | [diff] [blame] | 99 | ;; |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 100 | *-ibm-*) |
| 101 | hostOS=`uname` |
| 102 | hostOS=`echo $hostOS | sed -e "s/\s+$//"` |
| 103 | hostOS=`echo $hostOS | tr '[A-Z]' '[a-z]'` |
| 104 | |
| 105 | if [ $hostOS == "linux" ] |
| 106 | then |
| 107 | LDSHARED_FLAGS="-o libc++.so.1 \ |
| 108 | -qmkshrobj -Wl,-soname,libc++.so.1 \ |
| 109 | -lpthread -lrt -lc -lstdc++" |
| 110 | EXTRA_FLAGS="-qlanglvl=extended0x -D__GLIBCXX__=1" |
| 111 | else |
| 112 | LDSHARED_FLAGS="-o shr.o -qmkshrobj -lpthread -bnoquiet" |
| 113 | EXTRA_FLAGS="-qlanglvl=extended0x" |
| 114 | fi |
| 115 | RC_CFLAGS="-qpic=large" |
| 116 | ;; |
Howard Hinnant | adff489 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 117 | *) |
| 118 | RC_CFLAGS="-fPIC" |
| 119 | SOEXT=so |
| 120 | LDSHARED_FLAGS="-o libc++.so.1.0 \ |
| 121 | -shared -nodefaultlibs -Wl,-soname,libc++.so.1 \ |
Howard Hinnant | d5fed03 | 2011-05-29 13:57:49 +0000 | [diff] [blame] | 122 | -lpthread -lrt -lc -lstdc++" |
Howard Hinnant | adff489 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 123 | ;; |
| 124 | esac |
| 125 | |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 126 | if [ -z "$RC_XBS" ] |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 127 | then |
Howard Hinnant | adff489 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 128 | rm -f libc++.1.$SOEXT* |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 129 | fi |
| 130 | |
| 131 | set -x |
| 132 | |
Howard Hinnant | adff489 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 133 | for FILE in ../src/*.cpp; do |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 134 | $CXX -c -g -Os $RC_CFLAGS $EXTRA_FLAGS -I../include $FILE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 135 | done |
Howard Hinnant | efbe406 | 2011-09-28 21:39:20 +0000 | [diff] [blame] | 136 | case $TRIPLE in |
| 137 | *-*-mingw*) |
| 138 | for FILE in ../src/support/win32/*.cpp; do |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 139 | $CXX -c -g -Os $RC_CFLAGS $EXTRA_FLAGS -I../include $FILE |
Howard Hinnant | efbe406 | 2011-09-28 21:39:20 +0000 | [diff] [blame] | 140 | done |
| 141 | ;; |
| 142 | esac |
Nick Kledzik | c6e08d6 | 2011-05-04 21:50:46 +0000 | [diff] [blame] | 143 | $CC *.o $RC_CFLAGS $LDSHARED_FLAGS $EXTRA_FLAGS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 144 | |
| 145 | #libtool -static -o libc++.a *.o |
| 146 | |
Daniel Dunbar | a38e2c9 | 2013-02-06 00:04:54 +0000 | [diff] [blame] | 147 | # Create the link for the final library name, so that we can use this directory |
| 148 | # as a link target for the tests. |
| 149 | case $TRIPLE in |
| 150 | *-apple-*) |
| 151 | rm -f libc++.dylib |
| 152 | ln -s libc++.1.dylib libc++.dylib |
| 153 | ;; |
| 154 | *-*-mingw*) |
| 155 | ;; |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 156 | *-ibm-*) |
| 157 | if [ $hostOS == "linux" ] |
| 158 | then |
| 159 | rm -f libc++.so |
| 160 | ln -s libc++.so.1 libc++.so |
| 161 | else #AIX |
| 162 | rm -f libc++.a |
| 163 | ar r libc++.a shr.o |
| 164 | fi |
| 165 | ;; |
Daniel Dunbar | a38e2c9 | 2013-02-06 00:04:54 +0000 | [diff] [blame] | 166 | *) |
| 167 | rm -f libc++.so |
| 168 | ln -s libc++.so.1 libc++.so |
| 169 | ;; |
| 170 | esac |
| 171 | |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 172 | if [ -z "$RC_XBS" ] |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 173 | then |
| 174 | rm *.o |
| 175 | fi |