blob: 29dfcbc2b7e6020588cfac8f4c64e286b0beb342 [file] [log] [blame]
Benny Prijono8ec5eae2010-05-12 10:59:20 +00001#!/bin/bash
2
Benny Prijonoc02fdd62010-05-13 04:35:16 +00003F="configure-iphone"
4
Benny Prijono8ec5eae2010-05-12 10:59:20 +00005if test "$*" = "--help" -o "$*" = "-h"; then
Benny Prijonoc02fdd62010-05-13 04:35:16 +00006 echo "$F [OPTIONS]"
Benny Prijono8ec5eae2010-05-12 10:59:20 +00007 echo ""
Benny Prijonoc02fdd62010-05-13 04:35:16 +00008 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."
Benny Prijono9f1d73e2010-10-13 23:57:11 +000020 echo " ARCH Optional flags to specify target architecture, e.g."
21 echo " ARCH='-arch armv6'"
Benny Prijono8ec5eae2010-05-12 10:59:20 +000022 echo ""
23 exit 0
24fi
25
Benny Prijono8ec5eae2010-05-12 10:59:20 +000026# Set the main iPhone developer directory, if not set
27if test "x${DEVPATH}" = "x"; then
28 DEVPATH=/Developer/Platforms/iPhoneOS.platform/Developer
Benny Prijonoc02fdd62010-05-13 04:35:16 +000029 echo "$F: DEVPATH is not specified, using ${DEVPATH}"
Benny Prijono8ec5eae2010-05-12 10:59:20 +000030fi
31
32# Make sure $DEVPATH directory exist
33if test ! -d $DEVPATH; then
34 echo "$F error: directory $DEVPATH does not exist. Please install iPhone development kit"
35 exit 1
36fi
37
38# Choose SDK version to use
Benny Prijonofd71d3a2010-05-13 00:04:51 +000039if test "$IPHONESDK" = ""; then
40 # If IPHONESDK is not set, use the latest one
Benny Prijono8ec5eae2010-05-12 10:59:20 +000041 for f in `ls $DEVPATH/SDKs/`; do echo $f | sed 's/\(.sdk\)//'; done | sort | tail -1 > tmpsdkname
Benny Prijonofd71d3a2010-05-13 00:04:51 +000042 IPHONESDK=`cat tmpsdkname`.sdk
Benny Prijono8ec5eae2010-05-12 10:59:20 +000043 rm -f tmpsdkname
Benny Prijonofd71d3a2010-05-13 00:04:51 +000044 SDKPATH=${DEVPATH}/SDKs/${IPHONESDK}
Benny Prijonoa9866ae2010-05-13 04:57:13 +000045 echo "$F: IPHONESDK is not specified, choosing ${IPHONESDK}"
Benny Prijonofd71d3a2010-05-13 00:04:51 +000046elif test -d ${IPHONESDK}; then
47 # .. else if IPHONESDK is set and it points to a valid path, just use it
48 SDKPATH=${IPHONESDK}
Benny Prijono8ec5eae2010-05-12 10:59:20 +000049else
50 # .. else assume the SDK name is used.
Benny Prijonofd71d3a2010-05-13 00:04:51 +000051 SDKPATH=${DEVPATH}/SDKs/${IPHONESDK}
Benny Prijono8ec5eae2010-05-12 10:59:20 +000052fi
53
54# Test the SDK directory
55if test ! -d ${SDKPATH}/usr/include; then
56 echo "$F error: unable to find valid iPhone SDK in ${SDKPATH}"
57 exit 1
58fi
59
Benny Prijonofd71d3a2010-05-13 00:04:51 +000060# Default CFLAGS if it's not specified
61if test "$CFLAGS" = ""; then
62 CFLAGS="-O2 -Wno-unused-label"
63fi
64
65# Default LDFLAGS if it's not specified
66if test "$LDFLAGS" = ""; then
67 LDFLAGS="-O2"
68fi
69
Benny Prijonoc02fdd62010-05-13 04:35:16 +000070# Determine which gcc for this SDK. Binaries should have the
Benny Prijonofd71d3a2010-05-13 00:04:51 +000071# full path as it's not normally in user's PATH
Benny Prijonoc02fdd62010-05-13 04:35:16 +000072
73if test "${CC}" = ""; then
Sauw Minge7dbbc82011-10-24 09:28:13 +000074 # Try to use llvm-gcc if available
75 gccpath="${DEVPATH}/usr/bin/llvm-gcc"
76 if test -e ${gccpath}; then
77 export CC="${gccpath}"
78
79 if test "${ARCH}" = ""; then
80 export ARCH="-arch armv7"
81 echo "$F: ARCH is not specified, choosing ${ARCH}"
Benny Prijonoc02fdd62010-05-13 04:35:16 +000082 fi
Sauw Minge7dbbc82011-10-24 09:28:13 +000083 else
84 for archpath in `ls -d ${SDKPATH}/usr/lib/gcc/arm-apple-darwin*`; do
85 archname=`basename ${archpath}`
86 for gccver in `ls ${archpath}`; do
87 gccpath="${DEVPATH}/usr/bin/${archname}-gcc-${gccver}"
88 if test -e ${gccpath}; then
89 export CC="${gccpath}"
90 fi
91 done
92 done
93 fi
94 if test ! "${CC}" = ""; then
95 echo "$F: CC is not specified, choosing ${CC}"
96 fi
Benny Prijonoc02fdd62010-05-13 04:35:16 +000097fi
98
99if test "${CC}" = ""; then
100 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."
101 exit 1
102fi
103
104# Set CXX if not set
105if test "${CXX}" = ""; then
106 export CXX=`echo ${CC} | sed 's/gcc/g++/'`
107 echo "$F: CXX is not specified, using ${CXX}"
108fi
109
110# Other settings to feed to configure script.
Benny Prijonoa9866ae2010-05-13 04:57:13 +0000111#ARCH="-arch armv6"
Sauw Ming6a970a32011-03-01 05:25:27 +0000112export CFLAGS="${CFLAGS} -DPJ_SDK_NAME=\"\\\"`basename $SDKPATH`\\\"\" ${ARCH} -isysroot ${SDKPATH}"
Benny Prijonoa9866ae2010-05-13 04:57:13 +0000113export LDFLAGS="${LDFLAGS} ${ARCH} -isysroot ${SDKPATH} -framework AudioToolbox -framework Foundation"
Benny Prijono8ec5eae2010-05-12 10:59:20 +0000114export AR="${DEVPATH}/usr/bin/libtool -static -o"
115export RANLIB="echo ranlib"
116# Use gcc -E as preprocessor instead of cpp, since cpp will find the
Benny Prijonofd71d3a2010-05-13 00:04:51 +0000117# header files in standard /usr/include instead of in isysroot
Benny Prijono9f1d73e2010-10-13 23:57:11 +0000118export CPP="${CC} ${ARCH} -E -isysroot ${SDKPATH}"
Benny Prijono8ec5eae2010-05-12 10:59:20 +0000119
Benny Prijonoc02fdd62010-05-13 04:35:16 +0000120# Print settings
121if test "1" = "1"; then
Benny Prijonoa9866ae2010-05-13 04:57:13 +0000122 echo "$F: calling ./aconfigure with env vars:"
Benny Prijonoc02fdd62010-05-13 04:35:16 +0000123 echo " CC = ${CC}"
124 echo " CXX = ${CXX}"
125 echo " SDKPATH = ${SDKPATH}"
126 echo " CFLAGS = ${CFLAGS}"
Benny Prijonoa9866ae2010-05-13 04:57:13 +0000127 echo " LDFLAGS = ${LDFLAGS}"
Benny Prijonoc02fdd62010-05-13 04:35:16 +0000128 echo " AR = ${AR}"
Benny Prijonoa9866ae2010-05-13 04:57:13 +0000129 echo " RANLIB = ${RANLIB}"
Benny Prijonoc02fdd62010-05-13 04:35:16 +0000130fi
131
Benny Prijonofd71d3a2010-05-13 00:04:51 +0000132# And finally invoke the configure script itself
Benny Prijono8ec5eae2010-05-12 10:59:20 +0000133./aconfigure --host=arm-apple-darwin9 --disable-floating-point $*
134
Benny Prijonofd71d3a2010-05-13 00:04:51 +0000135if test "$?" = "0"; then
136 echo "Done configuring for `basename $SDKPATH`"
137 echo ""
138fi
139