-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
149 lines (111 loc) · 5.51 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
# Name of the executable
TARGET=webserver
# Files to be deployed with the webserver for use by it
DEPLOYFILES=example_config bunny.jpg chatbox.htm markdown.md design.html
# Test executables
TESTEXEC=config_parser_test response_test server_config_parser_test request_test static_file_handler_test echo_handler_test not_found_handler_test reverse_proxy_handler_test
GCOVEXEC=config_parser_gcov response_gcov server_config_parser_gcov request_gcov static_file_handler_gcov echo_handler_gcov not_found_handler_gcov reverse_proxy_handler_gcov
# GoogleTest directory and output files
GTEST_DIR=googletest/googletest
GTEST_FILES=libgtest.a gtest-all.o
# Gcov flags and files
GCOVFLAGS=-fprofile-arcs -ftest-coverage
GCOVFILES=*.gcno *.gcda *.gcov
# Compiler flags
CXXFLAGS+= -std=c++11 -pthread -Wall -Werror -ILuaJIT-2.0.4/include/luajit-2.0
# Linker flags
LDFLAGS+= -static-libgcc -static-libstdc++ -Wl,-rpath '-Wl,$$ORIGIN' \
-L./LuaJIT-2.0.4/src -lluajit -pthread -Wl,-Bstatic -lssl -lcrypto \
-lboost_system -lboost_regex -Wl,-Bdynamic -ldl
# Test flags
TESTFLAGS=-std=c++11 -isystem ${GTEST_DIR}/include -pthread \
-ILuaJIT-2.0.4/include/luajit-2.0
# Test files, e.g., downloaded files from integration tests
TEST_FILES=proxy_bunny
# Source files
SRC=server.cc config_parser.cc response.cc \
server_config_parser.cc request.cc echo_handler.cc \
static_file_handler.cc request_handler.cc \
not_found_handler.cc status_handler.cc reverse_proxy_handler.cc \
cpp-markdown/markdown.cpp cpp-markdown/markdown-tokens.cpp
.PHONY: clean clean_target gcov test test_gcov test_setup deploy docker
$(TARGET): clean_target sqlite lua
$(CXX) -o $@ main.cc $(SRC) $(CXXFLAGS) $(LDFLAGS)
lua:
cd LuaJIT-2.0.4 && make install PREFIX=$(shell cd LuaJIT-2.0.4 && pwd)
cp LuaJIT-2.0.4/lib/libluajit-5.1.so.2 .
cp LuaJIT-2.0.4/lib/libluajit-5.1.so.2.0.4 .
sqlite:
bash fix-timestamps.sh
cd sqlite-autoconf-3170000 && ./configure --prefix=$(shell cd \
sqlite-autoconf-3170000 && pwd) && make install
cp sqlite-autoconf-3170000/lib/libsqlite3.so .
cp sqlite-autoconf-3170000/lib/libsqlite3.so.0 .
cp sqlite-autoconf-3170000/lib/libsqlite3.so.0.8.6 .
clean_target:
$(RM) $(TARGET)
clean: clean_target
$(RM) $(GCOVFILES) $(TESTEXEC) $(GTEST_FILES) *_gcov.txt
$(RM) $(TEST_FILES)
$(RM) binary.tar webserver_image
$(RM) -r deploy
test_gcov: $(GCOVEXEC)
test_setup:
g++ $(TESTFLAGS) -I${GTEST_DIR} -c ${GTEST_DIR}/src/gtest-all.cc
ar -rv libgtest.a gtest-all.o
test: $(TARGET) $(TESTEXEC) integration_test
integration_test: $(TARGET)
python webserver_test.py
config_parser_test: test_setup config_parser.cc config_parser_test.cc
g++ $(GCOVFLAGS) $(TESTFLAGS) config_parser_test.cc config_parser.cc ${GTEST_DIR}/src/gtest_main.cc libgtest.a -o $@ $(LDFLAGS)
./$@
config_parser_gcov: config_parser_test
gcov -r config_parser.cc > config_parser_gcov.txt
response_test: test_setup response.cc response_test.cc
g++ $(GCOVFLAGS) $(TESTFLAGS) response_test.cc response.cc ${GTEST_DIR}/src/gtest_main.cc libgtest.a -o $@ $(LDFLAGS)
./$@
response_gcov: response_test
gcov -r response.cc > response_gcov.txt
request_test: test_setup request.cc request_test.cc
g++ $(GCOVFLAGS) $(TESTFLAGS) request_test.cc request.cc ${GTEST_DIR}/src/gtest_main.cc libgtest.a -o $@ $(LDFLAGS)
./$@
request_gcov: request_test
gcov -r request.cc > request_gcov.txt
static_file_handler_test: test_setup static_file_handler.cc static_file_handler_test.cc
g++ $(GCOVFLAGS) $(TESTFLAGS) static_file_handler_test.cc static_file_handler.cc request.cc response.cc not_found_handler.cc request_handler.cc config_parser.cc cpp-markdown/markdown.cpp cpp-markdown/markdown-tokens.cpp ${GTEST_DIR}/src/gtest_main.cc libgtest.a -o $@ $(LDFLAGS)
./$@
static_file_handler_gcov: static_file_handler_test
gcov -r static_file_handler.cc > static_file_handler_gcov.txt
echo_handler_test: test_setup echo_handler.cc echo_handler_test.cc
g++ $(GCOVFLAGS) $(TESTFLAGS) echo_handler_test.cc echo_handler.cc request.cc response.cc request_handler.cc config_parser.cc ${GTEST_DIR}/src/gtest_main.cc libgtest.a -o $@ $(LDFLAGS)
./$@
echo_handler_gcov: echo_handler_test
gcov -r echo_handler.cc > echo_handler_gcov.txt
not_found_handler_test: test_setup not_found_handler.cc not_found_handler_test.cc
g++ $(GCOVFLAGS) $(TESTFLAGS) not_found_handler_test.cc not_found_handler.cc request.cc response.cc request_handler.cc config_parser.cc ${GTEST_DIR}/src/gtest_main.cc libgtest.a -o $@ $(LDFLAGS)
./$@
not_found_handler_gcov: not_found_handler_test
gcov -r not_found_handler.cc > not_found_handler_gcov.txt
server_config_parser_test: test_setup server_config_parser.cc server_config_parser_test.cc
g++ $(GCOVFLAGS) $(TESTFLAGS) server_config_parser_test.cc $(SRC) ${GTEST_DIR}/src/gtest_main.cc libgtest.a -o $@ $(LDFLAGS)
./$@
server_config_parser_gcov: server_config_parser_test
gcov -r server_config_parser.cc > server_config_parser_gcov.txt
reverse_proxy_handler_test: test_setup reverse_proxy_handler.cc reverse_proxy_handler_test.cc
g++ $(GCOVFLAGS) $(TESTFLAGS) reverse_proxy_handler_test.cc $(SRC) ${GTEST_DIR}/src/gtest_main.cc libgtest.a -o $@ $(LDFLAGS)
./$@
reverse_proxy_handler_gcov: reverse_proxy_handler_test
gcov -r reverse_proxy_handler.cc > reverse_proxy_handler_gcov.txt
docker:
rm -r -f deploy binary.tar
docker build -t httpserver.build .
docker run httpserver.build > binary.tar
mkdir deploy
cp $(DEPLOYFILES) deploy
cp -r sqlite-ffi deploy/sqlite-ffi
cp /lib/x86_64-linux-gnu/libgcc_s.so.1 deploy
tar -xvf binary.tar -C deploy/
cp Dockerfile.run deploy/Dockerfile
docker build -t httpserver deploy
deploy:
./deploy.sh