build dir isn't properly specified as a dependency
A free file archiver for extremely high compression
Brought to you by:
ipavlov
When using parallel the mkdir needs to be complete before object files are attempted to be created. But the makefile doesn't specify the build dir to be a dependency of the objects so make may attempt to create object files before the build dir was created.
Short reproducer on linux using GNU Make:
$ cd CPP/7zip/Bundles/Alone2
$ make -f ../../cmpl_gcc.mak -j10 --shuffle=reverse
Proposed fix, add $(O) as a order-only dependency for all the $(OBJS) files:
--- CPP/7zip/7zip_gcc.mak
+++ CPP/7zip/7zip_gcc.mak
all: $(O) $(PROGPATH) $(STATIC_TARGET)
+$(OBJS): | $(O)
+
$(O):
$(MY_MKDIR) $(O)
Bug report about this on gentoo: https://bugs.gentoo.org/933619
Sorry, I meant to open this as a bug not patch.
Is it new switch:
--shuffle=reverse
?It doesn't work in my
make
.The
--shuffle
switch was added in GNU Make v4.4 in order to detect missing dependencies that causes parallel build failures: https://trofi.github.io/posts/238-new-make-shuffle-mode.htmlGNU Make v4.4 was released in 31 Oct 2022, so it's not too new. I suppose your make version is older than that.
I've also seen sporadic build errors with -j due to the target directory sometimes not getting created before the first ASMC output completes and tries and fails to write to the output location.
Since I was batching my builds together into a shell script I just pre-created the directories beforehand in my script before calling make.
GNU Make 4.4.1 was released "Sun, 26 Feb 2023 15:18:17 -0500"
and it is Today 2025-05-10 so Why not try to use that now ???
Please see:
https://lists.gnu.org/archive/html/info-gnu/2023-02/msg00011.html
Does it NOT make any difference that it now supports:
"New feature: Parallel builds of archives
Previously it was not possible to use parallel builds with archives. It is
still not possible using the built-in rules, however you can now override
the built-in rules with a slightly different set of rules and use parallel
builds with archive creation. See the "Dangers When Using Archives" section
of the GNU Make manual, and https://savannah.gnu.org/bugs/index.php?14927
"
???
Please see also note what is is written in the updated GNU Make 4.4.1
manua for the section 11.3 Dangers When Using Archives
id est what is written below...
11.3 Dangers When Using Archives
(Source:
https://www.gnu.org/software/make/manual/make.html#Archive-Pitfalls
)
"11.3 Dangers When Using Archives
The built-in rules for updating archives are incompatible with parallel builds. These rules (required by the POSIX standard) add each object file into the archive as it’s compiled. When parallel builds are enabled this allows multiple ar commands to be updating the same archive simultaneously, which is not supported.
If you want to use parallel builds with archives you can override the default rules by adding these lines to your makefile:
(%) : % ;
%.a : ; $(AR) $(ARFLAGS) $@ $?
The first line changes the rule that updates an individual object in the archive to do nothing, and the second line changes the default rule for building an archive to update all the outdated objects ($?) in one command.
Of course you will still need to declare the prerequisites of your library using the archive syntax:
libfoo.a: libfoo.a(x.o y.o …)
If you prefer to write an explicit rule you can use:
libfoo.a: libfoo.a(x.o y.o …)
$(AR) $(ARFLAGS) $@ $?
Previous: Dangers When Using Archives, Up: Using make to Update Archive Files [Contents][Index]"