Search code examples
build-processmakefile

make: hierarchical make file


(disclaimer: I am used to scons ... I am somewhat unexperienced with make)

Context: I am using Eclipse CDT which generates makefiles.

Let's say I have a project directory 'lib' and 2 build configurations 'Debug' and 'Release'. Eclipse CDT gracefully generates a makefile for each build configuration. The said makefiles end-up residing in 'Debug' and 'Release' folders.

Now, what I want to do is have a makefile in the folder 'lib' which calls the makefiles 'Debug/makefile' and 'Release/makefile'.

How do I do that?

I want to be able to launch 'make' in the folder 'lib' and both configurations would be called with the specified target(s).

Solution Based on all the great input gathered here, I devised the following:

MAKE=make
BUILDS=Release Debug
TARGETS=all clean

$(TARGETS):
    @for b in $(BUILDS) ; do $(MAKE) -C $$b $@ ; done

$(BUILDS):
    @for t in $(TARGETS) ; do $(MAKE) -C $@ $$t ; done

%:
    @for b in $(BUILDS) ; do $(MAKE) -C $$b $@ ; done

Solution

  • depends on what is "calls". You want to either

    include $(BUILD)/Makefile

    or

    $(MAKE) -C $(BUILD) $@

    or some such. I'd guess you want the latter. Maybe something like

    release debug:
        $(MAKE) -C $@
    

    You get the idea.

    More examples:

    BUILDS=release debug
    TARGETS=all clean
    
    $(TARGETS):
        for b in $(BUILDS) ; do $(MAKE) -C $$b $@ ; done
    
    $(BUILDS):
        for t in $(TARGETS) ; do $(MAKE) -C $@ $$t ; done