Subject: [RFC] making PKGBASE and PKGVERSION read-only
To: None <tech-pkg@netbsd.org>
From: Roland Illig <roland.illig@gmx.de>
List: tech-pkg
Date: 10/15/2005 09:16:42
This is a multi-part message in MIME format.
--------------030607040300050807000500
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

The confusion of my last RFC arose from wrong code in bsd.pkg.mk.

It is common practice to initialize user-settable variables using the 
"?=" operator. But this operator is used in too many places. For 
example, the variables PKGBASE and PKGREVISION, which are probably not 
intended to be user-settable, are defined with it.

This patch makes these variables practically read-only.

This patch also reduces the confusion that might arise because the 
PKGNAME and PKGNAME_NOREV are assigned using the ":=" operator. As the 
PKGBASE and PKGVERSION are derived from the modified PKGNAME (including 
the PKGREVISION), they are placed below that assignment. I also removed 
a nested .if ... .endif, which made the code look more complicated than 
it actually is. I don't consider these "layout changes", although they 
technically are. That's the reason why I combined them in this one patch.

Roland

--------------030607040300050807000500
Content-Type: text/plain;
 name="bsd.pkg.mk.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="bsd.pkg.mk.patch"

Index: bsd.pkg.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.mk,v
retrieving revision 1.1730
diff -u -p -r1.1730 bsd.pkg.mk
--- bsd.pkg.mk	10 Oct 2005 17:37:17 -0000	1.1730
+++ bsd.pkg.mk	15 Oct 2005 07:06:05 -0000
@@ -78,19 +78,24 @@ ACCEPTABLE_LICENSES=	${ACCEPTABLE_LICENC
 
 ##### PKGBASE, PKGNAME[_NOREV], PKGVERSION
 
-PKGBASE?=		${PKGNAME:C/-[^-]*$//}
-PKGVERSION?=		${PKGNAME:C/^.*-//}
+.if defined(PKGBASE)
+PKG_FAIL_REASON+=	"[bsd.pkg.mk] error: PKGBASE is a read-only variable."
+.endif
+.if defined(PKGVERSION)
+PKG_FAIL_REASON+=	"[bsd.pkg.mk] error: PKGVERSION is a read-only variable."
+.endif
+
 .if defined(PKGREVISION) && !empty(PKGREVISION) && (${PKGREVISION} != "0")
-.  if defined(PKGNAME)
-PKGNAME_NOREV:=		${PKGNAME}
-PKGNAME:=		${PKGNAME}nb${PKGREVISION}
-.  else
-PKGNAME?=		${DISTNAME}nb${PKGREVISION}
-PKGNAME_NOREV=		${DISTNAME}
-.  endif
+_PKGREVISIONPART=	nb${PKGREVISION}
 .else
+_PKGREVISIONPART=	# empty
+.endif
+
 PKGNAME?=		${DISTNAME}
-PKGNAME_NOREV=		${PKGNAME}
+PKGNAME_NOREV:=		${PKGNAME}
+PKGNAME:=		${PKGNAME}${_PKGREVISIONPART}
+PKGBASE=		${PKGNAME:C/-[^-]*$//}
+PKGVERSION=		${PKGNAME:C/^.*-//}
 .endif
 
 ##### PLIST

--------------030607040300050807000500--