From c76a587148d9b69667852311ece53403b1458844 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sat, 22 Apr 2023 16:47:51 +0200 Subject: *.mk: lint, lint-mdoc, lint-mdoc-mandoc: Support mdoc(7) pages Signed-off-by: Alejandro Colomar --- Makefile | 12 +++++--- share/mk/build/_.mk | 4 +++ share/mk/lint/_.mk | 2 +- share/mk/lint/man.mk | 77 ----------------------------------------------- share/mk/lint/man/_.mk | 16 ++++++++++ share/mk/lint/man/man.mk | 72 ++++++++++++++++++++++++++++++++++++++++++++ share/mk/lint/man/mdoc.mk | 45 +++++++++++++++++++++++++++ 7 files changed, 146 insertions(+), 82 deletions(-) delete mode 100644 share/mk/lint/man.mk create mode 100644 share/mk/lint/man/_.mk create mode 100644 share/mk/lint/man/man.mk create mode 100644 share/mk/lint/man/mdoc.mk diff --git a/Makefile b/Makefile index 9f5fd84de..9f24c1adb 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ help: $(info build-src-cc Compile C programs from EXAMPLES) $(info build-src-ld Link C programs from EXAMPLES) $(info ) - $(info lint Wrapper for "lint-c lint-man") + $(info lint Wrapper for "lint-c lint-man lint-mdoc") $(info lint-c Wrapper for lint-c-* targets) $(info lint-c-checkpatch Lint C programs from EXAMPLES with checkpatch(1)) $(info lint-c-clang-tidy Lint C programs from EXAMPLES with clang-tidy(1)) @@ -73,8 +73,10 @@ help: $(info lint-c-cpplint Lint C programs from EXAMPLES with cpplint(1)) $(info lint-c-iwyu Lint C programs from EXAMPLES with iwyu(1)) $(info lint-man Wrapper for lint-man-* targets) - $(info lint-man-mandoc Lint man pages with mandoc(1)) - $(info lint-man-tbl Lint man pages about '\" t' comment for tbl(1)) + $(info lint-man-mandoc Lint man(7) pages with mandoc(1)) + $(info lint-man-tbl Lint man(7) pages about '\" t' comment for tbl(1)) + $(info lint-mdoc Wrapper for lint-mdoc-* targets) + $(info lint-mdoc-mandoc Lint mdoc(7) pages with mandoc(1)) $(info ) $(info check Alias for "check-catman") $(info check-catman Check cat pages; alias for "check-catman-grep") @@ -125,7 +127,9 @@ include $(MAKEFILEDIR)/install/html.mk include $(MAKEFILEDIR)/install/man.mk include $(MAKEFILEDIR)/lint/_.mk include $(MAKEFILEDIR)/lint/c.mk -include $(MAKEFILEDIR)/lint/man.mk +include $(MAKEFILEDIR)/lint/man/_.mk +include $(MAKEFILEDIR)/lint/man/man.mk +include $(MAKEFILEDIR)/lint/man/mdoc.mk include $(MAKEFILEDIR)/verbose.mk diff --git a/share/mk/build/_.mk b/share/mk/build/_.mk index 0bd4c949c..bcdba6062 100644 --- a/share/mk/build/_.mk +++ b/share/mk/build/_.mk @@ -27,6 +27,10 @@ NONSO_MAN := $(shell $(FIND) $(MANDIR)/man*/ -type f \ | $(GREP) '$(MANEXT)' \ | $(XARGS) $(GREP) -l '^\.TH ' \ | $(SORT)) +NONSO_MDOC := $(shell $(FIND) $(MANDIR)/man*/ -type f \ + | $(GREP) '$(MANEXT)' \ + | $(XARGS) $(GREP) -l '^\.Dt ' \ + | $(SORT)) _MANDIRS := $(patsubst $(MANDIR)/%,$(_MANDIR)/%/,$(MANDIRS)) diff --git a/share/mk/lint/_.mk b/share/mk/lint/_.mk index c81f283da..56d8d2359 100644 --- a/share/mk/lint/_.mk +++ b/share/mk/lint/_.mk @@ -8,7 +8,7 @@ ifndef MAKEFILE_LINT_INCLUDED MAKEFILE_LINT_INCLUDED := 1 -lint := lint-c lint-man +lint := lint-c lint-man lint-mdoc .PHONY: lint diff --git a/share/mk/lint/man.mk b/share/mk/lint/man.mk deleted file mode 100644 index c696e2df0..000000000 --- a/share/mk/lint/man.mk +++ /dev/null @@ -1,77 +0,0 @@ -######################################################################## -# Copyright (C) 2021 - 2023 Alejandro Colomar -# SPDX-License-Identifier: GPL-3.0-or-later OR LGPL-3.0-or-later -######################################################################## - - -ifndef MAKEFILE_LINT_MAN_INCLUDED -MAKEFILE_LINT_MAN_INCLUDED := 1 - - -include $(MAKEFILEDIR)/cmd.mk -include $(MAKEFILEDIR)/build/_.mk -include $(MAKEFILEDIR)/lint/_.mk -include $(MAKEFILEDIR)/src.mk - - -DEFAULT_MANDOCFLAGS := -man -DEFAULT_MANDOCFLAGS += -Tlint -EXTRA_MANDOCFLAGS := -MANDOCFLAGS := $(DEFAULT_MANDOCFLAGS) $(EXTRA_MANDOCFLAGS) - - -_LINT_man_mandoc:=$(patsubst $(MANDIR)/%,$(_MANDIR)/%.lint-man.mandoc.touch,$(NONSO_MAN)) -_LINT_man_tbl :=$(patsubst $(MANDIR)/%,$(_MANDIR)/%.lint-man.tbl.touch,$(NONSO_MAN)) - - -linters_man := mandoc tbl -lint_man := $(foreach x,$(linters_man),lint-man-$(x)) - - -$(_LINT_man_mandoc): $(_MANDIR)/%.lint-man.mandoc.touch: $(MANDIR)/% | $$(@D)/ - $(info LINT (mandoc) $@) - ! ($(MANDOC) $(MANDOCFLAGS) $< 2>&1 \ - | $(GREP) -v 'STYLE: lower case character in document title:' \ - | $(GREP) -v 'UNSUPP: ignoring macro in table:' \ - | $(GREP) -v 'WARNING: cannot parse date, using it verbatim: TH (date)' \ - | $(GREP) -v 'WARNING: empty block: UR' \ - | $(GREP) -v 'WARNING: missing date, using "": TH' \ - | $(GREP) -v 'WARNING: undefined escape, printing literally: \\\\' \ - ||:; \ - ) \ - | $(GREP) '.' >&2 - touch $@ - -$(_LINT_man_tbl): $(_MANDIR)/%.lint-man.tbl.touch: $(MANDIR)/% | $$(@D)/ - $(info LINT (tbl comment) $@) - if $(GREP) -q '^\.TS$$' $< && ! $(HEAD) -n1 $< | $(GREP) -q '\\" t$$'; \ - then \ - >&2 $(ECHO) "$<:1: missing '\\\" t' comment:"; \ - >&2 $(HEAD) -n1 <$<; \ - exit 1; \ - fi - if $(HEAD) -n1 $< | $(GREP) -q '\\" t$$' && ! $(GREP) -q '^\.TS$$' $<; \ - then \ - >&2 $(ECHO) "$<:1: spurious '\\\" t' comment:"; \ - >&2 $(HEAD) -n1 <$<; \ - exit 1; \ - fi - if $(TAIL) -n+2 <$< | $(GREP) -q '\\" t$$'; \ - then \ - >&2 $(ECHO) "$<: spurious '\\\" t' not in first line:"; \ - >&2 $(GREP) -n '\\" t$$' $< /dev/null; \ - exit 1; \ - fi - touch $@ - - -.PHONY: $(lint_man) -$(lint_man): lint-man-%: $$(_LINT_man_%) - @: - -.PHONY: lint-man -lint-man: $(lint_man) - @: - - -endif # MAKEFILE_LINT_MAN_INCLUDED diff --git a/share/mk/lint/man/_.mk b/share/mk/lint/man/_.mk new file mode 100644 index 000000000..17c3a0bbd --- /dev/null +++ b/share/mk/lint/man/_.mk @@ -0,0 +1,16 @@ +######################################################################## +# Copyright 2021-2023, Alejandro Colomar +# SPDX-License-Identifier: GPL-3.0-or-later OR LGPL-3.0-or-later +######################################################################## + + +ifndef MAKEFILE_LINT_MAN_INCLUDED +MAKEFILE_LINT_MAN_INCLUDED := 1 + + +DEFAULT_MANDOCFLAGS := -Tlint +EXTRA_MANDOCFLAGS := +MANDOCFLAGS := $(DEFAULT_MANDOCFLAGS) $(EXTRA_MANDOCFLAGS) + + +endif # MAKEFILE_LINT_MAN_INCLUDED diff --git a/share/mk/lint/man/man.mk b/share/mk/lint/man/man.mk new file mode 100644 index 000000000..4e9512ed9 --- /dev/null +++ b/share/mk/lint/man/man.mk @@ -0,0 +1,72 @@ +######################################################################## +# Copyright 2021-2023, Alejandro Colomar +# SPDX-License-Identifier: GPL-3.0-or-later OR LGPL-3.0-or-later +######################################################################## + + +ifndef MAKEFILE_LINT_MAN_MAN_INCLUDED +MAKEFILE_LINT_MAN_MAN_INCLUDED := 1 + + +include $(MAKEFILEDIR)/cmd.mk +include $(MAKEFILEDIR)/build/_.mk +include $(MAKEFILEDIR)/lint/_.mk +include $(MAKEFILEDIR)/lint/man/_.mk +include $(MAKEFILEDIR)/src.mk + + +_LINT_man_mandoc :=$(patsubst $(MANDIR)/%,$(_MANDIR)/%.lint-man.mandoc.touch,$(NONSO_MAN)) +_LINT_man_tbl :=$(patsubst $(MANDIR)/%,$(_MANDIR)/%.lint-man.tbl.touch,$(NONSO_MAN)) + + +linters_man := mandoc tbl +lint_man := $(foreach x,$(linters_man),lint-man-$(x)) + + +$(_LINT_man_mandoc): $(_MANDIR)/%.lint-man.mandoc.touch: $(MANDIR)/% | $$(@D)/ + $(info LINT (mandoc) $@) + ! ($(MANDOC) -man $(MANDOCFLAGS) $< 2>&1 \ + | $(GREP) -v 'STYLE: lower case character in document title:' \ + | $(GREP) -v 'UNSUPP: ignoring macro in table:' \ + | $(GREP) -v 'WARNING: cannot parse date, using it verbatim: TH (date)' \ + | $(GREP) -v 'WARNING: empty block: UR' \ + | $(GREP) -v 'WARNING: missing date, using "": TH' \ + | $(GREP) -v 'WARNING: undefined escape, printing literally: \\\\' \ + ||:; \ + ) \ + | $(GREP) '.' >&2 + touch $@ + +$(_LINT_man_tbl): $(_MANDIR)/%.lint-man.tbl.touch: $(MANDIR)/% | $$(@D)/ + $(info LINT (tbl comment) $@) + if $(GREP) -q '^\.TS$$' $< && ! $(HEAD) -n1 $< | $(GREP) -q '\\" t$$'; \ + then \ + >&2 $(ECHO) "$<:1: missing '\\\" t' comment:"; \ + >&2 $(HEAD) -n1 <$<; \ + exit 1; \ + fi + if $(HEAD) -n1 $< | $(GREP) -q '\\" t$$' && ! $(GREP) -q '^\.TS$$' $<; \ + then \ + >&2 $(ECHO) "$<:1: spurious '\\\" t' comment:"; \ + >&2 $(HEAD) -n1 <$<; \ + exit 1; \ + fi + if $(TAIL) -n+2 <$< | $(GREP) -q '\\" t$$'; \ + then \ + >&2 $(ECHO) "$<: spurious '\\\" t' not in first line:"; \ + >&2 $(GREP) -n '\\" t$$' $< /dev/null; \ + exit 1; \ + fi + touch $@ + + +.PHONY: $(lint_man) +$(lint_man): lint-man-%: $$(_LINT_man_%) + @: + +.PHONY: lint-man +lint-man: $(lint_man) + @: + + +endif # MAKEFILE_LINT_MAN_MAN_INCLUDED diff --git a/share/mk/lint/man/mdoc.mk b/share/mk/lint/man/mdoc.mk new file mode 100644 index 000000000..0982f42cb --- /dev/null +++ b/share/mk/lint/man/mdoc.mk @@ -0,0 +1,45 @@ +######################################################################## +# Copyright 2023, Alejandro Colomar +# SPDX-License-Identifier: GPL-3.0-or-later OR LGPL-3.0-or-later +######################################################################## + + +ifndef MAKEFILE_LINT_MAN_MDOC_INCLUDED +MAKEFILE_LINT_MAN_MDOC_INCLUDED := 1 + + +include $(MAKEFILEDIR)/cmd.mk +include $(MAKEFILEDIR)/build/_.mk +include $(MAKEFILEDIR)/lint/_.mk +include $(MAKEFILEDIR)/lint/man/_.mk +include $(MAKEFILEDIR)/src.mk + + +_LINT_mdoc_mandoc:=$(patsubst $(MANDIR)/%,$(_MANDIR)/%.lint-mdoc.mandoc.touch,$(NONSO_MDOC)) + + +linters_mdoc := mandoc +lint_mdoc := $(foreach x,$(linters_mdoc),lint-mdoc-$(x)) + + +$(_LINT_mdoc_mandoc): $(_MANDIR)/%.lint-mdoc.mandoc.touch: $(MANDIR)/% | $$(@D)/ + $(info LINT (mandoc) $@) + ! ($(MANDOC) -mdoc $(MANDOCFLAGS) $< 2>&1 \ + | $(GREP) -v 'STYLE: operating system explicitly specified: Os ' \ + | $(GREP) -v 'WARNING: cross reference to self: Xr ' \ + ||:; \ + ) \ + | $(GREP) '.' >&2 + touch $@ + + +.PHONY: $(lint_mdoc) +$(lint_mdoc): lint-mdoc-%: $$(_LINT_mdoc_%) + @: + +.PHONY: lint-mdoc +lint-mdoc: $(lint_mdoc) + @: + + +endif # MAKEFILE_LINT_MAN_MDOC_INCLUDED -- cgit v1.2.3