[Top][All Lists]

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

Re: clean recursively into sub-directories

From: Paul Smith
Subject: Re: clean recursively into sub-directories
Date: Tue, 29 Apr 2008 11:14:30 -0400

On Tue, 2008-04-29 at 08:57 -0600, John Calcote wrote:

> You have multiple conflicting rules for "all" and "clean".

This is true.  You may only have one recipe defined for a given target.
Else, how can make know which one you want to run?

> Here's the right way to do this (untested):

But this is not correct.  See the GNU make manual for a number of
reasons why this model (using a for-loop in a single rule) is a bad way
to handle subdirectory makes.

Hongliang's method of handling "all" is correct and appropriate.

However, to have a different set of rules that also are run in
subdirectories, you have to create different targets.  Something like:

        SUBCLEAN = $(addsuffix .clean,$(SUBDIRS))
        .PHONY: clean $(SUBCLEAN)
        clean: $(SUBCLEAN)
        $(SUBCLEAN): %.clean:
                $(MAKE) -C $* -f Makefile.hvr_gcc clean

(untested).  There are a lot of ways to do this but you need to do
something like it.

> all clean:
>         for dir in $(SUBDIRS); do \
>         $(MAKE) -C $$dir -f Makefile.hvr_gcc $@; \
>         done

> Cleaner and simpler.

But, not correct :-).  For example, what happens if one of the submakes
fails?  That's not even mentioning the problems this brings if you want
to run parallel builds.

 Paul D. Smith <address@hidden>       
 "Please remain calm--I may be mad, but I am a professional."--Mad Scientist

reply via email to

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