Getting Started print

This page gives a simple overview of what to expect from NOSPB.

Examples

Recursing into sub-directories

# A typical Makefile demonstrating recursion into sub-directories.

default:
    $(MAKE) -C lib
    $(MAKE) -C client
    $(MAKE) -C server

all: default test

test:
    $(MAKE) -C lib test
    $(MAKE) -C client test
    $(MAKE) -C server test

clean:
    $(MAKE) -C lib clean
    $(MAKE) -C client clean
    $(MAKE) -C server clean

# A NOSPB Makefile demonstrating recursion into sub-directories.

TOP?=..
SUBDIRS=lib client server
include $(TOP)/nospb/mk/rules.mk

Building a C++ library

# A typical Makefile that builds a C++ library.
# (Does not support cross platform of build variants.)

TARGET=../../output/lib/foo.a
FILES=$(wildcard *.cxx)
OBJECTS=$(FILES:%.cxx=%.o)
CPPFLAGS=-DBAR
CXXFLAGS=-O2 -Wall

default: $(TARGET)

all: default

$(TARGET): $(OBJECTS)
    mkdir -p $(dir $@)
    $(AR) $(ARFLAGS) $@ $^

clean:
    rm -f $(OBJECTS) $(TARGET)

%.o : %.cxx
    $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@

# A nospb Makefile that builds a C++ library.
TOP?=../..
NAME=foo
WHAT=lib
DEFINES=BAR
include $(TOP)/nospb/mk/rules.mk

Assignments

Gnu Make supports two basic assignment modes. In most cases, this documentation will refer to the lazy evaluation assignment (=), and will only refer to immediate evaluation assignments (:=) when required.

Formatting

You should already know that Gnu Make requires all commands under a target to be indented with a tab (\t). If you have make preprocessor logic mixed in with your targets, though, you must use regular spaces for indentation. It can be a real pain to keep switching between spaces and tabs for indentation, but it is worth it when you are actually able to read your Make configurations.

If you cut and paste examples from this site, you will probably have to replace spaced indentation with tab indentation for all target commands.

TOP

In order to find the Make configuration files, the NOSPB Makefile needs to know the path to the TOP of the source tree. Examples in this documentation will generally use a relative path, but you should also be able to use an absolute path, which is useful if you set TOP in the environment from a build script.

TOP?=../..

You could also potentially run a script from the PATH to set TOP.

TOP?=$(shell findsrctop.sh)

Including rules.mk

Every NOSPB Makefile needs to include the rules.mk file. If you follow the examples in this documentation, this will look like:

include $(TOP)/nospb/mk/rules.mk