]> Savannah Git Hosting - gnulib.git/commitdiff
maintainer-makefile: Add indentation syntax-check rule.
authorSimon Josefsson <simon@josefsson.org>
Fri, 3 Sep 2021 19:59:43 +0000 (21:59 +0200)
committerSimon Josefsson <simon@josefsson.org>
Fri, 3 Sep 2021 19:59:43 +0000 (21:59 +0200)
* 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
top/maint.mk

index 1b1372cb76b327fd6089db4dc095c19438bbf196..51d1f3d37a697acf006730971be6b82771c934f3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2021-09-03  Simon Josefsson  <simon@josefsson.org>
+
+       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  <eggert@cs.ucla.edu>
 
        idx: add commentary
index 6a3ea9606f388f0d0ee0003fb94ad8d1ba7a307a..72070a7b039a20b5dd4250caee8b46f188cbacf2 100644 (file)
@@ -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.