Search code examples
makefile

GNU Makefile rule generating a few targets from a single source file


I am attempting to do the following. There is a program, call it foo-bin, that takes in a single input file and generates two output files. A dumb Makefile rule for this would be:

file-a.out file-b.out: input.in
    foo-bin input.in file-a.out file-b.out

However, this does not tell make in any way that both targets will be generated simultaneously. That is fine when running make in serial, but will likely cause trouble if one tries make -j16 or something equally crazy.

The question is whether there exists a way to write a proper Makefile rule for such a case? Clearly, it would generate a DAG, but somehow the GNU make manual does not specify how this case could be handled.

Running the same code twice and generating only one result is out of the question, because the computation takes time (think: hours). Outputting only one file would also be rather difficult, because frequently it is used as an input to GNUPLOT which doesn't know how to handle only a fraction of a data file.


Solution

  • I would solve it as follows :

    file-a.out: input.in
        foo-bin input.in file-a.out file-b.out   
    
    file-b.out: file-a.out
        #do nothing
        noop
    

    In this case parallel make will 'serialize' creating a and b but since creating b does not do anything it takes no time.