autoconf
[Top][All Lists]
Advanced

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

Re: Use pipe and sed in configure.ac


From: Gary V. Vaughan
Subject: Re: Use pipe and sed in configure.ac
Date: Thu, 10 Feb 2011 23:43:05 +0700

On 10 Feb 2011, at 10:39, Lyre <address@hidden> wrote:

> I tried to exact an option from php-config using:
> 
> php-config --configure-options | sed -n
> 's|.*--with-config-file-scan-dir=\([^ ]*\).*|\1|p'
> 
> It works on shell, and outputs "/etc/php5/conf.d/" on opensuse.
> 
> And I tired it in configure.ac, as following:
> 
> PHPINC=`php-config --includes`
> PHPCDIR=`php-config --configure-options | sed -n
> 's|.*--with-config-file-scan-dir=\([^ ]*\).*|\1|p'`
> 
> AC_SUBST([PHPINC])
> AC_SUBST([PHPCDIR])
> 
> After subsitution in Makefile, the PHPCDIR is empty, meanwhile PHPINC get
> the correct result.
> 
> What' the correct way to use it?

Autoconf turns your configure.ac specification in a configure shell script by 
running
it through GNU M4, with the M4 quote characters set to [ and ]. So M4 thinks you
are telling it not to expand [^ ] in the sed match expression, and after doing 
that, it
then throws those quote marks away.

If you search for the expanded text in the configure script, you'll see 
something
like this:

    PHPCDIR=`php-config --configure-options | sed -n \
      's|.*--with-config-file-scan-dir=\(^ *\).*|\1|p'`

Note the missing brackets, which means the sed match expression no longer
works as expected.

A rule of thumb is that you need to M4 quote sections of raw shell code in the
configure.ac file if you don't want them to remain unmolested in the generated
configure script. Things get a little more complicated if you are writing 
Autoconf
macros, but in this case doubling up the [ and ] in configure.ac should work:

    PHPCDIR=`php-config --configure-options | sed -n \
      's|.*--with-config-file-scan-dir=\([[^ ]]*\).*|\1|p'`

And you can search the generated configure script for PHPCDIR to check!

There are some other M4 syntaxes you need to watch out for too, but I'm pretty
sure they're all covered by the info manuals.

HTH,
Gary
-- 
Gary V. Vaughan (address@hidden)


reply via email to

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