@@ -564,6 +564,16 @@ $(objpfx)check-wrapper-headers.out: scripts/check-wrapper-headers.py $(headers)
--generated $(common-generated) > $@; $(evaluate-test)
endif # $(headers)
+# Lint all Makefiles; including this one. Pass `pwd` as the source
+# directory since the top-level Makefile is in the root of the source
+# tree and these tests are run from there. We add light-weight linting
+# to the 'check' target to support the existing developer workflow of:
+# edit -> make -> make check; without needing an additional step.
+tests-special += $(objpfx)lint-makefiles.out
+$(objpfx)lint-makefiles.out: scripts/lint-makefiles.sh
+ $(SHELL) $< "$(PYTHON)" `pwd` > $@ ; \
+ $(evaluate-test)
+
define summarize-tests
@grep -E -v '^(PASS|XFAIL):' $(objpfx)$1 || true
@echo "Summary of test results$2:"
new file mode 100644
@@ -0,0 +1,57 @@
+#!/bin/bash
+# Copyright (C) 2023 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library 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
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <https://www.gnu.org/licenses/>.
+
+# This script checks to see that all Makefiles in the source tree
+# conform to the sorted variable rules as defined by:
+# scripts/sort-makefile-lines.py.
+# Any difference is an error and should be corrected e.g. the lines
+# reordered to sort correctly.
+# The intent with this check is to ensure that changes made by
+# developers match the expected format for the project.
+
+set -e
+export LC_ALL=C
+
+tmpfile="$(mktemp)"
+
+cleanup () {
+ rm -f -- "$tmpfile"
+}
+
+trap cleanup 0
+
+PYTHON=$1
+# Absolute or relative path to the source directory.
+srcdir=$2
+
+# Must specify $PYTHON.
+test -n "$PYTHON"
+# Absolute or relative $srcdir must exist and be a directory.
+test -d "$srcdir"
+
+echo "Linting Makefiles:"
+echo "Check: Are all lines sorted correctly?"
+linted=0
+for mfile in `find "$srcdir" -name Makefile`; do
+ echo "$mfile"
+ $PYTHON "${srcdir}/scripts/sort-makefile-lines.py" < "$mfile" > "$tmpfile"
+ diff -q "$mfile" "$tmpfile"
+ linted=$(( linted++ ))
+done
+# Must have linted at least the top-level Makefile
+test $linted -ge 1