blob: 5dc1f020025d6f729da2a2a1ff2bdebd552ff574 (
plain)
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
|
#!/bin/sh
# A small script to generate the chroot environment where building will take place
export WORKING_DIR="/var/lib/xib"
BUILDFILES_REPO_URL="https://xi.davidovski.xyz/git/buildfiles.git"
export SYSTEM_DIR="$WORKING_DIR/chroot"
TOOL_DIR="$SYSTEM_DIR/tools"
SOURCES="$SYSTEM_DIR/sources"
TGT=$(uname -m)-xi-linux-gnu
export PATH=/usr/bin
if [ ! -L /bin ]; then export PATH=/bin:$PATH; fi
export PATH=$SYSTEM_DIR/tools/bin:$PATH
packages=(binutils gcc linux glibc mpfr gmp mpc m4 ncurses bash coreutils diffutils file findutils gawk grep gzip make patch sed tar xz)
get_build_files() {
mkdir -p $WORKING_DIR/buildfiles
git clone "$BUILDFILES_REPO_URL" $WORKING_DIR/buildfiles
}
list_build_files() {
ls -1 $WORKING_DIR/buildfiles/repo/*/*.xibuild
}
parse_package_versions() {
for pkg_file in $(list_build_files); do
local pkg_name=$(basename -s .xibuild $pkg_file)
local pkg_ver=$(sed -n "s/^PKG_VER=\(.*\)$/\1/p" $pkg_file)
[ -z "$pkg_ver" ] && pkg_ver=$(sed -n "s/^BRANCH=\(.*\)$/\1/p" $pkg_file)
[ -z "$pkg_ver" ] && pkg_ver="latest"
printf "%-16s %16s\n" $pkg_name $pkg_ver
done
}
extract () {
FILE=$1
case "${FILE#*.}" in
"tar.gz" )
tar -zxf $FILE
;;
"tar.lz" )
tar --lzip -xf "$FILE"
;;
"zip" )
unzip $FILE
;;
* )
tar -xf $FILE
;;
esac
}
make_dir_struct() {
local system=$1
mkdir -pv $system/{etc,var,proc,sys,run,tmp} $system/usr/{bin,lib,sbin} $system/bin/{pts,shm}
for i in bin lib sbin; do
ln -sv usr/$i $system/$i
done
case $(uname -m) in
x86_64) mkdir -pv $system/lib64 ;;
esac
}
extract () {
FILE=$1
case "${FILE#*.}" in
"tar.gz" )
tar -zxf $FILE
;;
"tar.lz" )
tar --lzip -xf "$FILE"
;;
"zip" )
unzip $FILE
;;
* )
tar -xf $FILE
;;
esac
}
init_versions() {
local versions_file="$SYSTEM_DIR/versions"
[ -f $versions_file ] || exit 1
for i in ${packages[@]}; do
local name=${i^^}
local version=$(sed -n "s/^$i \s*\(.*\)$/\1/p" $versions_file)
eval "${i^^}_VERSION"="$version"
done
}
get_source() {
local buildfile="$1"
local package_name=$(basename -s .xibuild $buildfile)
echo "fetching $buildfile"
if [ ! -d $package_name ]; then
mkdir -p $package_name
cd $package_name
rm -rf *
source $buildfile
if git ls-remote -q $SOURCE $BRANCH &> /dev/null; then
git clone $SOURCE .
git checkout $BRANCH
elif hg identify $SOURCE &> /dev/null; then
hg clone $SOURCE package_name .
else
local downloaded=$(basename $SOURCE)
curl -Ls $SOURCE > $downloaded
extract $downloaded
mv */* .
fi
fi
}
get_sources() {
mkdir -p $SYSTEM_DIR/sources
for pkg in $@; do
local pkg_file="$WORKING_DIR/buildfiles/repo/*/$pkg.xibuild"
cd $SYSTEM_DIR/sources
get_source $pkg_file
done
}
# builds binutils to toolchain
#
build_binutils1() {
cd $SOURCES/binutils/
mkdir -v build
cd build
../configure --prefix="$SYSTEM_DIR/tools" \
--with-sysroot="$SYSTEM_DIR" \
--target=$TGT \
--disable-nls \
--disable-werror &&
make &&
make install -j1
}
# builds gcc to toolchain
#
build_gcc1() {
cd $SOURCES/gcc/
#rm -rf mpfr gmp mpc
[ -d mpfr ] || cp -r $SOURCES/mpfr mpfr
[ -d gmp ] || cp -r $SOURCES/gmp gmp
[ -d mpc ] || cp -r $SOURCES/mpc mpc
sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64
mkdir -v build
cd build
../configure \
--target=$TGT \
--prefix=$SYSTEM_DIR/tools \
--with-glibc-version=$GLIBC_VERSION \
--with-sysroot=$SYSTEM_DIR \
--with-newlib \
--without-headers \
--without-zstd \
--enable-initfini-array \
--disable-nls \
--disable-shared \
--disable-multilib \
--disable-decimal-float \
--disable-threads \
--disable-libatomic \
--disable-libgomp \
--disable-libquadmath \
--disable-libssp \
--disable-libvtv \
--disable-libstdcxx \
--enable-languages=c,c++
make &&
make install
cd ..
cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
`dirname $($TGT-gcc -print-libgcc-file-name)`/install-tools/include/limits.h
}
build_linux_headers() {
cd $SOURCES/linux/
make mrproper
make headers
find usr/include -name '.*' -delete
rm usr/include/Makefile
cp -rv usr/include $SYSTEM_DIR/usr
}
build_glibc() {
cd $SOURCES/glibc/
case $(uname -m) in
i?86) ln -sfv ld-linux.so.2 $SYSTEM_DIR/lib/ld-lsb.so.3
;;
x86_64) ln -sfv ../lib/ld-linux-x86-64.so.2 $SYSTEM_DIR/lib64
ln -sfv ../lib/ld-linux-x86-64.so.2 $SYSTEM_DIR/lib64/ld-lsb-x86-64.so.3
;;
esac
mkdir -v build
cd build
echo "rootsbindir=/usr/sbin" > configparms
../configure \
--prefix=/usr \
--host=$TGT \
--build=$(../scripts/config.guess) \
--enable-kernel=3.2 \
--with-headers=$SYSTEM_DIR/usr/include \
libc_cv_slibdir=/usr/lib
make &&
make DESTDIR=$SYSTEM_DIR install
sed '/RTLDLIST=/s@/usr@@g' -i $SYSTEM_DIR/usr/bin/ldd
$SYSTEM_DIR/tools/libexec/gcc/$TGT/$GCC_VERSION/install-tools/mkheaders
}
build_libstdcxx() {
cd $SOURCES/gcc/
rm -rf build
mkdir build
cd build
../libstdc++-v3/configure \
--host=$TGT \
--build=$(../config.guess) \
--prefix=/usr \
--disable-multilib \
--disable-nls \
--disable-libstdcxx-pch \
--with-gxx-include-dir=/tools/$SYSTEM_DIR/include/c++/$GCC_VERSION
make &&
make DESTDIR=$SYSTEM_DIR install
}
build_m4() {
cd $SOURCES/m4/
./configure --prefix=/usr \
--host=$TGT \
--build=$(build-aux/config.guess)
make
make DESTDIR=$SYSTEM_DIR install
}
build_ncurses() {
cd $SOURCES/ncurses/
sed -i s/mawk// configure
mkdir build
pushd build
../configure
make -C include
make -C progs tic
popd
./configure --prefix=/usr \
--host=$TGT \
--build=$(./config.guess) \
--mandir=/usr/share/man \
--with-manpage-format=normal \
--with-shared \
--without-debug \
--without-ada \
--without-normal \
--disable-stripping \
--enable-widec
make
make DESTDIR=$SYSTEM_DIR TIC_PATH=$(pwd)/build/progs/tic install
echo "INPUT(-lncursesw)" > $SYSTEM_DIR/usr/lib/libncurses.so
}
build_bash() {
cd $SOURCES/bash/
./configure --prefix=/usr \
--build=$(support/config.guess) \
--host=$TGT \
--without-bash-malloc
make
make DESTDIR=$SYSTEM_DIR install
ln -sv bash $SYSTEM_DIR/bin/sh
}
build_coreutils() {
cd $SOURCES/coreutils/
./configure --prefix=/usr \
--host=$TGT \
--build=$(build-aux/config.guess) \
--enable-install-program=hostname \
--enable-no-install-program=kill,uptime
make
make DESTDIR=$SYSTEM_DIR install
mv -v $SYSTEM_DIR/usr/bin/chroot $SYSTEM_DIR/usr/sbin
mkdir -pv $SYSTEM_DIR/usr/share/man/man8
mv -v $SYSTEM_DIR/usr/share/man/man1/chroot.1 $SYSTEM_DIR/usr/share/man/man8/chroot.8
sed -i 's/"1"/"8"/' $SYSTEM_DIR/usr/share/man/man8/chroot.8
}
build_diffutils() {
cd $SOURCES/diffutils/
./configure --prefix=/usr --host=$TGT
make
make DESTDIR=$SYSTEM_DIR install
}
build_file() {
cd $SOURCES/file/
mkdir build
pushd build
../configure --disable-bzlib \
--disable-libseccomp \
--disable-xzlib \
--disable-zlib
make
popd
./configure --prefix=/usr --host=$TGT --build=$(./config.guess)
make FILE_COMPILE=$(pwd)/build/src/file
make DESTDIR=$SYSTEM_DIR install
}
build_findutils() {
cd $SOURCES/findutils/
./configure --prefix=/usr \
--localstatedir=/var/lib/locate \
--host=$TGT \
--build=$(build-aux/config.guess)
make
make DESTDIR=$SYSTEM_DIR install
}
build_gawk() {
cd $SOURCES/gawk/
sed -i 's/extras//' Makefile.in
./configure --prefix=/usr \
--host=$TGT \
--build=$(build-aux/config.guess)
make
make DESTDIR=$SYSTEM_DIR install
}
build_grep() {
cd $SOURCES/grep
./configure --prefix=/usr \
--host=$TGT
make
make DESTDIR=$SYSTEM_DIR install
}
build_gzip() {
cd $SOURCES/gzip/
./configure --prefix=/usr --host=$TGT
make
make DESTDIR=$SYSTEM_DIR install
}
build_make() {
cd $SOURCES/make/
./configure --prefix=/usr \
--without-guile \
--host=$TGT \
--build=$(build-aux/config.guess)
make
make DESTDIR=$SYSTEM_DIR install
}
build_patch() {
cd $SOURCES/patch/
./configure --prefix=/usr \
--host=$TGT \
--build=$(build-aux/config.guess)
make
make DESTDIR=$SYSTEM_DIR install
}
build_sed() {
cd $SOURCES/sed/
./configure --prefix=/usr --host=$TGT
make
make DESTDIR=$SYSTEM_DIR install
}
build_tar() {
cd $SOURCES/tar/
./configure --prefix=/usr \
--host=$TGT \
--build=$(build-aux/config.guess)
make
make DESTDIR=$SYSTEM_DIR install
}
build_xz() {
cd $SOURCES/xz/
./configure --prefix=/usr \
--host=$TGT \
--build=$(build-aux/config.guess) \
--disable-static \
--docdir=/usr/share/doc/xz-$XZ_VERSION
make
make DESTDIR=$SYSTEM_DIR install
}
build_binutils2() {
cd $SOURCES/binutils/
make clean
rm -rf build
mkdir -v build
cd build
../configure \
--prefix=/usr \
--build=$(../config.guess) \
--host=$TGT \
--disable-nls \
--enable-shared \
--disable-werror \
--enable-64-bit-bfd
make
make DESTDIR=$SYSTEM_DIR install -j1
install -vm755 libctf/.libs/libctf.so.0.0.0 $SYSTEM_DIR/usr/lib
}
build_gcc2() {
cd $SOURCES/gcc/
rm -rf build
mkdir -v build
cd build
mkdir -pv $TGT/libgcc
ln -s ../../../libgcc/gthr-posix.h $TGT/libgcc/gthr-default.h
../configure \
--build=$(../config.guess) \
--host=$TGT \
--prefix=/usr \
CC_FOR_TARGET=$TGT-gcc \
--with-build-sysroot=$SYSTEM_DIR \
--enable-initfini-array \
--disable-nls \
--disable-multilib \
--disable-decimal-float \
--disable-libatomic \
--disable-libgomp \
--disable-libquadmath \
--disable-libssp \
--disable-libvtv \
--disable-libstdcxx \
--enable-languages=c,c++
make
make DESTDIR=$SYSTEM_DIR install
ln -sv gcc $SYSTEM_DIR/usr/bin/cc
}
mkdir -p "$SYSTEM_DIR"
get_build_files
parse_package_versions > "$SYSTEM_DIR/versions"
get_sources ${packages[@]}
make_dir_struct $SYSTEM_DIR
init_versions
cd $SYSTEM_DIR; printf "\033[0;34mbuilding binutils1...\033[0m"
build_binutils1 >> build.log && printf "passed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding gcc1...\033[0m"
build_gcc1 >> build.log && printf "passed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding linux headers...\033[0m"
build_linux_headers >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding glibc...\033[0m"
build_glibc >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding libstdc++...\033[0m"
build_libstdcxx >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding m4...\033[0m"
build_m4 && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding ncurses...\033[0m"
build_ncurses >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding bash...\033[0m"
build_bash >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding coreutils...\033[0m"
build_coreutils >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding diffutils...\033[0m"
build_diffutils >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding file...\033[0m"
build_file >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding findutils...\033[0m"
build_findutils >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding gawk...\033[0m"
build_gawk >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding grep...\033[0m"
build_grep >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding gzip...\033[0m"
build_gzip >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding make...\033[0m"
build_make >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding patch...\033[0m"
build_patch >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding sed...\033[0m"
build_sed >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding tar...\033[0m"
build_tar >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding xz...\033[0m"
build_xz >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding binutils2...\033[0m"
build_binutils2 >> build.log && printf "\033[0;32mpassed" || exit 1
cd $SYSTEM_DIR; printf "\033[0;34mbuilding gcc2...\033[0m"
build_gcc2 >> build.log && printf "\033[0;32mpassed" || exit 1
echo "DONE?"
|