5.5. GCC-4.5.2 - Pass 1
The GCC package contains the GNU compiler collection, which includes the C and C++ compilers.
はじめに
Linuxのインストールをするとき、ほとんどのディストリだとインストーラが付いていると思います。
ですが、インストーラ無しで地道に自分のビルド環境を使ってLinuxをインストールする方法としてLFSというものがあります。
LFS online Document
を基本的には読んで実行していけばいいのですが、
結構抜けが多かったので、公開しておきます。
ビルド環境
Fedora,RHクローン
FedoraやScientific Linux,CentOSなどのRHクローンなら、
su -c yum groupinstall "Development tools" "Development Libraries"
を実行してビルド環境を整えておきます。
Ubuntu,debian系
Ubuntuなどのdebian系はあまりつかったことが無いですが、 最低限必要なものは
apt-get install build-essential
ですかね。それ以外も必要かも… どなたか知ってる方がいらっしゃったら教えてください。
LFS
さて、本題。LFSのhowtoというかメモを公開。
システム
ファイルイメージを作る
[kenken@localhost lfs]$ dd if=/dev/zero of=lfs.img bs=1M count=1 seek=8192 1+0 records in 1+0 records out 1048576 bytes (1.0 MB) copied, 0.00904098 s, 116 MB/s [kenken@localhost lfs]$ dd if=/dev/zero of=swap.img bs=1M count=1 seek=511 1+0 records in 1+0 records out 1048576 bytes (1.0 MB) copied, 0.0218202 s, 48.1 MB/s [kenken@localhost lfs]$ ls -lh 合計 4.0M -rw-rw-r-- 1 kenken kenken 8.1G 2011-05-18 16:47 lfs.img -rw-rw-r-- 1 kenken kenken 512M 2011-05-18 16:46 swap.img
フォーマット
[kenken@localhost lfs]$ mke2fs -jv lfs.img mke2fs 1.41.12 (17-May-2010) lfs.img is not a block special device. Proceed anyway? (y,n) y fs_types for mke2fs.conf resolution: 'ext3', 'default' warning: Unable to get device geometry for lfs.img Calling BLKDISCARD from 0 to 4294967296 failed. warning: 256 blocks unused. Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 262656 inodes, 1048576 blocks 52441 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1073741824 32 block groups 32768 blocks per group, 32768 fragments per group 8208 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 39 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
swap作成
[kenken@localhost lfs]$ mkswap swap.img スワップ空間バージョン1を設定します、サイズ = 524284 KiB ラベルはありません, UUID=0422614e-707a-4778-aea2-37b59dbfcae7
mount ポイントは-o loopオプション
[kenken@localhost lfs]$ su パスワード: [root@localhost lfs]# mkdir -p /mnt/lfs [root@localhost lfs]# exit [kenken@localhost lfs]$ export LFS=/mnt/lfs [kenken@localhost lfs]$ su パスワード: [root@localhost lfs]# mount -o loop lfs.img $LFS
swap not enogh ?
[root@localhost lfs]# /sbin/swapon -v swap.img swap.img に swapon swapon: /home/kenken/ダウンロード/lfs/swap.img: insecure permissions 0664, 0600 suggested. swapon: /home/kenken/ダウンロード/lfs/swap.img: skipping - it appears to have holes. [root@localhost lfs]# chmod 0600 swap.img [root@localhost lfs]# /sbin/swapon -v swap.img swap.img に swapon swapon: /home/kenken/ダウンロード/lfs/swap.img: skipping - it appears to have holes. [root@localhost lfs]# exit
#packages
[kenken@localhost lfs]$ mkdir -v $LFS/sources mkdir: created directory `/mnt/lfs/sources'
[kenken@localhost lfs]$ chmod -v a+wt $LFS/sources/ `/mnt/lfs/sources/' のモードを 1777 (rwxrwxrwt) に変更しました
ダウンロード
[kenken@localhost lfs]$ wget http://www.linuxfromscratch.org/lfs/view/stable/wget-list [kenken@localhost lfs]$ wget -i wget-list -P $LFS/sources
toolsフォルダ作成
[kenken@localhost lfs]$ mkdir -v $LFS/tools mkdir: created directory `/mnt/lfs/tools'
ユーザーとグループの追加
[kenken@localhost lfs]$ su パスワード: [root@localhost lfs]# groupadd lfs [root@localhost lfs]# useradd -s /bin/bas basename bash [root@localhost lfs]# useradd -s /bin/bash -g lfs -m -k /dev/null lfs [root@localhost lfs]# passwd lfs [root@localhost lfs]# chown -v lfs $LFS/tools `/mnt/lfs/tools' の所有者を lfs に変更しました [root@localhost lfs]# ll $LFS 合計 24 drwx------ 2 root root 16384 2011-05-18 16:47 lost+found drwxrwxrwt 2 kenken kenken 4096 2011-05-18 17:20 sources drwxrwxr-x 2 lfs kenken 4096 2011-05-18 17:21 tools [root@localhost lfs]# chown -v lfs $LFS/sources `/mnt/lfs/sources' の所有者を lfs に変更しました [root@localhost lfs]# ll $LFS 合計 24 drwx------ 2 root root 16384 2011-05-18 16:47 lost+found drwxrwxrwt 2 lfs kenken 4096 2011-05-18 17:20 sources drwxrwxr-x 2 lfs kenken 4096 2011-05-18 17:21 tools
環境を構築する
cat > ~/.bash_profile << "EOF" exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash EOF
cat > ~/.bashrc << "EOF" set +h umask 022 LFS=/mnt/lfs LC_ALL=POSIX LFS_TGT=$(uname -m)-lfs-linux-gnu PATH=/tools/bin:/bin:/usr/bin export LFS LC_ALL LFS_TGT PATH EOF
ビルド
ファイルの展開、解凍
for i in `ls *tar.bz2` ; do tar xvjf $i ; done for i in `ls *tar.gz` ; do tar xvzf $i ; done
binutils
準備
binutilsのディレクトリで直接configureしない方が良いと書いているので、 $LFS/sourcesの下に、mkdir binutils-2.21-build cd binutils-2.21-build/
configure
../binutils-2.21/configure --target=$LFS_TGT --prefix=$LFS/tools --disable-nls --disable-werror
lfs:/mnt/lfs/sources/binutils-2.21-build$ ls Makefile config.log config.status serdep.tmp
makeアンドmake install
make make install cd ..
gcc Pass1
準備
lfs:/mnt/lfs/sources$ mv mpfr-3.0.0 mpfr lfs:/mnt/lfs/sources$ mv gmp-5.0.1 gmp lfs:/mnt/lfs/sources$ mv mpc-0.8.2 mpc
configure
lfs:/mnt/lfs/sources$ mkdir gcc-4.5.2-build && cd gcc-4.5.2-build lfs:/mnt/lfs/sources/gcc-4.5.2-build$ ../gcc-4.5.2/configure \ --target=$LFS_TGT --prefix=/tools \ --disable-nls --disable-shared --disable-multilib \ --disable-decimal-float --disable-threads \ --disable-libmudflap --disable-libssp \ --disable-libgomp --enable-languages=c \ --with-gmp-include=$(pwd)/gmp --with-gmp-lib=$(pwd)/gmp/.libs \ --without-ppl --without-cloog configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+. Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify their locations. Source code for these libraries can be found at their respective hosting sites as well as at ftp://gcc.gnu.org/pub/gcc/infrastructure/. See also http://gcc.gnu.org/install/prerequisites.html for additional info. If you obtained GMP, MPFR and/or MPC from a vendor distribution package, make sure that you have installed both the libraries and the header files. They may be located in separate packages.言われビルド失敗。 configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+ gccでググると、gcc-4.5.0をインストールしてみるがヒットし、gmp,mpfr,mpcをそれぞれビルドせよと。 そりゃあ、まあ、そうだわな。 つまり、 mpfr,gmp,mpcそれぞれを--prefix=/tools/{mpfr,gmp,mpc}としてビルド。 gcc --with-mpfr,gmp,mpc=/tools/.... とすればよい。
gmp
というわけで、まずはgmpのビルド。準備
lfs:/mnt/lfs/sources/gcc-4.5.2-build$ cd $LFS/sources lfs:/mnt/lfs/sources/gmp-build$ mkdir gmp-build lfs:/mnt/lfs/sources/gmp-build$ cd gmp-build
configure
mkdir $LFS/tools/gmp lfs:/mnt/lfs/sources/gmp-build$ ../gmp/configure --prefix=$LFS/tools/gmp --target=$LFS_TGTとすると、
configure: error: --target is not appropriate for GMP Use --build=CPU-VENDOR-OS if you need to specify your CPU and/or system explicitly. Use --host if cross-compiling (see "Installing GMP" in the manual for more on this).と言われるので、
lfs:/mnt/lfs/sources/gmp-build$ ../gmp/configure --prefix=$LFS/tools/gmp --build=$LFS_TGこれで、lsでみてみると、
lfs:/mnt/lfs/sources/gmp-build$ ls Makefile config.m4 demos gmp.h mpbsd mpq scanf tune config.h config.status doc libtool mpf mpz stamp-h1 config.log cxx gmp-mparam.h mp.h mpn printf testsと、ちゃんとMakefileが出来てる。
make アンド make install
lfs:/mnt/lfs/sources/gmp-build$ make lfs:/mnt/lfs/sources/gmp-build$ make check lfs:/mnt/lfs/sources/gmp-build$ make install lfs:/mnt/lfs/sources/gmp-build$ cd ../
mpfr
準備
lfs:/mnt/lfs/sources/gcc-4.5.2-build$ cd $LFS/sources lfs:/mnt/lfs/sources/gcc-4.5.2-build$ mkdir mpfr-build lfs:/mnt/lfs/sources/gcc-4.5.2-build$ cd mpfr-build
configure
mkir $LFS/tools/mpfr lfs:/mnt/lfs/sources/mpfr-build$ ../mpfr/configure --prefix=$LFS/tools/mpfr --target=$LFS_TGT lfs:/mnt/lfs/sources/mpfr-build$ ls Makefile config.log config.status libtool mparam.h tests
make アンド make install
lfs:/mnt/lfs/sources/mpfr-build$ make lfs:/mnt/lfs/sources/mpfr-build$ make install
mpc
準備
lfs:/mnt/lfs/sources/gcc-4.5.2-build$ cd $LFS/sources lfs:/mnt/lfs/sources/$ mkdir mpc-build lfs:/mnt/lfs/sources/$ cd mpc-build
configure
mkdir $LFS/tools/mpc lfs:/mnt/lfs/sources/mpc-build$ ../mpc/configure --prefix=$LFS/tools/mpc --target=$LFS_TGT
configure: error: libmpfr not found or uses a different ABI.とエラー。
../mpc/configure --prefix=$LFS/tools/ --build=$LFS_TGT --with-mpfr-include=$LFS/tools/include/ --with-mpfr-lib=$LFS/tools/mpfrとすれば、無事configureが通って
lfs:/mnt/lfs/sources/mpc-build$ ls Makefile config.log doc src tests config.h config.status libtool stamp-h1
でMakefileが出来ているのを確認。
make アンド make install
lfs:/mnt/lfs/sources/mpc-build$ make lfs:/mnt/lfs/sources/mpc-build$ make install lfs:/mnt/lfs/sources/mpc-build$ cd .. lfs:/mnt/lfs/sources/$
gccを再度ビルド
やっと、gccがビルド出来る環境が整いました。準備
lfs:/mnt/lfs/sources/$ cd gcc-4.5.2-build lfs:/mnt/lfs/sources/gcc-4.5.2-build$
configure
lfs:/mnt/lfs/sources/gcc-4.5.2-build$ ../gcc-4.5.2/configure --target=$LFS_TGT --prefix=$LFS/tools \ --with-gmp=$LFS/tools/gmp --with-mpfr=$LFS/tools/mpfr \ --with-mpc=$LFS/tools/mpcでconfigureが通って、
lfs:/mnt/lfs/sources/gcc-4.5.2-build$ ls Makefile config.log config.status serdep.tmpで無事Makefileが出来とります。
make アンド make install
lfs:/mnt/lfs/sources/gcc-4.5.2-build$ make lfs:/mnt/lfs/sources/gcc-4.5.2-build$ make install
と思ったら、ビルドエラー… gcc-4.6.1などの4.6系列のビルドしてみたらいけた。
とりあえず、今回はここまで(*´∀`*
改訂 新Linux/UNIX入門
クチコミを見る
プロのための Linuxシステム構築・運用技術 (Software Design plus)
クチコミを見る
日経 Linux (リナックス) 2011年 11月号 [雑誌]
クチコミを見る