1 # Quick-and-dirty makefile to bootstrap the sqlite3-jni project. This
2 # build assumes a Linux-like system.
5 JAVA_HOME ?
= $(HOME
)/jdk
/current
6 # e.g. /usr/lib/jvm/default-javajava-19-openjdk-amd64
7 JDK_HOME ?
= $(JAVA_HOME
)
8 # ^^^ JDK_HOME is not as widely used as JAVA_HOME
9 bin.jar
:= $(JDK_HOME
)/bin
/jar
10 bin.java
:= $(JDK_HOME
)/bin
/java
11 bin.javac
:= $(JDK_HOME
)/bin
/javac
12 bin.javadoc
:= $(JDK_HOME
)/bin
/javadoc
13 ifeq (,$(wildcard $(JDK_HOME
)))
14 $(error set JDK_HOME to the top-most
dir of your JDK installation.
)
16 MAKEFILE
:= $(lastword
$(MAKEFILE_LIST
))
19 package.jar
:= sqlite3-jni.jar
22 dir.tool
:= ..
/..
/tool
23 dir.jni
:= $(patsubst %/,%,$(dir $(MAKEFILE
)))
24 dir.src
:= $(dir.jni
)/src
25 dir.src.c
:= $(dir.src
)/c
26 dir.bld
:= $(dir.jni
)/bld
27 dir.bld.c
:= $(dir.bld
)
28 dir.src.jni
:= $(dir.src
)/org
/sqlite
/jni
29 dir.src.jni.tester
:= $(dir.src.jni
)/tester
34 classpath
:= $(dir.src
)
35 CLEAN_FILES
:= $(package.jar
)
36 DISTCLEAN_FILES
:= $(dir.jni
)/*~
$(dir.src.c
)/*~
$(dir.src.jni
)/*~
38 sqlite3-jni.h
:= $(dir.src.c
)/sqlite3-jni.h
39 .NOTPARALLEL
: $(sqlite3-jni.h
)
40 SQLite3Jni.java
:= src
/org
/sqlite
/jni
/SQLite3Jni.java
41 SQLTester.java
:= src
/org
/sqlite
/jni
/tester
/SQLTester.java
42 SQLite3Jni.class
:= $(SQLite3Jni.java
:.java
=.class
)
43 SQLTester.class
:= $(SQLTester.java
:.java
=.class
)
45 ########################################################################
46 # The future of FTS5 customization in this API is as yet unclear.
47 # It would be a real doozy to bind to JNI.
49 # If enable.tester is 0, the org/sqlite/jni/tester/* bits are elided.
52 # bin.version-info = binary to output various sqlite3 version info
53 # building the distribution zip file.
54 bin.version-info
:= $(dir.top
)/version-info
55 .NOTPARALLEL
: $(bin.version-info
)
56 $(bin.version-info
): $(dir.tool
)/version-info.c
$(sqlite3.h
) $(dir.top
)/Makefile
57 $(MAKE
) -C
$(dir.top
) version-info
59 # Be explicit about which Java files to compile so that we can work on
60 # in-progress files without requiring them to be in a compilable statae.
61 JAVA_FILES.main
:= $(patsubst %,$(dir.src.jni
)/%,\
64 CollationNeeded.java \
66 NativePointerHolder.java \
68 ProgressHandler.java \
73 sqlite3_context.java \
83 ifeq (1,$(enable.fts5
))
84 JAVA_FILES.main
+= $(patsubst %,$(dir.src.jni
)/%,\
86 fts5_extension_function.java \
90 Fts5ExtensionApi.java \
97 JAVA_FILES.tester
:= $(dir.src.jni.tester
)/SQLTester.java
99 CLASS_FILES.main
:= $(JAVA_FILES.main
:.java
=.class
)
100 CLASS_FILES.tester
:= $(JAVA_FILES.tester
:.java
=.class
)
102 JAVA_FILES
+= $(JAVA_FILES.main
)
103 ifeq (1,$(enable.tester
))
104 JAVA_FILES
+= $(JAVA_FILES.tester
)
109 $(1).class
: $(1).java
$(MAKEFILE
)
111 CLASS_FILES
+= $(1).class
113 $(foreach B
,$(basename $(JAVA_FILES
)),$(eval
$(call DOTCLASS_DEPS
,$(B
))))
114 $(CLASS_FILES.tester
): $(CLASS_FILES.main
)
115 javac.flags ?
= -Xlint
:unchecked
-Xlint
:deprecation
119 java.flags
+= -Xcheck
:jni
121 $(SQLite3Jni.class
): $(JAVA_FILES
)
122 $(bin.javac
) $(javac.flags
) -h
$(dir.bld.c
) -cp
$(classpath
) $(JAVA_FILES
)
123 all: $(SQLite3Jni.class
)
126 ########################################################################
127 # Set up sqlite3.c and sqlite3.h...
129 # To build with SEE (https://sqlite.org/see), either put sqlite3-see.c
130 # in the top of this build tree or pass
131 # sqlite3.c=PATH_TO_sqlite3-see.c to the build. Note that only
132 # encryption modules with no 3rd-party dependencies will currently
133 # work here: AES256-OFB, AES128-OFB, and AES128-CCM. Not
134 # coincidentally, those 3 modules are included in the sqlite3-see.c
137 # A custom sqlite3.c must not have any spaces in its name.
138 # $(sqlite3.canonical.c) must point to the sqlite3.c in
139 # the sqlite3 canonical source tree, as that source file
140 # is required for certain utility and test code.
141 sqlite3.canonical.c
:= $(firstword $(wildcard $(dir.src.c
)/sqlite3.c
) $(dir.top
)/sqlite3.c
)
142 sqlite3.canonical.h
:= $(firstword $(wildcard $(dir.src.c
)/sqlite3.h
) $(dir.top
)/sqlite3.h
)
143 sqlite3.c
:= $(sqlite3.canonical.c
)
144 sqlite3.h
:= $(sqlite3.canonical.h
)
145 #ifeq (,$(shell grep sqlite3_activate_see $(sqlite3.c) 2>/dev/null))
146 # SQLITE_C_IS_SEE := 0
148 # SQLITE_C_IS_SEE := 1
149 # $(info This is an SEE build.)
152 .NOTPARALLEL
: $(sqlite3.h
)
154 $(MAKE
) -C
$(dir.top
) sqlite3.c
155 $(sqlite3.c
): $(sqlite3.h
)
158 -DSQLITE_ENABLE_RTREE \
159 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
160 -DSQLITE_ENABLE_STMTVTAB \
161 -DSQLITE_ENABLE_DBPAGE_VTAB \
162 -DSQLITE_ENABLE_DBSTAT_VTAB \
163 -DSQLITE_ENABLE_BYTECODE_VTAB \
164 -DSQLITE_ENABLE_OFFSET_SQL_FUNC \
165 -DSQLITE_ENABLE_PREUPDATE_HOOK \
166 -DSQLITE_ENABLE_SQLLOG \
167 -DSQLITE_OMIT_LOAD_EXTENSION \
168 -DSQLITE_OMIT_DEPRECATED \
169 -DSQLITE_OMIT_SHARED_CACHE \
170 -DSQLITE_THREADSAFE
=1 \
171 -DSQLITE_TEMP_STORE
=2 \
173 -DSQLITE_C
=$(sqlite3.c
) \
176 SQLITE_OPT
+= -g
-DDEBUG
-UNDEBUG
178 ifeq (1,$(enable.fts5
))
179 SQLITE_OPT
+= -DSQLITE_ENABLE_FTS5
182 sqlite3-jni.c
:= $(dir.src.c
)/sqlite3-jni.c
183 sqlite3-jni.o
:= $(dir.bld.c
)/sqlite3-jni.o
184 sqlite3-jni.h
:= $(dir.src.c
)/sqlite3-jni.h
185 sqlite3-jni.dll
:= $(dir.bld.c
)/libsqlite3-jni.so
186 # All javac-generated .h files must be listed in $(sqlite3-jni.h.in):
189 sqlite3-jni.h.in
+= $$(dir.bld.c
)/org_sqlite_jni_
$(1).h
190 $$(dir.bld.c
)/org_sqlite_jni_
$(1).h
: $$(dir.src.jni
)/$(1).java
192 $(eval
$(call ADD_JNI_H
,SQLite3Jni
))
193 ifeq (1,$(enable.fts5
))
194 $(eval
$(call ADD_JNI_H
,Fts5ExtensionApi
))
195 $(eval
$(call ADD_JNI_H
,fts5_api
))
196 $(eval
$(call ADD_JNI_H
,fts5_tokenizer
))
198 ifeq (1,$(enable.tester
))
199 sqlite3-jni.h.in
+= $(dir.bld.c
)/org_sqlite_jni_tester_SQLTester.h
200 $(dir.bld.c
)/org_sqlite_jni_tester_SQLTester.h
: $(dir.src.jni.tester
)/SQLTester.java
202 #sqlite3-jni.dll.cfiles := $(dir.src.c)
203 sqlite3-jni.dll.
cflags = \
206 -I
$(dir $(sqlite3.h
)) \
208 -I
$(JDK_HOME
)/include \
209 $(patsubst %,-I
%,$(patsubst %.h
,,$(wildcard $(JDK_HOME
)/include/*))) \
211 # Using (-Wall -Wextra) triggers an untennable number of
212 # gcc warnings from sqlite3.c for mundane things like
215 # The gross $(patsubst...) above is to include the platform-specific
216 # subdir which lives under $(JDK_HOME)/include and is a required
217 # include path for client-level code.
218 ########################################################################
219 ifeq (1,$(enable.tester
))
220 sqlite3-jni.dll.
cflags += -DS3JNI_ENABLE_SQLTester
222 $(sqlite3-jni.h
): $(sqlite3-jni.h.in
) $(MAKEFILE
)
223 cat
$(sqlite3-jni.h.in
) > $@
224 $(sqlite3-jni.dll
): $(sqlite3-jni.h
) $(sqlite3.c
) $(sqlite3.h
)
225 $(sqlite3-jni.dll
): $(dir.bld.c
) $(sqlite3-jni.c
) $(SQLite3Jni.java
) $(MAKEFILE
)
226 $(CC
) $(sqlite3-jni.dll.
cflags) $(SQLITE_OPT
) \
227 $(sqlite3-jni.c
) -shared
-o
$@
228 all: $(sqlite3-jni.dll
)
230 .PHONY
: test test-one
232 test.main.flags
= -ea
-Djava.library.path
=$(dir.bld.c
) \
233 $(java.flags
) -cp
$(classpath
) \
234 org.sqlite.jni.Tester1
235 test-one
: $(SQLite3Jni.class
) $(sqlite3-jni.dll
)
236 $(bin.java
) $(test.main.flags
) $(test.flags
)
238 @echo
"Again in multi-threaded mode:";
239 $(bin.java
) $(test.main.flags
) -t
5 -r
20 -shuffle
$(test.flags
)
241 tester.scripts
:= $(sort $(wildcard $(dir.src
)/tests
/*.
test))
242 tester.flags ?
= # --verbose
243 .PHONY
: tester tester-local tester-ext
244 ifeq (1,$(enable.tester
))
245 tester-local
: $(CLASS_FILES.tester
) $(sqlite3-jni.dll
)
246 $(bin.java
) -ea
-Djava.library.path
=$(dir.bld.c
) \
247 $(java.flags
) -cp
$(classpath
) \
248 org.sqlite.jni.tester.SQLTester
$(tester.flags
) $(tester.scripts
)
252 @echo
"SQLTester support is disabled. Build with enable.tester=1 to enable it."
255 tester.extdir.default
:= src
/tests
/ext
256 tester.extdir ?
= $(tester.extdir.default
)
257 tester.extern-scripts
:= $(wildcard $(tester.extdir
)/*.
test)
258 ifneq (,$(tester.extern-scripts
))
260 $(bin.java
) -ea
-Djava.library.path
=$(dir.bld.c
) \
261 $(java.flags
) -cp
$(classpath
) \
262 org.sqlite.jni.tester.SQLTester
$(tester.flags
) $(tester.extern-scripts
)
265 @echo
"******************************************************"; \
266 echo
"*** Include the out-of-tree test suite in the 'tester'"; \
267 echo
"*** target by either symlinking its directory to"; \
268 echo
"*** $(tester.extdir.default) or passing it to make"; \
269 echo
"*** as tester.extdir=/path/to/that/dir."; \
270 echo
"******************************************************";
273 tester-ext
: tester-local
276 package.jar.in
:= $(abspath
$(dir.src
)/jar.in
)
277 CLEAN_FILES
+= $(package.jar.in
)
278 $(package.jar.in
): $(MAKEFILE
) $(CLASS_FILES.main
)
279 cd
$(dir.src
); ls
-1 org
/sqlite
/jni
/*.java org
/sqlite
/jni
/*.class
> $@
280 @echo
"To use this jar you will need the -Djava.library.path=DIR/CONTAINING/libsqlite3-jni.so flag."
281 @echo
"e.g. java -jar $@ -Djava.library.path=bld"
283 $(package.jar
): $(CLASS_FILES
) $(MAKEFILE
) $(package.jar.in
)
284 rm -f
$(dir.src
)/c
/*~
$(dir.src.jni
)/*~
285 cd
$(dir.src
); $(bin.jar
) -cfe ..
/$@ org.sqlite.jni.Tester1 @
$(package.jar.in
)
289 dir.doc
:= $(dir.jni
)/doc
290 doc
: $(JAVA_FILES.main
)
291 $(bin.javadoc
) -cp
$(classpath
) -d
$(dir.doc
) -quiet org.sqlite.jni
293 ########################################################################
295 CLEAN_FILES
+= $(dir.bld.c
)/* \
296 $(dir.src.jni
)/*.class \
297 $(dir.src.jni.tester
)/*.class \
301 .PHONY
: clean distclean
303 -rm -f
$(CLEAN_FILES
)
305 -rm -f
$(DISTCLEAN_FILES
)
308 ########################################################################
309 # disttribution bundle rules...
311 ifeq (,$(filter snapshot
,$(MAKECMDGOALS
)))
312 dist-name-prefix
:= sqlite-jni
314 dist-name-prefix
:= sqlite-jni-snapshot-
$(shell /usr
/bin
/date
+%Y
%m
%d
)
316 dist-name
:= $(dist-name-prefix
)-TEMP
319 dist-dir.top
:= $(dist-name
)
320 dist-dir.src
:= $(dist-dir.top
)/src
324 .PHONY
: dist snapshot
327 $(bin.version-info
) $(sqlite3.canonical.c
) \
328 $(package.jar
) $(MAKEFILE
)
329 @echo
"Making end-user deliverables..."
330 @echo
"****************************************************************************"; \
331 echo
"*** WARNING: be sure to build this with JDK8 (javac 1.8) for compatibility."; \
332 echo
"*** reasons!"; $$($(bin.javac
) -version
); \
333 echo
"****************************************************************************"
334 @
rm -fr
$(dist-dir.top
)
335 @mkdir
-p
$(dist-dir.src
)
336 @cp
-p
$(dist.top.extras
) $(dist-dir.top
)/.
337 @cp
-p jar-dist.make
$(dist-dir.top
)/Makefile
338 @cp
-p
$(dir.src.c
)/*.
[ch
] $(dist-dir.src
)/.
339 @cp
-p
$(sqlite3.canonical.c
) $(sqlite3.canonical.h
) $(dist-dir.src
)/.
341 vnum
=$$($(bin.version-info
) --download-version
); \
342 vjar
=$$($(bin.version-info
) --version
); \
343 vdir
=$(dist-name-prefix
)-$$vnum; \
345 cp
-p
$(package.jar
) $(dist-dir.top
)/sqlite3-jni-
$${vjar}.jar
; \
346 echo
"Making $$arczip ..."; \
347 rm -fr
$$arczip $$vdir; \
348 mv
$(dist-dir.top
) $$vdir; \
349 zip
-qr
$$arczip $$vdir; \
353 unzip
-lv
$$arczip || echo
"Missing unzip app? Not fatal."
360 rm -fr
$(dist-name
) $(wildcard sqlite-jni-
*.zip
)