-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
83 lines (64 loc) · 2 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
74
75
76
77
78
79
80
81
82
83
# Copyright 2018 AtrioInc
SHELL=/bin/bash -u
export GOPATH ?= $(shell echo $(CURDIR) | sed -e 's,/src/.*,,')
BASE := ${PWD}
PACKAGE := multi-cri
ABSOLUTE_PROJECT = $(GOPATH)/src/multi-cri
PROJECT := $(shell realpath --relative-to=$(CURDIR) $(ABSOLUTE_PROJECT))
FIND_PROJECT_DIRS = find $(PROJECT) -mindepth 1 -maxdepth 1 -type d -not -name vendor -not -name '_vendor-*'
PROJECT_DIRS := $(shell $(FIND_PROJECT_DIRS))
FIND_PROJECT_FILES = find $(PROJECT_DIRS) -name '*.go'
PROJECT_FILES := $(shell $(FIND_PROJECT_FILES))
BIN := $(shell realpath --relative-to=$(CURDIR) $(GOPATH)/bin/)
DEP ?= $(BIN)/dep
GOIMPORTS ?= $(BIN)/goimports$(BIN_ARCH)
GOIMPORTS_CMD = $(GOIMPORTS) -local multi-cri
.PHONY: all
all: build
goimports: $(GOIMPORTS)
$(GOIMPORTS):
@echo Building $(GOIMPORTS)...
@go get -u golang.org/x/tools/cmd/goimports
dep: $(DEP)
$(DEP):
@echo Building $(DEP)...
@go get -u github.com/golang/dep/cmd/dep
tools: $(GOIMPORTS) $(DEP)
build: govendor
@echo Building in bin/${PACKAGE}...
@go build -o bin/${PACKAGE} main.go
build-static:
@echo Building in bin/${PACKAGE}_static...
@CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o bin/${PACKAGE}_static main.go
clean:
rm -rf bin
rm -rf vendor
rm -rf $(GOPATH)/bin
rm -rf $(GOPATH)/pkg
rm -rf $(GOPATH)/src/golang.org
rm -rf $(GOPATH)/src/github.com
.PHONY: test
test:
: Unit tests
go test -run Unit ./...
.PHONY: integration
integration:
: Integration tests
go test -run Integration ./...
# install vendor packages required by Gopkg and original code
govendor: $(BASE)/vendor
$(BASE)/vendor: dep Gopkg.toml
@echo Updating govendor dependencies
@$(DEP) ensure -v
GOIMPORTS_PATCH = $(PROJECT)/.patch
GOIMPORTS_CMD = $(GOIMPORTS) -local rstor
.PHONY: imports
imports: $(GOIMPORTS)
: Imports
@$(GOIMPORTS_CMD) -d $(PROJECT_FILES) | tee $(GOIMPORTS_PATCH)
@[[ ! -s $(GOIMPORTS_PATCH) ]]
.PHONY: fix
fix: $(GOIMPORTS)
: Fix
@$(GOIMPORTS_CMD) -d $(PROJECT_FILES)
@$(GOIMPORTS_CMD) -w $(PROJECT_FILES)