help-make
[Top][All Lists]
Advanced

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

Re: prerequisite ignored when running 'make' (alone)


From: Paul Smith
Subject: Re: prerequisite ignored when running 'make' (alone)
Date: Tue, 09 May 2017 08:29:46 -0400

On Tue, 2017-05-09 at 14:06 +0200, Federico Bruni wrote:
> ### Makefile ###
> all: doc
> 
> dependencies = $(shell find docs -type f)
> 
> doc: $(dependencies)
>         echo "Something has changed in the docs/ directory!"
> 
> ### end ###
> 
> 
> It looks up the files in the docs/ directory and executes the doc
> target if any file is changed.

As written here, that's not what it does.

> If I run 'make doc', it behaves as expected.
> If I run 'make', the target is executed every time, even if no file 
> changed in docs/.

I can't explain the difference in behavior.  In fact, the behavior of
"make" (target is executed every time) is what I expect to happen no
matter how you invoke make.

Why?  Because make decides whether or not to rebuild something by
comparing _file timestamps_.

In this makefile you'll compare the timestamps of all the files under
the "docs" directory to... what?

It will be compared to the timestamp of a file named "doc" in the
current directory.  But there is no file named "doc" in the current
directory, so the target will always be considered out of date, and
always rebuilt.

You need to modify your rule to update the target, like this:

  doc: $(dependencies)
          @echo "Something has changed in the docs/ directory"
          touch $@




reply via email to

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