-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·132 lines (96 loc) · 4.1 KB
/
build.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
#!/bin/bash
GCC_VERSION=12.2.0
GLIBC_VERSION=2.36
BINUTILS_VERSION=2.40
GDB_VERSION=10.2
LANGUAGES=c,c++,fortran
FOLDER_VERSION=64
KERNEL=kernel8
ARCH=armv8-a+fp+simd
TARGET=aarch64-linux-gnu
BUILDDIR=/tmp
DOWNLOADDIR=$BUILDDIR/build_toolchains
INSTALLDIR=$BUILDDIR/cross-pi-gcc-$GCC_VERSION-$FOLDER_VERSION
SYSROOTDIR=$BUILDDIR/cross-pi-gcc-$GCC_VERSION-$FOLDER_VERSION/$TARGET/libc
mkdir -p $DOWNLOADDIR
mkdir -p $INSTALLDIR
cd $DOWNLOADDIR
if [ ! -d "linux" ]; then
git clone --depth=1 https://github.com/raspberrypi/linux
fi
if [ ! -d "gcc-$GCC_VERSION" ]; then
wget -q https://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.gz
tar xf gcc-$GCC_VERSION.tar.gz
rm -f gcc-$GCC_VERSION.tar.gz
mkdir -p gcc-$GCC_VERSION/build
cd gcc-$GCC_VERSION
sed -i 's/#include <limits.h>/#include <linux\/limits.h>/' libsanitizer/asan/asan_linux.cpp # patch
contrib/download_prerequisites
rm -f *.tar.*
cd $DOWNLOADDIR
fi
if [ ! -d "binutils-$BINUTILS_VERSION" ]; then
wget -q https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VERSION.tar.bz2
tar xf binutils-$BINUTILS_VERSION.tar.bz2
rm -rf binutils-$BINUTILS_VERSION.tar.bz2
mkdir -p binutils-$BINUTILS_VERSION/build
fi
if [ ! -d "glibc-$GLIBC_VERSION" ]; then
wget -q https://ftp.gnu.org/gnu/glibc/glibc-$GLIBC_VERSION.tar.bz2
tar xf glibc-$GLIBC_VERSION.tar.bz2
rm -rf glibc-$GLIBC_VERSION.tar.bz2
mkdir -p glibc-$GLIBC_VERSION/build
fi
if [ ! -d "gdb-$GDB_VERSION" ]; then
wget -q https://ftp.gnu.org/gnu/gdb/gdb-$GDB_VERSION.tar.xz
tar xf gdb-$GDB_VERSION.tar.xz
rm -rf gdb-$GDB_VERSION.tar.xz
mkdir -p gdb-$GDB_VERSION/build
fi
PATH=$BUILDDIR/cross-pi-gcc-$GCC_VERSION-$FOLDER_VERSION/bin:$PATH
echo "Building Kernel Headers ..."
cd $DOWNLOADDIR/linux
make -s ARCH=arm64 INSTALL_HDR_PATH=$SYSROOTDIR/usr headers_install
mkdir -p $SYSROOTDIR/usr/lib
echo "Building Binutils ..."
rm -rf $DOWNLOADDIR/binutils-$BINUTILS_VERSION/build/*
cd $DOWNLOADDIR/binutils-$BINUTILS_VERSION/build
../configure --target=$TARGET --prefix= --with-arch=$ARCH --with-sysroot=/$TARGET/libc --with-build-sysroot=$SYSROOTDIR --disable-multilib
make -s -j$(nproc)
make -s install-strip DESTDIR=$INSTALLDIR
echo "Building GCC and glibc ..."
rm -rf $DOWNLOADDIR/gcc-$GCC_VERSION/build/*
cd $DOWNLOADDIR/gcc-$GCC_VERSION/build
../configure --prefix= --target=$TARGET --enable-languages=$LANGUAGES --with-sysroot=/$TARGET/libc --with-build-sysroot=$SYSROOTDIR --with-arch=$ARCH --disable-multilib
make -s -j$(nproc) all-gcc
make -s install-strip-gcc DESTDIR=$INSTALLDIR
rm -rf $DOWNLOADDIR/glibc-$GLIBC_VERSION/build/*
cd $DOWNLOADDIR/glibc-$GLIBC_VERSION/build
../configure --prefix=/usr --build=$MACHTYPE --host=$TARGET --target=$TARGET --with-arch=$ARCH --with-sysroot=/$TARGET/libc --with-build-sysroot=$SYSROOTDIR --with-headers=$SYSROOTDIR/usr/include --with-lib=$SYSROOTDIR/usr/lib --disable-multilib libc_cv_forced_unwind=yes
make -s install-bootstrap-headers=yes install-headers DESTDIR=$SYSROOTDIR
make -s -j$(nproc) csu/subdir_lib
install csu/crt1.o csu/crti.o csu/crtn.o $SYSROOTDIR/usr/lib
$TARGET-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $SYSROOTDIR/usr/lib/libc.so
touch $SYSROOTDIR/usr/include/gnu/stubs.h $SYSROOTDIR/usr/include/bits/stdio_lim.h
cd $DOWNLOADDIR/gcc-$GCC_VERSION/build
make -s -j$(nproc) all-target-libgcc
make -s install-target-libgcc DESTDIR=$INSTALLDIR
cd $DOWNLOADDIR/glibc-$GLIBC_VERSION/build
make -s -j$(nproc)
make -s install DESTDIR=$SYSROOTDIR
cd $DOWNLOADDIR/gcc-$GCC_VERSION/build
make -s -j$(nproc)
make -s install-strip DESTDIR=$INSTALLDIR
cd $DOWNLOADDIR"/gcc-"$GCC_VERSION
cat gcc/limitx.h gcc/glimits.h gcc/limity.h >$(dirname $($TARGET-gcc -print-libgcc-file-name))/include-fixed/limits.h
echo "Building GDB ..."
rm -rf $DOWNLOADDIR/gdb-$GDB_VERSION/build/*
cd $DOWNLOADDIR/gdb-$GDB_VERSION/build
../configure --prefix= --target=$TARGET --with-arch=$ARCH --with-float=hard
make -s -j$(nproc)
make -s install DESTDIR=$INSTALLDIR
echo "Creating TAR archive ..."
cd $BUILDDIR
tar czf cross-gcc-$GCC_VERSION-pi_$FOLDER_VERSION.tar.gz cross-pi-gcc-$GCC_VERSION-$FOLDER_VERSION
mkdir -p /out
mv cross-gcc-$GCC_VERSION-pi_$FOLDER_VERSION.tar.gz /out