"Help" string variable substitution for "configure --help"

476 views Asked by At

I have a string that I want to use multiple times for the output of configure --help. So I try doing something like this in configure.ac:

AC_ARG_ENABLE([foobar],
              AS_HELP_STRING([--enable-foobar], [$foobar_help_str]))

But no expansion or substitution is done, so the output is just $foobar_help_str.

2

There are 2 answers

1
ptomato On BEST ANSWER

Define the string as an M4 macro:

m4_define([FOOBAR_HELP_STR], [Turn on the foobar features])
AC_ARG_ENABLE([foobar], [AS_HELP_STRING([--enable-foobar], FOOBAR_HELP_STR)])
0
Greg A. Woods On

FYI, if you look at the generated configure script you'll see that the help text is all pre-formatted into one blob of text in a quoted "here document" (sent to stdout by cat), i.e. there's no opportunity whatsoever for any form of substitution to happen at the time the script runs (i.e. when you run it as ./configure --help). One could no doubt argue this is a bug, but on the other hand since the processing done by autoconf to pretty-print the help text is done without any knowledge of how the final script will execute, and thus without any idea what variables might be set and what range of values they might take on, autoconf has no way to know how much space to allocate in its formatting of the help text for whatever value(s) any variable might have at run-time.

For cases were only binary options are desired (i.e. where the [=ARG] feature is not used/needed), then it should be possible to write a smart wrapper macro which would generate appropriate help text based on the default setting, if that default is itself first defined as an M4 macro in a way similar to what was suggested in the accepted answer.