Subject: Re: tools/Makefile parallel make issue
To: Lubomir Sedlacik <salo@Xtrmntr.org>
From: Jachym Holecek <freza@dspfpga.com>
List: tech-toolchain
Date: 08/02/2006 17:35:13
Hello,

# Lubomir Sedlacik 2006-07-06:
> yesterday, my "tools" build failed while building a i386 distribution
> from the same sources with which i just hours ago successfully built
> sparc64 sets.
> 
> i always build from read-only source tree, with a clean TOOLDIR and
> OBJDIR (nonexistent, actually), e.g., typically like this:
> 
>   ./build.sh -O /opt/obj -T /opt/tools -U -j 2 tools
> 
> the failure was caused by a "cleandir" running in parallel within the
> same directory "dependall" was just spawned (running configure at the
> moment), in tools/compat.
> 
> the problem seems to lie in src/tools/Makefile:
> 
>   realall realdepend: .MAKE
>   .if "${PREVIOUSTOOLDIR}" != "${TOOLDIR}"
>           @echo "*** WARNING: TOOLDIR has moved?"
>           @echo "*** PREVIOUSTOOLDIR '${PREVIOUSTOOLDIR}'"
>           @echo "***     !=  TOOLDIR '${TOOLDIR}'"
>           @echo "*** Cleaning mis-matched tools"
>           rm -f PREVIOUSTOOLDIR
>           (cd ${.CURDIR} && ${MAKE} cleandir)
>   .endif

The patch below seems to help for me (tested from -j2 upto -j16). The
problem seems to be the lack of ordering between tools/Makefile's
realall & realdepend targets and <bsd.subdir.mk> in combination with
toplevel rules in <bsd.own.mk>.

It's somewhat of a hack though, I would have thought that:

.ORDER: realdepend subdir-dependall
.ORDER: realall subdir-all

would just work (as my reading of make(1) suggests), but it didn't.
Also, I've only tried with build.sh, not manual build -- so I don't
claim the underlying problem was identified correctly...

	-- Jachym

Index: tools/Makefile
===================================================================
RCS file: /cvsroot/src/tools/Makefile,v
retrieving revision 1.99
diff -d -p -u -u -r1.99 Makefile
--- tools/Makefile	22 Jun 2006 20:03:41 -0000	1.99
+++ tools/Makefile	2 Aug 2006 15:07:40 -0000
@@ -126,7 +126,13 @@ PREVIOUSTOOLDIR=	
 
 CLEANFILES+=	PREVIOUSTOOLDIR
 
+.for sub in ${SUBDIR}
+.ORDER: realdepend dependall-${sub}
+.ORDER: realall all-${sub}
+.endfor
+
 realall realdepend: .MAKE
+	@echo "######### Start ${.TARGET} {{{"
 .if "${PREVIOUSTOOLDIR}" != "${TOOLDIR}"
 	@echo "*** WARNING: TOOLDIR has moved?"
 	@echo "*** PREVIOUSTOOLDIR '${PREVIOUSTOOLDIR}'"
@@ -136,6 +142,7 @@ realall realdepend: .MAKE
 	(cd ${.CURDIR} && ${MAKE} cleandir)
 .endif
 	echo ${TOOLDIR} > PREVIOUSTOOLDIR
+	@echo "######### End ${.TARGET} }}}"
 
 # For each .WAIT point, make sure the immediately preceding target is
 # installed before building anything after that point.