-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
93 lines (79 loc) · 2.22 KB
/
Makefile
File metadata and controls
93 lines (79 loc) · 2.22 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Default config
VERSION ?= $(shell echo `git describe --tag 2>/dev/null || git rev-parse --short HEAD` | sed -E 's|^v||g')
VERBOSE ?= false
# Go configuration
GOBIN := $(shell which go)
GOENV ?=
GOOPT ?=
GOLDF = -X main.Version=$(VERSION)
# Gulp configuration
GULPBIN := node_modules/.bin/gulp
GULPDIST := dist/
GULPOPT += --no-color
# Docker configuration
DOCKBIN := $(shell which docker)
DOCKIMG := blippar/balrog
DOCKOPTS += --build-arg VERSION="$(VERSION)"
# If run as 'make VERBOSE=true', it will pass the '-v' option to GOBIN and will restore docker build output
ifeq ($(VERBOSE),true)
GOOPT += -v
else
DOCKOPTS += -q
GULPOPT += -LL
.SILENT:
endif
# Target configuration
TARGET := bin/balrog
GOPKGDIR = $(@:bin/%=./cmd/%)
# Local meta targets
balrog: $(TARGET)
assets: $(GULPDIST)
all: $(TARGET) $(GULPDIST)
# Build binary with GOBIN using target name & GOPKGDIR
$(TARGET): GOOPT += -ldflags '$(GOLDF)'
$(TARGET):
$(info >>> Building $@ from $(GOPKGDIR) using $(GOBIN))
$(if $(GOENV),$(info >>> with $(GOENV) and GOOPT=$(GOOPT)),)
$(GOENV) $(GOBIN) build $(GOOPT) -o $@ $(GOPKGDIR)
# Build binary staticly
static: GOLDF += -extldflags "-static"
static: GOENV += CGO_ENABLED=0 GOOS=linux
static: $(TARGET)
# Build assets using GULPBIN
$(GULPDIST):
$(info >>> Building all assets using $(GULPBIN))
$(GULPBIN) $(GULPOPT) build
# Run tests using GOBIN
test: GOOPT += -ldflags '$(GOLDF)'
test:
$(info >>> Testing ./... using $(GOBIN))
$(GOENV) $(GOBIN) test $(GOOPT) -cover ./...
# Docker
docker:
$(info >>> Building docker image $(DOCKIMG) using $(DOCKBIN))
$(DOCKBIN) build $(DOCKOPTS) -t $(DOCKIMG):$(VERSION) -t $(DOCKIMG):latest .
# Run linters using gometalinter
lint:
$(info >>> Linting source code using gometalinter)
gometalinter \
--deadline 10m \
--vendor \
--sort="path" \
--aggregate \
--enable-gc \
--disable-all \
--enable goimports \
--enable misspell \
--enable vet \
--enable deadcode \
--enable varcheck \
--enable ineffassign \
--enable structcheck \
--enable unconvert \
--enable gofmt \
./...
# Clean
clean:
$(info >>> Cleaning up binaries and assets)
rm -rv $(TARGET) $(GULPDIST)
.PHONY: all balrog $(TARGET) $(GULPDIST) static test lint check clean