-
Notifications
You must be signed in to change notification settings - Fork 35
/
makefile
200 lines (177 loc) · 6.22 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
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
# The SONAME sets the api version compatibility.
# It is using the same SONAME from the pre-installed sqlite3 library so
# the library can be loaded by existing applications as python. For this
# we can set the LD_LIBRARY_PATH when opening the app or set the rpath
# in the executable.
LIBFLAGS = -Wall -I$(LMDBINCPATH) $(CFLAGS)
LDFLAGS = $(LFLAGS) -L$(LMDBPATH) -llmdb
ifeq ($(OS),Windows_NT)
IMPLIB = litetree-0.1
LIBRARY = litetree-0.1.dll
LMDBPATH = ../lmdb/libraries/liblmdb
LMDBINCPATH = $(LMDBPATH)
#LIBFLAGS += $(LMDBPATH)mdb.c $(LMDBPATH)midl.c
LDFLAGS += -static-libgcc -static-libstdc++
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
OS = OSX
LIBRARY = liblitetree.0.dylib
LIBNICK1 = liblitetree.dylib
LIBNICK2 = libsqlite3.0.dylib
LIBNICK3 = libsqlite3.dylib
INSTNAME = $(LIBPATH2)/libsqlite3.dylib
CURR_VERSION = 1.0.0
COMPAT_VERSION = 1.0.0
else
LIBRARY = liblitetree.so.0.0.1
LIBNICK1 = liblitetree.so.0
LIBNICK2 = liblitetree.so
LIBNICK3 = libsqlite3.so.0
LIBNICK4 = libsqlite3.so
SONAME = libsqlite3.so.0
endif
LMDBPATH = /usr/local/lib
LMDBINCPATH = /usr/local/include
prefix ?= /usr/local
LIBPATH = $(prefix)/lib
LIBPATH2 = $(prefix)/lib/litetree
INCPATH = $(prefix)/include
EXEPATH = $(prefix)/bin
LIBFLAGS += -fPIC
LDFLAGS += -lpthread
SHELLFLAGS = -DHAVE_READLINE
endif
CC = gcc
SHORT = sqlite3
# the item below cannot be called SHELL because it's a reserved name
ifeq ($(OS),Windows_NT)
SSHELL = sqlite3.exe
else
SSHELL = sqlite3
endif
#LIBFLAGS = -Wall -DSQLITE_USE_URI=1 -DSQLITE_ENABLE_JSON1 -DSQLITE_THREADSAFE=1 -DHAVE_USLEEP -DSQLITE_ENABLE_COLUMN_METADATA
LIBFLAGS := $(LIBFLAGS) -DSQLITE_USE_URI=1 -DSQLITE_ENABLE_JSON1 -DSQLITE_THREADSAFE=1 -DHAVE_USLEEP -DSQLITE_ENABLE_COLUMN_METADATA
.PHONY: install debug test benchmark clean
all: $(LIBRARY) $(SSHELL)
debug: $(LIBRARY) $(SSHELL)
debug: export LIBFLAGS := -g -DSQLITE_DEBUG=1 -DDEBUGPRINT $(LIBFLAGS)
litetree-0.1.dll: $(SHORT).o
$(CC) -shared -Wl,--out-implib,$(IMPLIB).lib $^ -o $@ $(LDFLAGS)
strip $(LIBRARY)
liblitetree.0.dylib: $(SHORT).o
$(CC) -dynamiclib -install_name "$(INSTNAME)" -current_version $(CURR_VERSION) -compatibility_version $(COMPAT_VERSION) $^ -o $@ $(LDFLAGS)
strip -x $(LIBRARY)
install_name_tool -change liblmdb.so $(LMDBPATH)/liblmdb.so $@
ln -sf $(LIBRARY) $(LIBNICK1)
ln -sf $(LIBRARY) $(LIBNICK2)
ln -sf $(LIBRARY) $(LIBNICK3)
liblitetree.so.0.0.1: $(SHORT).o
$(CC) -shared -Wl,-soname,$(SONAME) -Wl,-rpath,$(LMDBPATH) $^ -o $@ $(LDFLAGS)
strip $(LIBRARY)
ln -sf $(LIBRARY) $(LIBNICK1)
ln -sf $(LIBNICK1) $(LIBNICK2)
ln -sf $(LIBRARY) $(LIBNICK3)
ln -sf $(LIBNICK3) $(LIBNICK4)
$(SHORT).o: $(SHORT).c $(SHORT).h
$(CC) $(LIBFLAGS) -c $< -o $@
$(SSHELL): shell.o $(LIBRARY)
ifeq ($(OS),Windows_NT)
$(CC) $< -o $@ -L. -l$(IMPLIB)
else ifeq ($(OS),OSX)
$(CC) $< -o $@ -L. -lsqlite3 -ldl -lreadline
else
$(CC) $< -o $@ -Wl,-rpath,$(LIBPATH) -L. -lsqlite3 -ldl -lreadline
endif
strip $(SSHELL)
shell.o: shell.c
$(CC) -c $(SHELLFLAGS) $< -o $@
install:
mkdir -p $(LIBPATH)
mkdir -p $(LIBPATH2)
cp $(LIBRARY) $(LIBPATH)/
cd $(LIBPATH) && ln -sf $(LIBRARY) $(LIBNICK1)
ifeq ($(OS),OSX)
cd $(LIBPATH2) && ln -sf ../$(LIBNICK1) $(LIBNICK2)
cd $(LIBPATH2) && ln -sf $(LIBNICK2) $(LIBNICK3)
else
cd $(LIBPATH) && ln -sf $(LIBNICK1) $(LIBNICK2)
cd $(LIBPATH2) && ln -sf ../$(LIBRARY) $(LIBNICK3)
cd $(LIBPATH2) && ln -sf $(LIBNICK3) $(LIBNICK4)
endif
cp $(SHORT).h $(INCPATH)
cp $(SSHELL) $(EXEPATH)
clean:
rm -f *.o $(LIBRARY) $(LIBNICK1) $(LIBNICK2) $(LIBNICK3) $(LIBNICK4) $(SSHELL)
test: test/test.py test/test-64bit-commit-ids.py test/varint.py
ifeq ($(OS),Windows_NT)
ifeq ($(PY_HOME),)
@echo "PY_HOME is not set"
else
cd $(PY_HOME)/DLLs && [ ! -f sqlite3-orig.dll ] && mv sqlite3.dll sqlite3-orig.dll || true
cp litetree-0.1.dll $(PY_HOME)/DLLs/sqlite3.dll
cp $(LMDBPATH)/lmdb.dll $(PY_HOME)/DLLs/lmdb.dll
cd test && python -mpip install lmdb
cd test && python test.py -v
cd test && python test-64bit-commit-ids.py -v
endif
else # not Windows
ifneq ($(shell python -c "import lmdb" 2> /dev/null; echo $$?),0)
sudo python -m easy_install cffi
cd test && sudo python -m easy_install lmdb
ifneq ($(shell python -c "import lmdb" 2> /dev/null; echo $$?),0)
git clone --depth=1 https://github.com/dw/py-lmdb
cd py-lmdb && sudo LMDB_FORCE_CPYTHON=1 python setup.py install
ifneq ($(shell python -c "import lmdb" 2> /dev/null; echo $$?),0)
sudo python -c "import cffi"
sudo python -c "import lmdb"
endif
endif
endif
ifeq ($(OS),OSX)
ifneq ($(shell python -c "import pysqlite2.dbapi2" 2> /dev/null; echo $$?),0)
ifneq ($(shell [ -d $(LIBPATH2) ]; echo $$?),0)
@echo "run 'sudo make install' first"
endif
git clone --depth=1 https://github.com/ghaering/pysqlite
cd pysqlite && echo "include_dirs=$(INCPATH)" >> setup.cfg
cd pysqlite && echo "library_dirs=$(LIBPATH2)" >> setup.cfg
cd pysqlite && python setup.py build
cd pysqlite && sudo python setup.py install
endif
cd test && python test.py -v
cd test && python test-64bit-commit-ids.py -v
else # Linux
cd test && LD_LIBRARY_PATH=.. python test.py -v
cd test && LD_LIBRARY_PATH=.. python test-64bit-commit-ids.py -v
endif
endif
benchmark: test/benchmark.py
ifeq ($(OS),Windows_NT)
ifeq ($(PY_HOME),)
@echo "PY_HOME is not set"
else
cd $(PY_HOME)/DLLs && [ ! -f sqlite3-orig.dll ] && mv sqlite3.dll sqlite3-orig.dll || true
cp litetree-0.1.dll $(PY_HOME)/DLLs/sqlite3.dll
cp $(LMDBPATH)/lmdb.dll $(PY_HOME)/DLLs/lmdb.dll
cd test && python benchmark.py -v
endif
else ifeq ($(OS),OSX)
ifneq ($(shell python -c "import pysqlite2.dbapi2" 2> /dev/null; echo $$?),0)
ifneq ($(shell [ -d $(LIBPATH2) ]; echo $$?),0)
@echo "run 'sudo make install' first"
endif
git clone --depth=1 https://github.com/ghaering/pysqlite
cd pysqlite && echo "include_dirs=$(INCPATH)" >> setup.cfg
cd pysqlite && echo "library_dirs=$(LIBPATH2)" >> setup.cfg
cd pysqlite && python setup.py build
cd pysqlite && sudo python setup.py install
endif
cd test && python benchmark.py -v
else
cd test && LD_LIBRARY_PATH=.. python benchmark.py -v
endif
# variables:
# $@ output
# $^ all the requirements
# $< first requirement