ems_rust_template/Makefile

50 lines
1.6 KiB
Makefile

ifdef RELEASE
RUST_BUILD_TYPE := release
RUST_EXTRA_FLAGS := --release
C_OTHER_FLAGS := -DNDEBUG -O2
else
RUST_BUILD_TYPE := debug
RUST_EXTRA_FLAGS :=
C_OTHER_FLAGS := -Og
endif
CC := source ${HOME}/git/emsdk/emsdk_env.sh && emcc
CFLAGS := \
-Irust_src/include \
-sEXPORTED_FUNCTIONS=_main \
-sSTACK_SIZE=2097152 \
-s USE_GLFW=3 \
${C_OTHER_FLAGS}
# Check https://emscripten.org/docs/tools_reference/emcc.html for more compiler
# flags to pass to emcc.
HEADERS := \
rust_src/include/rust_src.h
RUST_SOURCES := $(shell find rust_src/src/ -regex '.*\.rs$$')
all: dist/my_project.html
rust_src/target/wasm32-unknown-emscripten/${RUST_BUILD_TYPE}/libems_rust_template.a: third_party/raylib/src/libraylib.a ${RUST_SOURCES}
cd rust_src && cargo build --target=wasm32-unknown-emscripten ${RUST_EXTRA_FLAGS}
dist/my_project.html: rust_src/target/wasm32-unknown-emscripten/${RUST_BUILD_TYPE}/libems_rust_template.a src/main.c.o third_party/raylib/src/libraylib.a
@mkdir -p dist
${CC} -o dist/my_project.html ${CFLAGS} $^
ln -sf my_project.html dist/index.html
third_party/raylib/src/libraylib.a:
test -d third_party/raylib/src || git clone --depth=1 --no-single-branch https://github.com/raysan5/raylib.git third_party/raylib
cd third_party/raylib/ && git restore . && git checkout 5.0 && patch -p1 < ../raylib_patch_00.patch
source ${HOME}/git/emsdk/emsdk_env.sh && make -C third_party/raylib/src
.PHONY: clean
clean:
cd rust_src && cargo clean
rm -f src/*.c.o
rm -rf dist
test -d third_party/raylib/src && make -C third_party/raylib/src clean
%.c.o: %.c ${HEADERS}
${CC} -o $@ -c ${CFLAGS} $<