1.PHONY: format
2
3all:
4
5format:
6	# Convert tabs to spaces
7	find ./source -type f -iname '*.[cpp\|c\|h]' -exec bash -c 'expand -t 4 "$$0" | sponge "$$0"' {} \;
8	# Remove trailing whitespaces
9	find ./source -type f -iname '*.[cpp\|c\|h]' -exec sed -i 's/ *$$//' {} \;
10
11preprocess: preprocess_restore
12	cp ./source/m3_exec.h    ./source/m3_exec.h.bak
13	cp ./source/m3_compile.c ./source/m3_compile.c.bak
14	awk 'BEGIN {RS=""}{gsub(/\\\n/,"\\\n__NL__ ")}1' ./source/m3_exec.h | sponge ./source/m3_exec.h
15	cpp -I./source -P ./source/m3_compile.c | sponge ./source/m3_compile.c
16	awk '{gsub(/__NL__/,"\n")}1' ./source/m3_compile.c | sponge ./source/m3_compile.c
17	mv ./source/m3_exec.h.bak ./source/m3_exec.h
18
19preprocess_restore:
20	-mv source/m3_compile.c.bak source/m3_compile.c
21	touch source/m3_compile.c
22
23
24test_rv64:
25	riscv64-linux-gnu-gcc -DDEBUG -Dd_m3HasWASI \
26		-I./source ./source/*.c ./platforms/app/main.c \
27		-O3 -g0 -flto -lm -static \
28		-o wasm3-rv64
29
30	cd test; python3 run-wasi-test.py --fast --exec "qemu-riscv64-static ../wasm3-rv64"
31	rm ./wasm3-rv64
32
33test_cpp:
34	clang -xc++ -Dd_m3HasWASI \
35		-I./source ./source/*.c ./platforms/app/main.c \
36		-O3 -g0 -flto -lm -static \
37		-o wasm3-cpp
38	cd test; python3 run-wasi-test.py --fast --exec "../wasm3-cpp"
39	rm ./wasm3-cpp
40