Search code examples
configureautoconf

Can you override the default configure help message generated as part of running autoconf?


I would like to modify a configure.ac script so that when I generate it's configure script via autoconf, it will have a custom help message.

E.g:

$autoconf
$./configure --help

yields

"Hello World"

Instead of the default which talks about fine tuning installation directories and modifying build flags.

Is this possible?


Solution

  • Look at _AC_INIT_HELP macro in autoconf general.m4 script. It is responsible for printing the help message.

    This script inserts text to different diversions, as listed in general.m4:

    dnl The order of the diversions here is
    dnl - HELP_BEGIN
    dnl   which may be extended by extra generic options such as with X or
    dnl   AC_ARG_PROGRAM.  Displayed only in long --help.
    dnl
    dnl - HELP_CANON
    dnl   Support for cross compilation (--build, --host and --target).
    dnl   Display only in long --help.
    dnl
    dnl - HELP_ENABLE
    dnl   which starts with the trailer of the HELP_BEGIN, HELP_CANON section,
    dnl   then implements the header of the non generic options.
    dnl
    dnl - HELP_WITH
    dnl
    dnl - HELP_VAR
    dnl
    dnl - HELP_VAR_END
    dnl
    dnl - HELP_END
    dnl   initialized below, in which we dump the trailer (handling of the
    dnl   recursion for instance).
    

    The simplest way to display Hello World help message would be to just insert following code at the end of your configure.ac file:

    m4_cleardivert([HELP_BEGIN])dnl
    m4_cleardivert([HELP_CANON])dnl
    m4_cleardivert([HELP_ENABLE])dnl
    m4_cleardivert([HELP_WITH])dnl
    m4_cleardivert([HELP_VAR])dnl
    m4_cleardivert([HELP_VAR_END])dnl
    m4_cleardivert([HELP_END])dnl
    m4_divert_push([HELP_BEGIN])dnl
      cat <<_ACEOF
    Hello World
    _ACEOF
    m4_divert_pop([HELP_BEGIN])dnl
    m4_divert_push([HELP_END])dnl
    exit 0
    m4_divert_pop([HELP_END])dnl
    

    It will clear all the diversions and insert your custom text without the need of including any custom m4 scripts. exit is needed to stop processing configure script when help is displayed.


    If you want to introduce more changes to help text you may include your own m4 script at the beginning of configure.ac file:

    m4_include([custom_help.m4])
    

    Copy _AC_INIT_HELP macro to your custom_help.m4 script and modify it according to your needs.