[メモ] CentOS 4.9/RHEL4(i386)で、とりあえずNode.js v4.4.5を動かす (LinuxKernel2.6.9にgcc-4.8とglibc2.11)

- こんなかんじ<br>![Nodev445onCent4.png](https://qiita-image-store.s3.amazonaws.com/0/75594/98abb859-93e6-efaf-1690-25cc90265573.png)

    ```shell-session
[mt08@centos4 node-v4.4.5]$ uname -a
Linux centos4.local 2.6.9-103.ELsmp #1 SMP Fri Dec 9 04:31:51 EST 2011 i686 i686 i386 GNU/Linux
[mt08@centos4 node-v4.4.5]$ PATH=$HOME/482/usr/bin:$PATH node
> console.log('Hello Node.js!')
Hello Node.js!
undefined
> [mt08@centos4 node-v4.4.5]$ PATH=$HOME/482/usr/bin:$PATH node -v
v4.4.5
[mt08@centos4 node-v4.4.5]$ 
```

## 目的
ふるいLinuxシステムで、最近のnodejsをうごかす。<br>(レンタルサーバとかで、RHEL4系とか、まだ現役だったりしませんか？？)

- 参考
    - [RHEL](https://ja.wikipedia.org/wiki/Red_Hat_Enterprise_Linux)4初版:2005年2月15日 - サポート:～2014年1月30日(延長)
    - [CentOS](https://ja.wikipedia.org/wiki/CentOS)4初版: 2005年3月9日 メンテ更新:～2012年2月29日

- (予定)そのうち、バイナリをアップする。githubとか??
 
## 概要
- [CentOS 4.9上](http://qiita.com/mt08/items/708dbd29eb8a25587100)で、Node.js v4.4.5をビルドする。
<br>のだけど、ツール類が古くて怒られるので、そこから入れる。
    - Python 2.3.4 => 2.7.12
    - make 3.80 => make 4.21
    - binutils 2.15.92 => 2.24
    - gcc 3.4.6 => 4.8.2
    - glibc 2.3 => 2.11.3 (新しい過ぎると、Linux KernelのVersionではじかれる)
- ここでつくったgcc(4.8.2)で生成されるものは、 `/tools/lib`とかを<font color='red'>*固定で使う*</font>ようになってる(`#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"`みたいな)

- Express HelloWorld!

    ```bash
export PATH=$HOME/482/usr/bin:/tools/bin:$HOME/usr/bin:$PATH
mkdir myapp
cd myapp
#
#
    cat > package.json <<EOF
    {
      "name": "helloworld",
      "version": "1.0.0",
      "description": "Hello World!",
      "main": "app.js",
      "scripts": {
      "start": "node app.js"
      },
      "keywords": [
        "HelloWorld"
      ],
      "author": "mt08",
      "license": "MIT",
      "dependencies": {
        "express": "^4.14.0"
      }
}
EOF
#
npm install
cat > app.js <<EOF
var express = require('express');
var app = express();
app.get('/', function (req, res) {
      res.send('Hello World!');
});
app.listen(3000, function () {
      console.log('Example app listening on port 3000!');
});
EOF
#
#
uname -a
npm start
```
- ffi

```shell-session
[mt08@centos4 myapp]$ npm install ffi
/
> ref@1.3.2 install /home/mt08/myapp/node_modules/ffi/node_modules/ref
> node-gyp rebuild

make: Entering directory '/home/mt08/myapp/node_modules/ffi/node_modules/ref/build'
  CXX(target) Release/obj.target/binding/src/binding.o
  SOLINK_MODULE(target) Release/obj.target/binding.node
  COPY Release/binding.node
make: Leaving directory '/home/mt08/myapp/node_modules/ffi/node_modules/ref/build'

> ffi@2.0.0 install /home/mt08/myapp/node_modules/ffi
> node-gyp rebuild

make: Entering directory '/home/mt08/myapp/node_modules/ffi/build'
  CC(target) Release/obj.target/ffi/deps/libffi/src/prep_cif.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/types.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/raw_api.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/java_raw_api.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/closures.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/x86/ffi.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/x86/ffi64.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/x86/unix64.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/x86/sysv.o
  AR(target) Release/obj.target/deps/libffi/libffi.a
  COPY Release/libffi.a
  CXX(target) Release/obj.target/ffi_bindings/src/ffi.o
  CXX(target) Release/obj.target/ffi_bindings/src/callback_info.o
  CXX(target) Release/obj.target/ffi_bindings/src/threaded_callback_invokation.o
  SOLINK_MODULE(target) Release/obj.target/ffi_bindings.node
  COPY Release/ffi_bindings.node
make: Leaving directory '/home/mt08/myapp/node_modules/ffi/build'
ffi@2.0.0 node_modules/ffi
├── bindings@1.2.1
├── ref-struct@1.0.2
├── debug@2.2.0 (ms@0.7.1)
├── nan@2.3.5
└── ref@1.3.2
[mt08@centos4 myapp]$ node
> var ffi = require('ffi')
undefined
> var math = ffi.Library('libm', {
...    'sqrt': [ 'double', [ 'double'] ],
...    'sin': [ 'double', [ 'double'] ],
... });
undefined
> math.sqrt(2)
1.4142135623730951
> math.sin(Math.PI/2)
1
> math.sin(Math.PI/6)
0.49999999999999994
> 
```


## ビルド環境

### CentOS 4.9

- このへんを参考に -> [[メモ] CentOS 4.x を VMWareにインストール(いまさら..)](708dbd29eb8a25587100)
- 'linux text' でインストール
- Firewall、SELinuxは、なし
- パッケージは、カスタムで、すべてチェックをはずした。
- ビルドツールをいれておく。

    ```bash
sudo yum install yum-utils
sudo yum groupinstall "Development Tools"
```


## 手順

### フォルダ
`~/work    `: 作業フォルダ
`~/usr     `: インストールフォルダ(gcc-3.4.6でビルド)
`~/482/usr `: インストールフォルダ(gcc-4.8.2でビルド)

### 準備

```
PATH=$HOME/usr/bin:$PATH
export DIR_WORK=$HOME/work
export DIR_INST=$HOME/usr
export DIR_INST_482=$HOME/482/usr
#
export MAKEFLAGS='-j 4'
#
# とりあえず ~/work フォルダ
cd
mkdir -p ${DIR_WORK} ${DIR_INST_482}
cd ${DIR_WORK}
```

### Python `2.7.12`
```
## python 2.7.12
cd ${DIR_WORK}
PYTHON_VERSION=2.7.12
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz --no-check-certificate
tar zxf ./Python-${PYTHON_VERSION}.tgz
cd Python-${PYTHON_VERSION}
time { date > build.log ; \
     ./configure --prefix=${DIR_INST} 2>&1 | tee -a ./build.log ; \
    date > build.log ; \
    make 2>&1 | tee -a ./build.log ;
    date >> ./build.log ; } 

#sudo porg -lp python-${PYTHON_VERSION} -E /home "make install"
make install
```

```shell-session
real    1m2.273s
user    1m20.189s
sys    0m15.742s
.
.

[mt08@centos4 Python-2.7.11]$ python -V
Python 2.3.4
[mt08@centos4 Python-2.7.11]$ type python
python is hashed (/usr/bin/python)
[mt08@centos4 Python-2.7.11]$ hash -r
[mt08@centos4 Python-2.7.11]$ python -V
Python 2.7.11
[mt08@centos4 Python-2.7.11]$ type python
python is hashed (/home/mt08/usr/bin/python)
[mt08@centos4 Python-2.7.11]$
```

### make `4.2.1`

```
## make-4.2.1
cd ${DIR_WORK}
MAKE_VERSION=4.2.1
wget https://ftp.gnu.org/gnu/make/make-${MAKE_VERSION}.tar.bz2 --no-check-certificate
tar jxf make-${MAKE_VERSION}.tar.bz2
mkdir build-make
cd build-make
time { date > build.log ; \
     ../make-${MAKE_VERSION}/configure --prefix=${DIR_INST} 2>&1 | tee -a ./build.log ; \
    date > build.log ; \
    make 2>&1 | tee -a ./build.log ;
    date >> ./build.log ; } 

#sudo porg -lp make-${MAKE_VERSION} "make install"
make install
```

```shell-session
real	0m7.476s
user	0m7.611s
sys	0m3.594s
.
.
[mt08@centos4 build-make]$ make -v
GNU Make 3.80
Copyright (C) 2002  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
[mt08@centos4 build-make]$ hash -r 
[mt08@centos4 build-make]$ make -v
GNU Make 4.2.1
Built for i686-pc-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[mt08@centos4 build-make]$ 
```





### ↓の[gcc-4.8.2環境のインストール](http://)で、gcc-4.8.2、glibc-2.11.3をインストール



### シンボリックリンクをはる 
```bash
sudo -u lfs ln -sf /tools/include/elf.h /tools/include/linux/auxvec.h
```

### Node.js (v4.4.5)

```bash
#gcc-4.8.2のPATH追加.
PATH=/tools/bin:$HOME/usr/bin:$PATH
#
#
cd ${DIR_WORK}
wget https://nodejs.org/dist/latest-v4.x/node-v4.4.5.tar.gz --no-check-certificate
tar zxf ./node-v4.4.5.tar.gz
cd node-v4.4.5
#
#
time { date > build.log ; \
     ./configure --prefix=${DIR_INST_482} 2>&1 | tee -a ./build.log ; \
    date > build.log ; \
    CC=/tools/bin/i686-pc-linux-gnu-gcc make 2>&1 | tee -a ./build.log ;
    date >> ./build.log ; }
#
#
CC=/tools/bin/i686-pc-linux-gnu-gcc make install
```

#### `vi $HOME/482/usr/bin/npm`
一行目を書き換える: 
`#!/usr/bin/env node`

- ログ

    ```shell-session
g++ -pthread -rdynamic -m32 -Wl,--whole-archive /home/mt08/work/node-v4.4.5/out/Release/libopenssl.a -Wl,--no-whole-archive -Wl,-z,noexecstack -Wl,--whole-archive /home/mt08/work/node-v4.4.5/out/Release/
.
.
.
bbase.a /home/mt08/work/node-v4.4.5/out/Release/obj.target/deps/v8/tools/gyp/libv8_snapshot.a -Wl,--end-group -ldl -lrt -lm
make[1]: Leaving directory '/home/mt08/work/node-v4.4.5/out'
ln -fs out/Release/node node
real	1m33.848s
user	19m33.633s
sys	1m23.548s
[mt08@centos4 node-v4.4.5]$
```


- - -
## gcc-4.8.2環境のインストール
### Follow LFS version 7.5 (for GCC-4.8.2 and glibc-2.11.3)
- http://lfsbookja.osdn.jp/7.5.ja/index.html
- http://www.linuxfromscratch.org/lfs/view/7.5/

- LFS(Linux From Scratch)にしたがって、すなおにいれていく。
- が、glibcの新しいのは、kernel 2.6.9に対応していないので、2.11.3あたりを使う。

### ビルドの準備

```bash
# root
su - 
#
# LFS folders
export LFS=/mnt/lfs 
mkdir -vp $LFS/tools
ln -sv $LFS/tools /
#
# lfs - user
groupadd lfs
useradd -s /bin/bash -g lfs -m -k /dev/null lfs
chown -v lfs $LFS/tools
# password for lfs
passwd lfs
```

```bash
#
# Switch user to lfs
su - lfs
#
# .bash* settings
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
DIR_DEVTOOLS=/tools
PATH=${DIR_DEVTOOLS}/bin:/bin:/usr/bin
export LFS LC_ALL LFS_TGT PATH
export MAKEFLAGS='-j 4'
EOF
##
source ~/.bash_profile
#
# 
```

### Binutils-2.24 - Pass 1

```bash
export BINUTIL_VER=2.24
wget https://ftp.gnu.org/gnu/binutils/binutils-${BINUTIL_VER}.tar.bz2 --no-check-certificate
tar jxf binutils-${BINUTIL_VER}.tar.bz2
mkdir -v ./binutils-build
cd ./binutils-build
time { date > build.log ; \
../binutils-${BINUTIL_VER}/configure     \
    --prefix=${DIR_DEVTOOLS}            \
    --with-sysroot=$LFS        \
    --with-lib-path=${DIR_DEVTOOLS}/lib \
    --target=$LFS_TGT          \
    --disable-nls              \
    --disable-werror 2>&1 | tee -a ./build.log ; \
    date > build.log ; \
    make 2>&1 | tee -a ./build.log ;
    date >> ./build.log ; } 
make install
```

```shell-session
real    0m37.774s
user    1m10.186s
sys    0m27.170s
.
.
lfs:~/binutils-build$ ${DIR_DEVTOOLS}/bin/i686-lfs-linux-gnu-as --version
GNU assembler (GNU Binutils) 2.24
Copyright 2013 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `i686-lfs-linux-gnu'.
lfs:~/binutils-build$
```

### GCC-4.8.2 - Pass 1

```bash
##
cd
export GCC_VER=4.8.2
wget --no-check-certificate http://www.netgull.com/gcc/releases/gcc-${GCC_VER}/gcc-${GCC_VER}.tar.bz2
wget --no-check-certificate https://ftp.gnu.org/gnu/mpfr/mpfr-3.1.4.tar.bz2
wget --no-check-certificate https://ftp.gnu.org/gnu/gmp/gmp-5.1.3.tar.bz2
wget --no-check-certificate https://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
#
tar jxf gcc-${GCC_VER}.tar.bz2
cd gcc-${GCC_VER}
tar jxf ../mpfr-3.1.4.tar.bz2 ; mv mpfr-3.1.4 mpfr
tar jxf ../gmp-5.1.3.tar.bz2 ; mv gmp-5.1.3 gmp
tar zxf ../mpc-1.0.3.tar.gz ; mv mpc-1.0.3 mpc
#
# Patch
for file in \
 $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
  cp -uv $file{,.orig}
  sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
      -e 's@/usr@/tools@g' $file.orig > $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 $file.orig
done
#
sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure
#
## ./contrib/download_prerequisites
#
mkdir -v ../gcc-build
cd ../gcc-build
##
##
##
time { date > build.log ; \
../gcc-${GCC_VER}/configure                               \
    --target=$LFS_TGT                                \
    --prefix=${DIR_DEVTOOLS}                         \
    --with-sysroot=$LFS                              \
    --with-newlib                                    \
    --without-headers                                \
    --with-local-prefix=${DIR_DEVTOOLS}              \
    --with-native-system-header-dir=${DIR_DEVTOOLS}/include   \
    --disable-nls                                    \
    --disable-shared                                 \
    --disable-multilib                               \
    --disable-decimal-float                          \
    --disable-threads                                \
    --disable-libatomic                              \
    --disable-libgomp                                \
    --disable-libitm                                 \
    --disable-libmudflap                             \
    --disable-libquadmath                            \
    --disable-libsanitizer                           \
    --disable-libssp                                 \
    --disable-libstdc++-v3                           \
    --enable-languages=c,c++                         \
    --with-mpfr-include=$(pwd)/../gcc-${GCC_VER}/mpfr/src \
    --with-mpfr-lib=$(pwd)/mpfr/src/.libs 2>&1 | tee -a ./build.log ; \
    date > build.log ; \
    make 2>&1 | tee -a ./build.log ;
    date >> ./build.log ; } 
```

- インストール

   ```
make install
ln -sv libgcc.a `$LFS_TGT-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/'`
```

```shell-session
real    1m43.495s
user    9m47.849s
sys     1m35.760s
.
.
.
lfs:~/gcc-build$ ${DIR_DEVTOOLS}/bin/i686-lfs-linux-gnu-gcc --version
i686-lfs-linux-gnu-gcc (GCC) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```


### これはスキップ - Linux Kernel Source 

```
### root
su -
#
#
#
### Linux-Kernel
cd 
mkdir -p dev/kernel
cd dev/kernel
# ソースのダウンロード
yumdownloader --source kernel
# => CentOS 4.9:: kernel-2.6.9-103.EL.src.rpm 
sudo yum-builddep ./kernel-2.6.9-103.EL.src.rpm
## ソース解凍、ビルド
echo '%_topdir %(echo $HOME)/dev/kernel/rpmbuild' > ~/.rpmmacros
mkdir -p ./rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
rpm -i ./kernel-2.6.9-103.EL.src.rpm
cd rpmbuild/SPECS/
rpmbuild -bp --target=`uname -m` kernel-2.6.spec
cd ../BUILD/kernel-2.6.9/linux-2.6.9/
mv .config .config.org
cp /boot/config-`uname -r` ./.config
```

```shell-session
[root@centos4 linux-2.6.9]# pwd
/root/dev/kernel/rpmbuild/BUILD/kernel-2.6.9/linux-2.6.9
```

### glibc
- glibc-2.20から、Kernel 2.6.32以降 (*The minimum Linux kernel version that this version of the GNU C Library
  can be used with is 2.6.32.*)
- glibc-2.17より、Kernel 2.6.16以降 (*When working with Linux kernels, this version of the GNU C Library requires Linux kernel version 2.6.16 or later.*)
- ?? glibc-2.16.0は、kernel-2.6.9でいけるのか??


```bash`
#
#
cd
mkdir -p ${DIR_DEVTOOLS}/include
cp -rv /usr/include/* ${DIR_DEVTOOLS}/include
##
cat > glibc-2.11.3.patch << EOF
diff -uprN glibc-2.11.3.orig/nptl/sysdeps/pthread/pt-initfini.c glibc-2.11.3/nptl/sysdeps/pthread/pt-initfini.c
--- glibc-2.11.3.orig/nptl/sysdeps/pthread/pt-initfini.c	2010-11-29 18:24:32.000000000 -0800
+++ glibc-2.11.3/nptl/sysdeps/pthread/pt-initfini.c	2016-06-23 12:47:41.000000000 -0700
@@ -45,6 +45,11 @@
 /* Embed an #include to pull in the alignment and .end directives. */
 asm ("\n#include \"defs.h\"");
 
+asm ("\n#if defined __i686 && defined __ASSEMBLER__");
+asm ("\n#undef __i686");
+asm ("\n#define __i686 __i686");
+asm ("\n#endif");
+
 /* The initial common code ends here. */
 asm ("\n/*@HEADER_ENDS*/");
 
diff -uprN glibc-2.11.3.orig/sysdeps/unix/sysv/linux/i386/sysdep.h glibc-2.11.3/sysdeps/unix/sysv/linux/i386/sysdep.h
--- glibc-2.11.3.orig/sysdeps/unix/sysv/linux/i386/sysdep.h	2010-11-29 18:24:32.000000000 -0800
+++ glibc-2.11.3/sysdeps/unix/sysv/linux/i386/sysdep.h	2016-06-23 12:46:59.000000000 -0700
@@ -29,6 +29,10 @@
 #include <dl-sysdep.h>
 #include <tls.h>
 
+#if defined __i686 && defined __ASSEMBLER__
+#undef __i686
+#define __i686 __i686
+#endif
 
 /* For Linux we can use the system call table in the header file
 	/usr/include/asm/unistd.h
EOF
##
export GLIBC_VER=2.11.3
wget http://gnu.mirror.constant.com/libc/glibc-${GLIBC_VER}.tar.bz2 --no-check-certificate
tar jxf glibc-${GLIBC_VER}.tar.bz2
cd glibc-${GLIBC_VER}
patch -p1 < ../glibc-2.11.3.patch
mkdir -v ../glibc-build
cd ../glibc-build
#
#
time { date > build.log ; \
../glibc-${GLIBC_VER}/configure                             \
      --prefix=${DIR_DEVTOOLS}                      \
      --host=$LFS_TGT                               \
      --build=$(../glibc-${GLIBC_VER}/scripts/config.guess) \
      --disable-profile                             \
      --with-headers=${DIR_DEVTOOLS}/include        \
      libc_cv_forced_unwind=yes                     \
      libc_cv_ctors_header=yes                      \
      libc_cv_c_cleanup=yes 2>&1 | tee -a ./build.log ; \
    date > build.log ; \
    make PARALLELMFLAGS=-j4 2>&1 | tee -a ./build.log ;
    date >> ./build.log ; } 
```

```
make install
```

```shell-session
real	2m25.898s
user	9m52.092s
sys	1m57.351s
...
...
lfs:~/glibc-build$ ${DIR_DEVTOOLS}/lib/libc.so.6 
GNU C Library stable release version 2.11.3, by Roland McGrath et al.
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.8.2.
Compiled on a Linux 2.4.20 system on 2016-06-23.
Available extensions:
	crypt add-on version 2.1 by Michael Glad and others
	GNU Libidn by Simon Josefsson
	Native POSIX Threads Library by Ulrich Drepper et al
	BIND-8.2.3-T5B
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
```

### Libstdc++ 

```
#
cd 
#
rm -rf gcc-${GCC_VER}
tar jxf gcc-${GCC_VER}.tar.bz2
cd gcc-${GCC_VER}
tar jxf ../mpfr-3.1.4.tar.bz2 ; mv mpfr-3.1.4 mpfr
tar jxf ../gmp-5.1.3.tar.bz2 ; mv gmp-5.1.3 gmp
tar zxf ../mpc-1.0.3.tar.gz ; mv mpc-1.0.3 mpc
#
cd
mkdir -pv ./gcc-build-libstcpp
cd ./gcc-build-libstcpp
#
#
#
time { date > build.log ; \
../gcc-${GCC_VER}/libstdc++-v3/configure \
    --host=$LFS_TGT                 \
    --prefix=${DIR_DEVTOOLS}        \
    --disable-multilib              \
    --disable-shared                \
    --disable-nls                   \
    --disable-libstdcxx-threads     \
    --disable-libstdcxx-pch         \
    --with-gxx-include-dir=${DIR_DEVTOOLS}/$LFS_TGT/include/c++/${GCC_VER} 2>&1 | tee -a ./build.log ; \
    date > build.log ; \
    make -j 4 2>&1 | tee -a ./build.log ;
    date >> ./build.log ; } 
#
#
make install
```

```
real	0m25.237s
user	0m36.341s
sys	0m13.510s
```


### Binutils-2.24 - Pass 2 

```bash
#
export BINUTIL_VER=2.24
cd
#
mkdir -v ./binutils-build2
cd ./binutils-build2
#
time { date > build.log ; \
CC=$LFS_TGT-gcc                \
AR=$LFS_TGT-ar                 \
RANLIB=$LFS_TGT-ranlib         \
../binutils-${BINUTIL_VER}/configure     \
    --prefix=${DIR_DEVTOOLS}   \
    --disable-nls              \
    --with-lib-path=${DIR_DEVTOOLS}/lib \
    --with-sysroot 2>&1 | tee -a ./build.log ; \
    date > build.log ; \
    make 2>&1 | tee -a ./build.log ;
    date >> ./build.log ; } 
#
#
make install
#
make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib
cp -v ld/ld-new ${DIR_DEVTOOLS}/bin
```


```
real	0m37.294s
user	1m59.288s
sys	0m31.555s
```

### GCC-4.8.2 - Pass 2 

```
#
export GCC_VER=4.8.2
cd
rm -rf gcc-${GCC_VER}
tar jxf gcc-${GCC_VER}.tar.bz2
cd gcc-${GCC_VER}
#
cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
  `dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include-fixed/limits.h
#
case `uname -m` in
  i?86) sed -i 's/^T_CFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in ;;
esac
#
for file in \
 $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
  cp -uv $file{,.orig}
  sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
      -e 's@/usr@/tools@g' $file.orig > $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 $file.orig
done
#
tar jxf ../mpfr-3.1.4.tar.bz2 ; mv mpfr-3.1.4 mpfr
tar jxf ../gmp-5.1.3.tar.bz2 ; mv gmp-5.1.3 gmp
tar zxf ../mpc-1.0.3.tar.gz ; mv mpc-1.0.3 mpc
#
mkdir -v ../gcc-build2
cd ../gcc-build2
#
time { date > build.log ; \
CC=$LFS_TGT-gcc                                      \
CXX=$LFS_TGT-g++                                     \
AR=$LFS_TGT-ar                                       \
RANLIB=$LFS_TGT-ranlib                               \
../gcc-${GCC_VER}/configure                               \
    --prefix=${DIR_DEVTOOLS}                                  \
    --with-local-prefix=${DIR_DEVTOOLS}                       \
    --with-native-system-header-dir=${DIR_DEVTOOLS}/include   \
    --enable-clocale=gnu                             \
    --enable-shared                                  \
    --enable-threads=posix                           \
    --enable-__cxa_atexit                            \
    --enable-languages=c,c++                         \
    --disable-libstdcxx-pch                          \
    --disable-multilib                               \
    --disable-bootstrap                              \
    --disable-libgomp                                \
    --with-mpfr-include=$(pwd)/../gcc-${GCC_VER}/mpfr/src \
    --with-mpfr-lib=$(pwd)/mpfr/src/.libs 2>&1 | tee -a ./build.log ; \
    date > build.log ; \
    make 2>&1 | tee -a ./build.log ;
    date >> ./build.log ; } 
#
make install
ln -sv gcc ${DIR_DEVTOOLS}/bin/cc
```

```shell-session
real	3m12.693s
user	19m14.054s
sys	2m55.119s
.
.
lfs:~/gcc-build2$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/mnt/lfs/tools/bin/../libexec/gcc/i686-pc-linux-gnu/4.8.2/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.8.2/configure --prefix=/tools --with-local-prefix=/tools --with-native-system-header-dir=/tools/include --enable-clocale=gnu --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-languages=c,c++ --disable-libstdcxx-pch --disable-multilib --disable-bootstrap --disable-libgomp --with-mpfr-include=/home/lfs/gcc-build2/../gcc-4.8.2/mpfr/src --with-mpfr-lib=/home/lfs/gcc-build2/mpfr/src/.libs
Thread model: posix
gcc version 4.8.2 (GCC) 
lfs:~/gcc-build2$ 
```

### とりあえず
- `/tools/`固定になってるけど、一応使えるっぽい。