Teach the Makefile how to "build" the audio assets
Some checks failed
Basic checks / Basic build-and-test supertask (push) Failing after 55s
Some checks failed
Basic checks / Basic build-and-test supertask (push) Failing after 55s
Makefiles are pretty strange things. There is a new wildcard target which will copy any .ogg file from "assets/" into "out/assets". On it's own, it does nothing -- it only knows how to create the output file by copying the input one. To drive this, a list of output assets must be created and depended upon by the main build target(s). I don't want to manually maintain an asset manifest in a Makefile, so I've achived this by wildcard matching anything in the "assets/" folder, then rewriting the prefix to be "out/assets/". This list is in a variable, which is now part of the dependency list for the main build target(s). All files will be installed, but only when they are out-of-date. Excellent.
This commit is contained in:
17
Makefile
17
Makefile
@@ -12,23 +12,26 @@ CARGO_PROFILE := tiny
|
||||
SRC_DIR = ./src
|
||||
SRCS := $(wildcard $(SRC_DIR)/**)
|
||||
|
||||
ASSET_SOURCE := $(wildcard assets/**)
|
||||
ASSETS := $(patsubst assets/%.ogg, out/assets/%.ogg, $(ASSET_SOURCE))
|
||||
|
||||
.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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
@@ -37,6 +40,12 @@ target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm: $(SRCS) Cargo.lock Cargo
|
||||
out:
|
||||
mkdir $@
|
||||
|
||||
out/assets: out
|
||||
mkdir $@
|
||||
|
||||
out/assets/%.ogg: out/assets assets/%.ogg
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user