lfs-4 編譯交叉工具鏈

本文中編譯的工具都會放到$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

創(chuàng)建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

接下來進(jìn)行編譯和安裝

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

創(chuàng)建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

遇到報(bào)錯(cuò)屑宠,這里是機(jī)器資源不足窍仰,我把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

做一下環(huán)境清理巴比,刪除所有配置

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'

打補(bǔ)丁

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

創(chuàng)建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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末云茸,一起剝皮案震驚了整個(gè)濱河市蜓堕,隨后出現(xiàn)的幾起案子墨叛,更是在濱河造成了極大的恐慌,老刑警劉巖尝盼,帶你破解...
    沈念sama閱讀 217,509評論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件吞滞,死亡現(xiàn)場離奇詭異,居然都是意外死亡盾沫,警方通過查閱死者的電腦和手機(jī)裁赠,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,806評論 3 394
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來赴精,“玉大人佩捞,你說我怎么就攤上這事±儆矗” “怎么了一忱?”我有些...
    開封第一講書人閱讀 163,875評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長谭确。 經(jīng)常有香客問我意乓,道長蔗崎,這世上最難降的妖魔是什么拂檩? 我笑而不...
    開封第一講書人閱讀 58,441評論 1 293
  • 正文 為了忘掉前任便贵,我火速辦了婚禮,結(jié)果婚禮上昂秃,老公的妹妹穿的比我還像新娘禀梳。我一直安慰自己杜窄,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,488評論 6 392
  • 文/花漫 我一把揭開白布算途。 她就那樣靜靜地躺著塞耕,像睡著了一般。 火紅的嫁衣襯著肌膚如雪郊艘。 梳的紋絲不亂的頭發(fā)上荷科,一...
    開封第一講書人閱讀 51,365評論 1 302
  • 那天,我揣著相機(jī)與錄音纱注,去河邊找鬼畏浆。 笑死,一個(gè)胖子當(dāng)著我的面吹牛狞贱,可吹牛的內(nèi)容都是我干的刻获。 我是一名探鬼主播,決...
    沈念sama閱讀 40,190評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼瞎嬉,長吁一口氣:“原來是場噩夢啊……” “哼蝎毡!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起氧枣,我...
    開封第一講書人閱讀 39,062評論 0 276
  • 序言:老撾萬榮一對情侶失蹤沐兵,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后便监,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體扎谎,經(jīng)...
    沈念sama閱讀 45,500評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,706評論 3 335
  • 正文 我和宋清朗相戀三年烧董,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了毁靶。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,834評論 1 347
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡逊移,死狀恐怖预吆,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情胳泉,我是刑警寧澤拐叉,帶...
    沈念sama閱讀 35,559評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站扇商,受9級特大地震影響凤瘦,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜钳吟,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,167評論 3 328
  • 文/蒙蒙 一廷粒、第九天 我趴在偏房一處隱蔽的房頂上張望窘拯。 院中可真熱鬧红且,春花似錦坝茎、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,779評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至壁酬,卻和暖如春次酌,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背舆乔。 一陣腳步聲響...
    開封第一講書人閱讀 32,912評論 1 269
  • 我被黑心中介騙來泰國打工岳服, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人希俩。 一個(gè)月前我還...
    沈念sama閱讀 47,958評論 2 370
  • 正文 我出身青樓吊宋,卻偏偏與公主長得像,于是被迫代替她去往敵國和親颜武。 傳聞我的和親對象是個(gè)殘疾皇子璃搜,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,779評論 2 354

推薦閱讀更多精彩內(nèi)容