yk-cli/Makefile

48 lines
918 B
Makefile
Raw Normal View History

2020-12-11 04:55:55 +00:00
VERSION ?= $(shell git describe --tags --dirty)
NAME := yk
2021-01-07 19:34:33 +00:00
GOFILES = *.go go.mod go.sum
2020-12-11 04:55:55 +00:00
# Multi-arch targets are generated from this
TARGET_ALIAS = $(NAME)-linux-amd64 $(NAME)-linux-arm $(NAME)-linux-arm64 $(NAME)-darwin-amd64
TARGETS = $(addprefix dist/,$(TARGET_ALIAS))
.PHONY: default
2021-07-26 05:14:45 +00:00
default: build/yk
2020-12-11 04:55:55 +00:00
.PHONY: all
all: $(TARGETS)
.PHONY: test
test: check
go test .
.PHONY: build
build: build/yk
build/yk: $(GOFILES)
mkdir -p build
go build -o build/yk
.PHONY: clean
clean:
rm -fr build/
rm -fr dist/
.PHONY: check
check:
pre-commit run --all-files
.PHONY: install-hooks
install-hooks:
pre-commit install -f --install-hooks
# Distribution targets
$(TARGETS): $(GOFILES)
mkdir -p ./dist
GOOS=$(word 2, $(subst -, ,$(@))) GOARCH=$(word 3, $(subst -, ,$(@))) \
go build -ldflags '-X "main.version=${VERSION}"' -a \
-o $@
.PHONY: $(TARGET_ALIAS)
$(TARGET_ALIAS):
$(MAKE) $(addprefix dist/,$@)