summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 9d7a97b0c5bdd0bf97a6abbb2d82eb45cfee9057 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# 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	?= --all
# 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_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) 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
	$(MAKE) -Csop build-release

.PHONY: install
install: build-release
	$(MAKE) -Copenpgp-ffi install
	$(MAKE) -Cffi install
	$(MAKE) -Csq install
	$(MAKE) -Csqv install
	$(MAKE) -Csop 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) 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: sanity-check-versions
sanity-check-versions:
	set -e ; V=$(VERSION) ; VV=$(shell echo $(VERSION) | cut -d. -f1-2) ;\
        bad() { echo "bad $$*." ; exit 1 ; } ;\
	for TOML in */Cargo.toml ; do \
	  echo -n "$$TOML " ;\
	  grep '^version *=' $$TOML | grep -q $$V || bad version ;\
	  grep '^documentation *=' $$TOML \
	    | egrep -q "($${V})|(https://docs.rs/)" || bad documentation ;\
	  grep '{ *path *= *"' $$TOML | while read L ; do \
	    echo $$L | grep -q $$VV || bad intra-workspace dependency ;\
	  done ;\
	  echo good. ;\
	done

.PHONY: codespell
codespell:
	$(CODESPELL) $(CODESPELL_FLAGS) \
	  -L "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"