On 12/14/18, Reuben Thomas wrote:
> What's the right way to do this? I currently have:
>
> AC_ARG_VAR([WORD_SIZE],
> [value of WORD_SIZE register [default: sizeof(long)]])
> if "$ac_cv_env_WORD_SIZE_set" != set; then
> AC_CHECK_SIZEOF([long])
> ac_cv_env_WORD_SIZE_value=SIZEOF_LONG
> fi
>
> which seems to work, but I'm conscious that I'm relying on undocumented
> variable names (ac_cv_env_*). I can't seem to get the same effect with, for
> example:
>
> AC_CHECK_SIZEOF([long])
> AC_SUBST([WORD_SIZE], [SIZEOF_LONG])
> AC_ARG_VAR([WORD_SIZE],
> [value of WORD_SIZE register [default: sizeof(long)]])
>
> (the AC_SUBST overrides whatever AC_ARG_VAR does, it seems).
AC_ARG_VAR doesn't actually set the variable to anything. That's up to
you. In essence, the only thing it does is[1]:
- Adds some help text to configure --help,
- Causes configure to save its _original_ value from the environment,
so that config.status --recheck can replay that value and work properly,
- When using a cache, it makes it an error to change the value in the
environment between configure runs (without cleaning first) because that
probably invalidates the cached results.
- It also does AC_SUBST on the variable because why not.
If you want to set a value to a variable only if the variable is
unset, a typical way to do that in shell programming is:
: "${FOO=value-if-unset}"
Or if you prefer also to set it the variable is _empty_ (i.e., including
the case where it is set to the empty string):
: "${FOO:=value-if-empty}"
[1]
https://www.gnu.org/software/autoconf/manual/autoconf.html#index-AC_005fARG_005fVAR-1209
Cheers,
Nick