git: 08559edad422 - stable/14 - bsd.man.mk: Add checkmanlinks target

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Thu, 14 Aug 2025 16:03:19 UTC
The branch stable/14 has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=08559edad42205ebd3b1e542c23f0a019ec63df4

commit 08559edad42205ebd3b1e542c23f0a019ec63df4
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-08-12 12:54:08 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-08-14 14:00:09 +0000

    bsd.man.mk: Add checkmanlinks target
    
    This target checks that every page mentioned in MLINKS exists and that
    every link corresponds to a (possibly commented-out) name entry in the
    page it links to.
    
    MFC after:      1 week
    Reviewed by:    bcr
    Differential Revision:  https://reviews.freebsd.org/D51862
    
    (cherry picked from commit 18a9f83630a7d4612066bb690bcec0437c0e2e72)
---
 share/mk/bsd.man.mk | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/share/mk/bsd.man.mk b/share/mk/bsd.man.mk
index 04316c46b705..e7b29b0bade1 100644
--- a/share/mk/bsd.man.mk
+++ b/share/mk/bsd.man.mk
@@ -241,11 +241,11 @@ maninstall: ${MAN}
 .endif
 .endfor
 
-manlint:
+manlint: .PHONY checkmanlinks
 .if defined(MAN) && !empty(MAN)
 .for __page in ${MAN}
 manlint: ${__page}lint
-${__page}lint: ${__page}
+${__page}lint: .PHONY ${__page}
 .if defined(MANFILTER)
 	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} -Tlint
 .else
@@ -253,3 +253,15 @@ ${__page}lint: ${__page}
 .endif
 .endfor
 .endif
+
+checkmanlinks: .PHONY
+.if defined(MLINKS)
+.for __page __link in ${MLINKS}
+checkmanlinks: checkmanlinks-${__link}
+checkmanlinks-${__link}: .PHONY ${__page}
+	@if ! egrep -q "^(\.\\\\\" )?\.Nm ${__link:R}( ,)?$$" ${.ALLSRC}; then \
+		echo "MLINKS: '.Nm ${__link:R}' not found in ${__page}"; \
+		exit 1; \
+	fi >&2
+.endfor # __page __link in ${MLINKS}
+.endif # defined(MLINKS)