makefileautotoolsautoconfgnulib

autoconf: how do I substitute the library prefix?


CLISP's interface to PARI is configured with the configure.in containing AC_LIB_LINKFLAGS([pari]) from lib-link.m4.

The build process also requires the Makefile to know where the datadir of PARI is located. To this end, Makefile.in has

prefix = @LIBPARI_PREFIX@
DATADIR = @datadir@

and expects to find $(DATADIR)/pari/pari.desc (normally /usr/share/pari/pari.desc or /usr/local/share/pari/pari.desc).

This seems to work on Mac OS X where PARI is installed by homebrew in /usr/local (and LIBPARI_PREFIX=/usr/local), but not on Ubuntu, where PARI is in /usr, and LIBPARI_PREFIX is empty.

How do I insert the location of the PARI's datadir into the Makefile?

PS. I also asked this on the autoconf mailing list.

PPS. In response to @BrunoHaible's suggestion, here is the meager attempt at debugging on Linux (where LIBPARI_PREFIX is empty).

$ bash -x configure 2>&1 | grep found_dir
+ found_dir=
+ eval ac_val=$found_dir
+ eval ac_val=$found_dir

Solution

  • You are trying to use $(prefix) in an unintended way. In an Autotools-based build system, the $(prefix) represents a prefix to the target installation location of the software you're building. By setting it in your Makefile.in, you are overriding the prefix that configure will try to assign. However, since you appear not to have any installation targets anyway, at least at that level, that's probably more an issue of poor form than a cause for malfunction.

    How do I insert the location of the PARI's datadir into the Makefile?

    I'd recommend computing or discovering the needed directory in your configure script, and exporting it to the generated Makefile via its own output variable. Let's take the second part first, since it's simple. In configure.in, having in some manner located the wanted data directory and assigned it to a variable

    DATADIR=...
    

    , you would make an output variable of that via the AC_SUBST macro:

    AC_SUBST([DATADIR])
    

    Since you are using only Autoconf, not Automake, you would then manually receive that into your Makefile by changing the assignment in your Makefile.in:

    DATDIR = @DATADIR@
    

    Now, as for locating the data directory in the first place, you have to know what you're trying to implement before you can implement it. From your question and followup comments, it seems to me that you want this:

    1. Use a data directory explicitly specified by the user if there is one. Otherwise,

    2. look for a data directory relative to the location of the shared library. If it's not found there then

    3. (optional) look under the prefix specified to configure, or specifically in the specified datadir (both of which may come from the top-level configure). Finally, if it still has not been found then

    4. look in some standard locations.

    To create a configure option by which the user can specify a custom data directory, you would probably use the AC_ARG_WITH macro, maybe like this:

    AC_ARG_WITH([pari-datadir], [AS_HELP_STRING([--with-pari-datadir],
        [explicitly specifies the PARI data directory])],
      [], [with_pari_datadir=''])
    

    Thanks to @BrunoHaible, we see that although the Gnulib manual does not document it, the macro's internal documentation specifies that if AC_LIB_LINKFLAGS locates libpari then it will set LIBPARI_PREFIX to the library directory prefix. You find that that does work when the --with-libpari option is used to give it an alternative location to search, so I suggest working with that. You certainly can try to debug AC_LIB_LINKFLAGS to make it set LIBPARI_PREFIX in all cases in which the lib is found, but if you don't want to go to that effort then you can work around it (see below).

    Although the default or specified installation prefix is accessible in configure as $prefix, I would suggest instead going to the specified $datadir. That is slightly tricky, however, because by default it refers to the prefix indirectly. Thus, you might do this:

    eval "datadir_expanded=${datadir}"
    

    Finally, you might hardcode a set of prefixes such as /usr and /usr/local.


    Following on from all the foregoing, then, your configure.in might do something like this:

    DATADIR=
    for d in \
        ${with_pari_datadir} \
        ${LIBPARI_PREFIX:+${LIBPARI_PREFIX}/share/pari} \
        ${datadir_expanded}/pari \
        /usr/local/share/pari \
        /usr/share/pari
    do
      AS_IF([test -r "$[]d/pari.desc"], [DATADIR="$[]d"; break])
    done
    
    AS_IF([test x = "x$DATADIR"], [AC_MSG_ERROR(["Could not identify PARI data directory"])])
    AC_SUBST([DATADIR])