From e35245a4f72136aad1f0d5a54d005892ff2d929a Mon Sep 17 00:00:00 2001 From: davidovski Date: Tue, 1 Mar 2022 17:38:38 +0000 Subject: fixed bootstrap --- bootstrap/bootstrap.sh | 163 +++++++++++--- bootstrap/cross_tools.sh | 165 -------------- bootstrap/stage1.sh | 165 ++++++++++++++ bootstrap/stage2.sh | 553 +++++++++++++++++++++++++++++++++++++++++++++++ bootstrap/stage3.sh | 135 ++++++++++++ bootstrap/toolchain.sh | 507 ------------------------------------------- 6 files changed, 986 insertions(+), 702 deletions(-) delete mode 100644 bootstrap/cross_tools.sh create mode 100644 bootstrap/stage1.sh create mode 100644 bootstrap/stage2.sh create mode 100644 bootstrap/stage3.sh delete mode 100644 bootstrap/toolchain.sh (limited to 'bootstrap') diff --git a/bootstrap/bootstrap.sh b/bootstrap/bootstrap.sh index 191bebc..814f39a 100755 --- a/bootstrap/bootstrap.sh +++ b/bootstrap/bootstrap.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash ## VERSIONS ## @@ -48,12 +48,13 @@ CPU=x86-64 CROSS_TOOLS=/cross-tools TOOLS=/tools +chroot=$(pwd)/chroot PATH=${TOOLS}/bin:${CROSS_TOOLS}/bin:/usr/bin MAKEFLAGS="-j$(nproc)" -export CHROOT TARGET PATH WD CURL_OPTS CROSS_TOOLS TOOLS MAKEFLAGS +export chroot TARGET PATH WD CURL_OPTS CROSS_TOOLS TOOLS MAKEFLAGS unset CFLAGS CXXFLAGS @@ -63,6 +64,7 @@ die () { } extract () { + echo "extracting $1" FILE=$1 case "${FILE##*.}" in "gz" ) @@ -74,6 +76,9 @@ extract () { "zip" ) unzip $FILE ;; + "xz" ) + tar -xf $FILE + ;; * ) tar -xf $FILE ;; @@ -87,6 +92,7 @@ src () { printf "${LIGHT_BLUE}Fetching $filename...${RESET}\n" curl ${CURL_OPTS} $source > $filename + file $filename extract $filename cd ${filename%.t*} } @@ -105,6 +111,38 @@ clean () { mkdir -pv $WD $CROSS_TOOLS $TOOL } +mount_chroot () { + mkdir -p $chroot/{dev,proc,sys,run} + mknod -m 600 $chroot/dev/console c 5 1 + mknod -m 666 $chroot/dev/null c 1 3 + + mount --bind /dev $chroot/dev + mount -t devpts devpts $chroot/dev/pts -o gid=5,mode=620 + mount -t proc proc $chroot/proc + mount -t sysfs sysfs $chroot/sys + mount -t tmpfs tmpfs $chroot/run + if [ -h $chroot/dev/shm ]; then + mkdir -p $chroot/$(readlink $chroot/dev/shm) + fi +} + +umount_chroot () { + umount $chroot/dev/pts + umount $chroot/dev + umount $chroot/run + umount $chroot/proc + umount $chroot/sys +} + +tchroot () { + chroot "$chroot" /tools/bin/env -i \ + HOME=/root \ + TERM="$TERM" \ + PS1='(chroot) \u:\w\$ ' \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \ + $@ +} + patch_gcc () { local PATCH_SRC="https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/patches/gcc-alpine" @@ -145,41 +183,106 @@ patch_gcc () { #ptch $PATCH_SRC/0022-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch && } -package_chroot () { +create_chroot () { PATH=/usr/bin:/bin - local chroot=$(pwd)/chroot mkdir chroot - xi -r ${chroot} bootstrap - cp -r ${TOOLS} ${chroot}/tools - ln -s /tools/bin/bash ${chroot}/bin/sh + xi -l -r ${chroot} bootstrap + echo "copying tools..." + mkdir ${chroot}/tools + cp -r ${TOOLS} ${chroot}/ + + echo "making essential links" + + ln -s /tools/bin/bash ${chroot}/bin + ln -s /tools/bin/cat ${chroot}/bin + ln -s /tools/bin/dd ${chroot}/bin + ln -s /tools/bin/echo ${chroot}/bin + ln -s /tools/bin/ln ${chroot}/bin + ln -s /tools/bin/pwd ${chroot}/bin + ln -s /tools/bin/rm ${chroot}/bin + ln -s /tools/bin/stty ${chroot}/bin + ln -s /tools/bin/install ${chroot}/bin + ln -s /tools/bin/env ${chroot}/bin + #ln -s /tools/bin/perl ${chroot}/bin + + ln -s /tools/lib/libgcc_s.so.1 ${chroot}/usr/lib + ln -s /tools/lib/libgcc_s.so ${chroot}/usr/lib + + ln -s /tools/lib/libstdc++.a ${chroot}/usr/lib + ln -s /tools/lib/libstdc++.so ${chroot}/usr/lib + ln -s /tools/lib/libstdc++.so.6 ${chroot}/usr/lib + ln -s bash ${chroot}/bin/sh + + mkdir -p ${chroot}/etc + ln -s /proc/self/mounts ${chroot}/etc/mtab + + cat > ${chroot}/etc/passwd << "EOF" +root:x:0:0:root:/root:/bin/bash +daemon:x:6:6:Daemon User:/dev/null:/bin/false +messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false +nobody:x:99:99:Unprivileged User:/dev/null:/bin/false +EOF + + cat > ${chroot}/etc/group << "EOF" +root:x:0: +sys:x:2: +kmem:x:3: +tape:x:4: +tty:x:5: +daemon:x:6: +floppy:x:7: +disk:x:8: +lp:x:9: +dialout:x:10: +audio:x:11: +video:x:12: +utmp:x:13: +usb:x:14: +cdrom:x:15: +adm:x:16: +messagebus:x:18: +input:x:24: +mail:x:34: +nogroup:x:99: +users:x:999: +EOF + + echo "Created chroot" +} + +package_chroot () { + PATH=/usr/bin:/bin + echo "compressing..." + echo ${chroot} tar -C ${chroot} -czf chroot-tools.tar.gz ./ + echo "created chroot-tools.tar.gz..." } [ -f /usr/lib/colors.sh ] && . /usr/lib/colors.sh rm -rf $WD ; mkdir $WD -# TODO bad impl -if [ "$#" = "0" ]; then - clean - $0 stage1 - $0 stage2 -else - case "$1" in - stage1|cross|cross_tools) - . ./cross_tools.sh - ;; - stage2|tools|toolchain) - . ./toolchain.sh - ;; - package) - package_chroot - ;; - *) - clean - $0 stage1 - $0 stage2 - ;; - esac -fi +case "$1" in + stage1|cross|cross_tools) + . ./stage1.sh + ;; + stage2|tools|toolchain) + . ./stage2.sh + ;; + stage3) + . ./stage3.sh + ;; + package) + umount_chroot + package_chroot + ;; + *) + clean + $0 stage1 + $0 stage2 + $0 stage3 + umount_chroot + package_chroot + ;; +esac diff --git a/bootstrap/cross_tools.sh b/bootstrap/cross_tools.sh deleted file mode 100644 index 68fa048..0000000 --- a/bootstrap/cross_tools.sh +++ /dev/null @@ -1,165 +0,0 @@ -#!/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" 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" diff --git a/bootstrap/stage2.sh b/bootstrap/stage2.sh new file mode 100644 index 0000000..161f799 --- /dev/null +++ b/bootstrap/stage2.sh @@ -0,0 +1,553 @@ +#!/bin/sh + +set_env () { + CC="${TARGET}-gcc" + CXX="${TARGET}-g++" + AR="${TARGET}-ar" + AS="${TARGET}-as" + RANLIB="${TARGET}-ranlib" + LD="${TARGET}-ld" + STRIP="${TARGET}-strip" + export CC CXX AR AS RANLIB LD STRIP +} + +toolchain_musl () { + src "https://musl.libc.org/releases/musl-$MUSL_VER.tar.gz" + ./configure \ + CROSS_COMPILE=${TARGET}- \ + --prefix=/ \ + --target=${TARGET} && + + make && make DESTDIR=$TOOLS install && + + case $(uname -m) in + x86_64) rm -v $TOOLS/lib/ld-musl-x86_64.so.1 + ln -sv libc.so $TOOLS/lib/ld-musl-x86_64.so.1 + export barch=$(uname -m) + ;; + i686) rm -v $TOOLS/lib/ld-musl-i386.so.1 + ln -sv libc.so $TOOLS/lib/ld-musl-i386.so.1 + export barch=i386 + ;; + arm*) rm -v $TOOLS/lib/ld-musl-arm.so.1 + ln -sv libc.so $TOOLS/lib/ld-musl-arm.so.1 + export barch=arm + ;; + aarch64) rm -v $TOOLS/lib/ld-musl-aarch64.so.1 + ln -sv libc.so $TOOLS/lib/ld-musl-aarch64.so.1 + export barch=$(uname -m) + ;; + esac && + + # Create dynamic linker config + mkdir -pv $TOOLS/etc && + echo "$TOOLS/lib" > $TOOLS/etc/ld-musl-${barch}.path + unset barch +} + +toolchain_cross_adjustments () { + export SPECFILE=`dirname $(${TARGET}-gcc -print-libgcc-file-name)`/specs + ${TARGET}-gcc -dumpspecs > specs + + case $(uname -m) in + x86_64) sed -i 's/\/lib\/ld-musl-x86_64.so.1/\/tools\/lib\/ld-musl-x86_64.so.1/g' specs + # check with + grep "/tools/lib/ld-musl-x86_64.so.1" specs --color=auto + ;; + i686) sed -i 's/\/lib\/ld-musl-i386.so.1/\/tools\/lib\/ld-musl-i386.so.1/g' specs + # check with + grep "/tools/lib/ld-musl-i386.so.1" specs --color=auto + ;; + arm*) sed -i 's/\/lib\/ld-musl-arm/\/tools\/lib\/ld-musl-arm/g' specs + # check with + grep "/tools/lib/ld-musl-arm" specs --color=auto + ;; + aarch64) sed -i 's/\/lib\/ld-musl-aarch64/\/tools\/lib\/ld-musl-aarch64/g' specs + # check with + grep "/tools/lib/ld-musl-aarch64" specs --color=auto + ;; + esac + + # Install modified specs to the cross toolchain + mv specs $SPECFILE + unset SPECFILE + + # Quick check the tool chain: + echo 'int main(){}' > dummy.c + ${TARGET}-gcc dummy.c + ${TARGET}-readelf -l a.out | grep Requesting + + echo + echo "Output should be:" + echo "[Requesting program interpreter: /tools/lib/ld-musl-x86_64.so.1]" + echo "or" + echo "[Requesting program interpreter: /tools/lib/ld-musl-i386.so.1]" + echo "or" + echo "[Requesting program interpreter: /tools/lib/ld-musl-arm.so.1]" + echo "or" + echo "[Requesting program interpreter: /tools/lib/ld-musl-aarch64.so.1]" + echo "Please confirm the above, and pres enter to continue:" + read confirm + + rm a.out dummy.c +} + +toolchain_adjustments () { + SPECFILE=`dirname $(${TARGET}-gcc -print-libgcc-file-name)`/specs && + ${TARGET}-gcc -dumpspecs > tempspecfile + + #case $(uname -m) in + # i686) # for i386 + # sed -i 's/\/lib\/ld-musl-i386.so.1/\/tools\/lib\/ld-musl-i386.so.1/g' tempspecfile + # # check with sed + # grep "/tools/lib/ld-musl-i386.so.1" tempspecfile --color=auto + # ;; + # x86_64) # for x86_64 + # sed -i 's/\/lib\/ld-musl-x86_64.so.1/\/tools\/lib\/ld-musl-x86_64.so.1/g' tempspecfile + # # check with + # grep "/tools/lib/ld-musl-x86_64.so.1" tempspecfile --color=auto + # ;; + # arm*) # for arm + # sed -i 's/\/lib\/ld-musl-arm/\/tools\/lib\/ld-musl-arm/g' tempspecfile + # # check with + # grep "/tools/lib/ld-musl-arm" tempspecfile --color=auto + # ;; + # aarch64) # for 64-bit arm64 + # sed -i 's/\/lib\/ld-musl-aarch64/\/tools\/lib\/ld-musl-aarch64/g' tempspecfile + # # check with + # grep "/tools/lib/ld-musl-aarch64" tempspecfile --color=auto + # ;; + #esac + + mv -f tempspecfile $SPECFILE && + unset SPECFILE + + GCC_INCLUDEDIR=`dirname $(${TARGET}-gcc -print-libgcc-file-name)`/include && + find ${GCC_INCLUDEDIR}/* -maxdepth 0 -xtype d -exec rm -rvf '{}' \; && + rm -vf `grep -l "DO NOT EDIT THIS FILE" ${GCC_INCLUDEDIR}/*` && + unset GCC_INCLUDEDIR + + echo 'int main(){}' > dummy.c + ${TARGET}-gcc -B/tools/lib dummy.c + readelf -l a.out | grep ': /tools' + read confirm + + rm -v dummy.c a.out + +} + +toolchain_binutils () { + src "https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VER.tar.xz" + + # Link directories so libraries can be found in both lib & lib64 + case $(uname -m) in + x86_64) ln -sv lib $TOOLS/lib64 ;; + esac && + + # Configure in dedicated build directory + mkdir -v build && cd build && + ../configure --prefix=$TOOLS \ + --with-lib-path=$TOOLS/lib \ + --build=${HOST} \ + --host=${TARGET} \ + --target=${TARGET} \ + --disable-nls \ + --disable-werror \ + --with-sysroot && + + make && + make install && + + make -C ld clean && + make -C ld LIB_PATH=/usr/lib:/lib && + cp -v ld/ld-new $TOOLS/bin +} + +toolchain_gcc () { + 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 && + + # Re-create internal header + cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \ + $(dirname $($TARGET-gcc -print-libgcc-file-name))/include-fixed/limits.h && + + ## Change the location of GCC's default dynamic linker to use the one installed in /tools + # + # For i686/x86_64: + for file in gcc/config/linux/linux.h gcc/config/linux/linux64.h gcc/config/i386/linux.h gcc/config/i386/linux64.h + do + cp -uv $file $file.orig + sed -e "s,/lib\(64\)\?\(32\)\?/ld,$TOOLS&,g" \ + -e "s,/usr,$TOOLS,g" ${file}.orig > ${file} + echo " +#undef STANDARD_STARTFILE_PREFIX_1 +#undef STANDARD_STARTFILE_PREFIX_2 +#define STANDARD_STARTFILE_PREFIX_1 \"$TOOLS/lib/\" +#define STANDARD_STARTFILE_PREFIX_2 \"\"" >> ${file} + touch ${file}.orig + done && + + # Configure in dedicated build directory + mkdir -v build && cd build && + CFLAGS='-g0 -O0' \ + CXXFLAGS=$CFLAGS \ + ../configure \ + --target=${TARGET} \ + --build=${HOST} \ + --host=${TARGET} \ + --prefix=$TOOLS \ + --with-local-prefix=$TOOLS \ + --with-native-system-header-dir=$TOOLS/include \ + --with-pic \ + --enable-languages=c,c++ \ + --disable-libstdcxx-pch \ + --disable-multilib \ + --disable-bootstrap \ + --disable-libgomp \ + --disable-libquadmath \ + --disable-libssp \ + --disable-libvtv \ + --disable-symvers \ + --disable-libitm \ + --disable-libsanitizer && + + PATH=$CROSS_TOOLS/bin:/bin:/usr/bin:$TOOLS/bin make && + make install && + ln -sv gcc $TOOLS/bin/cc +} + +toolchain_kernel_headers () { + src "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-$LINUX_VER.tar.xz" + + make mrproper && + ARCH=${ARCH} make headers && + cp -rv usr/include/* $TOOLS/include + + find $TOOLS/include -name '.*.cmd' -exec rm -vf {} \; + rm -v $TOOLS/include/Makefile +} + +toolchain_libstdcxx () { + rm -rf ${WD} ; mkdir ${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 && + + ptch "https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/patches/gcc-mlfs-$GCC_VER/fix_fenv_header.patch" && + patch_gcc && + + mkdir -v build && cd build && + ../libstdc++-v3/configure \ + --target=${TARGET} \ + --build=${HOST} \ + --host=${TARGET} \ + --prefix=$TOOLS \ + --disable-multilib \ + --disable-nls \ + --disable-libstdcxx-threads \ + --disable-libstdcxx-pch \ + --with-pic \ + --with-gxx-include-dir=$TOOLS/${TARGET}/include/c++/$GCC_VER && + + make && + make install +} + +toolchain_tcl () { + local source="https://downloads.sourceforge.net/tcl/tcl$TCL_VER-src.tar.gz" + local filename=$(basename $source) + printf "${LIGHT_BLUE}Fetching $filename...${RESET}\n" + curl ${CURL_OPTS} $source > $filename + extract $filename + cd tcl$TCL_VER + + cd unix + ac_cv_func_strtod=yes \ + tcl_cv_strtod_buggy=1 \ + ./configure --build=${HOST} \ + --host=${TARGET} \ + --prefix=${TOOLS} && + + make && make install + + chmod -v u+w $TOOLS/lib/libtcl${TCL_VER%.*}.so + make install-private-headers + ln -sv tclsh${TCL_VER%.*} $TOOLS/bin/tclsh +} + +toolchain_expect () { + src "https://prdownloads.sourceforge.net/expect/expect$EXPECT_VER.tar.gz" + + PATCH_URL="https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/patches/expect-5.45.3" + ptch $PATCH_URL/dont-put-toolchain-in-libpath.patch + ptch $PATCH_URL/dont-configure-testsuites.patch + ptch $PATCH_URL/allow-cross-compile.patch + + curl ${CURL_OPTS} "https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/files/config.guess-musl" > tclconfig/config.guess + curl ${CURL_OPTS} "https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/files/config.sub-musl" > tclconfig/config.sub + cp -v configure configure.orig + sed 's:/usr/local/bin:/bin:' configure.orig > configure + + ./configure --build=${HOST} \ + --host=${TARGET} \ + --prefix=$TOOLS \ + --with-tcl=$TOOLS/lib \ + --with-tclinclude=$TOOLS/include && + + make && make SCRIPTS="" install +} + +toolchain_dejagnu () { + src "https://ftp.gnu.org/gnu/dejagnu/dejagnu-$DEJAGNU_VER.tar.gz" + ./configure --build=${HOST} \ + --host=${TARGET} \ + --prefix=$TOOLS && + + make && make install +} + +toolchain_m4 () { + src "https://ftp.gnu.org/gnu/m4/m4-$M4_VER.tar.xz" + + ./configure --prefix=$TOOLS \ + --build=${HOST} \ + --host=${TARGET} && + + make && make install +} + +toolchain_ncurses () { + src "https://invisible-mirror.net/archives/ncurses/ncurses-$NCURSES_VER.tar.gz" + sed -i s/mawk// configure + + # Configure source + ./configure --prefix=${TOOLS} \ + --build=${HOST} \ + --host=${TARGET} \ + --with-shared \ + --without-debug \ + --without-ada \ + --enable-widec \ + --enable-overwrite + make && make install + echo "INPUT(-lncursesw)" > ${TOOLS}/lib/libncurses.so + ln -s libncurses.so ${TOOLS}/lib/libcurses.so +} + +toolchain_bash () { + src "https://ftp.gnu.org/gnu/bash/bash-$BASH_VER.tar.gz" + + cat > config.cache << "EOF" +ac_cv_func_mmap_fixed_mapped=yes +ac_cv_func_strcoll_works=yes +ac_cv_func_working_mktime=yes +bash_cv_func_sigsetjmp=present +bash_cv_getcwd_malloc=yes +bash_cv_job_control_missing=present +bash_cv_printf_a_format=yes +bash_cv_sys_named_pipes=present +bash_cv_ulimit_maxfds=yes +bash_cv_under_sys_siglist=yes +bash_cv_unusable_rtsigs=no +gt_cv_int_divbyzero_sigfpe=yes +EOF + ./configure --prefix=${TOOLS} \ + --without-bash-malloc \ + --build=${HOST} \ + --host=${TARGET} \ + --cache-file=config.cache && + + make && make install +} + +toolchain_bison () { + src "https://ftp.gnu.org/gnu/bison/bison-$BISON_VER.tar.xz" + ./configure --prefix=${TOOLS} \ + --build=${HOST} \ + --host=${TARGET} && + make && make install +} + +toolchain_coreutils () { + git clone git://git.suckless.org/sbase sbase + cd sbase + make && make PREFIX=/ DESTDIR=$TOOLS install +} + +toolchain_diffutils () { + src "https://ftp.gnu.org/gnu/diffutils/diffutils-$DIFFUTILS_VER.tar.xz" + ./configure --prefix=${TOOLS} \ + --build=${HOST} \ + --host=${TARGET} + + make && make install +} + +toolchain_file () { + src "https://astron.com/pub/file/file-$FILE_VER.tar.gz" + ./configure --prefix=${TOOLS} \ + --build=${HOST} \ + --host=${TARGET} + make && make install +} + +toolchain_findutils () { + src "https://ftp.gnu.org/gnu/findutils/findutils-$FINDUTILS_VER.tar.xz" + sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' gl/lib/*.c && + sed -i '/unistd/a #include ' gl/lib/mountlist.c && + echo "#define _IO_IN_BACKUP 0x100" >> gl/lib/stdio-impl.h + + ./configure --prefix=${TOOLS} \ + --build=${HOST} \ + --host=${TARGET} + + make && make install +} + +toolchain_gawk () { + src "https://ftp.gnu.org/gnu/gawk/gawk-$GAWK_VER.tar.xz" + ./configure --prefix=${TOOLS} \ + --build=${HOST} \ + --host=${TARGET} + make && make install +} + +toolchain_gettext () { + src "https://ftp.barfooze.de/pub/sabotage/tarballs/gettext-tiny-$GETTEXT_TINY_VER.tar.xz" + make ${MJ} LIBINTL=MUSL prefix=$TOOLS + cp -v msgfmt msgmerge xgettext $TOOLS/bin +} + +toolchain_grep () { + src "https://ftp.gnu.org/gnu/grep/grep-$GREP_VER.tar.xz" + + ./configure --prefix=${TOOLS} \ + --build=${HOST} \ + --host=${TARGET} && + make && make install +} + +toolchain_make () { + src "https://ftp.gnu.org/gnu/make/make-$MAKE_VER.tar.gz" + + ./configure --prefix=${TOOLS} \ + --build=${HOST} \ + --host=${TARGET} \ + --without-guile && + make && make install +} + +toolchain_patch () { + src "https://ftp.gnu.org/gnu/patch/patch-$PATCH_VER.tar.xz" + ./configure --prefix=${TOOLS} \ + --build=${HOST} \ + --host=${TARGET} && + make && make install +} + +toolchain_sed () { + src "https://ftp.gnu.org/gnu/sed/sed-$SED_VER.tar.xz" + ./configure --prefix=${TOOLS} \ + --build=${HOST} \ + --host=${TARGET} && + make && make install +} + +toolchain_perl () { + src "https://github.com/arsv/perl-cross/releases/download/$PERL_CROSS_VER/perl-cross-$PERL_CROSS_VER.tar.gz" + src "https://www.cpan.org/src/5.0/perl-$PERL_VER.tar.xz" + + cp -vrf ../perl-cross-$PERL_CROSS_VER/* ./ + + ./configure --prefix=${TOOLS} \ + --target=${TARGET} && + make && + cp -v perl cpan/podlators/scripts/pod2man ${TOOLS}/bin && + mkdir -pv ${TOOLS}/lib/perl5/$PERL_VER && + cp -Rv lib/* ${TOOLS}/lib/perl5/$PERL_VER +} + +toolchain_texinfo () { + src "https://ftp.gnu.org/gnu/texinfo/texinfo-$TEXINFO_VER.tar.xz" + ./configure --prefix=${TOOLS} \ + --build=${HOST} \ + --host=${TARGET} && + make && make install +} + +toolchain_flex () { + src "https://github.com/westes/flex/releases/download/v$FLEX_VER/flex-$FLEX_VER.tar.gz" + + ac_cv_func_malloc_0_nonnull=yes \ + ac_cv_func_realloc_0_nonnull=yes \ + HELP2MAN=${TOOLS}/bin/true \ + ./configure --prefix=${TOOLS} \ + --build=${HOST} \ + --host=${TARGET} + make && make install +} + +toolchain_strip () { + find ${TOOLS}/lib -type f -exec strip --strip-unneeded {} \; + /usr/bin/strip --strip-unneeded ${TOOLS}/bin/* ${TOOLS}/sbin/* + + # Remove the documentation: + rm -rf ${TOOLS}/share/info \ + ${TOOLS}/share/man \ + ${TOOLS}/share/doc \ + ${TOOLS}/info \ + ${TOOLS}/man \ + ${TOOLS}/doc + + find ${TOOLS}/lib ${TOOLS}/libexec -name \*.la -exec rm -rvf {} \; +} + +printf "${BLUE}building musl...\n${RESET}" +toolchain_musl || die "Failed building musl" +toolchain_cross_adjustments +for p in \ + binutils \ + gcc \ + kernel_headers \ + adjustments \ + libstdcxx \ + tcl \ + expect \ + dejagnu \ + m4 \ + ncurses \ + bash \ + bison \ + coreutils \ + diffutils \ + file \ + findutils \ + gawk \ + gettext \ + grep \ + make\ + patch \ + sed \ + texinfo \ + flex \ + ; do + + printf "${BLUE}building $p...\n${RESET}" + set_env + toolchain_$p || die "Failed building $p" +done + +printf "${GREEN}finished building toolchain${RESET}\n" diff --git a/bootstrap/stage3.sh b/bootstrap/stage3.sh new file mode 100644 index 0000000..567a4ad --- /dev/null +++ b/bootstrap/stage3.sh @@ -0,0 +1,135 @@ +#!/bin/bash + +clean_build () { + rm -rf ${chroot}/build + mkdir ${chroot}/build +} + +build_headers () { + src "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-$LINUX_VER.tar.xz" + make mrproper + + ptch "https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/patches/kernel/include-uapi-linux-swab-Fix-potentially-missing-__always_inline.patch" + + cat > ${chroot}/build/build.sh << "EOF" +#!/bin/bash +cd /build/ +cp -r */* . + +make headers +mkdir /usr/include +cp -r usr/include/* /usr/include +find /usr/include -name '.*' -exec rm -f {} \; +rm /usr/include/Makefile +EOF + chmod +x ${chroot}/build/build.sh + tchroot /build/build.sh +} + +build_musl () { + src "https://musl.libc.org/releases/musl-$MUSL_VER.tar.gz" + ptch "https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/patches/musl-mlfs/fix-utmp-wtmp-paths.patch" + ptch "https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/patches/musl-mlfs/change-scheduler-functions-Linux-compatib.patch" + ptch "https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/patches/musl-alpine/0001-riscv64-define-ELF_NFPREG.patch" + ptch "https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/patches/musl-alpine/handle-aux-at_base.patch +" + ptch "https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/patches/musl-alpine/syscall-cp-epoll.patch" + curl "https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/files/__stack_chk_fail_local.c" > __stack_chk_fail_local.c + + cat > ${chroot}/build/build.sh << "EOF" +#!/bin/bash +cd /build/ +cp -r */* . +LDFLAGS="$LDFLAGS -Wl,-soname,libc.musl-${CARCH}.so.1" \ +./configure --prefix=/usr \ + --sysconfdir=/etc \ + --localstatedir=/var \ + --disable-gcc-wrapper + +make && make install + + +/tools/bin/x86_64-linux-musl-gcc -fpie -c __stack_chk_fail_local.c -o __stack_chk_fail_local.o +/tools/bin/x86_64-linux-musl-gcc-ar r libssp_nonshared.a __stack_chk_fail_local.o + +cp libssp_nonshared.a /usr/lib/ + +export ARCH="x86_64" + +ln -s /lib/ld-musl-$ARCH.so.1 /bin/ldd +EOF + chmod +x ${chroot}/build/build.sh + tchroot /build/build.sh +} + +adjust_tools() { + + cat > ${chroot}/build/build.sh << "EOF" +#!/bin/bash +export TARGET="x86_64-linux-musl" +mv /tools/bin/{ld,ld-old} +mv /tools/${TARGET}/bin/{ld,ld-old} +mv /tools/bin/{ld-new,ld} +ln -s /tools/bin/ld /tools/${TARGET}/bin/ld + +export SPECFILE=`dirname $(gcc -print-libgcc-file-name)`/specs +gcc -dumpspecs | sed -e 's@/tools@@g' \ + -e '/\*startfile_prefix_spec:/{n;s@.*@/usr/lib/ @}' \ + -e '/\*cpp:/{n;s@$@ -isystem /usr/include@}' > tempspecfile +mv -f tempspecfile $SPECFILE && +unset SPECFILE TARGET + +echo 'int main(){}' > dummy.c +cc dummy.c -v -Wl,--verbose > dummy.log 2>&1 +readelf -l a.out | grep ': /lib' +printf "above should be:\n\033[0;33m[Requesting program interpreter: /lib/ld-musl-x86_64.so.1]\033[0m\n" +printf "######################\n" +read wait + +grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log +printf "above should be:\033[0;33m\n" +printf "/usr/lib/crt1.o succeeded\n" +printf "/usr/lib/crti.o succeeded\n" +printf "/usr/lib/crtn.o succeeded\n" +printf "\033[0m\n" +printf "######################\n" +read wait + + +grep -B1 '^ /usr/include' dummy.log +printf "above should be:\033[0;33m\n" +printf "#include <...> search starts here:\n" +printf "/usr/include\n" +printf "\033[0m\n" +printf "######################\n" +read wait + +grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g' +printf "above should be:\033[0;33m\n" +printf "SEARCH_DIR(\"=/tools/x86_64-mlfs-linux-musl/lib64\")\n" +printf "SEARCH_DIR(\"/usr/lib\")\n" +printf "SEARCH_DIR(\"/lib\")\n" +printf "SEARCH_DIR(\"=/tools/x86_64-mlfs-linux-musl/lib\")\n" +printf "\033[0m\n" +printf "######################\n" +read wait +rm dummy.c a.out dummy.log +EOF + chmod +x ${chroot}/build/build.sh + tchroot /build/build.sh +} + +umount_chroot +rm -r ${chroot} +create_chroot +mount_chroot +export WD=${chroot}/build +clean_build +build_headers +clean_build +build_musl +clean_build +adjust_tools +clean_build + +printf "${GREEN}Completed stage3\n" diff --git a/bootstrap/toolchain.sh b/bootstrap/toolchain.sh deleted file mode 100644 index 5923bf3..0000000 --- a/bootstrap/toolchain.sh +++ /dev/null @@ -1,507 +0,0 @@ -#!/bin/sh - -set_env () { - CC="${TARGET}-gcc" - CXX="${TARGET}-g++" - AR="${TARGET}-ar" - AS="${TARGET}-as" - RANLIB="${TARGET}-ranlib" - LD="${TARGET}-ld" - STRIP="${TARGET}-strip" - export CC CXX AR AS RANLIB LD STRIP -} - -toolchain_musl () { - src "https://musl.libc.org/releases/musl-$MUSL_VER.tar.gz" - ./configure \ - CROSS_COMPILE=${TARGET}- \ - --prefix=/ \ - --target=${TARGET} && - - make && make DESTDIR=$TOOLS install && - - case $(uname -m) in - x86_64) rm -v $TOOLS/lib/ld-musl-x86_64.so.1 - ln -sv libc.so $TOOLS/lib/ld-musl-x86_64.so.1 - export barch=$(uname -m) - ;; - i686) rm -v $TOOLS/lib/ld-musl-i386.so.1 - ln -sv libc.so $TOOLS/lib/ld-musl-i386.so.1 - export barch=i386 - ;; - arm*) rm -v $TOOLS/lib/ld-musl-arm.so.1 - ln -sv libc.so $TOOLS/lib/ld-musl-arm.so.1 - export barch=arm - ;; - aarch64) rm -v $TOOLS/lib/ld-musl-aarch64.so.1 - ln -sv libc.so $TOOLS/lib/ld-musl-aarch64.so.1 - export barch=$(uname -m) - ;; - esac && - - # Create dynamic linker config - mkdir -pv $TOOLS/etc && - echo "$TOOLS/lib" > $TOOLS/etc/ld-musl-${barch}.path - unset barch -} - -toolchain_adjustments () { - export SPECFILE=`dirname $(${TARGET}-gcc -print-libgcc-file-name)`/specs - ${TARGET}-gcc -dumpspecs > specs - - case $(uname -m) in - x86_64) sed -i 's/\/lib\/ld-musl-x86_64.so.1/\/tools\/lib\/ld-musl-x86_64.so.1/g' specs - # check with - grep "/tools/lib/ld-musl-x86_64.so.1" specs --color=auto - ;; - i686) sed -i 's/\/lib\/ld-musl-i386.so.1/\/tools\/lib\/ld-musl-i386.so.1/g' specs - # check with - grep "/tools/lib/ld-musl-i386.so.1" specs --color=auto - ;; - arm*) sed -i 's/\/lib\/ld-musl-arm/\/tools\/lib\/ld-musl-arm/g' specs - # check with - grep "/tools/lib/ld-musl-arm" specs --color=auto - ;; - aarch64) sed -i 's/\/lib\/ld-musl-aarch64/\/tools\/lib\/ld-musl-aarch64/g' specs - # check with - grep "/tools/lib/ld-musl-aarch64" specs --color=auto - ;; - esac - - # Install modified specs to the cross toolchain - mv -v specs $SPECFILE - unset SPECFILE - - # Quick check the tool chain: - echo 'int main(){}' > dummy.c - ${TARGET}-gcc dummy.c - ${TARGET}-readelf -l a.out | grep Requesting - - echo - echo "Output should be:" - echo "[Requesting program interpreter: /tools/lib/ld-musl-x86_64.so.1]" - echo "or" - echo "[Requesting program interpreter: /tools/lib/ld-musl-i386.so.1]" - echo "or" - echo "[Requesting program interpreter: /tools/lib/ld-musl-arm.so.1]" - echo "or" - echo "[Requesting program interpreter: /tools/lib/ld-musl-aarch64.so.1]" - echo "Please confirm the above, and pres enter to continue:" - read confirm - - rm -v a.out dummy.c -} - -toolchain_binutils () { - src "https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VER.tar.xz" - - # Link directories so libraries can be found in both lib & lib64 - case $(uname -m) in - x86_64) ln -sv lib $TOOLS/lib64 ;; - esac && - - # Configure in dedicated build directory - mkdir -v build && cd build && - ../configure --prefix=$TOOLS \ - --with-lib-path=$TOOLS/lib \ - --build=${HOST} \ - --host=${TARGET} \ - --target=${TARGET} \ - --disable-nls \ - --disable-werror \ - --with-sysroot && - - make && - make install && - - make -C ld clean && - make -C ld LIB_PATH=/usr/lib:/lib && - cp -v ld/ld-new $TOOLS/bin -} - -toolchain_gcc () { - 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 && - - # Re-create internal header - cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \ - $(dirname $($TARGET-gcc -print-libgcc-file-name))/include-fixed/limits.h && - - ## Change the location of GCC's default dynamic linker to use the one installed in /tools - # - # For i686/x86_64: - for file in gcc/config/linux/linux.h gcc/config/linux/linux64.h gcc/config/i386/linux.h gcc/config/i386/linux64.h - do - cp -uv $file $file.orig - sed -e "s,/lib\(64\)\?\(32\)\?/ld,$TOOLS&,g" \ - -e "s,/usr,$TOOLS,g" ${file}.orig > ${file} - echo " -#undef STANDARD_STARTFILE_PREFIX_1 -#undef STANDARD_STARTFILE_PREFIX_2 -#define STANDARD_STARTFILE_PREFIX_1 \"$TOOLS/lib/\" -#define STANDARD_STARTFILE_PREFIX_2 \"\"" >> ${file} - touch ${file}.orig - done && - - # Configure in dedicated build directory - mkdir -v build && cd build && - CFLAGS='-g0 -O0' \ - CXXFLAGS=$CFLAGS \ - ../configure \ - --target=${TARGET} \ - --build=${HOST} \ - --host=${TARGET} \ - --prefix=$TOOLS \ - --with-local-prefix=$TOOLS \ - --with-native-system-header-dir=$TOOLS/include \ - --enable-languages=c,c++ \ - --disable-libstdcxx-pch \ - --disable-multilib \ - --disable-bootstrap \ - --disable-libgomp \ - --disable-libquadmath \ - --disable-libssp \ - --disable-libvtv \ - --disable-symvers \ - --disable-libitm \ - --disable-libsanitizer && - - PATH=/bin:/usr/bin:$CROSS_TOOLS/bin:$TOOLS/bin make && - make install && - ln -sv gcc $TOOLS/bin/cc -} - -toolchain_kernel_headers () { - src "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-$LINUX_VER.tar.xz" - - make mrproper && - ARCH=${ARCH} make headers && - cp -rv usr/include/* $TOOLS/include - - find $TOOLS/include -name '.*.cmd' -exec rm -vf {} \; - rm -v $TOOLS/include/Makefile -} - -toolchain_libstdcxx () { - rm -rf ${WD} ; mkdir ${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 && - - ptch "https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/patches/gcc-mlfs-$GCC_VER/fix_fenv_header.patch" && - patch_gcc && - - mkdir -v build && cd build && - ../libstdc++-v3/configure \ - --target=${TARGET} \ - --build=${HOST} \ - --host=${TARGET} \ - --prefix=$TOOLS \ - --disable-multilib \ - --disable-nls \ - --disable-libstdcxx-threads \ - --disable-libstdcxx-pch \ - --with-gxx-include-dir=$TOOLS/${TARGET}/include/c++/$GCC_VER && - - make && - make install -} - -toolchain_tcl () { - local source="https://downloads.sourceforge.net/tcl/tcl$TCL_VER-src.tar.gz" - local filename=$(basename $source) - printf "${LIGHT_BLUE}Fetching $filename...${RESET}\n" - curl ${CURL_OPTS} $source > $filename - extract $filename - cd tcl$TCL_VER - - cd unix - ac_cv_func_strtod=yes \ - tcl_cv_strtod_buggy=1 \ - ./configure --build=${HOST} \ - --host=${TARGET} \ - --prefix=${TOOLS} && - - make && make install - - chmod -v u+w $TOOLS/lib/libtcl${TCL_VER%.*}.so - make install-private-headers - ln -sv tclsh${TCL_VER%.*} $TOOLS/bin/tclsh -} - -toolchain_expect () { - src "https://prdownloads.sourceforge.net/expect/expect$EXPECT_VER.tar.gz" - - PATCH_URL="https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/patches/expect-5.45.3" - ptch $PATCH_URL/dont-put-toolchain-in-libpath.patch - ptch $PATCH_URL/dont-configure-testsuites.patch - ptch $PATCH_URL/allow-cross-compile.patch - - curl ${CURL_OPTS} "https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/files/config.guess-musl" > tclconfig/config.guess - curl ${CURL_OPTS} "https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/files/config.sub-musl" > tclconfig/config.sub - cp -v configure configure.orig - sed 's:/usr/local/bin:/bin:' configure.orig > configure - - ./configure --build=${HOST} \ - --host=${TARGET} \ - --prefix=$TOOLS \ - --with-tcl=$TOOLS/lib \ - --with-tclinclude=$TOOLS/include && - - make && make SCRIPTS="" install -} - -toolchain_dejagnu () { - src "https://ftp.gnu.org/gnu/dejagnu/dejagnu-$DEJAGNU_VER.tar.gz" - ./configure --build=${HOST} \ - --host=${TARGET} \ - --prefix=$TOOLS && - - make && make install -} - -toolchain_m4 () { - src "https://ftp.gnu.org/gnu/m4/m4-$M4_VER.tar.xz" - - ./configure --prefix=$TOOLS \ - --build=${HOST} \ - --host=${TARGET} && - - make && make install -} - -toolchain_ncurses () { - src "https://invisible-mirror.net/archives/ncurses/ncurses-$NCURSES_VER.tar.gz" - sed -i s/mawk// configure - - # Configure source - ./configure --prefix=${TOOLS} \ - --build=${HOST} \ - --host=${TARGET} \ - --with-shared \ - --without-debug \ - --without-ada \ - --enable-widec \ - --enable-overwrite - make && make install - echo "INPUT(-lncursesw)" > ${TOOLS}/lib/libncurses.so - ln -s libncurses.so ${TOOLS}/lib/libcurses.so -} - -toolchain_bash () { - src "https://ftp.gnu.org/gnu/bash/bash-$BASH_VER.tar.gz" - - cat > config.cache << "EOF" -ac_cv_func_mmap_fixed_mapped=yes -ac_cv_func_strcoll_works=yes -ac_cv_func_working_mktime=yes -bash_cv_func_sigsetjmp=present -bash_cv_getcwd_malloc=yes -bash_cv_job_control_missing=present -bash_cv_printf_a_format=yes -bash_cv_sys_named_pipes=present -bash_cv_ulimit_maxfds=yes -bash_cv_under_sys_siglist=yes -bash_cv_unusable_rtsigs=no -gt_cv_int_divbyzero_sigfpe=yes -EOF - ./configure --prefix=${TOOLS} \ - --without-bash-malloc \ - --build=${HOST} \ - --host=${TARGET} \ - --cache-file=config.cache && - - make && make install -} - -toolchain_bison () { - src "https://ftp.gnu.org/gnu/bison/bison-$BISON_VER.tar.xz" - ./configure --prefix=${TOOLS} \ - --build=${HOST} \ - --host=${TARGET} && - make && make install -} - -toolchain_coreutils () { - git clone git://git.suckless.org/sbase sbase - cd sbase - make && make DESTDIR=$TOOLS install -} - -toolchain_diffutils () { - src "https://ftp.gnu.org/gnu/diffutils/diffutils-$DIFFUTILS_VER.tar.xz" - ./configure --prefix=${TOOLS} \ - --build=${HOST} \ - --host=${TARGET} - - make && make install -} - -toolchain_file () { - src "https://astron.com/pub/file/file-$FILE_VER.tar.gz" - ./configure --prefix=${TOOLS} \ - --build=${HOST} \ - --host=${TARGET} - make && make install -} - -toolchain_findutils () { - src "https://ftp.gnu.org/gnu/findutils/findutils-$FINDUTILS_VER.tar.xz" - sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' gl/lib/*.c && - sed -i '/unistd/a #include ' gl/lib/mountlist.c && - echo "#define _IO_IN_BACKUP 0x100" >> gl/lib/stdio-impl.h - - ./configure --prefix=${TOOLS} \ - --build=${HOST} \ - --host=${TARGET} - - make && make install -} - -toolchain_gawk () { - src "https://ftp.gnu.org/gnu/gawk/gawk-$GAWK_VER.tar.xz" - ./configure --prefix=${TOOLS} \ - --build=${HOST} \ - --host=${TARGET} - make && make install -} - -toolchain_gettext () { - src "https://ftp.barfooze.de/pub/sabotage/tarballs/gettext-tiny-$GETTEXT_TINY_VER.tar.xz" - make ${MJ} LIBINTL=MUSL prefix=$TOOLS - cp -v msgfmt msgmerge xgettext $TOOLS/bin -} - -toolchain_grep () { - src "https://ftp.gnu.org/gnu/grep/grep-$GREP_VER.tar.xz" - - ./configure --prefix=${TOOLS} \ - --build=${HOST} \ - --host=${TARGET} && - make && make install -} - -toolchain_make () { - src "https://ftp.gnu.org/gnu/make/make-$MAKE_VER.tar.gz" - - ./configure --prefix=${TOOLS} \ - --build=${HOST} \ - --host=${TARGET} \ - --without-guile && - make && make install -} - -toolchain_patch () { - src "https://ftp.gnu.org/gnu/patch/patch-$PATCH_VER.tar.xz" - ./configure --prefix=${TOOLS} \ - --build=${HOST} \ - --host=${TARGET} && - make && make install -} - -toolchain_sed () { - src "https://ftp.gnu.org/gnu/sed/sed-$SED_VER.tar.xz" - ./configure --prefix=${TOOLS} \ - --build=${HOST} \ - --host=${TARGET} && - make && make install -} - -#toolchain_perl () { -# src "https://github.com/arsv/perl-cross/releases/download/$PERL_CROSS_VER/perl-cross-$PERL_CROSS_VER.tar.gz" -# src "https://www.cpan.org/src/5.0/perl-$PERL_VER.tar.xz" -# -# cp -vrf ../perl-cross-$PERL_CROSS_VER/* ./ -# -# ./configure --prefix=${TOOLS} \ -# --target=${TARGET} && -# make && -# cp -v perl cpan/podlators/scripts/pod2man ${TOOLS}/bin && -# mkdir -pv ${TOOLS}/lib/perl5/$PERL_VER && -# cp -Rv lib/* ${TOOLS}/lib/perl5/$PERL_VER -#} - -toolchain_texinfo () { - src "https://ftp.gnu.org/gnu/texinfo/texinfo-$TEXINFO_VER.tar.xz" - ./configure --prefix=${TOOLS} \ - --build=${HOST} \ - --host=${TARGET} && - make && make install -} - -toolchain_flex () { - src "https://github.com/westes/flex/releases/download/v$FLEX_VER/flex-$FLEX_VER.tar.gz" - - ac_cv_func_malloc_0_nonnull=yes \ - ac_cv_func_realloc_0_nonnull=yes \ - HELP2MAN=${TOOLS}/bin/true \ - ./configure --prefix=${TOOLS} \ - --build=${HOST} \ - --host=${TARGET} - make && make install -} - -toolchain_strip () { - find ${TOOLS}/lib -type f -exec strip --strip-unneeded {} \; - /usr/bin/strip --strip-unneeded ${TOOLS}/bin/* ${TOOLS}/sbin/* - - # Remove the documentation: - rm -rf ${TOOLS}/share/info \ - ${TOOLS}/share/man \ - ${TOOLS}/share/doc \ - ${TOOLS}/info \ - ${TOOLS}/man \ - ${TOOLS}/doc - - find ${TOOLS}/lib ${TOOLS}/libexec -name \*.la -exec rm -rvf {} \; -} - -printf "${BLUE}building musl...\n${RESET}" -toolchain_musl || die "Failed building musl" -toolchain_adjustments - #perl \ -for p in \ - binutils \ - gcc \ - kernel_headers \ - libstdcxx \ - tcl \ - expect \ - dejagnu \ - m4 \ - ncurses \ - bash \ - bison \ - coreutils \ - diffutils \ - file \ - findutils \ - gawk \ - gettext \ - grep \ - make\ - patch \ - sed \ - texinfo \ - flex \ - ; do - - printf "${BLUE}building $p...\n${RESET}" - set_env - toolchain_$p || die "Failed building $p" -done - -printf "${GREEN}finished building toolchain${RESET}\n" -- cgit v1.2.1