Hi all:

I am trying to change the default of an AC_ARG_ENABLE option depending on the 
host architecture.

I am using the Autoconf 2.71 which comes with Ubuntu 22.04. I want to 
understand how Autoconf works, so let's not question for a moment whether 
changing an option's default this way actually makes sense.

The gory details are here:

https://review.openocd.org/c/openocd/+/8892

The configure.ac code is complicated, but basically it boils down to this 
(simplified):

AC_ARG_ENABLE(some-option,
  AS_HELP_STRING([--enable-some-option=[[[yes/no/auto]]]],
                 [blah blah (default is $someDefault)])

The trouble is, when I run "./configure --help", the $someDefault variable 
appears as a literal, that is, it is not being substituted. I tried with an M4 macro 
instead of a shell variable, to no avail.

After a while struggling with this weird Autoconf behaviour, I came up with 
this test:

AS_IF([test "a" = "a"], [
  AC_MSG_NOTICE([true branch])
  
AC_ARG_ENABLE([argname-true-branch],AS_HELP_STRING([--enable-argname-true-branch],[Help
 string for the true branch]))
], [
  AC_MSG_NOTICE([false branch])
  
AC_ARG_ENABLE([argname-false-branch],AS_HELP_STRING([--enable-argname-false-branch],[Help
 string for the false branch]))
])

The output when running "./configure --help" is:
--enable-argname-true-branch  Help string for the true branch
--enable-argname-false-branch Help string for the false branch

That is, both AS_IF branches are being evaluated when generating the help text. Compare 
with the output when running "./configure":
  configure: true branch
In this case, only the true branch runs, as expected.

My guess is that "./configure --help" is not evaluating the script properly, 
but it is just grepping all AC_ARG_ENABLE occurrences and doing some minimal M4 parsing 
which does not include normal variable or M4 macro substitution.

Can someone confirm this suspicion?

I searched for AC_ARG_ENABLE in the Autoconf manual, and the Internet for this 
behaviour, but I couldn't find anything relevant.

Is there any way to have AC_ARG_ENABLE and/or AS_HELP_STRING evaluate arguments properly 
when running "./configure --help"? Or did I miss something? I am no Autoconf 
expert.

Thanks in advance,
  rdiez


Reply via email to