Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / development / compilers / ios-cross-compile / 9.2_builder.sh
blob4eef8acb069343ac82884a35371236f2ce3fc4b2
1 # -*- shell-script -*-
2 if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
3 source $stdenv/setup
5 function extract
7 printf "extracting $(basename $1) ...\n"
8 local tarflags="xf"
10 case "$1" in
11 *.tar.xz)
12 xz -dc $1 | tar "$tarflags" - ;;
14 printf "Make sure you give a iPhoneOS9.2.sdk.tar.xz file \n" ;;
15 esac
18 function verify_arch {
19 case "$1" in
20 # Our good arches.
21 armv7|arm64) ;;
23 local
24 acc="armv7 | arm64"
25 error_message=$(
26 printf '%s is not an acceptable arch. Try one of %s' "$1" "$acc"
28 printf "$error_message\n"
29 exit
30 esac
33 function verify_sdk_version {
34 sdk_version=$(basename "$1" | grep -P -o "[0-9].[0-9]+")
35 case "$sdk_version" in
36 # Make sure the SDK is correct.
37 [5-9].[0-9]) ;;
39 printf 'No iPhone SDK version in file name\n'
40 esac
43 function do_build {
45 if [ $# -lt 2 ]; then
46 printf "usage: $0 iPhoneOS.sdk.tar* <target cpu>\n" 1>&2
47 printf "i.e. $0 /path/to/iPhoneOS.sdk.tar.xz armv7\n" 1>&2
48 exit 1
51 mkdir -p $out
53 chmod -R 755 "$cctools_port"
55 pushd "$cctools_port"/usage_examples/ios_toolchain &> /dev/null
57 export LC_ALL=C
59 local
60 triple='%s-apple-darwin11'
61 target_dir="$PWD/target"
62 sdk_dir="$target_dir/SDK"
63 platform="$(uname -s)"
64 # Will be mutated by verify_sdk_version
65 sdk_version=
67 mkdir -p "$target_dir"
68 mkdir -p "$target_dir/bin"
69 mkdir -p "$sdk_dir"
71 verify_arch "$2"
72 verify_sdk_version "$1"
74 triple="$(printf "$triple" "$2")"
75 pushd "$sdk_dir" &>/dev/null
76 extract "$1"
78 local sys_lib=$(
79 find $sdk_dir -name libSystem.dylib -o -name libSystem.tbd | head -n1
82 if [ -z "$sys_lib" ]; then
83 printf "SDK should contain libSystem{.dylib,.tbd}\n" 1>&2
84 exit 1
87 local sys_root=$(readlink -f "$(dirname $sys_lib)/../..")
89 local sdk_unboxed=$(basename $sys_root)
91 mv -f "$sys_root"/* "$sdk_dir" || true
93 popd &>/dev/null
95 printf "\nbuilding wrapper\n"
97 printf "int main(){return 0;}" | clang -xc -O2 -o "$target_dir"/bin/dsymutil -
99 clang -O2 -std=c99 $alt_wrapper \
100 -DTARGET_CPU=$(printf '"%s"' "$2") \
101 -DNIX_APPLE_HDRS=$(
102 printf '"%s"' "-I$out/$sdk/usr/include"
104 -DNIX_APPLE_FRAMEWORKS=$(
105 printf '"%s"' "$out/$sdk/System/Library/Frameworks"
107 -DNIX_APPLE_PRIV_FRAMEWORKS=$(
108 printf '"%s"' "$out/$sdk/System/Library/PrivateFrameworks"
110 -DOS_VER_MIN=$(printf '"%s"' "7.1") \
111 -o "$target_dir/bin/$triple-clang"
113 pushd "$target_dir"/bin &>/dev/null
115 cp "$triple"-clang "$triple"-clang++
117 popd &>/dev/null
119 printf "\nbuilding ldid\n"
121 mkdir -p tmp
122 pushd tmp &>/dev/null
123 pushd "$ldid" &>/dev/null
125 chmod -R 755 "$ldid"
127 make INSTALLPREFIX="$target_dir" -j4 install
128 popd &>/dev/null
129 popd &>/dev/null
131 printf "\nbuilding cctools / ld64\n"
133 pushd ../../cctools &>/dev/null
134 git clean -fdx . &>/dev/null || true
135 ./autogen.sh
136 ./configure --target="$triple" --prefix="$target_dir"
137 make -j4
138 make install &>/dev/null
140 popd &>/dev/null
142 local me=`whoami`
144 for d in bin libexec SDK; do
145 chown -R $me:$me target/$d
146 cp -R target/$d $out
147 done
149 # Crucial piece
150 rm -rf $out/$sdk
151 mv $out/SDK $out/$sdk
154 do_build $src armv7