blob: 79bf226f99dba5bf4d71de8a9cf64e96d85032eb [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."
21 echo " ARCH='-arch armv6'"
22 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
73# Determine which gcc for this SDK. Binaries should have the
74# full path as it's not normally in user's PATH
75
76if test "${CC}" = ""; then
77 # Try to use llvm-gcc if available
78 gccpath="${DEVPATH}/usr/bin/llvm-gcc"
79 if test -e ${gccpath}; then
80 export CC="${gccpath}"
81
82 if test "${ARCH}" = ""; then
83 export ARCH="-arch armv7"
84 echo "$F: ARCH is not specified, choosing ${ARCH}"
85 fi
86 else
87 for archpath in `ls -d ${SDKPATH}/usr/lib/gcc/arm-apple-darwin*`; do
88 archname=`basename ${archpath}`
89 for gccver in `ls ${archpath}`; do
90 gccpath="${DEVPATH}/usr/bin/${archname}-gcc-${gccver}"
91 if test -e ${gccpath}; then
92 export CC="${gccpath}"
93 fi
94 done
95 done
96 fi
97 if test ! "${CC}" = ""; then
98 echo "$F: CC is not specified, choosing ${CC}"
99 fi
100fi
101
102if test "${CC}" = ""; then
103 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."
104 exit 1
105fi
106
107# Set CXX if not set
108if test "${CXX}" = ""; then
109 export CXX=`echo ${CC} | sed 's/gcc/g++/'`
110 echo "$F: CXX is not specified, using ${CXX}"
111fi
112
113# Other settings to feed to configure script.
114#ARCH="-arch armv6"
115export CFLAGS="${CFLAGS} -DPJ_SDK_NAME=\"\\\"`basename $SDKPATH`\\\"\" ${ARCH} -isysroot ${SDKPATH}"
116export LDFLAGS="${LDFLAGS} ${ARCH} -isysroot ${SDKPATH} -framework AudioToolbox -framework Foundation"
117export AR="${DEVPATH}/usr/bin/libtool -static -o"
118export RANLIB="echo ranlib"
119# Use gcc -E as preprocessor instead of cpp, since cpp will find the
120# header files in standard /usr/include instead of in isysroot
121export CPP="${CC} ${ARCH} -E -isysroot ${SDKPATH}"
122
123# Print settings
124if test "1" = "1"; then
125 echo "$F: calling ./aconfigure with env vars:"
126 echo " CC = ${CC}"
127 echo " CXX = ${CXX}"
128 echo " SDKPATH = ${SDKPATH}"
129 echo " CFLAGS = ${CFLAGS}"
130 echo " LDFLAGS = ${LDFLAGS}"
131 echo " AR = ${AR}"
132 echo " RANLIB = ${RANLIB}"
133fi
134
135# And finally invoke the configure script itself
136./aconfigure --host=arm-apple-darwin9 --disable-sdl $*
137
138if test "$?" = "0"; then
139 echo "Done configuring for `basename $SDKPATH`"
140 echo ""
141fi
142