Subject: RFC: Removing redundancy from packages that use bsd.options.mk
To: NetBSD pkgsrc Discussion <tech-pkg@NetBSD.org>
From: Roland Illig <rillig@NetBSD.org>
List: tech-pkg
Date: 06/06/2007 09:44:43
This is a multi-part message in MIME format.
--------------040300090001040102050601
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

we have a fairly established convention of how the variables for 
package-specific options are called: PKG_OPTIONS.${pkgbase}. In most 
cases, this value can be computed from either PKGNAME or DISTNAME (in 
that order), so that most of the currently 570 definitions for that 
variable can be removed. The appended patch does the work to enable the 
removal. May I commit it?

I'm asking because I am not sure about other's opinions. Maybe some 
developers want to keep that redundancy to make the reader aware of the 
variable name. But to those I can say that the variable name is printed 
in an eye-catching way when building the package.

By the way, the WARNINGS variable isn't used yet, but certainly will 
become used in the near future. In the same step, I may want to rename 
PKG_FAIL_REASON to ERRORS, since I didn't like that variable name from 
the beginning: It's a list of things, but the name isn't a plural form. 
The name is also quite long. See NetBSD's htdocs/share/mk/web.site.mk, 
at the very end, for prior art.

Roland

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

Index: bsd.options.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.options.mk,v
retrieving revision 1.60
diff -u -p -r1.60 bsd.options.mk
--- bsd.options.mk	6 Jun 2007 07:12:31 -0000	1.60
+++ bsd.options.mk	6 Jun 2007 07:35:48 -0000
@@ -11,9 +11,11 @@
 #
 #			PKG_SUPPORTED_OPTIONS=	kerberos ldap ssl
 #
-#	PKG_OPTIONS_VAR (must be defined)
+#	PKG_OPTIONS_VAR
 #               The variable the user can set to enable or disable
-#		options specifically for this package.
+#		options specifically for this package. If it is not
+#		given, it is derived from either PKGNAME or DISTNAME,
+#		and is of the form PKG_OPTIONS.${PKGBASE}.
 #
 #	PKG_OPTIONS_OPTIONAL_GROUPS
 #		This is a list of names of groups of mutually exclusive
@@ -155,6 +157,22 @@
 PKG_OPTIONS=		# empty
 
 # Check for variable definitions required before including this file.
+.if defined(PKG_OPTIONS_VAR) && defined(PKGNAME)
+.  if ${PKG_OPTIONS_VAR} == "PKG_OPTIONS.${PKGNAME:C/-[0-9].*//}"
+WARNINGS+=	"[bsd.options.mk] Setting PKG_OPTIONS_VAR is redundant, since it can be derived from PKGNAME."
+.  endif
+.endif
+.if defined(PKG_OPTIONS_VAR) && defined(DISTNAME)
+.  if ${PKG_OPTIONS_VAR} == "PKG_OPTIONS.${DISTNAME:C/-[0-9].*//}"
+WARNINGS+=	"[bsd.options.mk] Setting PKG_OPTIONS_VAR is redundant, since it can be derived from DISTNAME."
+.  endif
+.endif
+.if defined(PKGNAME)
+PKG_OPTIONS_VAR?=	PKG_OPTIONS.${PKGNAME:C/-[0-9].*//}
+.endif
+.if defined(DISTNAME)
+PKG_OPTIONS_VAR?=	PKG_OPTIONS.${DISTNAME:C/-[0-9].*//}
+.endif
 .if !defined(PKG_OPTIONS_VAR)
 PKG_FAIL_REASON+=	"[bsd.options.mk] PKG_OPTIONS_VAR is not defined."
 .endif

--------------040300090001040102050601--