Discussion:
$sysconfdir substitution
Kip Warner
2016-06-10 06:10:27 UTC
Permalink
Hey list,

I'd like to make the fully expanded $sysconfdir shell variable
available within a file processed via AC_CONFIG_FILES. I am currently
trying AC_SUBST([SYSCONFDIR], [$sysconfdir]), but it is not fully
evaluated at ${prefix}/etc which is useless for me. Any ideas?

Regards,
--
Kip Warner -- Senior Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com
Peter Johansson
2016-06-10 07:05:53 UTC
Permalink
Hi Kip,

I have the following rule in my Makefile.am to generate a C header file.

configmake.h: Makefile
$(AM_V_GEN)echo '#define BINDIR "$(bindir)"' > $@

You could have a similar rule to generate a file suitable to source into
your script.

Cheers,
Peter
Post by Kip Warner
Hey list,
I'd like to make the fully expanded $sysconfdir shell variable
available within a file processed via AC_CONFIG_FILES. I am currently
trying AC_SUBST([SYSCONFDIR], [$sysconfdir]), but it is not fully
evaluated at ${prefix}/etc which is useless for me. Any ideas?
Regards,
_______________________________________________
Autoconf mailing list
https://lists.gnu.org/mailman/listinfo/autoconf
Gavin Smith
2016-06-10 19:30:28 UTC
Permalink
Post by Peter Johansson
Hi Kip,
I have the following rule in my Makefile.am to generate a C header file.
configmake.h: Makefile
You could have a similar rule to generate a file suitable to source into
your script.
This works because the variable "bindir" is completely expanded in the
Makefile rules.

The Texinfo project has similar code to substitute for variables in a
AC_CONFIG_FILE-like way in an output file:

do_subst = sed \
-e 's,[@]PACKAGE_VERSION[@],$(PACKAGE_VERSION),g' \
-e 's,[@]PACKAGE_NAME[@],$(PACKAGE_NAME),g' \
-e 's,[@]PACKAGE_URL[@],$(PACKAGE_URL),g' \
-e 's,[@]sysconfdir[@],$(sysconfdir),g' \
-e 's,[@]prefix[@],$(prefix),g' \
-e 's,[@]datarootdir[@],$(datarootdir),g' \
-e 's,[@]datadir[@],$(datadir),g' \
-e 's,[@]pkglibdir[@],$(pkglibdir),g' \
-e 's,[@]PACKAGE[@],$(PACKAGE),g' \
-e 's,[@]USE_EXTERNAL_LIBINTL[@],$(USE_EXTERNAL_LIBINTL),g' \
-e 's,[@]USE_EXTERNAL_EASTASIANWIDTH[@],$(USE_EXTERNAL_EASTASIANWIDTH),g' \
-e 's,[@]USE_EXTERNAL_UNIDECODE[@],$(USE_EXTERNAL_UNIDECODE),g' \
-e 's,[@]TEXINFO_DTD_VERSION[@],$(TEXINFO_DTD_VERSION),g' \
-e 's,[@]enable_xs[@],$(enable_xs),g' \
-e '1 s,/usr/bin/env perl,$(PERL),g'

texi2any: texi2any.pl $(top_builddir)/config.status
$(do_subst) $(srcdir)/texi2any.pl >$@
chmod a+x $@

The gist of this is that it's using sed to generate one file from
another, substituting in the values of some Makefile variables. I
don't know if it's possible or advisable to use this in combination
with AC_CONFIG_FILES, but using it instead of AC_CONFIG_FILES would
certainly work.
Kip Warner
2016-06-10 21:09:11 UTC
Permalink
Post by Gavin Smith
Post by Peter Johansson
Hi Kip,
I have the following rule in my Makefile.am to generate a C header file.
configmake.h: Makefile
You could have a similar rule to generate a file suitable to source into
your script.
This works because the variable "bindir" is completely expanded in the
Makefile rules.
The Texinfo project has similar code to substitute for variables in a
do_subst = sed \
-e
' \
-e '1 s,/usr/bin/env perl,$(PERL),g'
texi2any: texi2any.pl $(top_builddir)/config.status
The gist of this is that it's using sed to generate one file from
another, substituting in the values of some Makefile variables. I
don't know if it's possible or advisable to use this in combination
with AC_CONFIG_FILES, but using it instead of AC_CONFIG_FILES would
certainly work.
Thanks Gavin. I think this is a good recipe to use if I end up having
regrets later about the solution I just proposed to Peter Johansson.
--
Kip Warner -- Senior Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com
Kip Warner
2016-06-10 21:08:29 UTC
Permalink
Post by Peter Johansson
Hi Kip,
I have the following rule in my Makefile.am to generate a C header file.
configmake.h: Makefile
You could have a similar rule to generate a file suitable to source into
your script.
Hey Peter,

That looks good, but I really like the AC_CONFIG_FILES approach because
I think it looks cleaner. If I went your method it would be similar,
but I'd probably use sed instead.

What I ended up coming up with seems to work, albeit it is a bit ugly.

SYSCONFDIR=`test "$prefix" = NONE && prefix=$ac_default_prefix; eval echo "${sysconfdir}"`
AC_SUBST([sysconfdir], [$SYSCONFDIR])
AC_CONFIG_FILES([myfile])
--
Kip Warner -- Senior Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com
Gavin Smith
2016-06-10 18:33:22 UTC
Permalink
Post by Kip Warner
I'd like to make the fully expanded $sysconfdir shell variable
available within a file processed via AC_CONFIG_FILES. I am currently
trying AC_SUBST([SYSCONFDIR], [$sysconfdir]), but it is not fully
evaluated at ${prefix}/etc which is useless for me. Any ideas?
Regards,
It's possible to communicate shell variables with AM_CPPFLAGS. I wrote
about this method at
http://buildsystem-manual.sourceforge.net/Adding-a-data-file-to-be-installed.html#Adding-a-data-file-to-be-installed.
For convenience, I've attached a small project that uses this method.

There are very likely other methods as well. For example, you could
use AC_DEFINE or AC_DEFINE_UNQUOTED with AC_CONFIG_HEADER.

Your question reminds me of this:
http://lists.gnu.org/archive/html/autoconf/2015-09/msg00015.html It
seems to be hard to get ahold of the values of the shell variables
with directories in them from within the configure script.
Kip Warner
2016-06-10 18:51:12 UTC
Permalink
Post by Gavin Smith
about this method at
http://buildsystem-manual.sourceforge.net/Adding-a-data-file-to-be-in
stalled.html#Adding-a-data-file-to-be-installed.
For convenience, I've attached a small project that uses this method.
There are very likely other methods as well. For example, you could
use AC_DEFINE or AC_DEFINE_UNQUOTED with AC_CONFIG_HEADER.
http://lists.gnu.org/archive/html/autoconf/2015-09/msg00015.html It
seems to be hard to get ahold of the values of the shell variables
with directories in them from within the configure script.
Hey Gavin,

Thanks for the suggestion. Unfortunately I've already got access to the
variable through the pre-processor (e.g. AM_CPPFLAGS), but I need the
variable substituted in a non-compiled .in file with AC_CONFIG_FILES.
--
Kip Warner -- Senior Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com
Nick Bowler
2016-06-10 19:37:11 UTC
Permalink
Post by Kip Warner
Thanks for the suggestion. Unfortunately I've already got access to the
variable through the pre-processor (e.g. AM_CPPFLAGS), but I need the
variable substituted in a non-compiled .in file with AC_CONFIG_FILES.
It would be possible to make this work by writing sh code to expand the
variables, but it is not recommended. Users are supposed to be able to
set installation directory variables on the make command line, e.g.,

make sysconfdir=/some/where

and substituting expanded paths in AC_CONFIG_FILES will usually fail in
this situation.

Instead, the straightforward approach is to generate the files with a
make rule, as suggested by Peter Johansson.

Regards,
Nick
Kip Warner
2016-06-10 21:10:57 UTC
Permalink
Post by Nick Bowler
It would be possible to make this work by writing sh code to expand
the variables, but it is not recommended. Users are supposed to be
able to set installation directory variables on the make command
line, e.g.,
make sysconfdir=/some/where
and substituting expanded paths in AC_CONFIG_FILES will usually fail
in this situation.
Instead, the straightforward approach is to generate the files with a
make rule, as suggested by Peter Johansson.
Yeah, this is one of my big reservations in substituting the the
expanded paths in AC_CONFIG_FILES because the user can override when
they run make.

*sigh* Maybe I will have to do it through Automake after all...
--
Kip Warner -- Senior Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com
Loading...