11# =================================================================
22#
3- # Copyright (C) 2019 Spatial Current, Inc. - All Rights Reserved
3+ # Copyright (C) 2020 Spatial Current, Inc. - All Rights Reserved
44# Released as open source under the MIT License. See LICENSE file.
55#
66# =================================================================
77
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- ifndef DEST
17- DEST =bin
18- endif
19-
208.PHONY : help
21-
229help : # # Print the help documentation
23- @grep -E ' ^[a-zA-Z0-9_-\]+:.*?## .*$$' $(MAKEFILE_LIST ) | sort | awk ' BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
24-
25- #
26- # Dependencies
27- #
28-
29- deps_go : # # Install Go dependencies
30- go get -d -t ./...
31-
32- .PHONY : deps_go_test
33- deps_go_test : # # Download Go dependencies for tests
34- go get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # download shadow
35- go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # install shadow
36- go get -u github.com/kisielk/errcheck # download and install errcheck
37- go get -u github.com/client9/misspell/cmd/misspell # download and install misspell
38- go get -u github.com/gordonklaus/ineffassign # download and install ineffassign
39- go get -u honnef.co/go/tools/cmd/staticcheck # download and instal staticcheck
40- go get -u golang.org/x/tools/cmd/goimports # download and install goimports
41-
42- deps_arm : # # Install dependencies to cross-compile to ARM
43- # ARMv7
44- 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
45- # ARMv8
46- apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
10+ @grep -E ' ^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST ) | sort | awk ' BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
4711
4812#
4913# Go building, formatting, testing, and installing
@@ -53,45 +17,61 @@ fmt: ## Format Go source code
5317 go fmt $$(go list ./... )
5418
5519.PHONY : imports
56- imports : # # Update imports in Go source code
57- # If missing, install goimports with: go get golang.org/x/tools/cmd/goimports
58- goimports -w -local github.com/spatialcurrent/gocat,github.com/spatialcurrent $$(find . -iname '*.go' )
20+ imports : bin/goimports # # Update imports in Go source code
21+ bin/goimports -w -local github.com/spatialcurrent/gocat,github.com/spatialcurrent $$(find . -iname '*.go' )
5922
6023vet : # # Vet Go source code
61- go vet $$(go list ./... )
24+ go vet github.com/spatialcurrent/gocat/pkg/... # vet packages
25+ go vet github.com/spatialcurrent/gocat/cmd/... # vet commands
26+
27+ tidy : # # Tidy Go source code
28+ go mod tidy
6229
6330.PHONY : test_go
64- test_go : # # Run Go tests
31+ test_go : bin/errcheck bin/misspell bin/staticcheck bin/shadow # # Run Go tests
6532 bash scripts/test.sh
6633
6734.PHONY : test_cli
68- test_cli : # # Run CLI tests
35+ test_cli : bin/gocat # # Run CLI tests
6936 bash scripts/test-cli.sh
7037
71- .PHONY : build
72- build : build_cli build_javascript build_so build_android # # Build CLI, Shared Objects (.so), JavaScript, and Android
73-
74- install : # # Install gocat CLI on current platform
75- go install -gcflags=" $( GCFLAGS) " -ldflags=" $( LDFLAGS) " github.com/spatialcurrent/gocat
38+ install : # # Install the CLI on current platform
39+ go install github.com/spatialcurrent/gocat/cmd/gocat
7640
7741#
7842# Command line Programs
7943#
8044
81- bin/gocat_darwin_amd64 : # # Build gocat CLI for Darwin / amd64
82- GOOS=darwin GOARCH=amd64 go build -o $(DEST ) /gocat_darwin_amd64 -gcflags=" $( GCFLAGS) " -ldflags=" $( LDFLAGS) " github.com/spatialcurrent/gocat
45+ bin/errcheck :
46+ go build -o bin/errcheck github.com/kisielk/errcheck
47+
48+ bin/goimports :
49+ go build -o bin/goimports golang.org/x/tools/cmd/goimports
50+
51+ bin/gox :
52+ go build -o bin/gox github.com/mitchellh/gox
8353
84- bin/gocat_linux_amd64 : # # Build gocat CLI for Linux / amd64
85- GOOS=linux GOARCH=amd64 go build -o $( DEST ) /gocat_linux_amd64 -gcflags= " $( GCFLAGS ) " -ldflags= " $( LDFLAGS ) " github.com/spatialcurrent/gocat
54+ bin/misspell :
55+ go build -o bin/misspell github.com/client9/misspell/cmd/misspell
8656
87- bin/gocat_windows_amd64.exe : # # Build gocat CLI for Windows / amd64
88- GOOS=windows GOARCH=amd64 go build -o $( DEST ) /gocat_windows_amd64.exe -gcflags= " $( GCFLAGS ) " -ldflags= " $( LDFLAGS ) " github.com/spatialcurrent/gocat
57+ bin/staticcheck :
58+ go build -o bin/staticcheck honnef.co/go/tools/cmd/staticcheck
8959
90- bin/gocat_linux_arm64 : # # Build gocat CLI for Linux / arm64
91- GOOS=linux GOARCH=arm64 go build -o $(DEST ) /gocat_linux_arm64 -gcflags=" $( GCFLAGS) " -ldflags=" $( LDFLAGS) " github.com/spatialcurrent/gocat
60+ bin/shadow :
61+ go build -o bin/shadow golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
62+
63+ bin/gocat : # # Build CLI for Darwin / amd64
64+ go build -o bin/gocat github.com/spatialcurrent/gocat/cmd/gocat
65+
66+ bin/gocat_linux_amd64 : bin/gox # # Build CLI for Darwin / amd64
67+ scripts/build-release linux amd64
68+
69+ .PHONY : build
70+ build : bin/gocat
9271
93- .PHONY : build_cli
94- build_cli : bin/gocat_darwin_amd64 bin/gocat_linux_amd64 bin/gocat_windows_amd64.exe bin/gocat_linux_arm64 # # Build command line programs
72+ .PHONY : build_release
73+ build_release : bin/gox
74+ scripts/build-release
9575
9676# # Clean
9777
0 commit comments