prevent Makefile from remaking itself

Makefile: ; # <-- empty rule

Makefile that builds or cleans all projects in a “solution”

Scenario:

  • “Solution” with several projects, where each project has its own Makefile.
  • Each project Makefile accepts the all and clean target.
  • The root directory of each project is a direct sub-directory of the solution’s root directory.
MAKE_TARGET=all

first: all

# list of all projects (directories) in building order
projects = project1 project2 project3

$(projects):
	(cd $@ ; make ${MAKE_TARGET})

all:
	make $(projects)

clean:
	make MAKE_TARGET=clean $(projects)

help:
	@cmake -E echo "usage:"
	@cmake -E echo
	@cmake -E echo "make [all]   Build all projects."
	@cmake -E echo "make clean   Clean all projects."

.PHONY: all clean help $(projects)