Quantcast

$sysconfdir substitution

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

$sysconfdir substitution

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,

--
Kip Warner -- Senior Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com


_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: $sysconfdir substitution

Peter Johansson-6
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

On 06/10/2016 04:10 PM, Kip Warner wrote:

> 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
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/autoconf

_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: $sysconfdir substitution

Gavin Smith
In reply to this post by Kip Warner
On 10 June 2016 at 07:10, Kip Warner <[hidden email]> wrote:
> 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.

_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf

helloprog-1.0.tar.xz (78K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: $sysconfdir substitution

Kip Warner
On Fri, 2016-06-10 at 19:33 +0100, Gavin Smith wrote:

> 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-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.
>
> 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.
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


_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: $sysconfdir substitution

Gavin Smith
In reply to this post by Peter Johansson-6
On 10 June 2016 at 08:05, Peter Johansson <[hidden email]> wrote:
> 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.

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.

_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: $sysconfdir substitution

Nick Bowler-2
In reply to this post by Kip Warner
On 6/10/16, Kip Warner <[hidden email]> wrote:
> 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

_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: $sysconfdir substitution

Kip Warner
In reply to this post by Peter Johansson-6
On Fri, 2016-06-10 at 17:05 +1000, Peter Johansson wrote:

> 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.
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


_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: $sysconfdir substitution

Kip Warner
In reply to this post by Gavin Smith
On Fri, 2016-06-10 at 20:30 +0100, Gavin Smith wrote:

> On 10 June 2016 at 08:05, Peter Johansson <[hidden email]> wrote:
> > 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.
>
> 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.
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


_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: $sysconfdir substitution

Kip Warner
In reply to this post by Nick Bowler-2
On Fri, 2016-06-10 at 15:37 -0400, Nick Bowler wrote:

> 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


_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf

signature.asc (188 bytes) Download Attachment
Loading...