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 0.92.4: --extension-directory works, no --system-data-directory
59 # inkscape 1.0.2: --system-data-directory, no --extension-directory
60 INKSCAPE_EXTENSIONS := $(shell set -e; { sdd=$$( $(INKSCAPE) --system-data-directory ) && echo "$$sdd/extensions"; } || $(INKSCAPE) --extension-directory )
62 RECOLOUR_SVG ?= $(INKSCAPE_EXTENSIONS)/color_replace.py
64 DEPLOY_ARCH=x86_64-unknown-linux-musl
66 DEPLOY_TARGET_DIR=$(TARGET_DIR)/$(addsuffix /,$(DEPLOY_ARCH))$(DEPLOY_RELEASE)
67 DEPLOYED_BRANCH=deployed
68 PUBLISHED_BRANCH=published
70 #---------- nailing-cargo ----------
72 ifneq (,$(wildcard ../Cargo.nail))
74 NAILING_CARGO = nailing-cargo
75 CARGO = $(NAILING_CARGO)
76 BUILD_SUBDIR ?= ../Build
77 TARGET_DIR = $(BUILD_SUBDIR)/$(notdir $(PWD))/target
79 NAILING_CARGO_JUST_RUN ?= $(NAILING_CARGO) --just-run -q ---
80 BUNDLE_SOURCES_CMD ?= $(NAILING_CARGO) --- $(BUNDLE_SOURCES)
81 USVG_CMD ?= $(NAILING_CARGO_JUST_RUN) $(USVG)
82 WASM_BINDGEN_CLI_CARGO_OPTS ?= --subcommand-props=!manifest-path
85 $(NAILING_CARGO_JUST_RUN) \
86 sh -c 'cd "$1"; find -mindepth 1 -maxdepth 1 -print0 | xargs -0r rm -rf --' \
87 $(abspath $(BUILD_SUBDIR)/$(notdir $(PWD)))
93 BUILD_SUBDIR ?= ../Build
94 BUNDLE_SOURCES_CMD ?= $(BUNDLE_SOURCES)
97 WASM_PACKED=$(TARGET_DIR)/packed-wasm
99 #---------- local programs ----------
102 stamp/cargo.$2: $(call rsrcs, ! -name \*.rs)
103 $$(CARGO) build $(call cr,$3) -p $2
105 $1 := $(abspath $(TARGET_DIR)/$3/$4)
108 $(eval $(call lp,BUNDLE_SOURCES,bundle-sources,debug,bundle-rust-sources))
109 $(eval $(call lp,USVG,usvg,release,usvg))
111 #---------- variables defining bits of source etc. ----------
113 PROGRAMS=daemon-otter otter
115 WASM_ASSETS := $(addprefix otter_wasm,.js _bg.wasm)
116 WASM_OUTPUTS := $(addprefix otter_wasm,.d.ts)
120 $(addprefix templates/,$(addsuffix .ts,$(TS_SRCS))) \
121 webassembly-types/webassembly.d.ts \
122 $(WASM_PACKED)/otter_wasm.d.ts
124 LITFILES= LICENCE AGPLv3
125 TXTFILES= CC-BY-SA-3.0 CC-BY-SA-4.0
127 FILEASSETS = $(addprefix templates/, libre shapelib.html script.js \
128 $(LITFILES) $(TXTFILES)) \
129 $(wildcard templates/*.tera)
131 WASM := wasm32-unknown-unknown
132 # ^ todo: Is this still right after
133 # Use correct ABI for wasm32 by default
134 # https://github.com/rust-lang/rust/pull/79998
135 # ? But maybe it doesn't matter since we're very conservative and
136 # only pass JsValue and a few strings across the WASM ABI.
138 #---------- toplevel aggregate targets ----------
140 check: stamp/cargo.debug-check at wdt
141 @echo 'Tests passed.'
143 full-check: stamp/cargo.release-check
144 full-check: stamp/cargo.release-miri stamp/cargo.debug-miri
147 @echo 'Full tests passed.'
149 doc: cargo-doc doc-sphinx
151 debug release:: %: stamp/cargo.% assets libraries extra-%
153 cargo: cargo-debug cargo-wasm-release
155 cargo-debug cargo-release cargo-check cargo-doc \
156 cargo-wasm-debug cargo-wasm-release:: \
157 cargo-%: stamp/cargo.%
159 cargo-wasm: cargo-wasm-release
161 wasm: stamp/wasm-bindgen
163 assets: js stamp/wasm-bindgen $(FILEASSETS)
165 js: templates/script.js
168 extra-release: bundled-sources
170 cargo-syntaxcheck: cargo-syntaxcheck-host cargo-syntaxcheck-wasm
171 cargo-syntaxcheck-host:
172 $(CARGO) check --workspace
173 cargo-syntaxcheck-wasm:
174 $(CARGO) check --target $(WASM) -p otter-wasm --release
175 cargo-syntaxcheck-release:
176 $(CARGO) check --workspace --release
178 #---------- cargo ----------
181 CARGOES=$(foreach t, wasm-,$(addprefix $t,check $(DR)))
183 $(addprefix stamp/cargo.,$(DR)):: \
184 stamp/cargo.%: $(call rsrcs,. ! -path './wasm/*')
185 $(CARGO) build --workspace $(call cr,$*) -p otter -p otter-daemon
188 $(TARGET_DIR)/debug/%: $(call rsrcs, ! -path './wasm/*')
189 $(CARGO) build --workspace -p otter --bin $*
191 stamp/cargo.wasm-bindgen: $(call rsrcs, ! -name \*.rs)
192 $(CARGO) $(WASM_BINDGEN_CLI_CARGO_OPTS) build --target-dir=target \
193 --manifest-path=$(abspath wasm/Cargo.toml) -p wasm-bindgen-cli
196 stamp/cargo.%-check: $(call rsrcs,.)
197 $(CARGO) test --workspace $(call cr,$*)
200 stamp/cargo.%-miri: $(call rsrcs,.)
201 $(CARGO) miri test --workspace $(call cr,$*)
204 stamp/cargo-at.debug: $(call rsrcs,.)
205 $(CARGO) build --workspace $(call cr,$*) -p otter-api-tests
208 stamp/cargo-wdt.debug: $(call rsrcs,.)
209 $(CARGO) build --workspace $(call cr,$*) -p otter-webdriver-tests
212 stamp/cargo.doc: $(call rsrcs,.)
213 $(CARGO) doc $(CARGO_DOC_OPTS) --workspace 2>&1 |egrep -vf .cargo-doc-suppress-errors
216 stamp/cargo.doc-otter-only: $(call rsrcs,.)
217 $(CARGO) doc $(CARGO_DOC_OPTS) --workspace -p otter --no-deps
220 $(addprefix stamp/cargo.wasm-,$(DR)):: \
221 stamp/cargo.wasm-%: $(call rsrcs, base wasm Cargo.*)
222 $(CARGO) build --target $(WASM) -p otter-wasm $(call cr,$*)
225 stamp/cargo.deploy-build: $(call rsrcs,.)
226 $(CARGO) build --target $(DEPLOY_ARCH) $(call cr,$(DEPLOY_RELEASE)) -p otter -p otter-daemon
229 #---------- sphnix ----------
231 doc-sphinx: docs/html/index.html
232 @echo 'Documentation can now be found here:'
233 @echo ' file://$(PWD)/$<'
235 docs/html/index.html: docs/conf.py $(wildcard docs/*.md docs/*.rst)
236 $(SPHINXBUILD) -M html docs docs $(SPHINXOPTS)
238 #---------- wasm ----------
240 $(addprefix $(WASM_PACKED)/,$(WASM_ASSETS) $(WASM_OUTPUTS)): stamp/wasm-bindgen
241 stamp/wasm-bindgen: stamp/cargo.wasm-bindgen stamp/cargo.wasm-release
242 $(NAILING_CARGO_JUST_RUN) $(abspath $(WASM_BINDGEN)) \
243 $(WASM_BINDGEN_OPTIONS) --out-dir target/packed-wasm \
244 target/$(WASM)/release/otter_wasm.wasm
247 #---------- bundle-sources ----------
249 BUNDLED_SOURCES_DIRS += otter
251 bundled-sources:: $(addprefix bundled-sources/, $(BUNDLED_SOURCES_DIRS))
253 TARGET_BUNDLED=$(TARGET_DIR)/bundled-sources
256 $(NAILING_CARGO_JUST_RUN) mkdir -p $@
258 $(addprefix bundled-sources/, $(BUNDLED_SOURCES_DIRS)): \
259 bundled-sources/%: stamp/cargo.bundle-sources $(TARGET_BUNDLED)
260 set -e; d=$(abspath $(TARGET_BUNDLED)); \
261 $(if $(filter-out otter,$*), cd ../$*;) \
262 $(BUNDLE_SOURCES_CMD) --output $$d/$*
264 bundled-sources:: $(addprefix $(TARGET_BUNDLED)/, $(BUNDLED_SOURCES_FILES))
266 $(addprefix $(TARGET_BUNDLED)/, $(BUNDLED_SOURCES_LIT)): \
267 $(TARGET_BUNDLED)/%: % $(TARGET_BUNDLED)
268 $(NAILING_CARGO_JUST_RUN) cp $(abspath $(src))/$< $(abspath $@)
270 $(TARGET_BUNDLED)/index.html: bundled-sources-make-index \
271 $(MAKEFILE_DEP) $(TARGET_BUNDLED)
272 $(NAILING_CARGO_JUST_RUN) sh -ec ' \
273 cd $(abspath $(src)); mkdir -p $(dir $@); \
274 ./$< >$@.tmp $(BUNDLED_SOURCES_LINKS); \
279 @echo Bundled sources.
281 #---------- svg processing ----------
283 LIBRARIES ?= $(basename $(wildcard library/*.toml))
284 USVG_DEP = stamp/cargo.usvg
286 include $(addsuffix /files.make, $(LIBRARIES))
288 USVG_PROCESSOR = usvg-processor
289 LIBRARY_PROCESS_SVG = ./$(USVG_PROCESSOR) $@ $(wordlist 1,2,$^) '$(USVG_CMD) $(USVG_OPTIONS)'
290 $(LIBRARY_FILES): $(USVG_PROCESSOR) $(USVG_DEP) $(MAKEFILE_DEP)
292 # actual command for each of $(LIBRARY_FILES) is in one of the files.make
294 library/%/files.make: media-scraper library/%.toml
295 ./$< --offline library/$*.toml
297 #---------- typescript ----------
299 templates/%.js: tsc-wrap tsconfig.json
300 ./tsc-wrap $@ tsconfig.json $(filter %.ts,$^)
302 templates/script.js: $(TS_SRC_FILES) stamp/wasm-bindgen
304 #---------- other templates ----------
306 $(addprefix templates/,$(LITFILES)): templates/%: %
307 cp $< $@.new && mv -f $@.new $@
309 $(addprefix templates/,$(TXTFILES)): templates/%: %.txt
310 cp $< $@.new && mv -f $@.new $@
312 libraries: $(LIBRARY_FILES)
314 templates/shapelib.html: $(TARGET_DIR)/debug/otterlib $(LIBRARY_FILES)
315 $(NAILING_CARGO_JUST_RUN) $(abspath $<) \
316 --libs '$(addprefix $(PWD)/, $(addsuffix .toml, $(LIBRARIES)))' \
317 preview >$@.tmp && mv -f $@.tmp $@
319 #---------- webdriver tests (wdt) ----------
321 AT_TESTS := $(basename $(notdir $(wildcard apitest/at-*.rs)))
322 WDT_TESTS := $(basename $(notdir $(wildcard wdriver/wdt-*.rs)))
324 WDT_LANDSCAPE_TESTS = wdt-altergame
326 at: $(foreach f, $(AT_TESTS), stamp/$f.check)
328 wdt: $(foreach f, $(WDT_TESTS), stamp/$f.check) \
329 $(foreach f, $(WDT_LANDSCAPE_TESTS), stamp/$f.lcheck) \
331 RUNTEST_DEPS = apitest/run1 stamp/cargo.debug $(FILEASSETS) \
332 $(wildcard libraries/*.toml) $(LIBRARY_FILES)
334 AT_DEPS = $(filter-out templates/script.js, $(RUNTEST_DEPS)) \
337 WDT_DEPS = $(RUNTEST_DEPS) \
338 stamp/cargo-wdt.debug
340 AT_WDT_RUN = $(NAILING_CARGO_JUST_RUN) $(abspath $<)
342 AT_RUN = $(AT_WDT_RUN) $(basename $(notdir $@))
343 WDT_RUN = $(AT_WDT_RUN) wdriver --test=$(basename $(notdir $@))
346 stamp/at-%.check: $(AT_DEPS)
351 stamp/wdt-%.check: $(WDT_DEPS)
355 stamp/wdt-%.lcheck: $(WDT_DEPS)
356 $(WDT_RUN) --as-if=lwdt-$* --layout=Landscape
359 #---------- docs publication ----------
361 PUBLISH_USER=ianmdlvl@login.chiark.greenend.org.uk
362 PUBLISH_DOC_SPHINX=$(PUBLISH_USER):public-html/otter/docs
365 rsync -r --delete-delay docs/html/. $(PUBLISH_DOC_SPHINX)/.
366 git branch -f $(PUBLISHED_BRANCH)
368 #---------- deployment ----------
370 DEPLOY_USER=ian@login.chiark.greenend.org.uk
371 DEPLOY_BASE=$(DEPLOY_USER):/volatile/Otter
372 DEPLOY_FINISH=/home/Otter/etc/deploy-finish
374 for-deploy: stamp/cargo.deploy-build
375 deploy: for-deploy bundled-sources assets libraries
376 rsync -zv --progress $(addprefix $(DEPLOY_TARGET_DIR)/,$(PROGRAMS)) $(DEPLOY_BASE)/bin/
377 rsync -rv --progress $(TARGET_DIR)/bundled-sources/. $(DEPLOY_BASE)/bundled-sources
378 rsync -r README.md $(DEPLOY_BASE)/.
379 rsync -r --delete --exclude=\*~ library specs $(DEPLOY_BASE)/.
380 rsync -r $(FILEASSETS) $(addprefix $(WASM_PACKED)/, $(WASM_ASSETS)) \
381 $(DEPLOY_BASE)/assets/
382 rsync -r nwtemplates/*.tera $(DEPLOY_BASE)/nwtemplates/
383 ssh -o BatchMode=true $(DEPLOY_USER) $(DEPLOY_FINISH)
384 git branch -f $(DEPLOYED_BRANCH)
385 -git push origin master
386 -git push chiark master
388 #$(DEPLOY_BASE)/bundled-sources
390 #---------- clean ----------
393 rm -f templates/script.js library/*/*.usvg stamp/*
394 rm -rf $(LIBRARY_CLEAN)
395 find * -name '*~' -print0 | xargs -0r rm --
397 clean: clean-nailing clean-for-retest
399 $(NAILING_CARGO_JUST_RUN) rm -rf target