-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
119 lines (92 loc) · 3.58 KB
/
Makefile
File metadata and controls
119 lines (92 loc) · 3.58 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
main_package_path = .
binary_name = 3lv
build_dir = ./dist/bin
package_dir = ./dist/package
go_os = $(shell go env GOOS)
go_arch = $(shell go env GOARCH)
cli_version = $(shell cat VERSION | sed -e 's/-\(alpha\|beta\)[0-9]*//')
package_name = ${binary_name}-${cli_version}-${go_os}-${go_arch}
## help: Show this help message.
.PHONY: help
help:
@echo 'Usage:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
## test: Run unit tests.
.PHONY: test
test:
go test -v -cover ./...
## lint: Run linter (golangci-lint).
.PHONY: lint
lint:
golangci-lint run ./...
## lint-fix: Run linter (golangci-lint) with auto-fix.
.PHONY: lint-fix
lint-fix:
golangci-lint run --fix ./...
## build: Build the binary (tries to guess the OS and architecture).
.PHONY: build
build:
GOOS=${go_os} GOARCH=${go_arch} CGO_ENABLED=0 go build -o ${build_dir}/${go_os}/${go_arch}/${binary_name} ${main_package_path}
## build-linux-amd64: Build the binary for Linux (amd64).
.PHONY: build-linux-amd64
build-linux-amd64: go_os=linux
build-linux-amd64: go_arch=amd64
build-linux-amd64: build
## build-macos-amd64: Build the binary for macOS (amd64).
.PHONY: build-macos-amd64
build-macos-amd64: go_os=darwin
build-macos-amd64: go_arch=amd64
build-macos-amd64: build
## build-macos-arm64: Build the binary for macOS (arm64).
.PHONY: build-macos-arm64
build-macos-arm64: go_os=darwin
build-macos-arm64: go_arch=arm64
build-macos-arm64: build
## run: Build and then run the binary (tries to guess the OS and architecture).
.PHONY: run
run: build
${build_dir}/${go_os}/${go_arch}/${binary_name}
## package: Build and then package the binary as a tarball (tries to guess the OS and architecture).
.PHONY: package
package: build
mkdir -p ${package_dir}
tar -czf ${package_dir}/${package_name}.tar.gz LICENSE README.md -C ${build_dir}/${go_os}/${go_arch} ${binary_name}
cd ${package_dir} && md5sum ${package_name}.tar.gz > ${package_name}.tar.gz.md5
## package-linux-amd64: Build and then package the binary for Linux (amd64).
.PHONY: package-linux-amd64
package-linux-amd64: go_os=linux
package-linux-amd64: go_arch=amd64
package-linux-amd64: package
## package-macos-amd64: Build and then package the binary for macOS (amd64).
.PHONY: package-macos-amd64
package-macos-amd64: go_os=darwin
package-macos-amd64: go_arch=amd64
package-macos-amd64: package
## package-macos-arm64: Build and then package the binary for macOS (arm64).
.PHONY: package-macos-arm64
package-macos-arm64: go_os=darwin
package-macos-arm64: go_arch=arm64
package-macos-arm64: package
## install: Build and then install the binary to $HOME/.local/bin. Does not require root. Only works on Linux and macOS (tries to guess the OS and architecture).
.PHONY: install
install: build
install -Dm755 -t "$$HOME/.local/bin" ${build_dir}/${go_os}/${go_arch}/${binary_name}
## install-linux-amd64: Build and then install the binary for Linux (amd64) to /usr/local/bin. Requires root.
.PHONY: install-linux-amd64
install-linux-amd64: go_os=linux
install-linux-amd64: go_arch=amd64
install-linux-amd64: install
## install-macos-amd64: Build and then install the binary for macOS (amd64) to /usr/local/bin. Requires root.
.PHONY: install-macos-amd64
install-macos-amd64: go_os=darwin
install-macos-amd64: go_arch=amd64
install-macos-amd64: install
## install-macos-arm64: Build and then install the binary for macOS (arm64) to /usr/local/bin. Requires root.
.PHONY: install-macos-arm64
install-macos-arm64: go_os=darwin
install-macos-arm64: go_arch=arm64
install-macos-arm64: install
## clean: Remove build and package directories.
.PHONY: clean
clean:
rm -rf ${build_dir} ${package_dir}