2020-02-01 21:13:59 +00:00
|
|
|
.PHONY: usage build test run tidy release release-all
|
2019-11-17 16:17:24 +00:00
|
|
|
|
|
|
|
OK_COLOR=\033[32;01m
|
|
|
|
NO_COLOR=\033[0m
|
|
|
|
ERROR_COLOR=\033[31;01m
|
|
|
|
WARN_COLOR=\033[33;01m
|
|
|
|
|
|
|
|
PKGS = $(shell go list ./...)
|
|
|
|
BIN = git-sv
|
|
|
|
|
|
|
|
ECHOFLAGS ?=
|
|
|
|
|
2020-02-01 21:44:51 +00:00
|
|
|
BUILD_TIME = $(shell date +"%Y%m%d%H%M")
|
|
|
|
VERSION ?= dev-$(BUILD_TIME)
|
2019-12-04 23:18:38 +00:00
|
|
|
|
2019-11-17 16:17:24 +00:00
|
|
|
BUILDOS ?= linux
|
|
|
|
BUILDARCH ?= amd64
|
|
|
|
BUILDENVS ?= CGO_ENABLED=0 GOOS=$(BUILDOS) GOARCH=$(BUILDARCH)
|
2019-12-04 23:18:38 +00:00
|
|
|
BUILDFLAGS ?= -a -installsuffix cgo --ldflags '-X main.Version=$(VERSION) -extldflags "-lm -lstdc++ -static"'
|
2019-11-17 16:17:24 +00:00
|
|
|
|
|
|
|
usage: Makefile
|
|
|
|
@echo $(ECHOFLAGS) "to use make call:"
|
|
|
|
@echo $(ECHOFLAGS) " make <action>"
|
|
|
|
@echo $(ECHOFLAGS) ""
|
|
|
|
@echo $(ECHOFLAGS) "list of available actions:"
|
|
|
|
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
|
|
|
|
|
|
|
|
## build: build git-sv
|
|
|
|
build: test
|
|
|
|
@echo $(ECHOFLAGS) "$(OK_COLOR)==> Building binary ($(BUILDOS)/$(BUILDARCH)/$(BIN))...$(NO_COLOR)"
|
|
|
|
@$(BUILDENVS) go build -v $(BUILDFLAGS) -o bin/$(BUILDOS)_$(BUILDARCH)/$(BIN) ./cmd/git-sv
|
|
|
|
|
|
|
|
## test: run unit tests
|
|
|
|
test:
|
|
|
|
@echo $(ECHOFLAGS) "$(OK_COLOR)==> Running tests...$(NO_COLOR)"
|
|
|
|
@go test $(PKGS)
|
|
|
|
|
2019-12-04 22:35:47 +00:00
|
|
|
## run: run git-sv
|
2019-11-17 16:17:24 +00:00
|
|
|
run:
|
|
|
|
@echo $(ECHOFLAGS) "$(OK_COLOR)==> Running bin/$(BUILDOS)_$(BUILDARCH)/$(BIN)...$(NO_COLOR)"
|
|
|
|
@./bin/$(BUILDOS)_$(BUILDARCH)/$(BIN) $(args)
|
|
|
|
|
|
|
|
## tidy: execute go mod tidy
|
|
|
|
tidy:
|
|
|
|
@echo $(ECHOFLAGS) "$(OK_COLOR)==> runing tidy"
|
2019-12-04 23:46:22 +00:00
|
|
|
@go mod tidy
|
|
|
|
|
|
|
|
## release: prepare binary for release
|
|
|
|
release:
|
|
|
|
make build
|
|
|
|
@zip -j bin/git-sv_$(VERSION)_$(BUILDOS)_$(BUILDARCH).zip bin/$(BUILDOS)_$(BUILDARCH)/$(BIN)
|
|
|
|
|
|
|
|
## release-all: prepare linux, darwin and windows binary for release
|
|
|
|
release-all:
|
|
|
|
@rm -rf bin
|
|
|
|
BUILDOS=linux make release
|
|
|
|
BUILDOS=darwin make release
|
|
|
|
BUILDOS=windows make release
|