Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
72 lines (67 loc) · 2.49 KB
/
Copy pathMakefile
File metadata and controls
72 lines (67 loc) · 2.49 KB
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
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
DIST_DIR := dist
ARCHIVE := $(DIST_DIR)/coding_standards.tar.gz
CHECKSUM := $(ARCHIVE).sha256
.PHONY: all clean dist-check
all: clean
@command -v tar >/dev/null 2>&1 || { printf '%s\n' 'GNU tar is required' >&2; exit 1; }
@tar --version | grep -q 'GNU tar' || { printf '%s\n' 'GNU tar is required' >&2; exit 1; }
@command -v gzip >/dev/null 2>&1 || { printf '%s\n' 'gzip is required' >&2; exit 1; }
@test -d standards || { printf '%s\n' 'standards directory not found' >&2; exit 1; }
@first_link="$$(find standards -type l -print -quit)"; \
if [[ -n "$$first_link" ]]; then \
printf 'symbolic links are not permitted in standards: %s\n' "$$first_link" >&2; \
exit 1; \
fi
@mkdir -p "$(DIST_DIR)"
@tmp="$$(mktemp -d "$${TMPDIR:-/tmp}/coding_standards.XXXXXX")"; \
archive_tmp="$(ARCHIVE).tmp"; \
checksum_tmp="$(CHECKSUM).tmp"; \
cleanup() { \
rm -f -- "$$archive_tmp" "$$checksum_tmp"; \
if [[ -d "$$tmp" ]]; then \
find "$$tmp" -depth -mindepth 1 -delete; \
rmdir -- "$$tmp"; \
fi; \
}; \
trap cleanup EXIT HUP INT TERM; \
cp -R -- standards/. "$$tmp/"; \
find "$$tmp" -type d -exec chmod 0755 {} +; \
find "$$tmp" -type f -exec chmod 0644 {} +; \
tar \
--sort=name \
--mtime='UTC 1970-01-01' \
--owner=0 \
--group=0 \
--numeric-owner \
-cf - \
-C "$$tmp" . | gzip -n >"$$archive_tmp"; \
if command -v sha256sum >/dev/null 2>&1; then \
digest="$$(sha256sum -- "$$archive_tmp" | awk '{print $$1}')"; \
elif command -v shasum >/dev/null 2>&1; then \
digest="$$(shasum -a 256 -- "$$archive_tmp" | awk '{print $$1}')"; \
else \
printf '%s\n' 'sha256sum or shasum -a 256 is required' >&2; \
exit 1; \
fi; \
printf '%s %s\n' "$$digest" 'coding_standards.tar.gz' >"$$checksum_tmp"; \
mv -- "$$archive_tmp" "$(ARCHIVE)"; \
mv -- "$$checksum_tmp" "$(CHECKSUM)"; \
cleanup; \
trap - EXIT HUP INT TERM
dist-check:
@tmp="$$(mktemp -d "$${TMPDIR:-/tmp}/coding_standards-check.XXXXXX")"; \
trap 'find "$$tmp" -depth -mindepth 1 -delete; rmdir -- "$$tmp"' EXIT HUP INT TERM; \
$(MAKE) --no-print-directory all >/dev/null; \
cp "$(ARCHIVE)" "$$tmp/first.tar.gz"; \
cp "$(CHECKSUM)" "$$tmp/first.sha256"; \
$(MAKE) --no-print-directory all >/dev/null; \
cmp "$$tmp/first.tar.gz" "$(ARCHIVE)"; \
cmp "$$tmp/first.sha256" "$(CHECKSUM)"; \
printf '%s\n' 'standards archive is deterministic'
clean:
@if [[ -d "$(DIST_DIR)" ]]; then \
find "$(DIST_DIR)" -depth -mindepth 1 -delete; \
rmdir -- "$(DIST_DIR)"; \
fi