Subject: Re: bin-install and running make package as root
To: None <tech-pkg@NetBSD.org>
From: Alan Barrett <apb@cequrux.com>
List: tech-pkg
Date: 06/17/2006 21:44:30
On Sat, 17 Jun 2006, Jeremy C. Reed wrote:
> Old PR is here
> http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=24626
> 
> It has a fix for this, but never got committed and now the code has 
> changed. I see the real-su-* are gone and it has a su-target. Any 
> suggestions or fixes for this before I jump into this?

Here's the relevant part of my private patches to bsd.pkg.mk.  This
is probably not directly usable, but perhaps you can treat it as a
suggestion.  I don't think I've tested this since the most recent round
of merge conflicts.

--apb (Alan Barrett)

--- bsd.pkg.mk
+++ bsd.pkg.mk
@@ -1196,11 +1205,17 @@
 acquire-wrapper-lock: acquire-lock
 acquire-configure-lock: acquire-lock
 acquire-build-lock: acquire-lock
+.PHONY: acquire-bin-install-lock
+acquire-bin-install-lock:
+	${_PKG_SILENT}${_PKG_DEBUG}${SHCOMMENT} "XXX Locking doesn't work if WRKDIR does not exist."
 
 .PHONY: release-wrapper-lock release-configure-lock release-build-lock
 release-wrapper-lock: release-lock
 release-configure-lock: release-lock
 release-build-lock: release-lock
+.PHONY: release-bin-install-lock
+release-bin-install-lock:
+	${_PKG_SILENT}${_PKG_DEBUG}${SHCOMMENT} "XXX Locking doesn't work if WRKDIR does not exist."
 
 ################################################################
 # Skeleton targets start here
@@ -1557,10 +1572,21 @@
 _SHORT_UNAME_R=	${:!${UNAME} -r!:C@\.([0-9]*)[_.].*@.\1@} # n.n[_.]anything => n.n
 
 # Install binary pkg, without strict uptodate-check first
-.PHONY: su-bin-install
-su-bin-install:
+.PHONY: su-bin-install-pkgadd
+su-bin-install-pkgadd:
+	${SETENV} PKG_PATH="$$pkgpath" ${PKG_ADD} ${_BIN_INSTALL_FLAGS} ${PKGNAME_REQD:U${PKGNAME}:Q}${PKG_SUFX}
+
+.PHONY: bin-install-pkgadd
+bin-install-pkgadd: su-target
+	@${PHASE_MSG} "Binary install for "${PKGNAME_REQD:U${PKGNAME}:Q}
+
+.PHONY: real-bin-install
+real-bin-install:
 	@found="`${PKG_BEST_EXISTS} \"${PKGWILDCARD}\" || ${TRUE}`";	\
-	if [ "$$found" != "" ]; then					\
+	if [ "$$found" = "${PKGNAME}" ]; then				\
+		${ECHO_MSG} "${_PKGSRC_IN}> $$found is already installed."; \
+		${SHCOMMENT} "This is not an error.";			\
+	elif [ "$$found" != "" ]; then					\
 		${ERROR_MSG} "$$found is already installed - perhaps an older version?"; \
 		${ERROR_MSG} "If so, you may wish to \`\`pkg_delete $$found'' and install"; \
 		${ERROR_MSG} "this package again by \`\`${MAKE} bin-install'' to upgrade it properly."; \
@@ -1571,7 +1598,7 @@
 	pkgpath=${PKGREPOSITORY:Q} ; \
 	for i in ${BINPKG_SITES} ; do pkgpath="$$pkgpath;$$i/All" ; done ; \
 	${ECHO} "Trying $$pkgpath" ; 	\
-	if ${SETENV} PKG_PATH="$$pkgpath" ${PKG_ADD} ${_BIN_INSTALL_FLAGS} ${PKGNAME_REQD:U${PKGNAME}:Q}${PKG_SUFX} ; then \
+	if ${MAKE} ${MAKEFLAGS} bin-install-pkgadd ; then \
 		${ECHO} "`${PKG_INFO} -e ${PKGNAME_REQD:U${PKGNAME}:Q}` successfully installed."; \
 	else 				 			\
 		${SHCOMMENT} Cycle through some FTP server here ;\
@@ -1582,10 +1609,9 @@
 	fi
 
 .PHONY: bin-install
-bin-install: su-target
-	@${PHASE_MSG} "Binary install for "${PKGNAME_REQD:U${PKGNAME}:Q}
+bin-install: install-depends
+bin-install: acquire-bin-install-lock real-bin-install release-bin-install-lock
 
-
 ################################################################
 # The special package-building targets
 # You probably won't need to touch these