"make -jN" requires mechanical changes to a Makefile

classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: "make -jN" requires mechanical changes to a Makefile [SOLVED]

Henrik Carlqvist-2
On Sun, 13 Sep 2020 20:07:27 +0100
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
> ===========================================

I would say there are two obvious solutions to make this work with parallel
make:


1) Allow the targets to be tuilt in paralllel:
===========================================
all : copy1 copy2 copy3 copy4
 
copy1 copy2 copy3 copy4: Makefile
  install -c -m 644 Makefile $@
===========================================

However, this solution 1 will not work for a single command that generates
multiple files, so we might need a solution 2:

2) Don't mention some of the extra targets:
===========================================
all : copy1
 
copy1: 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
===========================================

regards Henrik

Reply | Threaded
Open this post in threaded view
|

Re: "make -jN" requires mechanical changes to a Makefile [SOLVED]

Bruno Haible
Henrik Carlqvist wrote:

> 2) Don't mention some of the extra targets:
> ===========================================
> all : copy1
>  
> copy1: 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
> ===========================================

Fails (D) and (E). => Not a solution to the problem.

Bruno


Reply | Threaded
Open this post in threaded view
|

Re: "make -jN" requires mechanical changes to a Makefile [SOLVED]

Henrik Carlqvist-2
On Mon, 14 Sep 2020 12:15:58 +0200
Bruno Haible <[hidden email]> wrote:

> Henrik Carlqvist wrote:
> > 2) Don't mention some of the extra targets:
> > ===========================================
> > all : copy1
> >  
> > copy1: 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
> > ===========================================
>
> Fails (D) and (E). => Not a solution to the problem.
>
> Bruno
>

Ok, assuming that solution 1 did not meet your requirements, lets give it
another shot:

===========================================
COPIES=copy1 copy2 copy3 copy4

.INTERMEDIATE: dummy

all: $(COPIES)

$(COPIES): %: dummy
        $(RM) $<

dummy: 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
        touch $@
===========================================

I create an extra file "dummy" for a short time in an attempt to live up to
all your requirements.

regards Henrik

12