3

Is there a way to get AS_HELP_STRING (or there's some alternative macro) to nicely format help on multiple lines?

I've an --enable-option= which may take multiple values val1,val2,... and I'd like configure --help to show one help line for each value.

Alex
  • 3,264
  • 1
  • 25
  • 40
  • I've found this very frustrating too, e.g., when I want a brief description of different options *underneath* the: `--enable-foo[=yes] ... [basic description]` - sometimes it makes me abandon `AS_HELP_STRING` and use manual indentation to make the message look 'nice'. – Brett Hale Aug 21 '15 at 11:18
  • It's (typically) defined in `./share/autoconf/m4sugar/m4sh.m4` - and I keep putting off learning M4. This isn't a bug, but a feature request to the autoconf maintainers might be worthwhile. Unfortunately `2.7x` has been stalled for a long time. – Brett Hale Aug 21 '15 at 11:22
  • 1
    *m4* must be the macro language of some ancient alien ... – Alex Aug 21 '15 at 12:18
  • 3
    It's actually been found written on ancient neolithic cave walls, and mistakenly believed to be hieroglyphs inside the the pyramids. – Brett Hale Aug 21 '15 at 12:23
  • So, looking at `m4sh.m4` there's no way it handle multiple line, any way to wrap it in a loop? (I took a look at looping with m4... hence the comment above) – Alex Aug 21 '15 at 12:50

1 Answers1

2

I had written my own NA_HELP_STRINGS() macro for this kind of situations:

dnl  NA_HELP_STRINGS(list1, help1[, list2, help2[, ... listN, helpN]])
dnl  **************************************************************************
dnl
dnl  Similar to `AS_HELP_STRING()`, but with support for multiple strings, each
dnl  one associated with one or more options
dnl
dnl  From: https://github.com/madmurphy/not-autotools
dnl
dnl  **************************************************************************
m4_define([NA_HELP_STRINGS],
    [m4_if(m4_count($1), [1],
        [m4_if([$#], [0], [], [$#], [1],
            [m4_text_wrap($1, [  ])],
            [AS_HELP_STRING(m4_normalize($1), [$2])m4_if([$#], [2], [], [m4_newline()NA_HELP_STRINGS(m4_shift2($@))])])],
        [m4_text_wrap(m4_argn(1, $1)[,], [  ])m4_newline()NA_HELP_STRINGS(m4_dquote(m4_shift($1))m4_if([$#], [1], [], [, m4_shift($@)]))])])

Sample usage:

AC_ARG_ENABLE([foo],
    [NA_HELP_STRINGS(
        [--disable-foo],
            [disable the `foo` feature; on some machines the package might not
            work properly without the `foo` feature enabled],
        [[--enable-foo], [--enable-foo=yes], [--enable-foo=enhanced]],
            [install this package with the `foo` feature enabled; if `foo` is
            enabled in `enhanced` mode Autoconf might get sentimental],
        [[--enable-foo=auto], [--enable-foo=check], [@<:@omitted@:>@]],
            [decide automatically whether it is opportune to enable the `foo`
            feature on this machine or not]
    )],
    [:],
    [AS_VAR_SET([enable_foo], ['check'])])

Output when the user launches ./configure --help:

  --disable-foo           disable the `foo` feature; on some machines the
                          package might not work properly without the `foo`
                          feature enabled
  --enable-foo,
  --enable-foo=yes,
  --enable-foo=enhanced   install this package with the `foo` feature enabled;
                          if `foo` is enabled in `enhanced` mode Autoconf
                          might get sentimental
  --enable-foo=auto,
  --enable-foo=check,
  [omitted]               decide automatically whether it is opportune to
                          enable the `foo` feature on this machine or not

For more m4-ish examples please have a look at the Not Autotools project.

madmurphy
  • 1,451
  • 11
  • 20
  • 1
    Thanks @madmurphy, it's been a while since I needed to use autotools, accepted on trust – Alex Dec 05 '19 at 11:27
  • 1
    This is a really good work. You should consider contributing a version of it to the [Autoconf Archive](https://www.gnu.org/software/autoconf-archive/). – Brett Hale Oct 05 '20 at 12:27
  • Thank you, Brett! I [just had a discussion](https://github.com/madmurphy/not-autotools/issues/1) today at my _Not Autotools_ repository about contributing to the Autoconf Archive. The truth is that I would not have time for that. Also, publishing macros in a repository with a large base of users would be quite a responsibility. I would be happy though if someone interested published my macros in AX. – madmurphy Oct 07 '20 at 01:18