265 lines
6.0 KiB
Bash
Executable File
265 lines
6.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
umask 022
|
|
|
|
export LC_ALL="POSIX"
|
|
|
|
export TARGET="x86_64-axe-linux-gnu"
|
|
|
|
export MAKEFLAGS="-j$(nproc)"
|
|
|
|
export SYSROOT="$PWD/sysroot"
|
|
|
|
export PROJDIR="$PWD"
|
|
|
|
export SOURCES="$SYSROOT/sources"
|
|
|
|
export CROSS="$SYSROOT/cross"
|
|
|
|
export PATH="$CROSS/bin:/usr/bin:/usr/sbin"
|
|
|
|
export CONFIG_SITE="$SYSROOT/usr/share/config.site"
|
|
|
|
BINUTILS_VERSION=2.45.1
|
|
BINUTILS_URL=https://mirror.ufs.ac.za/gnu/binutils/binutils-$BINUTILS_VERSION.tar.xz
|
|
|
|
GCC_VERSION=15.2.0
|
|
GCC_URL=https://mirror.ufs.ac.za/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz
|
|
|
|
GMP_VERSION=6.3.0
|
|
GMP_URL=https://mirror.ufs.ac.za/gnu/gmp/gmp-$GMP_VERSION.tar.xz
|
|
|
|
MPC_VERSION=1.3.1
|
|
MPC_URL=https://mirror.ufs.ac.za/gnu/mpc/mpc-$MPC_VERSION.tar.gz
|
|
|
|
MPFR_VERSION=4.2.2
|
|
MPFR_URL=https://mirror.ufs.ac.za/gnu/mpfr/mpfr-$MPFR_VERSION.tar.xz
|
|
|
|
ISL_VERSION=0.27
|
|
ISL_URL=https://libisl.sourceforge.io/isl-$ISL_VERSION.tar.xz
|
|
|
|
GLIBC_VERSION=2.43
|
|
GLIBC_URL=https://mirror.ufs.ac.za/gnu/glibc/glibc-$GLIBC_VERSION.tar.xz
|
|
|
|
LINUX_VERSION=6.18.7
|
|
IFS='.' read -r LINUX_VERSION_MAJOR LINUX_VERSION_MINOR LINUX_VERSION_PATCH <<< $LINUX_VERSION
|
|
LINUX_URL=https://cdn.kernel.org/pub/linux/kernel/v$LINUX_VERSION_MAJOR.x/linux-$LINUX_VERSION.tar.xz
|
|
|
|
M4_VERSION=1.4.20
|
|
M4_URL=https://mirror.ufs.ac.za/gnu/m4/m4-$M4_VERSION.tar.xz
|
|
|
|
NCURSES_VERSION=6.6
|
|
NCURSES_URL=https://mirror.ufs.ac.za/gnu/ncurses/ncurses-$NCURSES_VERSION.tar.gz
|
|
|
|
if [ ! -d "$SYSROOT" ]; then
|
|
mkdir -p "$SYSROOT"/{etc,cross,sources,usr,dev,proc,sys,run}
|
|
mkdir -p "$SYSROOT"/usr/{bin,sbin,lib,include}
|
|
|
|
for directory in bin sbin lib; do
|
|
ln -fs "usr/$directory" "$SYSROOT/$directory"
|
|
done
|
|
fi
|
|
|
|
fetch() {
|
|
wget -N -c --show-progress -q -P "$SOURCES" $1
|
|
}
|
|
|
|
bootstrap_binutils() {
|
|
fetch $BINUTILS_URL
|
|
|
|
cd "$SOURCES" && tar xf binutils-$BINUTILS_VERSION.tar.xz && cd binutils-$BINUTILS_VERSION
|
|
|
|
mkdir -p build && cd build
|
|
|
|
../configure \
|
|
--prefix="$CROSS" \
|
|
--with-sysroot="$SYSROOT" \
|
|
--target=$TARGET \
|
|
--disable-nls \
|
|
--enable-gprofng=no \
|
|
--disable-werror \
|
|
--enable-new-dtags \
|
|
--enable-default-hash-style=gnu
|
|
|
|
make && make install
|
|
|
|
cd "$SOURCES"
|
|
rm -rf binutils-$BINUTILS_VERSION
|
|
}
|
|
|
|
bootstap_gcc() {
|
|
fetch $GCC_URL
|
|
fetch $GMP_URL
|
|
fetch $ISL_URL
|
|
fetch $MPC_URL
|
|
fetch $MPFR_URL
|
|
|
|
cd "$SOURCES" && tar xf gcc-$GCC_VERSION.tar.xz && cd gcc-$GCC_VERSION
|
|
|
|
tar xf ../gmp-$GMP_VERSION.tar.xz && mv gmp-$GMP_VERSION gmp
|
|
tar xf ../isl-$ISL_VERSION.tar.xz && mv isl-$ISL_VERSION isl
|
|
tar xf ../mpc-$MPC_VERSION.tar.gz && mv mpc-$MPC_VERSION mpc
|
|
tar xf ../mpfr-$MPFR_VERSION.tar.xz && mv mpfr-$MPFR_VERSION mpfr
|
|
|
|
sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64
|
|
|
|
mkdir -p build && cd build
|
|
|
|
../configure \
|
|
--target=$TARGET \
|
|
--prefix="$CROSS" \
|
|
--with-glibc-version=$GLIBC_VERSION \
|
|
--with-sysroot="$SYSROOT" \
|
|
--with-newlib \
|
|
--without-headers \
|
|
--enable-default-pie \
|
|
--enable-default-ssp \
|
|
--disable-nls \
|
|
--disable-shared \
|
|
--disable-multilib \
|
|
--disable-threads \
|
|
--disable-libatomic \
|
|
--disable-libgomp \
|
|
--disable-libquadmath \
|
|
--disable-libssp \
|
|
--disable-libvtv \
|
|
--disable-libstdcxx \
|
|
--enable-languages=c,c++
|
|
|
|
make && make install
|
|
|
|
cd ..
|
|
cat gcc/limitx.h gcc/glimits.h gcc/limity.h > "`dirname $($TARGET-gcc -print-libgcc-file-name)`/include/limits.h"
|
|
|
|
cd "$SOURCES" && rm -rf gcc-$GCC_VERSION
|
|
}
|
|
|
|
bootstap_linux() {
|
|
fetch $LINUX_URL
|
|
|
|
cd "$SOURCES" && tar xf linux-$LINUX_VERSION.tar.xz && cd linux-$LINUX_VERSION
|
|
|
|
make mrproper
|
|
make headers
|
|
find usr/include -type f ! -name '*.h' -delete
|
|
cp -r usr/include "$SYSROOT"/usr
|
|
|
|
cd "$SOURCES" && rm -rf linux-$LINUX_VERSION
|
|
}
|
|
|
|
bootstap_glibc() {
|
|
fetch $GLIBC_URL
|
|
fetch https://www.linuxfromscratch.org/patches/lfs/development/glibc-fhs-1.patch
|
|
|
|
cd "$SOURCES" && tar xf glibc-$GLIBC_VERSION.tar.xz && cd glibc-$GLIBC_VERSION
|
|
|
|
ln -sf ld-linux-x86-64.so.2 "$SYSROOT"/lib/ld-lsb-x86-64.so.3
|
|
|
|
patch -Np1 -i "$SOURCES"/glibc-fhs-1.patch
|
|
|
|
mkdir -p build && cd build
|
|
|
|
echo "rootsbindir=/usr/sbin" > configparms
|
|
|
|
../configure \
|
|
--prefix=/usr \
|
|
--host=$TARGET \
|
|
--build=$(../scripts/config.guess) \
|
|
--disable-nscd \
|
|
--disable-nls \
|
|
libc_cv_slibdir=/usr/lib \
|
|
--enable-kernel=$LINUX_VERSION
|
|
|
|
make && make DESTDIR="$SYSROOT" install
|
|
|
|
sed '/RTLDLIST=/s@/usr@@g' -i "$SYSROOT"/usr/bin/ldd
|
|
|
|
cd "$SOURCES" && rm -rf gcc-$GLIBC_VERSION
|
|
}
|
|
|
|
bootstap_libstdcpp() {
|
|
cd "$SOURCES" && tar xf gcc-$GCC_VERSION.tar.xz && cd gcc-$GCC_VERSION
|
|
|
|
mkdir -p build && cd build
|
|
|
|
../libstdc++-v3/configure \
|
|
--host=$TARGET \
|
|
--build=$(../config.guess) \
|
|
--prefix=/usr \
|
|
--disable-multilib \
|
|
--disable-nls \
|
|
--disable-libstdcxx-pch \
|
|
--with-gxx-include-dir=/cross/$TARGET/include/c++/$GCC_VERSION
|
|
|
|
make && make DESTDIR="$SYSROOT" install
|
|
|
|
rm -rf "$SYSROOT"/usr/lib/lib{stdc++{,exp,fs},supc++}.la
|
|
|
|
cd "$SOURCES" && rm -rf gcc-$GCC_VERSION
|
|
}
|
|
|
|
toolchain_m4() {
|
|
fetch $M4_URL
|
|
|
|
cd "$SOURCES" && tar xf m4-$M4_VERSION.tar.xz && cd m4-$M4_VERSION
|
|
|
|
sed -r '/_GL_EXTERN_C/s/w?memchr|bsearch/(&)/' -i $(find -name \*.in.h)
|
|
|
|
./configure \
|
|
--prefix=/usr \
|
|
--host=$TARGET \
|
|
--build=$(build-aux/config.guess)
|
|
|
|
make && make DESTDIR="$SYSROOT" install
|
|
|
|
cd "$SOURCES" && rm -rf m4-$M4_VERSION
|
|
}
|
|
|
|
toolchain_ncurses() {
|
|
fetch $NCURSES_URL
|
|
|
|
cd "$SOURCES" && tar xf ncurses-$NCURSES_VERSION.tar.gz && cd ncurses-$NCURSES_VERSION
|
|
|
|
mkdir -p build
|
|
|
|
pushd build
|
|
../configure \
|
|
--prefix="$CROSS" \
|
|
AWK=gawk
|
|
make -C include
|
|
make -C progs tic
|
|
install progs/tic "$CROSS/bin"
|
|
popd
|
|
|
|
./configure \
|
|
--prefix=/usr \
|
|
--host=$TARGET \
|
|
--build=$(./config.guess) \
|
|
--mandir=/usr/share/man \
|
|
--with-manpage-format=normal \
|
|
--with-shared \
|
|
--without-normal \
|
|
--with-cxx-shared \
|
|
--without-debug \
|
|
--without-ada \
|
|
--disable-stripping \
|
|
AWK=gawk
|
|
|
|
make && make DESTDIR="$SYSROOT" install
|
|
|
|
ln -s libncursesw.so "$SYSROOT"/usr/lib/libncurses.so
|
|
|
|
sed -e 's/^#if.*XOPEN.*$/#if 1/' -i "$SYSROOT"/usr/include/curses.h
|
|
|
|
cd "$SOURCES" && rm -rf ncurses-$NCURSES_VERSION
|
|
}
|
|
|
|
#bootstrap_binutils
|
|
#bootstap_gcc
|
|
#bootstap_linux
|
|
#bootstap_glibc
|
|
#bootstap_libstdcpp
|
|
#toolchain_m4
|
|
toolchain_ncurses |