From 8f043c699535cdb0ffa0dee8d624ca38aada2deb Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Fri, 3 Sep 2021 21:59:43 +0200 Subject: maintainer-makefile: Add indentation syntax-check rule. * top/maint.mk (indent): Use AM_V_GEN and indent_args. (sc_indent): New rule. (indent_args): New variable. (C_SOURCES): New variable, initialized to reasonable C files. (exclude_file_name_regexp--indent): New variable. --- ChangeLog | 9 +++++++++ top/maint.mk | 28 ++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1b1372cb76..51d1f3d37a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2021-09-03 Simon Josefsson + + maintainer-makefile: Add indentation syntax-check rule. + * top/maint.mk (indent): Use AM_V_GEN and indent_args. + (sc_indent): New rule. + (indent_args): New variable. + (C_SOURCES): New variable, initialized to reasonable C files. + (exclude_file_name_regexp--indent): New variable. + 2021-08-30 Paul Eggert idx: add commentary diff --git a/top/maint.mk b/top/maint.mk index 6a3ea9606f..72070a7b03 100644 --- a/top/maint.mk +++ b/top/maint.mk @@ -1631,12 +1631,32 @@ refresh-po: ls $(PODIR)/*.po | $(SED) 's/\.po//;s,$(PODIR)/,,' | \ sort >> $(PODIR)/LINGUAS - # Running indent once is not idempotent, but running it twice is. +# Indentation + +indent_args ?= -ppi 1 +C_SOURCES ?= $$($(VC_LIST_EXCEPT) | grep '\.[ch]\(.in\)\?$$') INDENT_SOURCES ?= $(C_SOURCES) +exclude_file_name_regexp--indent ?= $(exclude_file_name_regexp--sc_indent) + .PHONY: indent -indent: - indent $(INDENT_SOURCES) - indent $(INDENT_SOURCES) +indent: # Running indent once is not idempotent, but running it twice is. + $(AM_V_GEN)indent $(indent_args) $(INDENT_SOURCES) && \ + indent $(indent_args) $(INDENT_SOURCES) + +sc_indent: + @if ! command -v indent > /dev/null; then \ + echo 1>&2 '$(ME): sc_indent: indent is missing'; \ + else \ + fail=0; files="$(INDENT_SOURCES)"; \ + for f in $$files; do \ + indent $(indent_args) -st $$f \ + | indent $(indent_args) -st - \ + | diff -u $$f - || fail=1; \ + done; \ + test $$fail = 1 && \ + { echo 1>&2 '$(ME): code format error, try "make indent"'; \ + exit 1; } || :; \ + fi # If you want to set UPDATE_COPYRIGHT_* environment variables, # put the assignments in this variable. -- cgit v1.2.1