Alexandre Lision | 8af73cb | 2013-12-10 14:11:20 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | F="configure-iphone" |
| 4 | |
| 5 | if test "$*" = "--help" -o "$*" = "-h"; then |
| 6 | echo "$F [OPTIONS]" |
| 7 | echo "" |
| 8 | echo "where:" |
| 9 | echo " OPTIONS Other options that will be passed directly to" |
| 10 | echo " ./aconfigure script. Run ./aconfigure --help" |
| 11 | echo " for more info." |
| 12 | echo "" |
| 13 | echo "Environment variables:" |
| 14 | echo " IPHONESDK Optionally specify which SDK to use. Value is the full " |
| 15 | echo " path of the SDK. By default, the latest SDK installed" |
| 16 | echo " will be used." |
| 17 | echo " CC Optionally specify the path of the ARM cross compiler" |
| 18 | echo " to use. By default, the compiler is deduced from the" |
| 19 | echo " SDK." |
| 20 | echo " ARCH Optional flags to specify target architecture, e.g." |
| 21 | echo " ARCH='-arch armv6'. Default is armv7." |
| 22 | echo "" |
| 23 | exit 0 |
| 24 | fi |
| 25 | |
| 26 | # Set the main iPhone developer directory, if not set |
| 27 | if test "x${DEVPATH}" = "x"; then |
| 28 | DEVPATH=/Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer |
| 29 | if test ! -d $DEVPATH; then |
| 30 | DEVPATH=/Developer/Platforms/iPhoneOS.platform/Developer |
| 31 | fi |
| 32 | echo "$F: DEVPATH is not specified, using ${DEVPATH}" |
| 33 | fi |
| 34 | |
| 35 | # Make sure $DEVPATH directory exist |
| 36 | if test ! -d $DEVPATH; then |
| 37 | echo "$F error: directory $DEVPATH does not exist. Please install iPhone development kit" |
| 38 | exit 1 |
| 39 | fi |
| 40 | |
| 41 | # Choose SDK version to use |
| 42 | if test "$IPHONESDK" = ""; then |
| 43 | # If IPHONESDK is not set, use the latest one |
| 44 | for f in `ls $DEVPATH/SDKs/`; do echo $f | sed 's/\(.sdk\)//'; done | sort | tail -1 > tmpsdkname |
| 45 | IPHONESDK=`cat tmpsdkname`.sdk |
| 46 | rm -f tmpsdkname |
| 47 | SDKPATH=${DEVPATH}/SDKs/${IPHONESDK} |
| 48 | echo "$F: IPHONESDK is not specified, choosing ${IPHONESDK}" |
| 49 | elif test -d ${IPHONESDK}; then |
| 50 | # .. else if IPHONESDK is set and it points to a valid path, just use it |
| 51 | SDKPATH=${IPHONESDK} |
| 52 | else |
| 53 | # .. else assume the SDK name is used. |
| 54 | SDKPATH=${DEVPATH}/SDKs/${IPHONESDK} |
| 55 | fi |
| 56 | |
| 57 | # Test the SDK directory |
| 58 | if test ! -d ${SDKPATH}/usr/include; then |
| 59 | echo "$F error: unable to find valid iPhone SDK in ${SDKPATH}" |
| 60 | exit 1 |
| 61 | fi |
| 62 | |
| 63 | # Default CFLAGS if it's not specified |
| 64 | if test "$CFLAGS" = ""; then |
| 65 | CFLAGS="-O2 -Wno-unused-label" |
| 66 | fi |
| 67 | |
| 68 | # Default LDFLAGS if it's not specified |
| 69 | if test "$LDFLAGS" = ""; then |
| 70 | LDFLAGS="-O2" |
| 71 | fi |
| 72 | |
| 73 | # Test the toolchain directory |
| 74 | TCPATH="${DEVPATH}/../../../Toolchains/XcodeDefault.xctoolchain" |
| 75 | if test ! -d ${TCPATH}/usr/bin; then |
| 76 | TCPATH="${DEVPATH}" |
| 77 | fi |
| 78 | |
| 79 | # Determine which gcc for this SDK. Binaries should have the |
| 80 | # full path as it's not normally in user's PATH |
| 81 | |
| 82 | if test "${CC}" = ""; then |
| 83 | # Try to use clang if available |
| 84 | ccpath="${TCPATH}/usr/bin/clang" |
| 85 | # Next, try to use llvm-gcc |
| 86 | gccpath="${DEVPATH}/usr/bin/llvm-gcc" |
| 87 | if test -e ${ccpath}; then |
| 88 | export CC="${ccpath}" |
| 89 | elif test -e ${gccpath}; then |
| 90 | export CC="${gccpath}" |
| 91 | else |
| 92 | for archpath in `ls -d ${SDKPATH}/usr/lib/gcc/arm-apple-darwin*`; do |
| 93 | archname=`basename ${archpath}` |
| 94 | for gccver in `ls ${archpath}`; do |
| 95 | gccpath="${DEVPATH}/usr/bin/${archname}-gcc-${gccver}" |
| 96 | if test -e ${gccpath}; then |
| 97 | export CC="${gccpath}" |
| 98 | fi |
| 99 | done |
| 100 | done |
| 101 | fi |
| 102 | if test ! "${CC}" = ""; then |
| 103 | echo "$F: CC is not specified, choosing ${CC}" |
| 104 | fi |
| 105 | fi |
| 106 | |
| 107 | if test "${CC}" = ""; then |
| 108 | echo "$F error: unable to find gcc for ${IPHONESDK}. If you think you have the right gcc, set the full path in CC environment variable." |
| 109 | exit 1 |
| 110 | fi |
| 111 | |
| 112 | if test "${ARCH}" = ""; then |
| 113 | export ARCH="-arch armv7" |
| 114 | echo "$F: ARCH is not specified, choosing ${ARCH}" |
| 115 | fi |
| 116 | |
| 117 | # Set CXX if not set |
| 118 | if test "${CXX}" = ""; then |
| 119 | export CXX=`echo ${CC} | sed 's/gcc/g++/'` |
| 120 | echo "$F: CXX is not specified, using ${CXX}" |
| 121 | fi |
| 122 | |
| 123 | # Other settings to feed to configure script. |
| 124 | #ARCH="-arch armv6" |
| 125 | export CFLAGS="${CFLAGS} -DPJ_SDK_NAME=\"\\\"`basename $SDKPATH`\\\"\" ${ARCH} -isysroot ${SDKPATH}" |
| 126 | export LDFLAGS="${LDFLAGS} ${ARCH} -isysroot ${SDKPATH} -framework AudioToolbox -framework Foundation" |
| 127 | export AR="${TCPATH}/usr/bin/libtool -static -o" |
| 128 | export AR_FLAGS=" " |
| 129 | export RANLIB="echo ranlib" |
| 130 | # Use gcc -E as preprocessor instead of cpp, since cpp will find the |
| 131 | # header files in standard /usr/include instead of in isysroot |
| 132 | export CPP="${CC} ${ARCH} -E -isysroot ${SDKPATH}" |
| 133 | |
| 134 | # Print settings |
| 135 | if test "1" = "1"; then |
| 136 | echo "$F: calling ./aconfigure with env vars:" |
| 137 | echo " CC = ${CC}" |
| 138 | echo " CXX = ${CXX}" |
| 139 | echo " SDKPATH = ${SDKPATH}" |
| 140 | echo " CFLAGS = ${CFLAGS}" |
| 141 | echo " LDFLAGS = ${LDFLAGS}" |
| 142 | echo " AR = ${AR}" |
| 143 | echo " RANLIB = ${RANLIB}" |
| 144 | fi |
| 145 | |
| 146 | # And finally invoke the configure script itself |
| 147 | ./aconfigure --host=arm-apple-darwin9 --disable-sdl $* |
| 148 | |
| 149 | if test "$?" = "0"; then |
| 150 | echo "Done configuring for `basename $SDKPATH`" |
| 151 | echo "" |
| 152 | fi |
| 153 | |