Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Things first you should be aware of:</p> <ul> <li>If you have directories as dependencies, make is going to consider building the targets (i.e. executing the recipes for such directory targets), only if the modification timestamp of the directory gets updated. This would happen only when you add a new file in the directory but not for file modifications in the directory. Adding files in a sub-directory <strong><em>does not</em></strong> change the timestamp of the directory.</li> <li>PHONY targets are meant to be used when executing such a target does not create a file with the name of the target. In other words, you want make to execute the rule irrespective of whether the file already exists or not.</li> </ul> <p>So your Makefile esentially only tells this:</p> <ul> <li>To build the target <code>all</code>, I need to build <code>$(APP_DIRS)</code>. Since <code>all</code> is a PHONY target, I will always execute the recipe for <code>all</code>.</li> <li><code>$(APP_DIRS)</code> is not a <code>PHONY</code> target and does not have any dependencies. So <strong>*only if</strong> <code>$(APP_DIRS)</code> does not exist already (i.e. the file or directory), I'm going to execute the recipe, otherwise I'm doing nothing for this target.</li> <li><code>clean</code> has no pre-requisite and not a <code>PHONY</code>, so I expect to execute this rule only when explicitly invoked by make (from the command line or another Makefile). Also <code>clean</code> is not a <code>PHONY</code>, so I expect the recipe to create a file called <code>clean</code> after execution (which is incorrect for your case)</li> </ul> <p>Hence changing the <code>.PHONY</code> line to:</p> <pre><code>.PHONY: all $(APP_DIRS) </code></pre> <p>makes the Makefile go and execute the recipe for $(APP_DIRS) always.</p> <p>So if you would like make to always traverse into all of the $(APP_DIRS) directories and invoke make again on them, you need to add <code>$(APP_DIRS)</code> to <code>.PHONY</code>, which makes $(APP_DIRS) a PHONY target, and executes the recipe irrespective of the file's/directory's timestamp if it exists.</p> <p>For your particular use-case, I think this is the Makefile you should be using:</p> <pre><code>APP_DIRS=rescoco ressys resvm .PHONY: all clean $(APP_DIRS) all: $(APP_DIRS) $(APP_DIRS): $(MAKE) --directory $@ clean: $(RM) *~ </code></pre> <p><strong>BONUS:</strong></p> <ul> <li>Changing <code>$(APP_DIRS):</code> to <code>$(APP_DIRS): clean</code> implies that <code>$(APP_DIRS)</code> depends on the <code>clean</code> target.</li> <li>Although <code>clean</code> is not marked a PHONY, make does not see a file named <code>clean</code> in the current directory. So it goes ahead and tries to execute the recipe for <code>clean</code>.</li> <li>Since a dependency of $(APP_DIRS) (i.e. <code>clean</code>) was built, this makes the Makefile execute the recipe for building $(APP_DIRS).</li> </ul> <p>This brings us to an interesting observation: - Any target that depends on a PHONY target will always get rebuilt (i.e. the recipe would be executed).</p> <p>Take this simple Makefile:</p> <pre><code>all: target1 target1: target2 @echo "$@" @touch $@ target2: target3 @echo "$@" @touch $@ target3: @echo "$@" .PHONY: all target3 </code></pre> <p>The first time I run <code>make</code>, I see this output:</p> <pre><code>target3 target2 target1 </code></pre> <p>After this, files <code>target1</code> and <code>target2</code> are created. Even then, if I run <code>make</code> again, I would see the output:</p> <pre><code>target3 target2 target1 </code></pre> <p>As you can see, the <code>PHONY</code> dependencies get propagated up and not the other way down. <code>target2</code> gets rebuilt just because <code>target3</code> is a PHONY, and <code>target1</code> gets rebuilt just because <code>target2</code> got rebuilt.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload