autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to specify a custom library directory


From: Allan Caffee
Subject: Re: How to specify a custom library directory
Date: Sun, 21 Dec 2008 13:26:53 -0500

On Sun, Dec 21, 2008 at 10:50 AM, Bastien Dalla Piazza
<address@hidden> wrote:
> I need to give the possibility to the user to specify custom directories for
> external libraries which must be linked to my program.
> So this would be an argument to the configure script like --<library
> name>-dir=<custom path>.

This is usually done with AC_ARG_WITH macro which will allow users to
run you configure script with an argument like
`--with-foo=/usr/local/foo'.  The full details for setting up your
project to work with external packages, including details about
AC_ARG_WITH are available in the Autoconf info page
(http://www.gnu.org/software/autoconf/manual/html_node/External-Software.html).

> I guess the given path must then be substituted in the makefiles with a
> "AC_SUBST(CUSTOM_DIR)"

That's exactly right, but I would recommend that you use two separate
variables such as FOO_LIBS and FOO_CFLAGS.  You would use the value
passed in to decide an appropriate value for FOO_LIBS and FOO_CFLAGS
(possibly "-L$with_foo/lib -lfoo" and "-I$with_foo/include"
respectively).  Finally as you suggested substitute the values into
your Makefile by using:

AC_SUBST([FOO_LIBS])
AC_SUBST([FOO_CFLAGS])

And adding the @FOO_LIBS@ and @FOO_CFLAGS@ to appropriate variables in
your Makefile.in (or Makefile.am if you are using Automake).  The
reason I recommend using separate variables containing the actual
compiler flags is that it would allow you more flexability in the
future like making certain external libraries optional or offering
separate `--with-foo-lib' and `--with-foo-inc' directories.

> How to provide such an option (which macro in the configure.in file)?

Just a point on programming practices: it's suggested that developers
name the source for configure as configure.ac instead of configure.in
because the use of the `.in' extension tends to lead to confusion
about which `.in' files are filled in by configure.

I hope that helps clear things up for you.

~Allan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]