autoconf qns
1. How do I define a custom #define macro in config.h based on configure arguments? eg if I set --with-foo, I would like to have #define WITH_FOO 1 set in config.h
2. How do I make the directory variables (eg @includedir, @shareddir etc) visible to my code? I know how to achieve this by adding -D options to AM_CPPFLAGS in Makefile.am, but I would like to have the macros inside config.h. Can this be done? 3. How do I fail the configure script when a test fails. eg if AC_HEADER_STDC is not found, exit/fail the configure script. Thanks. |
Long answer...
About a year ago I was wondering exactly the same things. I didn't find autoconf/automake/m4 stuff very easy. When I read your question I decided to make very basic example package that does the things you asked, so I have it documented for myself in the future as well.
Get it here if you are interested: http://www.xs4all.nl/~heiky/myprog-0.1.tar.gz It boils down to this: Quote:
(this assumes --with-foo to specify a library directory, not "WITH_FOO 1", but you can figure out how to that from this. It will be easier I think) Code:
AC_DEFUN([AC_FOO], [ Code:
sinclude(ac_foo.m4) Code:
EXTRA_DIST = ac_foo.m4 Code:
AC_INIT([My Program], [0.1], [you@somewhere.com], [myprog]) Quote:
Code:
dnl Taken from the autoconf archive (www.gnu.org) Code:
sinclude(ac_foo.m4) Code:
EXTRA_DIST = ac_define_dir.m4 ac_foo.m4 And finally call it from configure.ac". Here the datadir is #defined in config.h. (the datadir is the directory to store data used by your program. By default ./configure will make it: $PREFIX/share) Code:
AC_DEFINE_DIR([DATADIR], [datadir], [Directory for data files.]) Quote:
Code:
AC_MSG_FAILURE(["Your custom error message"]) http://www.xs4all.nl/~heiky/myprog-0.1.tar.gz If you can improve or extend that, I'd be very interested! |
Thanks a lot.That was really helpful. I'll see what I can add once I make sense of it. :)
|
P.S. The code assumes autoconf version 2.57 or higher.
|
Sorry for the evil bump.
How can I select certain subdirs to compile based on the user's configure --enable option? eg. /foo -> foo.c -> Makefile.am main.c configure.in Makefile.am If the user used configured --enable-foo, I would build in foo, otherwise, foo is left out. I tried this in configure.in, but didn't work as thought: Code:
if test x"with_foo" = xyes ; then |
All times are GMT -5. The time now is 10:21 AM. |