-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
74 lines (58 loc) · 1.67 KB
/
Makefile
File metadata and controls
74 lines (58 loc) · 1.67 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
# Makefile for torrbot (portable Linux binary from NixOS dev box)
# Usage:
# make # build
# make run # run locally
# make test # run tests
# make fmt vet lint
# make tidy
# make clean
APP := torrbot
PKG := ./...
BIN_DIR := bin
OUT := $(BIN_DIR)/$(APP)
GOOS ?= linux
GOARCH ?= amd64
CGO_ENABLED ?= 0
# Version info (optional, but handy)
GIT_SHA := $(shell git rev-parse --short HEAD 2>/dev/null || echo "nogit")
GIT_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
GIT_DESCR := $(shell git describe --tags 2>/dev/null || echo "v0.0.0-0-nogit")
BUILD_DATE:= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
# Flags
GOFLAGS ?=
LDFLAGS := -s -w \
-X main.Version=$(GIT_TAG) \
-X main.GitCommit=$(GIT_SHA) \
-X main.BuildDate=$(BUILD_DATE)
.PHONY: all build run test fmt vet lint tidy clean tools info
all: build
build:
@mkdir -p $(BIN_DIR)
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) \
go build $(GOFLAGS) -trimpath -ldflags='$(LDFLAGS)' -o $(OUT)$(if $(filter windows,$(GOOS)),.exe) .
run: build
./$(OUT)
test:
go test $(PKG)
fmt:
go fmt $(PKG)
vet:
go vet $(PKG)
# Installs tools to GOPATH/bin (or GOBIN) if missing
tools:
@command -v golangci-lint >/dev/null 2>&1 || { \
echo "Installing golangci-lint..."; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
}
lint: tools
@PATH="$$(go env GOPATH)/bin:$$PATH" golangci-lint run
tidy:
go mod tidy
clean:
rm -rf $(BIN_DIR)
info:
@echo "APP=$(APP)"
@echo "OUT=$(OUT)"
@echo "GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED)"
@echo "GIT_SHA=$(GIT_SHA)"
@echo "BUILD_DATE=$(BUILD_DATE)"