Makefile 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. ## Taken from http://www.codershaven.com/multi-platform-makefile-for-go/
  2. ## Could be a good possibility if more than one platform must be supported
  3. ## It also use the git version as version for the binary.
  4. EXECUTABLE=bin/autorestsrv
  5. WINDOWS=$(EXECUTABLE)_windows_amd64.exe
  6. LINUX=$(EXECUTABLE)_linux_amd64
  7. DARWIN=$(EXECUTABLE)_darwin_amd64
  8. VERSION=$(shell git describe --tags --always --long --dirty)
  9. LDFLAGS=-s -w -X main.version=$(VERSION)
  10. windows: $(WINDOWS) ## Build for Windows
  11. linux: $(LINUX) ## Build for Linux
  12. darwin: $(DARWIN) ## Build for Darwin (macOS)
  13. $(WINDOWS):
  14. env GOOS=windows GOARCH=amd64 go build -i -v -o $(WINDOWS) -ldflags="$(LDFLAGS)"
  15. $(LINUX):
  16. env GOOS=linux GOARCH=amd64 go build -i -v -o $(LINUX) -ldflags="$(LDFLAGS)"
  17. $(DARWIN):
  18. env GOOS=darwin GOARCH=amd64 go build -i -v -o $(DARWIN) -ldflags="$(LDFLAGS)"
  19. build: windows linux darwin ## Build binaries
  20. @echo version: $(VERSION)
  21. all: test build ## Build and run tests
  22. test: ## Run unit tests
  23. go test
  24. clean: ## Remove previous build
  25. rm -f $(WINDOWS) $(LINUX) $(DARWIN)
  26. help: ## Display available commands
  27. @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'