[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: replacement of variable placeholders in files

From: Dizzy
Subject: Re: replacement of variable placeholders in files
Date: Wed, 22 Aug 2007 15:28:25 +0300
User-agent: KMail/1.9.7

On Wednesday 22 August 2007 14:41:46 you wrote:
> > AC_CONFIG_FILES([project.conf
> >     Makefile
> >     subdir/Makefile])
> That doesn't always work for several reasons.  First off, people
> happen to this frequently to pass path information around.  Paths are
> mostly always defined in term of $prefix (at least).  At configure
> time, prefix is set to NONE so you can't do it here [1].  Moreover,
> several paths are defined in terms of others, eg:
> bindir='${exec_prefix}/bin'
> exec_prefix='${prefix}'
> prefix='/usr/local'
> So you end up doing several calls to `eval' to simulate the variable
> expansion performed by make.  Needless to say this is fragile (but
> doable).

Indeed, I have tried with AC_CONFIG_FILES or AC_OUTPUT (with corresponding 
AC_SUBSTs) and I got something like ${prefix}/etc ${prefix}/var substituted 
in the file.

> Back to Dizzy's question:
> I think the line should be:
> $(SED) -e 's,$${LOCALSTATEDIR},${localstatedir},g' $(top_srcdir)/conf/
> >$@
> You don't need to worry about the double-quotes thing because it's
> not your shell that expands the value of ${localstatedir} but make.
> Actually you could write $(localstatedir) instead and it wouldn't
> change anything.

Yeah, I had some confusion in my mind. After more debugging and printing of and Makefile contents I also realised what you said that it's 
replaced by make and not the shell heh.

> Actually what happens is that ${LOCALSTATEDIR} is recognized by make
> as a non-existant make variable and is (as such) expanded to an empty
> string.  What you want to do is to escape this variable so that make
> ignores it (by using `$$' instead of a single `$').

Had no idea about the $$ trick to escape variables in make, thank you (and 
Bernd) for the idea.

> $ cat >
> AC_INIT([foo], [0.1])
> AM_INIT_AUTOMAKE([foreign])
> AC_CONFIG_FILES([Makefile])
> $ cat >
> foo:
> ^Ised -e 's,$${LOCALSTATEDIR},${localstatedir},g' $(top_srcdir)/
> >$@
> $ cat >
> $ autoreconf -i
> installing `./missing'
> installing `./install-sh'
> $ ./configure
> checking for a BSD-compatible install... /opt/local/bin/ginstall -c
> checking whether build environment is sane... yes
> checking for a thread-safe mkdir -p... /opt/local/bin/mkdir -p
> checking for gawk... gawk
> checking whether make sets $(MAKE)... yes
> configure: creating ./config.status
> config.status: creating Makefile
> $ make foo
> sed -e 's,${LOCALSTATEDIR},/usr/local/var,g' ./ >foo
> $ sh foo
> /usr/local/var

Works very well indeed, the trick was mainly the $$ escape variable for make 

Thank you all, you have been very helpful.

Mihai RUSU                                      Email: address@hidden
                        "Linux is obsolete" -- AST

reply via email to

[Prev in Thread] Current Thread [Next in Thread]