Subject: Re: CVS commit: sharesrc/share/mk
To: Perry E. Metzger <perry@wasabisystems.com>
From: Todd Vierling <tv@wasabisystems.com>
List: tech-toolchain
Date: 11/02/2001 13:32:25
On 2 Nov 2001, Perry E. Metzger wrote:

: > How about "MKPRIV", with "yes"/"no" logic?  This requires the
: > following changes:
:
: I prefer a MKUNPRIV or something like that. We're definitely talking
: about the "new case".

This is divergent from all the other MK* variables which default to "yes",
all of which came from NO* negative definition flags.

I still believe that MKPRIV is the appropriate name.  With that said, below
is an untested diff to implement it, with automatic switch-off if building
as non-root.

Note that *separate* options should cause unprivileged building and metadata
logging.  There are cases where one may want to build (to test building, for
instance) and not do all the metadata collection.  This is the way I've been
building lately, for instance, and I don't want metadata to start building
all of a sudden.

=====

Index: etc/Makefile
===================================================================
RCS file: /cvsroot/basesrc/etc/Makefile,v
retrieving revision 1.190
diff -u -r1.190 Makefile
--- etc/Makefile	2001/10/31 02:58:58	1.190
+++ etc/Makefile	2001/11/02 18:27:54
@@ -274,9 +274,13 @@
 .endif
 .endif

+.if ${MKPRIV} == "no"
+MTREE_NOWHACK?=	-W
+.endif
+
 distrib-dirs:
 	${INSTALL} ${INSTPRIV} -d -o root -g wheel -m 755 ${DESTDIR}
-	${MTREE} -def mtree/NetBSD.dist -p ${DESTDIR}/ -U ${UNPRIVILEGED:D-W}
+	${MTREE} -def mtree/NetBSD.dist -p ${DESTDIR}/ -U ${MTREE_NOWHACK}
 	rm -f ${DESTDIR}/sys
 	${INSTALL} ${INSTPRIV} -l s -o root -g wheel -m 755 \
 		usr/src/sys ${DESTDIR}/sys
Index: games/phantasia/Makefile
===================================================================
RCS file: /cvsroot/basesrc/games/phantasia/Makefile,v
retrieving revision 1.23
diff -u -r1.23 Makefile
--- games/phantasia/Makefile	2001/06/06 17:34:19	1.23
+++ games/phantasia/Makefile	2001/11/02 18:27:54
@@ -1,7 +1,7 @@
 #	$NetBSD: Makefile,v 1.23 2001/06/06 17:34:19 lukem Exp $
 #	@(#)Makefile	8.1 (Berkeley) 5/31/93

-.include <bsd.own.mk>		# for UNPRIVILEGED
+.include <bsd.own.mk>

 PROG=	phantasia
 SRCS=	fight.c gamesupport.c interplayer.c io.c main.c misc.c phantglobs.c
Index: gnu/usr.bin/ld.new/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/ld.new/Makefile,v
retrieving revision 1.24
diff -u -r1.24 Makefile
--- gnu/usr.bin/ld.new/Makefile	2001/08/06 15:56:08	1.24
+++ gnu/usr.bin/ld.new/Makefile	2001/11/02 18:27:54
@@ -1,6 +1,5 @@
 #	$NetBSD: Makefile,v 1.24 2001/08/06 15:56:08 tv Exp $

-# for OBJECT_FMT, UNPRIVILEGED
 .include <bsd.own.mk>

 .if !defined(USE_NEW_TOOLCHAIN)
@@ -147,7 +146,7 @@
 afterinstall:
 .if ${MKSHARE} != "no"
 	(cd ldscripts ; pax -rw . ${DESTDIR}${SCRIPTDIR})
-.if !defined(UNPRIVILEGED)
+.if ${MKPRIV} != "no"
 	chown -R ${BINOWN}:${BINGRP} ${DESTDIR}${SCRIPTDIR}
 .endif
 	find ${DESTDIR}${SCRIPTDIR} -type f | xargs chmod a=rX
Index: share/mk/bsd.own.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.own.mk,v
retrieving revision 1.205
diff -u -r1.205 bsd.own.mk
--- share/mk/bsd.own.mk	2001/11/02 05:21:51	1.205
+++ share/mk/bsd.own.mk	2001/11/02 18:27:54
@@ -172,8 +172,10 @@
 COPY?=		-c
 PRESERVE?=	${UPDATE:D-p}
 RENAME?=	-r
-INSTPRIV?=	${UNPRIVILEGED:D-U}
 STRIPFLAG?=	-s
+.if ${MKPRIV} == "no"
+INSTPRIV?=	-U
+.endif

 INSTALL_DIR?=	${INSTALL} ${INSTPRIV} -d
 INSTALL_FILE?=	${INSTALL} ${COPY} ${PRESERVE} ${RENAME} ${INSTPRIV}
@@ -366,6 +368,21 @@
 .else
 MKPICINSTALL?=yes
 .endif
+
+# If UNPRIVILEGED is defined, or if MKPRIV is undefined (and the host
+# matches the target, and running as root), set MKPRIV to no.  Otherwise
+# default to yes.
+.if defined(UNPRIVILEGED)
+MKPRIV=		no
+.elif !defined(MKPRIV) && \
+      (${HOST_OSTYPE:C/^NetBSD-[^-]*-([^-]*)$/\1-\2/:M${MACHINE_ARCH}} != "")
+_ISPRIV!=	id -u
+.if ${_ISPRIV} != "0"
+MKPRIV=		no
+.endif
+.endif
+MKPRIV?=	yes
+.MAKEOVERRIDES+= MKPRIV

 .if defined(NOPROFILE)
 MKPROFILE=no
Index: share/zoneinfo/Makefile
===================================================================
RCS file: /cvsroot/sharesrc/share/zoneinfo/Makefile,v
retrieving revision 1.22
diff -u -r1.22 Makefile
--- share/zoneinfo/Makefile	1999/08/21 06:30:12	1.22
+++ share/zoneinfo/Makefile	2001/11/02 18:27:54
@@ -77,7 +77,7 @@
 .if ${MKSHARE} != "no"
 afterinstall: ${DATA} ${REDO}
 	${ZIC} -y ${YEARISTYPE} -d ${TZDIR} -p ${POSIXRULES}
-.if !defined(UNPRIVILEGED)
+.if ${MKPRIV} != "no"
 	chown -R ${BINOWN}:${BINGRP} ${TZDIR}
 .endif
 	find ${TZDIR} -type f | xargs chmod a=r