Re: Strange behavior with Make dependencies...



João Jerónimo wrote:
toby wrote:
When I do make in the directory where *this* makefile is, Make tells me:
make: Nothing to be done for `all'.
Whether I've updated some file inside any of the two subdirectories or
not... so, when I update some file, it's not propagated, which is wrong...
The makefile should always run "make -C bootsect" and "make -C bootldr",
but it never runs it, unless I'd run "make clean" before...
I've just solved my problem by telling that bootsect was a dependency of
bootsect.MBR :

bootsect.MBR: bootsect

Then, Make will check if the timestamp of the bootsect directory is
later than the bootsect.MBR's and run the target if so...

This is an unreliable workaround. (One reason is because the directory
timestamp does not reflect all changes to files inside it - it will
update when files are added or removed, but you can change contents of
a file without this being reflected in the parent dir's timestamp.)

On Linux it worked well...
But I know the importance of portability!

It's not a portability issue; it's a correctness issue.


But still it doesn't make sense, cause when a target has no
dependencies, it is always run... at least AFAIK...

NOT if it exists[1]. The build command is being skipped because make
sees that 'bootsect.MBR' already exists and is satisfied. Because the
rule has no pre-requisites, it has no way to know if it is out of date.

It's strange that I said a so-stupid-thing, because a while before I had
concluded that it's only executed if the file doesn't exist...

It is executed if the target does not exist, or if it is out of date.
Without specifying prerequisites, make cannot determine if it is out of
date, so simple existence will skip the commands.

The first "version" of the bootldr's Makefile was a "dummy" one... it
only created a file with many zeros using dd:

---------------------------------
all: bootldr.sys

bootldr.sys:
dd if=/dev/zero of=bootldr.sys count=somecount bs=somevalue
cp bootldr.sys ..
---------------------------------

So the file would only be created if it had been deleted...

This rule in fact perfectly correct, because it *has* no
pre-requisites; the file cannot be "out of date" except with respect to
commands in the Makefile itself (if you were being very correct, you'd
add a dependency on the Makefile).


The correct fix to your problem is to add the correct prerequisite(s)
to your rule for bootsect.MBR - which are the input files used by the
rule's command(s). The same needs to be done for 'bootldr.sys' rule.

The problem of this is that it breaks structure... The idea is that this
Makefile should not need to know anything about how the file is
generated... it only needs to invoke make inside bootsect/ and see if it
was updated...

This is a problem you have to solve. Currently, you're not giving make
enough information for it to work properly. It will probably be helpful
to avoid sub-makes, although a correct solution can still be recursive.


[2]
http://members.canb.auug.org.au/~millerp/rmch/recu-make-cons-harm.html

It's not very important, but I could figure out this document's date...
In the abstract it says 1997 but the other pages in the PDF say it's 29
March 2006!

JJ

.



Relevant Pages

  • Re: Strange behavior with Make dependencies...
    ... I've just solved my problem by telling that bootsect was a dependency of ... Make will check if the timestamp of the bootsect directory is ... The idea is that this Makefile should not need to know anything about how the file is generated... ...
    (comp.unix.programmer)
  • Re: Strange behavior with Make dependencies...
    ... later than the bootsect.MBR's and run the target if so... ... This is an unreliable workaround. ... timestamp does not reflect all changes to files inside it - it will ... Makefile should not need to know anything about how the file is ...
    (comp.unix.programmer)
  • Re: Java and make
    ... My makefile captures this as: ... make discovers a cyclic dependency and drops it. ... I believe make will not have problems of this kind in the context of C/ ... dependencies in Java programs where we don't have a seperate header ...
    (comp.lang.java.programmer)
  • Java and make
    ... I have a question about using make as the build-utilitiy for Java ... Please point me to a more appropriate news group if this is ... My makefile captures this as: ... make discovers a cyclic dependency and drops it. ...
    (comp.lang.java.programmer)
  • Re: make "quickworld"? (like in DragonFly)
    ... >> Makefile did something wrong. ... That kind of dependency (on a compiler ABI) is not easily ... As I said, there may be some exceptions, like midway compiler ...
    (freebsd-hackers)