Next: , Up: Compiling your application   [Contents]

3.4.1 Breakdown of example makefile: the core

Let’s break the provided makefile down to the core so we can discuss what is actually needed to compile the AlarmSystem application. The makefile assumes you will compile the application on a Raspberry Pi. To accomplish this, you need to transfer the source files and generated files to the Pi filesystem. With all that in place, the following snippet will compile the integrated application on the Pi:

CXX = g++
CXXFLAGS = -std=c++11 -I$(RUNTIME) -I$(SRC) -lwiringPi -lrt
CPPFLAGS = -MMD -MF $(@:%.o=%.d) -MT '$(@:%.o=%.d) $@' -I$(SRC) -I$(RUNTIME)
LDFLAGS = -lpthread
TARGET = dznpi

SRC = ./src
RUNTIME = ./lib

SRCS = $(wildcard $(SRC)/*.cc)
SRCS += $(wildcard $(RUNTIME)/*.cc)

OBJS = $(subst .cc,.o,$(SRCS))

	make $(TARGET)


-include $(wildcard $(SRC)/*.d $(RUNTIME)/*.d)

This makefile will search for the Dezyne runtime files in the directory pointed at by the RUNTIME variable. The C++ source files of your application should be in the directory pointed at by the SRC variable.

One of the key reasons for using a makefile, aside from not having to re-type your compilation recipe every time you make a change, is to save time by dynamically deciding what files have been changed. An unchanged file often does not need to be recompiled and in larger projects you can save a lot of time by not re-compiling every single file for every small change you make. In this makefile, this dynamic checking is realised with the -MMD -MF $(@:%.o=%.d) -MT '$(@:%.o=%.d) $@' CPPFLAGS and the -include $(wildcard $(SRC)/*.d $(RUNTIME)/*.d) line at the end of the file.

Remember when we first inspected the generated system in Inspecting the generated system? You were told that inclusion of runtime files must be done using ‘ <> ‘ tags and that this would have some implications for compiling the application. These implications are represented in the makefile by the -I$(RUNTIME) -I$(SRC) flags in CXX/CPPFLAGS. This means that for every compilation step, RUNTIME and SRC point to directories that must be searched for included dependencies. With these flags added to your compilation recipe, ‘<>’ tags can be used and the generated code can find its required headers.

The --lwiringPi and --lrt flags are required to be able to make use of the WiringPi library. Due to the --lrt flag, the pthread library must be linked to the executable post compilation; this is done with the LDFLAGS = -lpthread compilation step.

With this makefile and a properly structured filesystem containing your project, you can already compile an application consisting of foreign and generated Dezyne code. Awesome! In case you are unsure of what your filesystem should look like, you can use the Github repository as inspiration:


With this folder structure, if you type ‘make’ in a terminal window on your Raspberry Pi while inside the same folder the makefile is in, an executable called ‘dznpi’ will be created. If you run the dznpi executable on your Pi and have connected the RGB led to the GPIO pins you defined to be the Red, Green and Blue RGB pins then you should be able to control the dznpi application with sensorTriggered and validPincode events through the command line UI!

Next: , Up: Compiling your application   [Contents]