From d63195f775be90a5a9b9ea09a752629b383b8b11 Mon Sep 17 00:00:00 2001 From: Furkan Mudanyali Date: Sat, 30 Jul 2022 17:55:30 +0300 Subject: [PATCH] Build script fixes --- README.md | 7 ++++--- build-toolchain.sh | 33 ++++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 83be4a5..c2d7871 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,9 @@ such as QEMU or Virtualbox, bare-metal not tested. - grub2 (if under GNU/Linux) - xorriso - make -- tar (for compiling the toolchain) -- wget/curl (for compiling the toolchain) +- tar +### Dependencies for compiling toolchain +- wget/curl If it is your first time building, you need to compile the toolchain first. For that, you just need to run build-toolchain.sh, which will download binutils, @@ -45,4 +46,4 @@ you can run qemu.sh to compile and open the OS on QEMU or iso.sh to just generat ## License -This project is licensed under GPLv3.0 or later. \ No newline at end of file +This project is licensed under GPLv3.0 or later. diff --git a/build-toolchain.sh b/build-toolchain.sh index 3a8f455..337a24e 100755 --- a/build-toolchain.sh +++ b/build-toolchain.sh @@ -1,5 +1,5 @@ #!/bin/sh -#export PREFIX="$HOME/opt/cross-i686" +set -e echo "Welcome to rockOS toolchain compilation script, where would you like to install your toolchain?" echo "Leave blank for $HOME/opt/cross-i686" @@ -14,7 +14,6 @@ echo "This is the location you chose: $PREFIX" echo "Press Enter to continue" read continue -mkdir -p "$PREFIX" export TARGET=i686-elf export PATH="$PREFIX/bin:$PATH" @@ -22,6 +21,13 @@ 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 +if [ "$(uname)" == "Darwin" ]; then + export NPROC="sysctl -n hw.physicalcpu" +else + export NPROC="nproc" +fi + + if command -V wget >/dev/null 2>&1; then export DL_CMD="wget" export DL_OUTPUT="-O" @@ -35,45 +41,50 @@ fi mkdir -p "$PREFIX" cd /tmp +rm -rf rockos-toolchain-src mkdir rockos-toolchain-src cd rockos-toolchain-src -"${DL_CMD}" $DL_OUTPUT binutils.tar.gz $BINUTILS_LINK +$(echo $DL_CMD) $DL_OUTPUT binutils.tar.gz $BINUTILS_LINK 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 -make -j$(nproc) +make -j$($NPROC) make install cd .. -"${$DL_CMD}" $DL_OUTPUT gcc.tar.gz $GCC_LINK + +$(echo $DL_CMD) $DL_OUTPUT gcc.tar.gz $GCC_LINK mkdir gcc-src tar -xvf gcc.tar.gz -C ./gcc-src/ +cd gcc-src/*/ +./contrib/download_prerequisites +cd ../../ mkdir build-gcc cd build-gcc ../gcc-src/*/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers -make -j$(nproc) all-gcc -make -j$(nproc) all-target-libgcc +make -j$($NPROC) all-gcc +make -j$($NPROC) all-target-libgcc make install-gcc make install-target-libgcc cd .. if [ "$(uname)" == "Darwin" ]; then - "${DL_CMD}" $DL_OUTPUT grub.tar.gz $GRUB_LINK + $(echo $DL_CMD) $DL_OUTPUT grub.tar.gz $GRUB_LINK 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 - make -j$(nproc) + make -j$($NPROC) make install cd .. fi -rm -r rockos-toolchain-src +rm -rf /tmp/rockos-toolchain-src cd echo "Toolchain installation is complete!" echo "Please add this to your bashrc or zshrc or whatever" -echo "export \$PATH=\"$PREFIX/bin:\$PATH\"" \ No newline at end of file +echo "export \$PATH=\"$PREFIX/bin:\$PATH\""