Discussion:
About dynamic configure options.
Stefano Lattarini
2012-12-13 12:58:30 UTC
Permalink
Hi Eduardo.
Hi,
Is it possible at all to have a configure option whose help message can expand a
variable, or can otherwise accept the output of a command at configure-time?
--with-user=user Who to complain to (default X)
Where X could be, say, the output of the command `whoami'.
This might be done by usual means (couldn't do it) or just with some
trickery to to inject the string manually at the end of some section
(say HELP_CANON or other), and giving the output of the command on a
new line, so it doesn't get inside the `cat << LABEL ... LABEL'
constructs that seem to be used to output options and help messages.
Thanks,
This question really pertains to Autoconf, not Automake. I'm thus
forwarding it to the Autoconf list, where somebody might be willing
to answer it (I haven't looked at it in detail, since I'm busy with
other stuff right now; I might give it a shot in a few days maybe,
but no promise).

HTH,
Stefano
Eric Blake
2012-12-13 17:20:30 UTC
Permalink
Post by Stefano Lattarini
Hi Eduardo.
Hi,
Is it possible at all to have a configure option whose help message can expand a
variable, or can otherwise accept the output of a command at configure-time?
--with-user=user Who to complain to (default X)
Where X could be, say, the output of the command `whoami'.
This might be done by usual means (couldn't do it) or just with some
trickery to to inject the string manually at the end of some section
(say HELP_CANON or other), and giving the output of the command on a
new line, so it doesn't get inside the `cat << LABEL ... LABEL'
constructs that seem to be used to output options and help messages.
Unfortunately, it looks like the current setup of autoconf is pretty
hard-coded to constant strings determined at m4-time; making it use
shell variables for dynamic output would require quite a bit of patching
(maybe by introducing new macros such as AC_ARG_WITH_UNQUOTED, to take
care of the tweaks needed to close the quoted heredoc, open an unquoted
heredoc to do the substitution, then reopen the quoted heredoc for the
rest of the script). It sounds like a useful request, though.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Nick Bowler
2012-12-13 19:25:53 UTC
Permalink
Post by Eric Blake
Is it possible at all to have a configure option whose help message can expand a
variable, or can otherwise accept the output of a command at configure-time?
--with-user=user Who to complain to (default X)
Where X could be, say, the output of the command `whoami'.
This might be done by usual means (couldn't do it) or just with some
trickery to to inject the string manually at the end of some section
(say HELP_CANON or other), and giving the output of the command on a
new line, so it doesn't get inside the `cat << LABEL ... LABEL'
constructs that seem to be used to output options and help messages.
Unfortunately, it looks like the current setup of autoconf is pretty
hard-coded to constant strings determined at m4-time; making it use
shell variables for dynamic output would require quite a bit of patching
(maybe by introducing new macros such as AC_ARG_WITH_UNQUOTED, to take
care of the tweaks needed to close the quoted heredoc, open an unquoted
heredoc to do the substitution, then reopen the quoted heredoc for the
rest of the script). It sounds like a useful request, though.
FWIW it's not too hard to hack it:

AC_ARG_WITH([user], [_ACEOF
# Eschew error handling!
me=`whoami`
cat <<EOF dnl
m4_newline([AS_HELP_STRING([--with-user],
[Who to complain to (default $me)])])dnl
m4_newline([EOF])
cat <<\_ACEOF])

but that is, of course, relying on internal details of how Autoconf
generates the code to produce --help output. But there remain other
problems: firstly, the --help text appears quite early in the configure
output -- much earlier than the position of AC_ARG_WITH in configure.ac
would imply. This may make it hard to put anything useful in the help
text, without computing it directly in AC_ARG_WITH_UNQUOTED or whatever
(as done in the above example).

Secondly, regarding this specific example, I don't know if whoami is
universally available. So determining the default username is probably
within the realm of a "full" configure test, with at least one invocation
of AC_CHECK_PROGS. Such a test is almost certainly too much to do before
printing --help output.

Normally it is sufficient to just write the --help text as a static
string explaining how the default is determined. In the case of a
username like above, I would probably do something like:

--with-user=user Who to complain to (default: current user)

and then make the configure script print a line such as:

Checking which user will receive complaints... nbowler

Cheers,
--
Nick Bowler, Elliptic Technologies (http://www.elliptictech.com/)
Eduardo Costa
2012-12-13 22:22:55 UTC
Permalink
Thanks guys,

I actually sent a "solution" much like yours Nick. Don't know why
Stefano didn't send my answer. This is what I came up with:

AC_DEFUN([TRICK],
[m4_divert_text([HELP_CANON], [_ACEOF
echo -en "\n* --option=VAL Date: `date`"
cat <<\_ACEOF])])

TRICK

You can see automake's archives for my whole message.

Te code above will get hooked at the end of `HELP_CANON' (before the
`heredoc' ends), or after the `Fine tuning' options if canonical
support macros hasn't been called.

Something that did surprise by looking at `general.m4' is that
sections such as HELP_CANON, HELP_BEGIN, etc, have all been allocated
sequentially, leaving no room for per-project customization.

This is just my ignorant's opinion. I'm far from being a m4, autoconf,
or automake specialist.

Thanks,
Post by Nick Bowler
Post by Eric Blake
Is it possible at all to have a configure option whose help message can expand a
variable, or can otherwise accept the output of a command at configure-time?
--with-user=user Who to complain to (default X)
Where X could be, say, the output of the command `whoami'.
This might be done by usual means (couldn't do it) or just with some
trickery to to inject the string manually at the end of some section
(say HELP_CANON or other), and giving the output of the command on a
new line, so it doesn't get inside the `cat << LABEL ... LABEL'
constructs that seem to be used to output options and help messages.
Unfortunately, it looks like the current setup of autoconf is pretty
hard-coded to constant strings determined at m4-time; making it use
shell variables for dynamic output would require quite a bit of patching
(maybe by introducing new macros such as AC_ARG_WITH_UNQUOTED, to take
care of the tweaks needed to close the quoted heredoc, open an unquoted
heredoc to do the substitution, then reopen the quoted heredoc for the
rest of the script). It sounds like a useful request, though.
AC_ARG_WITH([user], [_ACEOF
# Eschew error handling!
me=`whoami`
cat <<EOF dnl
m4_newline([AS_HELP_STRING([--with-user],
[Who to complain to (default $me)])])dnl
m4_newline([EOF])
cat <<\_ACEOF])
but that is, of course, relying on internal details of how Autoconf
generates the code to produce --help output. But there remain other
problems: firstly, the --help text appears quite early in the configure
output -- much earlier than the position of AC_ARG_WITH in configure.ac
would imply. This may make it hard to put anything useful in the help
text, without computing it directly in AC_ARG_WITH_UNQUOTED or whatever
(as done in the above example).
Secondly, regarding this specific example, I don't know if whoami is
universally available. So determining the default username is probably
within the realm of a "full" configure test, with at least one invocation
of AC_CHECK_PROGS. Such a test is almost certainly too much to do before
printing --help output.
Normally it is sufficient to just write the --help text as a static
string explaining how the default is determined. In the case of a
--with-user=user Who to complain to (default: current user)
Checking which user will receive complaints... nbowler
Cheers,
--
Nick Bowler, Elliptic Technologies (http://www.elliptictech.com/)
Stefano Lattarini
2012-12-14 08:49:24 UTC
Permalink
Post by Eduardo Costa
Thanks guys,
I actually sent a "solution" much like yours Nick. Don't know
why Stefano didn't send my answer.
You mean this part?

This might be done by usual means (couldn't do it) or just with some
trickery to to inject the string manually at the end of some section
(say HELP_CANON or other), and giving the output of the command on a
new line, so it doesn't get inside the `cat << LABEL ... LABEL'
constructs that seem to be used to output options and help messages.

But I did send it ...
Post by Eduardo Costa
AC_DEFUN([TRICK],
[m4_divert_text([HELP_CANON], [_ACEOF
echo -en "\n* --option=VAL Date: `date`"
cat <<\_ACEOF])])
TRICK
You can see automake's archives for my whole message.
Here's the link BTW:

<http://lists.gnu.org/archive/html/automake/2012-12/msg00022.html>

And looking at my forward to the Autoconf list:

<http://lists.gnu.org/archive/html/autoconf/2012-12/msg00018.html>

you can see I quoted your original message in its entirety. Am I
missing something else here?

Regards,
Stefano
Eduardo Costa
2012-12-14 17:22:57 UTC
Permalink
Hi Stefano,

Sorry then!, I was a bit in a hurry yesterday. So they can have an idea then.

Thanks,
Post by Stefano Lattarini
Post by Eduardo Costa
Thanks guys,
I actually sent a "solution" much like yours Nick. Don't know
why Stefano didn't send my answer.
You mean this part?
This might be done by usual means (couldn't do it) or just with some
trickery to to inject the string manually at the end of some section
(say HELP_CANON or other), and giving the output of the command on a
new line, so it doesn't get inside the `cat << LABEL ... LABEL'
constructs that seem to be used to output options and help messages.
But I did send it ...
Post by Eduardo Costa
AC_DEFUN([TRICK],
[m4_divert_text([HELP_CANON], [_ACEOF
echo -en "\n* --option=VAL Date: `date`"
cat <<\_ACEOF])])
TRICK
You can see automake's archives for my whole message.
<http://lists.gnu.org/archive/html/automake/2012-12/msg00022.html>
<http://lists.gnu.org/archive/html/autoconf/2012-12/msg00018.html>
you can see I quoted your original message in its entirety. Am I
missing something else here?
Regards,
Stefano
Loading...