xref: /sqlite-3.40.0/ext/wasm/GNUmakefile (revision b5e2e6fc)
1########################################################################
2# This GNU makefile drives the build of the sqlite3 WASM
3# components. It is not part of the canonical build process.
4#
5# This build assumes a Linux platform and is not intended for
6# client-level use. It is for the sqlite project's own development of
7# the JS/WASM components.
8#
9# Primary targets:
10#
11#  default, all = build in dev mode
12#
13#  o0, o1, o2, o3, os, oz = full clean/rebuild with the -Ox level indicated
14#      by the target name. Rebuild is necessary for all components to get
15#      the desired optimization level.
16#
17#  dist = create end user deliverables. Add dist-opt=oX to build with a
18#      specific optimization level, where oX is one of the above-listed
19#      o? target names.
20#
21#  clean = clean up
22########################################################################
23SHELL := $(shell which bash 2>/dev/null)
24MAKEFILE := $(lastword $(MAKEFILE_LIST))
25default: all
26release: default
27
28# Emscripten SDK home dir and related binaries...
29EMSDK_HOME ?= $(word 1,$(wildcard $(HOME)/src/emsdk $(HOME)/emsdk))
30emcc.bin ?= $(word 1,$(wildcard $(shell which emcc) $(EMSDK_HOME)/upstream/emscripten/emcc))
31ifeq (,$(emcc.bin))
32  $(error Cannot find emcc.)
33endif
34
35wasm-strip ?= $(shell which wasm-strip 2>/dev/null)
36ifeq (,$(filter clean,$(MAKECMDGOALS)))
37ifeq (,$(wasm-strip))
38  $(info WARNING: *******************************************************************)
39  $(info WARNING: builds using -O2/-O3/-Os/-Oz will minify WASM-exported names,)
40  $(info WARNING: breaking _All The Things_. The workaround for that is to build)
41  $(info WARNING: with -g3 (which explodes the file size) and then strip the debug)
42  $(info WARNING: info after compilation, using wasm-strip, to shrink the wasm file.)
43  $(info WARNING: wasm-strip was not found in the PATH so we cannot strip those.)
44  $(info WARNING: If this build uses any optimization level higher than -O1 then)
45  $(info WARNING: the ***resulting WASM binary WILL NOT BE USABLE***.)
46  $(info WARNING: wasm-strip is part of the wabt package:)
47  $(info WARNING:    https://github.com/WebAssembly/wabt)
48  $(info WARNING: on Ubuntu-like systems it can be installed with:)
49  $(info WARNING:    sudo apt install wabt)
50  $(info WARNING: *******************************************************************)
51endif
52endif # 'make clean' check
53
54ifeq (,$(wasm-strip))
55  maybe-wasm-strip = echo "not wasm-stripping"
56else
57  maybe-wasm-strip = $(wasm-strip)
58endif
59
60dir.top := ../..
61# Reminder: some Emscripten flags require absolute paths
62dir.wasm := $(patsubst %/,%,$(dir $(abspath $(MAKEFILE))))
63dir.api := api
64dir.jacc := jaccwabyt
65dir.common := common
66dir.fiddle := fiddle
67dir.tool := $(dir.top)/tool
68CLEAN_FILES := *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~
69DISTCLEAN_FILES := ./-dummy
70emcc_enable_bigint ?= 1
71sqlite3.c := $(dir.top)/sqlite3.c
72sqlite3.h := $(dir.top)/sqlite3.h
73SQLITE_OPT = \
74  -DSQLITE_ENABLE_FTS4 \
75  -DSQLITE_ENABLE_RTREE \
76  -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
77  -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION \
78  -DSQLITE_ENABLE_STMTVTAB \
79  -DSQLITE_ENABLE_DBPAGE_VTAB \
80  -DSQLITE_ENABLE_DBSTAT_VTAB \
81  -DSQLITE_ENABLE_BYTECODE_VTAB \
82  -DSQLITE_ENABLE_OFFSET_SQL_FUNC \
83  -DSQLITE_OMIT_LOAD_EXTENSION \
84  -DSQLITE_OMIT_DEPRECATED \
85  -DSQLITE_OMIT_UTF16 \
86  -DSQLITE_OMIT_SHARED_CACHE \
87  -DSQLITE_OMIT_WAL \
88  -DSQLITE_THREADSAFE=0 \
89  -DSQLITE_TEMP_STORE=3 \
90  -DSQLITE_OS_KV_OPTIONAL=1 \
91  '-DSQLITE_DEFAULT_UNIX_VFS="unix-none"' \
92  -DSQLITE_USE_URI=1 \
93  -DSQLITE_WASM_ENABLE_C_TESTS
94# ^^^ most flags are set in sqlite3-wasm.c but we need them
95# made explicit here for building speedtest1.c.
96
97ifneq (,$(filter release,$(MAKECMDGOALS)))
98emcc_opt ?= -Oz -flto
99else
100emcc_opt ?= -O0
101# ^^^^ build times for -O levels higher than 0 are painful at
102# dev-time.
103endif
104# When passing emcc_opt from the CLI, += and re-assignment have no
105# effect, so emcc_opt+=-g3 doesn't work. So...
106emcc_opt_full := $(emcc_opt) -g3
107# ^^^ ALWAYS use -g3. See below for why.
108#
109# ^^^ -flto improves runtime speed at -O0 considerably but doubles
110# build time.
111#
112# ^^^^ -O3, -Oz, -Os minify symbol names and there appears to be no
113# way around that except to use -g3, but -g3 causes the binary file
114# size to absolutely explode (approx. 5x larger). This minification
115# utterly breaks the resulting module, making it unsable except as
116# self-contained/self-referential-only code, as ALL of the exported
117# symbols get minified names.
118#
119# However, we have an option for using -Oz or -Os:
120#
121# Build with (-Os -g3) or (-Oz -g3) then use wasm-strip, from the wabt
122# tools package (https://github.com/WebAssembly/wabt), to strip the
123# debugging symbols. That results in a small build with unmangled
124# symbol names. -Oz gives ever-so-slightly better compression than
125# -Os: not quite 1% in some completely unscientific tests. Runtime
126# speed for the unit tests is all over the place either way so it's
127# difficult to say whether -Os gives any speed benefit over -Oz.
128#
129# (Much later: -O2 consistently gives the best speeds.)
130########################################################################
131
132
133$(sqlite3.c) $(sqlite3.h):
134	$(MAKE) -C $(dir.top) sqlite3.c
135
136.PHONY: clean distclean
137clean:
138	-rm -f $(CLEAN_FILES)
139distclean: clean
140	-rm -f $(DISTCLEAN_FILES)
141
142ifeq (release,$(filter release,$(MAKECMDGOALS)))
143  ifeq (,$(wasm-strip))
144    $(error Cannot make release-quality binary because wasm-strip is not available. \
145            See notes in the warning above)
146  endif
147else
148  $(info Development build. Use '$(MAKE) release' for a smaller release build.)
149endif
150
151version-info := $(dir.wasm)/version-info
152$(version-info): $(dir.wasm)/version-info.c $(sqlite3.h) $(MAKEFILE)
153	$(CC) -O0 -I$(dir.top) -o $@ $<
154DISTCLEAN_FILES += $(version-info)
155
156stripccomments := $(dir.tool)/stripccomments
157$(stripccomments): $(stripccomments).c $(MAKEFILE)
158	$(CC) -o $@ $<
159DISTCLEAN_FILES += $(stripccomments)
160
161EXPORTED_FUNCTIONS.api.in := $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api
162
163EXPORTED_FUNCTIONS.api: $(EXPORTED_FUNCTIONS.api.in) $(MAKEFILE)
164	cat $(EXPORTED_FUNCTIONS.api.in) > $@
165CLEAN_FILES += EXPORTED_FUNCTIONS.api
166
167sqlite3-license-version.js := sqlite3-license-version.js
168sqlite3-license-version-header.js := $(dir.api)/sqlite3-license-version-header.js
169sqlite3-api-build-version.js := $(dir.api)/sqlite3-api-build-version.js
170sqlite3-api.jses := $(sqlite3-license-version.js)
171sqlite3-api.jses += $(dir.api)/sqlite3-api-prologue.js
172sqlite3-api.jses += $(dir.common)/whwasmutil.js
173sqlite3-api.jses += $(dir.jacc)/jaccwabyt.js
174sqlite3-api.jses += $(dir.api)/sqlite3-api-glue.js
175sqlite3-api.jses += $(sqlite3-api-build-version.js)
176sqlite3-api.jses += $(dir.api)/sqlite3-api-oo1.js
177sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.js
178sqlite3-api.jses += $(dir.api)/sqlite3-api-opfs.js
179sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js
180
181sqlite3-api.js := sqlite3-api.js
182CLEAN_FILES += $(sqlite3-api.js)
183CLEAN_FILES += $(sqlite3-license-version.js)
184CLEAN_FILES += $(sqlite3-api-build-version.js)
185$(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE)
186	@echo "Making $@..."
187	@for i in $(sqlite3-api.jses); do \
188		echo "/* BEGIN FILE: $$i */"; \
189		cat $$i; \
190		echo "/* END FILE: $$i */"; \
191	done > $@
192
193$(sqlite3-api-build-version.js): $(version-info)
194	@echo "Making $@..."
195	@{ \
196  echo 'self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){'; \
197	echo -n '  sqlite3.version = '; \
198  $(version-info) --json; \
199  echo ';'; \
200	echo '});'; \
201  } > $@
202
203########################################################################
204# --post-js and --pre-js are emcc flags we use to append/prepend JS to
205# the generated emscripten module file.
206pre-js.js := $(dir.api)/pre-js.js
207post-js.js := post-js.js
208CLEAN_FILES += $(post-js.js)
209post-jses := \
210  $(dir.api)/post-js-header.js \
211  $(sqlite3-api.js) \
212  $(dir.api)/post-js-footer.js
213$(post-js.js): $(post-jses) $(MAKEFILE)
214	@echo "Making $@..."
215	@for i in $(post-jses); do \
216		echo "/* BEGIN FILE: $$i */"; \
217		cat $$i; \
218		echo "/* END FILE: $$i */"; \
219	done > $@
220extern-post-js.js := $(dir.api)/extern-post-js.js
221extern-pre-js.js := $(dir.api)/extern-pre-js.js
222pre-post-common.flags := \
223  --post-js=$(post-js.js) \
224  --extern-post-js=$(extern-post-js.js) \
225  --extern-pre-js=$(dir.wasm)/$(sqlite3-license-version.js)
226pre-post-jses.deps := $(post-js.js) \
227  $(extern-post-js.js) $(extern-pre-js.js) $(sqlite3-license-version.js)
228$(sqlite3-license-version.js): $(sqlite3.h) $(sqlite3-license-version-header.js) $(MAKEFILE)
229	@echo "Making $@..."; { \
230    cat $(sqlite3-license-version-header.js); \
231    echo '/*'; \
232    echo '** This code was built from sqlite3 version...'; \
233    echo "** "; \
234    awk -e '/define SQLITE_VERSION/{$$1=""; print "**" $$0}' \
235        -e '/define SQLITE_SOURCE_ID/{$$1=""; print "**" $$0}' $(sqlite3.h); \
236    echo '*/'; \
237   } > $@
238
239########################################################################
240# call-make-pre-js creates rules for pre-js-$(1).js. $1 = the base
241# name of the JS file on whose behalf this pre-js is for.
242define call-make-pre-js
243pre-post-$(1).flags ?=
244pre-js-$(1).js: $$(pre-js.js) $$(MAKEFILE)
245	cp $$(pre-js.js) $$@
246	echo "Module[xInstantiateWasm].uri = '$(1).wasm';" >> $$@
247CLEAN_FILES += pre-js-$(1).js
248pre-post-$(1).deps := $$(pre-post-jses.deps) pre-js-$(1).js
249pre-post-$(1).flags += --pre-js=pre-js-$(1).js
250endef
251#$(error $(call call-make-pre-js,sqlite3-wasmfs))
252# /post-js and pre-js
253########################################################################
254
255########################################################################
256# emcc flags for .c/.o/.wasm/.js.
257emcc.flags =
258#emcc.flags += -v # _very_ loud but also informative about what it's doing
259# -g is needed to keep -O2 and higher from creating broken JS via
260# minification.
261
262########################################################################
263# emcc flags for .c/.o.
264emcc.cflags :=
265emcc.cflags += -std=c99 -fPIC
266# -------------^^^^^^^^ we currently need c99 for WASM-specific sqlite3 APIs.
267emcc.cflags += -I. -I$(dir.top)
268
269########################################################################
270# emcc flags specific to building the final .js/.wasm file...
271emcc.jsflags := -fPIC
272emcc.jsflags += --minify 0
273emcc.jsflags += --no-entry
274emcc.jsflags += -sMODULARIZE
275emcc.jsflags += -sSTRICT_JS
276emcc.jsflags += -sDYNAMIC_EXECUTION=0
277emcc.jsflags += -sNO_POLYFILL
278emcc.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.api
279emcc.exportedRuntimeMethods := \
280    -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory,allocateUTF8OnStack
281    # FS ==> stdio/POSIX I/O proxies
282    # wasmMemory ==> required by our code for use with -sIMPORTED_MEMORY
283    # allocateUTF8OnStack => for kvvfs internals
284emcc.jsflags += $(emcc.exportedRuntimeMethods)
285emcc.jsflags += -sUSE_CLOSURE_COMPILER=0
286emcc.jsflags += -sIMPORTED_MEMORY
287emcc.environment := -sENVIRONMENT=web,worker
288emcc.jsflags += -sALLOW_MEMORY_GROWTH
289# emcc: warning: USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code
290#       slowly, see https://github.com/WebAssembly/design/issues/1271
291#       [-Wpthreads-mem-growth]
292emcc.jsflags += -sINITIAL_MEMORY=13107200
293#emcc.jsflags += -sINITIAL_MEMORY=64225280
294# ^^^^ 64MB is not enough for WASMFS/OPFS test runs using batch-runner.js
295emcc.jsflags += $(emcc.environment)
296#emcc.jsflags += -sTOTAL_STACK=4194304
297
298sqlite3.js.init-func := sqlite3InitModule
299# ^^^^ $(sqlite3.js.init-func) symbol name is hard-coded in $(extern-post-js.js)
300
301emcc.jsflags += -sEXPORT_NAME=$(sqlite3.js.init-func)
302emcc.jsflags += -sGLOBAL_BASE=4096 # HYPOTHETICALLY keep func table indexes from overlapping w/ heap addr.
303#emcc.jsflags += -sSTRICT # fails due to missing __syscall_...()
304#emcc.jsflags += -sALLOW_UNIMPLEMENTED_SYSCALLS
305#emcc.jsflags += -sFILESYSTEM=0 # only for experimentation. sqlite3 needs the FS API
306#emcc.jsflags += -sABORTING_MALLOC
307emcc.jsflags += -sALLOW_TABLE_GROWTH
308emcc.jsflags += -Wno-limited-postlink-optimizations
309# ^^^^^ it likes to warn when we have "limited optimizations" via the -g3 flag.
310#emcc.jsflags += -sSTANDALONE_WASM # causes OOM errors, not sure why
311# https://lld.llvm.org/WebAssembly.html
312emcc.jsflags += -sERROR_ON_UNDEFINED_SYMBOLS=0
313emcc.jsflags += -sLLD_REPORT_UNDEFINED
314#emcc.jsflags += --allow-undefined
315emcc.jsflags += --import-undefined
316#emcc.jsflags += --unresolved-symbols=import-dynamic --experimental-pic
317#emcc.jsflags += --experimental-pic --unresolved-symbols=ingore-all --import-undefined
318#emcc.jsflags += --unresolved-symbols=ignore-all
319emcc.jsflags += -sWASM_BIGINT=$(emcc_enable_bigint)
320# ^^^^ MEMORY64=1 fails to load, erroring with:
321#  invalid memory limits flags 0x5
322#    (enable via --experimental-wasm-memory64)
323#
324# ^^^^ MEMORY64=2 builds and loads but dies when we do things like:
325#
326#  new Uint8Array(heapWrappers().HEAP8U.buffer, ptr, n)
327#
328# because ptr is now a BigInt, so is invalid for passing to arguments
329# which have strict must-be-a-Number requirements.
330########################################################################
331
332
333########################################################################
334# -sSINGLE_FILE:
335# https://github.com/emscripten-core/emscripten/blob/main/src/settings.js#L1704
336# -sSINGLE_FILE=1 would be really nice but we have to build with -g
337# for -O2 and higher to work (else minification breaks the code) and
338# cannot wasm-strip the binary before it gets encoded into the JS
339# file. The result is that the generated JS file is, because of the -g
340# debugging info, _huge_.
341########################################################################
342
343########################################################################
344# Maintenance reminder: the output .js and .wasm files of emcc must be
345# in _this_ dir, rather than a subdir, or else parts of the generated
346# code get confused and cannot load property (namely, the
347# sqlite3.worker.js generated in conjunction with -sWASMFS).
348sqlite3.js := sqlite3.js
349sqlite3.wasm := sqlite3.wasm
350sqlite3-wasm.o := $(dir.api)/sqlite3-wasm.o
351$(sqlite3-wasm.o): emcc.cflags += $(SQLITE_OPT)
352$(sqlite3-wasm.o): $(dir.top)/sqlite3.c
353sqlite3-wasm.c := $(dir.api)/sqlite3-wasm.c
354########################################################################
355# call-wasm-c-compile sets up build rules
356# for $1.o. $1 must be the name of a C file (with extension).
357define call-wasm-c-compile
358$(1).o := $$(subst .c,.o,$(1))
359sqlite3.wasm.obj += $$($(1).o)
360$$($(1).o): $$(MAKEFILE) $(1)
361	$$(emcc.bin) $$(emcc_opt_full) $$(emcc.flags) $$(emcc.cflags) -c $(1) -o $$@
362CLEAN_FILES += $$($(1).o)
363endef
364$(foreach c,$(sqlite3-wasm.c),$(eval $(call call-wasm-c-compile,$(c))))
365$(eval $(call call-make-pre-js,sqlite3))
366$(sqlite3.js): $(MAKEFILE) $(sqlite3.wasm.obj) \
367    EXPORTED_FUNCTIONS.api \
368    $(pre-post-sqlite3.deps)
369	@echo "Building $@ ..."
370	$(emcc.bin) -o $@ $(emcc_opt_full) $(emcc.flags) \
371    $(emcc.jsflags) $(pre-post-common.flags) $(pre-post-sqlite3.flags) \
372    $(sqlite3.wasm.obj)
373	chmod -x $(sqlite3.wasm)
374	$(maybe-wasm-strip) $(sqlite3.wasm)
375	@ls -la $@ $(sqlite3.wasm)
376$(sqlite3.wasm): $(sqlite3.js)
377CLEAN_FILES += $(sqlite3.js) $(sqlite3.wasm)
378all: $(sqlite3.js)
379wasm: $(sqlite3.js)
380# End main Emscripten-based module build
381########################################################################
382
383########################################################################
384# batch-runner.js...
385dir.sql := sql
386speedtest1 := ../../speedtest1
387speedtest1.c := ../../test/speedtest1.c
388speedtest1.sql := $(dir.sql)/speedtest1.sql
389speedtest1.cliflags := --size 25 --big-transactions
390$(speedtest1):
391	$(MAKE) -C ../.. speedtest1
392$(speedtest1.sql): $(speedtest1) $(MAKEFILE)
393	$(speedtest1) $(speedtest1.cliflags) --script $@
394batch-runner.list: $(MAKEFILE) $(speedtest1.sql) $(dir.sql)/000-mandelbrot.sql
395	bash split-speedtest1-script.sh $(dir.sql)/speedtest1.sql
396	ls -1 $(dir.sql)/*.sql | grep -v speedtest1.sql | sort > $@
397clean-batch:
398	rm -f batch-runner.list $(dir.sql)/speedtest1*.sql
399# ^^^ we don't do this along with 'clean' because we clean/rebuild on
400# a regular basis with different -Ox flags and rebuilding the batch
401# pieces each time is an unnecessary time sink.
402batch: batch-runner.list
403all: batch
404# end batch-runner.js
405########################################################################
406# speedtest1.js...
407# speedtest1-common.eflags = emcc flags used by multiple builds of speedtest1
408# speedtest1.eflags = emcc flags used by main build of speedtest1
409speedtest1-common.eflags := $(emcc_opt_full)
410speedtest1.eflags :=
411speedtest1.eflags += -sENVIRONMENT=web
412speedtest1-common.eflags += -sINVOKE_RUN=0
413speedtest1-common.eflags += --no-entry
414#speedtest1-common.eflags += -flto
415speedtest1-common.eflags += -sABORTING_MALLOC
416speedtest1-common.eflags += -sINITIAL_MEMORY=128450560
417speedtest1-common.eflags += -sSTRICT_JS
418speedtest1-common.eflags += -sMODULARIZE
419speedtest1-common.eflags += -Wno-limited-postlink-optimizations
420speedtest1-common.eflags += -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.speedtest1
421speedtest1-common.eflags += $(emcc.exportedRuntimeMethods)
422speedtest1-common.eflags += -sALLOW_TABLE_GROWTH
423speedtest1-common.eflags += -sDYNAMIC_EXECUTION=0
424speedtest1-common.eflags += --minify 0
425speedtest1-common.eflags += -sEXPORT_NAME=$(sqlite3.js.init-func)
426speedtest1-common.eflags += -sWASM_BIGINT=$(emcc_enable_bigint)
427speedtest1-common.eflags += $(pre-post-common.flags)
428speedtest1.exit-runtime0 := -sEXIT_RUNTIME=0
429speedtest1.exit-runtime1 := -sEXIT_RUNTIME=1
430# Re -sEXIT_RUNTIME=1 vs 0: if it's 1 and speedtest1 crashes, we get
431# this error from emscripten:
432#
433# > native function `free` called after runtime exit (use
434# NO_EXIT_RUNTIME to keep it alive after main() exits))
435#
436# If it's 0 and it crashes, we get:
437#
438# > stdio streams had content in them that was not flushed. you should
439# set EXIT_RUNTIME to 1 (see the FAQ), or make sure to emit a newline
440# when you printf etc.
441#
442# and pending output is not flushed because it didn't end with a
443# newline (by design). The lesser of the two evils seems to be
444# -sEXIT_RUNTIME=1 but we need EXIT_RUNTIME=0 for the worker-based app
445# which runs speedtest1 multiple times.
446
447EXPORTED_FUNCTIONS.speedtest1: EXPORTED_FUNCTIONS.api
448	{ echo _wasm_main; cat EXPORTED_FUNCTIONS.api; } > $@
449CLEAN_FILES += EXPORTED_FUNCTIONS.speedtest1
450speedtest1.js := speedtest1.js
451speedtest1.wasm := $(subst .js,.wasm,$(speedtest1.js))
452speedtest1.cflags := \
453  -I. -I.. -I$(dir.top) \
454  -DSQLITE_SPEEDTEST1_WASM
455speedtest1.cs := $(speedtest1.c) $(sqlite3-wasm.c)
456$(speedtest1.js): emcc.cflags+=
457# speedtest1 notes re. sqlite3-wasm.o vs sqlite3-wasm.c: building against
458# the latter (predictably) results in a slightly faster binary, but we're
459# close enough to the target speed requirements that the 500ms makes a
460# difference.
461$(eval $(call call-make-pre-js,speedtest1))
462$(speedtest1.js): $(MAKEFILE) $(speedtest1.cs) \
463    $(pre-post-speedtest1.deps) \
464    EXPORTED_FUNCTIONS.speedtest1
465	@echo "Building $@ ..."
466	$(emcc.bin) \
467        $(speedtest1.eflags) $(speedtest1-common.eflags) $(speedtest1.cflags) \
468        $(pre-post-speedtest1.flags) \
469        $(SQLITE_OPT) \
470        $(speedtest1.exit-runtime0) \
471        -o $@ $(speedtest1.cs) -lm
472	$(maybe-wasm-strip) $(speedtest1.wasm)
473	ls -la $@ $(speedtest1.wasm)
474
475speedtest1: $(speedtest1.js)
476all: speedtest1
477CLEAN_FILES += $(speedtest1.js) $(speedtest1.wasm)
478# end speedtest1.js
479########################################################################
480
481########################################################################
482# fiddle_remote is the remote destination for the fiddle app. It
483# must be a [user@]HOST:/path for rsync.
484# Note that the target "should probably" contain a symlink of
485# index.html -> fiddle.html.
486fiddle_remote ?=
487ifeq (,$(fiddle_remote))
488ifneq (,$(wildcard /home/stephan))
489  fiddle_remote = wh:www/wh/sqlite3/.
490else ifneq (,$(wildcard /home/drh))
491  #fiddle_remote = if appropriate, add that user@host:/path here
492endif
493endif
494$(fiddle_files): default
495push-fiddle: $(fiddle_files)
496	@if [ x = "x$(fiddle_remote)" ]; then \
497		echo "fiddle_remote must be a [user@]HOST:/path for rsync"; \
498		exit 1; \
499	fi
500	rsync -va fiddle/ $(fiddle_remote)
501# end fiddle remote push
502########################################################################
503
504########################################################################
505# Convenience rules to rebuild with various -Ox levels. Much
506# experimentation shows -O2 to be the clear winner in terms of speed.
507# Note that build times with anything higher than -O0 are somewhat
508# painful.
509
510.PHONY: o0 o1 o2 o3 os oz
511o-xtra := -flto
512# ^^^^ -flto can have a considerably performance boost at -O0 but
513# doubles the build time and seems to have negligible effect on
514# higher optimization levels.
515o0: clean
516	$(MAKE) -e "emcc_opt=-O0 $(o-xtra)"
517o1: clean
518	$(MAKE) -e "emcc_opt=-O1 $(o-xtra)"
519o2: clean
520	$(MAKE) -e "emcc_opt=-O2 $(o-xtra)"
521o3: clean
522	$(MAKE) -e "emcc_opt=-O3 $(o-xtra)"
523os: clean
524	@echo "WARNING: -Os can result in a build with mysteriously missing pieces!"
525	$(MAKE) -e "emcc_opt=-Os $(o-xtra)"
526oz: clean
527	$(MAKE) -e "emcc_opt=-Oz $(o-xtra)"
528
529########################################################################
530# Sub-makes...
531
532include fiddle.make
533
534########################################################################
535# Some platforms do not support the WASMFS build. Raspberry Pi OS is one
536# of them. As such platforms are discovered, add their (uname -m) name
537# to PLATFORMS_WITH_NO_WASMFS to exclude the wasmfs build parts.
538PLATFORMS_WITH_NO_WASMFS := aarch64 # add any others here
539THIS_ARCH := $(shell /usr/bin/uname -m)
540ifneq (,$(filter $(THIS_ARCH),$(PLATFORMS_WITH_NO_WASMFS)))
541$(info This platform does not support the WASMFS build.)
542HAVE_WASMFS := 0
543else
544HAVE_WASMFS := 1
545include wasmfs.make
546endif
547
548########################################################################
549# Create deliverables: TODO
550ifneq (,$(filter dist,$(MAKECMDGOALS)))
551include dist.make
552endif
553
554########################################################################
555# Push files to public wasm-testing.sqlite.org server
556wasm-testing.include = *.wasm *.js *.html \
557    batch-runner.list sql common fiddle jaccwabyt
558wasm-testing.exclude = sql/speedtest1.sql
559wasm-testing.dir     = /jail/sites/wasm-testing
560wasm-testing.dest   ?= wasm-testing:$(wasm-testing.dir)
561# ---------------------^^^^^^^^^^^^ ssh alias
562push:
563	rsync -z -e ssh --ignore-times --chown=stephan:www-data --group -r \
564    $(patsubst %,--exclude=%,$(wasm-testing.exclude)) \
565    $(wasm-testing.include) $(wasm-testing.dest)
566	ssh wasm-testing 'cd $(wasm-testing.dir) && bash .gzip' || \
567    echo "SSH failed: it's likely that stale content will be served via old gzip files."
568