1

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
sds
  • 58,617
  • 29
  • 161
  • 278
  • I guess you're talking about the `AC_LIB_LINKFLAGS` macro from gnulib (there is no such macro packaged with Autoconf itself), and I have updated the tags correspondingly. If you mean a different macro then please clarify and update the tags. – John Bollinger Jan 16 '18 at 18:43
  • Supposing that you do mean the macro from gnulib, [it's docs](https://www.gnu.org/software/gnulib/manual/html_node/Searching-for-Libraries.html) don't say anything about setting a `*_PREFIX` variable. From where, then, does that come? – John Bollinger Jan 16 '18 at 18:45
  • @JohnBollinger: the generated `configure` has `LIBPARI_PREFIX` in `ac_subst_vars` so I hoped that it would work... – sds Jan 16 '18 at 18:59
  • I see that `configure` indeed does contain that variable, and I think `AC_LIB_LINKFLAGS` must indeed be responsible for it, but that does not change the fact that it is not documented. But I guess that's moot because it doesn't adequately serve your purpose anyway. – John Bollinger Jan 16 '18 at 19:03
  • More generally then, do I understand correctly that you intend to locate PARI's data directory by assuming its location to be related to that of the library's through use of a common path prefix and conventional path suffix? Are you satisfied that that is sufficient? – John Bollinger Jan 16 '18 at 19:06
  • @JohnBollinger: I think you are implying that I should use something like `dirname(path-to-pari.so)/../share/pari/pari.desc`. This is clearly suboptimal (because pari might have been installed with a non-standard `--datadir` flag), but, I guess, it will work in most cases. – sds Jan 16 '18 at 19:15
  • I'm not implying anything -- I'm just trying to interpret your question. What I described is what the code you've presented appears to be trying to do. It sounds like you're *not* satisfied with that. – John Bollinger Jan 16 '18 at 19:16
  • Your expectation looks right, because the documentation of the macro says: `dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem. ` – Bruno Haible Jan 16 '18 at 19:43
  • The code of AC_LIB_LINKFLAGS_BODY is meant to optimize the special cases `/usr` and `/usr/local` only regarding the LIBPARI and LTLIBPARI variables (which are used for linking, without libtool vs. with libtool). The code that computes LIBPARI_PREFIX should not be affected by this optimization. – Bruno Haible Jan 16 '18 at 19:45
  • Therefore, you need to debug this macro yourself: Run the `configure` script with "bash -x configure" and inspect the output, paying special attention to the variable `found_dir`. Optionally, insert special debugging statement into lib-link.m4 and regenerate the `configure` script with them. – Bruno Haible Jan 16 '18 at 19:48
  • @BrunoHaible: my apologies, the please see edit. My code works on MacOSX but not Ubuntu. – sds Jan 18 '18 at 02:51

2 Answers2

2

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])
John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • thanks! why should I use `AS_IF` instead of `if`? Is `if` _really_ unportable?! – sds Jan 18 '18 at 16:10
  • @sds, it's mostly a question of style, but `AS_IF` does provide for ensuring that any macros required by its arguments are expanded first (i.e. outside the scope of the resulting conditional). My practice is to use M4sh macros such as `AS_IF` instead of raw shell syntax when in fact such macros exist. YMMV. – John Bollinger Jan 18 '18 at 17:32
0

Instead of guessing the location of datadir, why don't you ask PARI/GP where its datadir is located? Namely,

$ echo "default(datadir)" | gp -qf
"/usr/share/pari"

does the trick.

Dima Pasechnik
  • 336
  • 4
  • 16