[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Smart --with-package=DIR (for absentminded users)
From: |
Benoit SIGOURE |
Subject: |
Re: Smart --with-package=DIR (for absentminded users) |
Date: |
Thu, 5 Jul 2007 18:54:06 +0200 |
On Jul 5, 2007, at 1:29 PM, Thomas Lavergne wrote:
Hi all,
Hello Thomas,
Sorry if this is already in the archive. I looked through it and
was not lucky. You must also know that I am quite new to autoconf
but... I need to learn fast!
I want to implement the --with-package=DIR option to my
project's configure script. The --with-package[=yes|no] thing is
straightforward using AC_ARG_WITH(). I have however some questions
regarding others' experience wth the =DIR part.
1. What should I do if the user is so dumb to actually give a DIR
which does not exist? IMHO, I should issue an AC_MSG_ERROR and
terminate the configuration: we cannot configure taking into
account the user's input. What do you think of that and is there a
consensus on how to handle such a situation.
AC_MSG_ERROR is what I'd go for.
2. How can I detect that /path/to/foo helps in any way for
accessing foo.h and libfoo.a? Specifically, if library foo is
available in the system directories (e.g. /usr/include and /usr/
lib), then providing --with-foo=yes and --with-foo=/wrong/path/to/
foo will have the same effect. For foo is accessible to the
compiler and linker even if the options -I and -L point to 'wrong'
directories, i.e directories not containing foo.h and libfoo.a. Is
there a (portable) way of detecting that? In my case, the user
might have a custom-made version of foo (with the same file names)
and want to use it. I agree he should not have given a wrong path
to foo in the first place but users are users and I want to avoid
that the software is configured and compiled with the 'system-
version' of the library when the user (thought he) especially
demanded to use another version.
Any (portable or not) idea?
The autoconf way of dealing with this is to test the user's input.
If you know that libfoo *must* come with a header, say, foo.h, you
can test whether this header is usable with AC_CHECK_HEADERS [1] for
instance. Then it is generally a good idea to test that the header
"works". Say that you know for sure that the header must contain a
#define LIBFOO_VERSION, you should try to compile (or only
preprocess) a sample program that does something like:
#include <foo.h>
#ifndef LIBFOO_VERSION
# error foo.h did not define LIBFOO_VERSION
#endif
See for instance AC_PREPROC_IFELSE [2]
Similarily, you should test that you can link with libfoo and try to
compile (with AC_COMPILE_IFELSE [3] for instance) a small main that
uses one of the symbols of libfoo.
During these tests, you will have to add flags in CPPFLAGS (-I...)
and LDFLAGS (-L... -l...). Be careful, you should not overwrite
existing flags (that were set by previous tests or most probably by
the user). Also you should try to avoid to change these flags since
they're reserved for the user. Do something like:
old_CPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $flags_deduced_from_user_input"
AC_PREPROC_IFELSE(...your test here...)
CPPFLAGS=$old_CPPFLAGS
LIBFOO_CPPFLAGS=$flags_deduced_from_user_input
AC_SUBST([LIBFOO_CPPFLAGS])
And then use $(LIBFOO_CPPFLAGS) in your Makefile.am:
target_CPPFLAGS = $(LIBFOO_CPPFLAGS)
or
AM_CPPFLAGS = $(LIBFOO_CPPFLAGS)
(once again here do not use CPPFLAGS directly, they're reserved for
the user)
I hope this helps.
Cheers,
[1] http://www.gnu.org/software/autoconf/manual/html_node/Generic-
Headers.html
[2] http://www.gnu.org/software/autoconf/manual/html_node/Running-the-
Preprocessor.html
[3] http://www.gnu.org/software/autoconf/manual/html_node/Running-the-
Compiler.html
--
Benoit Sigoure aka Tsuna
EPITA Research and Development Laboratory
PGP.sig
Description: This is a digitally signed message part