## ## This Makefile exists to produce WASM builds. ## Do not use it if that isn't your goal! ## # # # Configuration Variables # # # # # Patch these to select a different build profile or target # The target shouldn't change any time soon. WASM64, I guess. Other targets # aren't aimed at the web, so you shouldn't be using this makefile. CARGO_TARGET := wasm32-unknown-unknown CARGO_PROFILE := tiny # # # Automatic Variables # # # SRC_DIR = ./src SRCS := $(wildcard $(SRC_DIR)/**) ASSET_SOURCE := $(wildcard assets/**) ASSETS := $(patsubst assets/%.ogg, out/assets/%.ogg, $(ASSET_SOURCE)) CRATE_VERSION != sed -nre 's/^version = "(.*)"/\1/p' Cargo.toml .PHONY: clean full-clean tarball tarball-standalone web web-standalone # "Standalone" version. It includes an index.html to serve as-is web-standalone: out/asteroids.js out/asteroids_bg.wasm.gz out/index.html $(ASSETS) # "Bundle-able" version. It has a page, but no index.html. Consumers are # expected to provide their own index.html and link to this page. web: out/asteroids.js out/asteroids_bg.wasm.gz out/asteroids.html $(ASSETS) tarball: asteroids_web_root.tar tarball_standalone: asteroids_web_root_standalone.tar asteroids_web_root.tar: out/asteroids.js out/asteroids_bg.wasm.gz out/asteroids.html $(ASSETS) tar -caf $@ $^ asteroids_web_root_standalone.tar: out/asteroids.js out/asteroids_bg.wasm.gz out/index.html $(ASSETS) tar -caf $@ $^ target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm: $(SRCS) Cargo.lock Cargo.toml cargo build --profile $(CARGO_PROFILE) --target $(CARGO_TARGET) out: mkdir $@ out/assets: | out mkdir $@ out/assets/%.ogg: assets/%.ogg | out/assets cp -ar assets/$*.ogg $@ # Both the JS and WASM files are generated by the wasm-bindgen call, so both # get to be on the target half of this recipe. out/asteroids.js out/asteroids_bg.wasm.gz &: target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm | out wasm-bindgen --no-typescript --target web --out-dir ./out/ --out-name asteroids target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm gzip -9 -f out/asteroids_bg.wasm # Copies the index page to the output dir. out/index.html: www/index.html cp -a $< $@ rm -f out/asteroids.html sed -i -e "s/#CRATE_VERSION_PLACEHOLDER#/$(CRATE_VERSION)/" $@ # Like `out/index.html`, but renames the page for use in a larger site. out/asteroids.html: www/index.html cp -a $< $@ rm -f out/index.html # Clean the web build, but not the Cargo cache. Cargo handles it's own caching # and I don't want to obliterate it all the time. clean: rm -rf out/ asteroids_web_root.tar asteroids_web_root_standalone.tar # Delete everything, including the Cargo build cache. In case someone needs # this, I guess. full-clean: clean cargo clean # Installation goal. It's meant to be a helper utility for moving the built # output into the web root. Only supports the "bundle-able" mode. install: web install -dm0755 $(DESTDIR) install -dm0755 $(DESTDIR)/assets install -m0644 out/asteroids.js $(DESTDIR)/ install -m0644 out/asteroids_bg.wasm.gz $(DESTDIR)/ install -m0644 out/asteroids.html $(DESTDIR)/ install -m0644 $(ASSETS) $(DESTDIR)/assets/