Makefile executing another makefile

Assume that I had created a makefile in directory "projectX". In directory "projectX", assume that there is a subdirectory named "projectY" with a makefile inside.

I want to make the makefile in directory "projectX", when executed, it will also execute the makefile stored in "projectY" at first.

What are the codes I need to implement in makefile in directory "projectX"?
Last edited on
make -f makefile i guess
Last edited on
cd $(subdir) && make
I think something a bit like this might do it:
1
2
3
4
5
6
7
8
SUBDIRS = projectX projectY

all: $(SUBDIRS)

$(SUBDIRS):
	$(MAKE) -C $@

.PHONY: $(SUBDIRS)


EDIT: That's not quite the example asked for. It will try to build two projects in sub directories projectX and projectY from the current project in the current directory.

EDIT: Fixed to use moorecm's invocation command
Last edited on
In a top-level makefile, just use something like:
$(MAKE) -C dir

The -C option changes the directory before invoking the make. The $(MAKE) variable will use the same make executable as the top-level makefile. man make for more information.
Topic archived. No new replies allowed.