-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
73 lines (55 loc) · 1.5 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
72
73
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
PROJECT_NAME := point
ENV ?= dev
STORAGE ?=
LDFLAGS ?= -X main.version=$(VERSION)
BUILDFLAGS ?= -a -ldflags '$(LDFLAGS)'
TEST_FLAGS ?= -count=1
GO ?= go
APPSOURCES := $(wildcard ./*.go cmd/point/*.go)
TAGS := $(ENV)
ifneq ($(STORAGE), )
TAGS += storage_$(STORAGE)
endif
export CGO_ENABLED=0
ifneq ($(ENV), dev)
LDFLAGS += -s -w -extldflags "-static"
BUILDFLAGS += -trimpath
endif
ifeq ($(shell git describe --always > /dev/null 2>&1 ; echo $$?), 0)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD | tr '/' '-')
HASH=$(shell git rev-parse --short HEAD)
VERSION ?= $(shell printf "%s-%s" "$(BRANCH)" "$(HASH)")
endif
ifeq ($(shell git describe --tags > /dev/null 2>&1 ; echo $$?), 0)
VERSION ?= $(shell git describe --tags | tr '/' '-')
endif
BUILD := $(GO) build $(BUILDFLAGS)
TEST := $(GO) test $(BUILDFLAGS)
.PHONY: all point download run clean test coverage
all: point
download: go.sum
go.sum: go.mod
$(GO) mod download all
$(GO) mod tidy
point: bin/point
bin/point: go.mod go.sum $(APPSOURCES)
$(BUILD) -tags "$(TAGS)" -o $@ ./cmd/point
run: ./bin/point
@./bin/point
clean:
-$(RM) bin/*
$(MAKE) -C images $@
images:
$(MAKE) -C images $@
test: TEST_TARGET := .
test: go.sum
$(TEST) $(TEST_FLAGS) -tags "$(TAGS)" $(TEST_TARGET)
coverage: TEST_TARGET := .
coverage: TEST_FLAGS += -covermode=count -coverprofile $(PROJECT_NAME).coverprofile
coverage: test