1 | SHELL := /usr/bin/env bash -o pipefail |
---|---|
2 | |
3 | GIT_VERSION ?= $(shell git describe --always --tags --match 'v*' --dirty) |
4 | COMMIT ?= $(shell git rev-parse HEAD) |
5 | BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) |
6 | BUILD_DATE ?= $(shell date +%s) |
7 | BUILD_HOST ?= $(shell hostname) |
8 | BUILD_USER ?= $(shell id -un) |
9 | |
10 | PROJECT := go-callvis |
11 | BUILD_DIR ?= .build |
12 | |
13 | GOOS ?= $(shell go env GOOS) |
14 | GOARCH = amd64 |
15 | PLATFORMS := linux-$(GOARCH) darwin-$(GOARCH) |
16 | |
17 | GO_BUILD_TAGS ?= "" |
18 | GO_LDFLAGS := \ |
19 | -X main.commit=$(GIT_VERSION) |
20 | GO_FILES := $(shell go list ./... | xargs go list -f '{{ range $$file := .GoFiles }} {{$$.Dir}}/{{$$file}}{{"\n"}}{{end}}') |
21 | |
22 | ifeq ($(NOSTRIP),) |
23 | GO_LDFLAGS += -w -s |
24 | endif |
25 | |
26 | ifeq ($(NOTRIM),) |
27 | GO_BUILD_ARGS += -trimpath |
28 | endif |
29 | |
30 | ifeq ($(V),1) |
31 | GO_BUILD_ARGS += -v |
32 | endif |
33 | |
34 | export GO111MODULE=on |
35 | export DOCKER_BUILDKIT=1 |
36 | |
37 | help: |
38 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
39 | |
40 | build: ## Build go-callvis |
41 | go build -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" $(GO_BUILD_ARGS) |
42 | |
43 | test: ## Run unit tests |
44 | go test -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" $(GO_BUILD_ARGS) -short -race ./... |
45 | |
46 | install: ## Install go-callvis |
47 | go install -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" $(GO_BUILD_ARGS) |
48 | |
49 | $(BUILD_DIR)/$(PROJECT): $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH) |
50 | cp $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH) $@ |
51 | |
52 | $(BUILD_DIR)/$(PROJECT)-%-$(GOARCH): $(GO_FILES) $(BUILD_DIR) |
53 | GOOS=$* GOARCH=$(GOARCH) go build -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" -o $@ $(GO_BUILD_ARGS) |
54 | |
55 | %.sha256: % |
56 | shasum -a 256 $< &> $@ |
57 | |
58 | $(BUILD_DIR): |
59 | mkdir -p $(BUILD_DIR) |
60 | |
61 | .PRECIOUS: $(foreach platform, $(PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform)) |
62 | |
63 | cross: $(foreach platform, $(PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform).sha256) |
64 | |
65 | release: cross ## Release go-callvis |
66 | ls -hl $(BUILD_DIR) |
67 | |
68 | clean: ## Clean build directory |
69 | rm -vrf $(BUILD_DIR) |
70 | |
71 | .PHONY: help build test install cross release clean |
72 |
Members