-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-gcc.sh
executable file
·86 lines (61 loc) · 2.4 KB
/
build-gcc.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
#!/bin/sh
# usage: ./build-gcc.sh PREFIX
set -ex
PREFIX=$1
GCC_VERSION=14.2.0
mkdir -p build-gcc
cd build-gcc
../gcc/configure --target=$ARCH-lfi-linux-musl \
--disable-docs \
--disable-bootstrap \
--disable-libssp \
--disable-multilib \
--enable-languages=c,c++ \
--enable-lto \
--enable-shared \
--enable-default-pie \
--prefix=$PREFIX \
--with-pkgversion="LFI"
make all-gcc -j$(nproc --all)
make install-strip-gcc
GCC=$PREFIX/bin/$ARCH-lfi-linux-musl-gcc
mkdir -p lib/gcc
../specgen.sh $GCC > lib/gcc/specs
../specgen.sh $GCC > gcc/specs
mkdir -p $PREFIX/$ARCH-lfi-linux-musl/lib
../specgen.sh $GCC > $PREFIX/$ARCH-lfi-linux-musl/lib/specs
# install musl headers
cd ../musl
make clean
CC=$PREFIX/bin/$ARCH-lfi-linux-musl-gcc ./configure --prefix=$PREFIX --syslibdir=$PREFIX/$ARCH-lfi-linux-musl/lib --libdir=$PREFIX/$ARCH-lfi-linux-musl/lib --includedir=$PREFIX/$ARCH-lfi-linux-musl/include
# first install musl headers
make install-headers
# install crt start files and a dummy libc.so
make lib/crt1.o lib/crti.o lib/crtn.o
install lib/crt1.o lib/crti.o lib/crtn.o $PREFIX/$ARCH-lfi-linux-musl/lib
$PREFIX/bin/$ARCH-lfi-linux-musl-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $PREFIX/$ARCH-lfi-linux-musl/lib/libc.so
cd ../build-gcc
# now we can build libgcc (requires libc headers)
make all-target-libgcc -j$(nproc --all)
make install-target-libgcc
cd ../musl
make clean
CC=$PREFIX/bin/$ARCH-lfi-linux-musl-gcc ./configure --prefix=$PREFIX --syslibdir=$PREFIX/$ARCH-lfi-linux-musl/lib --libdir=$PREFIX/$ARCH-lfi-linux-musl/lib --includedir=$PREFIX/$ARCH-lfi-linux-musl/include --disable-gcc-wrapper
# now we can build libc (requires libgcc)
make -j$(nproc --all)
make install
# make the linker symlink relative so that if we move PREFIX around it doesn't break
rm $PREFIX/$ARCH-lfi-linux-musl/lib/ld-musl-$ARCH.so.1
ln -s libc.so $PREFIX/$ARCH-lfi-linux-musl/lib/ld-musl-$ARCH.so.1
# copy musl installation to build-gcc/gcc
cd ../build-gcc
cp -r $PREFIX/lib/gcc/$ARCH-lfi-linux-musl/$GCC_VERSION/* gcc
# now build libstdc++ (requires libc and libgcc)
make all-target-libstdc++-v3 -j$(nproc --all)
make install-target-libstdc++-v3
# add linux/limits.h
mkdir -p $PREFIX/$ARCH-lfi-linux-musl/include/linux
cp /usr/include/linux/limits.h $PREFIX/$ARCH-lfi-linux-musl/include/linux
# now build libgfortran
# make all-target-libgfortran -j$(nproc --all)
# make install-target-libgfortran