List Info

Thread: How to dive into SUBDIRS




How to dive into SUBDIRS
country flaguser name
Germany
2008-03-28 12:11:59
[ Please CC me as I am not subscribed to the list ]

Hi there,

in 4.6 of the make manual there is an example for using
PHONY targets to
dive into SUBDIRS instead of the "for dir in.."
variant. But I'm unsure
how to handle situations where you want to execute specific
PHONY targets,
that all depend on the same SUBDIRS.

Example:
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

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

etc.

But how to do it with the PHONY target variant? Defining
different
variable names (my first guess) does obvious not work. Is
there any
special variable to indicate which rule implicitly matched
the $(DIRS):
rule? Then something like the following would work:

$(DIRS):
    $(MAKE) -C $ $magicvar

I didn't find anything. Whats the right way to do this?

Thanks and best Regards,

Patrick


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: How to dive into SUBDIRS
user name
2008-03-28 12:47:55
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 <psmithgnu.org>                
http://make.mad-scientis
t.us
 "Please remain calm--I may be mad, but I am a
professional."--Mad Scientist




_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )