-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
117 lines (96 loc) · 2.59 KB
/
Makefile
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
# This Makefile intended to be POSIX-compliant (2018 edition with .PHONY target).
#
# .PHONY targets are used by task definintions.
#
# More info:
# - docs: <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html>
# - .PHONY: <https://www.austingroupbugs.net/view.php?id=523>
#
.POSIX:
.SUFFIXES:
#
# PUBLIC MACROS
#
CLI = tasmota-cmd
DESTDIR = ./dist
LINT = shellcheck
TEST = ./unittest
#
# INTERNAL MACROS
#
CLI_CURRENT_VER_TAG = $$(git tag | grep "^v" | sed 's/^v//' | sort -t. -k 1,1n -k 2,2n -k 3,3n | tail -1)
CLI_VERSION = $$(grep "^ *TASMOTA_VERSION *=" $(CLI) | sed 's/^ *TASMOTA_VERSION *= *//')
TEST_SRC=https://github.com/macie/unittest.sh/releases/latest/download/unittest
#
# DEVELOPMENT TASKS
#
.PHONY: all
all: test check
.PHONY: clean
clean:
@echo '# Delete test runner:' >&2
rm -f $(TEST)
@echo '# Delete build directory' >&2
rm -rf $(DESTDIR)
.PHONY: info
info:
@printf '# OS info: '
@uname -rsv;
@echo '# Development dependencies:'
@echo; $(LINT) -V || true
@echo; $(TEST) -v || true
@echo '# Environment variables:'
@env || true
.PHONY: check
check: $(LINT)
@echo '# Static analysis:' >&2
$(LINT) $(CLI)
.PHONY: test
test: $(TEST)
@echo '# Unit tests:' >&2
$(TEST)
.PHONY: install
install:
@echo '# Install in /usr/local/bin' >&2
@mkdir -p /usr/local/bin; cp $(CLI) /usr/local/bin/
.PHONY: dist
dist:
@echo '# Copy CLI executable to $(DESTDIR)/$(CLI)' >&2
@mkdir -p $(DESTDIR); cp $(CLI) $(DESTDIR)/
@echo '# Add executable checksum to: $(DESTDIR)/$(CLI).sha256sum' >&2
@cd $(DESTDIR); sha256sum $(CLI) > $(CLI).sha256sum
.PHONY: cli-release
cli-release: check test
@echo '# Update local branch' >&2
@git pull --rebase
@printf '# Create release tag for CLI version %s\n' "$(CLI_VERSION)" >&2
@if [ "$(CLI_CURRENT_VER_TAG)" = "$(CLI_VERSION)" ]; then \
printf 'ERROR: version %s already released\n' "$(CLI_VERSION)" >&2; \
exit 1; \
fi
@printf 'Are you sure you want to release version %s (prev: %s)? [y/N]: ' "$(CLI_VERSION)" "$(CLI_CURRENT_VER_TAG)"
@read -r ANSWER; \
if [ "$$ANSWER" != "y" ]; then \
echo 'ERROR: canceled by user' >&2; \
exit 1; \
fi; \
git tag "v$(CLI_VERSION)"; \
git push --tags
#
# DEPENDENCIES
#
$(LINT):
@printf '# $@ installation path: ' >&2
@command -v $@ >&2 || { echo "ERROR: Cannot find $@" >&2; exit 1; }
$(TEST):
@echo '# Prepare $@:' >&2
@if [ "$$(uname -s)" = "OpenBSD" ]; then \
ftp -V $(TEST_SRC); \
ftp -V $(TEST_SRC).sha256sum; \
sha256 -c $@.sha256sum; \
else \
curl -fLO $(TEST_SRC); \
curl -fLO $(TEST_SRC).sha256sum; \
sha256sum -c $@.sha256sum; \
fi
chmod +x $@