diff options
author | davidovski <david@davidovski.xyz> | 2022-03-01 17:38:38 +0000 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2022-03-01 17:38:38 +0000 |
commit | e35245a4f72136aad1f0d5a54d005892ff2d929a (patch) | |
tree | c45b55c2bc517e484c31fef511947a799afdf78f /bootstrap/stage1.sh | |
parent | fe55aea04e6fa6914e3df635d4771fb2297dd3bd (diff) |
fixed bootstrap
Diffstat (limited to 'bootstrap/stage1.sh')
-rw-r--r-- | bootstrap/stage1.sh | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/bootstrap/stage1.sh b/bootstrap/stage1.sh new file mode 100644 index 0000000..68fa048 --- /dev/null +++ b/bootstrap/stage1.sh @@ -0,0 +1,165 @@ +#!/bin/sh + +cross_tools_kernel_headers () { + src "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-$LINUX_VER.tar.xz" + + make mrproper + + make ARCH=${ARCH} headers + mkdir -pv $CROSS_TOOLS/$TARGET/include + + cp -rv usr/include/* $CROSS_TOOLS/$TARGET/include + find $CROSS_TOOLS/$TARGET/include -name '.*.cmd' -exec rm -vf {} \; + rm -v $CROSS_TOOLS/$TARGET/include/Makefile +} + +cross_tools_binutils () { + src "https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VER.tar.xz" + + mkdir -v build && + cd build && + + ../configure \ + --prefix=${CROSS_TOOLS} \ + --target=${TARGET} \ + --with-sysroot=${CROSS_TOOLS}/${TARGET} \ + --disable-nls \ + --disable-multilib \ + --disable-werror \ + --enable-deterministic-archives \ + --disable-compressed-debug-sections && + + make configure-host && + make && make install +} + +cross_tools_gcc_static () { + cd ${WD} + src "https://www.mpfr.org/mpfr-$MPFR_VER/mpfr-$MPFR_VER.tar.xz" + src "https://ftp.gnu.org/gnu/gmp/gmp-$GMP_VER.tar.xz" + src "https://ftp.gnu.org/gnu/mpc/mpc-$MPC_VER.tar.gz" + src "https://ftp.gnu.org/gnu/gcc/gcc-$GCC_VER/gcc-$GCC_VER.tar.xz" + + mv -v ../mpfr-$MPFR_VER mpfr && + mv -v ../gmp-$GMP_VER gmp && + mv -v ../mpc-$MPC_VER mpc && + + mkdir -v build && cd build && + + CFLAGS='-g0 -O0' \ + CXXFLAGS=$CFLAGS \ + ../configure \ + --prefix=${CROSS_TOOLS} --build=${HOST} \ + --host=${HOST} --target=${TARGET} \ + --with-sysroot=${CROSS_TOOLS}/${TARGET} \ + --disable-nls --with-newlib \ + --disable-libitm --disable-libvtv \ + --disable-libssp --disable-shared \ + --disable-libgomp --without-headers \ + --disable-threads --disable-multilib \ + --disable-libatomic --disable-libstdcxx \ + --enable-languages=c --disable-libquadmath \ + --disable-libsanitizer --with-arch=${CPU} \ + --disable-decimal-float --enable-clocale=generic && + + make all-gcc all-target-libgcc && + make install-gcc install-target-libgcc +} + +cross_tools_musl () { + src https://musl.libc.org/releases/musl-$MUSL_VER.tar.gz + + ./configure \ + CROSS_COMPILE=${TARGET}- \ + --prefix=/ \ + --target=${TARGET} && + + make && DESTDIR=${CROSS_TOOLS} make install && + + # Add missing directory and link + mkdir -v ${CROSS_TOOLS}/usr && + ln -sv ../include ${CROSS_TOOLS}/usr/include && + + case $(uname -m) in + x86_64) export ARCH="x86_64" + ;; + i686) export ARCH="i386" + ;; + arm*) export ARCH="arm" + ;; + aarch64) export ARCH="aarch64" + ;; + esac + + # Fix link + rm -vf ${CROSS_TOOLS}/lib/ld-musl-${ARCH}.so.1 && + ln -sv libc.so ${CROSS_TOOLS}/lib/ld-musl-${ARCH}.so.1 + + # Create link for ldd: + ln -sv ../lib/ld-musl-$ARCH.so.1 ${CROSS_TOOLS}/bin/ldd + + # Create config for dynamic library loading: + mkdir -v ${CROSS_TOOLS}/etc + + echo $CROSS_TOOLS/lib >> ${CROSS_TOOLS}/etc/ld-musl-$ARCH.path + echo $TOOLS/lib >> ${CROSS_TOOLS}/etc/ld-musl-$ARCH.path + + unset ARCH ARCH2 +} + +cross_tools_gcc_final () { + cd ${WD} + rm -rf * + + src "https://www.mpfr.org/mpfr-$MPFR_VER/mpfr-$MPFR_VER.tar.xz" + src "https://ftp.gnu.org/gnu/gmp/gmp-$GMP_VER.tar.xz" + src "https://ftp.gnu.org/gnu/mpc/mpc-$MPC_VER.tar.gz" + src "https://ftp.gnu.org/gnu/gcc/gcc-$GCC_VER/gcc-$GCC_VER.tar.xz" + + mv -v ../mpfr-$MPFR_VER mpfr + mv -v ../gmp-$GMP_VER gmp + mv -v ../mpc-$MPC_VER mpc + + patch_gcc + +# Configure in a dedicated build directory +mkdir build && cd build && +AR=ar LDFLAGS="-Wl,-rpath,${CROSS_TOOLS}/lib" \ +../configure \ + --prefix=${CROSS_TOOLS} \ + --build=${HOST} \ + --host=${HOST} \ + --target=${TARGET} \ + --disable-multilib \ + --with-sysroot=${CROSS_TOOLS} \ + --disable-nls \ + --enable-shared \ + --enable-languages=c,c++ \ + --enable-threads=posix \ + --enable-clocale=generic \ + --enable-libstdcxx-time \ + --enable-fully-dynamic-string \ + --disable-symvers \ + --disable-libsanitizer \ + --disable-lto-plugin \ + --disable-libssp + + # Build + make AS_FOR_TARGET="${TARGET}-as" \ + LD_FOR_TARGET="${TARGET}-ld" && + + # Install + make install +} + +cross_tools_file () { + src "https://astron.com/pub/file/file-$FILE_VER.tar.gz" + ./configure --prefix=${CROSS_TOOLS} --disable-libseccomp + make && make install +} + +for p in kernel_headers binutils gcc_static musl gcc_final file; do + printf "${BLUE}building $p...\n${RESET}" + cross_tools_$p || die "Failed building $p" +done +printf "${GREEN}finished building cross-tools${RESET}\n" |