You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB

APP_NAME = imap-notes
VERSION ?= $(shell git describe --tags --dirty)
GOFILES = *.go
# Multi-arch targets are generated from this
TARGET_ALIAS = $(APP_NAME)-linux-amd64 $(APP_NAME)-linux-arm $(APP_NAME)-linux-arm64 $(APP_NAME)-darwin-amd64 $(APP_NAME)-darwin-arm64
TARGETS = $(addprefix dist/,$(TARGET_ALIAS))
# Default make target will run tests
# Build all static Minitor binaries
.PHONY: all
all: $(TARGETS)
# Build all static Linux Minitor binaries
.PHONY: all-linux
all-linux: $(filter dist/$(APP_NAME)-linux-%,$(TARGETS))
# Build imap-notes for the current machine
@echo Version: $(VERSION)
go build -ldflags '-X "main.version=$(VERSION)"' -o $(APP_NAME)
.PHONY: build
build: $(APP_NAME)
# Run all tests
.PHONY: test
go test -coverprofile=coverage.out
go tool cover -func=coverage.out
@go tool cover -func=coverage.out | awk -v target=80.0% \
'/^total:/ { print "Total coverage: " $3 " Minimum coverage: " target; if ($3+0.0 >= target+0.0) print "ok"; else { print "fail"; exit 1; } }'
# Installs pre-commit hooks
.PHONY: install-hooks
pre-commit install --install-hooks
# Runs pre-commit checks on files
.PHONY: check
pre-commit run --all-files
.PHONY: clean
rm -f ./$(APP_NAME)
rm -f ./coverage.out
rm -fr ./dist
## Multi-arch targets
mkdir -p ./dist
GOOS=$(word 2, $(subst -, ,$(@))) GOARCH=$(word 3, $(subst -, ,$(@))) CGO_ENABLED=0 \
go build -ldflags '-X "main.version=$(VERSION)"' -a -installsuffix nocgo \
-o $@
$(MAKE) $(addprefix dist/,$@)