b95f6cc
diff -up Python-2.7/Makefile.pre.in.fix-parallel-make Python-2.7/Makefile.pre.in
b95f6cc
--- Python-2.7/Makefile.pre.in.fix-parallel-make	2010-07-22 15:01:39.567996932 -0400
b95f6cc
+++ Python-2.7/Makefile.pre.in	2010-07-22 15:47:02.437998509 -0400
b95f6cc
@@ -207,6 +207,7 @@ SIGNAL_OBJS=	@SIGNAL_OBJS@
b95f6cc
 
b95f6cc
 ##########################################################################
b95f6cc
 # Grammar
b95f6cc
+GRAMMAR_STAMP=	$(srcdir)/grammar-stamp
b95f6cc
 GRAMMAR_H=	$(srcdir)/Include/graminit.h
b95f6cc
 GRAMMAR_C=	$(srcdir)/Python/graminit.c
b95f6cc
 GRAMMAR_INPUT=	$(srcdir)/Grammar/Grammar
b95f6cc
@@ -530,10 +531,24 @@ Modules/getpath.o: $(srcdir)/Modules/get
b95f6cc
 Modules/python.o: $(srcdir)/Modules/python.c
b95f6cc
 	$(MAINCC) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/python.c
b95f6cc
 
b95f6cc
+# GNU "make" interprets rules with two dependents as two copies of the rule.
b95f6cc
+# 
b95f6cc
+# In a parallel build this can lead to pgen being run twice, once for each of
b95f6cc
+# GRAMMAR_H and GRAMMAR_C, leading to race conditions in which the compiler
b95f6cc
+# reads a partially-overwritten copy of one of these files, leading to syntax
b95f6cc
+# errors (or linker errors if the fragment happens to be syntactically valid C)
b95f6cc
+#
b95f6cc
+# See http://www.gnu.org/software/hello/manual/automake/Multiple-Outputs.html
b95f6cc
+# for more information
b95f6cc
+#
b95f6cc
+# Introduce ".grammar-stamp" as a contrived single output from PGEN to avoid
b95f6cc
+# this:
b95f6cc
+$(GRAMMAR_H) $(GRAMMAR_C): $(GRAMMAR_STAMP)
b95f6cc
 
b95f6cc
-$(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
b95f6cc
+$(GRAMMAR_STAMP): $(PGEN) $(GRAMMAR_INPUT)
b95f6cc
 		-@$(INSTALL) -d Include
b95f6cc
 		-$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
b95f6cc
+		touch $(GRAMMAR_STAMP)
b95f6cc
 
b95f6cc
 $(PGEN):	$(PGENOBJS)
b95f6cc
 		$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)