linuxbrew でgcc 4.9 をビルド&インストール

gcc 4.9が使いたかったんだけど、2014年にもなって公式サイトでtarをダウンロードとかしたくなかったんで…。

けっこうはまった。

とりあえず linuxbrew をインストール

```bash
sudo apt-get install gcc gcc-c++ autoconf
git clone https://github.com/Homebrew/linuxbrew.git ~/linuxbrew
export LD_LIBRARY_PATH=${HOME}/linuxbrew/lib:${HOME}/linuxbrew/opt/gmp4/lib:${HOME}/linuxbrew/opt/libmpc08/lib:${HOME}/linuxbrew/opt/mpfr2/lib:${HOME}/linuxbrew/opt/isl011/lib
```

gcc はhomebrew/versionsってとこにいる。

```bash
brew tap homebrew/versions
```

linuxbrewっていってもFormula自体はmac用なので下のように編集する。
~/linuxbrew/Library/Taps/homebrew-versions/ 以下にいる。

```diff
diff --git a/gcc49.rb b/gcc49.rb
index b1372d3..82b219b 100644
--- a/gcc49.rb
+++ b/gcc49.rb
@@ -37,7 +37,7 @@ class Gcc49 < Formula
   depends_on 'gmp4'
   depends_on 'libmpc08'
   depends_on 'mpfr2'
-  depends_on 'cloog018'
+  #depends_on 'cloog018'
   depends_on 'ecj' if build.include? 'enable-java' or build.include? 'enable-all-languages'

@@ -64,7 +64,7 @@ class Gcc49 < Formula
     version_suffix = version.to_s.slice(/\d\.\d/)

     args = [
-      "--build=#{arch}-apple-darwin#{osmajor}",
+      #"--build=#{arch}-apple-darwin#{osmajor}",
       "--prefix=#{prefix}",
       "--enable-languages=#{languages.join(',')}",
       # Make most executables versioned to avoid conflicts.
@@ -72,16 +72,16 @@ class Gcc49 < Formula
       "--with-gmp=#{Formula["gmp4"].opt_prefix}",
       "--with-mpfr=#{Formula["mpfr2"].opt_prefix}",
       "--with-mpc=#{Formula["libmpc08"].opt_prefix}",
-      "--with-cloog=#{Formula["cloog018"].opt_prefix}",
+      "--without-cloog,#=#{Formula["cloog018"].opt_prefix}",
       "--with-system-zlib",
       # This ensures lib, libexec, include are sandboxed so that they
       # don't wander around telling little children there is no Santa
       # Claus.
       "--enable-version-specific-runtime-libs",
       "--enable-libstdcxx-time=yes",
-      "--enable-stage1-checking",
-      "--enable-checking=release",
+      #"--enable-stage1-checking",
+      #"--enable-checking=release",
       "--enable-lto",
       # A no-op unless --HEAD is built because in head warnings will
       # raise errors. But still a good idea to include.
@@ -123,7 +123,7 @@ class Gcc49 < Formula
         # optimise all the way to 11.
         system 'make profiledbootstrap'
       else
-        system 'make bootstrap'
+        system 'make bootstrap -j3 '
       end

       # At this point `make check` could be invoked to run the testsuite. The
diff --git a/gmp4.rb b/gmp4.rb
index 99175cb..b918bf5 100644
--- a/gmp4.rb
+++ b/gmp4.rb
@@ -20,15 +20,6 @@ class Gmp4 < Formula
   def install
     args = ["--prefix=#{prefix}", "--enable-cxx"]

-    # Build 32-bit where appropriate, and help configure find 64-bit CPUs
-    if MacOS.prefer_64_bit? and not build.build_32_bit?
-      ENV.m64
-      args << "--build=x86_64-apple-darwin"
-    else
-      ENV.m32
-      args << "--host=none-apple-darwin"
-    end
-
     system "./configure", *args
     system "make"
     ENV.j1 # Doesn't install in parallel on 8-core Mac Pro
diff --git a/mpfr2.rb b/mpfr2.rb
index 918c6ef..39ea78b 100644
--- a/mpfr2.rb
+++ b/mpfr2.rb
@@ -32,14 +32,6 @@ class Mpfr2 < Formula

     # Build 32-bit where appropriate, and help configure find 64-bit CPUs
     # Note: This logic should match what the GMP formula does.
-    if MacOS.prefer_64_bit? and not build.build_32_bit?
-      ENV.m64
-      args << "--build=x86_64-apple-darwin"
-    else
-      ENV.m32
-      args << "--build=none-apple-darwin"
-    end
-
     system "./configure", *args
     system "make"
     system "make check"
```

やってることは。
* build=darwinみたいなの削除
* gccで cloog、isl を使わないようにする
* gcc のビルドが速くなるように-j3をつけてる

cloogとislは最適化にしか使われていてなくて大丈夫っぽい。

先に、依存関係のあるライブラリをインストール

```bash
brew install gmp4 mpfr2 libmpc08 isl011
```
インストールしたライブラリの場所にLD_LIBRARY_PATHをセットする

```bash
export LD_LIBRARY_PATH=${HOME}/linuxbrew/lib:${HOME}/linuxbrew/opt/gmp4/lib:${HOME}/linuxbrew/opt/libmpc08/lib:${HOME}/linuxbrew/opt/mpfr2/lib:${HOME}/linuxbrew/opt/isl011/lib
```

やっと、gcc のインストール。かなり長い。

```bash
brew install gcc49 --disable-multilib 
```

コンパイルはこんな感じ。libgcc_s だけ解決してくれんかった。

```bash
g++-4.9 -L${HOME}/linuxbrew/lib/gcc/x86_64-unknown-linux-gnu/lib64 hello.cpp
```