Wednesday, December 31, 2008
Compiling GMP and MPFR
Once you've downloaded the source tarballs from the websites listed in my previous post and expanded them in a build directory, be sure to read the README and INSTALL text file for the latest requirements and instructions for building the libraries. Both libraries use an Autotools (autoconf, automake, etc.) generated configure script to generate a Makefile for compiling. Make sure to run "./configure --help" in a terminal to see all available configure options. Both GMP and MPFR have options for building shared and static libraries. If you decide to build static-only libraries or if you think you may want to explicitly link a static library into a shared binary, make sure you put "--with-pic" in the list of configure options. Also, you may want to make sure the proper compiler is used to build the libraries by setting the environment variables for them (CC,CXX,FC,CFLAGS,etc.) as described in the "./configure --help" output.
Below are the configure options I used on an AMD Opteron cluster running CentOS 4.4:
GMP:
> ./configure --prefix=/usr/local/gmp422-mpfr231 \
--disable-shared --enable-static --with-pic \
--infodir=/usr/share/info --mandir=/usr/share/man
> make check
> su root
> make install
In this configuration for GMP, I set the installation directory with the '--prefix=/usr/local/gmp422-mpfr231' option. This allows me to keep matching versions together while retaining other version on the system. Also, I disabled building shared libraries to simplify executing on other computers the programs that link against GMP. Using the '--with-pic' option allows the static GMP library to be linked into executables that also link against shared libraries. And finally I included the '--infodir=/usr/share/info --mandir=/usr/share/man' options to install the man and info files in the proper directories for my system.
Compiling MPFR is similar to GMP with the addition of the '--with-gmp=/usr/local/gmp422-mpfr231' option to point to the location of our new GMP library:
MPFR:
> ./configure --prefix=/usr/local/gmp422-mpfr231 --with-gmp=/usr/local/gmp422-mpfr231 --with-pic --disable-shared --enable-static
> make check
> su root
> make install
Congratulation! You are now ready to bootstrap GCC-4.x.x. There are a lot of issues to cover with bootstrapping GCC so I may have to cover that in several posts.
Have a Happy New Year!
Tuesday, July 8, 2008
Bootstrapping GCC-4.x.x: Prerequisites
In this post, I will be discussing the general process of compiling GCC, along with how to obtain the necessary source code for GCC and its prerequisites.
Bootstrapping a compiler is the process of building the compiler from source code that is written in the target computing language itself with minimal external resources. Therefore, when bootstrapping GCC-4.x.x, the system must containing a working C compiler and some pre-requisite libraries.
For the GCC-4.3.x series of compilers, the pre-requisite libraries are the GNU Multi-Precision Arithmetic library (GMP-4.1+) and the Multi-Precision Floating-Point with Rounding library (MPFR-2.3.0+). Earlier version of GCC-4.x.x only required these libraries when building the GCC GFORTRAN compiler; however, in all recent GCC versions, these libraries are required for building the compiler. Many modern UNIX/Linux systems come with these libraries pre-installed, however you must be sure to check the version of the included libraries against the version requirements for the specific GCC-4.x.x compiler you desire to bootstrap. Some of the older versions of these libraries contain bugs that can adversely affect the accuracy of the resulting bootstrapped compiler. The version numbers for the preinstalled prerequisite libraries can be found in the header files, gmp.h and mpfr.h, respectively.
GCC-4.x.x is an open source compiler collection know as the Gnu Compiler Collection (GCC), whose homepage is locate at http://gcc.gnu.org. The GCC homepage contains a wealth of information straight from the developer and user community. To download the desired version of GCC, just follow the appropriate links on the GCC homepage to one of the many ftp or http mirror sites. The source code comes in the form of a compressed tarball ending in ".tar.bz2". Once the source has been downloaded to your computer, put it in a build folder with a name such as "BuildDir" and expand the tarball with the following command: "tar -xjvf gcc_tarball_name.tar.bz2".
The GMP is another opensource project, whose homepage is located at http://gmplib.org. Just following the links on the homepage to download the desired GMP source code. Move the tarball to your "BuildDir" and expand the tarball. If the tarball ends with ".tar.gz", it can be expanded with the command: "tar -xzvf source_name.tar.gz". Similarly, MPFR is also an open source project, with it's homepage located at http://www.mpfr.org. Again, follow the links to download the appropriate source, move it to your "BuildDir", and expand the tarball.
Congratulations, you now have all the necessary source code to bootstrap GCC. In my next post, I will walk you through compiling and checking both the GMP and the MPFR libraries. I will also shared some of my experiences and tips for avoiding trouble down the road.
Until next time, God Bless and Have a great day!!!