[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Will a rule be updated if its dependent file is modified by another
From: |
Peng Yu |
Subject: |
Re: Will a rule be updated if its dependent file is modified by another rule? |
Date: |
Fri, 5 Mar 2010 12:00:58 -0600 |
On Thu, Mar 4, 2010 at 6:39 PM, Paul Smith <address@hidden> wrote:
> On Thu, 2010-03-04 at 17:41 -0600, Peng Yu wrote:
>> Suppose I have file2 that is newer than file1, and file4 is older than
>> file3. In the trials that I did, both rules in the makefile are always
>> executed. I'm wonder if this is always true. Or I just happen to
>> observer this behavior?
>>
>> .PHONY: all
>>
>> all: file1 file2
>>
>> file3: file4
>> touch file3
>>
>> file1: file2
>> touch file1
>> touch file3
>
> Are you SURE both rules are executed? You didn't show the command you
> ran or the output you got. Note that if both rules are really executed
> you should see "touch file3" _twice_, once for the rule to build file1
> and once for the rule to build file3. Maybe it would be easier to see
> what was really going on if you included some kind of "echo building $@"
> in your rules or similar.
>
> I cannot reproduce your behavior: if file2 is newer than file1 and file4
> is older than file3, then make rebuilds file1 (but this touches both
> file1 and file3) but does not run the command to build file3. That's as
> I would expect.
I misinterpreted the output. Yes, only one rule was executed.
I have the following example to demonstrate what I intended to ask.
dir1/ has a Makefile in it and would generated file3 in dir1/
depending on dir1/file3. There is a symbolic link file3 in the current
directory which points to dir1/file3. file1 depends on file2 and
file3.
In order to make the dependence in dir1 current, I'll have to specify
dir1 as a PHONY in the current directory Makefile (call it the main
Makefile), hence make always invoke make -C on dir1. At the time of
invoking make -C on dir1, dir1/file3 and hence file3 may not be
updated yet. Hence according to my understanding. The rule file1:
file2 file3 should not be invoked in the main Makefile. However, the
following commands show that 'file1: file2 file3' is invoked.
I think that I still don't completely understand how make interpret
dependencies. Would you please help explain it?
$ make
<...output omitted>
$ touch dir1/file3
$ make
make -C dir1
make[1]: Entering directory
`/home/pengy/test/make/question/directory_dependency/dir1'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory
`/home/pengy/test/make/question/directory_dependency/dir1'
touch file1
#############file and code
$ cat Makefile
.PHONY: all clean
.PHONY: dir1
all: dir1
dir1:
$(MAKE) -C $@
all: file1
file1: file2 file3
touch file1
clean:
$(MAKE) -C dir1 clean
$(RM) file1
$ cat dir1/Makefile
.PHONY: all
all: file3
file3: file4
sleep 1
touch file3
clean:
$(RM) file3
$ ls -lgo *
-rw------- 1 0 2010-03-05 11:44 file1
-rw------- 1 0 2010-03-05 11:34 file2
lrwxrwxrwx 1 10 2010-03-05 11:36 file3 -> dir1/file3
-rw------- 1 155 2010-03-05 11:41 Makefile
dir1:
total 4
-rw------- 1 0 2010-03-05 11:44 file3
-rw------- 1 0 2010-03-05 11:44 file4
-rw------- 1 82 2010-03-05 11:44 Makefile
Regards,
Peng