Fix sporadic failures when using make -j# #668
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
We've been running into sporadic failures when running a premake5 Makefile with
make -j4
. We get errors like:../../external/uuid/clear.c:42:1: fatal error: opening dependency file ../../intermediates/gmake/common/linux64/Debug/clear.d: No such file or directory
Premake generates a target like
all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)
, which works fine for single threaded builds because the prerequisites are run left to right, but with -j4 the rule for$(TARGET)
can get executed before the rule for$(OBJDIR)
, causing the error.Adding
$(OBJDIR)
as a prerequisite for each object file is not ideal because it causesmake; make
to build the project twice. The first time make will see that$(OBJDIR)
doesn't exist and build everything that depends on it, the second time make will see that$(OBJDIR)
has been modified and build everything that depends on it again.The (slightly unsatisfactory) solution that I know of is to call
mkdir -p $(OBJDIR)
every time you build an object.I've attached a patch which implements the unsatisfactory solution for C++ Makefiles. It's possible that there's a similar bug for C# projects too, but I don't have any C# projects and I didn't want to write "fixes" that I can't test. Similarly, I'm not familiar with the premake codebase so this patch isn't as clean as it could be, but hopefully it's a start!