From ef01c51fb2a11ee4dd3708d132d6d94c00791f94 Mon Sep 17 00:00:00 2001 From: Evie Viau Date: Sat, 28 Aug 2021 15:30:35 -0400 Subject: [PATCH] Inital build toolchain --- README.md | 20 +++++++++++++++- binutils.sh | 28 +++++++++++++++++++++++ clang.sh | 27 ++++++++++++++++++++++ cmake.sh | 28 +++++++++++++++++++++++ create-toolchain.sh | 18 +++++++++++++++ gcc.sh | 56 +++++++++++++++++++++++++++++++++++++++++++++ glibc.sh | 52 +++++++++++++++++++++++++++++++++++++++++ libstdcxx.sh | 32 ++++++++++++++++++++++++++ linux-headers.sh | 24 +++++++++++++++++++ openssl.sh | 26 +++++++++++++++++++++ 10 files changed, 310 insertions(+), 1 deletion(-) create mode 100755 binutils.sh create mode 100755 clang.sh create mode 100755 cmake.sh create mode 100755 create-toolchain.sh create mode 100755 gcc.sh create mode 100755 glibc.sh create mode 100755 libstdcxx.sh create mode 100755 linux-headers.sh create mode 100755 openssl.sh diff --git a/README.md b/README.md index d448ecd..8371439 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ # toolchain -The toolchain that is used to build yiffOS +The toolchain that is used to build yiffOS. + +You'll need a working clang + gcc setup on the host system to run these scripts. + +You'll also need the sources for: + binutils 2.36.1 + gcc 10.2.0 + linux 5.13.13 + glibc 2.33 + openssl 1.1.1l + cmake 3.21.1 + llvm 12.0.1 + +To allow the scripts to find the sources, please ensure the extracted sources are in a folder with only it's name as the folder name. (Example: gcc 10.2.0 would be in /sources/gcc) + +A destination folder and a target folder will need to be created to allow the toolchain to properly link. + +Script Usage: +./create-toolchain.sh "destination folder" "target folder" "source folder" "makeflags" diff --git a/binutils.sh b/binutils.sh new file mode 100755 index 0000000..2eed08f --- /dev/null +++ b/binutils.sh @@ -0,0 +1,28 @@ +#! /bin/bash + +# Binutils can be compiled with clang +export CC=clang +export CXX=clang++ + +echo "########" +echo "Building: binutils" +echo "########" +echo "Mount: $1" +echo "Target: $2" +echo "Source: $3" +echo "Makeflags: $4" +echo "########" + + +cd $3 +mkdir -v build +cd build + +../configure --prefix=$1/tools \ + --with-sysroot=$1 \ + --target=$2 \ + --disable-nls \ + --disable-werror + +make $4 +make install \ No newline at end of file diff --git a/clang.sh b/clang.sh new file mode 100755 index 0000000..1bb01d9 --- /dev/null +++ b/clang.sh @@ -0,0 +1,27 @@ +#! /bin/bash + +# clang can be compiled with clang +export CC=clang +export CXX=clang++ + +echo "########" +echo "Building: clang" +echo "########" +echo "Mount: $1" +echo "Target: $2" +echo "Source: $3" +echo "Makeflags: $4" +echo "########" + + +cd $3 +mkdir -v build +cd build + +cmake -DCMAKE_INSTALL_PREFIX=$1/tools \ + -DCMAKE_BUILD_TYPE=Release \ + -DLLVM_TARGETS_TO_BUILD="host" \ + -Wno-dev .. + +make $4 +make install \ No newline at end of file diff --git a/cmake.sh b/cmake.sh new file mode 100755 index 0000000..13b9e46 --- /dev/null +++ b/cmake.sh @@ -0,0 +1,28 @@ +#! /bin/bash + +# CMake can be compiled with clang +export CC=clang +export CXX=clang++ + +echo "########" +echo "Building: cmake" +echo "########" +echo "Mount: $1" +echo "Target: $2" +echo "Source: $3" +echo "Makeflags: $4" +echo "########" + + +cd $3 +mkdir -v build +cd build + +sed -i '/CMAKE_USE_LIBUV 1/s/1/0/' CMakeLists.txt +sed -i '/"lib64"/s/64//' Modules/GNUInstallDirs.cmake + +../bootstrap --prefix=$1/tools \ + --no-system-libs + +make $4 +make install \ No newline at end of file diff --git a/create-toolchain.sh b/create-toolchain.sh new file mode 100755 index 0000000..d149fdd --- /dev/null +++ b/create-toolchain.sh @@ -0,0 +1,18 @@ +#! /bin/bash + +echo "########" +echo "Now building the yiffOS toolchain" +echo "########" +echo "Mount: $1" +echo "Target: $2" +echo "Source: $3" +echo "Makeflags: $4" +echo "########" +./binutils.sh $1 $2 $3 $4 +./gcc.sh $1 $2 $3 $4 +./linux-headers.sh $1 $2 $3 $4 +./glibc.sh $1 $2 $3 $4 +./libstdcxx.sh $1 $2 $3 $4 +./openssl.sh $1 $2 $3 $4 +./cmake.sh $1 $2 $3 $4 +./clang.sh $1 $2 $3 $4 \ No newline at end of file diff --git a/gcc.sh b/gcc.sh new file mode 100755 index 0000000..a5b8c8a --- /dev/null +++ b/gcc.sh @@ -0,0 +1,56 @@ +#! /bin/bash + +# GCC can be compiled with clang (somehow) +export CC=clang +export CXX=clang++ + +echo "########" +echo "Building: gcc" +echo "########" +echo "Mount: $1" +echo "Target: $2" +echo "Source: $3" +echo "Makeflags: $4" +echo "########" + + +cd $3 + +case $(uname -m) in + x86_64) + sed -e '/m64=/s/lib64/lib/' \ + -i.orig gcc/config/i386/t-linux64 + ;; +esac + + +mkdir -v build +cd build + +../configure \ + --target=$2 \ + --prefix=$1/tools \ + --with-glibc-version=2.11 \ + --with-sysroot=$1 \ + --with-newlib \ + --without-headers \ + --enable-initfini-array \ + --disable-nls \ + --disable-shared \ + --disable-multilib \ + --disable-decimal-float \ + --disable-threads \ + --disable-libatomic \ + --disable-libgomp \ + --disable-libquadmath \ + --disable-libssp \ + --disable-libvtv \ + --disable-libstdcxx \ + --enable-languages=c,c++ + +make $4 +make install + +cd .. +cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \ + `dirname $($2-gcc -print-libgcc-file-name)`/install-tools/include/limits.h \ No newline at end of file diff --git a/glibc.sh b/glibc.sh new file mode 100755 index 0000000..9b643b8 --- /dev/null +++ b/glibc.sh @@ -0,0 +1,52 @@ +#! /bin/bash + +# Glibc can NOT be compiled with clang +export CC=gcc +export CXX=g++ + +echo "########" +echo "Building: glibc" +echo "########" +echo "Mount: $1" +echo "Target: $2" +echo "Source: $3" +echo "Makeflags: $4" +echo "########" + + +cd $3 + +case $(uname -m) in + i?86) ln -sfv ld-linux.so.2 $1/lib/ld-lsb.so.3 + ;; + x86_64) ln -sfv ../lib/ld-linux-x86-64.so.2 $1/lib64 + ln -sfv ../lib/ld-linux-x86-64.so.2 $1/lib64/ld-lsb-x86-64.so.3 + ;; +esac + +patch -Np1 -i ./glibc-2.33-fhs-1.patch + +mkdir -v build +cd build + +../configure \ + --prefix=/usr \ + --host=$2 \ + --build=$(../scripts/config.guess) \ + --enable-kernel=3.2 \ + --with-headers=$1/usr/include \ + libc_cv_slibdir=/lib + + +make $4 +make DESTDIR=$1 install + +echo "########" +echo "Testing glibc and gcc" +echo "########" +echo 'int main(){}' > dummy.c +$2-gcc dummy.c +readelf -l a.out | grep '/ld-linux' +echo "########" +echo "Please check if the above content is [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] or [Requesting program interpreter: /lib64/ld-linux.so.2]" +read -p "Press any key if it matches, exit the script if it doesn't." diff --git a/libstdcxx.sh b/libstdcxx.sh new file mode 100755 index 0000000..26ccc05 --- /dev/null +++ b/libstdcxx.sh @@ -0,0 +1,32 @@ +#! /bin/bash + +# libstdc++ can NOT be compiled with clang +export CC=gcc +export CXX=g++ + +echo "########" +echo "Building: libstdc++" +echo "########" +echo "Mount: $1" +echo "Target: $2" +echo "Source: $3" +echo "Makeflags: $4" +echo "########" + + +cd $3 +mkdir -v build +cd build + +../libstdc++-v3/configure \ + --host=$2 \ + --build=$(../config.guess) \ + --prefix=/usr \ + --disable-multilib \ + --disable-nls \ + --disable-libstdcxx-pch \ + --with-gxx-include-dir=/tools/$2/include/c++/10.2.0 + + +make $4 +make DESTDIR=$1 installs \ No newline at end of file diff --git a/linux-headers.sh b/linux-headers.sh new file mode 100755 index 0000000..cefdf11 --- /dev/null +++ b/linux-headers.sh @@ -0,0 +1,24 @@ +#! /bin/bash + +# Linux headers can be compiled with clang +export CC=clang +export CXX=clang++ + +echo "########" +echo "Building: Linux headers" +echo "########" +echo "Mount: $1" +echo "Target: $2" +echo "Source: $3" +echo "Makeflags: $4" +echo "########" + + +cd $3 + +make mrproper + +make $4 headers +find usr/include -name '.*' -delete +rm usr/include/Makefile +cp -rv usr/include $1/usr diff --git a/openssl.sh b/openssl.sh new file mode 100755 index 0000000..2e634fa --- /dev/null +++ b/openssl.sh @@ -0,0 +1,26 @@ +#! /bin/bash + +# OpenSSL can be compiled with clang +export CC=clang +export CXX=clang++ + +echo "########" +echo "Building: openssl" +echo "########" +echo "Mount: $1" +echo "Target: $2" +echo "Source: $3" +echo "Makeflags: $4" +echo "########" + + +cd $3 +mkdir -v build +cd build + +../config --prefix=$1/tools \ + --openssldir=$1/tools/etc/ssl \ + --libdir=lib + +make $4 +make MANSUFFIX=ssl install \ No newline at end of file