-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
69 lines (54 loc) · 1.61 KB
/
Copy pathMakefile
File metadata and controls
69 lines (54 loc) · 1.61 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
SHELL := /bin/sh
BINARY := agx
PACKAGE := ./cmd/agx
BIN_DIR := bin
DIST_DIR := dist
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || printf 'dev')
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
CGO_ENABLED ?= 0
LDFLAGS := -s -w -X main.version=$(VERSION)
EXT :=
ifeq ($(GOOS),windows)
EXT := .exe
endif
DIST_NAME := $(BINARY)_$(VERSION)_$(GOOS)_$(GOARCH)
STAGE_DIR := $(DIST_DIR)/$(DIST_NAME)
.PHONY: all build install test test-race vet check package checksums clean
all: build
build:
@mkdir -p "$(BIN_DIR)"
CGO_ENABLED=$(CGO_ENABLED) go build -trimpath -ldflags '$(LDFLAGS)' -o "$(BIN_DIR)/$(BINARY)$(EXT)" $(PACKAGE)
install:
CGO_ENABLED=$(CGO_ENABLED) go install -trimpath -ldflags '$(LDFLAGS)' $(PACKAGE)
test:
go test ./...
test-race:
go test -race ./...
vet:
go vet ./...
check: test-race vet
package:
@mkdir -p "$(STAGE_DIR)"
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) go build -trimpath -ldflags '$(LDFLAGS)' -o "$(STAGE_DIR)/$(BINARY)$(EXT)" $(PACKAGE)
@if [ "$(GOOS)" = "windows" ]; then \
(cd "$(STAGE_DIR)" && zip -q "../$(DIST_NAME).zip" "$(BINARY)$(EXT)"); \
else \
tar -C "$(STAGE_DIR)" -czf "$(DIST_DIR)/$(DIST_NAME).tar.gz" "$(BINARY)$(EXT)"; \
fi
@rm -rf "$(STAGE_DIR)"
checksums:
@mkdir -p "$(DIST_DIR)"
@cd "$(DIST_DIR)" && { \
: > checksums.txt; \
for file in $(BINARY)_*.tar.gz $(BINARY)_*.zip; do \
[ -f "$$file" ] || continue; \
if command -v sha256sum >/dev/null 2>&1; then \
sha256sum "$$file"; \
else \
shasum -a 256 "$$file"; \
fi; \
done >> checksums.txt; \
}
clean:
@rm -rf "$(BIN_DIR)" "$(DIST_DIR)"