Unix Programming - A GNU autotools question

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > November 2004 > A GNU autotools question





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author A GNU autotools question
Daniel Haude

2004-11-26, 5:50 pm

Slooowly, sloowly I'm beginning to succeed in wrapping my head around GNU
autotools. But there remain many very basic points I don't understand.

I have a very small project called 'uc', consiting of a single-source ISO
C program (uc.c), a data file (uc.dat), and a man page (uc.1). So after
grappling with the autotools book for quite some time, this is what I came
up with for configure.in (Makefile.am at the bottom if needed):

------------------------
dnl Process this file with autoconf to produce a configure script.
AC_INIT(uc.c)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(uc, 1.0)
AC_PROG_CC
AC_OUTPUT(Makefile)
-----------------------

Now my problem is the following: Obviously I need my program to know where
the "make install" at the end-user's machine puts the data file, uc.dat
(I've tried it; it ends up in /usr/local/share/uc/uc.dat which is fine). I
guess this information should be put into config.h by configure, but it
doesn't. All that gets #defined in config.h is the package name and the
version.

Thanks for any hints,
--Daniel

(below: Makefile.am)
----------------------------------------------------

## Process this file with automake to produce Makefile.in

AM_CFLAGS = -Wall -W -ansi -pedantic -g

bin_PROGRAMS = uc

uc_SOURCES = uc.c

uc_LDFLAGS =

uc_LDADD = -lm

man_MANS = uc.1

pkgdata_DATA = uc.dat

EXTRA_DIST = man_MANS

uc.1 : uc.man
sed -e s\=PREFIX=$prefix= < uc.man > uc.1
Måns Rullgård

2004-11-26, 5:50 pm

Daniel Haude <haude@kir.physnet.uni-hamburg.de> writes:

> Slooowly, sloowly I'm beginning to succeed in wrapping my head around GNU
> autotools. But there remain many very basic points I don't understand.
>
> I have a very small project called 'uc', consiting of a single-source ISO
> C program (uc.c), a data file (uc.dat), and a man page (uc.1). So after
> grappling with the autotools book for quite some time, this is what I came
> up with for configure.in (Makefile.am at the bottom if needed):
>
> ------------------------
> dnl Process this file with autoconf to produce a configure script.
> AC_INIT(uc.c)
> AM_CONFIG_HEADER(config.h)
> AM_INIT_AUTOMAKE(uc, 1.0)
> AC_PROG_CC
> AC_OUTPUT(Makefile)
> -----------------------
>
> Now my problem is the following: Obviously I need my program to know where
> the "make install" at the end-user's machine puts the data file, uc.dat
> (I've tried it; it ends up in /usr/local/share/uc/uc.dat which is fine). I
> guess this information should be put into config.h by configure, but it
> doesn't. All that gets #defined in config.h is the package name and the
> version.


Use AC_DEFINE() to define anything you like. You might want to do
something like AC_DEFINE([DATA_DIR], [$datadir/$PACKAGE]).

> Thanks for any hints,
> --Daniel
>
> (below: Makefile.am)


Seems OK.

--
Måns Rullgård
mru@inprovide.com
Heiko

2004-11-26, 5:50 pm

Daniel Haude wrote:

> Now my problem is the following: Obviously I need my program to know where
> the "make install" at the end-user's machine puts the data file, uc.dat
> (I've tried it; it ends up in /usr/local/share/uc/uc.dat which is fine). I
> guess this information should be put into config.h by configure, but it
> doesn't. All that gets #defined in config.h is the package name and the
> version.


Some time ago I figured this out, and I've put an example source package
on the web that does this, and also adds a custom "--with-foo" option to
the configure script. It's here:
http://www.xs4all.nl/~heiky/myprog-0.1.tar.gz

Please note that it uses a newer autoconf that expects "configure.ac"
instead of "configure.in".

Heiko
Roger Leigh

2004-11-26, 5:50 pm

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Daniel Haude <haude@kir.physnet.uni-hamburg.de> writes:

> Slooowly, sloowly I'm beginning to succeed in wrapping my head around GNU
> autotools. But there remain many very basic points I don't understand.
>
> I have a very small project called 'uc', consiting of a single-source ISO
> C program (uc.c), a data file (uc.dat), and a man page (uc.1). So after
> grappling with the autotools book for quite some time, this is what I came
> up with for configure.in (Makefile.am at the bottom if needed):


You are using an older version of autoconf/make. I've written the
updated syntax below. Also note the m4 quoting (`[' and `]')! You
should really upgrade to the latest versions if at all possible.

> ------------------------
> dnl Process this file with autoconf to produce a configure script.
> AC_INIT(uc.c)


AC_INIT([uc], [0.1.0], [uc-devel@some.where])
AC_PREREQ([2.59])
AC_CONFIG_SRCDIR([uc.c])

> AM_CONFIG_HEADER(config.h)
> AM_INIT_AUTOMAKE(uc, 1.0)


AM_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE

> AC_PROG_CC
> AC_OUTPUT(Makefile)


AC_CONFIG_FILES([Makefile])
AC_OUTPUT

> -----------------------
>
> Now my problem is the following: Obviously I need my program to know where
> the "make install" at the end-user's machine puts the data file, uc.dat
> (I've tried it; it ends up in /usr/local/share/uc/uc.dat which is fine). I
> guess this information should be put into config.h by configure, but it
> doesn't. All that gets #defined in config.h is the package name and the
> version.


dnl Set PACKAGE_DATA_DIR in config.h.
AH_TEMPLATE(PACKAGE_DATA_DIR,, [Package data directory])
if test "x${datadir}" = 'x${prefix}/share'; then
if test "x${prefix}" = "xNONE"; then
PACKAGE_DATA_DIR="${ac_default_prefix}/share/${PACKAGE}"
else
PACKAGE_DATA_DIR="${prefix}/share/${PACKAGE}"
fi
else
PACKAGE_DATA_DIR="${datadir}/${PACKAGE}"
fi

AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${PACKAGE_DATA_DIR}")

[What MÃ¥ns suggested with AC_DEFINE is correct, but $pkgdatadir and
$datadir are only partially defined during the configure run, and the
above ensures that it is expanded as it would be if you were to take
it from config.status or after subsitution and expansion in a
Makefile.]

> (below: Makefile.am)
> ----------------------------------------------------
>
> ## Process this file with automake to produce Makefile.in
>
> AM_CFLAGS = -Wall -W -ansi -pedantic -g


These are compiler-specific; you might want to check GCC is in use
before substituting them in. The rest looks just fine, though.


Regards,
Roger

- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iD8DBQFBp1arVcFcaSW/ uEgRAroZAKDY5LS6qFJ5TWbHegmYEI5ycSls4ACg
yuj7
sYdh4TUxwAJgQcGiZbgcRsE=
=ZFTM
-----END PGP SIGNATURE-----
Måns Rullgård

2004-11-26, 5:50 pm

Roger Leigh <${roger}@invalid.whinlatter.uklinux.net.invalid> writes:

>
> dnl Set PACKAGE_DATA_DIR in config.h.
> AH_TEMPLATE(PACKAGE_DATA_DIR,, [Package data directory])
> if test "x${datadir}" = 'x${prefix}/share'; then
> if test "x${prefix}" = "xNONE"; then
> PACKAGE_DATA_DIR="${ac_default_prefix}/share/${PACKAGE}"
> else
> PACKAGE_DATA_DIR="${prefix}/share/${PACKAGE}"
> fi
> else
> PACKAGE_DATA_DIR="${datadir}/${PACKAGE}"
> fi
>
> AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${PACKAGE_DATA_DIR}")
>
> [What Måns suggested with AC_DEFINE is correct,


Actually, it's not. I forgot some quotes.

> but $pkgdatadir and $datadir are only partially defined during the
> configure run, and the above ensures that it is expanded as it would
> be if you were to take it from config.status or after subsitution
> and expansion in a Makefile.]


I usually let make do the expansion of ${prefix}, so I forgot about
this. Of course you are right.

--
Måns Rullgård
mru@inprovide.com
Daniel Haude

2004-11-27, 5:51 pm

On Fri, 26 Nov 2004 16:15:40 +0000,
Roger Leigh <${roger}@invalid.whinlatter.uklinux.net.invalid> wrote
in Msg. <873bywtwlv.fsf@whinlatter.whinlatter.ukfsn.org>

> You are using an older version of autoconf/make. I've written the
> updated syntax below. Also note the m4 quoting (`[' and `]')! You
> should really upgrade to the latest versions if at all possible.


I just realized that I'm using a quite recent version, but with outdated
documentation (something called the "autoconf book"). Just found something
newer.

Thanks for all the hints, I'm a bit more on my way now.

--Daniel

Daniel Haude

2004-11-29, 7:51 am

On Fri, 26 Nov 2004 16:15:40 +0000,
Roger Leigh <${roger}@invalid.whinlatter.uklinux.net.invalid> wrote
in Msg. <873bywtwlv.fsf@whinlatter.whinlatter.ukfsn.org>

> dnl Set PACKAGE_DATA_DIR in config.h.
> AH_TEMPLATE(PACKAGE_DATA_DIR,, [Package data directory])
> if test "x${datadir}" = 'x${prefix}/share'; then
> if test "x${prefix}" = "xNONE"; then
> PACKAGE_DATA_DIR="${ac_default_prefix}/share/${PACKAGE}"
> else
> PACKAGE_DATA_DIR="${prefix}/share/${PACKAGE}"
> fi
> else
> PACKAGE_DATA_DIR="${datadir}/${PACKAGE}"
> fi
>
> AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${PACKAGE_DATA_DIR}")
>
> [What Måns suggested with AC_DEFINE is correct, but $pkgdatadir and
> $datadir are only partially defined during the configure run, and the
> above ensures that it is expanded as it would be if you were to take
> it from config.status or after subsitution and expansion in a
> Makefile.]


Hmmm... this seems awfully convoluted for something as simple as a data
directory which many programs require. Also, what exactly does "partially
defined" mean?

Talking about definition... your example assumes that
${ac_default_prefix} is defined, right? So let's see what ends up in
config.h when I do this in configure.ac:

----
AC_DEFINE([PREFIX], ${ac_default_prefix}, test)
----

and the result in config.h reads
(after autoheader && automake && autoconf && ./configure):

----
/* test */
#define PREFIX ${ac_uefault_prefix}
----

Weird! It's really a "u" instead of a "d"! I'm totally flustered. What can
I rely on with this autoconf stuff?

Autoheader and autoconf are both version 2.9.5, automake is 1.9.3

--Daniel

--
"With me is nothing wrong! And with you?" (from r.a.m.p)
Daniel Haude

2004-11-29, 7:51 am

On Fri, 26 Nov 2004 16:55:52 +0100,
Måns Rullgård <mru@inprovide.com> wrote
in Msg. <yw1xwtw8a9kn.fsf@ford.inprovide.com>

> Use AC_DEFINE() to define anything you like. You might want to do
> something like AC_DEFINE([DATA_DIR], [$datadir/$PACKAGE]).


This ends up as this in config.h:

/* test */
#define DATA_DIR $datadir/$PACKAGE


(I had to use add a third parameter to stop autoheader from bitching about
a missing template or something):

AC_DEFINE([DATA_DIR], [$datadir/$PACKAGE], test)

--Daniel
Daniel Haude

2004-11-29, 7:51 am

On 29 Nov 2004 10:32:20 GMT,
Daniel Haude <haude@kir.physnet.uni-hamburg.de> wrote
in Msg. <slrncqluo2.aps.haude@kir.physnet.uni-hamburg.de>

> ----
> AC_DEFINE([PREFIX], ${ac_default_prefix}, test)
> ----


BTW, it doesn't matter if I put []'s around the second argument or not.

Roger Leigh

2004-11-29, 7:51 am

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Daniel Haude <haude@kir.physnet.uni-hamburg.de> writes:

> On Fri, 26 Nov 2004 16:15:40 +0000,
> Roger Leigh <${roger}@invalid.whinlatter.uklinux.net.invalid> wrote
> in Msg. <873bywtwlv.fsf@whinlatter.whinlatter.ukfsn.org>
>
>
> Hmmm... this seems awfully convoluted for something as simple as a data
> directory which many programs require.


Yes. Perhaps something like that could get into autoconf eventually.

> Also, what exactly does "partially defined" mean?


Some of the variables contain other variables:

datadir='${prefix}/share'

This is substituted directly in Makefiles:

Makefile.in:
pkgdatadir = $(datadir)/@PACKAGE@
datadir = @datadir@
pkgdatadir = $(datadir)/photoprint
datadir = ${prefix}/share

You can't evaluate it in configure, since it could well be changed
during execution, or vary depending on which options the user ran
configure with (or has in config.site). This simply duplicates how it
will eventutally get expanded for config.status--it's ripped straight
from autoconf anyway--we just call it early.

> Talking about definition... your example assumes that
> ${ac_default_prefix} is defined, right? So let's see what ends up in
> config.h when I do this in configure.ac:


$ grep ac_default_prefix configure | head -n 1
ac_default_prefix=/usr/local

Check your generated configure--it's a fallback if you don't use
- --prefix.

> ----
> AC_DEFINE([PREFIX], ${ac_default_prefix}, test)
> ----
>
> and the result in config.h reads
> (after autoheader && automake && autoconf && ./configure):
>
> ----
> /* test */
> #define PREFIX ${ac_uefault_prefix}
> ----
>
> Weird! It's really a "u" instead of a "d"! I'm totally flustered. What can
> I rely on with this autoconf stuff?


I'm not sure what's going on there. Try AC_SUBST instead, and check
what's in config.status.

> Autoheader and autoconf are both version 2.9.5, automake is 1.9.3


Are you sure about the autoconf version? 2.59 is current.


- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iD8DBQFBqwdEVcFcaSW/uEgRAhG8AKDnXLHqxVXjKS/ol4ZuUtaw5gQ4hACg0iHV
+rrtArgkn+Y0TcWXnyzLzUU=
=8iy/
-----END PGP SIGNATURE-----
Roger Leigh

2004-11-29, 7:51 am

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Daniel Haude <haude@kir.physnet.uni-hamburg.de> writes:

> On Fri, 26 Nov 2004 16:55:52 +0100,
> Måns Rullgård <mru@inprovide.com> wrote
> in Msg. <yw1xwtw8a9kn.fsf@ford.inprovide.com>
>
>
> This ends up as this in config.h:
>
> /* test */
> #define DATA_DIR $datadir/$PACKAGE


Try AC_DEFINE_UNQUOTED?

> (I had to use add a third parameter to stop autoheader from bitching about
> a missing template or something):


> AC_DEFINE([DATA_DIR], [$datadir/$PACKAGE], test)


You can use AH_TEMPLATE to tell autoheader about it.


- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iD8DBQFBqwzpVcFcaSW/ uEgRAoQZAKDnIno+VFBHCCN6gI1JHEZabBCGZwCd
Enai
h8PVB2KWV50cmeQW1IO6pNU=
=8vt6
-----END PGP SIGNATURE-----
Daniel Haude

2004-11-29, 7:51 am

Hi people (esp Roger and Mans),

thanks for the tips. I'm not much more along as fas as the whole autoconf
mess is concerned, but I found this interesting snippet in autoconf.html:

-----
4.7.2 Installation Directory Variables

[...]

A corollary is that you should not use these variables except in
Makefiles. For instance, instead of trying to evaluate datadir in
configure and hard-coding it in Makefiles using e.g.,
AC_DEFINE_UNQUOTED(DATADIR, "$datadir"), you should add
-DDATADIR="$(datadir)" to your CPPFLAGS.
-----

So it looks as if config.h really isn't the right place to put this sort
of stuff anyway.

So much for now. Before long I'll be back, pestering y'all about the next
problem.

--Daniel

--
"With me is nothing wrong! And with you?" (from r.a.m.p)
Måns Rullgård

2004-11-29, 7:51 am

Daniel Haude <haude@kir.physnet.uni-hamburg.de> writes:

> Hi people (esp Roger and Mans),
>
> thanks for the tips. I'm not much more along as fas as the whole autoconf
> mess is concerned, but I found this interesting snippet in autoconf.html:
>
> -----
> 4.7.2 Installation Directory Variables
>
> [...]
>
> A corollary is that you should not use these variables except in
> Makefiles. For instance, instead of trying to evaluate datadir in
> configure and hard-coding it in Makefiles using e.g.,
> AC_DEFINE_UNQUOTED(DATADIR, "$datadir"), you should add
> -DDATADIR="$(datadir)" to your CPPFLAGS.
> -----
>
> So it looks as if config.h really isn't the right place to put this sort
> of stuff anyway.


I usually don't use config.h at all. If you don't AM_CONFIG_HEADER()
all those #defines will turn into -D flags in the Makefile, and make
will have a chance to expand any variables that might be in there.

--
Måns Rullgård
mru@inprovide.com
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com