From: David Bond on
Hello,
I'm working on a project that we are converting to autotools and I had
a question. If this is the wrong place to ask these please direct me
to the right location.

Our project has a particle feature with three posible states:
STATIC, DYNAMIC, or NONE

Ideally we would like the build to be like:
../configure STATE=STATIC ; make

What I want this to do is, depending on the configure time STATE value
giveni, generate a Makefile that executes Make code specific for that
STATE. There should also be a default STATE in case this command line
option not be given. i.e. DYNAMIC. This is what I believe should
accomplish
this:

configure.ac
---------------------------------------
AM_CONDITIONAL([STATE_DYNAMIC],[test x$STATE = xDYNAMIC])
AM_CONDITIONAL([STATE_STATIC],[test x$STATE = xSTATIC])

AC_ARG_VAR([STATE],[The STATE STATIC DYNAMIC or NONE.])
AC_SUBST([STATE],[DYNAMIC])

Makefile.am
----------------------------------------
if STATE_DYNAMIC
... DO SOMETHING ...
else
if STATE_STATIC
... DO SOMETHING ...
endif
endif
.... Etc ...


This is not doing what I expect it to. Any ideas what my
misunderstanding is? Also, what is the reason for appending an x in
front of test varibles.
I saw that in the make manual along with several examples.

Thanks,
David
From: Scott Lurndal on
David Bond <davidmokonbond(a)gmail.com> writes:
>Hello,
>I'm working on a project that we are converting to autotools and I had
>a question. If this is the wrong place to ask these please direct me
>to the right location.
>
>Our project has a particle feature with three posible states:
>STATIC, DYNAMIC, or NONE
>
>Ideally we would like the build to be like:
>./configure STATE=STATIC ; make
>
>What I want this to do is, depending on the configure time STATE value
>giveni, generate a Makefile that executes Make code specific for that
>STATE. There should also be a default STATE in case this command line
>option not be given. i.e. DYNAMIC. This is what I believe should
>accomplish
>this:
>
>configure.ac
>---------------------------------------
>AM_CONDITIONAL([STATE_DYNAMIC],[test x$STATE = xDYNAMIC])
>AM_CONDITIONAL([STATE_STATIC],[test x$STATE = xSTATIC])
>
>AC_ARG_VAR([STATE],[The STATE STATIC DYNAMIC or NONE.])
>AC_SUBST([STATE],[DYNAMIC])
>
>Makefile.am
>----------------------------------------
>if STATE_DYNAMIC
> ... DO SOMETHING ...
>else
>if STATE_STATIC
> ... DO SOMETHING ...
>endif
>endif
>... Etc ...
>
>
>This is not doing what I expect it to. Any ideas what my
>misunderstanding is? Also, what is the reason for appending an x in
>front of test varibles.
>I saw that in the make manual along with several examples.
>
>Thanks,
>David

One adds the 'x' when using test(1) to avoid a syntax error if the
variable (e.g. STATE) is not set[*]. Note that '[' is a link to /usr/bin/test.

You can also use [[ "$STATE" == "DYNAMIC" ]] which avoids the 'x' and
doesn't fork/exec test(1), but requires a POSIX shell (e.g. bash, ksh).

I don't use autoconf/automake, so I can't help you there.

scott

[*] if STATE were not set and you didn't have the leading 'x', the
test would resolve to [ = DYNAMIC ] which would throw a syntax error;
with the 'x' [ x = xDYNAMIC ] which is syntatically correct.
From: David Bond on
Thanks