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