Solaris 10: how to build and install GCC 4


The GCC (or GNU Compiler Collection) is a free and multi-platform compiler system used as a development tool for software written in several programming languages.

In this post we will see how to install gcc on a solaris operating system, taking into account all the pre-requisites and configuration parameters strictly required, so as to elaborate a procedure suitable for both sparc and x86 platforms.

Hence, in the following paragraphs I will not go deeper into details regarding how GCC works or how it can be customized by the final user. If you need any further explanation you can read the official documentation here.


Pre-requisites

In order to build GCC on Solaris, first you need to install the following packages from the original CD/DVD (if you performed a full installation of the operating system these packages have been all already added):

  • SUNWbinutils (GNU binutils)
  • SUNWarc (Lint Libraries)
  • SUNWgcc (GNU C compiler and runtime libraries)
  • SUNWgm4 (GNU m4)
  • SUNWgmake (GNU make)
  • SUNWhea (SunOS Header Files)
  • SUNWlibmr (Math Library Lint Files)
  • SUNWlibm (Math & Microtasking Libraries Headers & Lint Files)

Then, the external pre-requisites, downloadable from Unix Packages, are as follows (must be installed with the “pkgadd -d” command):

  • libgcc-3.4.6-sol10-platform-local.gz
  • libintl-3.4.0-sol10-platform-local.gz
  • libiconv-1.14-sol10-platform-local.gz
  • tar-1.27.1-sol10-platform-local.gz
  • zlib-1.2.8-sol10-platform-local.gz
  • binutils-2.23.1-sol10-platform-local.gz
  • patch-2.7-sol10-platform-local.gz

where platform can be “sparc” or “x86”.

Furthermore, in order to build GCC (for C, C++, and Objective-C), GMP, MPFR, and MPC libraries are necessary as prerequisites (see GNU doc), so we will be forced to build all of them.

References

The installation process should be carried out with the “root” user:

# su - root

You should check your root user’s path, appending directories /usr/ccs/bin and /usr/sfw/bin at the end of the default list:

# echo $PATH
/usr/sbin:/usr/bin
# export PATH=/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/sfw/bin

In this way, the following executables will be used during building processes:

  • /usr/ccs/bin/m4
  • /usr/sfw/bin/gcc (GNU GCC 3.4.3)
  • /usr/sfw/bin/gmake (GNU Make 3.82)

Leave the library system’s path as default one:

# crle
...
Default Library Path (ELF): /lib:/usr/lib
...

Also, by typing the command:

# /usr/sfw/bin/gcc -v

you can discover which assembler and linker the system embedded gcc uses while compiling:

  • SPARC:
    • –prefix=/usr/sfw
    • –with-as=/usr/ccs/bin/as –without-gnu-as (Sun assembler)
    • –with-ld=/usr/ccs/bin/ld –without-gnu-ld (Sun linker)
    • –enable-languages=c,c++ –enable-shared
  • x86:
    • –prefix=/usr/sfw
    • –with-as=/usr/sfw/bin/gas –with-gnu-as (GNU assembler)
    • –with-ld=/usr/ccs/bin/ld  –without-gnu-ld (Sun linker)
    • –enable-languages=c,c++ –enable-shared

So, we are ready to make compilations of source codes, but first it is appropriate to mention what is the right parameter that identifies your Solaris’s architecture when configuring your build:

--build=sparc-sun-solaris2.10 (for SPARC)
--build=i386-pc-solaris2.10   (for x86)

Build GMP 6.0.0a

Create a source directory under /application/gmp-6.0.0a in which gmp’s files have to be unzipped (take care to use the GNU version of the tar command!):

# cd /application
# mkdir gmp-6.0.0a
# cd gmp-6.0.0a
# cp /tmp/gmp-6.0.0a.tar.gz .
# /usr/local/bin/tar xzvf gmp-6.0.0a.tar.gz
# mv gmp-6.0.0a src
# chown -R root:root src
# cd src

Configure the building process with desired options:

# ./configure --build=platform
              --prefix=/application/gmp-6.0.0a
...
configure: summary of build options:

  Version:           GNU MP 6.0.0
  Host type:         i386-pc-solaris2.10
  ABI:               32
  Install prefix:    /application/gmp-6.0.0a
  Compiler:          gcc -std=gnu99
  Static libraries:  yes
  Shared libraries:  yes

Launch the compiling process, installing all built files (libraries and include files will be
copied in /application/gmp-6.0.0a/lib and /application/gmp-6.0.0a/include):

# gmake install

It’s strongly advised to do a check to verify that libraries work as expected:

# gmake check

In the event that errors occur, once made the necessary corrections, the process can be repeated from the beginning before doing a clean-up:

# gmake clean

Build MPFR 3.1.2

Create a source directory under /application/mpfr-3.1.2 in which mpfr’s files have to be unzipped (take care to use the GNU version of the tar command!):

# cd /application
# mkdir mpfr-3.1.2
# cd mpfr-3.1.2
# cp /tmp/mpfr-3.1.2.tar.gz .
# /usr/local/bin/tar xzvf mpfr-3.1.2.tar.gz
# mv mpfr-3.1.2 src
# chown -R root:root src
# cd src

Then, download from the MPFR website the latest patches and apply them with “gpatch” command:

# /usr/local/bin/patch -N -Z -p1 < mpfr-3.1.2-patches.txt

This may generate a “Not setting time” warning for the patches file, but you can safely ignore it.

Take care to set the linking stage variable LDFLAGS, referring to the directory in which GMP libraries are stored:

# export LDFLAGS="-L/application/gmp-6.0.0a/lib -R/application/gmp-6.0.0a/lib"

Configure the building process with desired options:

# ./configure --build=platform
              --prefix=/application/mpfr-3.1.2
              --with-gmp=/application/gmp-6.0.0a

Make sure that the following line pops up:

“checking if gmp.h version and libgmp version are the same… (6.0.0/6.0.0) yes”

Launch the compiling process, installing all built files (libraries and includes will be copied in /application/mpfr-3.1.2/lib and /application/mpfr-3.1.2/include):

# gmake install

It’s strongly advised to do a check to verify that libraries work as expected:

# gmake check

In the event that errors occur, once made the necessary corrections, the process can be repeated from the beginning before doing a clean-up:

# gmake clean

Finally, reset any flag you exported before:

# export LDFLAGS=""

Build MPC 1.0.2

Create a source directory under /application/mpc-1.0.2 in which mpc’s files have to be unzipped (take care to use the GNU version of the tar command!):

# cd /application
# mkdir mpc-1.0.2
# cd mpc-1.0.2
# cp /tmp/mpc-1.0.2.tar.gz .
# /usr/local/bin/tar xzvf mpc-1.0.2.tar.gz
# mv mpc-1.0.2 src
# chown -R root:root src
# cd src

Take care to set the linking stage variable LDFLAGS, referring to the directory in which GMP and MPFR libraries are stored:

# export LDFLAGS="-L/application/gmp-6.0.0a/lib -R/application/gmp-6.0.0a/lib -L/application/mpfr-3.1.2/lib -R/application/mpfr-3.1.2/lib"

Configure the building process with desired options:

# ./configure --build=platform
              --prefix=/application/mpc-1.0.2
              --with-gmp=/application/gmp-6.0.0a
              --with-mpfr=/application/mpfr-3.1.2

Launch the compiling process, installing all built files (libraries will be copied in /application/mpc-1.0.2/lib):

# gmake install

It’s strongly advised to do a check to verify that libraries work as expected:

# gmake check

In the event that errors occur, once made the necessary corrections, the process can be repeated from the beginning before doing a clean-up:

# gmake clean

Finally, reset any flag you exported before:

# export LDFLAGS=""

4) Build GCC 4.9.0

Create a source directory under /application/gcc-4.9.0 in which gcc’s files have to be unzipped (take care to use the GNU version of the tar command!):

# cd /application
# mkdir gcc-4.9.0
# cd gcc-4.9.0
# cp /tmp/gcc-4.9.0.tar.gz .
# /usr/local/bin/tar xzvf gcc-4.9.0.tar.gz
# mv gcc-4.9.0 src
# chown -R root:root src
# cd src
# mkdir objdir

Then, make soft links of previous built libraries:

  • /application/gmp-6.0.0a/lib
  • /application/mpfr-3.1.2/lib
  • /application/mpc-1.0.2/lib

under /application/gcc-4.9.0/lib/math with the following commands:

# cd /application/gcc-4.9.0
# mkdir lib
# cd lib
# mkdir math
# cd math
# ln -s /application/gmp-6.0.0a/lib/libgmp.a libgmp.a
# ln -s /application/gmp-6.0.0a/lib/libgmp.la libgmp.la
# ln -s /application/gmp-6.0.0a/lib/libgmp.so libgmp.so
# ln -s /application/gmp-6.0.0a/lib/libgmp.so.10 libgmp.so.10
# ln -s /application/gmp-6.0.0a/lib/libgmp.so.10.2.0 libgmp.so.10.2.0
# ln -s /application/mpfr-3.1.2/lib/libmpfr.a libmpfr.a
# ln -s /application/mpfr-3.1.2/lib/libmpfr.la libmpfr.la
# ln -s /application/mpfr-3.1.2/lib/libmpfr.so libmpfr.so
# ln -s /application/mpfr-3.1.2/lib/libmpfr.so.4 libmpfr.so.4
# ln -s /application/mpfr-3.1.2/lib/libmpfr.so.4.1.2 libmpfr.so.4.1.2
# ln -s /application/mpc-1.0.2/lib/libmpc.a libmpc.a
# ln -s /application/mpc-1.0.2/lib/libmpc.la libmpc.la
# ln -s /application/mpc-1.0.2/lib/libmpc.so libmpc.so
# ln -s /application/mpc-1.0.2/lib/libmpc.so.3 libmpc.so.3
# ln -s /application/mpc-1.0.2/lib/libmpc.so.3.0.0 libmpc.so.3.0.0

Configure the building process with desired options (type “configure -help” to see all the available parameters and their defaults):

# cd /application/gcc-4.9.0/src/objdir
# ../configure --build=platform 
               --with-gmp=/application/gmp-6.0.0a 
               --with-mpfr=/application/mpfr-3.1.2 
               --with-mpc=/application/mpc-1.0.2 
               --with-gnu-as --with-as=/usr/local/bin/as 
               --with-gnu-ld --with-ld=/usr/local/bin/ld 
               --enable-shared 
               --disable-nls 
               --enable-languages=c,c++,objc 
               --prefix=/application/gcc-4.9.0 
               --with-stage1-ldflags="-Wl,-rpath=/application/gcc-4.9.0/lib/math,-rpath=/usr/local/lib -static-libgcc -static-libstdc++" 
               --with-boot-ldflags="-Wl,-rpath=/application/gcc-4.9.0/lib/math,-rpath=/usr/local/lib -static-libgcc -static-libstdc++"

So as to use:

  • /usr/local/bin/as (GNU assembler 2.23)
  • /usr/local/bin/ld (GNU linker 2.23)

For further information about each available flag, please read GCC doc.

Finally, launch the compiling process parallelizing the process as much as you can and, if successful, install all built files (libraries will be copied in /application/gcc-4.9.0/lib):

# gmake -j 12
# gmake install

As usually, the process can be repeated from the beginning before doing a clean-up:

# gmake distclean

After build: specs

To automatically set a runpath for gcc-4.9.0’s libgcc in every binary the new gcc produces (this is necessary when linking programs dynamically against libgcc), you must adjust the specs of the compiler. Hence, type the following:

# cd /application/gcc-4.9.0/lib/gcc/architecture/4.9.0
# /application/gcc-4.9.0/bin/gcc -dumpspecs > specs
# vi specs

where architecture can be “amd64” or “sparcv9”.

Then modify the following line from:

*libgcc:
%{static|static-libgcc:-lgcc -lgcc_eh}%{!static:%{!static-libgcc:%{!shared:%{!shared-libgcc:-lgcc -lgcc_eh}%{shared-libgcc:
-lgcc_s -lgcc}}%{shared:-lgcc_s}}}

to:

*libgcc_arch32:
%{static|static-libgcc:-lgcc -lgcc_eh}%{!static:%{!static-libgcc:%{!shared:%{!shared-libgcc:-R/application/gcc-4.9.0/lib -lgcc -lgcc_eh}%{shared-libgcc:-R/application/gcc-4.9.0/lib -lgcc_s -lgcc}}%{shared:-R/application/gcc-4.9.0/lib -lgcc_s}}}

*libgcc_arch64:
%{static|static-libgcc:-lgcc -lgcc_eh}%{!static:%{!static-libgcc:%{!shared:%{!shared-libgcc:-R/application/gcc-4.9.0/lib/architecture -lgcc -lgcc_eh}%{shared-libgcc:-R/application/gcc-4.9.0/lib/architecture -lgcc_s -lgcc}}%{shared:-R/application/gcc-4.9.0/lib/architecture -lgcc_s}}}

*libgcc:
%{m32:%(libgcc_arch32)} %{m64:%(libgcc_arch64)} %{!m32:%{!m64:%(libgcc_arch32)}}

where architecture can be “amd64” or “sparcv9”.

Test

Now, you can test your gcc executable (so as to exclude the presence of errors) simply by dumping its version and options:

# /application/gcc-4.9.0/bin/gcc --target-help -v

 

Wow, it has been a long journey but we finally nailed it! Let me give you my congratulations for your new software development environment, make good use! 😀