-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
212 lines (164 loc) · 5.1 KB
/
Makefile
File metadata and controls
212 lines (164 loc) · 5.1 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# C++ financial library
# =====================
# Copyright 2013 Paul Griffiths
# Email: mail@paulgriffiths.net
#
# Distributed under the terms of the GNU General Public License.
# http://www.gnu.org/licenses/
# Variables section
# =================
# Library and executable names
LIBNAME=financial
OUT=lib$(LIBNAME).a
TESTOUT=unittests
SAMPLEOUT=sample
# Install paths
#LIB_INSTALL_PATH=/home/paul/lib/cpp
INC_INSTALL_PREFIX=paulgrif
INC_INSTALL_PATH=$(HOME)/include/$(INC_INSTALL_PREFIX)
LIB_INSTALL_PATH=$(HOME)/lib/cpp
HEADERS=financial.h basic_dcf.h common_financial_types.h bond.h
# Compiler and archiver executable names
AR=ar
CXX=g++
# Archiver flags
ARFLAGS=rcs
# Compiler flags
CXXFLAGS=-std=c++11 -pedantic -Wall -Wextra
CXX_DEBUG_FLAGS=-Weffc++ -ggdb -DDEBUG -DDEBUG_ALL
CXX_RELEASE_FLAGS=-Weffc++ -O3 -DNDEBUG
CXX_TEST_FLAGS=-ggdb -DDEBUG -DDEBUG_ALL
# Linker flags
LDFLAGS=
LD_TEST_FLAGS=-lboost_system -lboost_thread -lboost_unit_test_framework
LD_TEST_FLAGS+=-lstdc++
LD_TEST_FLAGS+=-l$(LIBNAME) -L$(CURDIR)
# Object code files
OBJS=basic_dcf.o bond.o
TESTOBJS=tests/test_main.o
TESTOBJS+=tests/test_discount_factor.o
TESTOBJS+=tests/test_present_value.o
TESTOBJS+=tests/test_future_value.o
TESTOBJS+=tests/test_perpetuity.o
TESTOBJS+=tests/test_annuity.o
TESTOBJS+=tests/test_sinking_fund.o
TESTOBJS+=tests/test_loan_repayment.o
TESTOBJS+=tests/test_simple_bond.o
# Source and clean files and globs
SRCS=$(wildcard *.cpp *.h)
SRCS+=$(wildcard tests/*.cpp)
SRCGLOB=*.cpp *.h
SRCGLOB+=tests/*.cpp
CLNGLOB=$(OUT) $(TESTOUT) $(SAMPLEOUT)
CLNGLOB+=*~ *.o *.gcov *.out *.gcda *.gcno
CLNGLOB+=tests/*~ tests/*.o tests/*.gcov tests/*.out tests/*.gcda tests/*.gcno
# Build targets section
# =====================
default: debug
# debug - builds objects with debugging info
.PHONY: debug
debug: CXXFLAGS+=$(CXX_DEBUG_FLAGS)
debug: main
# release - builds with optimizations and without debugging info
.PHONY: release
release: CXXFLAGS+=$(CXX_RELEASE_FLAGS)
release: main
# tests - builds unit tests
.PHONY: tests
tests: CXXFLAGS+=$(CXX_TEST_FLAGS)
tests: LDFLAGS+=$(LD_TEST_FLAGS)
tests: testmain
# install - installs library and headers
.PHONY: install
install:
@if [ ! -d $(INC_INSTALL_PATH) ]; then \
mkdir $(INC_INSTALL_PATH); fi
@echo "Copying library to $(LIB_INSTALL_PATH)..."
@cp $(OUT) $(LIB_INSTALL_PATH)
@echo "Copying headers to $(INC_INSTALL_PATH)..."
@cp $(HEADERS) $(INC_INSTALL_PATH)
@echo "Done."
# sample - makes sample program
.PHONY: sample
sample: LDFLAGS+=-l$(LIBNAME)
sample: main.o
@echo "Linking sample program..."
@$(CXX) -o $(SAMPLEOUT) main.o $(LDFLAGS)
@echo "Done."
# clean - removes ancilliary files from working directory
.PHONY: clean
clean:
-@rm $(CLNGLOB) 2>/dev/null
# lint - runs cpplint with specified options
.PHONY: lint
lint:
@cpplint --verbose=5 --filter=-runtime/references,-build/header_guard,\
-readability/streams,-build/include,-legal/copyright,\
-runtime/threadsafe_fn,-whitespace/blank_line,-runtime/int,\
-build/namespaces \
$(SRCGLOB)
# check - runs cppcheck with specified options
.PHONY: check
check:
@cppcheck --enable=all $(SRCGLOB)
# Executable targets section
# ==========================
# Main library
main: $(OBJS)
@echo "Building library..."
@$(AR) $(ARFLAGS) $(OUT) $(OBJS)
@echo "Done."
# Unit tests executable
testmain: $(TESTOBJS)
@echo "Linking unit tests..."
@$(CXX) -o $(TESTOUT) $(TESTOBJS) $(LDFLAGS)
@echo "Done."
# Object files targets section
# ============================
# Sample program
main.o: main.cpp
@echo "Compiling $<..."
@$(CXX) $(CXXFLAGS) -c -o $@ $<
# Object files for library
basic_dcf.o: basic_dcf.cpp basic_dcf.h common_financial_types.h
@echo "Compiling $<..."
@$(CXX) $(CXXFLAGS) -c -o $@ $<
bond.o: bond.cpp bond.h basic_dcf.h common_financial_types.h
@echo "Compiling $<..."
@$(CXX) $(CXXFLAGS) -c -o $@ $<
# Unit tests
tests/test_main.o: tests/test_main.cpp
@echo "Compiling $<..."
@$(CXX) $(CXXFLAGS) -c -o $@ $<
tests/test_discount_factor.o: tests/test_discount_factor.cpp \
basic_dcf.h common_financial_types.h
@echo "Compiling $<..."
@$(CXX) $(CXXFLAGS) -c -o $@ $<
tests/test_present_value.o: tests/test_present_value.cpp \
basic_dcf.h common_financial_types.h
@echo "Compiling $<..."
@$(CXX) $(CXXFLAGS) -c -o $@ $<
tests/test_future_value.o: tests/test_future_value.cpp \
basic_dcf.h common_financial_types.h
@echo "Compiling $<..."
@$(CXX) $(CXXFLAGS) -c -o $@ $<
tests/test_perpetuity.o: tests/test_perpetuity.cpp \
basic_dcf.h common_financial_types.h
@echo "Compiling $<..."
@$(CXX) $(CXXFLAGS) -c -o $@ $<
tests/test_annuity.o: tests/test_annuity.cpp \
basic_dcf.h common_financial_types.h
@echo "Compiling $<..."
@$(CXX) $(CXXFLAGS) -c -o $@ $<
tests/test_sinking_fund.o: tests/test_sinking_fund.cpp \
basic_dcf.h common_financial_types.h
@echo "Compiling $<..."
@$(CXX) $(CXXFLAGS) -c -o $@ $<
tests/test_loan_repayment.o: tests/test_loan_repayment.cpp \
basic_dcf.h common_financial_types.h
@echo "Compiling $<..."
@$(CXX) $(CXXFLAGS) -c -o $@ $<
tests/test_simple_bond.o: tests/test_simple_bond.cpp \
bond.h basic_dcf.h common_financial_types.h
@echo "Compiling $<..."
@$(CXX) $(CXXFLAGS) -c -o $@ $<