multiple targets from one recipe and parallel execution

后端 未结 5 1264
醉梦人生
醉梦人生 2020-12-03 15:19

I have a project which includes a code generator which generates several .c and .h files from one input file with just one invocation of the code generator. I have a rule w

5条回答
  •  离开以前
    2020-12-03 15:35

    Answer by Ivan Zaentsev almost worked for me, with exception of the following issue. Only when running parallel make (-j2 or above), when a prerequisite of the generated file was changed, the generated file was regenerated successfully, however, the subsequent targets that depend on the generated file were not rebuilt.

    The workaround I found was to provide a recipe for the generated files (the trivial copy command), besides the dependency on the intermediate target (d):

    d: i1 i2
        cat i1 i2 > a.gen 
        cat i1 i2 > b.gen
        cat i1 i2 > c.gen
    .INTERMEDIATE: d
    a.gen : d
    b.gen : d
    c.gen : d
    
    a: a.gen d
        cp $< $@
    b: b.gen d
        cp $< $@
    c: c.gen d
        cp $< $@
    
    e: a b c
        some_command $@ $^
    

    The clue was this debug output from make when running without the workaround (where 'e' was not rebuilt with make -j2, despite a,b,c being rebuilt):

           Finished prerequisites of target file `a'.
           Prerequisite `d' of target `a' does not exist.
          No recipe for `a' and no prerequisites actually changed.
          No need to remake target `a'.
    

提交回复
热议问题