bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

"make -jN" requires mechanical changes to a Makefile


From: Bruno Haible
Subject: "make -jN" requires mechanical changes to a Makefile
Date: Fri, 10 May 2019 22:49:55 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-145-generic; KDE/5.18.0; x86_64; ; )

Hi,

The GNU standards [1] say:
  "Try to make the build and installation targets, at least (and all their
   subtargets) work correctly with a parallel make."

But supporting parallel requires, in some cases, mechanical changes to a
Makefile. How about if GNU make was improved to not require me to make these
changes?

Namely, consider this Makefile:
===================================================
all : copy1 copy2 copy3 copy4

copy1 copy2 copy3 copy4: Makefile
        install -c -m 644 Makefile copy1
        install -c -m 644 Makefile copy2
        install -c -m 644 Makefile copy3
        install -c -m 644 Makefile copy4
===================================================

Observe:
* "rm -f copy?; make" works fine.
* "rm -f copy?; make -j8" occasionally fails:
$ rm -f copy? ; make -j8
install -c -m 644 Makefile copy1
install -c -m 644 Makefile copy1
install -c -m 644 Makefile copy1
install -c -m 644 Makefile copy1
install -c -m 644 Makefile copy2
install -c -m 644 Makefile copy2
install -c -m 644 Makefile copy2
install -c -m 644 Makefile copy2
install: cannot change permissions of 'copy2': No such file or directory
install -c -m 644 Makefile copy3
Makefile:4: recipe for target 'copy2' failed
make: *** [copy2] Error 1
make: *** Waiting for unfinished jobs....
install -c -m 644 Makefile copy3
install -c -m 644 Makefile copy3
install -c -m 644 Makefile copy4
install -c -m 644 Makefile copy4
install -c -m 644 Makefile copy4

The workaround is to introduce an intermediate target:

===================================================
all : copy1 copy2 copy3 copy4

copy1 copy2 copy3 copy4: install-copies
.PHONY: install-copies
install-copies: Makefile
        install -c -m 644 Makefile copy1
        install -c -m 644 Makefile copy2
        install -c -m 644 Makefile copy3
        install -c -m 644 Makefile copy4
===================================================

This is tedious, mechanical work. Couldn't GNU make implement the workaround
by itself? Namely, when during a parallel make, it encounters a rule

target1 ... targetN : dependencies
        STATEMENTS

and none of the statements depends on the precise target ($@ or similar),
it should transform that to the form

target1 ... targetN : intermediate_target
.PHONY: intermediate_target
intermediate_target: dependencies
        STATEMENTS

internally.

$ make --version
GNU Make 4.1

Best regards,

              Bruno

[1] https://www.gnu.org/prep/standards/html_node/Makefile-Basics.html




reply via email to

[Prev in Thread] Current Thread [Next in Thread]