天天看點

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

(題圖來自: techradar.com)

繼續來編譯工具,接下來編譯glibc

<code>if [ ! -r /usr/include/rpc/types.h ]; then</code>

<code>su -c ‘mkdir -pv /usr/include/rpc’</code>

<code>su -c ‘cp -v sunrpc/rpc/*.h /usr/include/rpc’</code>

<code>fi</code>

<code></code>

<code>tar -xf glibc-2.21.tar.xz</code>

<code>cd glibc-2.21/</code>

<code>mkdir -v ../glibc-build</code>

<code>cd ../glibc-build/</code>

<code>../glibc-2.21/configure \</code>

<code>–prefix=/tools \</code>

<code>–host=$lfs_tgt \</code>

<code>–build=$(../glibc-2.21/scripts/config.guess) \</code>

<code>–disable-profile \</code>

<code>–enable-kernel=2.6.32 \</code>

<code>–with-headers=/tools/include \</code>

<code>libc_cv_forced_unwind=yes \</code>

<code>libc_cv_ctors_header=yes \</code>

<code>libc_cv_c_cleanup=yes</code>

<code>make</code>

<code>make install</code>

編譯安裝沒什麼新鮮的,不同的是需要測試一下

<code>echo ‘main(){}’ &gt; dummy.c</code>

<code>$lfs_tgt-gcc dummy.c</code>

<code>readelf -l a.out | grep ‘: /tools’</code>

這時候回顯一行

<code>[requesting program interpreter: /tools/lib64/ld-linux-x86-64.so.2]</code>

最後删除測試檔案

<code>rm -v dummy.c a.out</code>

編譯libstdc++有點麻煩,需要先重命名一下gcc-build,免得和上次的編譯目錄摻和了

回到$lfs/src,然後執行以下指令

<code>mv gcc-build gcc-build.first</code>

建立gcc-build目錄

<code>mkdir -pv  gcc-build</code>

<code>cd gcc-build</code>

調整libstdc++配置

<code>../gcc-4.9.2/libstdc++-v3/configure \</code>

<code>–disable-multilib \</code>

<code>–disable-shared \</code>

<code>–disable-nls \</code>

<code>–disable-libstdcxx-threads \</code>

<code>–disable-libstdcxx-pch \</code>

<code>–with-gxx-include-dir=/tools/$lfs_tgt/include/c++/4.9.2</code>

然後編譯安裝就好了

進度很快,我們要二次編譯binutils了

在此之前,我們需要回到$lfs/src,然後重命名binutils-build,再建立一個

<code>mv binutils-build binutils-build.first</code>

<code>mkdir -v binutils-build</code>

<code>cd binutils-build</code>

<code>cc=$lfs_tgt-gcc \</code>

<code>ar=$lfs_tgt-ar \</code>

<code>ranlib=$lfs_tgt-ranlib \</code>

<code>../binutils-2.25/configure \</code>

<code>–disable-werror \</code>

<code>–with-lib-path=/tools/lib \</code>

<code>–with-sysroot</code>

編譯安裝

第二次編譯安裝binutils之後,需要調整一下連接配接器來進行主體編譯

<code>make -c ld clean</code>

<code>make -c ld lib_path=/usr/lib:/lib</code>

<code>cp -v ld/ld-new /tools/bin</code>

至此binutils二次編譯安裝調整完畢,接下來要進行gcc的二次編譯

進入gcc源碼目錄

<code>cd $lfs/src/gcc-4.9.2</code>

我們需要先寫一個限制檔案

<code>cat gcc/limitx.h gcc/glimits.h gcc/limity.h &gt; \</code>

<code>`dirname $($lfs_tgt-gcc -print-libgcc-file-name)`/include-fixed/limits.h</code>

然後調整一下編譯環境

<code>for file in \</code>

<code>$(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)</code>

<code>do</code>

<code>cp -uv $file{,.orig}</code>

<code>sed -e ‘s@/lib\(64\)\?\(32\)\?/ld@/tools&amp;@g’ \</code>

<code>-e ‘s@/usr@/tools@g’ $file.orig &gt; $file</code>

<code>echo ‘</code>

<code>#undef standard_startfile_prefix_1</code>

<code>#undef standard_startfile_prefix_2</code>

<code>#define standard_startfile_prefix_1 “/tools/lib/”</code>

<code>#define standard_startfile_prefix_2 “”‘ &gt;&gt; $file</code>

<code>touch $file.orig</code>

<code>done</code>

加入mpfr,gmp,mpc三個包的支援

<code>tar -xf ../mpfr-3.1.2.tar.xz</code>

<code>mv -v mpfr-3.1.2 mpfr</code>

<code>tar -xf ../gmp-6.0.0a.tar.xz</code>

<code>mv -v gmp-6.0.0 gmp</code>

<code>tar -xf ../mpc-1.0.2.tar.gz</code>

<code>mv -v mpc-1.0.2 mpc</code>

重命名libc++編譯的目錄

<code>mv ../gcc-build ../gcc-build.libc++</code>

建立編譯目錄

<code>mkdir -v ../gcc-build</code>

<code>cd ../gcc-build</code>

配置編譯選項

<code>cxx=$lfs_tgt-g++ \</code>

<code>../gcc-4.9.2/configure \</code>

<code>–with-local-prefix=/tools \</code>

<code>–with-native-system-header-dir=/tools/include \</code>

<code>–enable-languages=c,c++ \</code>

<code>–disable-bootstrap \</code>

<code>–disable-libgomp</code>

編譯後安裝

在這之後我們需要做個軟連接配接

<code>ln -sv gcc /tools/bin/cc</code>

接下來寫個檔案測試一下

<code>cc dummy.c</code>

回顯應該還是這個

最後清理一下測試檔案

兩次編譯binutils和gcc之後,進入tcl的編譯安裝

回到$lfs/src目錄,解壓tcl源碼

<code>tar zxvf tcl8.6.3-src.tar.gz</code>

<code>cd tcl8.6.3</code>

<code>cd unix</code>

<code>./configure –prefix=/tools</code>

編譯并測試

<code>tz=utc make test</code>

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

6-tcltest

這個此時結果裡面有幾個數,total是一共做了多少項測試,passed是這些測試中通過了多少項,skipped是跳過了幾項測試,failed是這些測試中有多少失敗了。

從這份結果中,我們可以看到tcl編譯完全正常,一共116項測試,全部通過,這就意味着可以安裝了

下面給tcl庫檔案加上屬主的寫權限

<code>chmod -v u+w /tools/lib/libtcl8.6.so</code>

回顯應該是這樣

<code>mode of `/tools/lib/libtcl8.6.so’ changed from 0555 (r-xr-xr-x) to 0755 (rwxr-xr-x)</code>

安裝tcl的頭

<code>make install-private-headers</code>

<code>installing private header files to /tools/include/</code>

做個軟連接配接

<code>ln -sv tclsh8.6 /tools/bin/tclsh</code>

繼續進行expect編譯,解壓并進入expect目錄

<code>tar zxvf expect5.45.tar.gz</code>

<code>cd expect5.45</code>

首先得重寫configure檔案

<code>cp -v configure{,.orig}</code>

<code>sed ‘s:/usr/local/bin:/bin:’ configure.orig &gt; configure</code>

<code>./configure –prefix=/tools \</code>

<code>–with-tcl=/tools/lib \</code>

<code>–with-tclinclude=/tools/include</code>

編譯和測試

<code>make test</code>

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

7-excepttest

本次測試我們發現一共有26個用例,其中通過了15個,有11個失敗了。不過在lfs 7.7的官方文檔中有這麼一句

note that the expect test suite is known to experience failures under certain host conditions that are not within our control. therefore, test suite failures here are not surprising and are not considered critical.

這就說明測試用例失敗不代表主要依據,是以我們繼續往下安裝,隻要安裝和使用不出問題,就沒關系。

<code>make scripts=”” install</code>

安裝沒有報錯,是以我們不必擔心那近乎一半的測試用例失敗。

繼續我們回到$lfs/src并解壓并配置編譯dejagnu

<code>tar zxvf dejagnu-1.5.2.tar.gz</code>

<code>cd dejagnu-1.5.2</code>

這個配置完編譯選項之後可以直接安裝并檢查編譯

<code>make check</code>

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

8-dejagnutest

測試結果summary顯示有68個測試通過,沒有失敗資訊

接下來是check的編譯安裝,check有點特殊的是,在配置編譯選項的時候,需要将配置結果設定一個變量。回到$lfs/src,解壓并進入源碼目錄

<code>tar zxvf check-0.9.14.tar.gz</code>

<code>cd check-0.9.14</code>

開始配置編譯選項

<code>pkg_config= ./configure –prefix=/tools</code>

除了這個沒什麼新鮮的,就是configure的最後有個summary of check options

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

9-checkcfgsummary

再就是編譯和編譯檢查

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

10-checktestpass

檢查結果顯示,7個測試全部通過,安裝即可

安裝成功後回到$lfs/src,繼續解壓ncurses并進入源碼目錄

<code>cd $lfs/src</code>

<code>tar zxvf ncurses-5.9.tar.gz</code>

<code>cd ncurses-5.9</code>

下面的倒是沒新鮮的,配置編譯選項并且編譯安裝就可以了

<code>–with-shared \</code>

<code>–without-debug \</code>

<code>–without-ada \</code>

<code>–enable-widec \</code>

<code>–enable-overwrite</code>

回到$lfs/src,解壓bash并進入源碼目錄

<code>tar zxvf bash-4.3.30.tar.gz</code>

<code>cd bash-4.3.30</code>

配置編譯選項并且編譯

<code>./configure –prefix=/tools –without-bash-malloc</code>

進行編譯測試并且安裝

<code>make tests</code>

再加個軟連接配接就完成了

<code>ln -sv bash /tools/bin/sh</code>

解壓編譯安裝bzip2

<code>tar zxvf bzip2-1.0.6.tar.gz</code>

<code>cd bzip2-1.0.6</code>

<code>make prefix=/tools install</code>

來進行編譯coreutils,還是先回到$lfs/src,再解壓并進入coreutils源碼目錄

<code>tar -xf coreutils-8.23.tar.xz</code>

<code>cd coreutils-8.23</code>

配置coreutils的編譯選項

<code>./configure –prefix=/tools –enable-install-program=hostname</code>

編譯後測試,這次測試需要加個選項

<code>make run_expensive_tests=yes check</code>

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

11-coreutilstestpass

測試結果顯示,共306項測試,通過270項,跳過36項,沒有失敗和錯誤,繼續安裝就可以了

接下來的diffutils沒有新鮮的,配置安裝路徑後編譯,檢查安裝就好了

<code>tar -xf diffutils-3.3.tar.xz</code>

<code>cd diffutils-3.3</code>

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

12-diffutilstestpass

測試結果顯示共140項,通過112項,跳過28項,可以正常安裝

接下來的file也如是一樣

<code>tar zxvf file-5.22.tar.gz</code>

<code>cd file-5.22</code>

下一個是findutils,同樣的步驟

<code>tar zxvf findutils-4.4.2.tar.gz</code>

<code>cd findutils-4.4.2</code>

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

13-findutilstestpass

測試結果表明,28項測試全部通過,沒有失敗記錄,可以安裝

繼續下一個軟體編譯,gawk過程也沒新鮮的,老規矩

<code>tar -xf gawk-4.1.1.tar.xz</code>

<code>cd gawk-4.1.1</code>

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

14-gawktestfailed

檢查結果認為有6項測試失敗,先不去理會,繼續安裝

下一個軟體是gettext,這個稍微有點複雜

首先依舊進入$lfs/src來解壓并進入源碼目錄

<code>tar -xf gettext-0.19.4.tar.xz</code>

<code>cd gettext-0.19.4</code>

先進入gettext-tools目錄

<code>cd gettext-tools</code>

<code>emacs=”no” ./configure –prefix=/tools –disable-shared</code>

接下來需要分别編譯

<code>make -c gnulib-lib</code>

<code>make -c intl pluralx.c</code>

<code>make -c src msgfmt</code>

<code>make -c src msgmerge</code>

<code>make -c src xgettext</code>

之後來手動安裝到/tools/bin下面

<code>cp -v src/{msgfmt,msgmerge,xgettext} /tools/bin</code>

繼續解壓編譯安裝grep

<code>tar -xf grep-2.21.tar.xz</code>

<code>cd grep-2.21</code>

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

15-greptestpass

測試結果顯示共測試138項,通過120項,跳過18項,可以正常安裝

接下來的gzip也如是一樣

<code>tar -xf gzip-1.6.tar.xz</code>

<code>cd gzip-1.6</code>

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

16-gziptestpass

檢測結果顯示共15項測試,通過15項,可以正常安裝

繼續下一個,m4的編譯安裝

<code>tar -xf m4-1.4.17.tar.xz</code>

<code>cd m4-1.4.17</code>

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

17-m4testpass

檢查結果顯示,共163項測試,通過142項,跳過21項,可以正常安裝

繼續來編譯make

<code>tar jxvf make-4.1.tar.bz2</code>

<code>./configure –prefix=/tools –without-guile</code>

重走LFS之路:(五) 工具鍊編譯-2重走LFS之路:(五) 工具鍊編譯-2

18-maketestpass

檢測結果顯示,共544項測試,沒有失敗,可以正常安裝

大部分的工具軟體都是指定一下prefix參數就可以編譯安裝了,隻有個别的需要做一下其他的調整。随後,還會有一部分工具需要編譯安裝。

原文釋出時間:2015-04-06

本文來自雲栖合作夥伴“linux中國”

繼續閱讀