-
-
Notifications
You must be signed in to change notification settings - Fork 415
/
Makefile
71 lines (50 loc) · 1.94 KB
/
Makefile
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
SHELL := /usr/bin/env bash -o pipefail
GIT_VERSION ?= $(shell git describe --always --tags --match 'v*' --dirty)
COMMIT ?= $(shell git rev-parse HEAD)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
BUILD_DATE ?= $(shell date +%s)
BUILD_HOST ?= $(shell hostname)
BUILD_USER ?= $(shell id -un)
PROJECT := go-callvis
BUILD_DIR ?= .build
GOOS ?= $(shell go env GOOS)
GOARCH = amd64
PLATFORMS := linux-$(GOARCH) darwin-$(GOARCH)
GO_BUILD_TAGS ?= ""
GO_LDFLAGS := \
-X main.commit=$(GIT_VERSION)
GO_FILES := $(shell go list ./... | xargs go list -f '{{ range $$file := .GoFiles }} {{$$.Dir}}/{{$$file}}{{"\n"}}{{end}}')
ifeq ($(NOSTRIP),)
GO_LDFLAGS += -w -s
endif
ifeq ($(NOTRIM),)
GO_BUILD_ARGS += -trimpath
endif
ifeq ($(V),1)
GO_BUILD_ARGS += -v
endif
export GO111MODULE=on
export DOCKER_BUILDKIT=1
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
build: ## Build go-callvis
go build -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" $(GO_BUILD_ARGS)
test: ## Run unit tests
go test -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" $(GO_BUILD_ARGS) -short -race ./...
install: ## Install go-callvis
go install -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" $(GO_BUILD_ARGS)
$(BUILD_DIR)/$(PROJECT): $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH)
cp $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH) $@
$(BUILD_DIR)/$(PROJECT)-%-$(GOARCH): $(GO_FILES) $(BUILD_DIR)
GOOS=$* GOARCH=$(GOARCH) go build -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" -o $@ $(GO_BUILD_ARGS)
%.sha256: %
shasum -a 256 $< &> $@
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
.PRECIOUS: $(foreach platform, $(PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform))
cross: $(foreach platform, $(PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform).sha256)
release: cross ## Release go-callvis
ls -hl $(BUILD_DIR)
clean: ## Clean build directory
rm -vrf $(BUILD_DIR)
.PHONY: help build test install cross release clean