#!/bin/bash -e # #©K. D. Hedger. Wed 3 Mar 14:36:07 GMT 2021 keithdhedger@gmail.com # #This file (BuildTools1) is part of LFSPkgBuilds. # #LFSPkgBuilds is free software: you can redistribute it and/or modify #it under the terms of the GNU General Public License as published by #the Free Software Foundation, either version 3 of the License, or #at your option) any later version. # #LFSPkgBuilds is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with LFSPkgBuilds. If not, see . # #Version 12.0 #Sanitize env [ ! -e /etc/bash.bashrc ] || sudo -p "Enter admin PW to move /etc/bash.bashrc aside : " mv -v /etc/bash.bashrc /etc/bash.bashrc.NOUSE [ "$HOME" != "" ] && exec -c /usr/bin/env -i USER=$USER TERM="$TERM" $0 RED='\e[1;31m' GREEN='\e[1;32m' NORMAL='\e[0;0m' trap 'echo -e "$0 ${RED}FAILED${NORMAL} at line ${GREEN}${LINENO}${NORMAL}"' ERR if [ -e ./SystemData ];then . ./SystemData else echo "No SystemData file found ..." exit 100 fi mkdir -vp "${LFS}${SOURCEARCHIVES}" "$LFS/${PKGARCHIVES}"|| true if ! mountpoint $LFS/${PKGARCHIVES} && ! mountpoint $LFS/${SOURCEARCHIVES} ;then if [ "X$EXTFOLDER" != "X" ];then sudo -p "Enter admin PW to bind $EXTFOLDER to $LFS/${PKGARCHIVES}: " mount --bind $EXTFOLDER/${PKGARCHIVES} $LFS/${PKGARCHIVES} sudo -p "Enter admin PW to bind $EXTFOLDER $LFS/${SOURCEARCHIVES}: " mount --bind $EXTFOLDER/${SOURCEARCHIVES} $LFS/${SOURCEARCHIVES} fi fi SYSTEMSOURCE="${LFS}${SOURCEARCHIVES}/SYSTEM" NETSOURCE="${LFS}${SOURCEARCHIVES}/NET" mkdir -vp "$SYSTEMSOURCE" "$NETSOURCE"|| true mkdir -pv $LFS/{bin,etc,lib${LIBDIRSUFFIX},sbin,usr,var,tmp,usr/lib${LIBDIRSUFFIX},usr/bin,usr/sbin} case $(uname -m) in x86_64) ln -sfnv lib${LIBDIRSUFFIX} $LFS/lib||true ln -sfnv lib${LIBDIRSUFFIX} $LFS/usr/lib||true ;; esac #mkdir -pv $LFS/{bin,etc,lib${LIBDIRSUFFIX},sbin,usr,var,tmp,usr/lib${LIBDIRSUFFIX}} case $(uname -m) in x86_64) ln -sfnv lib${LIBDIRSUFFIX} $LFS/lib ln -sfnv lib${LIBDIRSUFFIX} $LFS/usr/lib ;; esac mkdir -pv $LFS/tools sudo -p "Enter admin PW to set ownership of $LFS/*: " chown -v $USER $LFS/{usr,lib${LIBDIRSUFFIX},var,etc,bin,sbin,tools,tmp,usr/lib${LIBDIRSUFFIX}} cp ./SystemData* $SYSTEMSOURCE WGET_version=1.21.4 WGETTAR="https://ftp.gnu.org/gnu/wget/wget-$WGET_version.tar.gz" set +h umask 022 LC_ALL=POSIX case $(uname -m) in armv*) LFS_TGT=$(uname -m)-lfs-linux-gnueabihf ;; *) LFS_TGT=$(uname -m)-lfs-linux-gnu ;; esac PATH=/usr/bin if [ ! -L /bin ];then PATH=/bin:$PATH fi PATH=$LFS/tools/bin:$PATH CONFIG_SITE=$LFS/usr/share/config.site MAKEFLAGS="-j$(($(nproc)-1))" SYSTEMCONFIGOPTIONS="--prefix=/usr --sysconfdir=/etc --libexecdir=/usr/libexec --libdir=/usr/lib${LIBDIRSUFFIX} --bindir=/bin --sbindir=/sbin --disable-nls --disable-static" USRCONFIGOPTIONS="-prefix=/usr --sysconfdir=/etc --libexecdir=/usr/libexec --libdir=/usr/lib${LIBDIRSUFFIX} --disable-nls --disable-static" export LFS LC_ALL LFS_TGT PATH CONFIG_SITE echo $PATH $LFS $LC_ALL $LFS_TGT $CONFIG_SITE if [ ! -e "${SYSTEMSOURCE}/gotsystem" ];then if [ "$USESYSTEMD" -eq 1 ];then wget --no-check-certificate http://www.linuxfromscratch.org/lfs/view/systemd/wget-list wget --no-check-certificate http://www.linuxfromscratch.org/lfs/view/systemd/md5sums ./GetVersions else wget --no-check-certificate https://www.linuxfromscratch.org/lfs/view/$LFSVERSION/wget-list-sysv wget --no-check-certificate http://www.linuxfromscratch.org/lfs/view/$LFSVERSION/md5sums ./GetVersions fi mv md5sums $SYSTEMSOURCE wget --no-check-certificate -i wget-list --no-check-certificate -c -P $SYSTEMSOURCE||true #wget from the blfs book I prefer to make this as part of the main system wget --no-check-certificate -c "$WGETTAR" -P $NETSOURCE fi if [ -e ./PkgVersions ];then . ./PkgVersions else echo "No PkgVersions file found ..." exit 100 fi cd "$SYSTEMSOURCE" if [ ! -e ${SYSTEMSOURCE}/gotsystem ];then if ! md5sum -c md5sums;then echo "Files don't match ..." exit 1 else echo "All files check ..." touch "${SYSTEMSOURCE}/gotsystem" fi if [ "$PIBUILD" -eq 1 ];then wget --continue https://intestinate.com/pilfs/scripts/pilfs-bootscripts-20190902.tar.xz wget --continue https://github.com/raspberrypi/linux/archive/rpi-5.10.y.tar.gz wget --continue https://github.com/raspberrypi/firmware/archive/master.tar.gz -O firmware-master-5.10.tar.gz wget --no-check-certificate -c https://github.com/RPi-Distro/firmware-nonfree/archive/master.tar.gz -O firmware-RPI-blobs.tar.gz wget --continue https://github.com/raspberrypi/rpi-eeprom/archive/v2020.09.03-138a1.tar.gz wget --continue https://intestinate.com/pilfs/patches/gcc-9.1.0-rpi1-cpu-default.patch wget --continue https://intestinate.com/pilfs/patches/gcc-9.1.0-rpi2-cpu-default.patch wget --continue https://intestinate.com/pilfs/patches/gcc-9.1.0-rpi3-cpu-default.patch wget --continue https://intestinate.com/pilfs/patches/gcc-9.1.0-rpi4-cpu-default.patch fi fi TOOLNUM=$(cat ${SYSTEMSOURCE}/toolnum 2>/dev/null||true) if [ "X$TOOLNUM" = "X" ];then TOOLNUM=1 echo $TOOLNUM > ${SYSTEMSOURCE}/toolnum fi while [ $TOOLNUM != "DONE" ] do cd "$SYSTEMSOURCE" case $TOOLNUM in 1) NAME=binutils VERSION=$binutils_version tar -xvf ${NAME}-${VERSION}.$binutils_arctype pushd ${NAME}-${VERSION} rm -rf build mkdir -vp build cd build #../configure --prefix=$LFS/tools --with-sysroot=$LFS --target=$LFS_TGT --disable-nls --enable-gprofng=no --disable-werror ../configure --prefix=$LFS/tools --with-sysroot=$LFS --target=$LFS_TGT --disable-nls --enable-gprofng=no --disable-werror make $MAKEFLAGS||make make install popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 2) #pass 1 NAME=gcc VERSION=$gcc_version tar -xvf ${NAME}-${VERSION}.$gcc_arctype pushd ${NAME}-${VERSION} tar -Jxf ../mpfr-${mpfr_version}.$mpfr_arctype mv -v mpfr-$mpfr_version mpfr tar -Jxf ../gmp-${gmp_version}.$gmp_arctype mv -v gmp-$gmp_version gmp tar -zxf ../mpc-${mpc_version}.$mpc_arctype mv -v mpc-$mpc_version mpc case $(uname -m) in armv*) patch -Np1 -i ../gcc-9.1.0-rpi$PIVERS-cpu-default.patch ;; *) sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64 ;; esac rm -rf build mkdir -vp build cd build ../configure --target=$LFS_TGT --prefix=$LFS/tools --with-glibc-version=2.38 --with-sysroot=$LFS --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 $MAKEFLAGS||make -j1 make install cd .. cat gcc/limitx.h gcc/glimits.h gcc/limity.h > $(dirname $($LFS_TGT-gcc -print-libgcc-file-name))/include/limits.h popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 3) NAME=linux VERSION=$linux_version tar -xvf ${NAME}-${VERSION}.$linux_arctype pushd ${NAME}-${VERSION} make mrproper make headers find usr/include -type f ! -name '*.h' -delete cp -rv usr/include $LFS/usr popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 4) NAME=glibc VERSION=$glibc_version tar -xvf ${NAME}-${VERSION}.$glibc_arctype pushd ${NAME}-${VERSION} case $(uname -m) in i?86) ln -sfv ld-linux.so.2 $LFS/lib/ld-lsb.so.3 ;; x86_64) ln -sfv ld-linux-x86-64.so.2 $LFS/lib${LIBDIRSUFFIX}/ld-lsb-x86-64.so.3 ;; esac patch -Np1 -i ../${NAME}-${VERSION}-fhs-1.patch rm -rf build||true mkdir -vp build cd build echo "rootsbindir=/usr/sbin" > configparms # ../configure --prefix=/usr --host=$LFS_TGT --build=$(../scripts/config.guess) --enable-kernel=4.14 --with-headers=$LFS/usr/include libc_cv_slibdir=/usr/lib ../configure $SYSTEMCONFIGOPTIONS --host=$LFS_TGT --build=$(../scripts/config.guess) --enable-kernel=4.14 --with-headers=$LFS/usr/include libc_cv_slibdir=/lib make $MAKEFLAGS||make -j1|| exit 100 make DESTDIR=$LFS install sed '/RTLDLIST=/s@/usr@@g' -i $LFS/bin/ldd popd rm -rf ${NAME}-${VERSION} echo 'int main(){}' > dummy.c $LFS_TGT-gcc dummy.c readelf -l a.out | grep '/ld-linux' read -t 30 -p "check out " ||true rm -v dummy.c a.out #$LFS/tools/libexec/gcc/$LFS_TGT/$gcc_version/install-tools/mkheaders echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 5) #libstdc++ NAME=gcc VERSION=$gcc_version tar -xvf ${NAME}-${VERSION}.$gcc_arctype pushd ${NAME}-${VERSION} rm -rf build mkdir -pv build cd build ../libstdc++-v3/configure $SYSTEMCONFIGOPTIONS --host=$LFS_TGT --build=$(../config.guess) --disable-multilib --disable-libstdcxx-pch --with-gxx-include-dir=/tools/$LFS_TGT/include/c++/${VERSION} make $MAKEFLAGS||make make DESTDIR=$LFS install rm -v $LFS/usr/lib/lib{stdc++,stdc++fs,supc++}.la #rm -v $LFS/lib/lib{stdc++,stdc++fs,supc++}.la||exit 100 popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 6) NAME=m4 VERSION=$m4_version tar -xvf ${NAME}-${VERSION}.$m4_arctype pushd ${NAME}-${VERSION} ./configure $USRCONFIGOPTIONS --host=$LFS_TGT --build=$(build-aux/config.guess) make $MAKEFLAGS||make make DESTDIR=$LFS install popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 7) NAME=ncurses VERSION=$ncurses_version tar -xvf ${NAME}-${VERSION}.$ncurses_arctype pushd ${NAME}-${VERSION} sed -i s/mawk// configure rm -rf build||true mkdir build pushd build ../configure make -C include make -C progs tic popd ./configure $USRCONFIGOPTIONS --host=$LFS_TGT --build=$(./config.guess) --mandir=/usr/share/man --with-manpage-format=normal --with-shared --without-debug --without-ada --without-normal --enable-widec --with-cxx-shared --disable-stripping --enable-widec make $MAKEFLAGS||make make DESTDIR=$LFS TIC_PATH=$(pwd)/build/progs/tic install echo "INPUT(-lncursesw)" > $LFS/usr/lib/libncurses.so popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 8) NAME=bash VERSION=$bash_version tar -xvf ${NAME}-${VERSION}.$bash_arctype pushd ${NAME}-${VERSION} ./configure $SYSTEMCONFIGOPTIONS --build=$(sh support/config.guess) --host=$LFS_TGT --without-bash-malloc make $MAKEFLAGS||make make DESTDIR=$LFS install #mv $LFS/usr/bin/bash $LFS/bin/bash||exit 100 ln -sfnv bash $LFS/bin/sh popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 9) NAME=coreutils VERSION=$coreutils_version tar -xvf ${NAME}-${VERSION}.$coreutils_arctype pushd ${NAME}-${VERSION} ./configure $USRCONFIGOPTIONS --host=$LFS_TGT --build=$(build-aux/config.guess) --enable-install-program=hostname --enable-no-install-program=kill,uptime gl_cv_macro_MB_CUR_MAX_good=y make $MAKEFLAGS||make make DESTDIR=$LFS install mv -v $LFS/usr/bin/chroot $LFS/sbin mkdir -pv $LFS/usr/share/man/man8 mv -v $LFS/usr/share/man/man1/chroot.1 $LFS/usr/share/man/man8/chroot.8 sed -i 's/"1"/"8"/' $LFS/usr/share/man/man8/chroot.8 popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 10) NAME=diffutils VERSION=$diffutils_version tar -xvf ${NAME}-${VERSION}.$diffutils_arctype pushd ${NAME}-${VERSION} ./configure $USRCONFIGOPTIONS --host=$LFS_TGT --build=$(./build-aux/config.guess) make $MAKEFLAGS||make make DESTDIR=$LFS install popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 11) NAME=file VERSION=$file_version tar -xvf ${NAME}-${VERSION}.$file_arctype pushd ${NAME}-${VERSION} rm -rf build||true mkdir build pushd build ../configure --disable-bzlib --disable-libseccomp --disable-xzlib --disable-zlib make popd ./configure $USRCONFIGOPTIONS --host=$LFS_TGT --build=$(./config.guess) make FILE_COMPILE=$(pwd)/build/src/file make DESTDIR=$LFS install rm -v $LFS/usr/lib/libmagic.la #hack if [ "$USESYSTEMD" -eq 1 ];then mv -v $LFS/usr/lib/libmagic.so.* $LFS/lib ln -sfv ../../lib/$(readlink /usr/lib/libmagic.so) $LFS/usr/lib/libmagic.so fi popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 12) NAME=findutils VERSION=$findutils_version tar -xvf ${NAME}-${VERSION}.$findutils_arctype pushd ${NAME}-${VERSION} ./configure $USRCONFIGOPTIONS --localstatedir=/var/lib/locate --host=$LFS_TGT --build=$(build-aux/config.guess) make $MAKEFLAGS||make make DESTDIR=$LFS install popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 13) NAME=gawk VERSION=$gawk_version tar -xvf ${NAME}-${VERSION}.$gawk_arctype pushd ${NAME}-${VERSION} sed -i 's/extras//' Makefile.in ./configure $USRCONFIGOPTIONS --host=$LFS_TGT --build=$(./config.guess) make $MAKEFLAGS||make make DESTDIR=$LFS install popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 14) NAME=grep VERSION=$grep_version tar -xvf ${NAME}-${VERSION}.$grep_arctype pushd ${NAME}-${VERSION} ./configure $USRCONFIGOPTIONS --host=$LFS_TGT --build=$(./build-aux/config.guess) make $MAKEFLAGS||make make DESTDIR=$LFS install popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 15) NAME=gzip VERSION=$gzip_version tar -xvf ${NAME}-${VERSION}.$gzip_arctype pushd ${NAME}-${VERSION} ./configure $SYSTEMCONFIGOPTIONS --host=$LFS_TGT make $MAKEFLAGS||make make DESTDIR=$LFS install popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 16) NAME=make VERSION=$make_version tar -xvf ${NAME}-${VERSION}.$make_arctype pushd ${NAME}-${VERSION} #sed -e '/ifdef SIGPIPE/,+2 d' -e '/undef FATAL_SIG/i FATAL_SIG (SIGPIPE);' -i src/main.c ./configure $USRCONFIGOPTIONS --without-guile --host=$LFS_TGT --build=$(build-aux/config.guess) make $MAKEFLAGS||make make DESTDIR=$LFS install popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 17) NAME=patch VERSION=$patch_version tar -xvf ${NAME}-${VERSION}.$patch_arctype pushd ${NAME}-${VERSION} ./configure $USRCONFIGOPTIONS --host=$LFS_TGT --build=$(build-aux/config.guess) make $MAKEFLAGS||make make DESTDIR=$LFS install popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 18) NAME=sed VERSION=$sed_version tar -xvf ${NAME}-${VERSION}.$sed_arctype pushd ${NAME}-${VERSION} ./configure $USRCONFIGOPTIONS --host=$LFS_TGT make $MAKEFLAGS||make make DESTDIR=$LFS install popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 19) NAME=tar VERSION=$tar_version tar -xvf ${NAME}-${VERSION}.$tar_arctype pushd ${NAME}-${VERSION} ./configure $SYSTEMCONFIGOPTIONS --host=$LFS_TGT --build=$(build-aux/config.guess) make $MAKEFLAGS||make make DESTDIR=$LFS install popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 20) NAME=xz VERSION=$xz_version tar -xvf${NAME}-${VERSION}.$xz_arctype pushd ${NAME}-${VERSION} ./configure $SYSTEMCONFIGOPTIONS --host=$LFS_TGT --build=$(build-aux/config.guess) --docdir=/usr/share/doc/xz-${VERSION} make $MAKEFLAGS||make make DESTDIR=$LFS install rm -v $LFS/usr/lib/liblzma.la popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 21) #pass 2 NAME=binutils VERSION=$binutils_version tar -xvf ${NAME}-${VERSION}.$binutils_arctype pushd ${NAME}-${VERSION} sed '6009s/$add_dir//' -i ltmain.sh rm -rf build mkdir -v build cd build ../configure $USRCONFIGOPTIONS --build=$(../config.guess) --host=$LFS_TGT --enable-shared --enable-gprofng=no --disable-werror --enable-64-bit-bfd make $MAKEFLAGS||make make DESTDIR=$LFS install rm -v $LFS/usr/lib/lib{bfd,ctf,ctf-nobfd,opcodes}.la popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 22) #pass 2 NAME=gcc VERSION=$gcc_version tar -xvf ${NAME}-${VERSION}.$gcc_arctype pushd ${NAME}-${VERSION} case $(uname -m) in x86_64) sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64 ;; esac tar -xf ../mpfr-${mpfr_version}.$mpfr_arctype mv -v mpfr-$mpfr_version mpfr tar -xf ../gmp-${gmp_version}.$gmp_arctype mv -v gmp-$gmp_version gmp tar -xf ../mpc-${mpc_version}.$mpc_arctype mv -v mpc-$mpc_version mpc sed '/thread_header =/s/@.*@/gthr-posix.h/' -i libgcc/Makefile.in libstdc++-v3/include/Makefile.in rm -rf build mkdir -v build cd build mkdir -pv $LFS_TGT/libgcc ln -s ../../../libgcc/gthr-posix.h $LFS_TGT/libgcc/gthr-default.h ../configure $USRCONFIGOPTIONS --build=$(../config.guess) --host=$LFS_TGT --target=$LFS_TGT LDFLAGS_FOR_TARGET=-L$PWD/$LFS_TGT/libgcc --with-build-sysroot=$LFS --enable-default-pie --enable-default-ssp --disable-multilib --disable-libatomic --disable-libgomp --disable-libquadmath --disable-libsanitizer --disable-libssp --disable-libvtv --enable-languages=c,c++ make $MAKEFLAGS||make make DESTDIR=$LFS install ln -sfnv gcc $LFS/usr/bin/cc popd rm -rf ${NAME}-${VERSION} echo "$((++ TOOLNUM))" > ${SYSTEMSOURCE}/toolnum ;; 23) sudo -p "Enter admin PW to set ownership of $LFS/* back to root: " chown -R root:root $LFS/{usr,lib${LIBDIRSUFFIX},var,etc,bin,sbin,tools} echo "DONE" > ${SYSTEMSOURCE}/toolnum TOOLNUM="DONE" ;; esac done