]> git.saurik.com Git - cycript.git/blob - apple-configure.sh
Unify the build environment for Android and Apple.
[cycript.git] / apple-configure.sh
1 #!/usr/bin/env bash
2
3 # Cycript - The Truly Universal Scripting Language
4 # Copyright (C) 2009-2016 Jay Freeman (saurik)
5
6 # GNU Affero General Public License, Version 3 {{{
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
17 #
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # }}}
21
22 set -e
23
24 cd "${0%%/*}"
25
26 flags=("$@")
27 ccf=(-g0 -O3)
28
29 function path() {
30 xcodebuild -sdk "$1" -version Path
31 }
32
33 xcs=$(xcode-select --print-path)
34 mac=$(path macosx)
35 xct="${xcs}/Toolchains/XcodeDefault.xctoolchain/usr/lib"
36
37 system=1
38
39 function configure() {
40 local dir=$1
41 local sdk=$2
42 local arc=$3
43 local min=$4
44 local ffi=$5
45 local cpf=$6
46 local ldf=$7
47 local obc=$8
48 shift 8
49
50 set -- "$@" --enable-static --with-pic
51
52 cc=$(xcrun --sdk "${sdk}" -f clang)
53 cxx=$(xcrun --sdk "${sdk}" -f clang++)
54
55 flg="-arch ${arc} ${min}"
56 flg+=" -isysroot $(path "${sdk}")"
57
58 rm -rf build."${dir}"
59 mkdir build."${dir}"
60 cd build."${dir}"
61
62 if "${ffi}"; then
63 cpf+=" -I../libffi.${arch}/include"
64 ldf+=" -L../libffi.${arch}/.libs"
65 fi
66
67 cpf+=" -I../libuv/include"
68 ldf+=" -L../libuv.${arch}/.libs"
69
70 ../configure --enable-maintainer-mode "${flags[@]}" --prefix="/usr" "$@" \
71 --with-libclang="-rpath ${xct} ${xct}/libclang.dylib" \
72 CC="${cc} ${flg}" CXX="${cxx} ${flg}" OBJCXX="${cxx} ${flg}" \
73 CFLAGS="${ccf[*]}" CXXFLAGS="${ccf[*]}" OBJCXXFLAGS="${ccf[*]} ${obc}" \
74 CPPFLAGS="${cpf}" LDFLAGS="${ldf}" CY_SYSTEM="$((1<<system++))"
75
76 cd ..
77 }
78
79 for arch in i386 x86_64; do
80 configure "osx-${arch}" "${mac}" "${arch}" "-mmacosx-version-min=10.6" \
81 false "-I../readline.osx" "-L../readline.osx" "" \
82 --with-python=/usr/bin/python-config
83 done
84
85 for arch in i386 x86_64; do
86 configure "sim-${arch}" iphonesimulator "${arch}" "-mios-simulator-version-min=4.0" \
87 true "" "" "-fobjc-abi-version=2 -fobjc-legacy-dispatch" \
88 --disable-console
89 done
90
91 for arch in armv6 armv7 armv7s arm64; do
92 cpf=""
93 ldf=""
94
95 flg=()
96 if [[ ${arch} != armv6 ]]; then
97 flg+=(--disable-console)
98 else
99 flg+=(LTLIBGCC="-lgcc_s.1")
100 cpf+=" -include ${PWD}/xcode.h"
101 cpf+=" -mllvm -arm-reserve-r9"
102 cpf+=" -I../sysroot.ios/usr/include"
103 ldf+=" -L../sysroot.ios/usr/lib"
104 fi
105
106 if [[ ${arch} == arm64 ]]; then
107 min=7.0
108 else
109 min=2.0
110 ldf+=" -Wl,-segalign,4000"
111 #cpf+=" -mthumb"
112 fi
113
114 configure "ios-${arch}" iphoneos "${arch}" "-miphoneos-version-min=${min}" \
115 true "${cpf[*]}" "${ldf[*]}" "" \
116 --host=arm-apple-darwin10 LFLAGS="--ecs --meta-ecs" "${flg[@]}"
117 done