diff options
author | Zack Weinberg <zackw@panix.com> | 2020-08-14 13:16:58 -0400 |
---|---|---|
committer | Zack Weinberg <zackw@panix.com> | 2020-08-18 08:24:05 -0400 |
commit | aba75f6d4a9c875a9d5d90a07c6b3678db66a4bf (patch) | |
tree | bd22316093ce106881b5d9d5574dbdbc65d72191 /bin | |
parent | 6a0c0239449a98181c5dd7e505cddbc0840471a4 (diff) | |
download | autoconf-aba75f6d4a9c875a9d5d90a07c6b3678db66a4bf.tar.gz |
Warn if AC_INIT or AC_OUTPUT are missing from configure.ac (#107986)
It is almost always incorrect for a configure script to omit either
AC_INIT or AC_OUTPUT. Issue warnings in the ‘syntax’ category for
this.
The implementation is, unfortunately, a bit of a kludge. To check for
the _absence_ of a macro invocation, we can use m4_provide_if inside a
m4_wrap hook. However, if we activate the m4_wrap hook directly from
general.m4, we get spurious warnings at freeze time. We also get
warnings whenever a script that’s missing AC_INIT and/or AC_OUTPUT
is *traced*, which means we get double warnings from autoconf, and
autoheader and aclocal complain about it too, which seems unnecessary.
A clean way to deal with this would be to make the hook look for a
special macro that’s defined only when autoconf (the program) is
invoked without any --trace arguments. Unfortunately, autom4te
doesn’t pass --define down to M4, and changing that would involve
coordinating with Automake (the project), so instead I’ve gone for the
kludge: a new file lib/autoconf/trailer.m4 that calls m4_wrap. This
file is *not* included in autoconf.m4f, but it’s installed, and it’s
added to the m4 invocation by autoconf (the program) only when not
tracing. (It still uses m4_wrap, because we pass it to m4 *before*
configure.ac, because otherwise we get nonsense locations for any
*other* diagnostics coming out of this autoconf invocation. I don’t
know why.)
The additional checks in autoreconf are intended to make sure that if
autoreconf skips a directory entirely, you get told why.
Lots of tests in the testsuite didn’t bother with AC_OUTPUT, and
somewhat fewer didn’t bother with AC_INIT; where possible I just added
them.
Suggested by David A. Wheeler, who submitted a patch, but I didn’t
wind up using any of his code. (His implementation used an extra
tracing pass, only checked for a missing AC_INIT, and invented a new
command-line option to turn off this specific warning. I thought this
was tidier overall, despite the kludge.)
* lib/autoconf/general.m4 (_AC_FINALIZE): New macro: code to be run
when generating configure, after the entire configure.ac is
processed. Currently only checks that AC_INIT and AC_OUTPUT were
called at some point, issuing syntax-category warnings if not.
(AC_INIT, AC_OUTPUT): m4_provide self.
* lib/autoconf/trailer.m4: New file that just calls m4_wrap([_AC_FINALIZE]).
* lib/local.mk: Install new file.
* bin/autoconf.as: Add trailer.m4 to the final invocation of autom4te,
but only when not tracing.
* bin/autoreconf.in (autoreconf_current_directory): Distinguish in
diagnostics between “directory skipped because it doesn’t have a
configure.ac or configure.in” (e.g. Cygnus configure) and “directory
has a configure.ac but it doesn’t appear to be autoconf input.”
* tests/*.at: Fix all tests affected by the new warnings.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/autoconf.as | 14 | ||||
-rw-r--r-- | bin/autoreconf.in | 14 |
2 files changed, 23 insertions, 5 deletions
diff --git a/bin/autoconf.as b/bin/autoconf.as index 581eb81e..ab6e3c52 100644 --- a/bin/autoconf.as +++ b/bin/autoconf.as @@ -85,6 +85,7 @@ exit_missing_arg=' # Variables. : ${AUTOM4TE='@bindir@/@autom4te-name@'} +: ${trailer_m4='@pkgdatadir@/autoconf/trailer.m4'} autom4te_options= outfile= verbose=false @@ -183,9 +184,20 @@ esac # Unless specified, the output is stdout. test -z "$outfile" && outfile=- +# Don't read trailer.m4 if we are tracing. +if test -n "$traces"; then + trailer_m4="" +else + # The extra quotes will be stripped by eval. + trailer_m4=\""$trailer_m4"\" +fi + # Run autom4te with expansion. +# trailer.m4 is read _before_ $infile, despite the name, +# because putting it afterward screws up autom4te's location tracing. eval set x "$autom4te_options" \ - --language=autoconf --output=\"\$outfile\" "$traces" \"\$infile\" + --language=autoconf --output=\"\$outfile\" "$traces" \ + $trailer_m4 \"\$infile\" shift $verbose && AS_ECHO(["$as_me: running $AUTOM4TE $*"]) >&2 exec "$AUTOM4TE" "$@" diff --git a/bin/autoreconf.in b/bin/autoreconf.in index 12806d3a..1ca11f28 100644 --- a/bin/autoreconf.in +++ b/bin/autoreconf.in @@ -245,8 +245,9 @@ sub parse_args () # &autoreconf_current_directory # ----------------------------- -sub autoreconf_current_directory () +sub autoreconf_current_directory ($) { + my ($directory) = @_; my $configure_ac = find_configure_ac; # ---------------------- # @@ -266,10 +267,15 @@ sub autoreconf_current_directory () # See below for why we look for gettext here. $uses_gettext = 1 if /^AM_GNU_GETTEXT_VERSION/; } + if (!$uses_autoconf) + { + error "$configure_ac: AC_INIT not found; not an autoconf script?"; + return; + } } - if (!$uses_autoconf) + else { - verb "$configure_ac: not using Autoconf"; + verb "neither configure.ac nor configure.in present in $directory"; return; } @@ -598,7 +604,7 @@ sub autoreconf ($) chdir $directory or error "cannot chdir to $directory: $!"; - autoreconf_current_directory; + autoreconf_current_directory ($directory); # The format is not free: taken from Emacs, itself using GNU Make's # format. |