2 # Copyright 2020-2021 Ian Jackson and contributors to Otter
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4 # There is NO WARRANTY.
15 full-check: all check cargo-syntaxcheck-release shapelib doc-sphinx
16 full-check: for-deploy release
17 everything: debug doc release check bundled-sources
19 shapelib: templates/shapelib.html stamp/cargo.doc-otter-only
20 @echo 'Shape library preview and docs can now be found here:'
21 @echo ' file://$(PWD)/$<'
22 @echo ' file://$(abspath $(TARGET_DIR)/doc/otter/shapelib_toml/index.html)'
24 MAKEFILE_DEP ?= Makefile
26 # ^ set this to "x" to debug the $rsrcs rune
28 #---------- funky macros etc. ----------
30 cr = $(addprefix --,$(filter-out debug,$1))
31 rsrcs = $(shell $(foreach x,$(MAKEFILE_FIND_X),set -$x;)\
32 find -H $1 \( -name Cargo.toml -o -name Cargo.lock -o -name Cargo.lock.example -o -name \*.rs \) \! -path '*/build/*' )
33 stamp=@mkdir -p stamp; touch $@
35 BUNDLED_SOURCES_LIT = README.md LICENCE
36 BUNDLED_SOURCES_FILES = index.html $(BUNDLED_SOURCES_LIT)
37 BUNDLED_SOURCES_LINKS += $(BUNDLED_SOURCES_LIT) otter/
38 BUNDLED_SOURCES += $(BUNDLED_SOURCES_FILES)
40 #---------- programs and config variables ----------
45 USVG_OPTIONS = "--sans-serif-family=DejaVu Sans"
47 WASM_BINDGEN = $(TARGET_DIR)/debug/wasm-bindgen
48 WASM_BINDGEN_OPTIONS = \
49 --remove-name-section --remove-producers-section \
50 --typescript --no-modules \
52 BUNDLE_SOURCES ?= bundle-rust-sources
54 SPHINXBUILD = sphinx-build
56 ifndef INKSCAPE_EXTENSIONS
58 INKSCAPE_EXTENSIONS := $(shell $(INKSCAPE) -x)
60 RECOLOUR_SVG ?= $(INKSCAPE_EXTENSIONS)/color_replace.py
62 DEPLOY_ARCH=x86_64-unknown-linux-musl
64 DEPLOY_TARGET_DIR=$(TARGET_DIR)/$(addsuffix /,$(DEPLOY_ARCH))$(DEPLOY_RELEASE)
65 DEPLOYED_BRANCH=deployed
67 #---------- nailing-cargo ----------
69 ifneq (,$(wildcard ../Cargo.nail))
71 NAILING_CARGO = nailing-cargo
72 CARGO = $(NAILING_CARGO)
73 BUILD_SUBDIR ?= ../Build
74 TARGET_DIR = $(BUILD_SUBDIR)/$(notdir $(PWD))/target
76 NAILING_CARGO_JUST_RUN ?= $(NAILING_CARGO) --just-run -q ---
77 BUNDLE_SOURCES_CMD ?= $(NAILING_CARGO) --- $(BUNDLE_SOURCES)
78 USVG_CMD ?= $(NAILING_CARGO_JUST_RUN) $(USVG)
79 WASM_BINDGEN_CLI_CARGO_OPTS ?= --subcommand-props=!manifest-path
82 $(NAILING_CARGO_JUST_RUN) \
83 sh -c 'cd "$1"; find -mindepth 1 -maxdepth 1 -print0 | xargs -0r rm -rf --' \
84 $(abspath $(BUILD_SUBDIR)/$(notdir $(PWD)))
90 BUILD_SUBDIR ?= ../Build
91 BUNDLE_SOURCES_CMD ?= $(BUNDLE_SOURCES)
94 WASM_PACKED=$(TARGET_DIR)/packed-wasm
96 #---------- local programs ----------
99 stamp/cargo.$2: $(call rsrcs, ! -name \*.rs)
100 $$(CARGO) build $(call cr,$3) -p $2
102 $1 := $(abspath $(TARGET_DIR)/$3/$4)
105 $(eval $(call lp,BUNDLE_SOURCES,bundle-sources,debug,bundle-rust-sources))
106 $(eval $(call lp,USVG,usvg,release,usvg))
108 #---------- variables defining bits of source etc. ----------
110 PROGRAMS=daemon-otter otter
112 WASM_ASSETS := $(addprefix otter_wasm,.js _bg.wasm)
113 WASM_OUTPUTS := $(addprefix otter_wasm,.d.ts)
117 $(addprefix templates/,$(addsuffix .ts,$(TS_SRCS))) \
118 webassembly-types/webassembly.d.ts \
119 $(WASM_PACKED)/otter_wasm.d.ts
121 LITFILES= LICENCE AGPLv3
122 TXTFILES= CC-BY-SA-3.0 CC-BY-SA-4.0
124 FILEASSETS = $(addprefix templates/, libre shapelib.html script.js \
125 $(LITFILES) $(TXTFILES)) \
126 $(wildcard templates/*.tera)
128 WASM := wasm32-unknown-unknown
129 # ^ todo: Is this still right after
130 # Use correct ABI for wasm32 by default
131 # https://github.com/rust-lang/rust/pull/79998
132 # ? But maybe it doesn't matter since we're very conservative and
133 # only pass JsValue and a few strings across the WASM ABI.
135 #---------- toplevel aggregate targets ----------
137 check: stamp/cargo.debug-check at wdt
138 @echo 'Tests passed.'
140 full-check: stamp/cargo.release-check
141 full-check: stamp/cargo.release-miri stamp/cargo.debug-miri
144 @echo 'Full tests passed.'
146 doc: cargo-doc doc-sphinx
148 debug release:: %: stamp/cargo.% assets libraries extra-%
150 cargo: cargo-debug cargo-wasm-release
152 cargo-debug cargo-release cargo-check cargo-doc \
153 cargo-wasm-debug cargo-wasm-release:: \
154 cargo-%: stamp/cargo.%
156 cargo-wasm: cargo-wasm-release
158 wasm: stamp/wasm-bindgen
160 assets: js stamp/wasm-bindgen $(FILEASSETS)
162 js: templates/script.js
165 extra-release: bundled-sources
167 cargo-syntaxcheck: cargo-syntaxcheck-host cargo-syntaxcheck-wasm
168 cargo-syntaxcheck-host:
169 $(CARGO) check --workspace
170 cargo-syntaxcheck-wasm:
171 $(CARGO) check --target $(WASM) -p otter-wasm --release
172 cargo-syntaxcheck-release:
173 $(CARGO) check --workspace --release
175 #---------- cargo ----------
178 CARGOES=$(foreach t, wasm-,$(addprefix $t,check $(DR)))
180 $(addprefix stamp/cargo.,$(DR)):: \
181 stamp/cargo.%: $(call rsrcs,. ! -path './wasm/*')
182 $(CARGO) build --workspace $(call cr,$*) -p otter -p otter-daemon
185 $(TARGET_DIR)/debug/%: $(call rsrcs, ! -path './wasm/*')
186 $(CARGO) build --workspace -p otter --bin $*
188 stamp/cargo.wasm-bindgen: $(call rsrcs, ! -name \*.rs)
189 $(CARGO) $(WASM_BINDGEN_CLI_CARGO_OPTS) build --target-dir=target \
190 --manifest-path=$(abspath wasm/Cargo.toml) -p wasm-bindgen-cli
193 stamp/cargo.%-check: $(call rsrcs,.)
194 $(CARGO) test --workspace $(call cr,$*)
197 stamp/cargo.%-miri: $(call rsrcs,.)
198 $(CARGO) miri test --workspace $(call cr,$*)
201 stamp/cargo-at.debug: $(call rsrcs,.)
202 $(CARGO) build --workspace $(call cr,$*) -p otter-api-tests
205 stamp/cargo-wdt.debug: $(call rsrcs,.)
206 $(CARGO) build --workspace $(call cr,$*) -p otter-webdriver-tests
209 stamp/cargo.doc: $(call rsrcs,.)
210 $(CARGO) doc $(CARGO_DOC_OPTS) --workspace 2>&1 |egrep -vf .cargo-doc-suppress-errors
213 stamp/cargo.doc-otter-only: $(call rsrcs,.)
214 $(CARGO) doc $(CARGO_DOC_OPTS) --workspace -p otter --no-deps
217 $(addprefix stamp/cargo.wasm-,$(DR)):: \
218 stamp/cargo.wasm-%: $(call rsrcs, base wasm Cargo.*)
219 $(CARGO) build --target $(WASM) -p otter-wasm $(call cr,$*)
222 stamp/cargo.deploy-build: $(call rsrcs,.)
223 $(CARGO) build --target $(DEPLOY_ARCH) $(call cr,$(DEPLOY_RELEASE)) -p otter -p otter-daemon
226 #---------- sphnix ----------
228 doc-sphinx: docs/html/index.html
229 @echo 'Documentation can now be found here:'
230 @echo ' file://$(PWD)/$<'
232 docs/html/index.html: docs/conf.py $(wildcard docs/*.md docs/*.rst)
233 $(SPHINXBUILD) -M html docs docs $(SPHINXOPTS)
235 #---------- wasm ----------
237 $(addprefix $(WASM_PACKED)/,$(WASM_ASSETS) $(WASM_OUTPUTS)): stamp/wasm-bindgen
238 stamp/wasm-bindgen: stamp/cargo.wasm-bindgen stamp/cargo.wasm-release
239 $(NAILING_CARGO_JUST_RUN) $(abspath $(WASM_BINDGEN)) \
240 $(WASM_BINDGEN_OPTIONS) --out-dir target/packed-wasm \
241 target/$(WASM)/release/otter_wasm.wasm
244 #---------- bundle-sources ----------
246 BUNDLED_SOURCES_DIRS += otter
248 bundled-sources:: $(addprefix bundled-sources/, $(BUNDLED_SOURCES_DIRS))
250 TARGET_BUNDLED=$(TARGET_DIR)/bundled-sources
253 $(NAILING_CARGO_JUST_RUN) mkdir -p $@
255 $(addprefix bundled-sources/, $(BUNDLED_SOURCES_DIRS)): \
256 bundled-sources/%: stamp/cargo.bundle-sources $(TARGET_BUNDLED)
257 set -e; d=$(abspath $(TARGET_BUNDLED)); \
258 $(if $(filter-out otter,$*), cd ../$*;) \
259 $(BUNDLE_SOURCES_CMD) --output $$d/$*
261 bundled-sources:: $(addprefix $(TARGET_BUNDLED)/, $(BUNDLED_SOURCES_FILES))
263 $(addprefix $(TARGET_BUNDLED)/, $(BUNDLED_SOURCES_LIT)): \
264 $(TARGET_BUNDLED)/%: % $(TARGET_BUNDLED)
265 $(NAILING_CARGO_JUST_RUN) cp $(abspath $(src))/$< $(abspath $@)
267 $(TARGET_BUNDLED)/index.html: bundled-sources-make-index \
268 $(MAKEFILE_DEP) $(TARGET_BUNDLED)
269 $(NAILING_CARGO_JUST_RUN) sh -ec ' \
270 cd $(abspath $(src)); mkdir -p $(dir $@); \
271 ./$< >$@.tmp $(BUNDLED_SOURCES_LINKS); \
276 @echo Bundled sources.
278 #---------- svg processing ----------
280 LIBRARIES ?= $(basename $(wildcard library/*.toml))
281 USVG_DEP = stamp/cargo.usvg
283 include $(addsuffix /files.make, $(LIBRARIES))
285 USVG_PROCESSOR = usvg-processor
286 LIBRARY_PROCESS_SVG = ./$(USVG_PROCESSOR) $@ $(wordlist 1,2,$^) '$(USVG_CMD) $(USVG_OPTIONS)'
287 $(LIBRARY_FILES): $(USVG_PROCESSOR) $(USVG_DEP) $(MAKEFILE_DEP)
289 # actual command for each of $(LIBRARY_FILES) is in one of the files.make
291 library/%/files.make: media-scraper library/%.toml
292 ./$< --offline library/$*.toml
294 #---------- typescript ----------
296 templates/%.js: tsc-wrap tsconfig.json
297 ./tsc-wrap $@ tsconfig.json $(filter %.ts,$^)
299 templates/script.js: $(TS_SRC_FILES) stamp/wasm-bindgen
301 #---------- other templates ----------
303 $(addprefix templates/,$(LITFILES)): templates/%: %
304 cp $< $@.new && mv -f $@.new $@
306 $(addprefix templates/,$(TXTFILES)): templates/%: %.txt
307 cp $< $@.new && mv -f $@.new $@
309 libraries: $(LIBRARY_FILES)
311 templates/shapelib.html: $(TARGET_DIR)/debug/otterlib $(LIBRARY_FILES)
312 $(NAILING_CARGO_JUST_RUN) $(abspath $<) \
313 --libs '$(addprefix $(PWD)/, $(addsuffix .toml, $(LIBRARIES)))' \
314 preview >$@.tmp && mv -f $@.tmp $@
316 #---------- webdriver tests (wdt) ----------
318 AT_TESTS := $(basename $(notdir $(wildcard apitest/at-*.rs)))
319 WDT_TESTS := $(basename $(notdir $(wildcard wdriver/wdt-*.rs)))
321 WDT_LANDSCAPE_TESTS = wdt-altergame
323 at: $(foreach f, $(AT_TESTS), stamp/$f.check)
325 wdt: $(foreach f, $(WDT_TESTS), stamp/$f.check) \
326 $(foreach f, $(WDT_LANDSCAPE_TESTS), stamp/$f.lcheck) \
328 RUNTEST_DEPS = apitest/run1 stamp/cargo.debug $(FILEASSETS) \
329 $(wildcard libraries/*.toml) $(LIBRARY_FILES)
331 AT_DEPS = $(filter-out templates/script.js, $(RUNTEST_DEPS)) \
334 WDT_DEPS = $(RUNTEST_DEPS) \
335 stamp/cargo-wdt.debug
337 AT_WDT_RUN = $(NAILING_CARGO_JUST_RUN) $(abspath $<)
339 AT_RUN = $(AT_WDT_RUN) $(basename $(notdir $@))
340 WDT_RUN = $(AT_WDT_RUN) wdriver --test=$(basename $(notdir $@))
343 stamp/at-%.check: $(AT_DEPS)
348 stamp/wdt-%.check: $(WDT_DEPS)
352 stamp/wdt-%.lcheck: $(WDT_DEPS)
353 $(WDT_RUN) --as-if=lwdt-$* --layout=Landscape
356 #---------- deployment ----------
358 DEPLOY_USER=ian@login.chiark.greenend.org.uk
359 DEPLOY_BASE=$(DEPLOY_USER):/volatile/Otter
360 DEPLOY_FINISH=/home/Otter/etc/deploy-finish
362 for-deploy: stamp/cargo.deploy-build
363 deploy: for-deploy bundled-sources assets libraries
364 rsync -zv --progress $(addprefix $(DEPLOY_TARGET_DIR)/,$(PROGRAMS)) $(DEPLOY_BASE)/bin/
365 rsync -rv --progress $(TARGET_DIR)/bundled-sources/. $(DEPLOY_BASE)/bundled-sources
366 rsync -r README.md $(DEPLOY_BASE)/.
367 rsync -r --delete --exclude=\*~ library specs $(DEPLOY_BASE)/.
368 rsync -r $(FILEASSETS) $(addprefix $(WASM_PACKED)/, $(WASM_ASSETS)) \
369 $(DEPLOY_BASE)/assets/
370 rsync -r nwtemplates/*.tera $(DEPLOY_BASE)/nwtemplates/
371 ssh -o BatchMode=true $(DEPLOY_USER) $(DEPLOY_FINISH)
372 git branch -f $(DEPLOYED_BRANCH)
373 -git push origin master
374 -git push chiark master
376 #$(DEPLOY_BASE)/bundled-sources
378 #---------- clean ----------
381 rm -f templates/script.js library/*/*.usvg stamp/*
382 rm -rf $(LIBRARY_CLEAN)
383 find * -name '*~' -print0 | xargs -0r rm --
385 clean: clean-nailing clean-for-retest
387 $(NAILING_CARGO_JUST_RUN) rm -rf target