forked from AIS-Bonn/attitude_estimator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
151 lines (118 loc) · 3.68 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
# Makefile for Attitude Estimator
# This makefile is an example only, and is intended for demonstrating compilation on Linux
# systems. The attitude estimator 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 two library source files (attitude_estimator.h/cpp) 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 attitude_estimator, but due to the library's very 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.
#
# Get started by executing 'make list'.
# Executing 'make' attempts to build all targets.
MAJOR_VERSION = 1
MINOR_VERSION = 2
PATCH_VERSION = 0
SRCDIR = src
TESTDIR = test
INCLUDEDIR = src
BUILDDIR = build
LIBDIR = lib
BINDIR = bin
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)/attitude_estimator.o
LIB_OBJS = $(BUILDDIR)/attitude_estimator.o
TEST_OBJS = $(BUILDDIR)/test_attitude_estimator.o
DLIB_BASENAME = $(LIBDIR)/libattitude_estimator.so
SLIB_TARGET = $(LIBDIR)/libattitude_estimator.a
DLIB_TARGET = $(DLIB_BASENAME).$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)
TEST_TARGET = $(BINDIR)/test_attitude_estimator
CXX = g++
AR = ar
CXXFLAGS = -Wall -g
#
# 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 $@ $^
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp
$(ENSURE_DIR)
$(CXX) $(CXXFLAGS) -o $@ -c $< $(INCLUDES)
#
# 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)
#
# 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: $(TESTDIR)/%.cpp
$(ENSURE_DIR)
$(CXX) $(CXXFLAGS) -o $@ -c $< $(INCLUDES)
#
# Dependency rules
#
$(BUILDDIR)/attitude_estimator.o: $(INCLUDEDIR)/attitude_estimator.h
$(BUILDDIR)/test_attitude_estimator.o: $(INCLUDEDIR)/attitude_estimator.h
$(DYNDIR)/attitude_estimator.o: $(INCLUDEDIR)/attitude_estimator.h
#
# Clean rules
#
clean:
rm -f $(BUILDDIR)/*.o $(DYNDIR)/*.o
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