Makefile 871 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. .DEFAULT_GOAL := all
  2. .DELETE_ON_ERROR:
  3. .SUFFIXES:
  4. include .env
  5. export
  6. PROJECT := $(shell cat go.mod | grep '^module\s' | cut -b 8-)
  7. export VERSION ?= $(shell date -u '+%F')-snapshot
  8. export DEBUG ?= 0
  9. BUILD_TIME := $(shell date -u '+%F_%T')
  10. COMMIT_HASH := $(shell git rev-parse --short HEAD)
  11. LDFLAGS := '-linkmode external -w -s -extldflags "-static" -X $(PROJECT).Version=$(VERSION)'
  12. GCFLAGS :=
  13. ifeq ($(DEBUG),1)
  14. GCFLAGS = "all=-N -l"
  15. endif
  16. .PHONY: all
  17. all: deps fmt test
  18. .PHONY: deps
  19. deps:
  20. -@echo "-> $@"
  21. go mod tidy
  22. .PHONY: fmt
  23. fmt:
  24. -@echo "-> $@"
  25. -go fmt $(shell go list ./...)
  26. .PHONY: test
  27. test:
  28. -@echo "-> $@"
  29. CGO_ENABLED=1 go test $(shell go list ./...)
  30. -go vet $(shell go list ./...)
  31. .PHONE: gen-proto
  32. gen-proto:
  33. -@echo "-> $@"
  34. @protoc -I=. --go_out=paths=source_relative:. --python_out=. proto/*.proto
  35. @cp proto/*.pb.go ./
  36. -@rm proto/*.pb.go