-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
79 lines (68 loc) · 2.27 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
# Paths
PWD := $(shell pwd)
BUILD_PATH := $(PWD)/build
# Tools
AWK := awk
CD := cd
CP := cp -f
CURL := curl -sL
COLUMN := column
GIT := git
MKDIR := mkdir -p
RM := rm -f
RMDIR := rm -rf
SED := sed
SHA256 := sha256sum
TAR := tar
# Default targets
_DEFAULT_GOAL: help
# Directories creation
$(BUILD_PATH):
$(MKDIR) $@
# Release
.PHONY: check-version prepare-release publish-release
GIT_REMOTE = origin
SAC_GIT_URL = https://github.com/sacproj/sac-cli
SAC_FORMULA = Formula/sac.rb
SAC_TARBALL = sac-cli.tar.gz
SAC_TARBALL_URL = $(SAC_GIT_URL)/releases/download/$(VERSION)/$(SAC_TARBALL)
SAC_TARBALL_SHA256 := $(shell $(CURL) $(SAC_TARBALL_URL) | $(SHA256) - | head -c 64)
BUILD_SAC_FORMULA := $(BUILD_PATH)/$(shell basename $(SAC_FORMULA))
check-version:
@if [ "$(VERSION)" == "" ]; then echo "VERSION must be defined"; exit 1; fi
## Prepare release (requires defined VERSION)
prepare-release: $(BUILD_PATH) check-version
$(CP) $(SAC_FORMULA) $(BUILD_SAC_FORMULA)
$(SED) \
-e "s|url \".*|url \"$(SAC_TARBALL_URL)\"|" \
-e "s|version \".*|version \"$(VERSION)\"|" \
-e "s|sha256 \".*|sha256 \"$(SAC_TARBALL_SHA256)\"|" \
$(BUILD_SAC_FORMULA) > $(SAC_FORMULA)
$(GIT) add $(SAC_FORMULA)
$(GIT) commit --allow-empty -s -m "release: $(VERSION)"
$(GIT) tag -a $(VERSION) -s -m $(VERSION)
## Publish release (requires defined VERSION)
publish-release: check-version
$(GIT) push
$(GIT) push $(GIT_REMOTE) $(VERSION)
# Cleaning
.PHONY: clean clean-build
## Clean artifacts
clean: clean-build
clean-build:
$(RMDIR) $(BUILD_PATH)
.PHONY: help
## Display this help message
help:
$(info Available targets)
@$(AWK) '/^[a-zA-Z\-\\_0-9]+:/ { \
nb = sub( /^## /, "", helpMsg ); \
if(nb == 0) { \
helpMsg = $$0; \
nb = sub( /^[^:]*:.* ## /, "", helpMsg ); \
} \
if (nb) \
printf "\033[1;31m%-" width "s\033[0m %s\n", $$1, helpMsg; \
} \
{ helpMsg = $$0 }' \
$(MAKEFILE_LIST) | $(COLUMN) -ts: