Subject: bmake replace patch
To: None <tech-pkg@NetBSD.org>
From: pancake <pancake@phreaker.net>
List: tech-pkg
Date: 10/05/2004 03:33:49
By this way you can type "bmake replace" and no dependency will fail on missing case.

It's useful because you can mantain your software using only the "replace" target. It will autodetect if the target package is installed or not, and will install/replace instead of CRASH with the message "pkg_tarup no pkg found!"

What do you think about this patch?

root@bare:/usr/pkgsrc/mk# diff -u bsd.pkg.mk.orig bsd.pkg.mk
--- bsd.pkg.mk.orig     2004-10-05 03:03:41.000000000 -0400
+++ bsd.pkg.mk  2004-10-05 03:25:31.000000000 -0400
@@ -3257,11 +3257,16 @@
 
 .PHONY: do-su-replace
 do-su-replace:
-       @${ECHO_MSG} "${_PKGSRC_IN}> Replacing ${PKGNAME}"
+       @found="`${PKG_INFO} -e \"${PKGNAME}\" || ${TRUE}`"; \
+       case "$$found" in  \
+       "") realtarget="real-su-install"; action="install"; ${_SU_TARGET} ;; \
+       *) \
+       ${ECHO_MSG} "${_PKGSRC_IN}> Replacing ${PKGNAME}" \
        ${_PKG_SILENT}${_PKG_DEBUG}                                     \
        realtarget="real-su-replace";                                   \
        action="replace";                                               \
-       ${_SU_TARGET}
+       ${_SU_TARGET} ;\
+       esac
 
 .PHONY: do-su-undo-replace
 do-su-undo-replace: