#!/usr/bin/env bash
#

#set -eux -o pipefail
export LFS=/mnt/lfs
export MAKEFLAGS=-j32
set +h
umask 022
LC_ALL=POSIX
LFS_TGT=$(uname -m)-lfs-linux-gnu
PATH=/usr/bin
if [ ! -L /bin ]; then PATH=/bin:$PATH; fi
PATH=$LFS/tools/bin:$PATH
CONFIG_SITE=$LFS/usr/share/config.site
export LFS LC_ALL LFS_TGT PATH CONFIG_SITE

#sudo umount -R $LFS/{proc,sys,run,dev/{pts,shm,}}
#sudo rm -rf $LFS


function 3.1-get_sources(){
	mkdir -pv $LFS/sources
	chmod -v a+wt $LFS/sources
	wget https://lfs.maru-na.net/lfs/view/stable/wget-list-sysv
	wget https://lfs.maru-na.net/lfs/view/stable/md5sums
	wget --input-file=wget-list-sysv --continue --directory-prefix=$LFS/sources
	wget https://sourceforge.net/projects/expat/files/expat/2.6.4/expat-2.6.4.tar.xz --directory-prefix=$LFS/sources
}

function 4.2-folder_structure(){
	mkdir -pv $LFS/sources
	chmod -v a+wt $LFS/sources
	mkdir -pv $LFS/{root,etc,var} $LFS/usr/{bin,lib,sbin}

	for i in bin lib sbin; do
  		ln -svf usr/$i $LFS/$i
	done

	case $(uname -m) in
  		x86_64) mkdir -pv $LFS/lib64 ;;
	esac

	mkdir -pv $LFS/tools
}

#function 4.4-configure_environment(){
#	source /home/lomig/dev/bash_profile
#	source /home/lomig/dev/bashrc
#}


function 5.2-binutils(){
	echo "binutils"
	cd $LFS/sources
	tar -xf binutils-${1}.tar.xz
	cd binutils-${1}
	mkdir -v build
	cd build
	../configure --prefix=$LFS/tools \
		     --with-sysroot=$LFS \
		     --target=$LFS_TGT   \
		     --disable-nls       \
		     --enable-gprofng=no \
		     --disable-werror    \
		     --enable-new-dtags  \
		     --enable-default-hash-style=gnu
	make
	make install

	cd $LFS/sources
	rm -rf binutils-${1}
}

function 5.3-gcc(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf gcc-${1}.tar.xz
	cd gcc-${1}
	tar --use-compress-program=pixz -xf ../mpfr-4.2.1.tar.xz
	mv -v mpfr-4.2.1 mpfr
	tar --use-compress-program=pixz -xf ../gmp-6.3.0.tar.xz
	mv -v gmp-6.3.0 gmp
	tar --use-compress-program=pigz -xf ../mpc-1.3.1.tar.gz
	mv -v mpc-1.3.1 mpc

	sed -e '/m64=/s/lib64/lib/' \
        	-i.orig gcc/config/i386/t-linux64
	mkdir build
	cd build
	../configure                  \
		--target=$LFS_TGT         \
		--prefix=$LFS/tools       \
		--with-glibc-version=2.40 \
		--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
	make install
	cd ..
	cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
		`dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include/limits.h

	cd $LFS/sources
	rm -rf gcc-${1}
}

function 5.4-linux_headers(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf linux-${1}.tar.xz
	cd linux-${1}
	make mrproper
	make headers
	find usr/include -type f ! -name '*.h' -delete
	cp -rv usr/include $LFS/usr

	cd $LFS/sources
	rm -rf linux-${1}
}

function 5.5-glibc(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf glibc-${1}.tar.xz
	cd glibc-${1}
	ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64
	ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64/ld-lsb-x86-64.so.3
	patch -Np1 -i ../glibc-2.40-fhs-1.patch

	mkdir build
	cd build
	echo "rootsbindir=/usr/sbin" > configparms
	../configure                             \
	      --prefix=/usr                      \
	      --host=$LFS_TGT                    \
	      --build=$(../scripts/config.guess) \
	      --enable-kernel=4.19               \
	      --with-headers=$LFS/usr/include    \
	      --disable-nscd                     \
	      libc_cv_slibdir=/usr/lib
	make
	make DESTDIR=$LFS install

	sed '/RTLDLIST=/s@/usr@@g' -i $LFS/usr/bin/ldd
	echo 'int main(){}' | gcc -xc -
	readelf -l a.out | grep ld-linux
	rm -v a.out

	cd $LFS/sources
	rm -rf glibc-${1}
}

function 5.6-libstdcpp(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf gcc-${1}.tar.xz
	cd gcc-${1}
	mkdir build
	cd build
	../libstdc++-v3/configure           \
		--host=$LFS_TGT                 \
		--build=$(../config.guess)      \
		--prefix=/usr                   \
		--disable-multilib              \
		--disable-nls                   \
		--disable-libstdcxx-pch         \
		--with-gxx-include-dir=/tools/$LFS_TGT/include/c++/14.2.0
	make
	make DESTDIR=$LFS install
	rm -v $LFS/usr/lib/lib{stdc++{,exp,fs},supc++}.la

	cd $LFS/sources
	rm -rf gcc-${1}
}

function 6.2-m4(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf m4-${1}.tar.xz
	cd m4-${1}
	./configure --prefix=/usr   \
        --host=$LFS_TGT \
        --build=$(build-aux/config.guess)
	make
	make DESTDIR=$LFS install

	cd $LFS/sources
	rm -rf m4-${1}
}

function 6.3-ncurses(){
	cd $LFS/sources
	tar --use-compress-program=pigz -xf ncurses-${1}.tar.gz
	cd ncurses-${1}
	sed -i s/mawk// configure
	mkdir build
	pushd build
	../configure
	make -C include
	make -C progs tic
	popd
	./configure --prefix=/usr                \
		--host=$LFS_TGT              \
		--build=$(./config.guess)    \
		--mandir=/usr/share/man      \
		--with-manpage-format=normal \
		--with-shared                \
		--without-normal             \
		--with-cxx-shared            \
		--without-debug              \
		--without-ada                \
		--disable-stripping
	make
	make DESTDIR=$LFS TIC_PATH=$(pwd)/build/progs/tic install
	ln -sv libncursesw.so $LFS/usr/lib/libncurses.so
	sed -e 's/^#if.*XOPEN.*$/#if 1/' \
    	-i $LFS/usr/include/curses.h

	cd $LFS/sources
	rm -rf ncurses-${1}
}

function 6.4-bash(){
	cd $LFS/sources
	tar --use-compress-program=pigz -xf bash-${1}.tar.gz
	cd bash-${1}
	./configure --prefix=/usr                      \
            --build=$(sh support/config.guess) \
            --host=$LFS_TGT                    \
            --without-bash-malloc              \
            bash_cv_strtold_broken=no
	make
	make DESTDIR=$LFS install
	ln -sv bash $LFS/bin/sh

	cd $LFS/sources
	rm -rf bash-${1}
}

function 6.5-coreutils(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf coreutils-${1}.tar.xz
	cd coreutils-${1}
	./configure --prefix=/usr                     \
            --host=$LFS_TGT                   \
            --build=$(build-aux/config.guess) \
            --enable-install-program=hostname \
            --enable-no-install-program=kill,uptime
	make
	make DESTDIR=$LFS install
	mv -v $LFS/usr/bin/chroot $LFS/usr/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

	cd $LFS/sources
	rm -rf coreutils-${1}
}

function 6.6-diffutils(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf diffutils-${1}.tar.xz
	cd diffutils-${1}

	./configure --prefix=/usr   \
            --host=$LFS_TGT \
            --build=$(./build-aux/config.guess)
	make
	make DESTDIR=$LFS install

	cd $LFS/sources
	rm -rf diffutils-${1}
}

function 6.7-file(){
	cd $LFS/sources
	tar --use-compress-program=pigz -xf file-${1}.tar.gz
	cd file-${1}

	mkdir build
	pushd build
	../configure --disable-bzlib      \
				--disable-libseccomp \
				--disable-xzlib      \
				--disable-zlib
	make
	popd
	./configure --prefix=/usr --host=$LFS_TGT --build=$(./config.guess)
	make FILE_COMPILE=$(pwd)/build/src/file
	make DESTDIR=$LFS install
	rm -v $LFS/usr/lib/libmagic.la

	cd $LFS/sources
	rm -rf file-${1}
}

function 6.8-findutils(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf findutils-${1}.tar.xz
	cd findutils-${1}
	./configure --prefix=/usr                   \
            --localstatedir=/var/lib/locate \
            --host=$LFS_TGT                 \
            --build=$(build-aux/config.guess)
	make
	make DESTDIR=$LFS install

	cd $LFS/sources
	rm -rf findutils-${1}
}

function 6.9-gawk(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf gawk-${1}.tar.xz
	cd gawk-${1}
	sed -i 's/extras//' Makefile.in
	./configure --prefix=/usr   \
            --host=$LFS_TGT \
            --build=$(build-aux/config.guess)
	make
	make DESTDIR=$LFS install

	cd $LFS/sources
	rm -rf gawk-${1}
}

function 6.10-grep(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf grep-${1}.tar.xz
	cd grep-${1}
	./configure --prefix=/usr   \
            --host=$LFS_TGT \
            --build=$(./build-aux/config.guess)
	make
	make DESTDIR=$LFS install

	cd $LFS/sources
	rm -rf grep-${1}
}

function 6.11-gzip(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf gzip-${1}.tar.xz
	cd gzip-${1}
	./configure --prefix=/usr --host=$LFS_TGT
	make
	make DESTDIR=$LFS install

	cd $LFS/sources
	rm -rf gzip-${1}
}

function 6.12-make(){
	cd $LFS/sources
	tar --use-compress-program=pigz -xf make-${1}.tar.gz
	cd make-${1}
	./configure --prefix=/usr   \
            --without-guile \
            --host=$LFS_TGT \
            --build=$(build-aux/config.guess)
	make
	make DESTDIR=$LFS install

	cd $LFS/sources
	rm -rf make-${1}
}

function 6.13-patch(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf patch-${1}.tar.xz
	cd patch-${1}
	./configure --prefix=/usr   \
            --host=$LFS_TGT \
            --build=$(build-aux/config.guess)
	make
	make DESTDIR=$LFS install

	cd $LFS/sources
	rm -rf patch-${1}
}

function 6.14-sed(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf sed-${1}.tar.xz
	cd sed-${1}
	./configure --prefix=/usr   \
            --host=$LFS_TGT \
            --build=$(./build-aux/config.guess)
	make
	make DESTDIR=$LFS install

	cd $LFS/sources
	rm -rf sed-${1}
}

function 6.15-tar(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf tar-${1}.tar.xz
	cd tar-${1}
	./configure --prefix=/usr                     \
            --host=$LFS_TGT                   \
            --build=$(build-aux/config.guess)
	make
	make DESTDIR=$LFS install

	cd $LFS/sources
	rm -rf tar-${1}
}

function 6.16-xz(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf xz-${1}.tar.xz
	cd xz-${1}
	./configure --prefix=/usr                     \
            --host=$LFS_TGT                   \
            --build=$(build-aux/config.guess) \
            --disable-static                  \
            --docdir=/usr/share/doc/xz-${1}
	make
	make DESTDIR=$LFS install
	rm -v $LFS/usr/lib/liblzma.la

	cd $LFS/sources
	rm -rf xz-${1}
}

function 6.17-binutils(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf binutils-${1}.tar.xz
	cd binutils-${1}
	sed '6009s/$add_dir//' -i ltmain.sh
	mkdir -v build
	cd build
	../configure                   \
		--prefix=/usr              \
		--build=$(../config.guess) \
		--host=$LFS_TGT            \
		--disable-nls              \
		--enable-shared            \
		--enable-gprofng=no        \
		--disable-werror           \
		--enable-64-bit-bfd        \
		--enable-new-dtags         \
		--enable-default-hash-style=gnu
	make
	make DESTDIR=$LFS install

	rm -v $LFS/usr/lib/lib{bfd,ctf,ctf-nobfd,opcodes,sframe}.{a,la}

	cd $LFS/sources
	rm -rf binutils-${1}
}

function 6.18-gcc(){
	cd $LFS/sources
	tar --use-compress-program=pixz -xf gcc-${1}.tar.xz
	cd gcc-${1}
	tar --use-compress-program=pixz -xf ../mpfr-4.2.1.tar.xz
	mv -v mpfr-4.2.1 mpfr
	tar --use-compress-program=pixz -xf ../gmp-6.3.0.tar.xz
	mv -v gmp-6.3.0 gmp
	tar --use-compress-program=pigz -xf ../mpc-1.3.1.tar.gz
	mv -v mpc-1.3.1 mpc

	sed -e '/m64=/s/lib64/lib/' \
        -i.orig gcc/config/i386/t-linux64
	sed '/thread_header =/s/@.*@/gthr-posix.h/' \
    	-i libgcc/Makefile.in libstdc++-v3/include/Makefile.in
	mkdir build
	cd build
	../configure                                       \
		--build=$(../config.guess)                     \
		--host=$LFS_TGT                                \
		--target=$LFS_TGT                              \
		LDFLAGS_FOR_TARGET=-L$PWD/$LFS_TGT/libgcc      \
		--prefix=/usr                                  \
		--with-build-sysroot=$LFS                      \
		--enable-default-pie                           \
		--enable-default-ssp                           \
		--disable-nls                                  \
		--disable-multilib                             \
		--disable-libatomic                            \
		--disable-libgomp                              \
		--disable-libquadmath                          \
		--disable-libsanitizer                         \
		--disable-libssp                               \
		--disable-libvtv                               \
		--enable-languages=c,c++
	make
	make DESTDIR=$LFS install
	ln -sv gcc $LFS/usr/bin/cc

	cd $LFS/sources
	rm -rf gcc-${1}
}



function 7.3-prepare-filesystem(){
	mkdir -pv $LFS/{dev,proc,sys,run}
	mkdir /dev/pts
	mount -t devpts devpts /dev/pts
	/sbin/chroot /mnt/lfs /usr/bin/env -i HOME=/root TERM="$TERM" PATH=/usr/bin:/usr/sbin:/bin:/sbin /root/post-chroot
}

function 7.5-create-folders(){
	cat << 'EOF' > $LFS/root/7.5-create-folders
#!/bin/bash
set -eux -o pipefail
rm -rf /dev/null
mknod -m 600 /dev/console c 5 1
mknod -m 666 /dev/null c 1 3
mkdir -pv /{boot,home,mnt,opt,srv}
mkdir -pv /etc/{opt,sysconfig}
mkdir -pv /lib/firmware
mkdir -pv /media/{floppy,cdrom}
mkdir -pv /usr/{,local/}{include,src}
mkdir -pv /usr/lib/locale
mkdir -pv /usr/local/{bin,lib,sbin}
mkdir -pv /usr/{,local/}share/{color,dict,doc,info,locale,man}
mkdir -pv /usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -pv /usr/{,local/}share/man/man{1..8}
mkdir -pv /var/{cache,local,log,mail,opt,spool}
mkdir -pv /var/lib/{color,misc,locate}

ln -sfv /run /var/run
ln -sfv /run/lock /var/lock

install -dv -m 0750 /root
install -dv -m 1777 /tmp /var/tmp
EOF
}

function 7.6-create-symbolic-links(){
	cat << 'EOF' > $LFS/root/7.6-create-symbolic-links
#!/bin/bash
set -eux -o pipefail
ln -sfv /proc/self/mounts /etc/mtab
cat > /etc/hosts << EOFa
127.0.0.1  localhost erminig
::1        localhost
EOFa
cat > /etc/passwd << EOFb
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/dev/null:/usr/bin/false
penn:x:3:3:penn:/var/lib/govel:/bin/bash
daemon:x:6:6:Daemon User:/dev/null:/usr/bin/false
messagebus:x:18:18:D-Bus Message Daemon User:/run/dbus:/usr/bin/false
uuidd:x:80:80:UUID Generation Daemon User:/dev/null:/usr/bin/false
nobody:x:65534:65534:Unprivileged User:/dev/null:/usr/bin/false
EOFb

cat > /etc/group << EOFc
root:x:0:
bin:x:1:daemon
sys:x:2:
penn: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:
kmem:x:14:
cdrom:x:15:
adm:x:16:
messagebus:x:18:
input:x:24:
mail:x:34:
kvm:x:61:
uuidd:x:80:
wheel:x:97:
users:x:999:
nogroup:x:65534:
EOFc

localedef -i C -f UTF-8 C.UTF-8
echo "tester:x:101:101::/home/tester:/bin/bash" >> /etc/passwd
echo "tester:x:101:" >> /etc/group
install -o tester -d /home/tester

touch /var/log/{btmp,lastlog,faillog,wtmp}
chgrp -v utmp /var/log/lastlog
chmod -v 664  /var/log/lastlog
chmod -v 600  /var/log/btmp
EOF
}

function 7.7-gettext(){
cat << EOF > $LFS/root/7.7-gettext
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf gettext-0.22.5.tar.xz
cd gettext-0.22.5
./configure --disable-shared
make
cp -v gettext-tools/src/{msgfmt,msgmerge,xgettext} /usr/bin
EOF
}

function 7.8-bison(){
	cat << EOF > $LFS/root/7.8-bison
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf bison-3.8.2.tar.xz
cd bison-3.8.2
./configure --prefix=/usr \
            --docdir=/usr/share/doc/bison-3.8.2
make
make install
EOF
}

function 7.9-perl(){
	cat << EOF > $LFS/root/7.9-perl
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf perl-5.40.0.tar.xz
cd perl-5.40.0
sh Configure -des                                         \
             -D prefix=/usr                               \
             -D vendorprefix=/usr                         \
             -D useshrplib                                \
             -D privlib=/usr/lib/perl5/5.40/core_perl     \
             -D archlib=/usr/lib/perl5/5.40/core_perl     \
             -D sitelib=/usr/lib/perl5/5.40/site_perl     \
             -D sitearch=/usr/lib/perl5/5.40/site_perl    \
             -D vendorlib=/usr/lib/perl5/5.40/vendor_perl \
             -D vendorarch=/usr/lib/perl5/5.40/vendor_perl
make
make install
EOF
}

function 7.10-python(){
	cat << EOF > $LFS/root/7.10-python
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf Python-3.12.5.tar.xz
cd Python-3.12.5
./configure --prefix=/usr   \
            --enable-shared \
            --without-ensurepip
make
make install
EOF
}

function 7.11-texinfo(){
	cat << EOF > $LFS/root/7.11-texinfo
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf texinfo-7.1.tar.xz
cd texinfo-7.1
./configure --prefix=/usr
make
make install
EOF
}

function 7.12-util-linux(){
	cat << EOF > $LFS/root/7.12-util-linux
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf util-linux-2.40.2.tar.xz
cd util-linux-2.40.2
mkdir -pv /var/lib/hwclock
./configure --libdir=/usr/lib     \
            --runstatedir=/run    \
            --disable-chfn-chsh   \
            --disable-login       \
            --disable-nologin     \
            --disable-su          \
            --disable-setpriv     \
            --disable-runuser     \
            --disable-pylibmount  \
            --disable-static      \
            --disable-liblastlog2 \
            --without-python      \
            ADJTIME_PATH=/var/lib/hwclock/adjtime \
            --docdir=/usr/share/doc/util-linux-2.40.2
make
make install
EOF
}

function 7.13-cleaning(){
	cat << 'EOF' > $LFS/root/7.13-cleaning
#!/bin/bash
set -eux -o pipefail
rm -rf /usr/share/{info,man,doc}/*
find /usr/{lib,libexec} -name \*.la -delete
rm -rf /tools
EOF
}

function 8.3-man-pages(){
	cat << 'EOF' > $LFS/root/8.3-man-pages
#!/bin/bash
set -eux -o pipefail
cd /sources
tar xf man-pages-6.9.1.tar.xz
cd man-pages-6.9.1
rm -v man3/crypt*
make prefix=/usr install
cd /sources
rm -rf man-pages-6.9.1
EOF
}

function 8.4-iana-etc(){
	cat << 'EOF' > $LFS/root/8.4-iana-etc
#!/bin/bash
set -eux -o pipefail
cd /sources
tar xf iana-etc-20240806.tar.gz
cd iana-etc-20240806
cp services protocols /etc
cd /sources
rm -rf iana-etc-20240806
EOF
}

function 8.5-glibc(){
	cat << 'EOF' > $LFS/root/8.5-glibc
#!/bin/bash
set -eux -o pipefail
cd /sources
tar xf glibc-2.40.tar.xz
cd glibc-2.40
patch -Np1 -i ../glibc-2.40-fhs-1.patch
mkdir build
cd build
echo "rootsbindir=/usr/sbin" > configparms
../configure --prefix=/usr                            \
             --disable-werror                         \
             --enable-kernel=4.19                     \
             --enable-stack-protector=strong          \
             --disable-nscd                           \
             libc_cv_slibdir=/usr/lib
make
touch /etc/ld.so.conf
sed '/test-installation/s@$(PERL)@echo not running@' -i ../Makefile
make install
sed '/RTLDLIST=/s@/usr@@g' -i /usr/bin/ldd
localedef -i C -f UTF-8 C.UTF-8
localedef -i cs_CZ -f UTF-8 cs_CZ.UTF-8
localedef -i de_DE -f ISO-8859-1 de_DE
localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
localedef -i de_DE -f UTF-8 de_DE.UTF-8
localedef -i el_GR -f ISO-8859-7 el_GR
localedef -i en_GB -f ISO-8859-1 en_GB
localedef -i en_GB -f UTF-8 en_GB.UTF-8
localedef -i en_HK -f ISO-8859-1 en_HK
localedef -i en_PH -f ISO-8859-1 en_PH
localedef -i en_US -f ISO-8859-1 en_US
localedef -i en_US -f UTF-8 en_US.UTF-8
localedef -i es_ES -f ISO-8859-15 es_ES@euro
localedef -i es_MX -f ISO-8859-1 es_MX
localedef -i fa_IR -f UTF-8 fa_IR
localedef -i fr_FR -f ISO-8859-1 fr_FR
localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
localedef -i fr_FR -f UTF-8 fr_FR.UTF-8
localedef -i is_IS -f ISO-8859-1 is_IS
localedef -i is_IS -f UTF-8 is_IS.UTF-8
localedef -i it_IT -f ISO-8859-1 it_IT
localedef -i it_IT -f ISO-8859-15 it_IT@euro
localedef -i it_IT -f UTF-8 it_IT.UTF-8
localedef -i ja_JP -f EUC-JP ja_JP
localedef -i ja_JP -f SHIFT_JIS ja_JP.SJIS 2> /dev/null || true
localedef -i ja_JP -f UTF-8 ja_JP.UTF-8
localedef -i nl_NL@euro -f ISO-8859-15 nl_NL@euro
localedef -i ru_RU -f KOI8-R ru_RU.KOI8-R
localedef -i ru_RU -f UTF-8 ru_RU.UTF-8
localedef -i se_NO -f UTF-8 se_NO.UTF-8
localedef -i ta_IN -f UTF-8 ta_IN.UTF-8
localedef -i tr_TR -f UTF-8 tr_TR.UTF-8
localedef -i zh_CN -f GB18030 zh_CN.GB18030
localedef -i zh_HK -f BIG5-HKSCS zh_HK.BIG5-HKSCS
localedef -i zh_TW -f UTF-8 zh_TW.UTF-8
make localedata/install-locales

cd /sources
rm -rf glibc-2.40
cat > /etc/nsswitch.conf << "EOFa"
# Begin /etc/nsswitch.conf

passwd: files
group: files
shadow: files

hosts: files dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

# End /etc/nsswitch.conf
EOFa

cat > /etc/ld.so.conf << "EOFb"
# Begin /etc/ld.so.conf
/usr/local/lib
/opt/lib

EOFb

cat >> /etc/ld.so.conf << "EOFc"
# Add an include directory
include /etc/ld.so.conf.d/*.conf

EOFc
mkdir -pv /etc/ld.so.conf.d

EOF
}

function 8.6-zlib(){
	cat << 'EOF' > $LFS/root/8.6-zlib
#!/bin/bash
set -eux -o pipefail
cd /sources
tar xf zlib-1.3.1.tar.gz
cd zlib-1.3.1
./configure --prefix=/usr
make
make install
rm -fv /usr/lib/libz.a
cd /sources
rm -rf zlib-1.3.1
EOF
}

function 8.7-bzip2(){
	cat << 'EOF' > $LFS/root/8.7-bzip2
#!/bin/bash
set -eux -o pipefail
cd /sources
tar xf bzip2-1.0.8.tar.gz
cd bzip2-1.0.8
patch -Np1 -i ../bzip2-1.0.8-install_docs-1.patch
sed -i 's@\(ln -s -f \)$(PREFIX)/bin/@\1@' Makefile
sed -i "s@(PREFIX)/man@(PREFIX)/share/man@g" Makefile
make -f Makefile-libbz2_so
make clean
make
make PREFIX=/usr install
cp -av libbz2.so.* /usr/lib
ln -sfv libbz2.so.1.0.8 /usr/lib/libbz2.so
cp -v bzip2-shared /usr/bin/bzip2
for i in /usr/bin/{bzcat,bunzip2}; do
  ln -sfv bzip2 $i
done
rm -fv /usr/lib/libbz2.a
cd /sources
rm -rf bzip2-1.0.8
EOF
}

function 8.8-xz(){
	cat << 'EOF' > $LFS/root/8.8-xz
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf xz-5.6.2.tar.xz
cd xz-5.6.2
./configure --prefix=/usr    \
            --disable-static \
            --docdir=/usr/share/doc/xz-5.6.2
make
make install
cd /sources
rm -rf xz-5.6.2
EOF
}

function 8.9-lz4(){
	cat << 'EOF' > $LFS/root/8.9-lz4
#!/bin/bash
set -eux -o pipefail
cd /sources
tar xf lz4-1.10.0.tar.gz
cd lz4-1.10.0
make BUILD_STATIC=no PREFIX=/usr
make BUILD_STATIC=no PREFIX=/usr install
cd /sources
rm -rf lz4-1.10.0
EOF
}

function 8.10-zstd(){
	cat << 'EOF' > $LFS/root/8.10-zstd
#!/bin/bash
set -eux -o pipefail
cd /sources
tar xf zstd-1.5.6.tar.gz
cd zstd-1.5.6
make prefix=/usr
make prefix=/usr install
rm -v /usr/lib/libzstd.a
cd /sources
rm -rf zstd-1.5.6
EOF
}

function 8.11-file(){
	cat << 'EOF' > $LFS/root/8.11-file
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf file-5.45.tar.gz
cd file-5.45
./configure --prefix=/usr
make
make install
cd /sources
rm -rf file-5.45
EOF
}

function 8.12-readline(){
	cat << 'EOF' > $LFS/root/8.12-readline
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf readline-8.2.13.tar.gz
cd readline-8.2.13
sed -i '/MV.*old/d' Makefile.in
sed -i '/{OLDSUFF}/c:' support/shlib-install
sed -i 's/-Wl,-rpath,[^ ]*//' support/shobj-conf
./configure --prefix=/usr    \
            --disable-static \
            --with-curses    \
            --docdir=/usr/share/doc/readline-8.2.13
make SHLIB_LIBS="-lncursesw"
make SHLIB_LIBS="-lncursesw" install
install -v -m644 doc/*.{ps,pdf,html,dvi} /usr/share/doc/readline-8.2.13
cd /sources
rm -rf readline-8.2.13
EOF
}

function 8.13-m4(){
	cat << 'EOF' > $LFS/root/8.13-m4
#!/bin/bash
set -eux -o pipefail
cd /sources
tar xf m4-1.4.19.tar.xz
cd m4-1.4.19
./configure --prefix=/usr
make
make install
cd /sources
rm -rf m4-1.4.19
EOF
}

function 8.14-bc(){
	cat << 'EOF' > $LFS/root/8.14-bc
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf bc-6.7.6.tar.xz
cd bc-6.7.6
CC=gcc ./configure --prefix=/usr -G -O3 -r
make
make install
cd /sources
rm -rf bc-6.7.6
EOF
}

function 8.15-flex(){
	cat << 'EOF' > $LFS/root/8.15-flex
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf flex-2.6.4.tar.gz
cd flex-2.6.4
./configure --prefix=/usr \
            --docdir=/usr/share/doc/flex-2.6.4 \
            --disable-static
make
make install
ln -sv flex   /usr/bin/lex
ln -sv flex.1 /usr/share/man/man1/lex.1
cd /sources
rm -rf flex-2.6.4
EOF
}

function 8.16-tcl(){
	cat << 'EOF' > $LFS/root/8.16-tcl
#!/bin/bash
set -eux -o pipefail
cd /sources
tar xf tcl8.6.14-src.tar.gz
cd tcl8.6.14
SRCDIR=$(pwd)
cd unix
./configure --prefix=/usr           \
            --mandir=/usr/share/man \
            --disable-rpath
make

sed -e "s|$SRCDIR/unix|/usr/lib|" \
    -e "s|$SRCDIR|/usr/include|"  \
    -i tclConfig.sh

sed -e "s|$SRCDIR/unix/pkgs/tdbc1.1.7|/usr/lib/tdbc1.1.7|" \
    -e "s|$SRCDIR/pkgs/tdbc1.1.7/generic|/usr/include|"    \
    -e "s|$SRCDIR/pkgs/tdbc1.1.7/library|/usr/lib/tcl8.6|" \
    -e "s|$SRCDIR/pkgs/tdbc1.1.7|/usr/include|"            \
    -i pkgs/tdbc1.1.7/tdbcConfig.sh

sed -e "s|$SRCDIR/unix/pkgs/itcl4.2.4|/usr/lib/itcl4.2.4|" \
    -e "s|$SRCDIR/pkgs/itcl4.2.4/generic|/usr/include|"    \
    -e "s|$SRCDIR/pkgs/itcl4.2.4|/usr/include|"            \
    -i pkgs/itcl4.2.4/itclConfig.sh

unset SRCDIR
make install
chmod -v u+w /usr/lib/libtcl8.6.so
make install-private-headers
ln -sfv tclsh8.6 /usr/bin/tclsh
mv /usr/share/man/man3/{Thread,Tcl_Thread}.3
cd /sources
rm -rf tcl8.6.14
EOF
}

function 8.17-expect(){
	cat << 'EOF' > $LFS/root/8.17-expect
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf expect5.45.4.tar.gz
cd expect5.45.4
python3 -c 'from pty import spawn; spawn(["echo", "ok"])'
patch -Np1 -i ../expect-5.45.4-gcc14-1.patch
./configure --prefix=/usr           \
            --with-tcl=/usr/lib     \
            --enable-shared         \
            --disable-rpath         \
            --mandir=/usr/share/man \
            --with-tclinclude=/usr/include
make
make install
ln -svf expect5.45.4/libexpect5.45.4.so /usr/lib
cd /sources
rm -rf expect5.45.4
EOF
}

function 8.18-dejagnu(){
	cat << 'EOF' > $LFS/root/8.18-dejagnu
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf dejagnu-1.6.3.tar.gz
cd dejagnu-1.6.3
mkdir -v build
cd       build
../configure --prefix=/usr
makeinfo --html --no-split -o doc/dejagnu.html ../doc/dejagnu.texi
makeinfo --plaintext       -o doc/dejagnu.txt  ../doc/dejagnu.texi
make install
install -v -dm755  /usr/share/doc/dejagnu-1.6.3
install -v -m644   doc/dejagnu.{html,txt} /usr/share/doc/dejagnu-1.6.3
cd /sources
rm -rf dejagnu-1.6.3
EOF
}

function 8.19-pkgconf(){
	cat << 'EOF' > $LFS/root/8.19-pkgconf
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf pkgconf-2.3.0.tar.xz
cd pkgconf-2.3.0
./configure --prefix=/usr              \
            --disable-static           \
            --docdir=/usr/share/doc/pkgconf-2.3.0
make
make install
ln -sv pkgconf   /usr/bin/pkg-config
ln -sv pkgconf.1 /usr/share/man/man1/pkg-config.1
cd /sources
rm -rf pkgconf-2.3.0
EOF
}

function 8.20-binutils(){
	cat << 'EOF' > $LFS/root/8.20-binutils
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf binutils-2.43.1.tar.xz
cd binutils-2.43.1
mkdir -v build
cd       build
../configure --prefix=/usr       \
             --sysconfdir=/etc   \
             --enable-gold       \
             --enable-ld=default \
             --enable-plugins    \
             --enable-shared     \
             --disable-werror    \
             --enable-64-bit-bfd \
             --enable-new-dtags  \
             --with-system-zlib  \
             --enable-default-hash-style=gnu
make tooldir=/usr
make tooldir=/usr install
rm -fv /usr/lib/lib{bfd,ctf,ctf-nobfd,gprofng,opcodes,sframe}.a
cd /sources
rm -rf binutils-2.43.1
EOF
}

function 8.21-gmp(){
	cat << 'EOF' > $LFS/root/8.21-gmp
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf gmp-6.3.0.tar.xz
cd gmp-6.3.0
./configure --prefix=/usr    \
            --enable-cxx     \
            --disable-static \
            --docdir=/usr/share/doc/gmp-6.3.0
make
make install
cd /sources
rm -rf gmp-6.3.0
EOF
}

function 8.22-mpfr(){
	cat << 'EOF' > $LFS/root/8.22-mpfr
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf mpfr-4.2.1.tar.xz
cd mpfr-4.2.1
./configure --prefix=/usr        \
            --disable-static     \
            --enable-thread-safe \
            --docdir=/usr/share/doc/mpfr-4.2.1
make
make install
cd /sources
rm -rf mpfr-4.2.1
EOF
}

function 8.23-mpc(){
	cat << 'EOF' > $LFS/root/8.23-mpc
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf mpc-1.3.1.tar.gz
cd mpc-1.3.1
./configure --prefix=/usr    \
            --disable-static \
            --docdir=/usr/share/doc/mpc-1.3.1
make
make install
cd /sources
rm -rf mpc-1.3.1
EOF
}

function 8.24-attr(){
	cat << 'EOF' > $LFS/root/8.24-attr
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf attr-2.5.2.tar.gz
cd attr-2.5.2
./configure --prefix=/usr     \
            --disable-static  \
            --sysconfdir=/etc \
            --docdir=/usr/share/doc/attr-2.5.2
make
make install
cd /sources
rm -rf attr-2.5.2
EOF
}

function 8.25-acl(){
	cat << 'EOF' > $LFS/root/8.25-acl
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf acl-2.3.2.tar.xz
cd acl-2.3.2
./configure --prefix=/usr         \
            --disable-static      \
            --docdir=/usr/share/doc/acl-2.3.2
make
make install
cd /sources
rm -rf acl-2.3.2
EOF
}

function 8.26-libcap(){
	cat << 'EOF' > $LFS/root/8.26-libcap
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf libcap-2.70.tar.xz
cd libcap-2.70
sed -i '/install -m.*STA/d' libcap/Makefile
make prefix=/usr lib=lib
make prefix=/usr lib=lib install
cd /sources
rm -rf libcap-2.70
EOF
}

function 8.27-libxcrypt(){
	cat << 'EOF' > $LFS/root/8.27-libxcrypt
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf libxcrypt-4.4.36.tar.xz
cd libxcrypt-4.4.36
./configure --prefix=/usr                \
            --enable-hashes=strong,glibc \
            --enable-obsolete-api=no     \
            --disable-static             \
            --disable-failure-tokens
make
make install
cd /sources
rm -rf libxcrypt-4.4.36
EOF
}

function 8.28-shadow(){
	cat << 'EOF' > $LFS/root/8.28-shadow
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf shadow-4.16.0.tar.xz
cd shadow-4.16.0
sed -i 's/groups$(EXEEXT) //' src/Makefile.in
find man -name Makefile.in -exec sed -i 's/groups\.1 / /'   {} \;
find man -name Makefile.in -exec sed -i 's/getspnam\.3 / /' {} \;
find man -name Makefile.in -exec sed -i 's/passwd\.5 / /'   {} \;
sed -e 's:#ENCRYPT_METHOD DES:ENCRYPT_METHOD YESCRYPT:' \
    -e 's:/var/spool/mail:/var/mail:'                   \
    -e '/PATH=/{s@/sbin:@@;s@/bin:@@}'                  \
    -i etc/login.defs
touch /usr/bin/passwd
./configure --sysconfdir=/etc   \
            --disable-static    \
            --with-{b,yes}crypt \
            --without-libbsd    \
            --with-group-name-max-length=32
make
make exec_prefix=/usr install
pwconv
grpconv
mkdir -p /etc/default
useradd -D --gid 999
cd /sources
rm -rf shadow-4.16.0
EOF
}

function 8.29-gcc(){
	cat << 'EOF' > $LFS/root/8.29-gcc
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf gcc-14.2.0.tar.xz
cd gcc-14.2.0
sed -e '/m64=/s/lib64/lib/' \
        -i.orig gcc/config/i386/t-linux64
mkdir build
cd build
../configure --prefix=/usr            \
             LD=ld                    \
             --enable-languages=c,c++ \
             --enable-default-pie     \
             --enable-default-ssp     \
             --enable-host-pie        \
             --disable-multilib       \
             --disable-bootstrap      \
             --disable-fixincludes    \
             --with-system-zlib
make
make install
ln -svr /usr/bin/cpp /usr/lib
ln -sv gcc.1 /usr/share/man/man1/cc.1
ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/14.2.0/liblto_plugin.so \
        /usr/lib/bfd-plugins/
echo 'int main(){}' > dummy.c
cc dummy.c -v -Wl,--verbose &> dummy.log
readelf -l a.out | grep ': /lib'
grep -E -o '/usr/lib.*/S?crt[1in].*succeeded' dummy.log
grep -B4 '^ /usr/include' dummy.log
grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'
grep "/lib.*/libc.so.6 " dummy.log
grep found dummy.log
rm -v dummy.c a.out dummy.log
mkdir -pv /usr/share/gdb/auto-load/usr/lib
mv -v /usr/lib/*gdb.py /usr/share/gdb/auto-load/usr/lib
cd /sources
rm -rf gcc-14.2.0
EOF
}

function 8.30-ncurses(){
	cat << 'EOF' > $LFS/root/8.30-ncurses
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf ncurses-6.5.tar.gz
cd ncurses-6.5
./configure --prefix=/usr           \
            --mandir=/usr/share/man \
            --with-shared           \
            --without-debug         \
            --without-normal        \
            --with-cxx-shared       \
            --enable-pc-files       \
            --with-pkg-config-libdir=/usr/lib/pkgconfig
make
make DESTDIR=$PWD/dest install
install -vm755 dest/usr/lib/libncursesw.so.6.5 /usr/lib
rm -v  dest/usr/lib/libncursesw.so.6.5
sed -e 's/^#if.*XOPEN.*$/#if 1/' \
    -i dest/usr/include/curses.h
cp -av dest/* /
for lib in ncurses form panel menu ; do
    ln -sfv lib${lib}w.so /usr/lib/lib${lib}.so
    ln -sfv ${lib}w.pc    /usr/lib/pkgconfig/${lib}.pc
done
ln -sfv libncursesw.so /usr/lib/libcurses.so
cp -v -R doc -T /usr/share/doc/ncurses-6.5
cd /sources
rm -rf ncurses-6.5
EOF
}

function 8.31-sed(){
	cat << 'EOF' > $LFS/root/8.31-sed
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf sed-4.9.tar.xz
cd sed-4.9
./configure --prefix=/usr
make
make install
cd /sources
rm -rf sed-4.9
EOF
}

function 8.32-psmisc(){
	cat << 'EOF' > $LFS/root/8.32-psmisc
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf psmisc-23.7.tar.xz
cd psmisc-23.7
./configure --prefix=/usr
make
make install
cd /sources
rm -rf psmisc-23.7
EOF
}

function 8.33-gettext(){
	cat << 'EOF' > $LFS/root/8.33-gettext
#!/bin/bash
cd /sources
tar -xf gettext-0.22.5.tar.xz
cd gettext-0.22.5
./configure --prefix=/usr    \
            --disable-static \
            --docdir=/usr/share/doc/gettext-0.22.5
make
rm -rf /sources/gettext-0.22.5
set -eux -o pipefail
cd /sources
tar -xf gettext-0.22.5.tar.xz
cd gettext-0.22.5
./configure --prefix=/usr    \
            --disable-static \
            --docdir=/usr/share/doc/gettext-0.22.5
make
make install
chmod -v 0755 /usr/lib/preloadable_libintl.so
cd /sources
rm -rf gettext-0.22.5
EOF
}

function 8.34-bison(){
	cat << 'EOF' > $LFS/root/8.34-bison
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf bison-3.8.2.tar.xz
cd bison-3.8.2
./configure --prefix=/usr --docdir=/usr/share/doc/bison-3.8.2
make
make install
cd /sources
rm -rf bison-3.8.2
EOF
}

function 8.35-grep(){
	cat << 'EOF' > $LFS/root/8.35-grep
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf grep-3.11.tar.xz
cd grep-3.11
sed -i "s/echo/#echo/" src/egrep.sh
./configure --prefix=/usr
make
make install
cd /sources
rm -rf grep-3.11
EOF
}

function 8.36-bash(){
	cat << 'EOF' > $LFS/root/8.36-bash
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf bash-5.2.32.tar.gz
cd bash-5.2.32
./configure --prefix=/usr             \
            --without-bash-malloc     \
            --with-installed-readline \
            bash_cv_strtold_broken=no \
            --docdir=/usr/share/doc/bash-5.2.32
make
make install
#exec /usr/bin/bash --login
cd /sources
rm -rf bash-5.2.32
EOF
}

function 8.37-libtool(){
	cat << 'EOF' > $LFS/root/8.37-libtool
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf libtool-2.4.7.tar.xz
cd libtool-2.4.7
./configure --prefix=/usr
make
make install
rm -fv /usr/lib/libltdl.a
cd /sources
rm -rf libtool-2.4.7
EOF
}

function 8.38-gdbm(){
	cat << 'EOF' > $LFS/root/8.38-gdbm
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf gdbm-1.24.tar.gz
cd gdbm-1.24
./configure --prefix=/usr    \
            --disable-static \
            --enable-libgdbm-compat
make
make install
cd /sources
rm -rf gdbm-1.24
EOF
}

function 8.39-gperf(){
	cat << 'EOF' > $LFS/root/8.39-gperf
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf gperf-3.1.tar.gz
cd gperf-3.1
./configure --prefix=/usr --docdir=/usr/share/doc/gperf-3.1
make
make install
cd /sources
rm -rf gperf-3.1
EOF
}

function 8.40-expat(){
	cat << 'EOF' > $LFS/root/8.40-expat
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf expat-2.6.4.tar.xz
cd expat-2.6.4
./configure --prefix=/usr    \
            --disable-static \
            --docdir=/usr/share/doc/expat-2.6.4
make
make install
cd /sources
rm -rf expat-2.6.4
EOF
}

function 8.41-inetutils(){
	cat << 'EOF' > $LFS/root/8.41-inetutils
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf inetutils-2.5.tar.xz
cd inetutils-2.5
sed -i 's/def HAVE_TERMCAP_TGETENT/ 1/' telnet/telnet.c
./configure --prefix=/usr        \
            --bindir=/usr/bin    \
            --localstatedir=/var \
            --disable-logger     \
            --disable-whois      \
            --disable-rcp        \
            --disable-rexec      \
            --disable-rlogin     \
            --disable-rsh        \
            --disable-servers
make
make install
mv -v /usr/{,s}bin/ifconfig
cd /sources
rm -rf inetutils-2.5
EOF
}

function 8.42-less(){
	cat << 'EOF' > $LFS/root/8.42-less
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf less-661.tar.gz
cd less-661
./configure --prefix=/usr --sysconfdir=/etc
make
make install
cd /sources
rm -rf less-661
EOF
}

function 8.43-perl(){
	cat << 'EOF' > $LFS/root/8.43-perl
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf perl-5.40.0.tar.xz
cd perl-5.40.0
export BUILD_ZLIB=False
export BUILD_BZIP2=0
sh Configure -des                                          \
             -D prefix=/usr                                \
             -D vendorprefix=/usr                          \
             -D privlib=/usr/lib/perl5/5.40/core_perl      \
             -D archlib=/usr/lib/perl5/5.40/core_perl      \
             -D sitelib=/usr/lib/perl5/5.40/site_perl      \
             -D sitearch=/usr/lib/perl5/5.40/site_perl     \
             -D vendorlib=/usr/lib/perl5/5.40/vendor_perl  \
             -D vendorarch=/usr/lib/perl5/5.40/vendor_perl \
             -D man1dir=/usr/share/man/man1                \
             -D man3dir=/usr/share/man/man3                \
             -D pager="/usr/bin/less -isR"                 \
             -D useshrplib                                 \
             -D usethreads
make
make install
unset BUILD_ZLIB BUILD_BZIP2
cd /sources
rm -rf perl-5.40.0
EOF
}

function 8.44-xml-parser(){
	cat << 'EOF' > $LFS/root/8.44-xml-parser
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf XML-Parser-2.47.tar.gz
cd XML-Parser-2.47
perl Makefile.PL
make
make install
cd /sources
rm -rf XML-Parser-2.47
EOF
}

function 8.45-intltool(){
	cat << 'EOF' > $LFS/root/8.45-intltool
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf intltool-0.51.0.tar.gz
cd intltool-0.51.0
sed -i 's:\\\${:\\\$\\{:' intltool-update.in
./configure --prefix=/usr
make
make install
install -v -Dm644 doc/I18N-HOWTO /usr/share/doc/intltool-0.51.0/I18N-HOWTO
cd /sources
rm -rf intltool-0.51.0
EOF
}

function 8.46-autoconf(){
	cat << 'EOF' > $LFS/root/8.46-autoconf
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf autoconf-2.72.tar.xz
cd autoconf-2.72
./configure --prefix=/usr
make
make install
cd /sources
rm -rf autoconf-2.72
EOF
}

function 8.47-automake(){
	cat << 'EOF' > $LFS/root/8.47-automake
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf automake-1.17.tar.xz
cd automake-1.17
./configure --prefix=/usr --docdir=/usr/share/doc/automake-1.17
make
make install
cd /sources
rm -rf automake-1.17
EOF
}

function 8.48-openssl(){
	cat << 'EOF' > $LFS/root/8.48-openssl
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf openssl-3.3.1.tar.gz
cd openssl-3.3.1
./config --prefix=/usr         \
         --openssldir=/etc/ssl \
         --libdir=lib          \
         shared                \
         zlib-dynamic
make
sed -i '/INSTALL_LIBS/s/libcrypto.a libssl.a//' Makefile
make MANSUFFIX=ssl install
mv -v /usr/share/doc/openssl /usr/share/doc/openssl-3.3.1
cd /sources
rm -rf openssl-3.3.1
EOF
}

function 8.49-kmod(){
	cat << 'EOF' > $LFS/root/8.49-kmod
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf kmod-33.tar.xz
cd kmod-33
./configure --prefix=/usr     \
            --sysconfdir=/etc \
            --with-openssl    \
            --with-xz         \
            --with-zstd       \
            --with-zlib       \
            --disable-manpages
make
make install
for target in depmod insmod modinfo modprobe rmmod; do
  ln -sfv ../bin/kmod /usr/sbin/$target
  rm -fv /usr/bin/$target
done
cd /sources
rm -rf kmod-33
EOF
}

function 8.50-libelf(){
	cat << 'EOF' > $LFS/root/8.50-libelf
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf elfutils-0.191.tar.bz2
cd elfutils-0.191
./configure --prefix=/usr                \
            --disable-debuginfod         \
            --enable-libdebuginfod=dummy
make
make -C libelf install
install -vm644 config/libelf.pc /usr/lib/pkgconfig
rm /usr/lib/libelf.a
cd /sources
rm -rf elfutils-0.191
EOF
}

function 8.51-libffi(){
	cat << 'EOF' > $LFS/root/8.51-libffi
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf libffi-3.4.6.tar.gz
cd libffi-3.4.6
./configure --prefix=/usr          \
            --disable-static       \
            --with-gcc-arch=native
make
make install
cd /sources
rm -rf libffi-3.4.6
EOF
}

function 8.52-python(){
	cat << 'EOF' > $LFS/root/8.52-python
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf Python-3.12.5.tar.xz
cd Python-3.12.5
./configure --prefix=/usr        \
            --enable-shared      \
            --with-system-expat  \
            --enable-optimizations
make
make install
ln -s /usr/bin/python3 /usr/bin/python
cat > /etc/pip.conf << EOFa
[global]
root-user-action = ignore
disable-pip-version-check = true
EOFa
cat > /etc/pip.conf << EOFb
[global]
root-user-action = ignore
disable-pip-version-check = true
EOFb
cd /sources
rm -rf Python-3.12.5
EOF
}

function 8.53-flit-core(){
	cat << 'EOF' > $LFS/root/8.53-flit-core
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf flit_core-3.9.0.tar.gz
cd flit_core-3.9.0
pip3 wheel -w dist --no-cache-dir --no-build-isolation --no-deps $PWD
pip3 install --no-index --no-user --find-links dist flit_core
cd /sources
rm -rf flit_core-3.9.0
EOF
}

function 8.54-wheel(){
	cat << 'EOF' > $LFS/root/8.54-wheel
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf wheel-0.44.0.tar.gz
cd wheel-0.44.0
pip3 wheel -w dist --no-cache-dir --no-build-isolation --no-deps $PWD
pip3 install --no-index --find-links=dist wheel
cd /sources
rm -rf wheel-0.44.0
EOF
}

function 8.55-setuptools(){
	cat << 'EOF' > $LFS/root/8.55-setuptools
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf setuptools-72.2.0.tar.gz
cd setuptools-72.2.0
pip3 wheel -w dist --no-cache-dir --no-build-isolation --no-deps $PWD
pip3 install --no-index --find-links dist setuptools
cd /sources
rm -rf setuptools-72.2.0
EOF
}

function 8.56-ninja(){
	cat << 'EOF' > $LFS/root/8.56-ninja
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf ninja-1.12.1.tar.gz
cd ninja-1.12.1
export NINJAJOBS=4
sed -i '/int Guess/a \
  int   j = 0;\
  char* jobs = getenv( "NINJAJOBS" );\
  if ( jobs != NULL ) j = atoi( jobs );\
  if ( j > 0 ) return j;\
' src/ninja.cc
python3 configure.py --bootstrap
install -vm755 ninja /usr/bin/
install -vDm644 misc/bash-completion /usr/share/bash-completion/completions/ninja
install -vDm644 misc/zsh-completion  /usr/share/zsh/site-functions/_ninja
cd /sources
rm -rf ninja-1.12.1
EOF
}

function 8.57-meson(){
	cat << 'EOF' > $LFS/root/8.57-meson
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf meson-1.5.1.tar.gz
cd meson-1.5.1
pip3 wheel -w dist --no-cache-dir --no-build-isolation --no-deps $PWD
pip3 install --no-index --find-links dist meson
install -vDm644 data/shell-completions/bash/meson /usr/share/bash-completion/completions/meson
install -vDm644 data/shell-completions/zsh/_meson /usr/share/zsh/site-functions/_meson
cd /sources
rm -rf meson-1.5.1
EOF
}

function 8.58-coreutils(){
	cat << EOF > $LFS/root/8.58-coreutils
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf coreutils-9.5.tar.xz
cd coreutils-9.5
patch -Np1 -i ../coreutils-9.5-i18n-2.patch
autoreconf -fiv
FORCE_UNSAFE_CONFIGURE=1 ./configure \
            --prefix=/usr            \
            --enable-no-install-program=kill,uptime
make
make install
mv -v /usr/bin/chroot /usr/sbin
mv -v /usr/share/man/man1/chroot.1 /usr/share/man/man8/chroot.8
sed -i 's/"1"/"8"/' /usr/share/man/man8/chroot.8
cd /sources
rm -rf coreutils-9.5
EOF
}

function 8.59-check(){
	cat << 'EOF' > $LFS/root/8.59-check
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf check-0.15.2.tar.gz
cd check-0.15.2
./configure --prefix=/usr --disable-static
make
make docdir=/usr/share/doc/check-0.15.2 install
cd /sources
rm -rf check-0.15.2
EOF
}

function 8.60-diffutils(){
	cat << 'EOF' > $LFS/root/8.60-diffutils
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf diffutils-3.10.tar.xz
cd diffutils-3.10
./configure --prefix=/usr
make
make install
cd /sources
rm -rf diffutils-3.10
EOF
}

function 8.61-gawk(){
	cat << 'EOF' > $LFS/root/8.61-gawk
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf gawk-5.3.0.tar.xz
cd gawk-5.3.0
sed -i 's/extras//' Makefile.in
./configure --prefix=/usr
make
rm -f /usr/bin/gawk-5.3.0
make install
ln -sv gawk.1 /usr/share/man/man1/awk.1
cd /sources
rm -rf gawk-5.3.0
EOF
}

function 8.62-findutils(){
	cat << 'EOF' > $LFS/root/8.62-findutils
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf findutils-4.10.0.tar.xz
cd findutils-4.10.0
./configure --prefix=/usr --localstatedir=/var/lib/locate
make
make install
cd /sources
rm -rf findutils-4.10.0
EOF
}

function 8.63-groff(){
	cat << 'EOF' > $LFS/root/8.63-groff
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf groff-1.23.0.tar.gz
cd groff-1.23.0
PAGE=A4 ./configure --prefix=/usr
make
make install
cd /sources
rm -rf groff-1.23.0
EOF
}

function 8.64-grub(){
	cat << 'EOF' > $LFS/root/8.64-grub
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf grub-2.12.tar.xz
cd grub-2.12
unset {C,CPP,CXX,LD}FLAGS
echo depends bli part_gpt > grub-core/extra_deps.lst
./configure --prefix=/usr          \
            --sysconfdir=/etc      \
            --disable-efiemu       \
            --disable-werror
make
make install
mv -v /etc/bash_completion.d/grub /usr/share/bash-completion/completions
cd /sources
rm -rf grub-2.12
EOF
}

function 8.65-gzip(){
	cat << 'EOF' > $LFS/root/8.65-gzip
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf gzip-1.13.tar.xz
cd gzip-1.13
./configure --prefix=/usr
make
make install
cd /sources
rm -rf gzip-1.13
EOF
}

function 8.66-iproute(){
	cat << 'EOF' > $LFS/root/8.66-iproute
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf iproute2-6.10.0.tar.xz
cd iproute2-6.10.0
sed -i /ARPD/d Makefile
rm -fv man/man8/arpd.8
make NETNS_RUN_DIR=/run/netns
make SBINDIR=/usr/sbin install
cd /sources
rm -rf iproute2-6.10.0
EOF
}

function 8.67-kbd(){
	cat << 'EOF' > $LFS/root/8.67-kbd
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf kbd-2.6.4.tar.xz
cd kbd-2.6.4
patch -Np1 -i ../kbd-2.6.4-backspace-1.patch
sed -i '/RESIZECONS_PROGS=/s/yes/no/' configure
sed -i 's/resizecons.8 //' docs/man/man8/Makefile.in
./configure --prefix=/usr --disable-vlock
make
make install
cd /sources
rm -rf kbd-2.6.4
EOF
}

function 8.68-libpipeline(){
	cat << 'EOF' > $LFS/root/8.68-libpipeline
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf libpipeline-1.5.7.tar.gz
cd libpipeline-1.5.7
./configure --prefix=/usr
make
make install
cd /sources
rm -rf libpipeline-1.5.7
EOF
}

function 8.69-make(){
	cat << 'EOF' > $LFS/root/8.69-make
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf make-4.4.1.tar.gz
cd make-4.4.1
./configure --prefix=/usr
make
make install
cd /sources
rm -rf make-4.4.1
EOF
}

function 8.70-patch(){
	cat << 'EOF' > $LFS/root/8.70-patch
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf patch-2.7.6.tar.xz
cd patch-2.7.6
./configure --prefix=/usr
make
make install
cd /sources
rm -rf patch-2.7.6
EOF
}

function 8.71-tar(){
	cat << 'EOF' > $LFS/root/8.71-tar
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf tar-1.35.tar.xz
cd tar-1.35
FORCE_UNSAFE_CONFIGURE=1  \
./configure --prefix=/usr
make
make install
cd /sources
rm -rf tar-1.35
EOF
}

function 8.72-texinfo(){
	cat << 'EOF' > $LFS/root/8.72-texinfo
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf texinfo-7.1.tar.xz
cd texinfo-7.1
./configure --prefix=/usr
make
make install
cd /sources
rm -rf texinfo-7.1
EOF
}

function 8.73-vim(){
	cat << 'EOF' > $LFS/root/8.73-vim
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf vim-9.1.0660.tar.gz
cd vim-9.1.0660
echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h
./configure --prefix=/usr
make
make install
cat > /etc/vimrc << "EOFa"
" Début de /etc/vimrc

" Ensure defaults are set before customizing settings, not after
source $VIMRUNTIME/defaults.vim
let skip_defaults_vim=1

set nocompatible
set backspace=2
set mouse=
syntax on
if (&term == "xterm") || (&term == "putty")
  set background=dark
endif

" Fin de /etc/vimrc
EOFa
cd /sources
rm -rf vim-9.1.0660
EOF
}

function 8.74-markupsafe(){
	cat << 'EOF' > $LFS/root/8.74-markupsafe
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf MarkupSafe-2.1.5.tar.gz
cd MarkupSafe-2.1.5
pip3 wheel -w dist --no-cache-dir --no-build-isolation --no-deps $PWD
pip3 install --no-index --no-user --find-links dist Markupsafe
cd /sources
rm -rf MarkupSafe-2.1.5
EOF
}

function 8.75-jinja2(){
	cat << 'EOF' > $LFS/root/8.75-jinja2
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf jinja2-3.1.4.tar.gz
cd jinja2-3.1.4
pip3 wheel -w dist --no-cache-dir --no-build-isolation --no-deps $PWD
pip3 install --no-index --no-user --find-links dist Jinja2
cd /sources
rm -rf jinja2-3.1.4
EOF
}

function 8.76-udev(){
	cat << 'EOF' > $LFS/root/8.76-udev
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf systemd-256.4.tar.gz
cd systemd-256.4
sed -i -e 's/GROUP="render"/GROUP="video"/' \
       -e 's/GROUP="sgx", //' rules.d/50-udev-default.rules.in
sed '/systemd-sysctl/s/^/#/' -i rules.d/99-systemd.rules.in
sed '/NETWORK_DIRS/s/systemd/udev/' -i src/basic/path-lookup.h
mkdir -p build
cd       build

meson setup ..                  \
      --prefix=/usr             \
      --buildtype=release       \
      -D mode=release           \
      -D dev-kvm-mode=0660      \
      -D link-udev-shared=false \
      -D logind=false           \
      -D vconsole=false
export udev_helpers=$(grep "'name' :" ../src/udev/meson.build | \
                      awk '{print $3}' | tr -d ",'" | grep -v 'udevadm')
ninja udevadm systemd-hwdb                                           \
      $(ninja -n | grep -Eo '(src/(lib)?udev|rules.d|hwdb.d)/[^ ]*') \
      $(realpath libudev.so --relative-to .)                         \
      $udev_helpers
install -vm755 -d {/usr/lib,/etc}/udev/{hwdb.d,rules.d,network}
install -vm755 -d /usr/{lib,share}/pkgconfig
install -vm755 udevadm                             /usr/bin/
install -vm755 systemd-hwdb                        /usr/bin/udev-hwdb
ln      -svfn  ../bin/udevadm                      /usr/sbin/udevd
cp      -av    libudev.so{,*[0-9]}                 /usr/lib/
install -vm644 ../src/libudev/libudev.h            /usr/include/
install -vm644 src/libudev/*.pc                    /usr/lib/pkgconfig/
install -vm644 src/udev/*.pc                       /usr/share/pkgconfig/
install -vm644 ../src/udev/udev.conf               /etc/udev/
install -vm644 rules.d/* ../rules.d/README         /usr/lib/udev/rules.d/
install -vm644 $(find ../rules.d/*.rules \
                      -not -name '*power-switch*') /usr/lib/udev/rules.d/
install -vm644 hwdb.d/*  ../hwdb.d/{*.hwdb,README} /usr/lib/udev/hwdb.d/
install -vm755 $udev_helpers                       /usr/lib/udev
install -vm644 ../network/99-default.link          /usr/lib/udev/network
tar -xvf ../../udev-lfs-20230818.tar.xz
make -f udev-lfs-20230818/Makefile.lfs install
unset udev_helpers
cd /sources
rm -rf systemd-256.4
EOF
}

function 8.77-man-db(){
	cat << 'EOF' > $LFS/root/8.77-man-db
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf man-db-2.12.1.tar.xz
cd man-db-2.12.1
./configure --prefix=/usr                         \
            --docdir=/usr/share/doc/man-db-2.12.1 \
            --sysconfdir=/etc                     \
            --disable-setuid                      \
            --enable-cache-owner=bin              \
            --with-browser=/usr/bin/lynx          \
            --with-vgrind=/usr/bin/vgrind         \
            --with-grap=/usr/bin/grap             \
            --with-systemdtmpfilesdir=            \
            --with-systemdsystemunitdir=
make
make install
cd /sources
rm -rf man-db-2.12.1
EOF
}

function 8.78-procps-ng(){
	cat << 'EOF' > $LFS/root/8.78-procps-ng
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf procps-ng-4.0.4.tar.xz
cd procps-ng-4.0.4
./configure --prefix=/usr                           \
            --docdir=/usr/share/doc/procps-ng-4.0.4 \
            --disable-static                        \
            --disable-kill
make
make install
cd /sources
rm -rf procps-ng-4.0.4
EOF
}

function 8.79-util-linux(){
	cat << 'EOF' > $LFS/root/8.79-util-linux
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf util-linux-2.40.2.tar.xz
cd util-linux-2.40.2
./configure --bindir=/usr/bin     \
            --libdir=/usr/lib     \
            --runstatedir=/run    \
            --sbindir=/usr/sbin   \
            --disable-chfn-chsh   \
            --disable-login       \
            --disable-nologin     \
            --disable-su          \
            --disable-setpriv     \
            --disable-runuser     \
            --disable-pylibmount  \
            --disable-liblastlog2 \
            --disable-static      \
            --without-python      \
            --without-systemd     \
            --without-systemdsystemunitdir        \
            ADJTIME_PATH=/var/lib/hwclock/adjtime \
            --docdir=/usr/share/doc/util-linux-2.40.2
make
make install
cd /sources
rm -rf util-linux-2.40.2
EOF
}

function 8.80-e2fsprogs(){
	cat << 'EOF' > $LFS/root/8.80-e2fsprogs
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf e2fsprogs-1.47.1.tar.gz
cd e2fsprogs-1.47.1
mkdir -v build
cd       build
../configure --prefix=/usr           \
             --sysconfdir=/etc       \
             --enable-elf-shlibs     \
             --disable-libblkid      \
             --disable-libuuid       \
             --disable-uuidd         \
             --disable-fsck
make
make install
rm -fv /usr/lib/{libcom_err,libe2p,libext2fs,libss}.a
gunzip -v /usr/share/info/libext2fs.info.gz
install-info --dir-file=/usr/share/info/dir /usr/share/info/libext2fs.info
cd /sources
rm -rf e2fsprogs-1.47.1
EOF
}

function 8.81-sysklogd(){
	cat << 'EOF' > $LFS/root/8.81-sysklogd
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf sysklogd-2.6.1.tar.gz
cd sysklogd-2.6.1
./configure --prefix=/usr      \
            --sysconfdir=/etc  \
            --runstatedir=/run \
            --without-logger
make
make install
cat > /etc/syslog.conf << EOFa
# Début de /etc/syslog.conf

auth,authpriv.* -/var/log/auth.log
*.*;auth,authpriv.none -/var/log/sys.log
daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log
*.emerg *

# Ne pas ouvrir de ports internet.
secure_mode 2

# Fin de /etc/syslog.conf
EOFa
cd /sources
rm -rf sysklogd-2.6.1
EOF
}

function 8.82-libpsl(){
	cat << 'EOF' > $LFS/root/8.82-libpsl
#!/bin/bash
set -eux -o pipefail
cd /sources
tar xf libpsl-0.21.5.tar.gz
cd libpsl-0.21.5
mkdir build
cd build
meson setup --prefix=/usr --buildtype=release
ninja
ninja install
cd /sources
rm -rf libpsl-0.21.5
EOF
}

function 8.83-curl(){
	cat << 'EOF' > $LFS/root/8.83-curl
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf curl-8.11.0.tar.xz
cd curl-8.11.0
./configure --prefix=/usr                           \
            --disable-static                        \
            --with-openssl                          \
            --with-ca-path=/etc/ssl/certs
make
make install
cd /sources
rm -rf curl-8.11.0
EOF
}

function 8.84-cpio(){
	cat << 'EOF' > $LFS/root/8.84-cpio
#!/bin/bash
set -eux -o pipefail
cd /sources
tar -xf cpio-2.15.tar.bz2
cd cpio-2.15
./configure --prefix=/usr \
            --enable-mt   \
            --with-rmt=/usr/libexec/rmt
make
make install
cd /sources
rm -rf cpio-2.15
EOF
}

function 8.85-dracut(){
	cat << 'EOF' > $LFS/root/8.85-dracut
#!/bin/bash
set -eux -o pipefail
cd /sources
tar xf dracut-105.tar.gz
cd dracut-ng-105
./configure --prefix=/usr --disable-documentation
make
make install
cd /sources
rm -rf dracut-059
EOF
}

function 8.86-fakeroot(){
	cat << 'EOF' > $LFS/root/8.86-fakeroot
#!/bin/bash
set -eux -o pipefail
cd /sources
tar xf fakeroot-1.36.tar.gz
cd fakeroot-1.36
./configure --prefix=/usr
make
make install
libtool --finish /usr/lib
cd /sources
rm -rf fakeroot-1.36
EOF
}

function 8.87-erminig-tools(){
	cat << 'EOF' > $LFS/root/8.87-erminig-tools
#!/bin/bash
set -eux -o pipefail
install -d -o 3 -g 3 /usr/src
install -d -o 3 -g 3 /var/{cache,lib,log,tmp}/govel
install -d /var/cache/keo
EOF
}

function post-chroot(){
	7.5-create-folders
	7.6-create-symbolic-links
	7.7-gettext
	7.8-bison
	7.9-perl
	7.10-python
	7.11-texinfo
	7.12-util-linux
	7.13-cleaning
	8.3-man-pages
	8.4-iana-etc
	8.5-glibc
	8.6-zlib
	8.7-bzip2
	8.8-xz
	8.9-lz4
	8.10-zstd
	8.11-file
	8.12-readline
	8.13-m4
	8.14-bc
	8.15-flex
	8.16-tcl
	8.17-expect
	8.18-dejagnu
	8.19-pkgconf
	8.20-binutils
	8.21-gmp
	8.22-mpfr
	8.23-mpc
	8.24-attr
	8.25-acl
	8.26-libcap
	8.27-libxcrypt
	8.28-shadow
	8.29-gcc
	8.30-ncurses
	8.31-sed
	8.32-psmisc
	8.33-gettext
	8.34-bison
	8.35-grep
	8.36-bash
	8.37-libtool
	8.38-gdbm
	8.39-gperf
	8.40-expat
	8.41-inetutils
	8.42-less
	8.43-perl
	8.44-xml-parser
	8.45-intltool
	8.46-autoconf
	8.47-automake
	8.48-openssl
	8.49-kmod
	8.50-libelf
	8.51-libffi
	8.52-python
	8.53-flit-core
	8.54-wheel
	8.55-setuptools
	8.56-ninja
	8.57-meson
	8.58-coreutils
	8.59-check
	8.60-diffutils
	8.61-gawk
	8.62-findutils
	8.63-groff
	8.64-grub
	8.65-gzip
	8.66-iproute
	8.67-kbd
	8.68-libpipeline
	8.69-make
	8.70-patch
	8.71-tar
	8.72-texinfo
	8.73-vim
	8.74-markupsafe
	8.75-jinja2
	8.76-udev
	8.77-man-db
	8.78-procps-ng
	8.79-util-linux
	8.80-e2fsprogs
	8.81-sysklogd
	8.82-libpsl
	8.83-curl
	8.84-cpio
	8.85-dracut
	8.86-fakeroot
	8.87-erminig-tools
	cat << 'EOF' > $LFS/root/post-chroot
#!/bin/bash
set -eux -o pipefail
bash /root/7.5-create-folders
bash /root/7.6-create-symbolic-links
bash /root/7.7-gettext
bash /root/7.8-bison
bash /root/7.9-perl
bash /root/7.10-python
bash /root/7.11-texinfo
bash /root/7.12-util-linux
bash /root/7.13-cleaning
#bash /root/8.3-man-pages
bash /root/8.4-iana-etc
bash /root/8.5-glibc
bash /root/8.6-zlib
bash /root/8.7-bzip2
bash /root/8.8-xz
bash /root/8.9-lz4
bash /root/8.10-zstd
bash /root/8.11-file
bash /root/8.12-readline
bash /root/8.13-m4
bash /root/8.14-bc
bash /root/8.15-flex
bash /root/8.16-tcl
bash /root/8.17-expect
bash /root/8.18-dejagnu
bash /root/8.19-pkgconf
bash /root/8.20-binutils
bash /root/8.21-gmp
bash /root/8.22-mpfr
bash /root/8.23-mpc
bash /root/8.24-attr
bash /root/8.25-acl
bash /root/8.26-libcap
bash /root/8.27-libxcrypt
bash /root/8.28-shadow
bash /root/8.29-gcc
bash /root/8.30-ncurses
bash /root/8.31-sed
bash /root/8.32-psmisc
bash /root/8.33-gettext
bash /root/8.34-bison
bash /root/8.35-grep
bash /root/8.36-bash
bash /root/8.37-libtool
bash /root/8.38-gdbm
bash /root/8.39-gperf
bash /root/8.40-expat
#bash /root/8.41-inetutils
bash /root/8.42-less
bash /root/8.43-perl
bash /root/8.44-xml-parser
bash /root/8.45-intltool
bash /root/8.46-autoconf
bash /root/8.47-automake
bash /root/8.48-openssl
bash /root/8.49-kmod
bash /root/8.50-libelf
bash /root/8.51-libffi
bash /root/8.52-python
bash /root/8.53-flit-core
bash /root/8.54-wheel
bash /root/8.55-setuptools
bash /root/8.56-ninja
bash /root/8.57-meson
bash /root/8.58-coreutils
bash /root/8.59-check
bash /root/8.60-diffutils
bash /root/8.61-gawk
bash /root/8.62-findutils
bash /root/8.63-groff
bash /root/8.64-grub
bash /root/8.65-gzip
bash /root/8.66-iproute
bash /root/8.67-kbd
bash /root/8.68-libpipeline
bash /root/8.69-make
bash /root/8.70-patch
bash /root/8.71-tar
bash /root/8.72-texinfo
bash /root/8.73-vim
bash /root/8.74-markupsafe
bash /root/8.75-jinja2
#bash /root/8.76-udev
#bash /root/8.77-man-db
#bash /root/8.78-procps-ng
#bash /root/8.79-util-linux
#bash /root/8.80-e2fsprogs
#bash /root/8.81-sysklogd
#bash /root/8.82-libpsl
#bash /root/8.83-curl
#bash /root/8.84-cpio
#bash /root/8.85-dracut
#bash /root/8.86-fakeroot
#bash /root/8.87-erminig-tools
EOF
}

function main(){
	echo "Get sources"
	3.1-get_sources
	echo "Folder structure"
	4.2-folder_structure
	#4.4-configure_environment
	echo "Binutils"
	5.2-binutils 2.43.1
	5.3-gcc 14.2.0
	5.4-linux_headers 6.10.5
	5.5-glibc 2.40
	5.6-libstdcpp 14.2.0
	6.2-m4 1.4.19
	6.3-ncurses 6.5
	6.4-bash 5.2.32
	6.5-coreutils 9.5
	6.6-diffutils 3.10
    6.7-file 5.45
	6.8-findutils 4.10.0
	6.9-gawk 5.3.0
	6.10-grep 3.11
	6.11-gzip 1.13
	6.12-make 4.4.1
	6.13-patch 2.7.6
	6.14-sed 4.9
	6.15-tar 1.35
	6.16-xz 5.6.2
	6.17-binutils 2.43.1
	6.18-gcc 14.2.0
	7.3-prepare-filesystem
	post-chroot
}

main
