blob: dfe548e90573225ebeb327e1d8650e3304d734ac [file] [log] [blame]
Tristan Matthews0a329cc2013-07-17 13:20:14 -04001#!/bin/bash
2
3F="configure-iphone"
4
5if 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."
Alexandre Lision94f06ba2013-12-09 16:28:33 -050021 echo " ARCH='-arch armv6'. Default is armv7."
Tristan Matthews0a329cc2013-07-17 13:20:14 -040022 echo ""
23 exit 0
24fi
25
26# Set the main iPhone developer directory, if not set
27if 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}"
33fi
34
35# Make sure $DEVPATH directory exist
36if test ! -d $DEVPATH; then
37 echo "$F error: directory $DEVPATH does not exist. Please install iPhone development kit"
38 exit 1
39fi
40
41# Choose SDK version to use
42if 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}"
49elif test -d ${IPHONESDK}; then
50 # .. else if IPHONESDK is set and it points to a valid path, just use it
51 SDKPATH=${IPHONESDK}
52else
53 # .. else assume the SDK name is used.
54 SDKPATH=${DEVPATH}/SDKs/${IPHONESDK}
55fi
56
57# Test the SDK directory
58if test ! -d ${SDKPATH}/usr/include; then
59 echo "$F error: unable to find valid iPhone SDK in ${SDKPATH}"
60 exit 1
61fi
62
63# Default CFLAGS if it's not specified
64if test "$CFLAGS" = ""; then
65 CFLAGS="-O2 -Wno-unused-label"
66fi
67
68# Default LDFLAGS if it's not specified
69if test "$LDFLAGS" = ""; then
70 LDFLAGS="-O2"
71fi
72
Alexandre Lision94f06ba2013-12-09 16:28:33 -050073# Test the toolchain directory
74TCPATH="${DEVPATH}/../../../Toolchains/XcodeDefault.xctoolchain"
75if test ! -d ${TCPATH}/usr/bin; then
76 TCPATH="${DEVPATH}"
77fi
78
Tristan Matthews0a329cc2013-07-17 13:20:14 -040079# Determine which gcc for this SDK. Binaries should have the
80# full path as it's not normally in user's PATH
81
82if test "${CC}" = ""; then
Alexandre Lision94f06ba2013-12-09 16:28:33 -050083 # Try to use clang if available
84 ccpath="${TCPATH}/usr/bin/clang"
85 # Next, try to use llvm-gcc
Tristan Matthews0a329cc2013-07-17 13:20:14 -040086 gccpath="${DEVPATH}/usr/bin/llvm-gcc"
Alexandre Lision94f06ba2013-12-09 16:28:33 -050087 if test -e ${ccpath}; then
88 export CC="${ccpath}"
89 elif test -e ${gccpath}; then
Tristan Matthews0a329cc2013-07-17 13:20:14 -040090 export CC="${gccpath}"
Tristan Matthews0a329cc2013-07-17 13:20:14 -040091 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
105fi
106
107if 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
110fi
111
Alexandre Lision94f06ba2013-12-09 16:28:33 -0500112if test "${ARCH}" = ""; then
113 export ARCH="-arch armv7"
114 echo "$F: ARCH is not specified, choosing ${ARCH}"
115fi
116
Tristan Matthews0a329cc2013-07-17 13:20:14 -0400117# Set CXX if not set
118if test "${CXX}" = ""; then
119 export CXX=`echo ${CC} | sed 's/gcc/g++/'`
120 echo "$F: CXX is not specified, using ${CXX}"
121fi
122
123# Other settings to feed to configure script.
124#ARCH="-arch armv6"
125export CFLAGS="${CFLAGS} -DPJ_SDK_NAME=\"\\\"`basename $SDKPATH`\\\"\" ${ARCH} -isysroot ${SDKPATH}"
126export LDFLAGS="${LDFLAGS} ${ARCH} -isysroot ${SDKPATH} -framework AudioToolbox -framework Foundation"
Alexandre Lision94f06ba2013-12-09 16:28:33 -0500127export AR="${TCPATH}/usr/bin/libtool -static -o"
Tristan Matthews0a329cc2013-07-17 13:20:14 -0400128export RANLIB="echo ranlib"
129# Use gcc -E as preprocessor instead of cpp, since cpp will find the
130# header files in standard /usr/include instead of in isysroot
131export CPP="${CC} ${ARCH} -E -isysroot ${SDKPATH}"
132
133# Print settings
134if test "1" = "1"; then
135 echo "$F: calling ./aconfigure with env vars:"
136 echo " CC = ${CC}"
137 echo " CXX = ${CXX}"
138 echo " SDKPATH = ${SDKPATH}"
139 echo " CFLAGS = ${CFLAGS}"
140 echo " LDFLAGS = ${LDFLAGS}"
141 echo " AR = ${AR}"
142 echo " RANLIB = ${RANLIB}"
143fi
144
145# And finally invoke the configure script itself
146./aconfigure --host=arm-apple-darwin9 --disable-sdl $*
147
148if test "$?" = "0"; then
149 echo "Done configuring for `basename $SDKPATH`"
150 echo ""
151fi
152