11CC = clang
2- TARGET = clayterm.wasm
3- SRC = src/module.c
42
53CFLAGS = --target=wasm32 -nostdlib -O2 \
64 -ffunction-sections -fdata-sections \
75 -mbulk-memory \
86 -DCLAY_IMPLEMENTATION -DCLAY_WASM \
97 -Isrc -I.
108
11- EXPORTS = \
9+ LDFLAGS_COMMON = -Wl,--no-entry \
10+ -Wl,--import-memory \
11+ -Wl,--stack-first \
12+ -Wl,--strip-all \
13+ -Wl,--gc-sections
14+
15+ LAYOUT_EXPORTS = \
1216 -Wl,--export=__heap_base \
1317 -Wl,--export=clayterm_size \
1418 -Wl,--export=init \
@@ -24,35 +28,44 @@ EXPORTS = \
2428 -Wl,--export=error_count \
2529 -Wl,--export=error_type \
2630 -Wl,--export=error_message_length \
27- -Wl,--export=error_message_ptr \
31+ -Wl,--export=error_message_ptr
32+
33+ INPUT_EXPORTS = \
34+ -Wl,--export=__heap_base \
2835 -Wl,--export=input_size \
2936 -Wl,--export=input_init \
3037 -Wl,--export=input_scan \
3138 -Wl,--export=input_count \
3239 -Wl,--export=input_event \
3340 -Wl,--export=input_delay
3441
35- LDFLAGS = -Wl,--no-entry \
36- -Wl,--import-memory \
37- -Wl,--stack-first \
38- -Wl,--strip-all \
39- -Wl,--gc-sections \
40- -Wl,--undefined=Clay__MeasureText \
41- -Wl,--undefined=Clay__QueryScrollOffset \
42- $(EXPORTS )
42+ LAYOUT_LDFLAGS = $(LDFLAGS_COMMON ) \
43+ -Wl,--undefined=Clay__MeasureText \
44+ -Wl,--undefined=Clay__QueryScrollOffset \
45+ $(LAYOUT_EXPORTS )
4346
44- all : $( TARGET ) wasm.ts
45- @echo " Built $( TARGET ) ( $$ (wc -c < $( TARGET ) ) bytes raw, $$ (gzip -c $( TARGET ) | wc -c) bytes gzip) "
47+ INPUT_LDFLAGS = $( LDFLAGS_COMMON ) \
48+ $( INPUT_EXPORTS )
4649
4750DEPS = $(wildcard src/* .c src/* .h)
4851
49- $(TARGET ) : $(DEPS )
50- $(CC ) $(CFLAGS ) $(LDFLAGS ) -o $@ $(SRC )
52+ all : clayterm-layout.wasm clayterm-input.wasm wasm-layout.ts wasm-input.ts
53+ @echo " Built clayterm-layout.wasm ($$ (wc -c < clayterm-layout.wasm) bytes raw, $$ (gzip -c clayterm-layout.wasm | wc -c) bytes gzip)"
54+ @echo " Built clayterm-input.wasm ($$ (wc -c < clayterm-input.wasm) bytes raw, $$ (gzip -c clayterm-input.wasm | wc -c) bytes gzip)"
55+
56+ clayterm-layout.wasm : $(DEPS )
57+ $(CC ) $(CFLAGS ) $(LAYOUT_LDFLAGS ) -o $@ src/module-layout.c
58+
59+ clayterm-input.wasm : $(DEPS )
60+ $(CC ) $(filter-out -DCLAY_IMPLEMENTATION -DCLAY_WASM, $(CFLAGS ) ) $(INPUT_LDFLAGS ) -o $@ src/module-input.c
61+
62+ wasm-layout.ts : clayterm-layout.wasm
63+ deno run --allow-read --allow-write tasks/bundle-wasm.ts clayterm-layout.wasm wasm-layout.ts
5164
52- wasm.ts : $( TARGET )
53- deno run --allow-read --allow-write tasks/bundle-wasm.ts
65+ wasm-input .ts : clayterm-input.wasm
66+ deno run --allow-read --allow-write tasks/bundle-wasm.ts clayterm-input.wasm wasm-input.ts
5467
5568clean :
56- rm -f $( TARGET ) wasm.ts
69+ rm -f clayterm.wasm clayterm-layout. wasm clayterm-input.wasm wasm.ts wasm-layout.ts wasm-input .ts
5770
5871.PHONY : all clean
0 commit comments