configure-iphone 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/bin/bash
  2. F="configure-iphone"
  3. if test "$*" = "--help" -o "$*" = "-h"; then
  4. echo "$F [OPTIONS]"
  5. echo ""
  6. echo "where:"
  7. echo " OPTIONS Other options that will be passed directly to"
  8. echo " ./aconfigure script. Run ./aconfigure --help"
  9. echo " for more info."
  10. echo ""
  11. echo "Environment variables:"
  12. echo " IPHONESDK Optionally specify which SDK to use. Value is the full "
  13. echo " path of the SDK. By default, the latest SDK installed"
  14. echo " will be used."
  15. echo " CC Optionally specify the path of the ARM cross compiler"
  16. echo " to use. By default, the compiler is deduced from the"
  17. echo " SDK."
  18. echo " ARCH Optional flags to specify target architecture, e.g."
  19. echo " ARCH=\"-arch armv7\". Default is arm64."
  20. echo " MIN_IOS Optional flags to specify minimum supported iOS"
  21. echo " versions, e.g. MIN_IOS=\"-miphoneos-version-min=11.0\". "
  22. echo " Default is 11.0."
  23. echo ""
  24. exit 0
  25. fi
  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. # Make sure $DEVPATH directory exist
  35. if test ! -d $DEVPATH; then
  36. echo "$F error: directory $DEVPATH does not exist. Please install iPhone development kit"
  37. exit 1
  38. fi
  39. # Choose SDK version to use
  40. if test "$IPHONESDK" = ""; then
  41. # If IPHONESDK is not set, use the latest one
  42. for f in `ls $DEVPATH/SDKs/`; do echo $f | sed 's/\(.sdk\)//'; done | sort | tail -1 > tmpsdkname
  43. IPHONESDK=`cat tmpsdkname`.sdk
  44. rm -f tmpsdkname
  45. SDKPATH=${DEVPATH}/SDKs/${IPHONESDK}
  46. echo "$F: IPHONESDK is not specified, choosing ${IPHONESDK}"
  47. elif test -d ${IPHONESDK}; then
  48. # .. else if IPHONESDK is set and it points to a valid path, just use it
  49. SDKPATH=${IPHONESDK}
  50. else
  51. # .. else assume the SDK name is used.
  52. SDKPATH=${DEVPATH}/SDKs/${IPHONESDK}
  53. fi
  54. # Test the SDK directory
  55. if test ! -d ${SDKPATH}/usr/include; then
  56. echo "$F error: unable to find valid iPhone SDK in ${SDKPATH}"
  57. exit 1
  58. fi
  59. # Default CFLAGS if it's not specified
  60. if test "$CFLAGS" = ""; then
  61. CFLAGS="-O2 -Wno-unused-label"
  62. fi
  63. # Default LDFLAGS if it's not specified
  64. if test "$LDFLAGS" = ""; then
  65. LDFLAGS="-O2"
  66. fi
  67. # Test the toolchain directory
  68. TCPATH="${DEVPATH}/../../../Toolchains/XcodeDefault.xctoolchain"
  69. if test ! -d ${TCPATH}/usr/bin; then
  70. TCPATH="${DEVPATH}"
  71. fi
  72. # Determine which gcc for this SDK. Binaries should have the
  73. # full path as it's not normally in user's PATH
  74. if test "${CC}" = ""; then
  75. # Try to use clang if available
  76. ccpath="${TCPATH}/usr/bin/clang"
  77. # Next, try to use llvm-gcc
  78. gccpath="${DEVPATH}/usr/bin/llvm-gcc"
  79. if test -e ${ccpath}; then
  80. export CC="${ccpath}"
  81. elif test -e ${gccpath}; then
  82. export CC="${gccpath}"
  83. 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
  97. fi
  98. if test "${CC}" = ""; then
  99. 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."
  100. exit 1
  101. fi
  102. if test "${ARCH}" = ""; then
  103. export ARCH="-arch arm64"
  104. echo "$F: ARCH is not specified, choosing ${ARCH}"
  105. fi
  106. export ARCH_VAL=`echo ${ARCH} | sed 's/\-arch //' | sed -e 's/^[ \t]*//;s/[ \t]*$//' `
  107. if test "${ARCH_VAL}" = "arm64e"; then
  108. export ARCH_VAL="arm64"
  109. fi
  110. if test "${MIN_IOS}" = ""; then
  111. MIN_IOS_VER="11.0"
  112. echo "$F: MIN_IOS is not specified, choosing ${MIN_IOS_VER}"
  113. MIN_IOS="-miphoneos-version-min=${MIN_IOS_VER}"
  114. fi
  115. CFLAGS="${CFLAGS} ${MIN_IOS}"
  116. LDFLAGS="${LDFLAGS} ${MIN_IOS}"
  117. # Set CXX if not set
  118. if test "${CXX}" = ""; then
  119. export CXX=`echo ${CC} | sed 's/clang/clang++/'`
  120. echo "$F: CXX is not specified, using ${CXX}"
  121. fi
  122. # Other settings to feed to configure script.
  123. #ARCH="-arch armv6"
  124. export CFLAGS="${CFLAGS} -DPJ_SDK_NAME=\"\\\"`basename $SDKPATH`\\\"\" ${ARCH} -isysroot ${SDKPATH}"
  125. export LDFLAGS="${LDFLAGS} ${ARCH} -isysroot ${SDKPATH} -framework AudioToolbox -framework Foundation"
  126. export AR="${TCPATH}/usr/bin/libtool -static -o"
  127. export AR_FLAGS=" "
  128. export 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
  131. export CPP="${CC} ${ARCH} -E -isysroot ${SDKPATH}"
  132. # Print settings
  133. if test "1" = "1"; then
  134. echo "$F: calling ./aconfigure with env vars:"
  135. echo " MIN_IOS = ${MIN_IOS}"
  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}"
  143. echo " ARCH = ${ARCH_VAL}"
  144. fi
  145. # And finally invoke the configure script itself
  146. ./aconfigure --host=${ARCH_VAL}-apple-darwin_ios --disable-sdl $*
  147. if test "$?" = "0"; then
  148. echo "Done configuring for `basename $SDKPATH`"
  149. echo ""
  150. fi