-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
147 lines (117 loc) · 3.71 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
# This Makefile is based on Job Vranish's article at https://spin.atomicobject.com/2016/08/26/makefile-c-projects/
MAIN_EXEC ?= access-log-supervisor
TEST_EXEC ?= test
BUILD_DIR ?= ./build
SRC_DIRS ?= ./src
MAIN_SRCS := \
src/utils/AddressRange.cpp \
src/utils/Address.cpp \
src/utils/Timestamp.cpp \
src/utils/ParamList.cpp \
src/utils/Mail.cpp \
src/utils/sqlite/SQLiteDB.cpp \
src/utils/sqlite/SQLiteStatement.cpp \
src/utils/sqlite/SQLiteStatementIterator.cpp \
src/utils/Pipeline.cpp \
src/database/Database.cpp \
src/database/DatabaseObjects.cpp \
src/database/DatabaseRequest.cpp \
src/database/DatabaseRequestIterator.cpp \
src/parsers/AuthParser.cpp \
src/parsers/ApacheParser.cpp \
src/serializers/SerializerInterface.cpp \
src/serializers/TextSerializer.cpp \
src/serializers/HTMLSerializer.cpp \
src/Config.cpp \
src/Supervisor.cpp \
src/main.cpp
TEST_SRCS := \
tests/tests.cpp \
src/utils/AddressRange.cpp \
src/utils/Address.cpp \
src/utils/Timestamp.cpp \
src/utils/ParamList.cpp \
src/utils/sqlite/SQLiteDB.cpp \
src/utils/sqlite/SQLiteStatement.cpp \
src/utils/sqlite/SQLiteStatementIterator.cpp \
src/database/Database.cpp \
src/database/DatabaseObjects.cpp \
src/database/DatabaseRequest.cpp \
src/database/DatabaseRequestIterator.cpp \
src/parsers/AuthParser.cpp \
src/parsers/ApacheParser.cpp \
src/Config.cpp \
src/Supervisor.cpp \
tests/TestAddresses.cpp \
tests/TestAliasStore.cpp \
tests/TestParamList.cpp \
tests/TestSQLiteObjects.cpp \
tests/TestTimestamp.cpp \
tests/TestDatabase.cpp \
tests/TestConfigParsing.cpp \
tests/TestAuthParser.cpp \
tests/TestApacheParser.cpp \
tests/TestSupervisor.cpp
MAIN_STATIC_LIBS := libs/yaml-cpp/build/libyaml-cpp.a
TEST_STATIC_LIBS := libs/yaml-cpp/build/libyaml-cpp.a
MAIN_LDFLAGS = -lcidr -lsqlite3
TEST_LDFLAGS = -lcidr -lsqlite3
# Usual targets
all: $(BUILD_DIR)/$(MAIN_EXEC)
test: $(BUILD_DIR)/$(TEST_EXEC)
# Automatic substitution
MAIN_OBJS := $(MAIN_SRCS:%=$(BUILD_DIR)/%.o)
TEST_OBJS := $(TEST_SRCS:%=$(BUILD_DIR)/%.o)
ALL_DEPS := \
$(MAIN_OBJS:.o=.d) \
$(TEST_OBJS:.o=.d)
# Adding the static libs *after* defining .d files
MAIN_OBJS += $(MAIN_STATIC_LIBS)
TEST_OBJS += $(TEST_STATIC_LIBS)
# For automatic dependancy detection
CPPFLAGS ?= -MMD -MP
# Other flags
CPPFLAGS += -std=c++17 -Wall -Wextra
CPPFLAGS += -DGIT_VERSION_STRING='"$(shell git describe --tags --dirty)"'
# libs
CPPFLAGS += -Ilibs/yaml-cpp/include -Ilibs/
# Final executable
$(BUILD_DIR)/$(MAIN_EXEC): $(MAIN_OBJS)
$(CXX) $(MAIN_OBJS) -o $@ $(MAIN_LDFLAGS)
$(BUILD_DIR)/$(TEST_EXEC): $(TEST_OBJS)
$(CXX) $(TEST_OBJS) -o $@ $(TEST_LDFLAGS)
# assembly
$(BUILD_DIR)/%.s.o: %.s
$(MKDIR_P) $(dir $@)
$(AS) $(ASFLAGS) -c $< -o $@
# c source
$(BUILD_DIR)/%.c.o: %.c
$(MKDIR_P) $(dir $@)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
# c++ source
$(BUILD_DIR)/%.cpp.o: %.cpp
$(MKDIR_P) $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
-include $(ALL_DEPS)
MKDIR_P ?= mkdir -p
install: $(BUILD_DIR)/$(MAIN_EXEC)
$(MKDIR_P) $(DESTDIR)$(PREFIX)/bin
install -o supervision -g supervision -m 755 $(BUILD_DIR)/$(MAIN_EXEC) $(DESTDIR)$(PREFIX)/bin/access-log-supervisor
uninstall:
rm $(DESTDIR)$(PREFIX)/bin/access-log-supervisor
# static libs
libs/yaml-cpp/build/libyaml-cpp.a:
@echo "====================================================================="
@echo "= Building a dependancy ="
@echo "= make sure you have run git submodule init; git submodule update ="
@echo "====================================================================="
mkdir -p libs/yaml-cpp/build
cd libs/yaml-cpp/build; cmake .. ; make
# Utilities
.PHONY: clean
clean:
$(RM) -r $(BUILD_DIR)
.PHONY: doc
doc:
mkdir -p build/doc
doxygen doc/Doxyfile