Skip to content

Commit 7990686

Browse files
author
Kevin Pyle
committed
Avoid competing header generation in parallel builds
When GNU make is given the rule: a b: $(DEPS) command Then for each target that needs an update, command will run. If a single run of command generates all the targets, then multiple runs are at best wasteful and at worst counterproductive if concurrent runs can corrupt each other's output.
1 parent c4af0a9 commit 7990686

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

gcc-c-api/Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,19 @@ install: $(LIBGCC_C_API_SO)
106106
# The python interpreter to use:
107107
PYTHON=python
108108

109-
$(GENERATED_HEADERS): $(SOURCE_XML) xml-to-h.py xmltypes.py
109+
# Describe how to build the first generated header
110+
$(firstword $(GENERATED_HEADERS)):
110111
$(PYTHON) xml-to-h.py
111112

113+
# Make all generated headers depend on the true inputs
114+
$(GENERATED_HEADERS): xml-to-h.py xmltypes.py $(SOURCE_XML)
115+
116+
# Add a fake dependency so that all headers other than the first will
117+
# depend on the first. This allows the first generated header to do
118+
# double duty as a flag file. This indirection ensures that Make will
119+
# only run one instance of the generation rule, rather than one per
120+
# required header file.
121+
$(wordlist 2, $(words $(GENERATED_HEADERS)), $(GENERATED_HEADERS)): $(firstword $(GENERATED_HEADERS))
122+
112123
check-api:
113124
xmllint --noout --relaxng api.rng *.xml

0 commit comments

Comments
 (0)