-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
52 lines (40 loc) · 1.06 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
PROJECT := avatar
PKG := github.com/jadefish
BINARIES := login game
# Go and tools:
GO ?= $(shell command -v go)
FMT ?= $(GO) fmt
VET ?= $(GO) vet
# Platform, architecture, and build flags:
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOFLAGS ?= -v
# Directories and files:
SRC_FILES = $(wildcard **/*.go)
BIN_DIR ?= bin
COVERAGE_DIR ?= coverage
PKG := $(BINARIES:%=$(PKG)/$(PROJECT)/cmd/%)
TARGETS := $(BINARIES:%=$(BIN_DIR)/%)
.PHONY: go fmt vet deploy clean test coverage
build: $(TARGETS)
default: $(TARGETS) fmt vet
$(TARGETS): go $(BIN_DIR) $(SRC_FILES)
env GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build $(GOFLAGS) -o $(BIN_DIR) $(PKG)
$(BIN_DIR):
test -d $(BIN_DIR) || mkdir -p $(BIN_DIR)
fmt:
$(FMT) ./...
vet:
$(VET) ./...
clean:
test -d $(BIN_DIR) && $(RM) -r $(BIN_DIR)
test -d $(COVERAGE_DIR) && $(RM) -r $(COVERAGE_DIR)
test:
$(GO) test ./...
coverage:
$(GO) test -coverprofile=$(COVERAGE_DIR)/cover.out ./...
$(GO) tool cover -html=$(COVERAGE_DIR)/cover.out -o $(COVERAGE_DIR)/cover.html
go:
ifndef GO
$(error Unable to locate go)
endif