Luna/tools/setup-gcc.sh
2022-09-05 16:13:51 +02:00

42 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
set -e
source $(dirname $0)/setup-env.sh
cd $LUNA_ROOT
if [ ! -x $(command -v x86_64-elf-as) ]
then
echo Binutils should be cross-built before GCC.
exit 1
fi
mkdir -p toolchain/tarballs
mkdir -p toolchain/build
if [ ! -f toolchain/tarballs/gcc-$LUNA_GCC_VERSION_REQUIRED.tar.xz ]; then
echo Downloading GCC...
wget -Otoolchain/tarballs/gcc-$LUNA_GCC_VERSION_REQUIRED.tar.xz https://ftp.gnu.org/gnu/gcc/gcc-$LUNA_GCC_VERSION_REQUIRED/gcc-$LUNA_GCC_VERSION_REQUIRED.tar.xz
fi
echo Extracting GCC...
tar xf toolchain/tarballs/gcc-$LUNA_GCC_VERSION_REQUIRED.tar.xz -C toolchain/build/
echo Configuring GCC...
mkdir -p toolchain/build/gcc
cd toolchain/build/gcc
../gcc-$LUNA_GCC_VERSION_REQUIRED/configure --prefix="$PREFIX" --target=$TARGET --disable-nls --enable-languages=c,c++ --without-headers
echo Building GCC...
make all-gcc -j$(nproc)
make all-target-libgcc -j$(nproc) CFLAGS_FOR_TARGET='-g -O2 -mcmodel=large -mno-red-zone'
echo Installing GCC...
make install-gcc
make install-target-libgcc