Subject: [RFC] code replacement for the PKGBASE, PKGNAME section in bsd.pkg.mk
To: None <tech-pkg@netbsd.org>
From: Roland Illig <rillig@NetBSD.org>
List: tech-pkg
Date: 10/14/2005 11:16:31
This is a multi-part message in MIME format.
--------------000504010205060506010801
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Hi,
Roland Illig wrote:
> http://mail-index.netbsd.org/tech-pkg/2005/08/21/0004.html
some weeks ago I complained that the first line in package Makefiles has
to look like "DISTNAME=..." instead of "PKGNAME=...". I still find it
aesthetically more pleasing if a package's definition starts with
defining the PKGNAME instead of the DISTNAME. I have therefore written a
patch that can replace the current code to determine PKGNAME, PKGBASE,
PKGVERSION and the like.
The new code allows you to define an arbitrary subset of {DISTNAME,
PKGNAME, PKGBASE, PKGVERSION} and computes the others from them. If
that's not possible uniquely, an error message is printed. This prevents
cases like:
PKGNAME= package-1.0
# ... somewhere else, maybe in another file ...
PKGBASE= pkg
It also allows the following definition:
PKGBASE= httpd
# ,-- maybe in a Makefile.common
PKGVERSION= ${APACHE_VERSION}
This is useful for cases where we use Makefile.common files.
But the main point remains that I've never understood why DISTNAME
should be used over PKGNAME. Since the according check has been in
pkglint since revision 1.1, where we imported it from the FreeBSD ports
collection, that scheme isn't our fault. Can we get rid of it?
By the way, no changes are required to any current package. I know that
it takes another pkgsrc release until we can finally start replacing
DISTNAME=... with PKGNAME=... in packages, since this patch is highly
unlikely to be pulled up to 2005Q3.
Roland
--------------000504010205060506010801
Content-Type: text/plain;
name="bsd.pkg.mk.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="bsd.pkg.mk.patch"
? 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 14 Oct 2005 08:38:20 -0000
@@ -77,22 +77,63 @@ ACCEPTABLE_LICENSES= ${ACCEPTABLE_LICENC
.endif
##### PKGBASE, PKGNAME[_NOREV], PKGVERSION
-
+#
+# Input: DISTNAME PKGNAME PKGBASE PKGVERSION (each may be defined or not)
+# Output: all variables defined or an error message
+#
+# A B C D || (A = DISTNAME, B = PKGNAME, C = PKGBASE, D = PKGVERSION)
+#----------=-=-============================================================
+# - - - - => underspecified
+# - - - X => underspecified
+# - - X - => underspecified
+# - - X X => C+D->B B->A
+# - X - - => B->C B->D B->A
+# - X - X => overspecified
+# - X X - => overspecified
+# - X X X => overspecified
+# X - - - => A->C A->D C+D->B
+# X - - X => A->C C+D->B
+# X - X - => A->D C+D->B
+# X - X X => C+D->B
+# X X - - => B->C B->D
+# X X - X => overspecified
+# X X X - => overspecified
+# X X X X => overspecified
+#--------------------------------------------------------------------------
+
+.if defined(PKGNAME) && (defined(PKGBASE) || defined(PKGVERSION))
+PKG_FAIL_REASON+= "[bsd.pkg.mk] error: PKGNAME is overspecified."
+.elif !defined(DISTNAME) && !defined(PKGNAME) && \
+ !(defined(PKGBASE) && defined(PKGVERSION))
+PKG_FAIL_REASON+= "[bsd.pkg.mk] error: PKGNAME is underspecified."
+PKGNAME?= # empty, to prevent parse errors
+.endif
+.if defined(DISTNAME) && !defined(PKGNAME)
+PKGBASE?= ${DISTNAME:C/-[^-]*$//}
+PKGVERSION?= ${DISTNAME:C/^.*-//}
+.endif
+PKGNAME?= ${PKGBASE}-${PKGVERSION}
PKGBASE?= ${PKGNAME:C/-[^-]*$//}
PKGVERSION?= ${PKGNAME:C/^.*-//}
+DISTNAME?= ${PKGNAME}
+
.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
-PKGNAME?= ${DISTNAME}
-PKGNAME_NOREV= ${PKGNAME}
+_PKGREVISIONPART= # empty
.endif
+PKGNAME_NOREV= ${PKGNAME}
+PKGNAME_REV= ${PKGNAME}${_PKGREVISIONPART}
+PKGVERSION_NOREV= ${PKGVERSION}
+PKGVERSION_REV= ${PKGVERSION}${_PKGREVISIONPART}
+
+# FIXME: These two assignments should be eliminated, as they make
+# ${PKGNAME} and ${PKGVERSION} mean different things, depending on where
+# exactly that variable is used.
+PKGNAME:= ${PKGNAME_REV}
+PKGVERSION:= ${PKGVERSION_REV}
+
##### PLIST
.if ${PKG_INSTALLATION_TYPE} == "pkgviews"
--------------000504010205060506010801--