Nested GNU make files …

Sometimes you want to build potential goals of nested make files, i.e. make files that reside in a different folder. The best method I’ve been able to come up with so far was this one:

# Declare some (immediate) constants (uppercase) and
# (deferred) local variables (lowercase)
MAKE_VERSION_MAJOR := $(word 1, $(subst ., ,$(MAKE_VERSION)))
MAKE_VERSION_MINOR := $(word 2, $(subst ., ,$(MAKE_VERSION)))

# Do not allow to run on versions of GMAKE whose
# capabilities we don't know
$(if $(filter $(MAKE_VERSION),$(NEED_GMAKE_VERSION)),,\
$(error This makefile requires one of the following GNU make \
versions: $(NEED_GMAKE_VERSION)))

# The goals
MAKE_DIRECTORIES = folder1 folder2

.PHONY: all

    @$(MAKE) --keep-going --directory=$@ $(MAKECMDGOALS)

# All goals "forward" the make into the individual directories

Even if you don’t know the available goals in nested make files, this top-level make file will go into folder1 and folder2 and do its job. No matter whether you told it to make clean, make all or simply make.

// Oliver

PS: Of course you need not hard code the folders … they could also be retrieved by a find call.

This entry was posted in EN, Linux, Programming, Software. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *