kych

OAuth 2.0 API for Swiyu to enable Taler integration of Swiyu for KYC (experimental)
Log | Files | Refs | Submodules | README | LICENSE

Makefile (12168B)


      1 # This Makefile has been placed under the public domain
      2 
      3 # Written by ./configure.  The leading '-' keeps it optional, and it is
      4 # included BEFORE the '?=' defaults below, so a configured tree wins while a
      5 # plain 'make' in an unconfigured tree still builds with whatever is on $PATH.
      6 -include .config.mk
      7 
      8 # Defaults for an unconfigured tree.  No rustup required either way; any cargo
      9 # works, including an explicit override:
     10 #     make build cargo=/opt/rust/bin/cargo
     11 cargo ?= cargo
     12 prefix ?= /usr/local
     13 
     14 # Optional tools.  Empty means "not available": the man pages are then neither
     15 # built nor installed, and clippy is skipped by 'make check'.  ./configure
     16 # fills these in; see its output for what it found.
     17 sphinx_build ?=
     18 cargo_clippy ?= no
     19 
     20 # The SWIYU verifier is a second, foreign upstream (Java/Maven) in a submodule.
     21 # It is built only when ./configure said it could be -- see --enable-verifier.
     22 enable_verifier ?= no
     23 mvn ?=
     24 java_home ?=
     25 
     26 # Absolute DESTDIR, or the empty string when DESTDIR is unset/empty.
     27 abs_destdir = $(abspath $(DESTDIR))
     28 
     29 bin_dir = $(abs_destdir)$(prefix)/bin
     30 share_dir = $(abs_destdir)$(prefix)/share
     31 man_dir = $(share_dir)/man
     32 # $DATADIR as the configuration parser computes it: <prefix>/share/<project>,
     33 # with the project name "kych" (src/config.rs: ConfigSource::new("kych", ...)).
     34 # SQL_DIR defaults to "$DATADIR/sql", so a tree installed here needs no
     35 # configuration at all to find its schema.
     36 kych_data = $(share_dir)/kych
     37 verifier_data = $(share_dir)/swiyu-verifier
     38 
     39 # The crate root is a subdirectory, not the top of the tree, and it has one
     40 # path dependency which cargo builds along with it.
     41 crate = kych_oauth2_gateway
     42 vendored = taler-config
     43 release = $(crate)/target/release
     44 
     45 # The verifier's upstream checkout, and where its jar is staged under a name
     46 # that does not carry the version -- so that neither the install rules nor the
     47 # systemd unit change with every upstream release.
     48 verifier_src = swiyu-verifier/upstream
     49 verifier_jar = swiyu-verifier/jar/swiyu-verifier.jar
     50 
     51 # -DskipTests: upstream's own suite needs Testcontainers, hence a container
     52 # runtime.  -Dpgpverify.skip=true: upstream binds the pgpverify plugin to the
     53 # 'validate' phase, which checks every dependency's PGP signature against
     54 # public keyservers; it is upstream's documented escape hatch, and without it
     55 # the build needs keys.openpgp.org to be reachable.
     56 MAVEN_FLAGS ?= -B -DskipTests -Dpgpverify.skip=true
     57 
     58 # Man pages: generated here from the reStructuredText under
     59 # documentation/taler-docs/manpages, which is the single source shared with the
     60 # taler-docs repository.  A source tarball ships them pre-built in $(man_build),
     61 # so a build from a tarball needs no sphinx.
     62 man_build = doc/man
     63 man_sources = $(wildcard documentation/taler-docs/manpages/*.rst)
     64 # Keep these in step with man_pages in documentation/sphinx-man/conf.py.
     65 kych_man1 = kych-oauth2-gateway.1 kych-client-management.1 kych-dbinit.1 \
     66             kych-dbconfig.1
     67 kych_man5 = kych.conf.5
     68 verifier_man1 = swiyu-verifier.1 swiyu-verifier-dbconfig.1
     69 
     70 all: build
     71 
     72 .PHONY: help
     73 help:
     74 	@echo 'Targets:'
     75 	@echo '  build          build the gateway, the man pages and (if enabled) the verifier'
     76 	@echo '  check          run the test suites and, if available, clippy'
     77 	@echo '  install        install into $$(prefix), honouring $$(DESTDIR)'
     78 	@echo '  installcheck   smoke-test what install put in place'
     79 	@echo '  dist           build the kych-<version>.tar.gz source tarball'
     80 	@echo '  distcheck      build, test and install a tree unpacked from that tarball'
     81 	@echo '  deb            build the Debian packages'
     82 	@echo '  doc            cargo doc'
     83 	@echo '  fmt            cargo fmt'
     84 	@echo '  clean          remove build products'
     85 	@echo '  distclean      also remove ./configure output'
     86 	@echo
     87 	@echo "prefix = $(prefix), verifier = $(enable_verifier)"
     88 
     89 # ---------------------------------------------------------------- build
     90 
     91 .PHONY: build
     92 build: gateway man
     93 ifeq ($(strip $(enable_verifier)),yes)
     94 build: verifier
     95 endif
     96 
     97 .PHONY: gateway
     98 gateway:
     99 	$(cargo) build --release --manifest-path $(crate)/Cargo.toml
    100 
    101 # The stamp exists because sphinx-build has no single output file to depend on
    102 # and there are seven of them; it keeps a second 'make' from re-running sphinx.
    103 man_stamp = $(man_build)/.sphinx-stamp
    104 
    105 ifeq ($(strip $(sphinx_build)),)
    106 .PHONY: man
    107 man:
    108 	@if [ -d $(man_build) ]; then \
    109 	  echo "man: using the pre-built pages in $(man_build)"; \
    110 	else \
    111 	  echo "man: no sphinx-build, so no man pages will be built or installed;" \
    112 	       "install python3-sphinx and re-run ./configure" >&2; \
    113 	fi
    114 else
    115 .PHONY: man
    116 man: $(man_stamp)
    117 
    118 # Warnings about pages missing from a toctree are expected: the toctree they
    119 # belong to lives in the taler-docs repository.  See the comment in conf.py.
    120 $(man_stamp): $(man_sources) documentation/sphinx-man/conf.py
    121 	$(sphinx_build) -b man -q -c documentation/sphinx-man \
    122 	  documentation/taler-docs/manpages $(man_build)
    123 	@touch $@
    124 endif
    125 
    126 .PHONY: verifier
    127 verifier: $(verifier_jar)
    128 
    129 # A plain 'git clone' does not bring the submodule, and neither does a build
    130 # from a tree where ./bootstrap was never run; say so rather than letting Maven
    131 # complain about a missing pom.
    132 $(verifier_jar):
    133 	@test -f $(verifier_src)/pom.xml || { \
    134 	  echo "$(verifier_src) is empty: run ./bootstrap" >&2; exit 1; }
    135 	@test -n "$(strip $(mvn))" || { \
    136 	  echo "no maven: re-run ./configure --enable-verifier for the reason" >&2; \
    137 	  exit 1; }
    138 	cd $(verifier_src) && JAVA_HOME=$(java_home) $(mvn) $(MAVEN_FLAGS) package
    139 	@mkdir -p $(dir $@)
    140 # Exactly one jar, and not the '.jar.original' that the Spring Boot plugin
    141 # leaves beside it: a glob matching both would stage the wrong one.
    142 	cp $(verifier_src)/verifier-application/target/swiyu-verifier-application-*.jar $@
    143 
    144 # ---------------------------------------------------------------- check
    145 
    146 .PHONY: check
    147 check:
    148 # The two integration suites in $(crate)/tests/ return Ok(()) early when
    149 # DATABASE_URL is unset or unreachable, printing only to stderr -- so a green
    150 # run here does not mean the database layer was exercised.  Point it at a
    151 # throwaway database: the tests write to the live schema.
    152 	@test -n "$${DATABASE_URL:-}" || echo \
    153 	  "check: DATABASE_URL is unset, so the integration tests will skip themselves" >&2
    154 	$(cargo) test --manifest-path $(crate)/Cargo.toml
    155 # Not covered by the line above: the vendored crate has its own suite, and it
    156 # is the quickest check that a re-vendored taler-config still behaves.
    157 	$(cargo) test --manifest-path $(vendored)/Cargo.toml
    158 ifeq ($(strip $(cargo_clippy)),yes)
    159 	$(cargo) clippy --manifest-path $(crate)/Cargo.toml --all-targets
    160 endif
    161 
    162 # ---------------------------------------------------------------- install
    163 
    164 .PHONY: install
    165 install: install-gateway install-man install-verifier
    166 
    167 .PHONY: install-gateway
    168 install-gateway: gateway
    169 	install -D -t $(bin_dir) $(release)/kych-oauth2-gateway
    170 	install -D -t $(bin_dir) $(release)/kych-client-management
    171 	install -D -t $(bin_dir) $(release)/kych-dbinit
    172 # Creates the role and the database; kych-dbinit then applies the SQL patches.
    173 	install -D -t $(bin_dir) contrib/kych-dbconfig
    174 # The daemon serves /js from a path relative to its working directory
    175 # (ServeDir::new("js") in main.rs), so it has to be started from a directory
    176 # that has this one below it -- $(kych_data) for an installed tree.
    177 	install -m 644 -D -t $(kych_data)/js $(crate)/js/qrcode.min.js
    178 	install -m 644 -D -t $(kych_data)/sql $(crate)/oauth2_gatewaydb/versioning.sql
    179 	install -m 644 -D -t $(kych_data)/sql $(crate)/oauth2_gatewaydb/oauth2gw-*.sql
    180 # Deliberately NOT in sql/: kych-dbinit would take drop.sql for a patch file,
    181 # and dropping the schema is not a migration.
    182 	install -m 644 -D -t $(kych_data) $(crate)/oauth2_gatewaydb/drop.sql
    183 	install -m 644 -D -t $(kych_data) $(crate)/kych.conf.example
    184 # Read before the administrator's own configuration file on every start, which
    185 # therefore wins.  These are the options that have no built-in default, so
    186 # without this file the daemon refuses to start; the Debian package installs
    187 # the very same file.  Note that the parser does not sort config.d -- keep it
    188 # at one file.
    189 	install -m 644 -D -t $(kych_data)/config.d contrib/config.d/00-kych-defaults.conf
    190 
    191 # $(1): page names, $(2): manual section.  Every line is continued, so that
    192 # this expands to a single recipe line and therefore runs in a single shell.
    193 # A page that was never built is skipped with a warning rather than failing the
    194 # install: that is the case for a tarball unpacked on a host without sphinx.
    195 define install_man_pages
    196 	@set -eu; for page in $(1); do \
    197 	  if [ -f $(man_build)/$$page ]; then \
    198 	    install -m 644 -D $(man_build)/$$page $(man_dir)/man$(2)/$$page; \
    199 	  else \
    200 	    echo "install: $(man_build)/$$page was not built; skipping" >&2; \
    201 	  fi; \
    202 	done
    203 endef
    204 
    205 .PHONY: install-man
    206 install-man: man
    207 	$(call install_man_pages,$(kych_man1),1)
    208 	$(call install_man_pages,$(kych_man5),5)
    209 
    210 .PHONY: install-verifier
    211 ifeq ($(strip $(enable_verifier)),yes)
    212 install-verifier: verifier man
    213 	install -m 644 -D $(verifier_jar) $(verifier_data)/swiyu-verifier.jar
    214 	install -D -t $(bin_dir) contrib/swiyu-verifier
    215 	install -D -t $(bin_dir) contrib/swiyu-verifier-dbconfig
    216 # Not trusted by the JVM's default store; see swiyu-verifier/README for
    217 # building a truststore that holds it.
    218 	install -m 644 -D -t $(verifier_data)/certs $(verifier_src)/certs/root_ca_vi.crt
    219 	install -m 644 -D -t $(verifier_data) debian/signing-key.yml.example
    220 	install -m 644 -D -t $(verifier_data) swiyu-verifier/application-kych.yml.template
    221 	install -m 644 -D -t $(verifier_data) swiyu-verifier/client_metadata.json
    222 	$(call install_man_pages,$(verifier_man1),1)
    223 # contrib/swiyu-verifier looks for its jar, configuration and truststore under
    224 # the FHS paths the Debian package uses, so outside a /usr prefix it has to be
    225 # told where they are; swiyu-verifier/README covers running the jar directly.
    226 	@test "$(prefix)" = /usr || echo \
    227 	  "install: contrib/swiyu-verifier carries /usr/share paths; see swiyu-verifier/README" >&2
    228 else
    229 install-verifier:
    230 	@echo "install: the SWIYU verifier is not enabled; skipping it"
    231 endif
    232 
    233 .PHONY: installcheck
    234 installcheck:
    235 	@set -eu; status=0; \
    236 	for binary in kych-oauth2-gateway kych-client-management kych-dbinit; do \
    237 	  if "$(bin_dir)/$$binary" --help >/dev/null 2>&1; then \
    238 	    echo "installcheck: $$binary ok"; \
    239 	  else \
    240 	    echo "installcheck: $(bin_dir)/$$binary is missing or does not run" >&2; \
    241 	    status=1; \
    242 	  fi; \
    243 	done; \
    244 	for data in js/qrcode.min.js sql/versioning.sql; do \
    245 	  if [ -f "$(kych_data)/$$data" ]; then \
    246 	    echo "installcheck: $$data ok"; \
    247 	  else \
    248 	    echo "installcheck: $(kych_data)/$$data is missing" >&2; status=1; \
    249 	  fi; \
    250 	done; \
    251 	exit $$status
    252 
    253 # ---------------------------------------------------------------- dist
    254 
    255 .PHONY: dist
    256 # The man pages are built first so that the tarball carries them and a build
    257 # from it needs no sphinx.
    258 dist: man
    259 	./scripts/dist.sh
    260 
    261 .PHONY: distcheck
    262 distcheck: dist
    263 	./scripts/dist.sh --check
    264 
    265 .PHONY: deb
    266 deb:
    267 	./debian/stamp-version.sh
    268 	dpkg-buildpackage -b -uc -us
    269 
    270 .PHONY: doc
    271 doc:
    272 	$(cargo) doc --manifest-path $(crate)/Cargo.toml
    273 
    274 .PHONY: fmt
    275 fmt:
    276 	$(cargo) fmt --manifest-path $(crate)/Cargo.toml
    277 
    278 # ---------------------------------------------------------------- clean
    279 
    280 .PHONY: clean
    281 clean:
    282 	$(cargo) clean --manifest-path $(crate)/Cargo.toml
    283 	$(cargo) clean --manifest-path $(vendored)/Cargo.toml
    284 	rm -rf $(man_build) $(dir $(verifier_jar))
    285 # doc/ and swiyu-verifier/jar/ hold nothing but generated files, so take the
    286 # now-empty directories with them; '|| true' because they may not exist.
    287 	@rmdir doc 2>/dev/null || true
    288 # Only when the submodule is checked out: 'clean' has to work on a tree where
    289 # it is not.  Upstream's own build products only; the Maven repository is a
    290 # cache outside this tree and not ours to delete.
    291 	@test ! -f $(verifier_src)/pom.xml || rm -rf \
    292 	  $(verifier_src)/verifier-application/target $(verifier_src)/verifier-service/target
    293 
    294 .PHONY: distclean
    295 distclean: clean
    296 	rm -f .config.mk .version
    297 
    298 .PHONY: maintainer-clean
    299 maintainer-clean: distclean
    300 	rm -f kych-*.tar.gz