| 1 | #!/usr/bin/make -f |
| 2 | |
| 3 | # resolve DEB_VERSION DEB_VERSION_UPSTREAM |
| 4 | include /usr/share/dpkg/pkg-info.mk |
| 5 | |
| 6 | # generate documentation unless nodoc requested |
| 7 | ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS))) |
| 8 | DOCS = README.html README.txt |
| 9 | endif |
| 10 | |
| 11 | export DEB_BUILD_MAINT_OPTIONS = hardening=+all |
| 12 | export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic |
| 13 | export DEB_CXXFLAGS_MAINT_APPEND = -Wall -pedantic |
| 14 | |
| 15 | # trust upstream optimization level unless explicitly disabled |
| 16 | ifeq (,$(filter noopt,$(DEB_BUILD_OPTIONS))) |
| 17 | export DEB_CFLAGS_MAINT_STRIP=-O2 |
| 18 | export DEB_CXXFLAGS_MAINT_STRIP=-O2 |
| 19 | endif |
| 20 | |
| 21 | # generate manual pages from output of clap-based Rust binary |
| 22 | # arguments: 1:MANFILEPATH 2:COMMANDPATH 3:SUBCOMMAND(S) |
| 23 | _help2man = \ |
| 24 | $(eval suffix = $(lastword $(subst ., ,$(1))))\ |
| 25 | $(eval stem = $(patsubst %.$(suffix),%,$(1)))\ |
| 26 | help2man --section $(suffix) --no-info \ |
| 27 | --version-string='$(DEB_VERSION_UPSTREAM)' \ |
| 28 | --name $(shell $(2) $(3) --help | head --lines=1 | xargs -0 shell-quote --) \ |
| 29 | --output '$(stem)$(if $(3),-$(subst $() ,-,$(strip $(3)))).$(suffix)' \ |
| 30 | '$(2)$(if $(3), $(3))' \ |
| 31 | || { $(2) $(3) --help; false; } |
| 32 | |
| 33 | mainpkg = wasm-tools |
| 34 | cmd = wasm-tools |
| 35 | subcmds_$(cmd) = \ |
| 36 | parse validate print smith shrink mutate dump objdump strip compose \ |
| 37 | demangle component metadata wit-smith addr2line json-from-wast wast |
| 38 | |
| 39 | # generate documentation unless nodoc requested |
| 40 | ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS))) |
| 41 | MANPAGES = $(cmd).1 |
| 42 | endif |
| 43 | |
| 44 | %: |
| 45 | dh $@ |
| 46 | |
| 47 | %.html: %.md |
| 48 | cmark-gfm $< > $@ |
| 49 | |
| 50 | %.txt: %.md |
| 51 | cmark-gfm --to plaintext $< > $@ |
| 52 | |
| 53 | execute_after_dh_auto_build: $(DOCS) |
| 54 | |
| 55 | execute_after_dh_auto_install-arch: debian/$(mainpkg)/usr/bin/$(cmd) $(MANPAGES) |
| 56 | mkdir --parents debian/build |
| 57 | $< completion bash > debian/build/bash-completion |
| 58 | $< completion zsh > debian/build/_$(cmd) |
| 59 | |
| 60 | # avoid cleaning unless source is patched |
| 61 | override_dh_auto_clean: |
| 62 | grep -q playground Cargo.toml || dh_auto_clean --buildsystem rust |
| 63 | |
| 64 | override_dh_installdocs: |
| 65 | dh_installdocs -- $(DOCS) |
| 66 | |
| 67 | override_dh_gencontrol: |
| 68 | dh_gencontrol -plibrust-wasm-tools-dev -- \ |
| 69 | -V'rust:Version:zero-based=$(patsubst 1.%,0.%,$(DEB_VERSION))' |
| 70 | dh_gencontrol --remaining-packages |
| 71 | |
| 72 | # build manpages |
| 73 | $(cmd).1: %.1: debian/$(mainpkg)/usr/bin/% |
| 74 | $(call _help2man,$@,$<) |
| 75 | set -e; $(foreach x,$(subcmds_$(cmd)),\ |
| 76 | $(call _help2man,$@,$<,$x);) |