-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
78 lines (61 loc) · 2.08 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
# cna-installer makefile
PROJECTNAME := $(shell basename "$(PWD)")
# Detect OS
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OS = linux
endif
ifeq ($(UNAME_S),Darwin)
OS = darwin
endif
# Go related variables.
GOBASE := $(shell pwd)
#GOPATH := $(GOBASE)/vendor:$(GOBASE)
GOBIN := $(GOBASE)/build/bin
GOFILES := $(wildcard *.go)
TFBIN := $(GOBIN)/terraform
TFVERSION := 0.12.9
# Make is verbose in Linux. Make it silent.
MAKEFLAGS += --silent
# Redirect error output to a file, so we can show it in development mode.
STDERR := /tmp/.$(PROJECTNAME)-stderr.txt
## compile: Compile the binary.
build:
@-$(MAKE) -s go-compile 2> $(STDERR)
@cat $(STDERR)| sed -e '1s/.*/\nError:\n/' | sed 's/make\[.*/ /' | sed "/^/s/^/ /" 1>&2
## clean: Clean build files. Runs `go clean` internally.
clean:
@-rm $(GOBIN)/$(PROJECTNAME) 2> /dev/null
@-$(MAKE) go-clean
@-rm $(GOBIN)/terraform 2> /dev/null
go-compile: go-get go-build get-terraform
go-build:
@echo " > Building binary..."
@go build -o $(GOBIN)/$(PROJECTNAME) $(GOFILES)
#GOBIN=$(GOBIN) go build $(LDFLAGS) -o $(GOBIN)/$(PROJECTNAME) $(GOFILES)
go-generate:
@echo " > Generating dependency files..."
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go generate $(generate)
go-get:
@echo " > Checking if there is any missing dependencies..."
@GOBIN=$(GOBIN) go get $(get)
go-install:
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go install $(GOFILES)
go-clean:
@echo " > Cleaning build cache"
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go clean
get-terraform:
test -s $(TFBIN) && echo " > Found terraform binary at $(TFBIN). Skipping download."|| $(MAKE) download-terraform
download-terraform:
@echo " > Downloading dependent binaries..."
@curl -sS https://releases.hashicorp.com/terraform/$(TFVERSION)/terraform_$(TFVERSION)_$(OS)_amd64.zip --output $(GOBIN)/terraform.zip 2> $(STDERR)
@unzip -q -o $(GOBIN)/terraform.zip -d $(GOBIN) 2> $(STDERR)
@rm -f $(GOBIN)/terraform.zip
.PHONY: build clean help
all: help
help: Makefile
@echo
@echo " Choose a command run in "$(PROJECTNAME)":"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo