[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "make -jN" requires mechanical changes to a Makefile [SOLVED]
From: |
Howard Chu |
Subject: |
Re: "make -jN" requires mechanical changes to a Makefile [SOLVED] |
Date: |
Sun, 13 Sep 2020 20:07:27 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0 SeaMonkey/2.53.3 |
Bruno Haible wrote:
> Continuing this thread from May 2019
> <https://lists.gnu.org/archive/html/bug-make/2019-05/msg00022.html>:
> The problem was:
>
> How can a rule that generates multiple files be formulated so
> that it works with parallel make?
>
> For example, a rule that invokes bison, or a rule that invokes
> a different Makefile. For simplicity, here, use a rule that
> creates 4 files copy1, copy2, copy3, copy4.
>
> ===========================================
> 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
> ===========================================
>
> Unfortunately, with "make -j8", it invokes the rule multiple times.
>
> It is possible to change this Makefile so that
> (A) "rm -f copy?; make" executes the rule once.
> (B) "rm -f copy?; make -j8" executes the rule once as well.
> (C) After "make", another "make" just prints "Nothing to be done for 'all'."
> (D) After removing one of the files copy?, "make" executes the rule once.
> (This covers also the case of pressing Ctrl-C during "make", then
> doing "make" again.)
> (E) After replacing one of the files copy? with a file that is older than
> Makefile, "make" executes the rule once.
>
> There are three possibilities:
You're thinking about this the wrong way. Your set of commands is inherently
serial, therefore you need to write serial dependencies.
===========================================
all: copy1 copy2 copy3 copy4
copy1: Makefile
install -c -m 644 Makefile $@
copy2: copy1
install -c -m 644 Makefile $@
copy3: copy2
install -c -m 644 Makefile $@
copy4: copy3
install -c -m 644 Makefile $@
===========================================
This satisfies all your conditions, because it is inherently correct.
More on writing proper parallel Makefiles here http://highlandsun.com/hyc/#Make
--
-- Howard Chu
CTO, Symas Corp. http://www.symas.com
Director, Highland Sun http://highlandsun.com/hyc/
Chief Architect, OpenLDAP http://www.openldap.org/project/