help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make question


From: John Calcote
Subject: Re: Make question
Date: Fri, 05 Feb 2010 09:32:21 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.7) Gecko/20100111 Thunderbird/3.0.1

Hi Timothy,

On 2/5/2010 8:59 AM, Canham, Timothy K (316C) wrote:
Newbie on the list, so forgive me if this is asked frequently:

We have code generation, and we have  a rule like this:

fileout1.txt fileout2.txt fileout3.txt: filein.txt
        filegen.sh filein.txt

What you need to realize about a rule like this is that it's really just a shortcut notation for this:

fileout1.txt : filein.txt
        filegen.sh filein.txt

fileout2.txt : filein.txt
        filegen.sh filein.txt

fileout3.txt: filein.txt
        filegen.sh filein.txt


The advantages of using the single rule are clear - you only need to maintain one common command and rule, but the fact remains that make ultimately considers it to be three separate rules.

We run a parallel make (make -j x), and what I've found is that the rule often 
gets invoked three times, causes files to overwrite each other. We've had to 
make that part serial to avoid this, and it slows down the build. Some have 
suggested an approach like this:

filemarker.txt: filein.txt
        filegen.sh filein.txt
        touch filemarker.txt

This is a common pattern for managing commands with multiple output files. It's called a stamp rule, and it does have it's problems. The single file (filemarker.txt) acts as a representative of the three generated files in a way that make can understand and consume. This marker can also be used as a dependency in another rule. One problem is that if filemarker.txt is left in place, the outputs will not be generated, even if they're missing. That's because, as far as make is concerned, the file that represents those three is still there and up to date. The only way to get make to regenerate the outputs that you actually want is to touch filein.txt, or remove the stamp file.

This will work, but it leaves a clutter of files all over the place.

Is there a way to specify the rule so that the rule is only invoked once in a 
parallel make, or is there a technique that accomplishes the same thing?

By "a clutter of files all over the place" I presume you mean that the filemarker.txt file is left behind. Be sure to add this file to your clean rule so it get's deleted when you clean things up.

Regards,
John




reply via email to

[Prev in Thread] Current Thread [Next in Thread]