help-make
[Top][All Lists]
Advanced

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

Re: How to refer to the first target?


From: Peng Yu
Subject: Re: How to refer to the first target?
Date: Thu, 26 Nov 2009 07:42:33 -0600

On Wed, Nov 25, 2009 at 11:01 PM, Paul Smith <address@hidden> wrote:
> On Wed, 2009-11-25 at 19:59 -0600, Peng Yu wrote:
>> Suppose I have 'command.sh' that generate files 'a' and 'b'.
>>
>> If either of 'a' or 'b' is older than 'command.sh', I need to run
>> 'command.sh' again. The following Makefile has two targets, right? I
>> want to refer to the second target 'b' in this Makefile.
>>
>> $ cat Makefile
>> all: a b
>>
>> a b: command.sh
>>         ./command.sh
>
> You seem to be under the impression that this rule means that make will
> invoke your command.sh one time only, and believe that it generates two
> different files.
>
> That's not what this means.
>
> The rule you've written above is _identical_ to, just shorthand for,
> writing this:
>
>        a: command.sh
>                ./command.sh
>        b: command.sh
>                ./command.sh
>
> So, in this case, there is only one target file each time command.sh is
> invoked, and the name of that target will be stored in address@hidden  So the 
> first
> time command.sh is invoked, $@ will be set to "a" and the second time it
> will be set to "b".

I don't understand the following case. If there are two rules, why
command.sh is only executed once.

$ touch command.sh
$ make
./command.sh


If there are multiple files that are generated by command.sh, are you
suggesting to write a single rule for an arbitrarily chosen single
file? But if I only have a rule for 'a' but not for 'b', when the file
'b' is deleted, 'command.sh' will not called by make. But I do want
make to updated 'b'. How do you deal with this case?

a: command.sh
  ./command.sh




reply via email to

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