Do not pre-allocate sqlite3_aggregate_context() for Java UDFs, as it unduly complicat...
[sqlite.git] / ext / jni / GNUmakefile
blobc4fa4b5c06a253629a007bee5790b43c53f957c0
1 # Quick-and-dirty makefile to bootstrap the sqlite3-jni project. This
2 # build assumes a Linux-like system.
3 default: all
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.)
15 endif
16 MAKEFILE := $(lastword $(MAKEFILE_LIST))
17 $(MAKEFILE):
19 package.jar := sqlite3-jni.jar
21 dir.top := ../..
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
30 mkdir := mkdir -p
31 $(dir.bld.c):
32 $(mkdir) $@
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.
48 enable.fts5 ?= 1
49 # If enable.tester is 0, the org/sqlite/jni/tester/* bits are elided.
50 enable.tester ?= 1
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)/%,\
62 BusyHandler.java \
63 Collation.java \
64 CollationNeeded.java \
65 CommitHook.java \
66 NativePointerHolder.java \
67 OutputPointer.java \
68 ProgressHandler.java \
69 ResultCode.java \
70 RollbackHook.java \
71 SQLFunction.java \
72 SQLLog.java \
73 sqlite3_context.java \
74 sqlite3.java \
75 SQLite3Jni.java \
76 sqlite3_stmt.java \
77 sqlite3_value.java \
78 Tester1.java \
79 Tracer.java \
80 UpdateHook.java \
81 ValueHolder.java \
83 ifeq (1,$(enable.fts5))
84 JAVA_FILES.main += $(patsubst %,$(dir.src.jni)/%,\
85 fts5_api.java \
86 fts5_extension_function.java \
87 fts5_tokenizer.java \
88 Fts5.java \
89 Fts5Context.java \
90 Fts5ExtensionApi.java \
91 Fts5Function.java \
92 Fts5PhraseIter.java \
93 Fts5Tokenizer.java \
94 TesterFts5.java \
96 endif
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)
105 endif
107 CLASS_FILES :=
108 define DOTCLASS_DEPS
109 $(1).class: $(1).java $(MAKEFILE)
110 all: $(1).class
111 CLASS_FILES += $(1).class
112 endef
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
116 java.flags ?=
117 jnicheck ?= 1
118 ifeq (1,$(jnicheck))
119 java.flags += -Xcheck:jni
120 endif
121 $(SQLite3Jni.class): $(JAVA_FILES)
122 $(bin.javac) $(javac.flags) -h $(dir.bld.c) -cp $(classpath) $(JAVA_FILES)
123 all: $(SQLite3Jni.class)
124 #.PHONY: classfiles
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
135 # bundle.
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
147 #else
148 # SQLITE_C_IS_SEE := 1
149 # $(info This is an SEE build.)
150 #endif
152 .NOTPARALLEL: $(sqlite3.h)
153 $(sqlite3.h):
154 $(MAKE) -C $(dir.top) sqlite3.c
155 $(sqlite3.c): $(sqlite3.h)
157 SQLITE_OPT = \
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 \
172 -DSQLITE_USE_URI=1 \
173 -DSQLITE_C=$(sqlite3.c) \
174 -DSQLITE_DEBUG
176 SQLITE_OPT += -g -DDEBUG -UNDEBUG
178 ifeq (1,$(enable.fts5))
179 SQLITE_OPT += -DSQLITE_ENABLE_FTS5
180 endif
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):
187 sqlite3-jni.h.in :=
188 define ADD_JNI_H
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
191 endef
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))
197 endif
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
201 endif
202 #sqlite3-jni.dll.cfiles := $(dir.src.c)
203 sqlite3-jni.dll.cflags = \
204 -fPIC \
205 -I. \
206 -I$(dir $(sqlite3.h)) \
207 -I$(dir.src.c) \
208 -I$(JDK_HOME)/include \
209 $(patsubst %,-I%,$(patsubst %.h,,$(wildcard $(JDK_HOME)/include/*))) \
210 -Wall
211 # Using (-Wall -Wextra) triggers an untennable number of
212 # gcc warnings from sqlite3.c for mundane things like
213 # unused parameters.
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
221 endif
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
231 test.flags ?=
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)
237 test: test-one
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)
249 tester: tester-local
250 else
251 tester:
252 @echo "SQLTester support is disabled. Build with enable.tester=1 to enable it."
253 endif
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))
259 tester-ext:
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)
263 else
264 tester-ext:
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 "******************************************************";
271 endif
273 tester-ext: tester-local
274 tester: tester-ext
275 tests: test tester
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)
287 jar: $(package.jar)
289 dir.doc := $(dir.jni)/doc
290 doc: $(JAVA_FILES.main)
291 $(bin.javadoc) -cp $(classpath) -d $(dir.doc) -quiet org.sqlite.jni
293 ########################################################################
294 # Clean up...
295 CLEAN_FILES += $(dir.bld.c)/* \
296 $(dir.src.jni)/*.class \
297 $(dir.src.jni.tester)/*.class \
298 $(sqlite3-jni.dll) \
299 hs_err_pid*.log
301 .PHONY: clean distclean
302 clean:
303 -rm -f $(CLEAN_FILES)
304 distclean: clean
305 -rm -f $(DISTCLEAN_FILES)
306 -rm -fr $(dir.bld.c)
308 ########################################################################
309 # disttribution bundle rules...
311 ifeq (,$(filter snapshot,$(MAKECMDGOALS)))
312 dist-name-prefix := sqlite-jni
313 else
314 dist-name-prefix := sqlite-jni-snapshot-$(shell /usr/bin/date +%Y%m%d)
315 endif
316 dist-name := $(dist-name-prefix)-TEMP
319 dist-dir.top := $(dist-name)
320 dist-dir.src := $(dist-dir.top)/src
321 dist.top.extras := \
322 README.md
324 .PHONY: dist snapshot
326 dist: \
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)/.
340 @set -e; \
341 vnum=$$($(bin.version-info) --download-version); \
342 vjar=$$($(bin.version-info) --version); \
343 vdir=$(dist-name-prefix)-$$vnum; \
344 arczip=$$vdir.zip; \
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; \
350 rm -fr $$vdir; \
351 ls -la $$arczip; \
352 set +e; \
353 unzip -lv $$arczip || echo "Missing unzip app? Not fatal."
355 snapshot: dist
357 .PHONY: dist-clean
358 clean: dist-clean
359 dist-clean:
360 rm -fr $(dist-name) $(wildcard sqlite-jni-*.zip)