help-make
[Top][All Lists]
Advanced

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

Re: How to dive into SUBDIRS


From: Paul Smith
Subject: Re: How to dive into SUBDIRS
Date: Fri, 28 Mar 2008 13:47:55 -0400

On Fri, 2008-03-28 at 18:11 +0100, Patrick Schoenfeld wrote:
> You have DIRS defined and several targets all, update and upload.
> Normaly you would do something like this:
> 
> all:
>     set -e; for dir in $(DIRS); do make -C $$dir all; done

ALWAYS use $(MAKE) when invoking a sub-make, NEVER use "make".

> update:
>     set -e; for dir in $(DIRS); do make -C $$dir update; done
> 
> upload:
>     set -e; for dir in $(DIRS); do make -C $$dir upload; done

> But how to do it with the PHONY target variant?

There are a number of ways.  Here's one:

        all: $(addprefix all.,$(DIRS))
        update: $(addprefix update.,$(DIRS))
        upload: $(addprefix upload.,$(DIRS))
        
        all.%:
                $(MAKE) -C $* all
        update.%:
                $(MAKE) -C $* update
        upload.%:
                $(MAKE) -C $* upload
        
        .PHONY: all $(addsuffix .all,$(DIRS)) \
                update $(addsuffix .update,$(DIRS)) \
                upload $(addsuffix .upload,$(DIRS))

This has other nice properties, in that you can do things like running
"make update.onedir" to run the update rule in just one subdirectory
"onedir" for example.

There are fancy ways to reduce this even further, even down to one
statement, but unless you have a ton of these or expect them to change
often, it's probably just as easy to write them out.

-- 
-----------------------------------------------------------------------------
 Paul D. Smith <address@hidden>                 http://make.mad-scientist.us
 "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]