[Top][All Lists]

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

Re: Conditional AC_DEFINE with m4_define variable?

From: Eric Blake
Subject: Re: Conditional AC_DEFINE with m4_define variable?
Date: Sat, 22 Dec 2012 08:18:35 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

[adding autoconf, as this question technically is independent of automake]

On 12/22/2012 07:52 AM, Jef Driesen wrote:
> Hi,
> When I set a variable with:
> m4_define([dc_version_suffix],[devel])
> or leave it empty:
> m4_define([dc_version_suffix],[])
> And then try to conditionally call AC_DEFINE based on whether the
> dc_version_suffix is set or not, this doesn't work:
> AS_IF([test "x$dc_version_suffix" = "xdevel"], [
>    AC_DEFINE(ENABLE_PTY, [1], [Enable pseudo terminal support.])
> ])

This will expand to either:

test "x$" = "xdevel"


test "x$devel" = "xdevel"

based on the macro value.  Probably not what you wanted.

> However if I use m4_isset, then it does kind of work, except that the
> USE_REVISION macro in the config.h is either defined, or not present at
> all.
> m4_ifset([dc_version_suffix],[
>    AC_DEFINE(USE_REVISION, [1], [Use the revision number.])
> ])

Indeed, this actually does what _I_ would want - since dc_version_suffix
is known at m4 time, we might as well use that information to generate
the smallest possible configure.

But if you _insist_ on delaying the decision until shell time, even
though the condition being tested is known at m4 time, then you probably
want to use something like this:

AS_IF([test "x]dc_version_suffix[" = "xdevel"], [
  AC_DEFINE([USE_REVISION], [1], [Use the revision number.])

which expands the literal contents of the macro in place, so that your
configure will then either contain:

test "x" = "xdevel"


test "xdevel" = "xdevel"

Or, if you _want_ a shell variable rather than an m4 variable as the
source of your decision, then be sure you set up that shell variable:

AS_IF([[test "x$dc_version_suffix" = "xdevel"]], [
  AC_DEFINE([USE_REVISION], [1], [Use the revision number.])

where the extra quoting is necessary to ensure that your configure file
will look like either:

test "x$dc_version_suffix" = "xdevel"


test "x$dc_version_suffix" = "xdevel"

Using a different shell variable name than the m4 macro name will make
it easier to type, without quite so much quoting:

AS_IF([test "x$version_suffix" = "xdevel"], [
  AC_DEFINE([USE_REVISION], [1], [Use the revision number.])

> Does anyone know how to implement this correctly?

It really depends on what you are trying to accomplish by deciding
something at m4 time, but deferring the action on that decision until
configure time.

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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