summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbootstrap/bootstrap.sh185
-rw-r--r--bootstrap/cross_tools.sh165
-rw-r--r--bootstrap/toolchain.sh507
-rw-r--r--xibuild/build_profile3
4 files changed, 860 insertions, 0 deletions
diff --git a/bootstrap/bootstrap.sh b/bootstrap/bootstrap.sh
new file mode 100755
index 0000000..191bebc
--- /dev/null
+++ b/bootstrap/bootstrap.sh
@@ -0,0 +1,185 @@
+#!/bin/sh
+
+
+## VERSIONS ##
+# TODO move to a different package
+
+LINUX_VER=5.16.11
+BINUTILS_VER=2.38
+MPFR_VER=4.1.0
+MPC_VER=1.2.1
+GMP_VER=6.2.1
+GCC_VER=11.2.0
+MUSL_VER=1.2.2
+FILE_VER=5.41
+TCL_VER=8.6.12
+M4_VER=1.4.19
+EXPECT_VER=5.45.4
+DEJAGNU_VER=1.6.3
+NCURSES_VER=6.3
+BASH_VER=5.1.16
+BISON_VER=3.8.2
+BZIP2_VER=1.0.8
+COREUTILS_VER=9.0
+DIFFUTILS_VER=3.8
+GAWK_VER=5.1.1
+GETTEXT_VER=0.21
+GREP_VER=3.7
+GZIP_VER=1.11
+MAKE_VER=4.3
+PATCH_VER=2.7.6
+SED_VER=4.8
+PERL_VER=5.34.0
+TEXINFO_VER=6.8
+FLEX_VER=2.6.4
+PERL_CROSS_VER=1.3.6
+GETTEXT_TINY_VER=0.3.2
+FINDUTILS_VER=4.9.0
+
+####
+
+CURL_OPTS="-SsL"
+
+WD=$(pwd)/working
+
+TARGET=x86_64-linux-musl
+ARCH=x86
+CPU=x86-64
+
+CROSS_TOOLS=/cross-tools
+TOOLS=/tools
+
+PATH=${TOOLS}/bin:${CROSS_TOOLS}/bin:/usr/bin
+
+MAKEFLAGS="-j$(nproc)"
+
+export CHROOT TARGET PATH WD CURL_OPTS CROSS_TOOLS TOOLS MAKEFLAGS
+
+unset CFLAGS CXXFLAGS
+
+die () {
+ printf "${RED}$@${RESET}\n"
+ exit 1
+}
+
+extract () {
+ FILE=$1
+ case "${FILE##*.}" in
+ "gz" )
+ tar -zxf $FILE
+ ;;
+ "lz" )
+ tar --lzip -xf "$FILE"
+ ;;
+ "zip" )
+ unzip $FILE
+ ;;
+ * )
+ tar -xf $FILE
+ ;;
+ esac
+}
+
+src () {
+ cd ${WD}
+ local source=$1
+ local filename=$(basename $source)
+ printf "${LIGHT_BLUE}Fetching $filename...${RESET}\n"
+
+ curl ${CURL_OPTS} $source > $filename
+ extract $filename
+ cd ${filename%.t*}
+}
+
+ptch () {
+ local source=$1
+ local filename=$(basename $source)
+
+ printf "${LIGHT_BLUE}Patching $filename...${RESET}\n"
+ curl ${CURL_OPTS} $source > $filename
+ patch -Np1 -i $filename
+}
+
+clean () {
+ rm -rf $WD $CROSS_TOOLS $TOOLS
+ mkdir -pv $WD $CROSS_TOOLS $TOOL
+}
+
+patch_gcc () {
+ local PATCH_SRC="https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/patches/gcc-alpine"
+
+ ptch $PATCH_SRC/0001-posix_memalign.patch &&
+ ptch $PATCH_SRC/0003-Turn-on-Wl-z-relro-z-now-by-default.patch &&
+ ptch $PATCH_SRC/0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch &&
+ ptch $PATCH_SRC/0006-Enable-Wformat-and-Wformat-security-by-default.patch &&
+ ptch $PATCH_SRC/0007-Enable-Wtrampolines-by-default.patch &&
+ ptch $PATCH_SRC/0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch &&
+ ptch $PATCH_SRC/0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch &&
+ ptch $PATCH_SRC/0011-libiberty-copy-PIC-objects-during-build-process.patch &&
+ ptch $PATCH_SRC/0012-libitm-disable-FORTIFY.patch &&
+ ptch $PATCH_SRC/0013-libgcc_s.patch &&
+ ptch $PATCH_SRC/0014-nopie.patch &&
+ ptch $PATCH_SRC/0015-libffi-use-__linux__-instead-of-__gnu_linux__-for-mu.patch &&
+ ptch $PATCH_SRC/0016-dlang-update-zlib-binding.patch &&
+ ptch $PATCH_SRC/0017-dlang-fix-fcntl-on-mips-add-libucontext-dep.patch &&
+ ptch $PATCH_SRC/0018-ada-fix-shared-linking.patch &&
+ ptch $PATCH_SRC/0019-build-fix-CXXFLAGS_FOR_BUILD-passing.patch &&
+ ptch $PATCH_SRC/0020-add-fortify-headers-paths.patch &&
+ ptch $PATCH_SRC/0023-Pure-64-bit-MIPS.patch &&
+ ptch $PATCH_SRC/0024-use-pure-64-bit-configuration-where-appropriate.patch &&
+ ptch $PATCH_SRC/0025-always-build-libgcc_eh.a.patch &&
+ ptch $PATCH_SRC/0027-ada-musl-support-fixes.patch &&
+ ptch $PATCH_SRC/0028-gcc-go-Use-_off_t-type-instead-of-_loff_t.patch &&
+ ptch $PATCH_SRC/0029-gcc-go-Don-t-include-sys-user.h.patch &&
+ ptch $PATCH_SRC/0030-gcc-go-Fix-ucontext_t-on-PPC64.patch &&
+ ptch $PATCH_SRC/0031-gcc-go-Fix-handling-of-signal-34-on-musl.patch &&
+ ptch $PATCH_SRC/0032-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch &&
+ #ptch $PATCH_SRC/0034-gcc-go-signal-34-is-special-on-musl-libc &&
+ ptch $PATCH_SRC/0035-gcc-go-Prefer-_off_t-over-_off64_t.patch &&
+ ptch $PATCH_SRC/0036-gcc-go-undef-SETCONTEXT_CLOBBERS_TLS-in-proc.c.patch &&
+ ptch $PATCH_SRC/0037-gcc-go-link-to-libucontext.patch &&
+ ptch $PATCH_SRC/0038-gcc-go-Disable-printing-of-unaccessible-ppc64-struct.patch &&
+ ptch $PATCH_SRC/0041-Use-generic-errstr.go-implementation-on-musl.patch &&
+ ptch $PATCH_SRC/0042-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch &&
+ ptch $PATCH_SRC/0043-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch
+ #ptch $PATCH_SRC/0022-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch &&
+}
+
+package_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
+ tar -C ${chroot} -czf 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
+
diff --git a/bootstrap/cross_tools.sh b/bootstrap/cross_tools.sh
new file mode 100644
index 0000000..68fa048
--- /dev/null
+++ b/bootstrap/cross_tools.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/toolchain.sh b/bootstrap/toolchain.sh
new file mode 100644
index 0000000..5923bf3
--- /dev/null
+++ b/bootstrap/toolchain.sh
@@ -0,0 +1,507 @@
+#!/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 <sys/sysmacros.h>' 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"
diff --git a/xibuild/build_profile b/xibuild/build_profile
index d218fac..a009996 100644
--- a/xibuild/build_profile
+++ b/xibuild/build_profile
@@ -1,3 +1,6 @@
+export HOME=/root
+export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin
+
export MAKEFLAGS="-j$(grep "processor" /proc/cpuinfo | wc -l)"
export XORG_PREFIX="/usr"