Thursday, June 13, 2013

Building GCC 4.8.1 on CentOS 5.9

References:

Build:

  1. Install packages for dependencies (readline-devel is needed for guile build, dejagnu is needed for gcc make check)
    sudo yum install readline readline-devel guile guile-devel dejagnu expect
    sudo yum -y install readline readline-devel guile guile-devel dejagnu expect
    
  2. Download and untar all the sources
    mkdir -p ~/sources/gcc
    cd ~/sources/gcc
    
    gccver=4.8.1
    gmpver=5.1.2
    mpfrver=3.1.2
    mpcver=1.0.1
    binutilsver=2.23.2
    libtoolver=2.4.2
    libunistringver=0.9.3
    libffiver=3.0.13
    gcver=7.2d
    autogenver=5.17.4
    guilever=2.0.9
    prefixroot=/share/apps/tools
    
    wget http://www.netgull.com/gcc/releases/gcc-4.8.1/gcc-${gccver}.tar.bz2
    wget ftp://ftp.gnu.org/gnu/gmp/gmp-${gmpver}.tar.bz2
    wget http://mpfr.loria.fr/mpfr-current/mpfr-${mpfrver}.tar.bz2
    wget http://www.multiprecision.org/mpc/download/mpc-${mpcver}.tar.gz
    wget http://ftp.gnu.org/gnu/binutils/binutils-${binutilsver}.tar.bz2
    wget http://mirror.sbb.rs/gnu/libtool/libtool-${libtoolver}.tar.gz
    wget http://ftp.gnu.org/gnu/libunistring/libunistring-${libunistringver}.tar.gz
    wget ftp://sourceware.org/pub/libffi/libffi-${libffiver}.tar.gz
    wget http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gc-${gcver}.tar.gz
    wget http://ftp.gnu.org/gnu/autogen/rel5.17.4/autogen-${autogenver}.tar.gz
    wget ftp://ftp.gnu.org/gnu/guile/guile-${guilever}.tar.gz
    
    for file in *.{gz,bz2}; do echo tar xf $file; done
    
    for dir in `find . -maxdepth 1 -type d | grep -v ^.$ | cut -d \/ -f2` ; do
      app=$(echo $dir | cut -f1 -d-);
      ver=$(echo $dir | cut -f2 -d-);
      mkdir -p ${prefixroot}/${app}/${ver} ;
    done
    
    mv gc-7.2 gc-7.2d
    
  3. Build gmp
    cd gmp-${gmpver}
    mkdir build
    cd build
    .././configure --prefix=${prefixroot}/gmp/${gmpver}
    make
    make check
    make install
    
    EXAMPLE OUTPUT
    ================================================
      Version:           GNU MP 5.1.2
      Host type:         coreisbr-unknown-linux-gnu
      ABI:               64
      Install prefix:    /share/apps/tools/gmp/5.1.2
      Compiler:          gcc -std=gnu99
      Static libraries:  yes
      Shared libraries:  yes
    
    
    Libraries have been installed in:
       /share/apps/gcc/gmp/5.1.2/lib
    
    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the `-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the `LD_RUN_PATH' environment variable
         during linking
       - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to `/etc/ld.so.conf'
    
    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    
    4. Build mpfr
    cd ../../mpfr-${mpfrver}
    mkdir build
    cd build
    .././configure --prefix=${prefixroot}/mpfr/${mpfrver} \
      --with-gmp=${prefixroot}/gmp/${gmpver}
    make
    make check
    make install
    
    EXAMPLE OUTPUT
    ================================================
    Libraries have been installed in:
       /share/apps/gcc/mpfr/3.1.2/lib
    
    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the `-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the `LD_RUN_PATH' environment variable
         during linking
       - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to `/etc/ld.so.conf'
    
    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    
  4. Build mpc
    cd ../../mpc-${mpcver}
    mkdir build
    cd build
    .././configure --prefix=${prefixroot}/mpc/${mpcver} \
      --with-gmp=${prefixroot}/gmp/${gmpver} \
      --with-mpfr=${prefixroot}/mpfr/${mpfrver}
    make
    make check
    make install
    
    EXAMPLE OUTPUT
    ================================================
    Libraries have been installed in:
       /share/apps/gcc/mpc/1.0.1/lib
    
    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the `-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the `LD_RUN_PATH' environment variable
         during linking
       - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to `/etc/ld.so.conf'
    
    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    
  5. Build Binutils
    cd ../../binutils-${binutilsver}
    mkdir build
    cd build
    .././configure --prefix=${prefixroot}/binutils/${binutilsver}
    make
    make check
    make install
    
  6. Build libtool (make check runs for quite a while, upwards of an hour. Runs 126 tests.)
    cd ../../libtool-${libtoolver}
    mkdir build
    cd build
    .././configure --prefix=${prefixroot}/libtool/${libtoolver}
    make
    make check
    make install
    
    EXAMPLE OUTPUT
    ================================================
    ## ------------- ##
    ## Test results. ##
    ## ------------- ##
    
    105 tests behaved as expected.
    21 tests were skipped.
    
  7. Build libunistring
    cd ../../libunistring-${libunistringver}
    mkdir build
    cd build
    .././configure --prefix=${prefixroot}/libunistring/${libunistringver}
    make
    make check
    make install
    
  8. Build libffi
    cd ../../libffi-${libffiver}
    mkdir build
    cd build
    .././configure --prefix=${prefixroot}/libffi/${libffiver}
    make
    make check
    make install
    
    cd ${prefixroot}/libffi/${libffiver}
    ln -s lib/libffi-${libffiver}/include
    cd -
    
    EXAMPLE OUTPUT
    ================================================
    Libraries have been installed in:
       /share/apps/tools/libffi/3.0.13/lib/../lib64
    
    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the `-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the `LD_RUN_PATH' environment variable
         during linking
       - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to `/etc/ld.so.conf'
    
    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    
  9. Build gc
    cd ../../gc-${gcver}
    mkdir build
    cd build
    .././configure --prefix=${prefixroot}/gc/${gcver}
    make
    make check
    make install
    
    EXAMPLE OUTPUT
    ================================================
    Libraries have been installed in:
       /share/apps/tools/gc/7.2d/lib
    
    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the `-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the `LD_RUN_PATH' environment variable
         during linking
       - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to `/etc/ld.so.conf'
    
    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    
  10. Build guile. This keeps blowing up with the error following the code. CentOS base repo actually has the guile and guile-devel packages that are new enough to support autogen, so I used the package instead. Leaving this step for future reference.
    cd ../../guile-${guilever}
    mkdir build
    cd build
    .././configure --prefix=${prefixroot}/guile/${guilever} \
       --with-libltdl-prefix=${prefixroot}/libtool/${libtoolver} \
       --with-libgmp-prefix=${prefixroot}/gmp/${gmpver} \
       --with-libunistring-prefix=${prefixroot}/libunistring/${libunistringver} \
       LDFLAGS="-L${prefixroot}/libtool/${libtoolver}/lib -L${prefixroot}/gmp/${gmpver}/lib -L${prefixroot}/libunistring/${libunistringver}/lib -L${prefixroot}/libffi/${libffiver}/lib -L${prefixroot}/gc/${gcver}/lib" \
       CPPFLAGS="-I${prefixroot}/libtool/${libtoolver}/include -I${prefixroot}/libtool/${libtoolver}/include/libltdl -I${prefixroot}/libffi/${libffiver}/include -I${prefixroot}/gc/${gcver}/include -I${prefixroot}/gmp/${gmpver}/include" \
       LIBFFI_CFLAGS=-I${prefixroot}/libffi/${libffiver}/include \
       LIBFFI_LIBS=-L${prefixroot}/libffi/${libffiver}/lib \
       BDW_GC_CFLAGS=-I${prefixroot}/gc/${gcver}/include \
       BDW_GC_LIBS=-L${prefixroot}/gc/${gcver}/lib
    make
    make check
    make install
    
    EXAMPLE OUTPUT
    ================================================
    make[1]: Entering directory `/home/mhanby/sources/gcc/guile-2.0.9/build'
    Making all in lib
    make[2]: Entering directory `/home/mhanby/sources/gcc/guile-2.0.9/build/lib'
    make  all-recursive
    make[3]: Entering directory `/home/mhanby/sources/gcc/guile-2.0.9/build/lib'
    make[4]: Entering directory `/home/mhanby/sources/gcc/guile-2.0.9/build/lib'
    make[4]: Nothing to be done for `all-am'.
    make[4]: Leaving directory `/home/mhanby/sources/gcc/guile-2.0.9/build/lib'
    make[3]: Leaving directory `/home/mhanby/sources/gcc/guile-2.0.9/build/lib'
    make[2]: Leaving directory `/home/mhanby/sources/gcc/guile-2.0.9/build/lib'
    Making all in meta
    make[2]: Entering directory `/home/mhanby/sources/gcc/guile-2.0.9/build/meta'
    make[2]: Nothing to be done for `all'.
    make[2]: Leaving directory `/home/mhanby/sources/gcc/guile-2.0.9/build/meta'
    Making all in libguile
    make[2]: Entering directory `/home/mhanby/sources/gcc/guile-2.0.9/build/libguile'
    make  all-am
    make[3]: Entering directory `/home/mhanby/sources/gcc/guile-2.0.9/build/libguile'
      CC       libguile_2.0_la-finalizers.lo
    ../.././libguile/finalizers.c:167: error: static declaration of 'GC_set_finalizer_notifier' follows non-static declaration
    /share/apps/tools/gc/7.2d/include/gc/gc.h:177: error: previous declaration of 'GC_set_finalizer_notifier' was here
    make[3]: *** [libguile_2.0_la-finalizers.lo] Error 1
    make[3]: Leaving directory `/home/mhanby/sources/gcc/guile-2.0.9/build/libguile'
    make[2]: *** [all] Error 2
    make[2]: Leaving directory `/home/mhanby/sources/gcc/guile-2.0.9/build/libguile'
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/home/mhanby/sources/gcc/guile-2.0.9/build'
    make: *** [all] Error 2
    
  11. Build autogen
    cd ../../autogen-${autogenver}
    mkdir build
    cd build
    .././configure --prefix=${prefixroot}/autogen/${autogenver}
    make
    make check
    make install
    
    EXAMPLE OUTPUT
    ================================================
    ------------------------------------------------------------------------
    Configuration:
    
      Source code location:   ../.
      Compiler:               gcc -std=gnu99
      Compiler flags:         -g -O2
      Host System Type:       x86_64-unknown-linux-gnu
      Install path:           /share/apps/tools/autogen/5.17.4
    
      See config.h for further configuration information.
    ------------------------------------------------------------------------
    
    Libraries have been installed in:
       /share/apps/tools/autogen/5.17.4/lib
    
    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the `-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the `LD_RUN_PATH' environment variable
         during linking
       - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to `/etc/ld.so.conf'
    
    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    
  12. Build gcc (make took approximately 2.5 hours to run on a system with a 2.7GHz Intel Xeon E5-2680, make check took about 3 hours)
    cd ../../gcc-${gccver}
    mkdir build
    cd build
    
    OLD_LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
    export LD_LIBRARY_PATH=${prefixroot}/gmp/${gmpver}/lib:${prefixroot}/mpc/${mpcver}/lib:${prefixroot}/mpfr/${mpfrver}/lib:${LD_LIBRARY_PATH}
    
    .././configure \
      --prefix=${prefixroot}/gcc/${gccver} \
      --with-gmp=${prefixroot}/gmp/${gmpver} \
      --with-mpfr=${prefixroot}/mpfr/${mpfrver} \
      --with-mpc=${prefixroot}/mpc/${mpcver} \
      LD_FOR_TARGET=ld \
      AS_FOR_TARGET=as \
      --with-ld=${prefixroot}/binutils/${binutilsver}/bin/ld \
      --with-as=${prefixroot}/binutils/${binutilsver}/bin/as \
      --with-ar=${prefixroot}/binutils/${binutilsver}/bin/ar \
      AR_FOR_TARGET=ar
    
    time make
    
    #real 150m4.427s
    #user 101m21.408s
    #sys 12m54.047s
    
    OLD_PATH=${PATH}
    export PATH=/share/apps/tools/autogen/5.17.4/bin:${PATH}
    time make -k check
    make install
    
    export PATH=${OLD_PATH}
    export LD_LIBRARY_PATH=${OLD_LD_LIBRARY_PATH}
    
    EXAMPLE OUTPUT
    ================================================
    ----------------------------------------------------------------------
    Libraries have been installed in:
       /share/apps/tools/gcc/4.8.1/lib/../lib
    
    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the `-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the `LD_RUN_PATH' environment variable
         during linking
       - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to `/etc/ld.so.conf'
    
    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    ----------------------------------------------------------------------
    
    ----------------------------------------------------------------------
    Libraries have been installed in:
       /share/apps/tools/gcc/4.8.1/lib/../lib64
    
    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the `-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the `LD_RUN_PATH' environment variable
         during linking
       - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to `/etc/ld.so.conf'
    
    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    ----------------------------------------------------------------------
    
  13. Create the module file (for Environment Modules support)
    #%Module1.0####################################################################
    ##
    ## mymodule modulefile
    ##
    ## Sets up the 4.8.1 GCC compilation environment
    ##
    set ver [lrange [split [ module-info name ] / ] 1 1 ]
    set name [lrange [split [ module-info name ] / ] 0 0 ]
    set loading [module-info mode load]
    set subname [lrange [split $name - ] 0 0 ]
    
    proc ModulesHelp { } {
      puts stderr "\tThis module sets the environment for $name v$ver"
    }
    
    module-whatis   "Set environment variables to use $name version $ver"
    
    conflict compiler
    
    set base /share/apps/tools
    set gccdir $base/$subname/$ver
    set binutilsdir $base/binutils/2.23.2
    set gmpdir $base/gmp/5.1.2
    set mpcdir $base/mpc/1.0.1
    set mpfrdir $base/mpfr/3.1.2
    
    ## Add bin directories to the path
    prepend-path PATH $gccdir/bin
    prepend-path PATH $binutilsdir/bin
    
    prepend-path LD_LIBRARY_PATH $mpfrdir/lib
    prepend-path LD_LIBRARY_PATH $mpcdir/lib
    prepend-path LD_LIBRARY_PATH $gmpdir/lib
    prepend-path LD_LIBRARY_PATH $binutilsdir/lib
    prepend-path LD_LIBRARY_PATH $binutilsdir/lib64
    prepend-path LD_LIBRARY_PATH $gccdir/lib
    prepend-path LD_LIBRARY_PATH $gccdir/lib64
    
    prepend-path MANPATH $gccdir/share/man
    prepend-path C_INCLUDE_PATH $gccdir/include
    prepend-path CPLUS_INCLUDE_PATH $gccdir/include
    
    setenv CC $gccdir/bin/gcc
    setenv CXX $gccdir/bin/g++
    setenv FC $gccdir/bin/gfortran
    
    if { [ module-info mode load ] } {
      puts stderr "Note: $name $ver environment loaded."
    }