Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. -include .env
  2.  
  3. PROJECTNAME := $(shell basename "$(PWD)")
  4.  
  5. GO ?= go
  6. GOBUILD := $(GO) build
  7. GOARCH := amd64
  8. BIN_DIR := ./bin
  9. GOFILES := $(shell find . -name "*.go")
  10.  
  11. # These are injected into the build.
  12. BUILD_TIME := $(shell date "+%s")
  13. VERSION := $(shell git describe master --tags --abbrev=0)
  14. COMMIT := $(shell git rev-parse --short HEAD)
  15.  
  16. # Use linker flags to provide version/build settings.
  17. LDFLAGS=-ldflags "-X=main.Version=$(VERSION) -X=main.Commit=$(COMMIT) -X main.BuildTime=$(BUILD_TIME)"
  18.  
  19. # Use this for the package directory name.
  20. PKG_DIR := $(PROJECTNAME)-$(VERSION)
  21.  
  22. ## `make`: By default, build binaries for all platforms. To parallelize do `make -j3`.
  23. .PHONY: default
  24. default: all
  25.  
  26. ## `make all`: Build binaries for all platforms. To parallelize do `make -j3`.
  27. .PHONY: all
  28. all: darwin linux windows
  29.  
  30. .PHONY: darwin linux windows
  31. ## `make darwin`: Build binary for darwin.
  32. darwin: vet $(BIN_DIR)/$(PROJECTNAME)_darwin_$(GOARCH)
  33. ## `make linux`: Build binary for linux.
  34. linux: vet $(BIN_DIR)/$(PROJECTNAME)_linux_$(GOARCH)
  35. ## `make windows`: Build binary for windows.
  36. windows: vet $(BIN_DIR)/$(PROJECTNAME)_windows_$(GOARCH).exe
  37.  
  38. ## `make vet`: Run go vet to see if there are any issues.
  39. .PHONY: vet
  40. vet:
  41. $(info > Checking if there are issues reported by go vet...)
  42. @$(GO) vet -composites=false ./...
  43.  
  44. ## `make test`: Run integrations test to identify test issues.
  45. .PHONY: test
  46. test:
  47. $(info > Running integration test...)
  48. @$(GO) test -v ./test
  49.  
  50. ## `make outdated`: Check dependencies to see if there are any outdated.
  51. .PHONY: outdated
  52. outdated:
  53. $(info > Checking if there is any outdated dependencies...)
  54. @$(GO) list -u -m -f '{{if not .Indirect}}{{if .Update}}{{.}}{{end}}{{end}}' all 2> /dev/null
  55.  
  56. ## `make clean`: Clean build files. Runs `go clean` internally.
  57. .PHONY: clean
  58. clean:
  59. $(info > Cleaning build cache...)
  60. @-rm -rf $(BIN_DIR)
  61. @$(GO) clean
  62.  
  63. ## `make package`: Creates a zip file of binaries, testdata, and Readme.
  64. .PHONY: package
  65. package: all
  66. $(info > Creating package in $(PKG_DIR)...)
  67. mkdir -p $(PKG_DIR)
  68. cp README.md $(PKG_DIR)
  69. cp -r bin $(PKG_DIR)
  70. cp -r test/testdata $(PKG_DIR)
  71. zip -r $(PKG_DIR).zip $(PKG_DIR)
  72. rm -rf $(PKG_DIR)
  73.  
  74. # Darwin/Linux Build
  75. $(BIN_DIR)/$(PROJECTNAME)_%_$(GOARCH): $(GOFILES)
  76. $(info > Building binary for $*...)
  77. CGO_ENABLED=0 GOOS=$* GOARCH=$(GOARCH) $(GOBUILD) $(LDFLAGS) -o $(BIN_DIR)/$(PROJECTNAME)_$*_$(GOARCH)
  78.  
  79. # Windows Build
  80. $(BIN_DIR)/$(PROJECTNAME)_%_$(GOARCH).exe: $(GOFILES)
  81. $(info > Building binary for $*...)
  82. CGO_ENABLED=0 GOOS=$* GOARCH=$(GOARCH) $(GOBUILD) $(LDFLAGS) -o $(BIN_DIR)/$(PROJECTNAME)_$*_$(GOARCH).exe
  83.  
  84. .PHONY: help
  85. help: Makefile
  86. @echo
  87. @echo " Choose a command run in "$(PROJECTNAME)":"
  88. @echo
  89. @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
  90. @echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement