Submakes not being re-run with different target

77 Views Asked by At

I'm trying to get a top-level makefile to call make in a number of subfolders. The top-level has several targets and the important bit is shown below:

MAKE_DIRS := $(dir $(wildcard apps/**/Makefile))
.PHONY: clean_apps apps $(MAKE_DIRS)

clean_apps: TARGET_INFO := clean

apps clean_aps: $(MAKE_DIRS)

$(MAKE_DIRS):
    $(MAKE) -C $@ $(TARGET_INFO)

Now this works fine when I call the targets independently:

make apps; make clean_apps

However if I call them on the same commandline with:

make clean_apps apps

Then the apps target justs say nothing to do. I guess it's something to do with the dependency on the directories not having changed between invocations, but I thought the .PHONY command would avoid that problem...

I'm happy to know if there's a better way to deal with this.

Thanks, bob

1

There are 1 best solutions below

0
On

It is something much more simpler :

SUBDIRS :=  $(dir $(shell find apps -name "Makefile"))

.PHONY: all clean

all clean:
    $(foreach DIR, $(SUBDIRS), $(MAKE) $(MAKEFLAGS) -C $(DIR) $@;)