-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
54 lines (40 loc) · 1.16 KB
/
Makefile
File metadata and controls
54 lines (40 loc) · 1.16 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
BINARY := queryit
MODULE := $(shell go list -m)
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -s -w \
-X main.version=$(VERSION) \
-X main.commit=$(COMMIT) \
-X main.buildDate=$(BUILD_DATE)
PREFIX ?= /usr/local
BINDIR := $(PREFIX)/bin
.PHONY: all build install uninstall clean fmt vet lint test run
all: build
build:
go build -ldflags "$(LDFLAGS)" -o $(BINARY) .
INSTALL_CMD := install
ifeq ($(shell test -w $(BINDIR) 2>/dev/null || echo no), no)
INSTALL_CMD := sudo install
endif
install: build
$(INSTALL_CMD) -d $(BINDIR)
$(INSTALL_CMD) -m 755 $(BINARY) $(BINDIR)/$(BINARY)
@echo "Installed $(BINARY) to $(BINDIR)/$(BINARY)"
uninstall:
$(INSTALL_CMD) -d $(BINDIR)
rm -f $(BINDIR)/$(BINARY) 2>/dev/null || sudo rm -f $(BINDIR)/$(BINARY)
@echo "Removed $(BINDIR)/$(BINARY)"
clean:
rm -f $(BINARY)
clean-cache:
rm -rf $${XDG_CACHE_HOME:-$$HOME/.cache}/queryit
@echo "Cache cleared"
fmt:
gofmt -w .
vet:
go vet ./...
test:
go test ./...
run: build
./$(BINARY)