|
| 1 | +# ================================================================= |
| 2 | +# |
| 3 | +# Copyright (C) 2019 Spatial Current, Inc. - All Rights Reserved |
| 4 | +# Released as open source under the MIT License. See LICENSE file. |
| 5 | +# |
| 6 | +# ================================================================= |
| 7 | + |
| 8 | +ifdef GOPATH |
| 9 | +GCFLAGS=-trimpath=$(shell printenv GOPATH)/src |
| 10 | +else |
| 11 | +GCFLAGS=-trimpath=$(shell go env GOPATH)/src |
| 12 | +endif |
| 13 | + |
| 14 | +LDFLAGS=-X main.gitBranch=$(shell git branch | grep \* | cut -d ' ' -f2) -X main.gitCommit=$(shell git rev-list -1 HEAD) |
| 15 | + |
| 16 | +.PHONY: help |
| 17 | +help: ## Print the help documentation |
| 18 | + @grep -E '^[a-zA-Z0-9_-\]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
| 19 | + |
| 20 | +# |
| 21 | +# Dependencies |
| 22 | +# |
| 23 | + |
| 24 | +.PHONY: deps_go |
| 25 | +deps_go: ## Install Go dependencies |
| 26 | + go get -d -t ./... |
| 27 | + |
| 28 | +.PHONY: deps_go_test |
| 29 | +deps_go_test: ## Download Go dependencies for tests |
| 30 | + go get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # download shadow |
| 31 | + go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # install shadow |
| 32 | + go get -u github.com/kisielk/errcheck # download and install errcheck |
| 33 | + go get -u github.com/client9/misspell/cmd/misspell # download and install misspell |
| 34 | + go get -u github.com/gordonklaus/ineffassign # download and install ineffassign |
| 35 | + go get -u honnef.co/go/tools/cmd/staticcheck # download and instal staticcheck |
| 36 | + go get -u golang.org/x/tools/cmd/goimports # download and install goimports |
| 37 | + |
| 38 | +.PHONY: deps_arm |
| 39 | +deps_arm: ## Install dependencies to cross-compile to ARM |
| 40 | + # ARMv7 |
| 41 | + apt-get install -y libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi libncurses5-dev gcc-arm-linux-gnueabi g++-arm-linux-gnueabi |
| 42 | + # ARMv8 |
| 43 | + apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu |
| 44 | + |
| 45 | + |
| 46 | +# |
| 47 | +# Go building, formatting, testing, and installing |
| 48 | +# |
| 49 | + |
| 50 | +.PHONY: fmt |
| 51 | +fmt: ## Format Go source code |
| 52 | + go fmt $$(go list ./... ) |
| 53 | + |
| 54 | +.PHONY: imports |
| 55 | +imports: ## Update imports in Go source code |
| 56 | + # If missing, install goimports with: go get golang.org/x/tools/cmd/goimports |
| 57 | + goimports -w $$(find . -iname '*.go') |
| 58 | + |
| 59 | +.PHONY: vet |
| 60 | +vet: ## Vet Go source code |
| 61 | + go vet $$(go list ./...) |
| 62 | + |
| 63 | +.PHONY: test_go |
| 64 | +test_go: ## Run Go tests |
| 65 | + bash scripts/test.sh |
| 66 | + |
| 67 | +.PHONY: build |
| 68 | +build: build_cli ## Build all artifacts |
| 69 | + |
| 70 | +.PHONY: install |
| 71 | +install: ## Install goprintenv on current platform |
| 72 | + go install -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/goprintenv |
| 73 | + |
| 74 | +# |
| 75 | +# Command Line Programs |
| 76 | +# |
| 77 | + |
| 78 | +bin/goprintenv_darwin_amd64: ## Build goprintenv for Darwin / amd64 |
| 79 | + GOOS=darwin GOARCH=amd64 go build -o bin/goprintenv_darwin_amd64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...) |
| 80 | + |
| 81 | +bin/goprintenv_linux_amd64: ## Build goprintenv for Linux / amd64 |
| 82 | + GOOS=linux GOARCH=amd64 go build -o bin/goprintenv_linux_amd64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...) |
| 83 | + |
| 84 | +bin/goprintenv_windows_amd64.exe: ## Build goprintenv for Windows / amd64 |
| 85 | + GOOS=windows GOARCH=amd64 go build -o bin/goprintenv_windows_amd64.exe -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...) |
| 86 | + |
| 87 | +bin/goprintenv_linux_arm64: ## Build goprintenv for Linux / arm64 |
| 88 | + GOOS=linux GOARCH=arm64 go build -o bin/goprintenv_linux_arm64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...) |
| 89 | + |
| 90 | +bin/goprintenv_linux_arm: ## Build goprintenv for Linux / arm |
| 91 | + GOOS=linux GOARCH=arm go build -o bin/goprintenv_linux_arm -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...) |
| 92 | + |
| 93 | +.PHONY: build_cli |
| 94 | +build_cli: bin/goprintenv_darwin_amd64 bin/goprintenv_linux_amd64 bin/goprintenv_windows_amd64.exe bin/goprintenv_linux_arm bin/goprintenv_linux_arm64 ## Build command line programs |
| 95 | + |
| 96 | +## Clean |
| 97 | + |
| 98 | +.PHONY: clean |
| 99 | +clean: ## Clean artifacts |
| 100 | + rm -fr bin |
| 101 | + rm -fr dist |
0 commit comments