forked from cycloidio/inframap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
78 lines (60 loc) · 2.47 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
BIN := inframap
TOOL_BIN := $(PWD)/bin
GOLINT := $(TOOL_BIN)/golint
GOIMPORTS := $(TOOL_BIN)/goimports
ENUMER := $(TOOL_BIN)/enumer
PKGER := $(TOOL_BIN)/go-bindata
ARCHITECTURES=386 amd64
PLATFORMS=darwin linux windows
VERSION= $(shell git describe --tags --always)
# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS=-ldflags "-X github.com/cycloidio/inframap/cmd.Version=${VERSION}"
.PHONY: help
help: Makefile ## This help dialog
@IFS=$$'\n' ; \
help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//'`); \
for help_line in $${help_lines[@]}; do \
IFS=$$'#' ; \
help_split=($$help_line) ; \
help_command=`echo $${help_split[0]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
help_info=`echo $${help_split[2]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
printf "%-30s %s\n" $$help_command $$help_info ; \
done
$(ENUMER):
@GOBIN=$(TOOL_BIN) go install github.com/dmarkham/enumer
$(GOLINT):
@GOBIN=$(TOOL_BIN) go install golang.org/x/lint/golint
$(GOIMPORTS):
@GOBIN=$(TOOL_BIN) go install golang.org/x/tools/cmd/goimports
$(PKGER):
@GOBIN=$(TOOL_BIN) go install github.com/markbates/pkger/cmd/pkger
.PHONY: test
test: ## Tests all the project
@go test ./...
.PHONY: lint
lint: $(GOLINT) $(GOIMPORTS) ## Runs the linter
@$(GOLINT) -set_exit_status ./... && test -z "`go list -f {{.Dir}} ./... | xargs $(GOIMPORTS) -l | tee /dev/stderr`"
.PHONY: generate
generate: $(ENUMER) ## Generates the needed code
@go generate ./...
.PHONY: generate-icons
generate-icons: $(PKGER) ## Generates the needed code and Icons, it's separated as the icons generate always a new output
@go generate -tags icons ./...
.PHONY: build
build: ## Builds the binary
go build -o $(BIN) ${LDFLAGS}
.PHONY: install
install: ## Install the binary
go install ${LDFLAGS}
.PHONY: build-all build-compress
build-all: ## Builds the binaries
$(foreach GOOS, $(PLATFORMS),\
$(foreach GOARCH, $(ARCHITECTURES),\
$(shell export GO111MODULE=on; export CGO_ENABLED=0; export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build -v -o $(BUILD_PATH)/$(BIN)-$(GOOS)-$(GOARCH) ${LDFLAGS})))
build-compress: build-all ## Builds and compress the binaries
$(foreach GOOS, $(PLATFORMS),\
$(foreach GOARCH, $(ARCHITECTURES),\
$(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); tar -C $(BUILD_PATH) -czf $(BUILD_PATH)/$(BIN)-$(GOOS)-$(GOARCH).tar.gz $(BIN)-$(GOOS)-$(GOARCH))))
.PHONY: dbuild
dbuild: ## Builds the docker image with same name as the binary
@docker build -t $(BIN) .