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
16 everything: debug doc release check bundled-sources
18 shapelib: templates/shapelib.html stamp/cargo.doc-otter-only
19 @echo 'Now you can visit these in your web browser:'
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 ----------
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 $(if $(wildcard $(BUILD_SUBDIR)/$2),
100 $(shell echo >&2 'Makefile: lp: Using program $4 from $(BUILD_SUBDIR)/$2')
101 $1 := $(abspath $(BUILD_SUBDIR)/$2/target/$3/$4)
102 $(abspath $(BUILD_SUBDIR)/$2/target/$3/$4):; cd ../$2 && $$(CARGO) build $(call cr,$3)
103 BUNDLED_SOURCES_DIRS += $2
104 BUNDLED_SOURCES_LINKS += $2/
108 $(eval $(call lp,BUNDLE_SOURCES,bundle-sources,debug,bundle-rust-sources))
109 $(eval $(call lp,USVG,resvg,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.check at wdt
141 @echo 'All tests passed.'
143 doc: cargo-doc sphinx-doc
145 debug release:: %: stamp/cargo.% assets libraries extra-%
147 cargo: cargo-debug cargo-wasm-release
149 cargo-debug cargo-release cargo-check cargo-doc \
150 cargo-wasm-debug cargo-wasm-release:: \
151 cargo-%: stamp/cargo.%
153 cargo-wasm: cargo-wasm-release
155 wasm: stamp/wasm-bindgen
157 assets: js stamp/wasm-bindgen $(FILEASSETS)
159 js: templates/script.js
162 extra-release: bundled-sources
164 cargo-syntaxcheck: cargo-syntaxcheck-host cargo-syntaxcheck-wasm
165 cargo-syntaxcheck-host:
166 $(CARGO) check --workspace
167 cargo-syntaxcheck-wasm:
168 $(CARGO) check --target $(WASM) -p otter-wasm --release
169 cargo-syntaxcheck-release:
170 $(CARGO) check --workspace --release
172 #---------- cargo ----------
175 CARGOES=$(foreach t, wasm-,$(addprefix $t,check $(DR)))
177 $(addprefix stamp/cargo.,$(DR)):: \
178 stamp/cargo.%: $(call rsrcs,. ! -path './wasm/*')
179 $(CARGO) build --workspace $(call cr,$*) -p otter -p otter-daemon
182 $(TARGET_DIR)/debug/%: $(call rsrcs, ! -path './wasm/*')
183 $(CARGO) build --workspace -p otter --bin $*
185 stamp/cargo.wasm-bindgen: $(call rsrcs, ! -name \*.rs)
186 $(CARGO) $(WASM_BINDGEN_CLI_CARGO_OPTS) build --target-dir=target \
187 --manifest-path=$(abspath wasm/Cargo.toml) -p wasm-bindgen-cli
190 stamp/cargo.check: $(call rsrcs,.)
191 $(CARGO) test --workspace
194 stamp/cargo-at.debug: $(call rsrcs,.)
195 $(CARGO) build --workspace $(call cr,$*) -p otter-api-tests
198 stamp/cargo-wdt.debug: $(call rsrcs,.)
199 $(CARGO) build --workspace $(call cr,$*) -p otter-webdriver-tests
202 stamp/cargo.doc: $(call rsrcs,.)
203 $(CARGO) doc $(CARGO_DOC_OPTS) --workspace 2>&1 |egrep -vf .cargo-doc-suppress-errors
206 stamp/cargo.doc-otter-only: $(call rsrcs,.)
207 $(CARGO) doc $(CARGO_DOC_OPTS) --workspace -p otter --no-deps
210 $(addprefix stamp/cargo.wasm-,$(DR)):: \
211 stamp/cargo.wasm-%: $(call rsrcs, base wasm Cargo.*)
212 $(CARGO) build --target $(WASM) -p otter-wasm $(call cr,$*)
215 stamp/cargo.deploy-build: $(call rsrcs,.)
216 $(CARGO) -T$(DEPLOY_ARCH) build $(call cr,$(DEPLOY_RELEASE)) -p otter -p otter-daemon
219 #---------- sphnix ----------
221 sphinx-doc: docs/html/index.html
223 docs/html/index.html: docs/conf.py $(wildcard docs/*.md docs/*.rst)
224 $(SPHINXBUILD) -M html docs docs $(SPHINXOPTS)
226 #---------- wasm ----------
228 $(addprefix $(WASM_PACKED)/,$(WASM_ASSETS) $(WASM_OUTPUTS)): stamp/wasm-bindgen
229 stamp/wasm-bindgen: stamp/cargo.wasm-bindgen stamp/cargo.wasm-release
230 $(NAILING_CARGO_JUST_RUN) $(abspath $(WASM_BINDGEN)) \
231 $(WASM_BINDGEN_OPTIONS) --out-dir target/packed-wasm \
232 target/$(WASM)/release/otter_wasm.wasm
235 #---------- bundle-sources ----------
237 BUNDLED_SOURCES_DIRS += otter
239 bundled-sources:: $(addprefix bundled-sources/, $(BUNDLED_SOURCES_DIRS))
241 TARGET_BUNDLED=$(TARGET_DIR)/bundled-sources
243 $(addprefix bundled-sources/, $(BUNDLED_SOURCES_DIRS)): \
244 bundled-sources/%: $(wildcard $(BUNDLE_SOURCES))
245 set -e; d=$(abspath $(TARGET_BUNDLED)); \
246 $(NAILING_CARGO_JUST_RUN) mkdir -p $$d; \
247 $(if $(filter-out otter,$*), cd ../$*;) \
248 $(BUNDLE_SOURCES_CMD) --output $$d/$*
250 bundled-sources:: $(addprefix $(TARGET_BUNDLED)/, $(BUNDLED_SOURCES_FILES))
252 $(addprefix $(TARGET_BUNDLED)/, $(BUNDLED_SOURCES_LIT)): $(TARGET_BUNDLED)/%: %
253 $(NAILING_CARGO_JUST_RUN) cp $(abspath $(src))/$< $(abspath $@)
255 $(TARGET_BUNDLED)/index.html: bundled-sources-make-index $(MAKEFILE_DEP)
256 $(NAILING_CARGO_JUST_RUN) sh -ec ' \
257 cd $(abspath $(src)); mkdir -p $(dir $@); \
258 ./$< >$@.tmp $(BUNDLED_SOURCES_LINKS); \
263 @echo Bundled sources.
265 #---------- svg processing ----------
267 LIBRARIES ?= $(basename $(wildcard library/*.toml))
269 include $(addsuffix /files.make, $(LIBRARIES))
271 USVG_PROCESSOR = usvg-processor
272 LIBRARY_PROCESS_SVG = ./$(USVG_PROCESSOR) $@ $(wordlist 1,2,$^) '$(USVG_CMD) $(USVG_OPTIONS)'
273 $(LIBRARY_FILES): $(USVG_PROCESSOR) $(USVG_BINARY) $(MAKEFILE_DEP)
275 # actual command for each of $(LIBRARY_FILES) is in one of the files.make
277 library/%/files.make: media-scraper library/%.toml
278 ./$< --offline library/$*.toml
280 #---------- typescript ----------
282 templates/%.js: tsc-wrap tsconfig.json
283 ./tsc-wrap $@ tsconfig.json $(filter %.ts,$^)
285 templates/script.js: $(TS_SRC_FILES) stamp/wasm-bindgen
287 #---------- other templates ----------
289 $(addprefix templates/,$(LITFILES)): templates/%: %
290 cp $< $@.new && mv -f $@.new $@
292 $(addprefix templates/,$(TXTFILES)): templates/%: %.txt
293 cp $< $@.new && mv -f $@.new $@
295 libraries: $(LIBRARY_FILES)
297 templates/shapelib.html: $(TARGET_DIR)/debug/otterlib $(LIBRARY_FILES)
298 $(NAILING_CARGO_JUST_RUN) $(abspath $<) \
299 --libs '$(addprefix $(PWD)/, $(addsuffix .toml, $(LIBRARIES)))' \
300 preview >$@.tmp && mv -f $@.tmp $@
302 #---------- webdriver tests (wdt) ----------
304 AT_TESTS := $(basename $(notdir $(wildcard apitest/at-*.rs)))
305 WDT_TESTS := $(basename $(notdir $(wildcard wdriver/wdt-*.rs)))
307 WDT_LANDSCAPE_TESTS = wdt-altergame
309 at: $(foreach f, $(AT_TESTS), stamp/$f.check)
311 wdt: $(foreach f, $(WDT_TESTS), stamp/$f.check) \
312 $(foreach f, $(WDT_LANDSCAPE_TESTS), stamp/$f.lcheck) \
314 RUNTEST_DEPS = apitest/run1 stamp/cargo.debug $(FILEASSETS) \
315 $(wildcard libraries/*.toml) $(LIBRARY_FILES)
317 AT_DEPS = $(filter-out templates/script.js, $(RUNTEST_DEPS)) \
320 WDT_DEPS = $(RUNTEST_DEPS) \
321 stamp/cargo-wdt.debug
323 AT_WDT_RUN = $(NAILING_CARGO_JUST_RUN) $(abspath $<)
325 AT_RUN = $(AT_WDT_RUN) $(basename $(notdir $@))
326 WDT_RUN = $(AT_WDT_RUN) wdriver --test=$(basename $(notdir $@))
329 stamp/at-%.check: $(AT_DEPS)
334 stamp/wdt-%.check: $(WDT_DEPS)
338 stamp/wdt-%.lcheck: $(WDT_DEPS)
339 $(WDT_RUN) --as-if=lwdt-$* --layout=Landscape
342 #---------- deployment ----------
344 DEPLOY_USER=ian@login.chiark.greenend.org.uk
345 DEPLOY_BASE=$(DEPLOY_USER):/volatile/Otter
346 DEPLOY_FINISH=/home/Otter/etc/deploy-finish
348 deploy: stamp/cargo.deploy-build bundled-sources assets libraries
349 rsync -zv --progress $(addprefix $(DEPLOY_TARGET_DIR)/,$(PROGRAMS)) $(DEPLOY_BASE)/bin/
350 rsync -rv --progress $(TARGET_DIR)/bundled-sources/. $(DEPLOY_BASE)/bundled-sources
351 rsync -r README.md $(DEPLOY_BASE)/.
352 rsync -r --delete --exclude=\*~ library specs $(DEPLOY_BASE)/.
353 rsync -r $(FILEASSETS) $(addprefix $(WASM_PACKED)/, $(WASM_ASSETS)) \
354 $(DEPLOY_BASE)/assets/
355 rsync -r nwtemplates/*.tera $(DEPLOY_BASE)/nwtemplates/
356 ssh -o BatchMode=true $(DEPLOY_USER) $(DEPLOY_FINISH)
357 git branch -f $(DEPLOYED_BRANCH)
358 -git push origin master
359 -git push chiark master
361 #$(DEPLOY_BASE)/bundled-sources
363 #---------- clean ----------
366 rm -f templates/script.js library/*/*.usvg stamp/*
367 rm -rf $(LIBRARY_CLEAN)
368 find * -name '*~' -print0 | xargs -0r rm --
370 clean: clean-nailing clean-for-retest
372 $(NAILING_CARGO_JUST_RUN) rm -rf target