autoconf/lib/local.mk
Zack Weinberg aba75f6d4a
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.
2020-08-18 08:24:05 -04:00

198 lines
6.1 KiB
Makefile

# Make Autoconf-related libraries.
# Copyright (C) 2001-2005, 2009-2017, 2020 Free Software Foundation,
# Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
ETAGS_ARGS += $(ETAGS_FOR_AUTOCONF)
TAGS_FILES = # Incrementally updated later.
# Additional checks.
check-local: check-forbidden-patterns
forbidden_patterns = -e '^_*EOF' -e ' cmp '
forbidden_patterns_files = # Incrementally updated later.
## ---------------------------------------------------------------- ##
## Auxiliary perl modules used by autom4te and other perl scripts. ##
## ---------------------------------------------------------------- ##
perllibdir = $(pkgdatadir)/Autom4te
dist_perllib_DATA = \
lib/Autom4te/C4che.pm \
lib/Autom4te/ChannelDefs.pm \
lib/Autom4te/Channels.pm \
lib/Autom4te/Configure_ac.pm \
lib/Autom4te/FileUtils.pm \
lib/Autom4te/General.pm \
lib/Autom4te/Getopt.pm \
lib/Autom4te/Request.pm \
lib/Autom4te/XFile.pm
TAGS_FILES += $(dist_perllib_DATA)
# Note: ETAGS_ARGS should have already been extended to handle perl files.
## ------------------------------------------ ##
## Make Autom4te default configuration file. ##
## ------------------------------------------ ##
nodist_pkgdata_DATA = lib/autom4te.cfg
EXTRA_DIST += lib/autom4te.in
# All the files below depend on Makefile so that they are rebuilt
# when the prefix, etc. changes. Unfortunately, suffix rules
# cannot have additional dependencies, so we have to use explicit rules.
CLEANFILES += lib/autom4te.cfg
lib/autom4te.cfg: $(srcdir)/lib/autom4te.in Makefile
rm -f $@ $@-t
$(MKDIR_P) $(@D)
$(edit) $(srcdir)/lib/autom4te.in >$@-t
chmod a-w $@-t
mv -f $@-t $@
## ----------------------------- ##
## Make Autoconf Emacs library. ##
## ----------------------------- ##
dist_lisp_LISP = lib/emacs/autoconf-mode.el lib/emacs/autotest-mode.el
# TODO: This is required to work around a limitation in older
# Automake. Remove once we can assume Automake 1.13 or later.
CLEANFILES += autoconf-mode.elc autotest-mode.elc
## ----------------------- ##
## Make Autoconf library. ##
## ----------------------- ##
autoconflibdir = $(pkgdatadir)/autoconf
dist_autoconflib_DATA = \
lib/autoconf/autoconf.m4 \
lib/autoconf/general.m4 \
lib/autoconf/status.m4 \
lib/autoconf/oldnames.m4 \
lib/autoconf/specific.m4 \
lib/autoconf/autoheader.m4 \
lib/autoconf/autoupdate.m4 \
lib/autoconf/autotest.m4 \
lib/autoconf/autoscan.m4 \
lib/autoconf/lang.m4 \
lib/autoconf/c.m4 \
lib/autoconf/erlang.m4 \
lib/autoconf/fortran.m4 \
lib/autoconf/functions.m4 \
lib/autoconf/go.m4 \
lib/autoconf/headers.m4 \
lib/autoconf/types.m4 \
lib/autoconf/libs.m4 \
lib/autoconf/programs.m4 \
lib/autoconf/trailer.m4
nodist_autoconflib_DATA = lib/autoconf/autoconf.m4f
CLEANFILES += $(nodist_autoconflib_DATA)
TAGS_FILES += $(dist_autoconflib_DATA)
forbidden_patterns_files += $(dist_autoconflib_DATA)
lib/autoconf/autoconf.m4f: $(autoconf_m4f_dependencies)
## ------------------------ ##
## Make Autoscan library. ##
## ------------------------ ##
autoscanlibdir = $(pkgdatadir)/autoscan
EXTRA_DIST += lib/autoscan/autoscan.pre
nodist_autoscanlib_DATA = lib/autoscan/autoscan.list
CLEANFILES += lib/autoscan/autoscan.list
lib/autoscan/autoscan.list: $(srcdir)/lib/autoscan/autoscan.pre
$(MKDIR_P) $(@D)
echo '# Automatically Generated: do not edit this file' >$@
sed '/^[#]/!q' $(srcdir)/lib/autoscan/autoscan.pre >>$@
( \
sed -n '/^[^#]/p' $(srcdir)/lib/autoscan/autoscan.pre; \
$(MY_AUTOM4TE) --cache '' -M -l autoconf-without-aclocal-m4 \
-t'AN_OUTPUT:$$1: $$2 $$3' \
) | LC_ALL=C sort >>$@
lib/autoscan/autoscan.list: $(autoconf_m4f_dependencies) Makefile
## ----------------------------------- ##
## Make Autoconf library for M4sugar. ##
## ----------------------------------- ##
m4sugarlibdir = $(pkgdatadir)/m4sugar
dist_m4sugarlib_DATA = \
lib/m4sugar/m4sugar.m4 \
lib/m4sugar/foreach.m4 \
lib/m4sugar/m4sh.m4
nodist_m4sugarlib_DATA = \
lib/m4sugar/version.m4 \
lib/m4sugar/m4sugar.m4f \
lib/m4sugar/m4sh.m4f
CLEANFILES += $(nodist_m4sugarlib_DATA)
# The ':;' in the second line of the recipe works around a redirected
# compound command bash exit status bug.
lib/m4sugar/version.m4: Makefile
$(MKDIR_P) $(@D)
:;{ \
echo '# This file is part of -*- Autoconf -*-.' && \
echo '# Version of Autoconf.' && \
echo '# Copyright (C) 1999, 2000, 2001, 2002, 2006, 2007, 2009' && \
echo '# Free Software Foundation, Inc.' && \
echo &&\
echo 'm4_define([m4_PACKAGE_NAME], [$(PACKAGE_NAME)])' && \
echo 'm4_define([m4_PACKAGE_TARNAME], [$(PACKAGE_TARNAME)])' && \
echo 'm4_define([m4_PACKAGE_VERSION], [$(PACKAGE_VERSION)])' && \
echo 'm4_define([m4_PACKAGE_STRING], [$(PACKAGE_STRING)])' && \
echo 'm4_define([m4_PACKAGE_BUGREPORT], [$(PACKAGE_BUGREPORT)])' && \
echo 'm4_define([m4_PACKAGE_URL], [$(PACKAGE_URL)])' && \
echo 'm4_define([m4_PACKAGE_YEAR], [$(RELEASE_YEAR)])'; \
} > $@-t
mv $@-t $@
TAGS_FILES += $(dist_m4sugarlib_DATA)
forbidden_patterns_files += $(dist_m4sugarlib_DATA)
lib/m4sugar/m4sugar.m4f: $(m4sugar_m4f_dependencies)
lib/m4sugar/m4sh.m4f: $(m4sh_m4f_dependencies)
## ----------------------- ##
## Make Autotest library. ##
## ----------------------- ##
autotestlibdir = $(pkgdatadir)/autotest
dist_autotestlib_DATA = \
lib/autotest/autotest.m4 \
lib/autotest/general.m4 \
lib/autotest/specific.m4
nodist_autotestlib_DATA = lib/autotest/autotest.m4f
CLEANFILES += $(nodist_autotestlib_DATA)
TAGS_FILES += $(dist_autotestlib_DATA)
forbidden_patterns_files += $(dist_autotestlib_DATA)
lib/autotest/autotest.m4f: $(autotest_m4f_dependencies)