-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
128 lines (96 loc) · 3.25 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
SHELL := /bin/bash
BOOSTDIR := /usr/local/lib
PREFIX := /usr/local
CXXFLAGS := -Wall -fPIC -std=c++11 -pedantic
INCDIR := include
SRCDIR := src
BUILDDIR := build
TESTDIR := tests
BENCHDIR := benchmarks
LIBS := -L$(BOOSTDIR) -lboost_serialization -lstdc++ -lgmp
TESTLIBS := -L$(BOOSTDIR) -lboost_unit_test_framework
INC := -I$(INCDIR)
LIBSOURCES := $(wildcard $(SRCDIR)/*.cpp)
TESTSOURCES := $(wildcard $(TESTDIR)/*.cpp)
BENCHSOURCES := $(wildcard $(BENCHDIR)/*.cpp)
LIBOBJECTS := $(patsubst %.cpp,$(BUILDDIR)/%.o, $(LIBSOURCES))
TESTOBJECTS := $(patsubst %.cpp,$(BUILDDIR)/%.o, $(TESTSOURCES))
BENCHOBJECTS := $(patsubst %.cpp,$(BUILDDIR)/%.o, $(BENCHSOURCES))
TESTTARGETS := $(patsubst %.cpp,$(BUILDDIR)/%, $(TESTSOURCES))
BENCHTARGETS := $(patsubst %.cpp,$(BUILDDIR)/%, $(BENCHSOURCES))
LIBTARGET := $(BUILDDIR)/libshe.so
TESTOPTS := --log_level=test_suite
COVERAGEFILE := $(BUILDDIR)/coverage.info
GCOV := gcov
define \n
endef
# Messages
LINK := > Link
COMPILE := > Cmpl
EXEC := > Exec
.PHONY: all
all: library
# Library
.PHONY: library
library: CXXFLAGS += -O3
library: $(LIBTARGET)
$(LIBTARGET): $(LIBOBJECTS)
@echo "$(LINK): $^"
@$(CXX) $(LDFLAGS) -shared $^ $(LIBS) -o $@
$(LIBOBJECTS): $(BUILDDIR)/%.o: %.cpp
@echo "$(COMPILE): $^"
@mkdir -p $(BUILDDIR)/$(SRCDIR)
@$(CXX) $(CXXFLAGS) $(INC) -c $^ -o $@
# Tests
.PHONY: tests
tests: CXXFLAGS += -O0 -DDEBUG -g --coverage
tests: LDFLAGS = --coverage
tests: $(LIBSOURCES)
tests: $(TESTSOURCES)
tests: $(TESTTARGETS)
$(TESTTARGETS): $(LIBOBJECTS)
$(TESTTARGETS): $(BUILDDIR)/%: $(BUILDDIR)/%.o
@echo "$(LINK): $^"
@$(CXX) $(LDFLAGS) $^ $(TESTLIBS) $(LIBS) -o $@
$(foreach exe,$@,@echo "$(EXEC): $(exe)" && ./$(exe) $(TESTOPTS)${\n})
$(TESTOBJECTS): $(BUILDDIR)/%.o: %.cpp
@echo "$(COMPILE): $^"
@mkdir -p $(BUILDDIR)/$(TESTDIR)
@$(CXX) $(CXXFLAGS) $(INC) -c $^ -o $@
# Coverage report
.PHONY: coverage
coverage:
@lcov --gcov-tool $(GCOV) --directory . --capture --output-file $(COVERAGEFILE)
@lcov --gcov-tool $(GCOV) --remove $(COVERAGEFILE) 'tests/*' '/usr/*' --output-file $(COVERAGEFILE) 2> /dev/null
@lcov --gcov-tool $(GCOV) --list $(COVERAGEFILE)
@genhtml $(COVERAGEFILE) --output-directory $(BUILDDIR)/coverage
# Benchmarks
.PHONY: benchmarks
benchmarks: $(LIBSOURCES)
benchmarks: $(BENCHSOURCES)
benchmarks: $(BENCHTARGETS)
$(foreach exe,$<,@echo "$(EXEC): $(exe)" && ./$(exe) $(TESTOPTS)${\n})
$(BENCHTARGETS): $(LIBOBJECTS)
$(BENCHTARGETS): $(BUILDDIR)/%: $(BUILDDIR)/%.o
@echo "$(LINK): $^"
@$(CXX) $(LDFLAGS) $^ $(LIBS) -o $@
$(BENCHOBJECTS): $(BUILDDIR)/%.o: %.cpp
@echo "$(COMPILE): $^"
@mkdir -p $(BUILDDIR)/$(BENCHDIR)
@$(CXX) $(CXXFLAGS) $(INC) -c $^ -o $@
# Installation
.PHONY: install
install: $(BUILDDIR)/$(LIBTARGET)
@mkdir -p $(PREFIX)/include
@mkdir -p $(PREFIX)/lib
cp -rf $(INCDIR) -t $(PREFIX)
cp -f $(BUILDDIR)/$(LIBTARGET) -t $(PREFIX)/lib/
ldconfig
.PHONY: uninstall
uninstall:
rm $(PREFIX)/lib/$(LIBTARGET)
$(foreach header,$(shell ls -1 $(INCDIR)),rm -r $(PREFIX)/include/$(header)${\n})
ldconfig
.PHONY: clean
clean:
rm -rf $(BUILDDIR)