[PATCH] Makefile, etc/groff/tmac/deadly.tmac: Add lint and lint-groff targets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



'lint' is a metatarget that triggers all lint-* targets (currently
that is just 'lint-groff').
'lint-groff' is a target that runs groff -rCHECKSTYLE to check
manual pages' groff(7) correctness.

etc/groff/tmac/deadly.tmac is a file written by Branden, to make
make groff(1) abort when it finds a style problem, which then
causes make(1) to also abort.

CC: "G. Branden Robinson" <g.branden.robinson@xxxxxxxxx>
Signed-off-by: Alejandro Colomar <alx.manpages@xxxxxxxxx>
---

Hi Branden and Michael!

I'm delighted to add to the man-pages a make(1) target to run Branden's
brand new (pun not intended :)) groff(1) linter.

Please have a look at it, and feel free to comment.  As I expected,
one of the first pages linted had problems (and I am surprised for good
that it didn't abort right in the first page):

	INSTALL	tmp/lint/
	INSTALL	tmp/lint/man0/
	LINT (groff)	tmp/lint/man0/sysexits.h.0.lint.groff.touch
	INSTALL	tmp/lint/man1/
	LINT (groff)	tmp/lint/man1/getent.1.lint.groff.touch
	LINT (groff)	tmp/lint/man1/iconv.1.lint.groff.touch
	LINT (groff)	tmp/lint/man1/intro.1.lint.groff.touch
	an.tmac:man1/intro.1:72: style: blank line in input
	found style problems; aborting
	make: *** [Makefile:244: tmp/lint/man1/intro.1.lint.groff.touch] Error 1

I may start cleaning all of those one day.  Now that we have some tool
that finds those for us, that day may be sooner than later.

Branden, I'm curious to learn how/if you're using it in your own Makefile
in groff(1).

BTW, don't feel pressured by my premature usage of your unreleased feature
to consider not changing it too much to avoid breaking this build system.
I assume that it may change it the future when you release and will adapt
if necessary.

Cheers,

Alex


 Makefile                   | 54 +++++++++++++++++++++++++++++++++-----
 etc/groff/tmac/deadly.tmac |  7 +++++
 2 files changed, 55 insertions(+), 6 deletions(-)
 create mode 100644 etc/groff/tmac/deadly.tmac

diff --git a/Makefile b/Makefile
index f68066bec..7316b4582 100644
--- a/Makefile
+++ b/Makefile
@@ -29,15 +29,19 @@ MAKEFLAGS += --no-print-directory
 MAKEFLAGS += --warn-undefined-variables
 
 
+srcdir := .
 builddir := tmp
+LINTDIR := $(builddir)/lint
 htmlbuilddir := $(builddir)/html
 HTOPTS :=
 
 DESTDIR :=
 prefix := /usr/local
+SYSCONFDIR := $(srcdir)/etc
+TMACDIR := $(SYSCONFDIR)/groff/tmac
 datarootdir := $(prefix)/share
 docdir := $(datarootdir)/doc
-MANDIR := $(CURDIR)
+MANDIR := $(srcdir)
 mandir := $(datarootdir)/man
 MAN0DIR := $(MANDIR)/man0
 MAN1DIR := $(MANDIR)/man1
@@ -71,12 +75,23 @@ htmldir := $(docdir)
 htmldir_ := $(htmldir)/man
 htmlext := .html
 
-INSTALL := install
+TMACFILES            := $(sort $(shell find $(TMACDIR) -not -type d))
+TMACNAMES            := $(basename $(notdir $(TMACFILES)))
+GROFF_CHECKSTYLE_LVL := 3
+DEFAULT_GROFFFLAGS   := -man
+DEFAULT_GROFFFLAGS   += -M $(TMACDIR)
+DEFAULT_GROFFFLAGS   += $(foreach x,$(TMACNAMES),-m $(x))
+DEFAULT_GROFFFLAGS   += -rCHECKSTYLE=$(GROFF_CHECKSTYLE_LVL)
+EXTRA_GROFFFLAGS     :=
+GROFFFLAGS           := $(DEFAULT_GROFFFLAGS) $(EXTRA_GROFFFLAGS)
+
+INSTALL      := install
 INSTALL_DATA := $(INSTALL) -m 644
-INSTALL_DIR := $(INSTALL) -m 755 -d
-RM := rm
-RMDIR := rmdir --ignore-fail-on-non-empty
-MAN2HTML := man2html
+INSTALL_DIR  := $(INSTALL) -m 755 -d
+RM           := rm
+RMDIR        := rmdir --ignore-fail-on-non-empty
+GROFF        := groff
+MAN2HTML     := man2html
 
 MAN_SECTIONS := 0 1 2 3 4 5 6 7 8
 
@@ -132,9 +147,11 @@ _man5pages := $(filter %$(man5ext),$(_manpages))
 _man6pages := $(filter %$(man6ext),$(_manpages))
 _man7pages := $(filter %$(man7ext),$(_manpages))
 _man8pages := $(filter %$(man8ext),$(_manpages))
+LINT_groff := $(patsubst $(MANDIR)/%,$(LINTDIR)/%.lint.groff.touch,$(MANPAGES))
 
 MANDIRS   := $(sort $(shell find $(MANDIR)/man? -type d))
 HTMLDIRS  := $(patsubst $(MANDIR)/%,$(htmlbuilddir)/%/.,$(MANDIRS))
+LINTDIRS  := $(patsubst $(MANDIR)/%,$(LINTDIR)/%/.,$(MANDIRS))
 _htmldirs := $(patsubst $(htmlbuilddir)/%,$(DESTDIR)$(htmldir_)/%,$(HTMLDIRS))
 _mandirs  := $(patsubst $(MANDIR)/%,$(DESTDIR)$(mandir)/%/.,$(MANDIRS))
 _man0dir  := $(filter %man0/.,$(_mandirs))
@@ -216,6 +233,31 @@ uninstall-man: $(_mandir_rmdir) $(uninstall_manX)
 	@:
 
 
+########################################################################
+# lint
+
+linters := groff
+lint    := $(foreach x,$(linters),lint-$(x))
+
+$(LINT_groff): $(LINTDIR)/%.lint.groff.touch: $(MANDIR)/% | $$(@D)/.
+	$(info LINT (groff)	$@)
+	$(GROFF) $(GROFFFLAGS) -z $<
+	touch $@
+
+$(LINTDIRS): %/.: | $$(dir %). $(LINTDIR)/.
+
+.PHONY: lint-groff
+lint-groff: $(LINT_groff) | lintdirs
+	@:
+
+lintdirs: $(LINTDIRS)
+	@:
+
+.PHONY: lint
+lint: $(lint)
+	@:
+
+
 ########################################################################
 # html
 
diff --git a/etc/groff/tmac/deadly.tmac b/etc/groff/tmac/deadly.tmac
new file mode 100644
index 000000000..b87cb6a3d
--- /dev/null
+++ b/etc/groff/tmac/deadly.tmac
@@ -0,0 +1,7 @@
+.am an-style-warn
+.	ds LANDMINE\"
+..
+.de end-of-input-macro
+.	if d LANDMINE .ab found style problems; aborting
+..
+.em end-of-input-macro
-- 
2.35.1




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux