Building a Framework

Now that we have subdirs.mk, we can start to build a framework around our new automation.

Create Build System Directory

Create the nospb directory in the top level directory of your project. Under the nospb directory, create the mk directory.

cd MyProject
mkdir nospb
cd nospb
mkdir mk

Copy subdirs.mk to nospb/mk.

Create the Rules Framework

Create a file under nospb/mk called rules.mk. We’ll need a little extra logic in this file to figure out the path to nospb/mk.

rules.mk

# Determine the directory that contains rules.mk.  May be empty path.
__nospb_dir:=$(patsubst %rules.mk,%,$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))

# Declare the "default" target first to guarantee order.
default::

all:: default

# If the Makefile declares SUBDIRS, include subdirs.mk.
ifdef SUBDIRS
    include $(__nospb_dir)subdirs.mk
endif