Subject: RFC: Fix for IMAKE_MANINSTALL handling
To: NetBSD pkgsrc Discussion <tech-pkg@NetBSD.org>
From: Roland Illig <rillig@NetBSD.org>
List: tech-pkg
Date: 10/11/2007 23:32:23
This is a multi-part message in MIME format.
--------------010207000306090207000108
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Currently, the IMAKE_MANINSTALL handling is broken. On many platforms, 
it is set to "maninstall catinstall" although imake only installs the 
catpages.

I have some code that fixes this issue by adding a PLIST "macro"

     @imake-man <dir> <basename> <extension>

which expands to zero, one or two lines, depending in IMAKE_MANINSTALL. 
The reason that I want to fix this now is that I have installed XFree86 
4.6, which really installs both manpages and catpages.

I have changed the relevant infrastructure bits and packages, and it 
works great for me. As an example, I have appended the change for 
x11/oneko. Listing all the other packages would only make the patch larger.

Roland

--------------010207000306090207000108
Content-Type: text/plain;
 name="imake-maninstall.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="imake-maninstall.patch"

Index: mk/platform/NetBSD.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/platform/NetBSD.mk,v
retrieving revision 1.25
diff -u -p -r1.25 NetBSD.mk
--- mk/platform/NetBSD.mk	21 Aug 2007 22:49:33 -0000	1.25
+++ mk/platform/NetBSD.mk	11 Oct 2007 21:30:02 -0000
@@ -47,12 +47,12 @@ ULIMIT_CMD_memorysize?=	ulimit -m `ulimi
 # these values from /usr/X11R6/lib/X11/config/NetBSD.cf
 IMAKE_MAN_SOURCE_PATH=	man/cat
 IMAKE_MANNEWSUFFIX=	0
-IMAKE_MAN_SUFFIX=	${IMAKE_MANNEWSUFFIX}
-IMAKE_LIBMAN_SUFFIX=	${IMAKE_MANNEWSUFFIX}
-IMAKE_KERNMAN_SUFFIX=	${IMAKE_MANNEWSUFFIX}
-IMAKE_FILEMAN_SUFFIX=	${IMAKE_MANNEWSUFFIX}
-IMAKE_GAMEMAN_SUFFIX=	${IMAKE_MANNEWSUFFIX}
-IMAKE_MISCMAN_SUFFIX=	${IMAKE_MANNEWSUFFIX}
+IMAKE_MAN_SUFFIX=	1
+IMAKE_LIBMAN_SUFFIX=	3
+IMAKE_KERNMAN_SUFFIX=	4
+IMAKE_FILEMAN_SUFFIX=	5
+IMAKE_GAMEMAN_SUFFIX=	6
+IMAKE_MISCMAN_SUFFIX=	7
 IMAKE_MAN_DIR=		${IMAKE_MAN_SOURCE_PATH}1
 IMAKE_LIBMAN_DIR=	${IMAKE_MAN_SOURCE_PATH}3
 IMAKE_KERNMAN_DIR=	${IMAKE_MAN_SOURCE_PATH}4
Index: mk/plist/plist-functions.awk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/plist/plist-functions.awk,v
retrieving revision 1.1
diff -u -p -r1.1 plist-functions.awk
--- mk/plist/plist-functions.awk	12 Jan 2006 23:43:57 -0000	1.1
+++ mk/plist/plist-functions.awk	11 Oct 2007 21:30:02 -0000
@@ -57,3 +57,9 @@ function print_entry(entry) {
 		print entry
 	}
 }
+
+function getenv_or_die(varname) {
+	if (varname in ENVIRON)
+		return ENVIRON[varname]
+	print "ERROR: "varname" must be defined." | "cat 1>&2"
+}
Index: mk/plist/plist-macros.awk
===================================================================
RCS file: mk/plist/plist-macros.awk
diff -N mk/plist/plist-macros.awk
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mk/plist/plist-macros.awk	11 Oct 2007 21:30:02 -0000
@@ -0,0 +1,27 @@
+# $NetBSD$
+
+BEGIN {
+	IMAKE_MANINSTALL = getenv_or_die("IMAKE_MANINSTALL")
+}
+
+# @imake-man dir basename extension
+#
+# Creates up to two PLIST entries for man pages of imake-style programs.
+#
+/^@imake-man/ {
+	if (IMAKE_MANINSTALL ~ /catinstall/) {
+		n = split($2, components, "/")
+		sub("man", "cat", components[n])
+		print join(components, 1, n, "/") "/" $3 ".0"
+	}
+	if (IMAKE_MANINSTALL ~ /maninstall/) {
+		n = split($2, components, "/")
+		sub("cat", "man", components[n])
+		print join(components, 1, n, "/") "/" $3 "." $4
+	}
+	next;
+}
+
+1 {
+	print;
+}
Index: mk/plist/plist-man.awk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/plist/plist-man.awk,v
retrieving revision 1.5
diff -u -p -r1.5 plist-man.awk
--- mk/plist/plist-man.awk	7 Feb 2006 18:43:02 -0000	1.5
+++ mk/plist/plist-man.awk	11 Oct 2007 21:30:02 -0000
@@ -78,35 +78,13 @@ BEGIN {
 	sub("\\.gz$", "")
 }
 
-###
-### Rewrite "imake-installed" catman pages as man pages if imake only
-### supports man pages.
-###
-(IMAKE_MANINSTALL == "maninstall") && /^[^@]/ && \
-/^([^\/]*\/)+cat[1-9ln]\/[^\/]*\.[0-9ln]$/ {
-	n = split($0, components, "/")
-	sub("cat", "man", components[n-1])
-	section = substr(components[n-1], 4, 1)
-	sub("[0-9ln]$", section, components[n])
-	$0 = join(components, 1, n, "/")
-}
+# XXX: Can be removed when @dirrm is obsolete
 (IMAKE_MANINSTALL == "maninstall") && \
 /^@dirrm ([^\/]*\/)+cat[1-9ln]/ {
 	next
 }
 
-###
-### Rewrite "imake-installed" man pages as catman pages if imake only
-### supports catman pages.
-###
-(IMAKE_MANINSTALL == "catinstall") && /^[^@]/ && \
-/^([^\/]*\/)+man[1-9ln]\/[^\/]*\.[0-9ln]$/ {
-	n = split($0, components, "/")
-	sub("man", "cat", components[n-1])
-	section = "0"
-	sub("[0-9ln]$", section, components[n])
-	$0 = join(components, 1, n, "/")
-}
+# XXX: Can be removed when @dirrm is obsolete
 (IMAKE_MANINSTALL == "catinstall") && \
 /^@dirrm ([^\/]*\/)+man[1-9ln]/ {
 	next
Index: mk/plist/plist.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/plist/plist.mk,v
retrieving revision 1.31
diff -u -p -r1.31 plist.mk
--- mk/plist/plist.mk	3 Aug 2007 14:03:40 -0000	1.31
+++ mk/plist/plist.mk	11 Oct 2007 21:30:02 -0000
@@ -140,8 +140,11 @@ PLIST_SUBST+=	OPSYS=${OPSYS:Q}					\
 _PLIST_AWK_ENV+=	${PLIST_SUBST:S/^/PLIST_/}
 _PLIST_AWK_ENV+=	PLIST_SUBST_VARS=${PLIST_SUBST:S/^/PLIST_/:C/=.*//:M*:Q}
 
+_PLIST_1_AWK+=		-f ${PKGSRCDIR}/mk/plist/plist-functions.awk
+_PLIST_1_AWK+=		-f ${PKGSRCDIR}/mk/plist/plist-subst.awk
+_PLIST_1_AWK+=		-f ${PKGSRCDIR}/mk/plist/plist-macros.awk
+
 _PLIST_AWK+=		-f ${.CURDIR}/../../mk/plist/plist-functions.awk
-_PLIST_AWK+=		-f ${.CURDIR}/../../mk/plist/plist-subst.awk
 _PLIST_AWK+=		-f ${.CURDIR}/../../mk/plist/plist-locale.awk
 _PLIST_AWK+=		-f ${.CURDIR}/../../mk/plist/plist-info.awk
 _PLIST_AWK+=		-f ${.CURDIR}/../../mk/plist/plist-man.awk
@@ -218,12 +221,11 @@ plist: ${PLIST} ${_PLIST_NOKEYWORDS}
 ${PLIST}: ${PLIST_SRC}
 .endif
 ${PLIST}:
-	${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H}
-	${_PKG_SILENT}${_PKG_DEBUG}					\
-	{ ${_GENERATE_PLIST} } |					\
-	${SETENV} ${_PLIST_AWK_ENV} ${AWK} ${_PLIST_AWK} |		\
-	${SETENV} ${_PLIST_AWK_ENV} ${AWK} ${_PLIST_SHLIB_AWK}		\
-		> ${.TARGET}
+	${RUN} ${MKDIR} ${.TARGET:H}
+	${RUN} { ${_GENERATE_PLIST} } > ${.TARGET}-1src
+	${RUN} ${SETENV} ${_PLIST_AWK_ENV} ${AWK} ${_PLIST_1_AWK} < ${.TARGET}-1src > ${.TARGET}-2mac
+	${RUN} ${SETENV} ${_PLIST_AWK_ENV} ${AWK} ${_PLIST_AWK} < ${.TARGET}-2mac > ${.TARGET}-3mag
+	${RUN} ${SETENV} ${_PLIST_AWK_ENV} ${AWK} ${_PLIST_SHLIB_AWK} < ${.TARGET}-3mag > ${.TARGET}
 
 # for list of keywords see pkg_create(1)
 ${_PLIST_NOKEYWORDS}: ${PLIST}
Index: x11/oneko/PLIST
===================================================================
RCS file: /cvsroot/pkgsrc/x11/oneko/PLIST,v
retrieving revision 1.2
diff -u -p -r1.2 PLIST
--- x11/oneko/PLIST	3 Mar 2003 04:17:44 -0000	1.2
+++ x11/oneko/PLIST	11 Oct 2007 21:30:02 -0000
@@ -1,3 +1,3 @@
 @comment $NetBSD: PLIST,v 1.2 2003/03/03 04:17:44 jschauma Exp $
 bin/oneko
-${IMAKE_MAN_DIR}/oneko.${IMAKE_MANNEWSUFFIX}
+@imake-man ${IMAKE_MAN_DIR} oneko ${IMAKE_MAN_SUFFIX}

--------------010207000306090207000108--