In some cases, it’s neccessary to use a newer GCC compiler (Homepage) than the one provided via a package-manager. OpenSolaris currently provices a GCC 3.4.3 and GCC 4.3. This guide should help you to compile GCC 4 on OpenSolaris, in this case GCC 4.6.1.
The whole software compiled in this guide will be installed in /opt/local. As I don’t run OpenSolaris on a single-core machine, I’ll use the -j switch for make to compile multithreaded.
Basics
Like in most howtos, we need some basic packages from the repository. Those are required to compile GCC and it’s dependencies.
root@test:~# pkg install wget SUNWgcc SUNWgmake SUNWxcu4 system/library/math/header-math
Packages to install: 7
Create boot environment: No
DOWNLOAD PKGS FILES XFER (MB)
Completed 7/7 2393/2393 37.1/37.1
PHASE ACTIONS
Install Phase 3215/3215
PHASE ITEMS
Package State Update Phase 7/7
Image State Update Phase 2/2
Building dependencies
The next step is to compile some dependencies of GCC. We could use OpenSolaris packages, but those are most likely outdated too.
binutils
The first part of software we will build are the binutils (Homepage). The current release is 2.21.1 and can be downloaded from here.
root@test:~# wget http://ftp.gnu.org/gnu/binutils/binutils-2.21.1.tar.gz --2011-08-05 20:54:31-- http://ftp.gnu.org/gnu/binutils/binutils-2.21.1.tar.gz Connecting to ftp.gnu.org|140.186.70.20|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 25195472 (24M) [application/x-gzip] Saving to: `binutils-2.21.1.tar.gz' 100%[==============================================>] 25,195,472 441K/s in 58s 2011-08-05 20:55:29 (427 KB/s) - `binutils-2.21.1.tar.gz' saved [25195472/25195472] root@test:~# tar xjf binutils-2.21.1.tar.gz root@test:~# cd binutils-2.21.1 root@test:~/binutils-2.21.1# ./configure --prefix=/opt/local/gnu --disable-nls checking build system type... i386-pc-solaris2.11 checking host system type... i386-pc-solaris2.11 ... root@test:~/binutils-2.21.1# gmake -j 4 && gmake install gmake[1]: Entering directory `/root/binutils-2.21.1' Configuring in ./intl ... gmake[1]: Nothing to be done for `install-target'. gmake[1]: Leaving directory `/root/binutils-2.21.1' root@test:~/binutils-2.21.1# gmake clean gmake[1]: Entering directory `/root/binutils-2.21.1' Doing clean in bfd ... root@test:~/binutils-2.21.1# cd .. root@test:~# rm -r binutils-2.21.1*
gmplib
Now we will compile three libraries, which depend on each other. The first one is gmp (Homepage) in version 5.0.2.
root@test:~# wget ftp://ftp.gmplib.org/pub/gmp-5.0.2/gmp-5.0.2.tar.bz2
--2011-08-05 22:13:01-- ftp://ftp.gmplib.org/pub/gmp-5.0.2/gmp-5.0.2.tar.bz2
=> `gmp-5.0.2.tar.bz2'
Resolving ftp.gmplib.org... 130.237.222.241
Connecting to ftp.gmplib.org|130.237.222.241|:21... #connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD (1) /pub/gmp-5.0.2 ... done.
==> SIZE gmp-5.0.2.tar.bz2 ... 2024576
==> PASV ... done. ==> RETR gmp-5.0.2.tar.bz2 ... done.
Length: 2024576 (1.9M) (unauthoritative)
100%[===============================================>] 2,024,576 195K/s in 11s
2011-08-05 22:13:13 (187 KB/s) - `gmp-5.0.2.tar.bz2' saved [2024576]
root@test:~# tar xfj gmp-5.0.2.tar.bz2
root@test:~# cd gmp-5.0.2
root@test:~/gmp-5.0.2# ./configure --prefix=/opt/local/gmp/5.0.2 \
--build=i386-pc-solaris2.11
checking build system type... i386-pc-solaris2.11
checking host system type... i386-pc-solaris2.11
...
root@test:~/gmp-5.0.2# gmake -j 4
gcc -std=gnu99 `test -f 'gen-fac_ui.c' || echo './'`gen-fac_ui.c -o gen-fac_ui
gcc -std=gnu99 `test -f 'gen-fib.c' || echo './'`gen-fib.c -o gen-fib
...
root@test:~/gmp-5.0.2# gmake install
gmake install-recursive
gmake[1]: Entering directory `/root/gmp-5.0.2'
...
root@test:~/gmp-5.0.2# gmake clean
Making clean in doc
gmake[1]: Entering directory `/root/gmp-5.0.2/doc'
...
root@test:~/gmp-5.0.2# cd ..
root@test:~# rm -r gmp-5.0.2*
root@test:~# ln -s /opt/local/gmp/5.0.2/lib/* /usr/lib/
mpfr
MPFR (Homepage) depends on GMP and is next on our list.
root@test:~# wget http://www.mpfr.org/mpfr-current/mpfr-3.0.1.tar.gz
--2011-08-05 21:09:42-- http://www.mpfr.org/mpfr-current/mpfr-3.0.1.tar.gz
Resolving www.mpfr.org... 152.81.144.6
Connecting to www.mpfr.org|152.81.144.6|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1478243 (1.4M) [application/x-gzip]
Saving to: `mpfr-3.0.1.tar.gz'
100%[================================================>] 1,478,243 412K/s in 3.7s
2011-08-05 21:09:46 (394 KB/s) - `mpfr-3.0.1.tar.gz' saved [1478243/1478243]
root@test:~# tar xfj mpfr-3.0.1.tar.gz
root@test:~# cd mpfr-3.0.1
root@test:~/mpfr-3.0.1# ./configure --prefix=/opt/local/mpfr/3.0.1 \
--build=i386-pc-solaris2.11 \
--with-gmp=/opt/local/gmp/5.0.2
checking for a BSD-compatible install... ./install-sh -c
checking whether build environment is sane... yes
...
root@test:~/mpfr-3.0.1# gmake -j 4 install
gmake install-recursive
gmake[1]: Entering directory `/root/mpfr-3.0.1'
...
root@test:~/mpfr-3.0.1# gmake clean
Making clean in tests
gmake[1]: Entering directory `/root/mpfr-3.0.1/tests'
..
root@test:~/mpfr-3.0.1# cd ..
root@test:~# rm -r mpfr-3.0.1*
root@test:~# ln -s /opt/local/mpfr/3.0.1/lib/* /usr/lib/
mpc
The final dependeny is mpc (Homepage) which depends on both GMP and MPFR. The current version is 0.9, but this one doesn’t compile on OpenSolaris. We will use 0.8.2 instead.
root@test:~# wget http://www.multiprecision.org/mpc/download/mpc-0.8.2.tar.gz --2011-08-05 21:32:50-- http://www.multiprecision.org/mpc/download/mpc-0.8.2.tar.gz Resolving www.multiprecision.org... 213.165.76.208 Connecting to www.multiprecision.org|213.165.76.208|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 548401 (536K) [application/x-tar] Saving to: `mpc-0.8.2.tar.gz' 100%[=====================================================>] 548,401 265K/s in 2.0s 2011-08-05 21:32:52 (265 KB/s) - `mpc-0.8.2.tar.gz' saved [548401/548401] root@test:~# tar xfj mpc-0.8.2.tar.gz root@test:~# cd mpc-0.8.2 root@test:~/mpc-0.8.2# ./configure --prefix=/opt/local/mpc/0.8.2 --build=i386-pc-solaris2.11 --with-gmp=/opt/local/gmp/5.0.2 --with-mpfr=/opt/local/mpfr/3.0.1 checking for a BSD-compatible install... ... root@test:~/mpc-0.8.2# gmake -j 4 install Making install in src gmake[1]: Entering directory `/root/mpc-0.8.2/src' ... root@test:~/mpc-0.8.2# gmake clean Making clean in doc gmake[1]: Entering directory `/root/mpc-0.8.2/doc' ... root@test:~/mpc-0.8.2# cd .. root@test:~# rm -r mpc-0.8.2* root@test:~# ln -s /opt/local/mpc/0.8.2/lib/* /usr/lib/
GCC
Now we can finally begin to compile GCC. The current release is 4.6.1.
root@test:~# wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-4.6.1/gcc-4.6.1.tar.gz
--2011-08-05 21:36:24-- ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-4.6.1/gcc-4.6.1.tar.gz
=> `gcc-4.6.1.tar.gz'
Resolving ftp.fu-berlin.de... 130.133.3.130
Connecting to ftp.fu-berlin.de|130.133.3.130|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD (1) /unix/languages/gcc/releases/gcc-4.6.1 ... done.
==> SIZE gcc-4.6.1.tar.gz ... 93426552
==> PASV ... done. ==> RETR gcc-4.6.1.tar.gz ... done.
Length: 93426552 (89M) (unauthoritative)
100%[=================================================>] 93,426,552 348K/s in 3m 57s
2011-08-05 21:40:21 (385 KB/s) - `gcc-4.6.1.tar.gz' saved [93426552]
root@test:~# tar xjf gcc-4.6.1.tar.gz
root@test:~# mkdir gcc-obj
root@test:~# cd gcc-obj/
root@test:~/gcc-obj# ../gcc-4.6.1/configure \
--with-gmp=/opt/local/gmp/5.0.2 \
--with-mpfr=/opt/local/mpfr/3.0.1 \
--with-mpc=/opt/local/mpc/0.8.2 \
--with-gnu-as \
--with-as=/opt/local/gnu/bin/as \
--enable-shared \
--disable-nls \
--enable-languages=c,c++,objc \
--prefix=/opt/local/gcc/4.6.1
checking build system type... i386-pc-solaris2.11
checking host system type... i386-pc-solaris2.11
...
root@test:~/gcc-obj# gmake -j 4
a lot of stuff, get a coffee...
...
root@test:~/gcc-obj# gmake install
root@test:~/gcc-obj# gmake clean
root@test:~/gcc-obj# cd ..
root@test:~/gcc-obj# rm -r gcc*
Now you have compiled your own GCC and can call it from /opt/local/gcc/4.6.1/bin.



