forked from bjarneo/ku
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
38 lines (30 loc) · 1.08 KB
/
Copy pathMakefile
File metadata and controls
38 lines (30 loc) · 1.08 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
BINARY := ku
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
LDFLAGS := -s -w -X main.version=$(VERSION)
.PHONY: build install run test vet tidy clean
build:
go build -trimpath -ldflags="$(LDFLAGS)" -o $(BINARY) .
# install picks a destination directory by precedence (override with PREFIX=...):
# 1) ~/.local/bin, if it is on $PATH
# 2) /usr/local/bin, if it exists
# 3) the last directory on $PATH
install: build
@dest="$(PREFIX)"; \
if [ -z "$$dest" ]; then \
case ":$$PATH:" in *":$$HOME/.local/bin:"*) dest="$$HOME/.local/bin" ;; esac; \
fi; \
if [ -z "$$dest" ] && [ -d /usr/local/bin ]; then dest="/usr/local/bin"; fi; \
if [ -z "$$dest" ]; then dest="$$(printf '%s' "$$PATH" | tr ':' '\n' | grep -v '^$$' | tail -n1)"; fi; \
if [ -z "$$dest" ]; then echo "install: could not determine a bin directory"; exit 1; fi; \
mkdir -p "$$dest" && install -m 0755 $(BINARY) "$$dest/$(BINARY)" && \
echo "installed $(BINARY) -> $$dest/$(BINARY)"
run:
go run .
test:
go test ./...
vet:
go vet ./...
tidy:
go mod tidy
clean:
rm -f $(BINARY)