11CC = clang
22WASM_OPT ?= wasm-opt
3- TARGET = clayterm.wasm
4- SRC = src/module.c
53
64CFLAGS = --target=wasm32 -nostdlib -Oz \
75 -ffunction-sections -fdata-sections \
86 -mbulk-memory \
97 -DCLAY_IMPLEMENTATION -DCLAY_WASM \
108 -Isrc -I.
119
12- EXPORTS = \
10+ LDFLAGS_COMMON = -Wl,--no-entry \
11+ -Wl,--import-memory \
12+ -Wl,--stack-first \
13+ -Wl,--strip-all \
14+ -Wl,--gc-sections
15+
16+ LAYOUT_EXPORTS = \
1317 -Wl,--export=__heap_base \
1418 -Wl,--export=clayterm_size \
1519 -Wl,--export=init \
@@ -25,36 +29,46 @@ EXPORTS = \
2529 -Wl,--export=error_count \
2630 -Wl,--export=error_type \
2731 -Wl,--export=error_message_length \
28- -Wl,--export=error_message_ptr \
32+ -Wl,--export=error_message_ptr
33+
34+ INPUT_EXPORTS = \
35+ -Wl,--export=__heap_base \
2936 -Wl,--export=input_size \
3037 -Wl,--export=input_init \
3138 -Wl,--export=input_scan \
3239 -Wl,--export=input_count \
3340 -Wl,--export=input_event \
3441 -Wl,--export=input_delay
3542
36- LDFLAGS = -Wl,--no-entry \
37- -Wl,--import-memory \
38- -Wl,--stack-first \
39- -Wl,--strip-all \
40- -Wl,--gc-sections \
41- -Wl,--undefined=Clay__MeasureText \
42- -Wl,--undefined=Clay__QueryScrollOffset \
43- $(EXPORTS )
43+ LAYOUT_LDFLAGS = $(LDFLAGS_COMMON ) \
44+ -Wl,--undefined=Clay__MeasureText \
45+ -Wl,--undefined=Clay__QueryScrollOffset \
46+ $(LAYOUT_EXPORTS )
4447
45- all : $( TARGET ) wasm.ts
46- @echo " Built $( TARGET ) ( $$ (wc -c < $( TARGET ) ) bytes raw, $$ (gzip -c $( TARGET ) | wc -c) bytes gzip) "
48+ INPUT_LDFLAGS = $( LDFLAGS_COMMON ) \
49+ $( INPUT_EXPORTS )
4750
4851DEPS = $(wildcard src/* .c src/* .h)
4952
50- $(TARGET ) : $(DEPS )
51- $(CC ) $(CFLAGS ) $(LDFLAGS ) -o $@ $(SRC )
53+ all : clayterm-layout.wasm clayterm-input.wasm wasm-layout.ts wasm-input.ts
54+ @echo " Built clayterm-layout.wasm ($$ (wc -c < clayterm-layout.wasm) bytes raw, $$ (gzip -c clayterm-layout.wasm | wc -c) bytes gzip)"
55+ @echo " Built clayterm-input.wasm ($$ (wc -c < clayterm-input.wasm) bytes raw, $$ (gzip -c clayterm-input.wasm | wc -c) bytes gzip)"
56+
57+ clayterm-layout.wasm : $(DEPS )
58+ $(CC ) $(CFLAGS ) $(LAYOUT_LDFLAGS ) -o $@ src/module-layout.c
5259 $(WASM_OPT ) -Oz --enable-bulk-memory -o $@ $@
5360
54- wasm.ts : $(TARGET )
55- deno run --allow-read --allow-write tasks/bundle-wasm.ts
61+ clayterm-input.wasm : $(DEPS )
62+ $(CC ) $(filter-out -DCLAY_IMPLEMENTATION -DCLAY_WASM, $(CFLAGS ) ) $(INPUT_LDFLAGS ) -o $@ src/module-input.c
63+ $(WASM_OPT ) -Oz --enable-bulk-memory -o $@ $@
64+
65+ wasm-layout.ts : clayterm-layout.wasm
66+ deno run --allow-read --allow-write tasks/bundle-wasm.ts clayterm-layout.wasm wasm-layout.ts
67+
68+ wasm-input.ts : clayterm-input.wasm
69+ deno run --allow-read --allow-write tasks/bundle-wasm.ts clayterm-input.wasm wasm-input.ts
5670
5771clean :
58- rm -f $( TARGET ) wasm.ts
72+ rm -f clayterm.wasm clayterm-layout. wasm clayterm-input.wasm wasm.ts wasm-layout.ts wasm-input .ts
5973
6074.PHONY : all clean
0 commit comments