This repository has been archived on 2024-06-25. You can view files and clone it, but cannot push or open issues or pull requests.
rockOS/build-toolchain.sh

91 lines
2.4 KiB
Bash
Raw Permalink Normal View History

2022-07-21 18:09:22 +03:00
#!/bin/sh
2022-07-30 17:55:30 +03:00
set -e
2022-07-21 18:09:22 +03:00
2022-07-22 17:50:10 +03:00
echo "Welcome to rockOS toolchain compilation script, where would you like to install your toolchain?"
echo "Leave blank for $HOME/opt/cross-i686"
2022-07-21 18:09:22 +03:00
read PREFIX
if [ "$PREFIX" == "" ]; then
export PREFIX="$HOME/opt/cross-i686"
fi
2022-07-22 17:50:10 +03:00
echo "This is the location you chose: $PREFIX"
echo "Press Enter to continue"
read continue
2022-07-21 18:09:22 +03:00
export TARGET=i686-elf
export PATH="$PREFIX/bin:$PATH"
export BINUTILS_LINK=https://ftp.gnu.org/gnu/binutils/binutils-2.38.tar.gz
export GCC_LINK=https://ftp.gnu.org/gnu/gcc/gcc-12.1.0/gcc-12.1.0.tar.gz
export GRUB_LINK=https://ftp.gnu.org/gnu/grub/grub-2.06.tar.gz
2022-07-30 17:55:30 +03:00
if [ "$(uname)" == "Darwin" ]; then
export NPROC="sysctl -n hw.physicalcpu"
else
export NPROC="nproc"
fi
2022-07-21 18:09:22 +03:00
if command -V wget >/dev/null 2>&1; then
export DL_CMD="wget"
export DL_OUTPUT="-O"
elif command -V curl >/dev/null 2>&1; then
export DL_CMD="curl"
export DL_OUTPUT="-o"
else
echo "Please install curl or wget"
exit 1
fi
mkdir -p "$PREFIX"
cd /tmp
2022-07-30 17:55:30 +03:00
rm -rf rockos-toolchain-src
2022-07-21 18:09:22 +03:00
mkdir rockos-toolchain-src
cd rockos-toolchain-src
2022-07-30 17:55:30 +03:00
$(echo $DL_CMD) $DL_OUTPUT binutils.tar.gz $BINUTILS_LINK
2022-07-21 18:09:22 +03:00
mkdir binutils-src
tar -xvf binutils.tar.gz -C ./binutils-src/
mkdir build-binutils
cd build-binutils
../binutils-src/*/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
2022-07-30 17:55:30 +03:00
make -j$($NPROC)
2022-07-21 18:09:22 +03:00
make install
cd ..
2022-07-30 17:55:30 +03:00
$(echo $DL_CMD) $DL_OUTPUT gcc.tar.gz $GCC_LINK
2022-07-21 18:09:22 +03:00
mkdir gcc-src
tar -xvf gcc.tar.gz -C ./gcc-src/
2022-07-30 17:55:30 +03:00
cd gcc-src/*/
./contrib/download_prerequisites
cd ../../
2022-07-21 18:09:22 +03:00
mkdir build-gcc
cd build-gcc
../gcc-src/*/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
2022-07-30 17:55:30 +03:00
make -j$($NPROC) all-gcc
make -j$($NPROC) all-target-libgcc
2022-07-21 18:09:22 +03:00
make install-gcc
make install-target-libgcc
cd ..
if [ "$(uname)" == "Darwin" ]; then
2022-07-30 17:55:30 +03:00
$(echo $DL_CMD) $DL_OUTPUT grub.tar.gz $GRUB_LINK
2022-07-21 18:09:22 +03:00
mkdir grub-src
tar -xvf grub.tar.gz -C ./grub-src/
mkdir build-grub
cd build-grub
../grub-src/*/configure --target=$TARGET --prefix="$PREFIX" TARGET_CC=$TARGET-gcc TARGET_OBJCOPY=$TARGET-objcopy TARGET_STRIP=$TARGET-strip TARGET_NM=$TARGET-nm TARGET_RANLIB=$TARGET-ranlib --disable-nls --disable-werror
2022-07-30 17:55:30 +03:00
make -j$($NPROC)
2022-07-21 18:09:22 +03:00
make install
cd ..
fi
2022-07-30 17:55:30 +03:00
rm -rf /tmp/rockos-toolchain-src
2022-07-21 18:09:22 +03:00
cd
echo "Toolchain installation is complete!"
echo "Please add this to your bashrc or zshrc or whatever"
2022-07-30 17:55:30 +03:00
echo "export \$PATH=\"$PREFIX/bin:\$PATH\""