+# FIXME: add a check to prohibit definition in src/*.c of symbols defined
+# in system.h. E.g. today I removed from tail.c a useless definition of
+# ENOSYS. It was useless because system.h ensures it's defined.
+
+# Checks that don't require cvs.
+# Run `changelog-check' last, as previous test may reveal problems requiring
+# new ChangeLog entries.
+local-checks-available = \
+ po-check copyright-check writable-files m4-check author_mark_check \
+ changelog-check strftime-check $(syntax-check-rules) \
+ makefile_path_separator_check \
+ makefile-check
+.PHONY: $(local-checks-available)
+
+local-check = $(filter-out $(local-checks-to-skip), $(local-checks-available))
+
+.PHONY: $(syntax-check-rules)
+syntax-check-rules = \
+ sc_cast_of_argument_to_free \
+ sc_cast_of_x_alloc_return_value \
+ sc_cast_of_alloca_return_value \
+ sc_changelog \
+ sc_dd_max_sym_length \
+ sc_error_exit_success \
+ sc_file_system \
+ sc_no_if_have_config_h \
+ sc_obsolete_symbols \
+ sc_prohibit_atoi_atof \
+ sc_prohibit_jm_in_m4 \
+ sc_prohibit_assert_without_use \
+ sc_require_config_h \
+ sc_root_tests \
+ sc_space_tab \
+ sc_sun_os_names \
+ sc_system_h_headers \
+ sc_tight_scope \
+ sc_trailing_blank \
+ sc_two_space_separator_in_usage \
+ sc_unmarked_diagnostics \
+ sc_useless_cpp_parens
+
+syntax-check: $(syntax-check-rules)
+# @grep -nE '# *include <(limits|std(def|arg|bool))\.h>' \
+# $$(find -type f -name '*.[chly]') && \
+# { echo '$(ME): found conditional include' 1>&2; \
+# exit 1; } || :
+
+# grep -nE '^# *include <(string|stdlib)\.h>' \
+# $(srcdir)/{lib,src}/*.[chy] && \
+# { echo '$(ME): FIXME' 1>&2; \
+# exit 1; } || :
+# FIXME: don't allow `#include .strings\.h' anywhere
+
+sc_cast_of_argument_to_free:
+ @grep -nE '\<free \(\(' $(srcdir)/{lib,src}/*.[chly] && \
+ { echo '$(ME): don'\''t cast free argument' 1>&2; \
+ exit 1; } || :
+
+sc_cast_of_x_alloc_return_value:
+ @grep -nE --exclude=$(srcdir)/lib/regex.c \
+ '\*\) *x(m|c|re)alloc\>' \
+ $(srcdir)/{lib,src}/*.[chy] && \
+ { echo '$(ME): don'\''t cast x*alloc return value' 1>&2; \
+ exit 1; } || :
+
+sc_cast_of_alloca_return_value:
+ @grep -nE '\*\) *alloca\>' \
+ $(srcdir)/src/*.[chy] && \
+ { echo '$(ME): don'\''t cast alloca return value' 1>&2; \
+ exit 1; } || :
+
+sc_space_tab:
+ @grep -n '[ ] ' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): found SPACE-TAB sequence; remove the SPACE' \
+ 1>&2; exit 1; } || :
+
+# Don't use the old ato* functions in `real' code.
+# They provide no error checking mechanism.
+# Instead, use strto* functions.
+sc_prohibit_atoi_atof:
+ @grep -nE '\<ato([filq]|ll)\>' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): do not use ato''f, ato''i, ato''l, ato''ll, or ato''q' \
+ 1>&2; exit 1; } || :
+
+# Using EXIT_SUCCESS as the first argument to error is misleading,
+# since when that parameter is 0, error does not exit. Use `0' instead.
+sc_error_exit_success:
+ @grep -nF 'error (EXIT_SUCCESS,' \
+ $$(find -type f -name '*.[chly]') && \
+ { echo '$(ME): found error (EXIT_SUCCESS' 1>&2; \
+ exit 1; } || :
+
+sc_file_system:
+ @grep -ni 'file''system' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): found use of "file''system";' \
+ 'rewrite to use "file system"' 1>&2; \
+ exit 1; } || :
+
+sc_no_if_have_config_h:
+ @grep -n '^# *if HAVE_CONFIG_H' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): found use of #if HAVE_CONFIG_H; use #ifdef' \
+ 1>&2; exit 1; } || :
+
+# Nearly all .c files must include <config.h>.
+sc_require_config_h:
+ @grep -L '^# *include <config\.h>' \
+ $$($(CVS_LIST_EXCEPT) | grep '\.c$$') \
+ | grep . && \
+ { echo '$(ME): the above files do not include <config.h>' \
+ 1>&2; exit 1; } || :
+
+# Prohibit the inclusion of assert.h without an actual use of assert.
+sc_prohibit_assert_without_use:
+ @files=$$(grep -l '# *include <assert\.h>' \
+ $$($(CVS_LIST_EXCEPT) | grep '\.c$$')) && \
+ grep -L '\<assert (' $$files \
+ | grep . && \
+ { echo "$(ME): the above files include <assert.h> but don't use it" \
+ 1>&2; exit 1; } || :
+
+sc_obsolete_symbols:
+ @grep -nE '\<(HAVE''_FCNTL_H|O''_NDELAY)\>' \
+ $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): do not use HAVE''_FCNTL_H or O''_NDELAY' \
+ 1>&2; exit 1; } || :
+
+# FIXME: warn about definitions of EXIT_FAILURE, EXIT_SUCCESS, STREQ
+
+# Each nonempty line must start with a year number, or a TAB.
+sc_changelog:
+ @grep -n '^[^12 ]' $$(find . -maxdepth 2 -name ChangeLog) && \
+ { echo '$(ME): found unexpected prefix in a ChangeLog' 1>&2; \
+ exit 1; } || :
+
+# Ensure that dd's definition of LONGEST_SYMBOL stays in sync
+# with the strings from the two affected variables.
+dd_c = $(srcdir)/src/dd.c
+sc_dd_max_sym_length:
+ifneq ($(wildcard $(dd_c)),)
+ @len=$$( (sed -n '/conversions\[\] =$$/,/^};/p' $(dd_c);\
+ sed -n '/flags\[\] =$$/,/^};/p' $(dd_c) ) \
+ |sed -n '/"/s/^[^"]*"\([^"]*\)".*/\1/p' \
+ | wc --max-line-length); \
+ max=$$(sed -n '/^#define LONGEST_SYMBOL /s///p' $(dd_c) \
+ |tr -d '"' | wc --max-line-length); \
+ if test "$$len" = "$$max"; then :; else \
+ echo 'dd.c: LONGEST_SYMBOL is not longest' 1>&2; \
+ exit 1; \
+ fi
+endif
+
+# Many m4 macros names once began with `jm_'.
+# On 2004-04-13, they were all changed to start with gl_ instead.
+# Make sure that none are inadvertently reintroduced.
+sc_prohibit_jm_in_m4:
+ @grep -nE 'jm_[A-Z]' \
+ $$($(CVS_LIST) $(srcdir)/m4 |grep '\.m4$$') && \
+ { echo '$(ME): do not use jm_ in m4 macro names' \
+ 1>&2; exit 1; } || :
+
+sc_root_tests:
+ @t1=sc-root.expected; t2=sc-root.actual; \
+ grep -nl '^PRIV_CHECK_ARG=require-root' \
+ $$($(CVS_LIST) tests) |sed s,tests,., |sort > $$t1; \
+ sed -n 's, cd \([^ ]*\) .*MAKE..check TESTS=\(.*\),./\1/\2,p' \
+ $(srcdir)/tests/Makefile.am |sort > $$t2; \
+ diff -u $$t1 $$t2 || diff=1; \
+ rm -f $$t1 $$t2; \
+ test "$$diff" \
+ && { echo 'tests/Makefile.am: missing check-root action'>&2; \
+ exit 1; } || :
+
+# Create a list of regular expressions matching the names
+# of files included from system.h. Exclude a couple.
+.re-list:
+ @sed -n '/^# *include /s///p' $(srcdir)/src/system.h \
+ | grep -Ev 'sys/(param|file)\.h' \
+ | sed 's/ .*//;;s/^["<]/^# *include [<"]/;s/\.h[">]$$/\\.h[">]/' \
+ > $@-t
+ @mv $@-t $@
+
+# Files in src/ should not include directly any of
+# the headers already included via system.h.
+sc_system_h_headers: .re-list
+ @if test -f $(srcdir)/src/system.h; then \
+ trap 'rc=$$?; rm -f .re-list; exit $$rc' 0 1 2 3 15; \
+ grep -nE -f .re-list \
+ $$($(CVS_LIST) src | \
+ grep -Ev '((copy|system)\.h|parse-gram\.c)$$') \
+ && { echo '$(ME): the above are already included via system.h'\
+ 1>&2; exit 1; } || :; \
+ fi
+
+sc_sun_os_names:
+ @grep -nEi \
+ 'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \
+ $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): found misuse of Sun OS version numbers' 1>&2; \
+ exit 1; } || :
+
+sc_tight_scope:
+ $(MAKE) -C src $@
+
+sc_trailing_blank:
+ @grep -n '[ ]$$' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): found trailing blank(s)' \
+ 1>&2; exit 1; } || :
+
+sc_two_space_separator_in_usage:
+ @grep -n '^ *--[a-z][0-9A-Za-z-]* [^ ].*\\$$' \
+ $$($(CVS_LIST_EXCEPT)) && \
+ { echo "$(ME): help2man requires at least two spaces between"; \
+ echo "$(ME): an option and its description"; \
+ 1>&2; exit 1; } || :
+
+# Look for diagnostics that aren't marked for translation.
+# This won't find any for which error's format string is on a separate line.
+sc_unmarked_diagnostics:
+ @grep -nE \
+ '\<error \([^"]*"[^"]*[a-z]{3}' $$($(CVS_LIST_EXCEPT)) \
+ | grep -v '_''(' && \
+ { echo '$(ME): found unmarked diagnostic(s)' 1>&2; \
+ exit 1; } || :
+
+# Avoid useless parentheses like those in this example:
+# #if defined (SYMBOL) || defined (SYM2)
+sc_useless_cpp_parens:
+ @grep -n '^# *if .*defined *(' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): found useless parentheses in cpp directive' \
+ 1>&2; exit 1; } || :
+
+# Ensure that date's --help output stays in sync with the info
+# documentation for GNU strftime. The only exception is %N,
+# which date accepts but GNU strftime does not.
+extract_char = sed 's/^[^%][^%]*%\(.\).*/\1/'
+strftime-check:
+ if test -f $(srcdir)/src/date.c; then \
+ grep '^ %. ' $(srcdir)/src/date.c | sort \
+ | $(extract_char) > $@-src; \
+ { echo N; \
+ info libc date calendar format | grep '^ `%.'\' \
+ | $(extract_char); } | sort > $@-info; \
+ diff -u $@-src $@-info || exit 1; \
+ rm -f $@-src $@-info; \
+ fi
+
+# Ensure that we use only the standard $(VAR) notation,
+# not @...@ in Makefile.am, now that we can rely on automake
+# to emit a definition for each substituted variable.
+makefile-check:
+ grep -nE '@[A-Z_0-9]+@' `find . -name Makefile.am` \
+ && { echo 'Makefile.maint: use $$(...), not @...@' 1>&2; exit 1; } || :
+
+news-date-check: NEWS
+ today=`date +%Y-%m-%d`; \
+ if head NEWS | grep '^\*.* $(VERSION_REGEXP) ('$$today')' \
+ >/dev/null; then \
+ :; \
+ else \
+ echo "version or today's date is not in NEWS" 1>&2; \
+ exit 1; \
+ fi