Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Critical section in parallel make file

I am trying to parallelize an old Makefile.

In fact I need to make sure that some generator scripts are called not parallel before the compiling procedure starts.

The generators are always called before the compile. Is there any way to establish a somewhat critical section in a makefile?

The Makefile is messy, I'd prefer not to post it here.

like image 312
Stasik Avatar asked May 20 '11 10:05

Stasik


2 Answers

You could put the rules for the generated files in a separate Makefile, and do something like this:

generated-sources :
        $(MAKE) -f Makefile.Generators

However, with GNU Make, this will be parallel by default. You'll need to suppress it, and the manual isn't exactly clear how you would do that. Maybe some combination of the following would work, depending on which implementations of make you wish to support:

  • Pass the -j1 flag:

    generated-sources :
            $(MAKE) -j1 -f Makefile.Generators
    
  • Suppress MAKEFLAGS options:

    generated-sources :
            $(MAKE) -f Makefile.Generators MAKEFLAGS=
    
  • Suppress parallel execution with the following line in Makefile.Generators:

    .NOTPARALLEL :
    
like image 91
Dietrich Epp Avatar answered Nov 01 '22 08:11

Dietrich Epp


You can make a rule that runs all of the scripts, and then make sure all of your other rules depend on that rule.

all: ${SOURCES} scripts

scripts: last_script


first_script:
    ./script1.sh

second_script: first_script
    ./script2.sh

last_script: second_script
    ./script3.sh

source1.o: source1.c scripts
    gcc source1.c -c -o source1.o
like image 33
SoapBox Avatar answered Nov 01 '22 07:11

SoapBox