]> git.saurik.com Git - cydia.git/blob - sysroot.sh
Separate out extract() in syroot.sh.
[cydia.git] / sysroot.sh
1 #!/usr/bin/env bash
2
3 if [[ ${BASH_VERSION} != 4* ]]; then
4 echo "bash 4.0 required" 1>&2
5 exit 1
6 fi
7
8 set -o pipefail
9 set -e
10
11 shopt -s extglob
12 shopt -s nullglob
13
14 for command in unlzma wget; do
15 if ! which "${command}" &>/dev/null; then
16 echo "Cannot run \`${command}\`. Please read compiling.txt." 1>&2
17 exit 1
18 fi
19 done
20
21 if tar --help | grep bsdtar &>/dev/null; then
22 echo "Running \`tar\` is bsdtar :(. Please read compiling.txt." 1>&2
23 exit 1
24 fi
25
26 rm -rf sysroot
27 mkdir sysroot
28 cd sysroot
29
30 repository=http://apt.saurik.com/
31 distribution=tangelo
32 component=main
33 architecture=iphoneos-arm
34
35 declare -A dpkgz
36 dpkgz[gz]=gunzip
37 dpkgz[lzma]=unlzma
38
39 function extract() {
40 package=$1
41 url=$2
42
43 wget -O "${package}.deb" "${url}"
44 for z in lzma gz; do
45 compressed=data.tar.${z}
46
47 if ar -x "${package}.deb" "${compressed}" 2>/dev/null; then
48 ${dpkgz[${z}]} "${compressed}"
49 break
50 fi
51 done
52
53 if ! [[ -e data.tar ]]; then
54 echo "unable to extract package" 1>&2
55 exit 1
56 fi
57
58 ls -la data.tar
59 tar -xf ./data.tar
60 rm -f data.tar
61 }
62
63 wget -qO- "${repository}dists/${distribution}/${component}/binary-${architecture}/Packages.bz2" | bzcat | {
64 regex='^([^ \t]*): *(.*)'
65 declare -A fields
66
67 while IFS= read -r line; do
68 if [[ ${line} == '' ]]; then
69 package=${fields[package]}
70 if [[ ${package} == *(apr|apr-lib|apt7|apt7-lib|coreutils|mobilesubstrate|pcre) ]]; then
71 filename=${fields[filename]}
72 extract "${package}" "${repository}${filename}"
73 fi
74
75 unset fields
76 declare -A fields
77 elif [[ ${line} =~ ${regex} ]]; then
78 name=${BASH_REMATCH[1],,}
79 value=${BASH_REMATCH[2]}
80 fields[${name}]=${value}
81 fi
82 done
83 }
84
85 rm -f *.deb
86
87 if substrate=$(readlink usr/include/substrate.h); then
88 if [[ ${substrate} == /* ]]; then
89 ln -sf "../..${substrate}" usr/include/substrate.h
90 fi
91 fi
92
93 mkdir -p usr/include
94 cd usr/include
95
96 mkdir CoreFoundation
97 wget -O CoreFoundation/CFBundlePriv.h "http://www.opensource.apple.com/source/CF/CF-550/CFBundlePriv.h?txt"
98 wget -O CoreFoundation/CFPriv.h "http://www.opensource.apple.com/source/CF/CF-550/CFPriv.h?txt"
99 wget -O CoreFoundation/CFUniChar.h "http://www.opensource.apple.com/source/CF/CF-550/CFUniChar.h?txt"
100
101 if true; then
102 mkdir -p WebCore
103 wget -O WebCore/WebCoreThread.h 'http://www.opensource.apple.com/source/WebCore/WebCore-658.28/wak/WebCoreThread.h?txt'
104 else
105 wget -O WebCore.tgz http://www.opensource.apple.com/tarballs/WebCore/WebCore-658.28.tar.gz
106 tar -zx --transform 's@^[^/]*/@WebCore.d/@' -f WebCore.tgz
107
108 mkdir WebCore
109 cp -a WebCore.d/{*,rendering/style,platform/graphics/transforms}/*.h WebCore
110 cp -a WebCore.d/platform/{animation,graphics,network,text}/*.h WebCore
111 cp -a WebCore.d/{accessibility,platform{,/{graphics,network,text}}}/{cf,mac,iphone}/*.h WebCore
112 cp -a WebCore.d/bridge/objc/*.h WebCore
113
114 wget -O JavaScriptCore.tgz http://www.opensource.apple.com/tarballs/JavaScriptCore/JavaScriptCore-554.1.tar.gz
115 #tar -zx --transform 's@^[^/]*/API/@JavaScriptCore/@' -f JavaScriptCore.tgz $(tar -ztf JavaScriptCore.tgz | grep '/API/[^/]*.h$')
116 tar -zx \
117 --transform 's@^[^/]*/@@' \
118 --transform 's@^icu/@@' \
119 -f JavaScriptCore.tgz $(tar -ztf JavaScriptCore.tgz | sed -e '
120 /\/icu\/unicode\/.*\.h$/ p;
121 /\/profiler\/.*\.h$/ p;
122 /\/runtime\/.*\.h$/ p;
123 /\/wtf\/.*\.h$/ p;
124 d;
125 ')
126 fi
127
128 for framework in ApplicationServices CoreServices IOKit IOSurface JavaScriptCore WebKit; do
129 ln -s /System/Library/Frameworks/"${framework}".framework/Headers "${framework}"
130 done
131
132 for framework in /System/Library/Frameworks/CoreServices.framework/Frameworks/*.framework; do
133 name=${framework}
134 name=${name%.framework}
135 name=${name##*/}
136 ln -s "${framework}/Headers" "${name}"
137 done
138
139 mkdir -p Cocoa
140 cat >Cocoa/Cocoa.h <<EOF
141 #define NSImage UIImage
142 #define NSView UIView
143 #define NSWindow UIWindow
144
145 #define NSPoint CGPoint
146 #define NSRect CGRect
147
148 #define NSPasteboard UIPasteboard
149 #define NSSelectionAffinity int
150 @protocol NSUserInterfaceValidations;
151 EOF
152
153 mkdir -p GraphicsServices
154 cat >GraphicsServices/GraphicsServices.h <<EOF
155 typedef struct __GSEvent *GSEventRef;
156 typedef struct __GSFont *GSFontRef;
157 EOF