Build GCC 7 on Solaris 11.3

GCCが7まで出てることにちょっと驚愕しつつ、なんとなくSolarisコンパイルしてみたメモです。 Solarisを使っているとコンパイルが趣味になりがちです。

GCC, the GNU Compiler Collection - GNU Project - Free Software Foundation (FSF)

環境

$ uname -a
SunOS mercury 5.11 11.3 i86pc i386 i86pc Solaris
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/gcc/4.5/lib/gcc/i386-pc-solaris2.11/4.5.2/lto-wrapper
Target: i386-pc-solaris2.11
Configured with: /builds/hudson/workspace/nightly-update/build/i386/components/gcc45/gcc-4.5.2/configure CC=/ws/on11update-tools/SUNWspro/sunstudio12.1/bin/cc CXX=/ws/on11update-tools/SUNWspro/sunstudio12.1/bin/CC --prefix=/usr/gcc/4.5 --mandir=/usr/gcc/4.5/share/man --bindir=/usr/gcc/4.5/bin --libdir=/usr/gcc/4.5/lib --sbindir=/usr/gcc/4.5/sbin --infodir=/usr/gcc/4.5/share/info --libexecdir=/usr/gcc/4.5/lib --enable-languages=c,c++,fortran,objc --enable-shared --with-gmp-include=/usr/include/gmp --with-mpfr-include=/usr/include/mpfr --without-gnu-ld --with-ld=/usr/bin/ld --with-gnu-as --with-as=/usr/gnu/bin/as CFLAGS='-g -O2 '
Thread model: posix
gcc version 4.5.2 (GCC)

ダウンロード・展開

$ wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-7.2.0/gcc-7.2.0.tar.xz
...
$ tar Jxvf gcc-7.2.0.tar.xz
...
$ cd gcc-7.2.0
...

依存ライブラリ(gmp, mpfr, mpc, isl)のダウンロード

$ contrib/download_prerequisites
...

configure

$ ./configure \
  --prefix=/opt/gcc7 \
  --enable-languages=c,c++ \
  --enable-shared \
  --disable-bootstrap \
  --without-gnu-ld --with-ld=/usr/bin/ld \
  --with-gnu-as --with-as=/usr/gnu/bin/as \
  CC='gcc -m64' CXX='g++ -m64'

オプションはあんまりちゃんと吟味してませんが、なんとなくOS付属のgccを参考にしました。

make

$ gmake -j8
...
$ sudo gmake install
...

/opt/gcc7 配下にインストールされます。

$ /opt/gcc7/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/opt/gcc7/bin/gcc
COLLECT_LTO_WRAPPER=/opt/gcc7/libexec/gcc/x86_64-pc-solaris2.11/7.2.0/lto-wrapper
Target: x86_64-pc-solaris2.11
Configured with: ./configure --prefix=/opt/gcc7 --enable-languages=c,c++ --enable-shared --disable-bootstrap --without-gnu-ld --with-ld=/usr/bin/ld --with-gnu-as --with-as=/usr/gnu/bin/as CC='gcc -m64' CXX='g++ -m64'
Thread model: posix
gcc version 7.2.0 (GCC)