yk-cli/Makefile
2021-12-02 16:07:47 -08:00

48 lines
939 B
Makefile

VERSION ?= $(shell git describe --tags --dirty)
NAME := yk
GOFILES = *.go go.mod go.sum
# Multi-arch targets are generated from this
TARGET_ALIAS = $(NAME)-linux-amd64 $(NAME)-linux-arm $(NAME)-linux-arm64 $(NAME)-darwin-amd64 $(NAME)-darwin-arm64
TARGETS = $(addprefix dist/,$(TARGET_ALIAS))
.PHONY: default
default: build/yk
.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/,$@)