2 #^^^ help emacs select edit mode
4 # Intended to include'd by ./GNUmakefile.
5 #######################################################################
6 MAKEFILE.fiddle
:= $(lastword
$(MAKEFILE_LIST
))
8 ########################################################################
9 # shell.c and its build flags...
10 make-np-0
:= make
-C
$(dir.top
) -n
-p
11 make-np-1
:= sed
-e
's/(TOP)/(dir.top)/g'
12 $(eval
$(shell $(make-np-0
) | grep
-e
'^SHELL_OPT ' |
$(make-np-1
)))
13 $(eval
$(shell $(make-np-0
) | grep
-e
'^SHELL_SRC ' |
$(make-np-1
)))
14 # ^^^ can't do that in 1 invocation b/c newlines get stripped
16 $(error Could not parse SHELL_OPT from
$(dir.top
)/Makefile.
)
19 $(error Could not parse SHELL_SRC from
$(dir.top
)/Makefile.
)
21 $(dir.top
)/shell.c
: $(SHELL_SRC
) $(dir.top
)/tool
/mkshellc.tcl
$(sqlite3.c
)
22 $(MAKE
) -C
$(dir.top
) shell.c
24 ########################################################################
26 EXPORTED_FUNCTIONS.fiddle
:= $(dir.tmp
)/EXPORTED_FUNCTIONS.fiddle
28 $(emcc.
cflags) $(emcc_opt_full
) \
30 -sALLOW_TABLE_GROWTH \
33 -sENVIRONMENT
=web
,worker \
35 -sDYNAMIC_EXECUTION
=0 \
36 -sWASM_BIGINT
=$(emcc.WASM_BIGINT
) \
37 -sEXPORT_NAME
=$(sqlite3.js.init-func
) \
38 -Wno-limited-postlink-optimizations \
39 $(emcc.exportedRuntimeMethods
) \
40 -sEXPORTED_FUNCTIONS
=@
$(abspath
$(EXPORTED_FUNCTIONS.fiddle
)) \
41 -sEXPORTED_RUNTIME_METHODS
=FS
,wasmMemory \
42 $(SQLITE_OPT
) $(SHELL_OPT
) \
44 # -D_POSIX_C_SOURCE is needed for strdup() with emcc
46 fiddle.EXPORTED_FUNCTIONS.in
:= \
47 EXPORTED_FUNCTIONS.fiddle.in \
48 $(EXPORTED_FUNCTIONS.api
)
50 $(EXPORTED_FUNCTIONS.fiddle
): $(fiddle.EXPORTED_FUNCTIONS.in
) $(MAKEFILE.fiddle
)
51 sort -u
$(fiddle.EXPORTED_FUNCTIONS.in
) > $@
53 fiddle-module.js
:= $(dir.fiddle
)/fiddle-module.js
54 fiddle-module.wasm
:= $(subst .js
,.wasm
,$(fiddle-module.js
))
55 fiddle.cses
:= $(dir.top
)/shell.c
$(sqlite3-wasm.c
)
57 fiddle.SOAP.js
:= $(dir.fiddle
)/$(notdir $(SOAP.js
))
58 $(fiddle.SOAP.js
): $(SOAP.js
)
61 $(eval
$(call call-make-pre-post
,fiddle-module
,vanilla
))
62 $(fiddle-module.js
): $(MAKEFILE
) $(MAKEFILE.fiddle
) \
63 $(EXPORTED_FUNCTIONS.fiddle
) \
64 $(fiddle.cses
) $(pre-post-fiddle-module-vanilla.deps
) $(fiddle.SOAP.js
)
65 $(emcc.bin
) -o
$@
$(fiddle.emcc-flags
) \
66 $(pre-post-fiddle-module-vanilla.flags
) \
68 $(maybe-wasm-strip
) $(fiddle-module.wasm
)
70 gzip
< $(fiddle-module.wasm
) > $(fiddle-module.wasm
).gz
72 $(dir.fiddle
)/fiddle.js.gz
: $(dir.fiddle
)/fiddle.js
77 rm -f
$(fiddle-module.js
) $(fiddle-module.js
).gz \
78 $(fiddle-module.wasm
) $(fiddle-module.wasm
).gz \
79 $(dir.fiddle
)/$(SOAP.js
) \
80 $(dir.fiddle
)/fiddle-module.worker.js \
81 EXPORTED_FUNCTIONS.fiddle
83 fiddle
: $(fiddle-module.js
) $(dir.fiddle
)/fiddle.js.gz
86 ########################################################################
87 # fiddle_remote is the remote destination for the fiddle app. It
88 # must be a [user@]HOST:/path for rsync.
89 # Note that the target "should probably" contain a symlink of
90 # index.html -> fiddle.html.
92 ifeq (,$(fiddle_remote
))
93 ifneq (,$(wildcard /home
/stephan
))
94 fiddle_remote
= wh
:www
/wh
/sqlite3
/.
95 else ifneq (,$(wildcard /home
/drh
))
96 #fiddle_remote = if appropriate, add that user@host:/path here
100 @if
[ x
= "x$(fiddle_remote)" ]; then \
101 echo
"fiddle_remote must be a [user@]HOST:/path for rsync"; \
104 rsync
-va fiddle
/ $(fiddle_remote
)
105 # end fiddle remote push
106 ########################################################################
109 ########################################################################
110 # Explanation of the emcc build flags follows. Full docs for these can
113 # https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
115 # -sENVIRONMENT=web: elides bootstrap code related to non-web JS
116 # environments like node.js. Removing this makes the output a tiny
117 # tick larger but hypothetically makes it more portable to
118 # non-browser JS environments.
120 # -sMODULARIZE: changes how the generated code is structured to avoid
121 # declaring a global Module object and instead installing a function
122 # which loads and initializes the module. The function is named...
124 # -sEXPORT_NAME=jsFunctionName (see -sMODULARIZE)
126 # -sEXPORTED_RUNTIME_METHODS=@/absolute/path/to/file: a file
127 # containing a list of emscripten-supplied APIs, one per line, which
128 # must be exported into the generated JS. Must be an absolute path!
130 # -sEXPORTED_FUNCTIONS=@/absolute/path/to/file: a file containing a
131 # list of C functions, one per line, which must be exported via wasm
132 # so they're visible to JS. C symbols names in that file must all
133 # start with an underscore for reasons known only to the emcc
134 # developers. e.g., _sqlite3_open_v2 and _sqlite3_finalize. Must be
137 # -sSTRICT_JS ensures that the emitted JS code includes the 'use
138 # strict' option. Note that -sSTRICT is more broadly-scoped and
139 # results in build errors.
141 # -sALLOW_TABLE_GROWTH is required for (at a minimum) the UDF-binding
142 # feature. Without it, JS functions cannot be made to proxy C-side
145 # -sABORTING_MALLOC causes the JS-bound _malloc() to abort rather than
146 # return 0 on OOM. If set to 0 then all code which uses _malloc()
147 # must, just like in C, check the result before using it, else
148 # they're likely to corrupt the JS/WASM heap by writing to its
149 # address of 0. It is, as of this writing, enabled in Emscripten by
150 # default but we enable it explicitly in case that default changes.
152 # -sDYNAMIC_EXECUTION=0 disables eval() and the Function constructor.
153 # If the build runs without these, it's preferable to use this flag
154 # because certain execution environments disallow those constructs.
155 # This flag is not strictly necessary, however.
157 # -sWASM_BIGINT is UNTESTED but "should" allow the int64-using C APIs
158 # to work with JS/wasm, insofar as the JS environment supports the
159 # BigInt type. That support requires an extremely recent browser:
160 # Safari didn't get that support until late 2020.
162 # --no-entry: for compiling library code with no main(). If this is
163 # not supplied and the code has a main(), it is called as part of the
164 # module init process. Note that main() is #if'd out of shell.c
165 # (renamed) when building in wasm mode.
167 # --pre-js/--post-js=FILE relative or absolute paths to JS files to
168 # prepend/append to the emcc-generated bootstrapping JS. It's
169 # easier/faster to develop with separate JS files (reduces rebuilding
170 # requirements) but certain configurations, namely -sMODULARIZE, may
171 # require using at least a --pre-js file. They can be used
172 # individually and need not be paired.
174 # -O0..-O3 and -Oz: optimization levels affect not only C-style
175 # optimization but whether or not the resulting generated JS code
176 # gets minified. -O0 compiles _much_ more quickly than -O3 or -Oz,
177 # and doesn't minimize any JS code, so is recommended for
178 # development. -O3 or -Oz are recommended for deployment, but
179 # primarily because -Oz will shrink the wasm file notably. JS-side
180 # minification makes little difference in terms of overall
181 # distributable size.
183 # --minify 0: disables minification of the generated JS code,
184 # regardless of optimization level. Minification of the JS has
185 # minimal overall effect in the larger scheme of things and results
186 # in JS files which can neither be edited nor viewed as text files in
187 # Fossil (which flags them as binary because of their extreme line
188 # lengths). Interestingly, whether or not the comments in the
189 # generated JS file get stripped is unaffected by this setting and
190 # depends entirely on the optimization level. Higher optimization
191 # levels reduce the size of the JS considerably even without
194 ########################################################################