-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
127 lines (96 loc) · 3.38 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
118
119
120
121
122
123
124
125
126
127
MAKE = make --no-print-directory
FYNE_CROSS = $(shell go env | awk -F'"' '/GOPATH/ {print $$2}')/bin/fyne-cross
DESCRIBE := $(shell go run gen.go VERSION)
DESCRIBE_PARTS := $(subst -, ,$(DESCRIBE))
VERSION_TAG := $(word 1,$(DESCRIBE_PARTS))
COMMITS_SINCE_TAG := $(word 2,$(DESCRIBE_PARTS))
VERSION := $(subst v,,$(VERSION_TAG))
VERSION_PARTS := $(subst ., ,$(VERSION))
MAJOR := $(word 1,$(VERSION_PARTS))
MINOR := $(word 2,$(VERSION_PARTS))
MICRO := $(word 3,$(VERSION_PARTS))
NEXT_MAJOR := $(shell echo $$(($(MAJOR)+1)))
NEXT_MINOR := $(shell echo $$(($(MINOR)+1)))
NEXT_MICRO = $(shell echo $$(($(MICRO)+$(COMMITS_SINCE_TAG))))
BINARYNAME = $(shell go run gen.go PROGRAM)
MODNAME = github.com/AlbinoGeek/$(BINARYNAME)
APP_NAME = com.github.albinogeek.$(BINARYNAME)
TARGETDIR = _dist
ifeq ($(strip $(COMMITS_SINCE_TAG)),)
CURRENT_VERSION_MICRO := $(MAJOR).$(MINOR).$(MICRO)
CURRENT_VERSION_MINOR := $(CURRENT_VERSION_MICRO)
CURRENT_VERSION_MAJOR := $(CURRENT_VERSION_MICRO)
else
CURRENT_VERSION_MICRO := $(MAJOR).$(MINOR).$(NEXT_MICRO)
CURRENT_VERSION_MINOR := $(MAJOR).$(NEXT_MINOR).0
CURRENT_VERSION_MAJOR := $(NEXT_MAJOR).0.0
endif
DATE = $(shell date +'%d.%m.%Y')
TIME = $(shell date +'%H:%M:%S')
COMMIT := $(shell git rev-parse HEAD)
AUTHOR := $(firstword $(subst @, ,$(shell git show --format="%aE" $(COMMIT))))
BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD)
NCOMMITS = $(shell git log --oneline | wc -l)
TAG_MESSAGE = "$(TIME) $(DATE) $(AUTHOR) $(BRANCH_NAME)"
COMMIT_MESSAGE := $(shell git log --format=%B -n 1 $(COMMIT))
CURRENT_TAG_MICRO := "v$(CURRENT_VERSION_MICRO)"
CURRENT_TAG_MINOR := "v$(CURRENT_VERSION_MINOR)"
CURRENT_TAG_MAJOR := "v$(CURRENT_VERSION_MAJOR)"
# --- Recipes ---
release_build = \
$(FYNE_CROSS) $(1) -arch=$(2) \
-app-build $(NCOMMITS) \
-app-id $(APP_NAME) \
-app-version $(CURRENT_VERSION_MICRO) \
$(4) "$(MODNAME)" && \
cp "fyne-cross/bin/$(1)-$(2)/$(BINARYNAME)$(3)" \
"$(TARGETDIR)/$(BINARYNAME)-$(CURRENT_VERSION_MICRO)-$(1)-$(2)$(3)"
# --- Version commands ---
.PHONY: version
version:
@$(MAKE) version-micro
.PHONY: version-micro
version-micro:
@echo "$(CURRENT_VERSION_MICRO)"
.PHONY: version-minor
version-minor:
@echo "$(CURRENT_VERSION_MINOR)"
.PHONY: version-major
version-major:
@echo "$(CURRENT_VERSION_MAJOR)"
# --- Tag commands ---
.PHONY: tag-micro
tag-micro:
@echo "$(CURRENT_TAG_MICRO)"
.PHONY: tag-minor
tag-minor:
@echo "$(CURRENT_TAG_MINOR)"
.PHONY: tag-major
tag-major:
@echo "$(CURRENT_TAG_MAJOR)"
# --- Meta info ---
.PHONY: tag-message
tag-message:
@echo "$(TAG_MESSAGE)"
.PHONY: commit-message
commit-message:
@echo "$(COMMIT_MESSAGE)"
# --- Actual Make Targets ---
.PHONY: all
all: "$(TARGETDIR)/$(BINARYNAME)"
"$(TARGETDIR)/$(BINARYNAME)":
go generate
if [ ! -d "$(TARGETDIR)" ]; then mkdir "$(TARGETDIR)"; fi
go build -o "$(TARGETDIR)/$(BINARYNAME)" "$(MODNAME)" # -ldflags "-s -w"
.PHONY: release
release:
$(call release_build,linux,amd64,,-release)
$(call release_build,linux,386,,-release)
$(call release_build,windows,amd64,.exe)
$(call release_build,windows,386,.exe)
.PHONY: clean
clean:
rm -f "$(TARGETDIR)/$(BINARYNAME)"
.PHONY: update
update:
go get -u -v ./...