-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
156 lines (122 loc) · 4.16 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Makefile for Behaviour Control Framework
# This makefile is an example only, and is intended for demonstrating compilation on Linux
# systems. The behaviour control code is however completely platform-independent and can easily
# be built on Windows systems. Ideally this library should either be used by directly including
# the library source files in your project and compiling, or by building a static library and
# linking your project to it. It is also possible to build a dynamic library of the framework,
# but due to the library's rather small size and low resource requirements, this is not necessary
# and can possibly introduce unnecessary complications.
#
# All three building possibilities are demonstrated below (directly include source, build static
# library, build dynamic library).
#
# It is assumed that gtest/gtest.h is on a global include path, and the pthread, gtest and
# gtest_main libraries can be found. It is also assumed that the following Boost Libraries
# are installed and can be found: Static Assert, Type Traits, Utility
#
# Get started by executing 'make list'.
# Executing 'make' attempts to build all targets.
MAJOR_VERSION = 1
MINOR_VERSION = 0
PATCH_VERSION = 2
SRCDIR = src
INCLUDEDIR = include
BUILDDIR = build
LIBDIR = lib
BINDIR = bin
TESTDIR = test
DYNDIR = $(BUILDDIR)/for_dyn_lib
ENSURE_DIR = @mkdir -p $(@D)
INCLUDES = -I$(INCLUDEDIR)
LDFLAGS = ../../gtest/libgtest.a ../../gtest/libgtest_main.a -lpthread
DLIB_OBJS = $(DYNDIR)/behaviour.o $(DYNDIR)/behaviour_actuators.o $(DYNDIR)/behaviour_common.o $(DYNDIR)/behaviour_control.o $(DYNDIR)/behaviour_layer.o $(DYNDIR)/behaviour_manager.o $(DYNDIR)/behaviour_sensors.o
LIB_OBJS = $(BUILDDIR)/behaviour.o $(BUILDDIR)/behaviour_actuators.o $(BUILDDIR)/behaviour_common.o $(BUILDDIR)/behaviour_control.o $(BUILDDIR)/behaviour_layer.o $(BUILDDIR)/behaviour_manager.o $(BUILDDIR)/behaviour_sensors.o
TEST_OBJS = $(BUILDDIR)/test_behaviour_control.o $(BUILDDIR)/test_utilities.o
DLIB_BASENAME = $(LIBDIR)/libbehaviour_control.so
SLIB_TARGET = $(LIBDIR)/libbehaviour_control.a
DLIB_TARGET = $(DLIB_BASENAME).$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)
TEST_TARGET = $(BINDIR)/test_behaviour_control
CXX = g++
AR = ar
CXXFLAGS = -Wall -g -MMD
#
# Meta rules
#
all: libs tests
libs: lib-static lib-dynamic
#
# Static library rules
#
lib-static: $(SLIB_TARGET)
$(SLIB_TARGET): $(LIB_OBJS)
@echo "Building static library..."
$(ENSURE_DIR)
$(AR) -rcs $@ $^
#
# Dynamic library rules
#
lib-dynamic: $(DLIB_TARGET)
$(DLIB_TARGET): $(DLIB_OBJS)
@echo "Building dynamic library..."
$(ENSURE_DIR)
$(CXX) $(CXXFLAGS) -shared -o $@ $^ $(LDFLAGS)
ln -sf $(DLIB_TARGET) $(DLIB_BASENAME).$(MAJOR_VERSION).$(MINOR_VERSION)
ln -sf $(DLIB_TARGET) $(DLIB_BASENAME).$(MAJOR_VERSION)
ln -sf $(DLIB_TARGET) $(DLIB_BASENAME)
$(DYNDIR)/%.o: $(SRCDIR)/%.cpp
$(ENSURE_DIR)
$(CXX) $(CXXFLAGS) -fPIC -o $@ -c $< $(INCLUDES)
$(DYNDIR)/%.o: $(TESTDIR)/%.cpp
$(ENSURE_DIR)
$(CXX) $(CXXFLAGS) -fPIC -o $@ -c $< $(INCLUDES)
#
# Unit test rules
#
run-tests: tests
@echo "Running $(TEST_TARGET)..."
@./$(TEST_TARGET)
tests: $(TEST_TARGET)
$(TEST_TARGET): $(LIB_OBJS) $(TEST_OBJS)
@echo "Building $(TEST_TARGET)..."
$(ENSURE_DIR)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp
$(ENSURE_DIR)
$(CXX) $(CXXFLAGS) -o $@ -c $< $(INCLUDES)
$(BUILDDIR)/%.o: $(TESTDIR)/%.cpp
$(ENSURE_DIR)
$(CXX) $(CXXFLAGS) -o $@ -c $< $(INCLUDES)
#
# Dependency rules
#
-include $(LIB_OBJS:.o=.d)
-include $(DLIB_OBJS:.o=.d)
-include $(TEST_OBJS:.o=.d)
#
# Clean rules
#
clean:
rm -f $(BUILDDIR)/*.o $(BUILDDIR)/*.d $(DYNDIR)/*.o $(DYNDIR)/*.d
rm -f $(SLIB_TARGET)
rm -f $(DLIB_TARGET) $(DLIB_BASENAME).$(MAJOR_VERSION).$(MINOR_VERSION) $(DLIB_BASENAME).$(MAJOR_VERSION) $(DLIB_BASENAME)
rm -f $(TEST_TARGET)
rm -f *~
clean-hard:
rm -rf $(BUILDDIR)
rm -rf $(LIBDIR)
rm -rf $(BINDIR)
rm -f *~
clean-doc:
rm -rf doc/out
#
# Help
#
.PHONY: no_targets__ list doc
doc:
@doc/generate_doc.sh | grep warning || true
doc-verbose:
@doc/generate_doc.sh
no_targets__:
list:
@sh -c "$(MAKE) -p no_targets__ | awk -F':' '/^[a-zA-Z0-9][^\$$#\/\\t=]*:([^=]|$$)/ {split(\$$1,A,/ /);for(i in A)print A[i]}' | grep -v '__\$$' | sort"
# EOF