Skip to content

Commit

Permalink
Inital build toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
uwueviee committed Aug 28, 2021
1 parent ad5d481 commit ef01c51
Show file tree
Hide file tree
Showing 10 changed files with 310 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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"
28 changes: 28 additions & 0 deletions binutils.sh
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions clang.sh
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions cmake.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions create-toolchain.sh
Original file line number Diff line number Diff line change
@@ -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
56 changes: 56 additions & 0 deletions gcc.sh
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions glibc.sh
Original file line number Diff line number Diff line change
@@ -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."
32 changes: 32 additions & 0 deletions libstdcxx.sh
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions linux-headers.sh
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions openssl.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ef01c51

Please sign in to comment.