-## Syntax check with default Perl (on my machine, Perl 5).
-sc_perl_syntax:
- @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w automake
- @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w aclocal
+# I'm a lazy typist.
+lint: maintainer-check
+.PHONY: lint
+
+# The recipes of syntax checks require a modern GNU grep.
+sc_sanity_gnu_grep:
+ $(AM_V_GEN)grep --version | grep 'GNU grep' >/dev/null 2>&1 \
+ && ab=$$(printf 'a\nb') \
+ && test "$$(printf 'xa\nb\nc' | grep -Pzo 'a\nb')" = "$$ab" \
+ || { \
+ echo "Syntax checks recipes require a modern GNU grep" >&2; \
+ exit 1; \
+ }
+.PHONY: sc_sanity_gnu_grep
+$(syntax_check_rules): sc_sanity_gnu_grep
+
+# These check avoids accidental configure substitutions in the source.
+# There are exactly 8 lines that should be modified from automake.in to
+# automake, and 9 lines that should be modified from aclocal.in to
+# aclocal.
+automake_diff_no = 8
+aclocal_diff_no = 9
+sc_diff_automake sc_diff_aclocal: sc_diff_% :
+ @set +e; tmp=$*-diffs.tmp; \
+ diff -u $(srcdir)/$*.in $* > $$tmp; test $$? -eq 1 || exit 1; \
+ added=`grep -v '^+++ ' $$tmp | grep -c '^+'` || exit 1; \
+ removed=`grep -v '^--- ' $$tmp | grep -c '^-'` || exit 1; \
+ test $$added,$$removed = $($*_diff_no),$($*_diff_no) \
+ || { \
+ echo "Found unexpected diffs between $*.in and $*"; \
+ echo "Lines added: $$added" ; \
+ echo "Lines removed: $$removed"; \
+ cat $$tmp >&2; \
+ exit 1; \
+ } >&1; \
+ rm -f $$tmp