本文中编译的工具都会放到$LFS/tools
基本过程基本都是
- 解压
- configure
- make
- make install
- 删除解压文件
binutls
查看/mnt/lfs/sources下的压缩包
lfs:/mnt/lfs/sources$ ls | grep binutils
binutils-2.38-lto_fix-1.patch
binutils-2.38.tar.xz
解压
lfs:/mnt/lfs/sources$ tar -xf binutils-2.38.tar.xz
lfs:/mnt/lfs/sources$ ls | grep binutils
binutils-2.38
binutils-2.38-lto_fix-1.patch
binutils-2.38.tar.xz
创建build目录
lfs:/mnt/lfs/sources$ cd binutils-2.38
lfs:/mnt/lfs/sources/binutils-2.38$ mkdir -v build
mkdir: created directory 'build'
lfs:/mnt/lfs/sources/binutils-2.38$ cd build
lfs:/mnt/lfs/sources/binutils-2.38/build$
configure
lfs:/mnt/lfs/sources/binutils-2.38/build$ ../configure --prefix=$LFS/tools \
> --with-sysroot=$LFS \
> --target=$LFS_TGT \
> --disable-nls \
> --disable-werror
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-lfs-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /usr/bin/sed
checking for gawk... gawk
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for gcc option to accept ISO C99... -std=gnu99
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ accepts -static-libstdc++ -static-libgcc... no
checking for gnatbind... no
checking for gnatmake... no
checking whether compiler driver understands Ada... no
checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2
checking for objdir... .libs
checking for isl 0.15 or later... no
required isl version is 0.15 or later
checking for default BUILD_CONFIG...
checking for --enable-vtable-verify... no
checking for bison... bison -y
checking for bison... bison
checking for gm4... no
checking for gnum4... no
checking for m4... m4
checking for flex... no
checking for lex... no
checking for flex... no
checking for makeinfo... makeinfo
checking for expect... no
checking for runtest... no
checking for ar... ar
checking for as... as
checking for dlltool... no
checking for ld... ld
checking for lipo... no
checking for nm... nm
checking for ranlib... ranlib
checking for strip... strip
checking for windres... no
checking for windmc... no
checking for objcopy... objcopy
checking for objdump... objdump
checking for readelf... readelf
checking for -plugin option... ar: no operation specified
configure: WARNING: Failed: ar --plugin /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/liblto_plugin.so rc
no
checking for x86_64-lfs-linux-gnu-cc... no
checking for x86_64-lfs-linux-gnu-gcc... no
checking for x86_64-lfs-linux-gnu-c++... no
checking for x86_64-lfs-linux-gnu-g++... no
checking for x86_64-lfs-linux-gnu-cxx... no
checking for x86_64-lfs-linux-gnu-gxx... no
checking for x86_64-lfs-linux-gnu-gcc... no
checking for x86_64-lfs-linux-gnu-gfortran... no
checking for x86_64-lfs-linux-gnu-gccgo... no
checking for x86_64-lfs-linux-gnu-ar... no
checking for x86_64-lfs-linux-gnu-as... no
checking for x86_64-lfs-linux-gnu-dlltool... no
checking for x86_64-lfs-linux-gnu-ld... no
checking for x86_64-lfs-linux-gnu-lipo... no
checking for x86_64-lfs-linux-gnu-nm... no
checking for x86_64-lfs-linux-gnu-objcopy... no
checking for x86_64-lfs-linux-gnu-objdump... no
checking for x86_64-lfs-linux-gnu-ranlib... no
checking for x86_64-lfs-linux-gnu-readelf... no
checking for x86_64-lfs-linux-gnu-strip... no
checking for x86_64-lfs-linux-gnu-windres... no
checking for x86_64-lfs-linux-gnu-windmc... no
checking where to find the target ar... just compiled
checking where to find the target as... just compiled
checking where to find the target cc... pre-installed
checking where to find the target c++... pre-installed
checking where to find the target c++ for libstdc++... pre-installed
checking where to find the target dlltool... just compiled
checking where to find the target gcc... pre-installed
checking where to find the target gfortran... pre-installed
checking where to find the target gccgo... pre-installed
checking where to find the target ld... just compiled
checking where to find the target lipo... pre-installed
checking where to find the target nm... just compiled
checking where to find the target objcopy... just compiled
checking where to find the target objdump... just compiled
checking where to find the target ranlib... just compiled
checking where to find the target readelf... just compiled
checking where to find the target strip... just compiled
checking where to find the target windres... just compiled
checking where to find the target windmc... just compiled
checking whether to enable maintainer-specific portions of Makefiles... no
configure: creating ./config.status
config.status: creating Makefile
lfs:/mnt/lfs/sources/binutils-2.38/build$ ls
Makefile config.log config.status serdep.tmp
接下来进行编译和安装
lfs:/mnt/lfs/sources/binutils-2.38/build$make
lfs:/mnt/lfs/sources/binutils-2.38/build$make install
lfs:/mnt/lfs/sources/binutils-2.38/build$ ls
Makefile binutils config.status gas intl libctf opcodes zlib
bfd config.log etc gprof ld libiberty serdep.tmp
完成后,去sources文件夹下把解压的binutils文件夹删掉
lfs:/mnt/lfs/sources$ ls | grep binut
binutils-2.38
binutils-2.38-lto_fix-1.patch
binutils-2.38.tar.xz
lfs:/mnt/lfs/sources$ rm -rf binutils-2.38
lfs:/mnt/lfs/sources$ ls | grep binut
binutils-2.38-lto_fix-1.patch
binutils-2.38.tar.xz
GCC
解压
lfs:/mnt/lfs/sources$ ls | grep gcc
gcc-11.2.0.tar.xz
lfs:/mnt/lfs/sources$ tar -xf gcc-11.2.0.tar.xz
lfs:/mnt/lfs/sources$ ls | grep gcc
gcc-11.2.0
gcc-11.2.0.tar.xz
将GMP, MPFR and MPC packages 放入gcc
lfs:/mnt/lfs/sources$ cd gcc-11.2.0
lfs:/mnt/lfs/sources/gcc-11.2.0$ tar -xf ../mpfr-4.1.0.tar.xz
lfs:/mnt/lfs/sources/gcc-11.2.0$ mv -v mpfr-4.1.0 mpfr
'mpfr-4.1.0' -> 'mpfr'
lfs:/mnt/lfs/sources/gcc-11.2.0$ tar -xf ../gmp-6.2.1.tar.xz
lfs:/mnt/lfs/sources/gcc-11.2.0$ mv -v gmp-6.2.1 gmp
'gmp-6.2.1' -> 'gmp'
lfs:/mnt/lfs/sources/gcc-11.2.0$ tar -xf ../mpc-1.2.1.tar.gz
lfs:/mnt/lfs/sources/gcc-11.2.0$ mv -v mpc-1.2.1 mpc
'mpc-1.2.1' -> 'mpc'
case $(uname -m) in
x86_64)
sed -e '/m64=/s/lib64/lib/' \
-i.orig gcc/config/i386/t-linux64
;;
esac
创建build文件夹
lfs:/mnt/lfs/sources/gcc-11.2.0$ mkdir -v build
mkdir: created directory 'build'
lfs:/mnt/lfs/sources/gcc-11.2.0$ cd build
configure
../configure \
--target=$LFS_TGT \
--prefix=$LFS/tools \
--with-glibc-version=2.35 \
--with-sysroot=$LFS \
--with-newlib \
--without-headers \
--enable-initfini-array \
--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++
make
lfs:/mnt/lfs/sources/gcc-11.2.0/build$ make
遇到报错,这里是机器资源不足,我把MAKEFLAG 中-j4 删掉,重新make就成功了
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
Makefile:1142: recipe for target 'insn-emit.o' failed
make[2]: *** [insn-emit.o] Error 4
make[2]: *** Waiting for unfinished jobs....
rm gcc.pod
make[2]: Leaving directory '/mnt/lfs/sources/gcc-11.2.0/build/gcc'
Makefile:4420: recipe for target 'all-gcc' failed
make[1]: *** [all-gcc] Error 2
make[1]: Leaving directory '/mnt/lfs/sources/gcc-11.2.0/build'
Makefile:946: recipe for target 'all' failed
make: *** [all] Error 2
make install
cd ..
cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
`dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/install-tools/include/limits.h
删掉目录
lfs:/mnt/lfs/sources/gcc-11.2.0$ cd ..
lfs:/mnt/lfs/sources$ rm -rf gcc-11.2.0
Linux 头文件
解压
lfs:/mnt/lfs/sources$ tar -xf linux-5.16.9.tar.xz
lfs:/mnt/lfs/sources$ cd linux-5.16.9
做一下环境清理,删除所有配置
lfs:/mnt/lfs/sources/linux-5.16.9$ make mrproper
编译头文件
make headers
find usr/include -name '.*' -delete
rm usr/include/Makefile
cp -rv usr/include $LFS/usr
删除掉文件夹
lfs:/mnt/lfs/sources/linux-5.16.9$ cd ..
lfs:/mnt/lfs/sources$ rm -rf linux-5.16.9
Glibc
解压
lfs:/mnt/lfs/sources$ tar -xf glibc-2.35.tar.xz
lfs:/mnt/lfs/sources$ cd glibc-2.35
case $(uname -m) in
i?86) ln -sfv ld-linux.so.2 $LFS/lib/ld-lsb.so.3
;;
x86_64) 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
;;
esac
'/mnt/lfs/lib64/ld-linux-x86-64.so.2' -> '../lib/ld-linux-x86-64.so.2'
'/mnt/lfs/lib64/ld-lsb-x86-64.so.3' -> '../lib/ld-linux-x86-64.so.2'
打补丁
lfs:/mnt/lfs/sources/glibc-2.35$ patch -Np1 -i ../glibc-2.35-fhs-1.patch
patching file Makeconfig
Hunk #1 succeeded at 246 (offset -4 lines).
patching file nscd/nscd.h
Hunk #1 succeeded at 160 (offset 48 lines).
patching file nss/db-Makefile
Hunk #1 succeeded at 21 (offset -1 lines).
patching file sysdeps/generic/paths.h
patching file sysdeps/unix/sysv/linux/paths.h
创建build文件
lfs:/mnt/lfs/sources/glibc-2.35$ mkdir -v build
mkdir: created directory 'build'
lfs:/mnt/lfs/sources/glibc-2.35$ cd build
lfs:/mnt/lfs/sources/glibc-2.35/build$ ls
lfs:/mnt/lfs/sources/glibc-2.35/build$ echo "rootsbindir=/usr/sbin" > configparms
lfs:/mnt/lfs/sources/glibc-2.35/build$ ls
configparms
配置文件
../configure \
--prefix=/usr \
--host=$LFS_TGT \
--build=$(../scripts/config.guess) \
--enable-kernel=3.2 \
--with-headers=$LFS/usr/include \
libc_cv_slibdir=/usr/lib
make -j1
make DESTDIR=$LFS install
sed '/RTLDLIST=/s@/usr@@g' -i $LFS/usr/bin/ldd
lfs:/mnt/lfs/sources/glibc-2.35/build$ cd ../..
lfs:/mnt/lfs/sources$ rm -rf glibc-2.35
Libstdc++ from GCC-11.2.0
解压GCC
lfs:/mnt/lfs/sources$ tar -xf gcc-11.2.0.tar.xz
lfs:/mnt/lfs/sources$ cd gcc-11.2.0
lfs:/mnt/lfs/sources/gcc-11.2.0$ mkdir -v build
mkdir: created directory 'build'
lfs:/mnt/lfs/sources/gcc-11.2.0$ 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++/11.2.0
make
make DESTDIR=$LFS install
删掉文件夹
lfs:/mnt/lfs/sources/gcc-11.2.0/build$ cd ../..
lfs:/mnt/lfs/sources$ rm -rf gcc-11.2.0
网友评论