Here's a different approach that doesn't involve the ugly branching
depending on id -u.
When Theo and I discussed the problem, we concluded that the order of
cleandir: and includes: is wrong during make build. Swapping them
results in a list of 28 root-owned files in /usr/obj/:
lib/libcrypto/obj_mac.num.tmp
lib/libcrypto/obj_mac.h
lib/librpcsvc/bootparam_prot.h
lib/librpcsvc/klm_prot.h
lib/librpcsvc/mount.h
lib/librpcsvc/nfs_prot.h
lib/librpcsvc/nlm_prot.h
lib/librpcsvc/rex.h
lib/librpcsvc/rnusers.h
lib/librpcsvc/rusers.h
lib/librpcsvc/rquota.h
lib/librpcsvc/rstat.h
lib/librpcsvc/rwall.h
lib/librpcsvc/sm_inter.h
lib/librpcsvc/spray.h
lib/librpcsvc/yp.h
lib/librpcsvc/yppasswd.h
gnu/usr.bin/cc/include/mm_malloc.h
gnu/usr.bin/cc/include/unwind.h
sys/arch/amd64/stand/mbr/machine ->
/usr/src/sys/arch/amd64/stand/mbr/../../../../arch/amd64/include
sys/arch/amd64/stand/cdbr/machine ->
/usr/src/sys/arch/amd64/stand/cdbr/../../../../arch/amd64/include
sys/arch/amd64/stand/biosboot/machine ->
/usr/src/sys/arch/amd64/stand/biosboot/../../../../arch/amd64/include
sys/arch/amd64/stand/boot/machine ->
/usr/src/sys/arch/amd64/stand/boot/../../../../arch/amd64/include
sys/arch/amd64/stand/cdboot/machine ->
/usr/src/sys/arch/amd64/stand/cdboot/../../../../arch/amd64/include
sys/arch/amd64/stand/fdboot/machine ->
/usr/src/sys/arch/amd64/stand/fdboot/../../../../arch/amd64/include
sys/arch/amd64/stand/pxeboot/machine ->
/usr/src/sys/arch/amd64/stand/pxeboot/../../../../arch/amd64/include
sys/arch/amd64/stand/efiboot/bootx64/machine ->
/usr/src/sys/arch/amd64/stand/efiboot/bootx64/../../../../../arch/amd64/include
sys/arch/amd64/stand/efiboot/bootia32/machine ->
/usr/src/sys/arch/amd64/stand/efiboot/bootia32/../../../../../arch/amd64/include
The attached patch is a suggestion for solving the problem with the *.h
files only.
To see what's going on, notice that include/Makefile maintains two lists:
* PRDIRS: the directories with a prereq: target
* RDIRS: the directories with an include: target
the list of PRDIRS is appended to the RDIRS.
Currently, on non-gcc3 architectures, PRDIRS only contains libstdc++-v3.
If we add libcrypto, librpcsvc and gnu/usr.bin/cc to PRDIRS and add a
prereq target to their Makefiles, the prereq target is executed as
BUILDUSER before make includes, and the files end up being correctly
owned. I tested the patch successfully with make release on amd64.
I haven't yet invsetigated how to deal with the machine@ symlinks from
sys/arch/${MACHINE}, but a similar approach could work.
Index: Makefile
===================================================================
RCS file: /var/cvs/src/Makefile,v
retrieving revision 1.129
diff -u -p -U4 -r1.129 Makefile
--- Makefile 6 Oct 2016 18:56:17 -0000 1.129
+++ Makefile 13 Oct 2016 17:31:04 -0000
@@ -78,10 +78,10 @@ build:
echo $@ must be called by root >&2; \
false; \
fi
cd ${.CURDIR}/share/mk && exec ${MAKE} install
- exec ${MAKE} includes
exec ${MAKE} cleandir
+ exec ${MAKE} includes
cd ${.CURDIR}/lib && \
su ${BUILDUSER} -c '${MAKE} depend && exec ${MAKE}' && \
NOMAN=1 exec ${MAKE} install
cd ${.CURDIR}/gnu/lib && \
Index: include/Makefile
===================================================================
RCS file: /var/cvs/src/include/Makefile,v
retrieving revision 1.213
diff -u -p -U4 -r1.213 Makefile
--- include/Makefile 23 Sep 2016 09:18:05 -0000 1.213
+++ include/Makefile 15 Oct 2016 15:10:24 -0000
@@ -28,16 +28,16 @@ DIRS= arpa protocols rpc rpcsvc
LDIRS= crypto ddb dev isofs miscfs msdosfs net netinet netinet6 \
netmpls net80211 nfs ntfs scsi sys ufs uvm
# Places that need a prerequisite target met before includes
-PRDIRS=
+PRDIRS= ../lib/libcrypto ../lib/librpcsvc
# Directories with an includes target
-RDIRS= ../lib/libcrypto ../lib/libcurses ../lib/libedit \
+RDIRS= ../lib/libcurses ../lib/libedit \
../lib/libevent ../lib/libexpat ../lib/libform \
../lib/libfuse ../lib/libkeynote ../lib/libmenu \
../lib/libossaudio ../lib/libpanel ../lib/libpcap \
- ../lib/libradius ../lib/librpcsvc ../lib/librthread \
+ ../lib/libradius ../lib/librthread \
../lib/libskey ../lib/libssl ../lib/libtls \
../lib/libusbhid ../lib/libutil ../lib/libz \
../usr.bin/lex ../gnu/lib/libreadline \
../sys/arch/${MACHINE}
@@ -46,10 +46,9 @@ RDIRS= ../lib/libcrypto ../lib/libcurses
RDIRS+= ../gnu/usr.bin/gcc ../gnu/lib/libobjc
PRDIRS+= ../gnu/lib/libstdc++
.else
RDIRS+= ../gnu/usr.bin/cc/libobjc
-PRDIRS+= ../gnu/lib/libstdc++-v3
-RDIRS+= ../gnu/usr.bin/cc/include
+PRDIRS+= ../gnu/lib/libstdc++-v3 ../gnu/usr.bin/cc/include
.endif
# prereq implies includes
RDIRS += ${PRDIRS}
Index: lib/libcrypto/Makefile
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/Makefile,v
retrieving revision 1.7
diff -u -p -U4 -r1.7 Makefile
--- lib/libcrypto/Makefile 23 Sep 2016 21:49:30 -0000 1.7
+++ lib/libcrypto/Makefile 15 Oct 2016 14:19:17 -0000
@@ -372,9 +372,11 @@ HDRS=\
HDRS_GEN=\
${.CURDIR}/arch/${MACHINE_CPU}/opensslconf.h \
${.OBJDIR}/obj_mac.h
-includes: obj_mac.h
+prereq: obj_mac.h
+
+includes: prereq
@test -d ${DESTDIR}/usr/include/openssl || \
mkdir ${DESTDIR}/usr/include/openssl
@for i in $(HDRS); do \
j="cmp -s $$i ${DESTDIR}/usr/include/openssl/`basename $$i` || \
Index: lib/librpcsvc/Makefile
===================================================================
RCS file: /var/cvs/src/lib/librpcsvc/Makefile,v
retrieving revision 1.10
diff -u -p -U4 -r1.10 Makefile
--- lib/librpcsvc/Makefile 2 Aug 2012 13:38:39 -0000 1.10
+++ lib/librpcsvc/Makefile 15 Oct 2016 14:24:39 -0000
@@ -12,8 +12,9 @@ LIB= rpcsvc
NOMAN=
all: ${HDRS}
beforedepend: ${HDRS}
+prereq: ${HDRS}
includes: ${HDRS}
${INSTALL} -d -o ${BINOWN} -g ${BINGRP} -m 755 \
${DESTDIR}/usr/include/rpcsvc
Index: gnu/usr.bin/cc/include/Makefile
===================================================================
RCS file: /var/cvs/src/gnu/usr.bin/cc/include/Makefile,v
retrieving revision 1.11
diff -u -p -U4 -r1.11 Makefile
--- gnu/usr.bin/cc/include/Makefile 1 Sep 2016 11:03:09 -0000 1.11
+++ gnu/usr.bin/cc/include/Makefile 15 Oct 2016 14:29:53 -0000
@@ -43,8 +43,10 @@ cleandir: _SUBDIRUSE clean
depend:
# Nothing here so far...
+prereq: mm_malloc.h unwind.h
+
.if !empty(INCS)
install includes: ${INCS}
${INSTALL} -C -o ${BINOWN} -g ${LOCALEGRP} -m ${NONBINMODE} ${.ALLSRC} \
${DESTDIR}/usr/include