Building gcc-4.5.2 on Solaris 10

2010-12-28

In order to compile certain more recent programs, Solaris 10's default GCC is often too old. Thankfully, GCC 4 compiles without any problems on Solaris 10, so it is only a matter of hours to build a newer one.

At the same time, it is advisable to use a newer GNU assembler than /usr/sfw/bin/gas, which is 2.15. This is useful e. g. to build x264 with SSSE3 optimizations on x86. (The example here focuses on x86, but see notes on SPARC below!)

Thus, the first step is to obtain newer GNU binutils (I used 2.21) and build them like so – using the default gcc-3.4.3 and gmake-3.80 – assuming /usr/local/dist/gnu should be the installation path:

CC=gcc ./configure --prefix=/usr/local/dist/gnu --disable-nls
gmake install

The new as binary is then in /usr/local/dist/gnu/i386-pc-solaris2.10/bin/.

To actually build GCC (for C, C++, and Objective-C), GMP, MPFR, and MPC are necessary as prerequisites – see http://gcc.gnu.org/install/prerequisites.html. The gcc binary that will be built is a 32 bit ELF which can then build 32 and 64 bit targets alike.

/usr/local/dist/gcc-4.5.2 is assumed as target directory.

# To build everything, I use Solaris 10 x86's original gcc-3.4.3.

# As hinted on http://gcc.gnu.org/install/specific.html, GMP/MPFR/MPC
# have to be configured with the target triplet as obtained from
# GCC's ./config.guess.

wget ftp://ftp.gmplib.org/pub/gmp-4.3.2/gmp-4.3.2.tar.bz2
wget http://www.mpfr.org/mpfr-current/mpfr-3.0.0.tar.bz2
wget http://www.multiprecision.org/mpc/download/mpc-0.8.2.tar.gz
wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/\
gcc-4.5.2/gcc-4.5.2.tar.bz2

gtar xjf gmp-4.3.2.tar.bz2
cd gmp-4.3.2/
./configure --prefix=/usr/local/dist/gcc-4.5.2 \
    --build=i386-pc-solaris2.10
gmake install
gmake clean
cd ..

gtar xjf mpfr-3.0.0.tar.bz2
cd mpfr-3.0.0
./configure --prefix=/usr/local/dist/gcc-4.5.2 \
    --with-gmp=/usr/local/dist/gcc-4.5.2 \
    --build=i386-pc-solaris2.10
gmake install
gmake clean
cd ..

gtar xzf mpc-0.8.2.tar.gz
cd mpc-0.8.2
./configure --prefix=/usr/local/dist/gcc-4.5.2 \
    --with-gmp=/usr/local/dist/gcc-4.5.2 \
    --with-mpfr=/usr/local/dist/gcc-4.5.2 \
    --build=i386-pc-solaris2.10
gmake install
gmake clean
cd ..

# --with-boot-ldflags can be used to provide the cc1/cc1plus binaries
# with the correct RPATH to GMP/MPFR/MPC. Note that when this flag
# is specified, its default value must be repeated if necessary.
# According to http://gcc.gnu.org/install/configure.html,
# this would be '-static-libstdc++ -static-libgcc', meaning the build 
# below would use dynamic linking for libgcc. This is no problem.
gtar xjf gcc-4.5.2.tar.bz2
mkdir gcc-obj
cd gcc-obj
../gcc-4.5.2/configure \
    --with-gmp=/usr/local/dist/gcc-4.5.2 \
    --with-mpfr=/usr/local/dist/gcc-4.5.2 \
    --with-mpc=/usr/local/dist/gcc-4.5.2 \
    --with-gnu-as \
    --with-as=/usr/local/dist/gnu/i386-pc-solaris2.10/bin/as \
    --with-ld=/usr/ccs/bin/ld \
    --enable-shared \
    --disable-nls \
    --enable-languages=c,c++,objc \
    --prefix=/usr/local/dist/gcc-4.5.2 \
    --with-boot-ldflags='-R/usr/local/dist/gcc-4.5.2/lib'
LD_LIBRARY_PATH=/usr/local/dist/gcc-4.5.2/lib gmake
gmake install
gmake clean

Things to do after the build:

Notes for building gcc-4.5.2 on SPARC