开发者

Critical section in parallel make file

I am trying to parallelize an old Makefile.

In fact开发者_StackOverflow 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.


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 :
    


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜