summaryrefslogtreecommitdiffstats
path: root/.Makefile
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@sequoia-pgp.org>2021-04-16 15:52:20 +0200
committerJonas Bernoulli <jonas@sequoia-pgp.org>2021-04-22 16:25:36 +0200
commit58025f5a0390c137fe972d2940c4bea1941ab055 (patch)
tree432f8521d351fdc80a3db3ac2073f6e9c8ebcbc4 /.Makefile
parent633f4475531a2fe5b1dd42c1ab6560470e4a0943 (diff)
make: Hide Makefile to avoid confusion.
- Those make targets that are useful to users are just wrappers around the respective cargo commands, which means that they are not really necessary. The additional targets are primarily of use to Sequoia developers, which also means that they are not very useful to users. - That did not keep us from prominently advertising the use of make as a recommended installation mechanism, and that in turn contributed to some false expectations and confusion. - For example, a packager used the Makefile because they thought that that is what we would like them to do. Some users found it surprising that "sudo make install" ended up running the target "build-release" even though they had already build using "build". - People who want to keep using make without every time having to specify the name of the hidden Makefile can do so by creating a symbolic link.
Diffstat (limited to '.Makefile')
-rw-r--r--.Makefile167
1 files changed, 167 insertions, 0 deletions
diff --git a/.Makefile b/.Makefile
new file mode 100644
index 00000000..ecb3b2f8
--- /dev/null
+++ b/.Makefile
@@ -0,0 +1,167 @@
+# Makefile for Sequoia.
+
+# Configuration.
+PREFIX ?= /usr/local
+DESTDIR ?=
+CARGO_FLAGS ?=
+# cargo's "target" directory. Normally, this is in the root
+# directory of the project, but it can be overridden by setting
+# CARGO_TARGET_DIR.
+CARGO_TARGET_DIR ?= $(shell pwd)/target
+# We currently only support absolute paths.
+CARGO_TARGET_DIR := $(abspath $(CARGO_TARGET_DIR))
+# The packages to build, test and document, e.g., "-p sequoia-openpgp"
+CARGO_PACKAGES ?= --workspace
+# Additional arguments to pass to cargo test, e.g., "--doc".
+CARGO_TEST_ARGS ?=
+# Version as stated in the top-level Cargo.toml.
+VERSION ?= $(shell grep '^version[[:space:]]*=[[:space:]]*' openpgp/Cargo.toml\
+ | cut -d'"' -f2)
+
+# Signing source distributions.
+SIGN_WITH ?= XXXXXXXXXXXXXXXX
+
+# Tools.
+CARGO ?= cargo
+GIT ?= git
+TAR ?= tar
+GZIP ?= gzip
+XZ ?= xz
+GPG ?= gpg
+CODESPELL ?= codespell
+CODESPELL_FLAGS ?= --disable-colors --write-changes
+
+SOURCE_DATE_EPOCH = $(shell git show -s --no-show-signature --format=%cI)
+TAR_FLAGS = --sort=name \
+ --mtime="$(SOURCE_DATE_EPOCH)" \
+ --owner=0 --group=0 --numeric-owner \
+ --mode=go=rX,u+rw,a-s \
+ --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime
+
+ifneq ($(filter Darwin %BSD,$(shell uname -s)),)
+ INSTALL ?= ginstall
+else
+ INSTALL ?= install
+endif
+
+VERSION ?= $(shell grep '^version[[:space:]]*=[[:space:]]*' Cargo.toml | cut -d'"' -f2)
+
+# Make sure subprocesses pick these up.
+export PREFIX
+export DESTDIR
+export CARGO_FLAGS
+export CARGO_TARGET_DIR
+export CARGO_PACKAGES
+export CARGO_TEST_ARGS
+
+all: build examples
+
+.PHONY: build
+build:
+ CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) $(CARGO) build $(CARGO_FLAGS) $(CARGO_PACKAGES)
+ $(MAKE) -Copenpgp-ffi build
+ $(MAKE) -Cffi build
+
+# Testing and examples.
+#
+# If CARGO_PACKAGES contains a package specification ("-p foo"), then
+# only run cargo test.
+.PHONY: test check
+test check:
+ CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) $(CARGO) test $(CARGO_FLAGS) $(CARGO_PACKAGES) $(CARGO_TEST_ARGS)
+ if echo "$(CARGO_TEST_ARGS)" | grep -q -e '--benches'; \
+ then \
+ echo 'Already tested the benchmarks.'; \
+ else \
+ CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) $(CARGO) test $(CARGO_FLAGS) $(CARGO_PACKAGES) --benches; \
+ fi
+ if echo "$(CARGO_PACKAGES)" | grep -q -E -e '(^| )[-]p +.'; \
+ then \
+ echo 'WARNING: Not running other tests, because $$CARGO_PACKAGES specifies a package.'; \
+ else \
+ $(MAKE) -Copenpgp-ffi test && \
+ $(MAKE) -Cffi test && \
+ $(MAKE) --file=.Makefile examples; \
+ fi
+
+.PHONY: examples
+examples:
+ CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \
+ $(CARGO) build $(CARGO_FLAGS) --examples
+ $(MAKE) -Copenpgp-ffi examples
+ $(MAKE) -Cffi examples
+
+# Documentation.
+.PHONY: doc
+doc:
+ sed 's|"/|"file://$(shell pwd)/doc/|' doc/highlight.js/9.12.0/inc.html \
+ > $(CARGO_TARGET_DIR)/inc.html
+ RUSTDOCFLAGS="$$RUSTDOCFLAGS --html-in-header $(CARGO_TARGET_DIR)/inc.html" \
+ CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \
+ $(CARGO) doc $(CARGO_FLAGS) --no-deps $(CARGO_PACKAGES)
+
+# Installation.
+.PHONY: build-release
+build-release:
+ $(MAKE) -Copenpgp-ffi build-release
+ $(MAKE) -Cffi build-release
+ $(MAKE) -Csq build-release
+ $(MAKE) -Csqv build-release
+
+# "install" needs "build-release" as it builds the project
+# with optimizations enabled.
+.PHONY: install
+install: build-release
+ $(MAKE) -Copenpgp-ffi install
+ $(MAKE) -Cffi install
+ $(MAKE) -Csq install
+ $(MAKE) -Csqv install
+
+# Infrastructure for creating source distributions.
+.PHONY: dist
+dist: $(CARGO_TARGET_DIR)/dist/sequoia-$(VERSION).tar.pgp.gz \
+ $(CARGO_TARGET_DIR)/dist/sequoia-$(VERSION).tar.pgp.xz
+
+$(CARGO_TARGET_DIR)/dist/sequoia-$(VERSION):
+ $(GIT) clone . $(CARGO_TARGET_DIR)/dist/sequoia-$(VERSION)
+ cd $(CARGO_TARGET_DIR)/dist/sequoia-$(VERSION) && \
+ rm -rf .git
+
+$(CARGO_TARGET_DIR)/dist/sequoia-$(VERSION).tar: \
+ $(CARGO_TARGET_DIR)/dist/sequoia-$(VERSION)
+ $(TAR) $(TAR_FLAGS) -cf $@ -C $(CARGO_TARGET_DIR)/dist sequoia-$(VERSION)
+
+%.gz: %
+ $(GZIP) -c "$<" >"$@"
+
+%.xz: %
+ $(XZ) -c "$<" >"$@"
+
+%.pgp: %
+ $(GPG) --local-user "$(SIGN_WITH)" --compression-algo=none \
+ --sign --output "$@" "$<"
+
+# Testing source distributions.
+.PHONY: dist-test dist-check
+dist-test dist-check: $(CARGO_TARGET_DIR)/dist/sequoia-$(VERSION).tar.pgp.gz
+ mkdir -p "$(CARGO_TARGET_DIR)/dist-check"
+ rm -rf "$(CARGO_TARGET_DIR)/dist-check/sequoia-$(VERSION)"
+ $(GZIP) -d -c "$<" |\
+ $(GPG) -o - --verify |\
+ $(TAR) xf - -C "$(CARGO_TARGET_DIR)/dist-check"
+ cd "$(CARGO_TARGET_DIR)/dist-check/sequoia-$(VERSION)" && \
+ CARGO_HOME=$$(mktemp -d) $(MAKE) --file=.Makefile test CARGO_FLAGS=--locked
+ rm -rf "$(CARGO_TARGET_DIR)/dist-check/sequoia-$(VERSION)"
+
+# Housekeeping.
+.PHONY: clean
+clean:
+ CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) $(CARGO) $(CARGO_FLAGS) clean
+ $(MAKE) -Copenpgp-ffi clean
+ $(MAKE) -Cffi clean
+
+.PHONY: codespell
+codespell:
+ $(CODESPELL) $(CODESPELL_FLAGS) \
+ -L "crate,ede,iff,mut,nd,te,uint,KeyServer,keyserver,Keyserver,keyservers,Keyservers,keypair,keypairs,KeyPair,fpr,dedup" \
+ -S "*.bin,*.gpg,*.pgp,./.git,data,highlight.js,*/target,Makefile"