Subject: Re: Another try (was Re: moving md5 and patch-sum from files/ to pkg/)
To: Jeremy C. Reed <reed@reedmedia.net>
From: Alistair Crooks <agc@pkgsrc.org>
List: tech-pkg
Date: 04/05/2001 10:38:58
On Thu, Apr 05, 2001 at 02:08:29AM -0700, Jeremy C. Reed wrote:
> Below is my second try at a patch (for bsd.pkg.mk) to use pkg/ directory
> instead of files/ directory for md5 and patch-sum. It also changes name of
> md5 to checksum.
> 
> This patch is better than my previous patch (Mar. 15), because it will
> fallback to previous defaults (so it can work with old packages).
> 
> The benefit (in the long run) is to remove unnecessary files/ directories.
> This should save a little space and a lot of time.

Eek - it would appear that I've duplicated some of your work.

I made these patches, in response to feedback I received about some
earlier ones, to do roughly the same kind of thing:

As a management overview to this:

1.  If a file called "digest" exists in the pkgsrc directory for the
package, then the digests will be taken from there.  If a "digest"
file doesn't exist, the old files/* digests will be used.

2.  Any "make makesum" or "make makepatchsum" will create a new digest
file.  This will eliminate the need for the files/ directory in most
cases.

3.  I originally modified things so that there was only one target,
"make makesum", and it did digests/checksums for distfiles and
patches, but wiser voices prevailed upon me such that they would like
to be able to generate digests for packages without having the
distfile available.

4.  I placed the "digest" file in the package's directory, since I
believe it sits best there - it is part of the build process for the
package, not part of the packaging process for the package, and it
didn't seem right in the pkg/ directory.

5.  I called the file "digest", and I'm not completely wedded to the
name, mainly because it then comes up in the package directory in
roughly the same place as the files/ directory used to, when listed
alphabetically.  One person has asked for it to be "checksum", but I'd
like further feedback.  Whatever, I'd like to keep the name generic.

6.  This will leave us with some md5 digests in the new digest file,
but they will be replaced by sha1 digests over time.

7.  Note that this actually reduces the size of bsd.pkg.mk. Is this a
first?

Regards,
Alistair

--- bsd.pkg.mk.orig	Wed Apr  4 17:32:41 2001
+++ bsd.pkg.mk	Wed Apr  4 17:54:11 2001
@@ -273,8 +273,15 @@
 # Miscellaneous overridable commands:
 SHCOMMENT?=		${ECHO_MSG} >/dev/null '***'
 
+NEW_DIGEST_FILE?=	${.CURDIR}/digest
+
+.if exists(${NEW_DIGEST_FILE})
+DIGEST_FILE?=		${NEW_DIGEST_FILE}
+PATCH_SUM_FILE?=	${NEW_DIGEST_FILE}
+.else
 DIGEST_FILE?=		${FILESDIR}/md5
 PATCH_SUM_FILE?=	${FILESDIR}/patch-sum
+.endif
 
 .if exists(/usr/bin/m4)
 M4?=			/usr/bin/m4
@@ -2477,70 +2484,43 @@
 
 .if !target(makesum)
 makesum: fetch uptodate-digest
-	${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${FILESDIR}
-	${_PKG_SILENT}${_PKG_DEBUG}if [ -f ${DIGEST_FILE} ]; then ${RM} -f ${DIGEST_FILE}; fi
-	@${ECHO} -n "$$" > ${DIGEST_FILE};				\
-		${ECHO} -n "NetBSD" >> ${DIGEST_FILE}; 			\
-		${ECHO} "$$" >> ${DIGEST_FILE};				\
-		${ECHO} "" >> ${DIGEST_FILE}
-	${_PKG_SILENT}${_PKG_DEBUG}cd ${DISTDIR};			\
+	${_PKG_SILENT}${_PKG_DEBUG}					\
+	newfile=${NEW_DIGEST_FILE}.$$$$;				\
+	${ECHO} -n "$$" > $$newfile;					\
+		${ECHO} -n "NetBSD" >> $$newfile; 			\
+		${ECHO} "$$" >> $$newfile;				\
+		${ECHO} "" >> $$newfile;				\
+	cd ${DISTDIR};							\
 	for sumfile in "" ${_CKSUMFILES}; do				\
 		if [ "X$$sumfile" = "X" ]; then continue; fi;		\
-		${DIGEST} ${DIGEST_ALGORITHM} $$sumfile >> ${DIGEST_FILE}; \
-	done
-	${_PKG_SILENT}${_PKG_DEBUG}					\
+		${DIGEST} ${DIGEST_ALGORITHM} $$sumfile >> $$newfile;	\
+	done;								\
 	for ignore in "" ${_IGNOREFILES}; do				\
 		if [ "X$$ignore" = "X" ]; then continue; fi;		\
-		${ECHO} "${DIGEST_ALGORITHM} ($$ignore) = IGNORE" >> ${DIGEST_FILE}; \
-	done
+		${ECHO} "${DIGEST_ALGORITHM} ($$ignore) = IGNORE" >> $$newfile; \
+	done;								\
+	${AWK} '$$2 ~ /\(patch-[a-z0-9]+\)/ { print $$0 }' < ${PATCH_SUM_FILE} >> $$newfile; \
+	${MV} $$newfile ${NEW_DIGEST_FILE}
 .endif
 
 .if !target(makepatchsum)
 makepatchsum mps: uptodate-digest
 	${_PKG_SILENT}${_PKG_DEBUG}					\
-	(${MKDIR} ${FILESDIR};						\
-	${ECHO_MSG} "${_PKGSRC_IN}> Making patch checksums";		\
-	if [ -f "${PATCH_SUM_FILE}" ]; then				\
-		${AWK} -- '{print ; exit}' < ${PATCH_SUM_FILE} > ${PATCH_SUM_FILE}.new; \
-	else								\
-		${ECHO} -n "$$" > ${PATCH_SUM_FILE}.new;		\
-		${ECHO} -n "NetBSD" >> ${PATCH_SUM_FILE}.new;		\
-		${ECHO} "$$" >> ${PATCH_SUM_FILE}.new;			\
-	fi;								\
-	${ECHO} "" >> ${PATCH_SUM_FILE}.new;				\
-	havepatches=0;							\
+	newfile=${NEW_DIGEST_FILE}.$$$$;				\
+	${AWK} '$$2 !~ /\(patch-[a-z0-9]+\)/ { print $$0 }' < ${DIGEST_FILE} >> $$newfile; \
 	if [ -d ${PATCHDIR} ]; then					\
-		cd ${PATCHDIR};						\
+		(cd ${PATCHDIR};					\
 		for sumfile in "" patch-*; do				\
 			if [ "X$$sumfile" = "X" ]; then continue; fi;	\
 			if [ "X$$sumfile" = "Xpatch-*" ]; then break; fi; \
 			case $$sumfile in				\
 				patch-local-*) ;;			\
 				*.orig) continue ;;			\
-				*)	${ECHO} "${DIGEST_ALGORITHM} ($$sumfile) = `${SED} -e '/\$$NetBSD.*/d' $$sumfile | ${DIGEST} ${DIGEST_ALGORITHM}`" >> ${PATCH_SUM_FILE}.new; \
-					havepatches=1 ;;		\
+				*)	${ECHO} "${DIGEST_ALGORITHM} ($$sumfile) = `${SED} -e '/\$$NetBSD.*/d' $$sumfile | ${DIGEST} ${DIGEST_ALGORITHM}`" >> $$newfile;; \
 			esac;						\
-		done;							\
+		done);							\
 	fi;								\
-	if [ $$havepatches = 0 ]; then					\
-		if [ -f "${PATCH_SUM_FILE}" ]; then			\
-			${ECHO} "This placeholder file is generated by the \`\`makepatchsum'' target" >> ${PATCH_SUM_FILE}.new; \
-			${ECHO} "whenever the patches directory is empty or missing. Its purpose" >> ${PATCH_SUM_FILE}.new; \
-			${ECHO} "is to ensure that the presence of any obsolete patches will cause" >> ${PATCH_SUM_FILE}.new; \
-			${ECHO} "the proper error to be emitted at build time." >> ${PATCH_SUM_FILE}.new; \
-			${ECHO_MSG} "=> placeholder patch-sum file created"; \
-		else							\
-			${RM} -f ${PATCH_SUM_FILE}.new;			\
-			${ECHO_MSG} "=> no patch-sum file created";	\
-			exit 0;						\
-		fi;							\
-	fi;								\
-	if cmp -s ${PATCH_SUM_FILE}.new ${PATCH_SUM_FILE}; then		\
-		${RM} -f ${PATCH_SUM_FILE}.new;				\
-		${ECHO_MSG} "=> patch-sum file unchanged";		\
-	else								\
-		${MV} ${PATCH_SUM_FILE}.new ${PATCH_SUM_FILE};		\
-	fi)
+	${MV} $$newfile ${NEW_DIGEST_FILE}
 .endif
 
 .if !target(checksum)