-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
138 lines (119 loc) · 3.82 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
all: bin/tester bin/server bin/client bin/driver bin/sql
# Define compile and link flags
-include config.local
CXX ?= g++
opt = -g3 -O0
#opt = -g0 -O3
cf = $(opt) -Wall -Wextra -Wuninitialized --std=c++0x -I./src -I. -I./libs/gtest/include -I./libs/zmq/include/ -I./libs/gflags/include/ -fPIC
lf = $(opt) --std=c++0x -ldl -lpthread
# Object director
objDir:= build/
build_dir = @mkdir -p $(dir $@)
# Fix for clang
ifeq (ccache clang,$(filter $(CXX),ccache clang))
cf += -Qunused-arguments -fcolor-diagnostics
lf += -libstd=libc++
endif
# Get source file names
src_files := $(patsubst src/%,build/src/%, $(patsubst %.cpp,%.o,$(wildcard src/*.cpp src/*/*.cpp src/*/*/*.cpp)))
test_files := $(patsubst test/%,build/test/%, $(patsubst %.cpp,%.o,$(wildcard test/*.cpp test/*/*.cpp test/*/*/*.cpp)))
# Build database
bin/database.so: libs src/query/parser/Parser.cpp $(src_files)
$(build_dir) bin/gen bin/var
$(CXX) -shared -o bin/database.so $(src_files) libs/zmq/libzmq.a $(lf)
# Build tester
bin/tester: libs bin/database.so $(test_files) build/test/tester.o
$(build_dir) bin/gen bin/var
$(CXX) -o bin/tester $(test_files) bin/database.so libs/gtest/libgtest.a $(lf)
# Build driver
bin/driver: libs bin/database.so build/driver.o
$(build_dir) bin/gen bin/var
$(CXX) -o bin/driver build/driver.o bin/database.so $(lf)
# Build sql
bin/sql: libs bin/database.so build/sql.o
$(build_dir) bin/gen bin/var
$(CXX) -o bin/sql build/sql.o bin/database.so $(lf)
# Build server
bin/server: libs bin/database.so build/server.o
$(build_dir) bin/gen bin/var
$(CXX) -o bin/server build/server.o bin/database.so libs/zmq/libzmq.a $(lf)
# Build client
bin/client: libs build/client.o
$(build_dir) bin/gen bin/var
$(CXX) -o bin/client build/client.o libs/zmq/libzmq.a $(lf)
# Ensure latest parser version
src/query/parser/Parser.cpp: src/query/parser/Parser.leg
./libs/greg-cpp/greg -o src/query/parser/Parser.cpp src/query/parser/Parser.leg
LIBS := libs/gtest libs/zmq libs/greg-cpp
libs: $(LIBS)
# Command for building and keeping track of changed files
$(objDir)%.o: %.cpp
$(build_dir)
$(CXX) -MD -c -o $@ $< $(cf)
@cp $(objDir)$*.d $(objDir)$*.P; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(objDir)$*.d >> $(objDir)$*.P; \
rm -f $(objDir)$*.d
-include $(objDir)*.P
-include $(objDir)*/*.P
-include $(objDir)*/*/*.P
-include $(objDir)*/*/*/*.P
# Build gtest library
libs/gtest:
$(build_dir)
cd libs/ ;\
git clone https://github.com/google/googletest.git;\
mv googletest gtest-1.7.0;\
cd gtest-1.7.0;\
git checkout release-1.7.0;\
mkdir -p build ;\
cd build ;\
cmake -G"Unix Makefiles" .. ;\
make ;\
ar -r libgtest.a libgtest_main.a
mkdir -p libs/gtest/include/gtest
mv libs/gtest-1.7.0/include/gtest/* libs/gtest/include/gtest
mv libs/gtest-1.7.0/build/libgtest.a libs/gtest/
rm -rf libs/gtest-1.7.0
# Build zmq
libs/zmq:
$(build_dir)
cd libs/ ;\
wget http://download.zeromq.org/zeromq-3.2.3.tar.gz ;\
tar -xf zeromq-3.2.3.tar.gz ;\
cd zeromq-3.2.3 ;\
./configure --enable-static --disable-shared --prefix ${PWD}/libs/zmq ;\
make -j4 ;\
make install ;\
cd .. ;\
rm zeromq-3.2.3.tar.gz ;\
rm -rf zeromq-3.2.3 ;\
rm -rf zmq/share ;\
mv zmq/lib/libzmq.a zmq/ ;\
rm -rf zmq/lib ;\
mkdir zmq/include/zmq ;\
mv zmq/include/*.h zmq/include/zmq/
# now get c++ header files for zmq
cd libs ;\
git clone https://github.com/zeromq/cppzmq.git ;\
mv cppzmq/zmq.hpp zmq/include/zmq/ ;\
ruby -pi -e 'gsub("#include <zmq.h>", "#include \"zmq.h\"")' zmq/include/zmq/zmq.hpp ;\
rm -rf cppzmqx
# Build greg
libs/greg-cpp:
$(build_dir)
cd libs/ ;\
git clone https://github.com/alexandervanrenen/greg-cpp.git ;\
cd greg-cpp ;\
make
# Clean up =)
clean:
rm -rf bin
rm -rf build
touch src/query/parser/Parser.cpp
# Clean up =)
clean-complete:
rm -rf bin
rm -rf build
rm -rf libs
rm -rf src/query/parser/Parser.cpp