Previous: , Up: MPRIA Basics   [Index]


4.8 Autoconf

For applications using autoconf and its friends, the macro mpria_AM_PATH_MPRIA available in the file mpria.m4 can be employed to link with the MPRIA automatically from the configure script. As preliminary work, this macro checks whether MPRIA is properly installed and performs compatibility test against either a specified version of the library or a default workable version of a recent major release of the library. To use this macro simply add the following line to the configure.ac autoconf input file:

mpria_AM_PATH_MPRIA([MPRIA_VERSION], [action-if-found], [action-if-not-found])

where the arguments are optional. The first argument MPRIA_VERSION should be either the one digit version number MAJOR, the two digit dotted version number MAJOR.MINOR or the three digit dotted version number MAJOR.MINOR.MICRO of the required release of the GNU MPRIA library. While action-if-found might be worthily empty or :, a suitable choice for action-if-not-found is

AC_MSG_ERROR([no suitable GNU MPRIA library found])

Then the variables MPRIA_CPPFLAGS, MPRIA_CFLAGS, MPRIA_LDFLAGS and MPRIA_LIBS can be added to the Makefile.am automake input files to obtain the correct preprocessor, compiler and linker flags. For example:

libfoo_la_CPPFLAGS = $(MPRIA_CPPFLAGS) $(GMP_CPPFLAGS)
libfoo_la_CFLAGS = $(MPRIA_CFLAGS) $(GMP_CFLAGS)
libfoo_la_SOURCES = foo-dim.c foo-dam.c foo-dom.c
libfoo_la_LDFLAGS = $(MPRIA_LDFLAGS) $(GMP_LDFLAGS)
libfoo_la_LIBADD = $(MPRIA_LIBS) $(GMP_LIBS) $(LIBM)

Note that the macro mpria_AM_PATH_MPRIA requires the macro mpria_AM_PATH_GMP which is provided in the file mpria_ax_prog_path_gmp_cc.m4; as you have already guessed, the macro mpria_AM_PATH_GMP is for the GNU MP library what the macro mpria_AM_PATH_MPRIA is for the GNU MPRIA library. So, in the configure.ac file, the macro mpria_AM_PATH_GMP must precede the macro mpria_AM_PATH_MPRIA. In the previous example, the variables GMP_CPPFLAGS, GMP_CFLAGS, GMP_LDFLAGS and GMP_LIBS are furnished by the macro mpria_AM_PATH_GMP; the variable LIBM being set up by the Libtool macro LT_LIB_M.

For building more closely to the GNU MP library built, further tweaks are required. The main difficulty is to grab and use at proper time the compiler information stored at GNU MP build-time in the two macros __GMP_CC and __GMP_CFLAGS, which are defined in the header file gmp.h. Ideally this information should be first obtained with the help of a C PreProcessor (CPP) in such a way that the C Compiler (CC) could be then set up accordingly. Unfortunately, at the time of writing, the only ready-to-use autoconf macro meant to set up the C preprocessor to be employed, that is to say AC_PROG_CPP, depends to do so on the autoconf macro AC_PROG_CC, which determines with no easy comeback the C compiler to be employed: in short, the difficulty is harder than expected. As a matter of fact, the file mpria_ax_prog_path_gmp_cc.m4 contains a bunch of macros that allows to overcome the issue in a transparent way for the final developer: the macro mpria_AC_PROG_GMP_CC have to be used instead of the macro AC_PROG_CC. Typically the configure.ac file may so contain something similar to the following scrap of code:

dnl Setup CC and CFLAGS wrt GMP:
mpria_AC_PROG_GMP_CC

dnl Checks for libraries:
dnl  the math library:
LT_LIB_M
dnl  the GMP libray:
mpria_AM_PATH_GMP([5.1.3])
dnl  the GNU MPRIA library:
mpria_AM_PATH_MPRIA([0.7.1])

Besides, the usage of mpria_AC_PROG_GMP_CC reinforces the checks done by mpria_AM_PATH_GMP. To allow code readability improvement, the two latter macros have been combined into the single macro mpria_AC_PROG_PATH_GMP_CC. The above scrap of code can thus be rewritten as follows:

dnl Setup CC and CFLAGS wrt GMP:
mpria_AC_PROG_PATH_GMP_CC([5.1.3])

dnl Checks for libraries:
dnl  the math library:
LT_LIB_M
dnl  the GNU MPRIA library:
mpria_AM_PATH_MPRIA([0.7.1])

Last but not least, non-standard installation locations of the MPRIA and GMP libraries are handled with respect to customary use; in particular, command line options are implemented in the configure script to specify these locations. The macro mpria_AM_PATH_MPRIA affords the following command line options which accept an absolute path as compulsory argument:

The macros mpria_AC_PROG_GMP_CC, mpria_AM_PATH_GMP and mpria_AC_PROG_PATH_GMP_CC implement command line options that have exactly the same usage but for the GMP library instead: --with-gmp-prefix, --with-gmp-include and --with-gmp-lib, respectively. In addition, these macros declare the environment variable GMP_GPP as precious: this advanced feature enables to specify a Generic PreProcessor command for early processing of the header file gmp.h.


Previous: , Up: MPRIA Basics   [Index]