MK.
MK.

Reputation: 4027

recursive gmake question

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.

Upvotes: 2

Views: 1323

Answers (1)

rlb
rlb

Reputation:

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).

Upvotes: 8

Related Questions