Home

Installing the GNU Compiler Collection from Source on a Heroku Dyno

This is Part 1 of a set of posts on how to hack together a buildpack for Heroku that runs GNU Octave, the open-source Matlab clone that can solve and simulate medium-scale dynamic macroeconomic models. I’m starting with a Heroku app that runs node.js, and all the terminal commands I list here are run in a one-off web dyno that I accessed via heroku run bash.

Prerequisites

The GNU Compiler Collection (GCC) actually comes loaded on a Heroku web dyno out of the box, but as far as I can tell it comes without a Fortran compiler (which is required to build Octave). The full list of prerequisites can be found here, but the three that we’ll need to install are

These are actually pretty easy. They can all be downloaded from the GNU FTP archive, and they all have straightforward installation procedures.

The order in which these packages are installed does matter. GMP can be installed by itself, but MPFR must be compiled with GMP, and MPC must be compiled with GMP and MPFR.

GMP

Download the GMP tarball from the GNU archive and unzip it into a build folder. Make a directory in /app/.heroku/ where the installed files will live. Tell the configure script where the install directory is, then configure, make, and install.

~/.heroku $ curl ftp://ftp.gnu.org/gnu/gmp/gmp-5.1.3.tar.bz2 -s -O
~/.heroku $ tar -xjf gmp-5.1.3.tar.bz2
~/.heroku $ mkdir gmp
~/.heroku $ cd gmp-5.1.3
~/.heroku/gmp-5.1.3 $ ./configure --prefix=/app/.heroku/gmp
~/.heroku/gmp-5.1.3 $ make && make install

Lastly, we need to add the lib directory to the LD_LIBRARY_PATH. The easiest way to do this is navigate to the lib directory and add that directly to the LD_LIBRARY_PATH using $PWD.

~/.heroku/gmp-5.1.3 $ cd ../gmp/lib
~/.heroku/gmp/lib $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD

MPFR

We can install MPFR with the same procedure that we used for GMP. The only difference is that we need to point the configure script to the GMP install directory.

~/.heroku $ curl ftp://ftp.gnu.org/gnu/mpfr/mpfr-3.1.2.tar.xz -s -O
~/.heroku $ tar -xf mpfr-3.1.2.tar.xz
~/.heroku $ mkdir mpfr
~/.heroku $ cd mpfr-3.1.2
~/.heroku/mpfr-3.1.2 $ ./configure --prefix=/app/.heroku/mpfr --with-gmp=/app/.heroku/gmp
~/.heroku/mpfr-3.1.2 $ make && make install

Once again, add the lib directory to the LD_LIBRARY_PATH

~/.heroku/mpfr-3.1.2 $ cd ../mpfr/lib
~/.heroku/mpfr/lib $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD

MPC

Repeat for MPC. We need to tell the configure script where GMP and MPFR are installed.

~/.heroku $ curl ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.2.tar.gz -s -O
~/.heroku $ tar -xzf mpc-1.0.2.tar.gz
~/.heroku $ mkdir mpc
~/.heroku $ cd mpc-1.0.2
~/.heroku/mpc-1.0.2 $ ./configure --prefix=/app/.heroku/mpc --with-gmp=/app/.heroku/gmp --with-mpfr=/app/.heroku/mpfr
~/.heroku/mpc-1.0.2 $ make && make install

Again, add the lib directory to the LD_LIBRARY_PATH

~/.heroku/mpc-1.0.2 $ cd ../mpc/lib
~/.heroku/mpc/lib $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD

Installing GCC

Now we’re ready to install GCC. It follows more or less the same procedure. Normally, GCC will look for GMP, MPC, and MPFR in /usr/bin/ or some similar directory, but since we have these installed in a non-standard location, we will have to tell GCC’s configure script where they are. We can do this by passing arguments to the configure script that list the install directories we used in the previous steps.

The option –disable-multilib is oddly named, but it tells the configure script that we only want a 64-bit compiler (not a 32-bit compiler).

Running the configure script will take a few minutes, but running the make script will take a few hours (around 4, I think), so get it going and then go get a cup of coffee or read a book or something.

~/.heroku $ curl ftp://ftp.gnu.org/gnu/gcc/gcc-4.9.2/gcc-4.9.2.tar.gz -s -O
~/.heroku $ tar -xzf gcc-4.9.2.tar.gz
~/.heroku $ mkdir gcc
~/.heroku $ cd gcc-4.9.2
~/.heroku/gcc-4.9.2 $ ./configure --prefix=/app/.heroku/gcc --with-gmp=/app/.heroku/gmp/ --with-mpfr=/app/.heroku/mpfr/ --with-mpc=/app/.heroku/mpc/ --disable-multilib
~/.heroku/gcc-4.9.2 $ make && make install

This time, we need to add the lib64 directory to the LD_LIBRARY_PATH

~/.heroku/gcc-4.9.2 $ cd ../gcc/lib64
~/.heroku/gcc/lib64 $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD

Now GCC is ready for us to use to install Octave from source.


Discussion