Before building the lfs system, we need to build a new toolchain that is separated from the host system, and then use the new toolchain to build other basic tools. The purpose of this is to reduce the dependence and impact of the host system.
The built new toolchain will be placed in $LFS/toolsFoldersIn the process, separate it from the files installed later and the directories generated by the host system to prevent contamination of the lfs system to be made later.
Build a temporary lfs system
Unzip package command:
tar -xjf ***
Attachment: Without special instructions, delete the unzipped directory after compiling and installing one.
1. Binutils-2.26
Enter the Binutils-2.26 directory and create the compiled directory:
mkdir -v build
cd build
Compile and configure:
…/configure --prefix=/tools
–with-sysroot=$LFS
–with-lib-path=/tools/lib
–target=$LFS_TGT
–disable-nls
–disable-werror
Start compilation:
make
Since I'm using the x86_64 architecture platform, I need to create itSymbol Links:
case $(uname -m) in
x86_64) mkdir -v /tools/lib && ln -sv lib /tools/lib64 ;;
esac
Installation and compilation results:
make install
2. GCC-5.3.0
I still remember that in the preparation work of the first picture, when checking the host's library, there is the following output:
: not found
: not found
: not found
This shows that the current host does not have these three libraries, so we decompress these three packages in the sources directory and rename them so that these three libraries can be recognized when compiling gcc.
tar -xf …/mpfr-3.1.
mv -v mpfr-3.1.3 mpfr
tar -xf …/gmp-6.1.
mv -v gmp-6.1.0 gmp
tar -xf …/mpc-1.0.
mv -v mpc-1.0.3 mpc
The above is to unzip these three packages and move them to the compilation directory of gcc.
The following command will change the location of the GCC default dynamic linker to use the linker installed in /tools. It also removes /usr/include from the include search path of GCC:
for file in
$(find gcc/config -name -o -name linux.h -o -name )
do
cp -uv $file{,.orig}
sed -e ‘s@/lib(64)?(32)?/ld@/tools&@g’
-e ‘s@/usr@/tools@g’ $ > $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 $
done
For details of the above specific meanings, please refer to the lfs7.9 document.
Same as Binutils-2.26, create the build directory:
mkdir -v build
cd build
The configuration commands are as follows:
…/configure
–target=$LFS_TGT
–prefix=/tools
–with-glibc-version=2.11
–with-sysroot=$LFS
–with-newlib
–without-headers
–with-local-prefix=/tools
–with-native-system-header-dir=/tools/include
–disable-nls
–disable-shared
–disable-multilib
–disable-decimal-float
–disable-threads
–disable-libatomic
–disable-libgomp
–disable-libquadmath
–disable-libssp
–disable-libvtv
–disable-libstdcxx
–enable-languages=c,c++
Then make and make install. Here I would like to remind you that it is best not to use it by hand. The copy and paste method can better ensure the correctness.
3. Linux-4.13.16 API Headers
Due to business needs, I am using the Linux-4.13.16 kernel here (if there is no special requirements, use lfs7.9 provided). So move the api header file of this version of the kernel to the tools folder.
Unzip linux-4.13. File:
tar zxvf linux-4.13.
Clear old files and move header files to tools folder:
make mrproper
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /tools/include
4. Glibc-2.23
Similar to the above Binutils-2.26, the difference is that the compilation configuration:
…/configure
–prefix=/tools
–host=$LFS_TGT
–build=$(…/scripts/)
–disable-profile
–enable-kernel=2.6.32
–enable-obsolete-rpc
–with-headers=/tools/include
libc_cv_forced_unwind=yes
libc_cv_ctors_header=yes
libc_cv_c_cleanup=yes
Confirm that the function of the new toolchain is as expected and run the following command:
echo ‘int main(){}’ >
$LFS_TGT-gcc
readelf -l | grep ‘: /tools’
If everything is normal, there is the following output format:
[Requesting program interpreter: /tools/lib/.2]
My output format is as follows:
[Requesting program interpreter: /tools/lib64/.2]
Normally, clean the test files:
rm -v
5. Libstdc++5.3.0
Libstdc++ is in the gcc source code, so you need to re-decompress gcc and compile Libstdc++. The compilation configuration of Libstdc++ is as follows:
…/libstdc+±v3/configure
–host=$LFS_TGT
–prefix=/tools
–disable-multilib
–disable-nls
–disable-libstdcxx-threads
–disable-libstdcxx-pch
–with-gxx-include-dir=/tools/$LFS_TGT/include/c++/5.3.0
6. Recompile Binutils-2.26
As for why Binutils-2.26 needs to be recompiled, I guess it is to remove the host's dependencies. Previously, Binutils-2.26 may be compiled with it to compile several subsequent tools, and then compile Binutils-2.26 again, thereby breaking away from the dependencies of the host system.
Binutils-2.26 compilation configuration:
CC=$LFS_TGT-gcc
AR=$LFS_TGT-ar
RANLIB=$LFS_TGT-ranlib
…/configure
–prefix=/tools
–disable-nls
–disable-werror
–with-lib-path=/tools/lib
–with-sysroot
Prepare connectors for the following stages:
make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib
cp -v ld/ld-new /tools/bin
7. Recompile GCC-5.3.0
The system header file is not included when compiling GCC-5.3.0 for the first time: /tools/include/. This compilation requires the /tools/include/ header file, so create the full version of the header file:
cat gcc/ gcc/ gcc/ >
dirname $($LFS_TGT-gcc -print-libgcc-file-name)
/include-fixed/
Change the location of the default dynamic connector:
for file in
$(find gcc/config -name -o -name -o -name )
do
cp -uv $file{,.orig}
sed -e ‘s@/lib(64)?(32)?/ld@/tools&@g’
-e ‘s@/usr@/tools@g’ $ > $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 $
done
The same settings are three libraries:
tar -xf …/mpfr-3.1.
mv -v mpfr-3.1.3 mpfr
tar -xf …/gmp-6.1.
mv -v gmp-6.1.0 gmp
tar -xf …/mpc-1.0.
mv -v mpc-1.0.3 mpc
Compilation configuration:
CC=$LFS_TGT-gcc
CXX=$LFS_TGT-g++
AR=$LFS_TGT-ar
RANLIB=$LFS_TGT-ranlib
…/configure
–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
Link gcc to cc
ln -sv gcc /tools/bin/cc
The same confirmation of the correctness of the new toolchain:
echo ‘int main(){}’ >
cc
readelf -l | grep ‘: /tools’
My output results are as follows:
[Requesting program interpreter: /tools/lib64/.2]
Clean up test files:
rm -v
8. Tcl-core-8.6.4
thissoftwareThe package and the next three packages (Expect, DejaGNU, andCheck), provides test suite running support for other packages such as gcc and Binutils.
tcl compilation configuration
cd unix
./configure --prefix=/tools
Compile and test tcl
make
TZ=UTC make test
Make the installed library file writable:
chmod -v u+w /tools/lib/libtcl8.
Install the tcl header file
make install-private-headers
Create necessary links
ln -sv tclsh8.6 /tools/bin/tclsh
9. Expect-5.45
Force Expect's configuration script to use /bin/stty instead of /usr/local/bin/stty of the host:
cp -v configure{,.orig}
sed ‘s:/usr/local/bin:/bin:’ > configure
Configure Expect:
./configure --prefix=/tools
–with-tcl=/tools/lib
–with-tclinclude=/tools/include
Compilation and testing:
make
make test
Install the software package:
make SCRIPTS=“” install
10. DejaGNU-1.5.3
Execute the following commands to compile and install:
./configure --prefix=/tools
make install
make check
11. Check-0.10.0
Execution is as follows:
PKG_CONFIG= ./configure --prefix=/tools
make
make check
make install
12. Ncurses-6.0
First, make sure to find gawk first during configuration:
sed -i s/mawk// configure
Compilation configuration:
./configure --prefix=/tools
–with-shared
–without-debug
–without-ada
–enable-widec
–enable-overwrite
Compilation and installation: make and make install
12. Bash-4.3.30
Execution is as follows:
./configure --prefix=/tools --without-bash-malloc
make
make tests
make install
ln -sv bash /tools/bin/sh
13. Bzip2-1.0.6
make
make PREFIX=/tools install
14. Coreutils-8.25
./configure --prefix=/tools --enable-install-program=hostname
make
make RUN_EXPENSIVE_TESTS=yes check
make install
15. Diffutils-3.3
./configure --prefix=/tools
make
make check
make install
16. File-5.25
./configure --prefix=/tools
make
make check
make install
17. Findutils-4.6.0
./configure --prefix=/tools
make
make check
make install
18. Gawk-4.1.3
./configure --prefix=/tools
make
make check
make install
19. Gettext-0.19.7
cd gettext-tools
EMACS=“no” ./configure --prefix=/tools --disable-shared
According to requirements, only the following software packages are compiled:
make -C gnulib-lib
make -C intl
make -C src msgfmt
make -C src msgmerge
make -C src xgettext
Install msgfmt, msgmerge and xgettext
cp -v src/{msgfmt,msgmerge,xgettext} /tools/bin
20. Grep-2.23、Gzip-1.6、M4-1.4.17、Patch-2.7.5、Sed-4.2.2、Tar-1.28、Texinfo-6.1、Xz-5.2.2
./configure --prefix=/tools
make
make check
make install
21. Make-4.1
./configure --prefix=/tools --without-guile
make
make check
make install
22. Perl-5.22.1
sh Configure -des -Dprefix=/tools -Dlibs=-lm
make
cp -v perl cpan/podlators/pod2man /tools/bin
mkdir -pv /tools/lib/perl5/5.22.1
cp -Rv lib/* /tools/lib/perl5/5.22.1
As mentioned above, only a small number of applications and libraries are installed.
23. Util-linux-2.27.1
The configuration is as follows:
./configure --prefix=/tools
–without-python
–disable-makeinstall-chown
–without-systemdsystemunitdir
PKG_CONFIG=“”
Compile and install make && make install
24. Stripping
This step is optional. If your space is large enough, you don’t need to do this step. It mainly cleans up some useless content: delete some debugging symbols, etc., in order to reduce the file size.
strip --strip-debug /tools/lib/*
/usr/bin/strip --strip-unneeded /tools/{,s}bin/*
Delete the help document:
rm -rf /tools/{,share}/{info,man,doc}
I have a lot of space, and considering that I may check these things in the future, I won’t do this step.
24. Change the Lord
We need to perform subsequent operations under the root user and ensure that there are lfs users under the root. Here we change the user directory of $LFS/tools to the root user group:
chown -R root:root $LFS/tools
At the same time, we can back up the $LFS/tools folder, which is convenient for use when updating the lfs version in the future. In the future lfs construction, we can reduce operations on this step.