2022-01-21 04:24:36 +03:00
|
|
|
#! /bin/sh
|
2021-03-08 10:09:15 +03:00
|
|
|
|
2021-07-26 17:09:03 +03:00
|
|
|
set -ex
|
2021-03-08 10:09:15 +03:00
|
|
|
|
2022-01-22 05:10:25 +03:00
|
|
|
srcdir="$(dirname "$0")"
|
2022-01-21 04:57:31 +03:00
|
|
|
test -z "$srcdir" && srcdir=.
|
|
|
|
|
|
|
|
cd "$srcdir"
|
|
|
|
|
2021-03-08 10:09:15 +03:00
|
|
|
TARGET=x86_64-elf
|
2021-07-26 17:09:03 +03:00
|
|
|
BINUTILSVERSION=2.37
|
2021-07-31 21:18:43 +03:00
|
|
|
GCCVERSION=11.2.0
|
2021-03-08 10:09:15 +03:00
|
|
|
|
2022-01-21 04:57:31 +03:00
|
|
|
if command -v gmake; then
|
|
|
|
export MAKE=gmake
|
|
|
|
else
|
|
|
|
export MAKE=make
|
|
|
|
fi
|
|
|
|
|
2022-01-22 05:10:25 +03:00
|
|
|
if command -v gtar; then
|
|
|
|
export TAR=gtar
|
|
|
|
else
|
|
|
|
export TAR=tar
|
|
|
|
fi
|
|
|
|
|
2022-01-21 04:24:36 +03:00
|
|
|
export CFLAGS="-O2 -pipe"
|
|
|
|
|
|
|
|
unset CC
|
|
|
|
unset CXX
|
2021-04-03 01:48:38 +03:00
|
|
|
|
2021-07-26 19:27:05 +03:00
|
|
|
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
|
|
|
|
|
2022-01-21 04:57:31 +03:00
|
|
|
mkdir -p toolchain && cd toolchain
|
2022-01-22 05:10:25 +03:00
|
|
|
PREFIX="$(pwd -P)"
|
2021-03-08 10:09:15 +03:00
|
|
|
|
2022-01-22 05:10:25 +03:00
|
|
|
export MAKEFLAGS="-j$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || psrinfo -tc 2>/dev/null || echo 1)"
|
2021-03-08 10:09:15 +03:00
|
|
|
|
|
|
|
export PATH="$PREFIX/bin:$PATH"
|
|
|
|
|
|
|
|
if [ ! -f binutils-$BINUTILSVERSION.tar.gz ]; then
|
2021-07-06 01:02:28 +03:00
|
|
|
curl -o binutils-$BINUTILSVERSION.tar.gz https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILSVERSION.tar.gz
|
2021-03-08 10:09:15 +03:00
|
|
|
fi
|
|
|
|
if [ ! -f gcc-$GCCVERSION.tar.gz ]; then
|
2021-07-06 01:02:28 +03:00
|
|
|
curl -o gcc-$GCCVERSION.tar.gz https://ftp.gnu.org/gnu/gcc/gcc-$GCCVERSION/gcc-$GCCVERSION.tar.gz
|
2021-03-08 10:09:15 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
rm -rf build
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
|
2022-01-22 05:10:25 +03:00
|
|
|
$TAR -zxf ../binutils-$BINUTILSVERSION.tar.gz
|
|
|
|
$TAR -zxf ../gcc-$GCCVERSION.tar.gz
|
2021-03-08 10:09:15 +03:00
|
|
|
|
|
|
|
mkdir build-binutils
|
|
|
|
cd build-binutils
|
2021-08-06 06:05:50 +03:00
|
|
|
../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
|
2021-07-26 17:09:03 +03:00
|
|
|
$MAKE
|
|
|
|
$MAKE install
|
2021-03-08 10:09:15 +03:00
|
|
|
cd ..
|
|
|
|
|
|
|
|
cd gcc-$GCCVERSION
|
2022-01-22 05:10:25 +03:00
|
|
|
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
|
2021-03-08 10:09:15 +03:00
|
|
|
cd ..
|
|
|
|
mkdir build-gcc
|
|
|
|
cd build-gcc
|
2021-08-06 06:05:50 +03:00
|
|
|
../gcc-$GCCVERSION/configure CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" --target=$TARGET --prefix="$PREFIX" --program-prefix=limine- --disable-nls --enable-languages=c --without-headers
|
2021-07-26 17:09:03 +03:00
|
|
|
$MAKE all-gcc
|
|
|
|
$MAKE all-target-libgcc
|
|
|
|
$MAKE install-gcc
|
|
|
|
$MAKE install-target-libgcc
|
2021-03-08 10:09:15 +03:00
|
|
|
cd ..
|