This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: struggling with make inside GCC MELT

On 11 January 2012 09:08, Mingjie Xing wrote:
> 2012/1/10 Ian Lance Taylor <>:
>> Stamp files in make work like this:
>> FILE: STAMP-FILE; @true
>> ? ? ? ?commands to create FILE.tmp
>> ? ? ? ?move-if-change FILE.tmp FILE
>> ? ? ? ?touch $@
>> What this says is: if any of DEPENDENCIES change, then run the commands
>> to create FILE.tmp. ?The move-if-change shell script then compares
>> FILE.tmp and FILE; if they are different, it moves FILE.tmp to FILE,
>> updating the timestamp. ?If they are not different, FILE is left
>> unchanged, with the same timestamp.
>> The effect is that anything which depends on FILE is only rebuilt if the
>> contents of FILE changes.
> Hmm, will it work to just write as
> ? ? ? ?commands to create FILE.tmp
> ? ? ? ?move-if-change FILE.tmp FILE

No, this isn't the same. With your rule above, if FILE is not replaced
then its timestamp will not be updated, so every time you run make it
will notice the dependencies have changed and recreate FILE.tmp, but
not update FILE. That does lots of unnecessary work.
Using the stampfile ensures you only generate FILE.tmp once, when the
dependencies have first changed, then update the timestamp of the
stampfile to mark FILE as up to date.

>> Note that everything I show above is required. ?A naive approach would
>> omit the "; @true" but it is necessary.
>> Ian
> Then what the role here "; @true" ?play? I'm still confused by the usage.

If you don't have a recipe for the FILE target then make might try to
use an implicit recipe for the file type, so you need a "do nothing"

'true' is a shell command that does nothing and returns true. @
prevents the command being echoed.  So "updating" the FILE target
happens whenever the stampfile changes, but the recipe is a no-op.

I'm not sure why "@true" is needed, as I think GNU make allows simply
";" for an empty recipe, maybe Ian can explain that part.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]