-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathautobuild.sh
executable file
·256 lines (216 loc) · 4.88 KB
/
autobuild.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/bin/sh -e
#Define arg_c to avoid illegal number warnings
arg_c=0
help_function() {
printf %b \
"Usage: $0 [-ch]\n" \
'\t-c\tenable color output\n' \
'\t-h\tprint this help screen\n'
exit 0
}
print_info() {
if [ "$arg_c" -eq "1" ]; then
printf "%b" "\033[1;36m$1\n\033[m"
else
printf "%b" "$1\n"
fi
}
print_err() {
if [ "$arg_c" -eq 1 ]; then
printf "%b" "\033[0;31m$1\n\033[m"
else
printf "%b" "$1\n"
fi
}
on_exit() {
print_err "ERROR: the last step killed me :("
if [ $SILENT -eq 1 ]; then
print_err "HELP: use tail on the last step in the log directory."
fi
}
trap on_exit EXIT
SILENT=0
DEBUG=0
while getopts "chsd" opt
do
case "$opt" in
c ) arg_c=1 ;;
h ) help_function ;;
s ) SILENT=1;;
d ) DEBUG=1;;
? ) help_function ;;
esac
done
mkdir -p build
cd build
if [ "$DEBUG" -eq 0 ]; then
[ -d 'iglunix-bootstrap' ] || git clone --depth=1 https://github.com/iglunix/iglunix-bootstrap
[ -d 'iglunix' ] || git clone --depth=1 https://github.com/iglunix/iglunix
[ -d 'iglupkg' ] || git clone --depth=1 https://github.com/iglunix/iglupkg
cd iglunix-bootstrap
git pull
cd ..
cd iglunix
git pull
cd ..
cd iglupkg
git pull
cd ..
fi
SYSROOT_S2=$(pwd)/sysroot
IP=$(pwd)/iglupkg/
LOGS=$(pwd)/logs
mkdir -p $LOGS
print_info "=== STAGE 1 === Build cross toolchain"
cd iglunix-bootstrap
if command -V bad 2> /dev/null; then
if [ $SILENT -eq 0 ]; then
MAKE=gmake bad --gmake ./boot.sh
else
MAKE=gmake bad --gmake ./boot.sh 2>$LOGS/boot.1.err > $LOGS/boot.1.out
fi
else
if [ $SILENT -eq 0 ]; then
MAKE=make ./boot.sh
else
MAKE=make ./boot.sh 2>$LOGS/boot.1.err > $LOGS/boot.1.out
fi
fi
SYSROOT_S1=$(pwd)/sysroot
export CC=$(pwd)/x86_64-iglunix-linux-musl-cc.sh
export CXX_INCL=$(pwd)/x86_64-iglunix-linux-musl-c++.sh
export CXX_NOINCL=$(pwd)/x86_64-iglunix-linux-musl-c++-no-incl.sh
export CXX=$CXX_INCL
cd ..
print_info "=== STAGE 1 === Done"
s2_build() {
PKGDIR=$1
PKGNAME=$2
cd $1/$2
print_info "== Building $1/$2 =="
if [ $SILENT -eq 0 ]; then
[ -f .s2 ] || ${IP}iglupkg.sh --with-cross=x86_64 --with-cross-dir=$SYSROOT_S1 --for-cross --for-cross-dir= fbp
else
[ -f .s2 ] || ${IP}iglupkg.sh --with-cross=x86_64 --with-cross-dir=$SYSROOT_S1 --for-cross --for-cross-dir= fbp 2>$LOGS/$2.1.err > $LOGS/$2.1.out
fi
touch .s2
cd ../../
}
s2e_build() {
PKGDIR=$1
PKGNAME=$2
cd $1/$2
print_info "== Building $1/$2 =="
if [ $SILENT -eq 0 ]; then
[ -f .s2 ] || ${IP}iglupkg.sh --with-cross=x86_64 --with-cross-dir=$SYSROOT_S2 --for-cross --for-cross-dir= fbp
else
[ -f .s2 ] || ${IP}iglupkg.sh --with-cross=x86_64 --with-cross-dir=$SYSROOT_S2 --for-cross --for-cross-dir= fbp 2>$LOGS/$2.1.err > $LOGS/$2.1.out
fi
touch .s2
cd ../../
}
s2_extract() {
PKGDIR=$1
PKGNAME=$2
cd $1/$2/out
print_info "== Extracting $1/$2 =="
tar -xf $2-*.tar.zst -C $SYSROOT_S2 -I zstd
cd ../../../
}
cd iglunix
print_info "=== STAGE 2 === Build cross libs"
s2_build linux musl
# NOTE: this will only build the headers! Look at the build.sh for more information.
s2_build linux linux
s2_build base libunwind
export CXX=$CXX_NOINCL
s2_build base libcxx
export CXX=$CXX_INCL
print_info "=== STAGE 2 === Assemble sysroot"
mkdir -p $SYSROOT_S2
s2_extract linux musl
s2_extract linux linux
s2_extract base libunwind
s2_extract base libcxx
print_info "=== STAGE 2 === Build extra libs"
s2e_build base zlib-ng
sync
s2_extract base zlib-ng
s2e_build base libelf
sync
s2_extract base libelf
s2e_build base openssl
sync
s2_extract base openssl
print_info "=== STAGE 3 === Build target packages"
s3_build() {
PKGDIR=$1
PKGNAME=$2
cd $1/$2
print_info "== Building $1/$2 =="
if [ $SILENT -eq 0 ]; then
[ -f .s3 ] || ${IP}iglupkg.sh --with-cross=x86_64 --with-cross-dir=$SYSROOT_S2 fbp
else
[ -f .s3 ] || ${IP}iglupkg.sh --with-cross=x86_64 --with-cross-dir=$SYSROOT_S2 fbp 2>$LOGS/$2.1.err > $LOGS/$2.1.out
fi
touch .s3
# 2>$LOGS/$2.2.err > $LOGS/$2.2.out
cd ../../
}
s3_build linux limine
s3_build linux linux
s3_build linux make_ext4fs
s3_build linux musl
s3_build linux busybox
s3_build base mksh
s3_build base toybox
s3_build base compiler-rt
s3_build base libunwind
export CXX=$CXX_NOINCL
s3_build base libcxx
export CXX=$CXX_INCL
s3_build base llvm
s3_build base oslo
s3_build base zlib-ng
s3_build base bmake
s3_build base byacc
s3_build base curl
s3_build base openssl
s3_build base doas
s3_build base expat
s3_build base flex
s3_build base libelf
s3_build base man-pages-posix
s3_build base netbsd-curses
#s3_build base om4
s3_build base samurai
s3_build base zstd
s3_build bad bad
s3_build bad gmake
touch .autobuilt
trap - EXIT
# TODO
# - add wrapper scripts to use stage 2 sysroot in stage 3 instead of stage 1.
# - get whole of base cross compiling
# order to build packages
#
# build stage 1 cross toolchain with stage 0:
#
# linux
# musl
# libunwind
# libcxx
# ...
#
# build stage 2 final packages
#
# linux
# musl
# libunwind
# libcxx
# llvm
#
# mksh
# toybox
# busybox
# clang