views:

163

answers:

1

Hello,

I need to write a quick makefile for building all my projects. This is C++ code and I am using gmake.

Say I have a list of directories, I want to cd to each, issue gmake command and if it succeeds, go to the next one and so on.

I cooked this by looking at the gmake manual

.PHONY: all clean dirs $(DIRS)

dirs: $(DIRS)

$(DIRS): \n\t
    $(MAKE) -C $@

It works for the "all" target - if I just type gmake, it does the right thing. But if I do gmake clean it does nothing.

I am learning gmake as I go, so I am certainly doing something silly here :)

Thanks for any help.

+1  A: 

In order to recursively make something other than the first target (I'm guessing all is your first target), you need to give the sub-make an idea of what to build. You can do so with the MAKEFLAGS and MAKECMDGOALS variables.

For example:

$(DIRS):
        $(MAKE) -C "$@" $(MAKEFLAGS) $(MAKECMDGOALS)

Your rule was not passing along the target names, e.g. clean, so the sub-make had no work to do (since all was already built).

Yes indeed, that fixed it. Thanks.
MK