Reputation: 33
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?
Upvotes: 3
Views: 208
Reputation: 12819
I tried the answer by baf, but found it caused "Hello world" to be printed unconditionally, regardless of --help
! This might be due to a version difference in autoconf
; I am using version 2.69.
What I found worked as a variation that checks $ac_init_help
and also only exits right after printing the message. This goes at the end of configure.ac
or configure.in
:
dnl# Clear the default help message.
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
dnl# Specify custom help.
m4_divert_push([HELP_BEGIN])dnl
if test "$ac_init_help" = "long"; then
cat <<_ACEOF
Hello world. Remember this is processed by M4, so you will need
to quote any string that contains square brackets, for example:
Usage: my-program [[options]] [[file [file..]]]
_ACEOF
# Stop after printing the help.
exit 0
fi
m4_divert_pop([HELP_BEGIN])dnl
Then it works both with and without --help
:
$ ./configure --help
Hello world. Remember this is processed by M4, so you will need
to quote any string that contains square brackets, for example:
Usage: my-program [options] [file [file..]]
$ ./configure
checking for gcc... gcc
[...]
Upvotes: 0
Reputation: 4671
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.
Upvotes: 2