forked from limine-bootloader/limine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_toolchain.sh
executable file
·91 lines (73 loc) · 2.27 KB
/
make_toolchain.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
#! /bin/sh
set -ex
srcdir="$(dirname "$0")"
test -z "$srcdir" && srcdir=.
cd "$srcdir"
TARGET=x86_64-elf
BINUTILSVERSION=2.38
GCCVERSION=11.2.0
NASMVERSION=2.15.05
if command -v gmake; then
export MAKE=gmake
else
export MAKE=make
fi
if command -v gtar; then
export TAR=gtar
else
export TAR=tar
fi
export CFLAGS="-O2 -pipe"
unset CC
unset CXX
if [ "$(uname)" = "OpenBSD" ]; then
# OpenBSD has an awfully ancient GCC which fails to build our toolchain.
# Force clang/clang++.
export CC="clang"
export CXX="clang++"
fi
mkdir -p toolchain && cd toolchain
PREFIX="$(pwd -P)"
export MAKEFLAGS="-j$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || psrinfo -tc 2>/dev/null || echo 1)"
export PATH="$PREFIX/bin:$PATH"
if [ ! -f binutils-$BINUTILSVERSION.tar.gz ]; then
curl -o binutils-$BINUTILSVERSION.tar.gz https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILSVERSION.tar.gz
fi
if [ ! -f gcc-$GCCVERSION.tar.gz ]; then
curl -o gcc-$GCCVERSION.tar.gz https://ftp.gnu.org/gnu/gcc/gcc-$GCCVERSION/gcc-$GCCVERSION.tar.gz
fi
if [ ! -f nasm-$NASMVERSION.tar.gz ]; then
curl -o nasm-$NASMVERSION.tar.gz https://limine-bootloader.org/files/misc/nasm-$NASMVERSION.tar.gz
fi
rm -rf build
mkdir build
cd build
$TAR -zxf ../binutils-$BINUTILSVERSION.tar.gz
$TAR -zxf ../gcc-$GCCVERSION.tar.gz
$TAR -zxf ../nasm-$NASMVERSION.tar.gz
mkdir build-binutils
cd build-binutils
../binutils-$BINUTILSVERSION/configure CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" --target=$TARGET --prefix="$PREFIX" --program-prefix=limine- --with-sysroot --disable-nls --disable-werror --enable-targets=x86_64-elf,x86_64-pe
$MAKE
$MAKE install
cd ..
cd gcc-$GCCVERSION
sed 's|http://gcc.gnu|https://gcc.gnu|g' < contrib/download_prerequisites > dp.sed
mv dp.sed contrib/download_prerequisites
chmod +x contrib/download_prerequisites
./contrib/download_prerequisites --no-verify
cd ..
mkdir build-gcc
cd build-gcc
../gcc-$GCCVERSION/configure CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" --target=$TARGET --prefix="$PREFIX" --program-prefix=limine- --disable-nls --enable-languages=c --without-headers
$MAKE all-gcc
$MAKE all-target-libgcc
$MAKE install-gcc
$MAKE install-target-libgcc
cd ..
mkdir build-nasm
cd build-nasm
../nasm-$NASMVERSION/configure --prefix="$PREFIX"
MAKEFLAGS="" $MAKE
MAKEFLAGS="" $MAKE install
cd ..