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