blob: 79bf226f99dba5bf4d71de8a9cf64e96d85032eb [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
Benny Prijono28d3c562012-03-30 07:10:13 +000028 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
Benny Prijonoc02fdd62010-05-13 04:35:16 +000032 echo "$F: DEVPATH is not specified, using ${DEVPATH}"
Benny Prijono8ec5eae2010-05-12 10:59:20 +000033fi
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
Benny Prijonofd71d3a2010-05-13 00:04:51 +000042if test "$IPHONESDK" = ""; then
43 # If IPHONESDK is not set, use the latest one
Benny Prijono8ec5eae2010-05-12 10:59:20 +000044 for f in `ls $DEVPATH/SDKs/`; do echo $f | sed 's/\(.sdk\)//'; done | sort | tail -1 > tmpsdkname
Benny Prijonofd71d3a2010-05-13 00:04:51 +000045 IPHONESDK=`cat tmpsdkname`.sdk
Benny Prijono8ec5eae2010-05-12 10:59:20 +000046 rm -f tmpsdkname
Benny Prijonofd71d3a2010-05-13 00:04:51 +000047 SDKPATH=${DEVPATH}/SDKs/${IPHONESDK}
Benny Prijonoa9866ae2010-05-13 04:57:13 +000048 echo "$F: IPHONESDK is not specified, choosing ${IPHONESDK}"
Benny Prijonofd71d3a2010-05-13 00:04:51 +000049elif test -d ${IPHONESDK}; then
50 # .. else if IPHONESDK is set and it points to a valid path, just use it
51 SDKPATH=${IPHONESDK}
Benny Prijono8ec5eae2010-05-12 10:59:20 +000052else
53 # .. else assume the SDK name is used.
Benny Prijonofd71d3a2010-05-13 00:04:51 +000054 SDKPATH=${DEVPATH}/SDKs/${IPHONESDK}
Benny Prijono8ec5eae2010-05-12 10:59:20 +000055fi
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
Benny Prijonofd71d3a2010-05-13 00:04:51 +000063# 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
Benny Prijonoc02fdd62010-05-13 04:35:16 +000073# Determine which gcc for this SDK. Binaries should have the
Benny Prijonofd71d3a2010-05-13 00:04:51 +000074# full path as it's not normally in user's PATH
Benny Prijonoc02fdd62010-05-13 04:35:16 +000075
76if test "${CC}" = ""; then
Sauw Minge7dbbc82011-10-24 09:28:13 +000077 # 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}"
Benny Prijonoc02fdd62010-05-13 04:35:16 +000085 fi
Sauw Minge7dbbc82011-10-24 09:28:13 +000086 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
Benny Prijonoc02fdd62010-05-13 04:35:16 +0000100fi
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.
Benny Prijonoa9866ae2010-05-13 04:57:13 +0000114#ARCH="-arch armv6"
Sauw Ming6a970a32011-03-01 05:25:27 +0000115export CFLAGS="${CFLAGS} -DPJ_SDK_NAME=\"\\\"`basename $SDKPATH`\\\"\" ${ARCH} -isysroot ${SDKPATH}"
Benny Prijonoa9866ae2010-05-13 04:57:13 +0000116export LDFLAGS="${LDFLAGS} ${ARCH} -isysroot ${SDKPATH} -framework AudioToolbox -framework Foundation"
Benny Prijono8ec5eae2010-05-12 10:59:20 +0000117export 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
Benny Prijonofd71d3a2010-05-13 00:04:51 +0000120# header files in standard /usr/include instead of in isysroot
Benny Prijono9f1d73e2010-10-13 23:57:11 +0000121export CPP="${CC} ${ARCH} -E -isysroot ${SDKPATH}"
Benny Prijono8ec5eae2010-05-12 10:59:20 +0000122
Benny Prijonoc02fdd62010-05-13 04:35:16 +0000123# Print settings
124if test "1" = "1"; then
Benny Prijonoa9866ae2010-05-13 04:57:13 +0000125 echo "$F: calling ./aconfigure with env vars:"
Benny Prijonoc02fdd62010-05-13 04:35:16 +0000126 echo " CC = ${CC}"
127 echo " CXX = ${CXX}"
128 echo " SDKPATH = ${SDKPATH}"
129 echo " CFLAGS = ${CFLAGS}"
Benny Prijonoa9866ae2010-05-13 04:57:13 +0000130 echo " LDFLAGS = ${LDFLAGS}"
Benny Prijonoc02fdd62010-05-13 04:35:16 +0000131 echo " AR = ${AR}"
Benny Prijonoa9866ae2010-05-13 04:57:13 +0000132 echo " RANLIB = ${RANLIB}"
Benny Prijonoc02fdd62010-05-13 04:35:16 +0000133fi
134
Benny Prijonofd71d3a2010-05-13 00:04:51 +0000135# And finally invoke the configure script itself
Nanang Izzuddind4abcc02012-10-08 09:05:45 +0000136./aconfigure --host=arm-apple-darwin9 --disable-sdl $*
Benny Prijono8ec5eae2010-05-12 10:59:20 +0000137
Benny Prijonofd71d3a2010-05-13 00:04:51 +0000138if test "$?" = "0"; then
139 echo "Done configuring for `basename $SDKPATH`"
140 echo ""
141fi
142