1 # Copyright 2020-2021 Ian Jackson and contributors to Otter
2 # SPDX-License-Identifier: AGPL-3.0-or-later
3 # There is NO WARRANTY.
14 full-check: all check cargo-syntaxcheck-release shapelib doc-sphinx
15 full-check: for-deploy release
16 everything: debug doc release check bundled-sources
18 shapelib: templates/shapelib.html stamp/cargo.doc-otter-only
19 @echo 'Shape library preview and docs can now be found here:'
20 @echo ' file://$(PWD)/$<'
21 @echo ' file://$(abspath $(TARGET_DIR)/doc/otter/shapelib_toml/index.html)'
23 MAKEFILE_DEP ?= Makefile
25 # ^ set this to "x" to debug the $rsrcs rune
27 #---------- funky macros etc. ----------
29 cr = $(addprefix --,$(filter-out debug,$1))
30 rsrcs = $(shell $(foreach x,$(MAKEFILE_FIND_X),set -$x;)\
31 find -H $1 \( -name Cargo.toml -o -name Cargo.lock -o -name Cargo.lock.example -o -name \*.rs \) \! -path '*/build/*' )
32 stamp=@mkdir -p stamp; touch $@
34 BUNDLED_SOURCES_LIT = README.md LICENCE
35 BUNDLED_SOURCES_FILES = index.html $(BUNDLED_SOURCES_LIT)
36 BUNDLED_SOURCES_LINKS += $(BUNDLED_SOURCES_LIT) otter/
37 BUNDLED_SOURCES += $(BUNDLED_SOURCES_FILES)
39 #---------- programs and config variables ----------
44 USVG_OPTIONS = "--sans-serif-family=DejaVu Sans"
46 WASM_BINDGEN = $(TARGET_DIR)/debug/wasm-bindgen
47 WASM_BINDGEN_OPTIONS = \
48 --remove-name-section --remove-producers-section \
49 --typescript --no-modules \
51 BUNDLE_SOURCES ?= bundle-rust-sources
53 SPHINXBUILD = sphinx-build
55 ifndef INKSCAPE_EXTENSIONS
57 # inkscape 0.92.4: --extension-directory works, no --system-data-directory
58 # inkscape 1.0.2: --system-data-directory, no --extension-directory
59 INKSCAPE_EXTENSIONS := $(shell set -e; { sdd=$$( $(INKSCAPE) --system-data-directory ) && echo "$$sdd/extensions"; } || $(INKSCAPE) --extension-directory )
61 RECOLOUR_SVG ?= ./run-inkscape-extension $(INKSCAPE_EXTENSIONS)/color_replace.py
63 DEPLOY_ARCH=x86_64-unknown-linux-musl
65 DEPLOY_TARGET_DIR=$(TARGET_DIR)/$(addsuffix /,$(DEPLOY_ARCH))$(DEPLOY_RELEASE)
66 DEPLOYED_BRANCH=deployed
67 PUBLISHED_BRANCH=published
69 #---------- nailing-cargo ----------
71 ifneq (,$(wildcard ../Cargo.nail))
73 NAILING_CARGO = nailing-cargo
74 CARGO = $(NAILING_CARGO)
75 BUILD_SUBDIR ?= ../Build
76 TARGET_DIR = $(BUILD_SUBDIR)/$(notdir $(PWD))/target
78 NAILING_CARGO_JUST_RUN ?= $(NAILING_CARGO) --just-run -q ---
79 BUNDLE_SOURCES_CMD ?= $(NAILING_CARGO) --- $(BUNDLE_SOURCES)
80 USVG_CMD ?= $(NAILING_CARGO_JUST_RUN) $(USVG)
81 WASM_BINDGEN_CLI_CARGO_OPTS ?= --subcommand-props=!manifest-path
84 $(NAILING_CARGO_JUST_RUN) \
85 sh -c 'cd "$1"; find -mindepth 1 -maxdepth 1 -print0 | xargs -0r rm -rf --' \
86 $(abspath $(BUILD_SUBDIR)/$(notdir $(PWD)))
92 BUILD_SUBDIR ?= ../Build
93 BUNDLE_SOURCES_CMD ?= $(BUNDLE_SOURCES)
96 WASM_PACKED=$(TARGET_DIR)/packed-wasm
98 #---------- local programs ----------
101 stamp/cargo.$2: $(call rsrcs, ! -name \*.rs)
102 $$(CARGO) build $(call cr,$3) -p $2
104 $1 := $(abspath $(TARGET_DIR)/$3/$4)
107 $(eval $(call lp,BUNDLE_SOURCES,bundle-sources,debug,bundle-rust-sources))
108 $(eval $(call lp,USVG,usvg,release,usvg))
110 #---------- variables defining bits of source etc. ----------
112 PROGRAMS=daemon-otter otter
114 WASM_ASSETS := $(addprefix otter_wasm,.js _bg.wasm)
115 WASM_OUTPUTS := $(addprefix otter_wasm,.d.ts)
119 $(addprefix templates/,$(addsuffix .ts,$(TS_SRCS))) \
120 webassembly-types/webassembly.d.ts \
121 $(WASM_PACKED)/otter_wasm.d.ts
123 LITFILES= LICENCE AGPLv3
124 TXTFILES= CC-BY-SA-3.0 CC-BY-SA-4.0
126 FILEASSETS = $(addprefix templates/, libre shapelib.html script.js \
127 $(LITFILES) $(TXTFILES)) \
128 $(wildcard templates/*.tera)
130 WASM := wasm32-unknown-unknown
131 # ^ todo: Is this still right after
132 # Use correct ABI for wasm32 by default
133 # https://github.com/rust-lang/rust/pull/79998
134 # ? But maybe it doesn't matter since we're very conservative and
135 # only pass JsValue and a few strings across the WASM ABI.
137 #---------- toplevel aggregate targets ----------
139 check: stamp/cargo.debug-check at wdt
140 @echo 'Tests passed.'
142 full-check: stamp/cargo.release-check
143 full-check: stamp/cargo.release-miri stamp/cargo.debug-miri
146 @echo 'Full tests passed.'
148 doc: cargo-doc doc-sphinx
150 debug release:: %: stamp/cargo.% assets libraries extra-%
152 cargo: cargo-debug cargo-wasm-release
154 cargo-debug cargo-release cargo-check cargo-doc \
155 cargo-wasm-debug cargo-wasm-release:: \
156 cargo-%: stamp/cargo.%
158 cargo-wasm: cargo-wasm-release
160 wasm: stamp/wasm-bindgen
162 assets: js stamp/wasm-bindgen $(FILEASSETS)
164 js: templates/script.js
167 extra-release: bundled-sources
169 cargo-syntaxcheck: cargo-syntaxcheck-host cargo-syntaxcheck-wasm
170 cargo-syntaxcheck-host:
171 $(CARGO) check --workspace
172 cargo-syntaxcheck-wasm:
173 $(CARGO) check --target $(WASM) -p otter-wasm --release
174 cargo-syntaxcheck-release:
175 $(CARGO) check --workspace --release
177 #---------- cargo ----------
180 CARGOES=$(foreach t, wasm-,$(addprefix $t,check $(DR)))
182 $(addprefix stamp/cargo.,$(DR)):: \
183 stamp/cargo.%: $(call rsrcs,. ! -path './wasm/*')
184 $(CARGO) build --workspace $(call cr,$*) -p otter -p otter-daemon
187 $(TARGET_DIR)/debug/%: $(call rsrcs, ! -path './wasm/*')
188 $(CARGO) build --workspace -p otter --bin $*
190 stamp/cargo.wasm-bindgen: $(call rsrcs, ! -name \*.rs)
191 $(CARGO) $(WASM_BINDGEN_CLI_CARGO_OPTS) build --target-dir=target \
192 --manifest-path=$(abspath wasm/Cargo.toml) -p wasm-bindgen-cli
195 stamp/cargo.%-check: $(call rsrcs,.)
196 $(CARGO) test --workspace $(call cr,$*)
199 stamp/cargo.%-miri: $(call rsrcs,.)
200 $(CARGO) miri test --workspace $(call cr,$*)
203 stamp/cargo-at.debug: $(call rsrcs,.)
204 $(CARGO) build --workspace $(call cr,$*) -p otter-api-tests
207 stamp/cargo-wdt.debug: $(call rsrcs,.)
208 $(CARGO) build --workspace $(call cr,$*) -p otter-webdriver-tests
211 stamp/cargo.doc: $(call rsrcs,.)
212 $(CARGO) doc $(CARGO_DOC_OPTS) --workspace 2>&1 |egrep -vf .cargo-doc-suppress-errors
215 stamp/cargo.doc-otter-only: $(call rsrcs,.)
216 $(CARGO) doc $(CARGO_DOC_OPTS) --workspace -p otter --no-deps
219 $(addprefix stamp/cargo.wasm-,$(DR)):: \
220 stamp/cargo.wasm-%: $(call rsrcs, base wasm Cargo.*)
221 $(CARGO) build --target $(WASM) -p otter-wasm $(call cr,$*)
224 stamp/cargo.deploy-build: $(call rsrcs,.)
225 $(CARGO) build --target $(DEPLOY_ARCH) $(call cr,$(DEPLOY_RELEASE)) -p otter -p otter-daemon
228 #---------- sphnix ----------
230 doc-sphinx: docs/html/index.html
231 @echo 'Documentation can now be found here:'
232 @echo ' file://$(PWD)/$<'
234 docs/html/index.html: docs/conf.py $(wildcard docs/*.md docs/*.rst)
235 $(SPHINXBUILD) -M html docs docs $(SPHINXOPTS)
237 #---------- wasm ----------
239 $(addprefix $(WASM_PACKED)/,$(WASM_ASSETS) $(WASM_OUTPUTS)): stamp/wasm-bindgen
240 stamp/wasm-bindgen: stamp/cargo.wasm-bindgen stamp/cargo.wasm-release
241 $(NAILING_CARGO_JUST_RUN) $(abspath $(WASM_BINDGEN)) \
242 $(WASM_BINDGEN_OPTIONS) --out-dir target/packed-wasm \
243 target/$(WASM)/release/otter_wasm.wasm
246 #---------- bundle-sources ----------
248 BUNDLED_SOURCES_DIRS += otter
250 bundled-sources:: $(addprefix bundled-sources/, $(BUNDLED_SOURCES_DIRS))
252 TARGET_BUNDLED=$(TARGET_DIR)/bundled-sources
255 $(NAILING_CARGO_JUST_RUN) mkdir -p $@
257 $(addprefix bundled-sources/, $(BUNDLED_SOURCES_DIRS)): \
258 bundled-sources/%: stamp/cargo.bundle-sources $(TARGET_BUNDLED)
259 set -e; d=$(abspath $(TARGET_BUNDLED)); \
260 $(if $(filter-out otter,$*), cd ../$*;) \
261 $(BUNDLE_SOURCES_CMD) --output $$d/$*
263 bundled-sources:: $(addprefix $(TARGET_BUNDLED)/, $(BUNDLED_SOURCES_FILES))
265 $(addprefix $(TARGET_BUNDLED)/, $(BUNDLED_SOURCES_LIT)): \
266 $(TARGET_BUNDLED)/%: % $(TARGET_BUNDLED)
267 $(NAILING_CARGO_JUST_RUN) cp $(abspath $(src))/$< $(abspath $@)
269 $(TARGET_BUNDLED)/index.html: bundled-sources-make-index \
270 $(MAKEFILE_DEP) $(TARGET_BUNDLED)
271 $(NAILING_CARGO_JUST_RUN) sh -ec ' \
272 cd $(abspath $(src)); mkdir -p $(dir $@); \
273 ./$< >$@.tmp $(BUNDLED_SOURCES_LINKS); \
278 @echo Bundled sources.
280 #---------- svg processing ----------
282 LIBRARIES ?= $(basename $(wildcard library/*.toml))
283 USVG_DEP = stamp/cargo.usvg
285 include $(addsuffix /files.make, $(LIBRARIES))
287 USVG_PROCESSOR = usvg-processor
288 LIBRARY_PROCESS_SVG = ./$(USVG_PROCESSOR) $@ $(wordlist 1,2,$^) '$(USVG_CMD) $(USVG_OPTIONS)'
289 $(LIBRARY_FILES): $(USVG_PROCESSOR) $(USVG_DEP) $(MAKEFILE_DEP)
291 # actual command for each of $(LIBRARY_FILES) is in one of the files.make
293 library/%/files.make: media-scraper library/%.toml
294 ./$< --offline library/$*.toml
296 #---------- typescript ----------
298 templates/%.js: tsc-wrap tsconfig.json
299 ./tsc-wrap $@ tsconfig.json $(filter %.ts,$^)
301 templates/script.js: $(TS_SRC_FILES) stamp/wasm-bindgen
303 #---------- other templates ----------
305 $(addprefix templates/,$(LITFILES)): templates/%: %
306 cp $< $@.new && mv -f $@.new $@
308 $(addprefix templates/,$(TXTFILES)): templates/%: %.txt
309 cp $< $@.new && mv -f $@.new $@
311 libraries: $(LIBRARY_FILES)
313 templates/shapelib.html: $(TARGET_DIR)/debug/otterlib $(LIBRARY_FILES)
314 $(NAILING_CARGO_JUST_RUN) $(abspath $<) \
315 --libs '$(addprefix $(PWD)/, $(addsuffix .toml, $(LIBRARIES)))' \
316 preview >$@.tmp && mv -f $@.tmp $@
318 #---------- webdriver tests (wdt) ----------
320 AT_TESTS := $(basename $(notdir $(wildcard apitest/at-*.rs)))
321 WDT_TESTS := $(basename $(notdir $(wildcard wdriver/wdt-*.rs)))
323 WDT_LANDSCAPE_TESTS = wdt-altergame
325 at: $(foreach f, $(AT_TESTS), stamp/$f.check)
327 wdt: $(foreach f, $(WDT_TESTS), stamp/$f.check) \
328 $(foreach f, $(WDT_LANDSCAPE_TESTS), stamp/$f.lcheck) \
330 RUNTEST_DEPS = apitest/run1 stamp/cargo.debug $(FILEASSETS) \
331 $(wildcard libraries/*.toml) $(LIBRARY_FILES)
333 AT_DEPS = $(filter-out templates/script.js, $(RUNTEST_DEPS)) \
336 WDT_DEPS = $(RUNTEST_DEPS) \
337 stamp/cargo-wdt.debug
339 AT_WDT_RUN = $(NAILING_CARGO_JUST_RUN) $(abspath $<)
341 AT_RUN = $(AT_WDT_RUN) $(basename $(notdir $@))
342 WDT_RUN = $(AT_WDT_RUN) wdriver --test=$(basename $(notdir $@))
345 stamp/at-%.check: $(AT_DEPS)
350 stamp/wdt-%.check: $(WDT_DEPS)
354 stamp/wdt-%.lcheck: $(WDT_DEPS)
355 $(WDT_RUN) --as-if=lwdt-$* --layout=Landscape
358 #---------- docs publication ----------
360 PUBLISH_USER=ianmdlvl@login.chiark.greenend.org.uk
361 PUBLISH_DOC_SPHINX=$(PUBLISH_USER):public-html/otter/docs
364 rsync -r --delete-delay docs/html/. $(PUBLISH_DOC_SPHINX)/.
365 git branch -f $(PUBLISHED_BRANCH)
367 #---------- deployment ----------
369 DEPLOY_USER=ian@login.chiark.greenend.org.uk
370 DEPLOY_BASE=$(DEPLOY_USER):/volatile/Otter
371 DEPLOY_FINISH=/home/Otter/etc/deploy-finish
373 for-deploy: stamp/cargo.deploy-build
374 deploy: for-deploy bundled-sources assets libraries
375 rsync -zv --progress $(addprefix $(DEPLOY_TARGET_DIR)/,$(PROGRAMS)) $(DEPLOY_BASE)/bin/
376 rsync -rv --progress $(TARGET_DIR)/bundled-sources/. $(DEPLOY_BASE)/bundled-sources
377 rsync -r README.md $(DEPLOY_BASE)/.
378 rsync -r --delete --exclude=\*~ library specs $(DEPLOY_BASE)/.
379 rsync -r $(FILEASSETS) $(addprefix $(WASM_PACKED)/, $(WASM_ASSETS)) \
380 $(DEPLOY_BASE)/assets/
381 rsync -r nwtemplates/*.tera $(DEPLOY_BASE)/nwtemplates/
382 ssh -o BatchMode=true $(DEPLOY_USER) $(DEPLOY_FINISH)
383 git branch -f $(DEPLOYED_BRANCH)
384 -git push origin master
385 -git push chiark master
387 #$(DEPLOY_BASE)/bundled-sources
389 #---------- clean ----------
392 rm -f templates/script.js library/*/*.usvg stamp/*
393 rm -rf $(LIBRARY_CLEAN)
394 find * -name '*~' -print0 | xargs -0r rm --
396 clean: clean-nailing clean-for-retest
398 $(NAILING_CARGO_JUST_RUN) rm -rf target