Makefile 683 B

123456789101112131415161718192021222324252627282930
  1. .PHONY: build clean test test-race
  2. VERSION=$(shell git describe --tags `git rev-list --tags --max-count=1`)
  3. BIN=backup-x
  4. DIR_SRC=.
  5. DOCKER_CMD=docker
  6. GO_ENV=CGO_ENABLED=0
  7. GO_FLAGS=-ldflags="-X main.version=$(VERSION) -X 'main.buildTime=`date`' -extldflags -static"
  8. GO=$(GO_ENV) $(shell which go)
  9. GOROOT=$(shell `which go` env GOROOT)
  10. GOPATH=$(shell `which go` env GOPATH)
  11. build: $(DIR_SRC)/main.go
  12. @$(GO) build $(GO_FLAGS) -o $(BIN) $(DIR_SRC)
  13. build_docker_image:
  14. @$(DOCKER_CMD) build -f ./Dockerfile -t backup-x:$(VERSION) .
  15. test:
  16. @$(GO) test ./... -v
  17. test-race:
  18. @$(GO) test -race ./...
  19. # clean all build result
  20. clean:
  21. @$(GO) clean ./...
  22. @rm -f $(BIN)
  23. @rm -rf ./dist/*