Subject: Re: Build problem with "-j 2" in "src/usr.bin/ktruss"
To: None <current-users@NetBSD.org>
From: Alan Barrett <apb@cequrux.com>
List: current-users
Date: 07/10/2004 08:22:52
On Fri, 09 Jul 2004, Matthias Scheler wrote:
> building NetBSD-current with "-j 2" fails most of the time on my system
> in "src/usr.bin/ktruss". The reason is that it shares the dynamically
> generated source file "ioctl.c" with "src/usr.bin/kdump" but doesn't
> (reliably) wait until the file has really been created.
> 
> I can think of two ways to fix this:
> 
> 1.) Insert a ".WAIT" between "kdump" and "ktruss" in "src/usr.bin/Makefile".
> 2.) Prefixing the name of the created file with "${PROG}-":

3.) create the file under a unique name, and then rename it.

The appended patch attempts to do (3), but is untested.

BTW, if you use objdirs, then you probably won't see this problem at
all, because I would expect the two copies to end up in different
directories.

--apb (Alan Barrett)


Index: usr.bin/kdump/Makefile.ioctl-c
--- usr.bin/kdump/Makefile.ioctl-c	7 Jul 2004 14:28:17 -0000	1.15
+++ usr.bin/kdump/Makefile.ioctl-c	10 Jul 2004 06:18:32 -0000
@@ -8,10 +8,16 @@
 DEPFILES != egrep -l '(_IO\(|_IOR\(|_IOW\(|_IORW\()' ${DEPFILEGLOB}
 .endif
 
+# ioctl.c is used by both kdump and ktruss.  Avoid a race with "make -j N"
+# by generating the file under a unique name and then renaming it.
+TMPSUFFIX!= echo tmp.$$$$
+CLEANFILES+= *.tmp.*
+
 ioctl.c: mkioctls Makefile ${DEPFILES}
 	${_MKTARGET_CREATE}
 	CC="${CC}" DESTDIR=${DESTDIR} \
 	    ${HOST_SH} ${NETBSDSRCDIR}/usr.bin/kdump/mkioctls \
-	    ${DEPFILES} > ioctl.c
+	    ${DEPFILES} > ${.TARGET}.${TMPSUFFIX}
+	mv ${.TARGET}.${TMPSUFFIX} ${.TARGET}
 
 ${DEPFILES}: .PRECIOUS