-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
140 lines (109 loc) · 4.76 KB
/
Copy pathMakefile
File metadata and controls
140 lines (109 loc) · 4.76 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
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
# Makefile template: https://gist.github.com/grihabor/4a750b9d82c9aa55d5276bd5503829be
# source: https://github.com/CTNOriginals/getkeystate/blob/197603a7a57177510262a840f846956a43017ba0/Makefile
MAKE := make --no-print-directory
DESCRIBE := $(shell git describe --match "v*" --always --tags)
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))
PATCH := $(word 3,$(VERSION_PARTS))
NEXT_MAJOR := $(shell echo $$(($(MAJOR)+1)))
NEXT_MINOR := $(shell echo $$(($(MINOR)+1)))
NEXT_PATCH = $(shell echo $$(($(PATCH)+$(COMMITS_SINCE_TAG))))
ifeq ($(strip $(COMMITS_SINCE_TAG)),)
CURRENT_VERSION_PATCH := $(MAJOR).$(MINOR).$(PATCH)
CURRENT_VERSION_MINOR := $(CURRENT_VERSION_PATCH)
CURRENT_VERSION_MAJOR := $(CURRENT_VERSION_PATCH)
else
CURRENT_VERSION_PATCH := $(MAJOR).$(MINOR).$(NEXT_PATCH)
CURRENT_VERSION_MINOR := $(MAJOR).$(NEXT_MINOR).0
CURRENT_VERSION_MAJOR := $(NEXT_MAJOR).0.0
endif
.DEFAULT_GOAL := help
# --- Version commands ---
.PHONY: help version proto
help: ##@help Display all commands and descriptions
@awk 'BEGIN {FS = ":.*##@"; printf "\nUsage:\n make <target>\n"} \
/^[.a-zA-Z_-]+:.*?##@/ { \
split($$2, parts, " "); \
section = parts[1]; \
description = substr($$2, length(section) + 2); \
sections[section] = sections[section] sprintf(" \033[36m%-15s\033[0m %s\n", $$1, description); \
} \
END { \
for (section in sections) { \
printf "\n\033[1m%s\033[0m\n", section; \
printf "%s", sections[section]; \
} \
}' $(MAKEFILE_LIST)
list: ##@help List all targets and their commands
@awk 'BEGIN { \
target = ""; cmds = ""; \
} \
/^[.a-zA-Z_-]+:/ && !/^\.PHONY/ { \
if (target != "" && cmds != "") { \
printf " \033[36m%-15s\033[0m\n%s\n", target, cmds; \
} \
split($$0, a, ":"); \
target = (a[1] == "help" || a[1] == "list") ? "" : a[1]; \
cmds = ""; \
} \
/^\t/ && target != "" { \
cmds = cmds " " substr($$0, 2) "\n"; \
} \
END { \
if (target != "" && cmds != "") { \
printf " \033[36m%-15s\033[0m\n%s\n", target, cmds; \
} \
}' $(MAKEFILE_LIST)
version: ##@help Log the current version
@echo "v$(CURRENT_VERSION_PATCH)"
# proto: ##@help For prototyping makefile functionality
# @echo hello $1
# -- Git --
.PHONY: git-graph adog
git-graph: ##@git Log decorated graph
git log --all --decorate --oneline --graph
# git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)' --all
# -- Run --
.PHONY: run debug test test-coverage wrun
WGO_INCLUDE := -file .go -file .toml -file Makefile
run: ##@run Run normally. Pass arguments like so: args="arg1 arg2 ...".
go run . $(args)
debug: ##@run Run with --test $(testargs).
go run . $(args) --test $(testargs)
test: ##@run go test $(args); for all packaged that contain at least 1 *_test.go script.
go test $(args) $$(go list -f '{{if len .TestGoFiles}}{{.ImportPath}}{{end}}' ./...)
test-coverage: ##@run Generate an preview test coverage in html form.
$(MAKE) test args="$(args) -coverprofile tmp/cover.out"
go tool cover -html="tmp/cover.out" -o "tmp/cover.html"
xdg-open tmp/cover.html
wrun: ##@run Run a make target and restart on file change. make wrun <wgoargs="args..."> target=[TARGET]. Requires wgo: https://github.com/bokwoon95/wgo
wgo $(WGO_INCLUDE) $(wgoargs) $(MAKE) $(target)
wrunstdin: ##@run Run a make wrun with wgoargs -stdin.
$(MAKE) wrun wgoargs="-stdin $(wgoargs)" target="$(target)"
# -- Build --
.PHONY: build-win build-linux build-mac build
build-win: ##@build Build for windows. Binary will be located at ./build/
GOOS=windows GOARCH=amd64 go build -o ./build/BitburnerGoFilesync_win.exe .
build-linux: ##@build Build for linux. Binary will be located at ./build/
GOOS=linux GOARCH=amd64 go build -o ./build/BitburnerGoFilesync_linux .
build-mac: ##@build Build for linux. Binary will be located at ./build/
GOOS=darwin GOARCH=amd64 go build -o ./build/BitburnerGoFilesync_mac .
build: ##@build Build for both windows and linux. Binary will be located at ./build/
$(MAKE) build-win
$(MAKE) build-linux
$(MAKE) build-mac
# -- Release --
.PHONY: tag patch minor major
tag: ##@versioning Push tags
git push --tags
patch: ##@versioning Create and add a patch tag (vx.x.+commits)
git tag "v$(MAJOR).$(MINOR).$(NEXT_PATCH)"
minor: ##@versioning Create and add a minor tag (vx.+1.x)
git tag "v$(MAJOR).$(NEXT_MINOR).0"
major: ##@versioning Create and add a major tag (v+1.x.x)
git tag "v$(NEXT_MAJOR).0.0"