1
0
Fork 0
git-sv/Makefile

104 lines
2.6 KiB
Makefile
Raw Normal View History

2023-10-12 14:18:25 +00:00
# renovate: datasource=github-releases depName=mvdan/gofumpt
GOFUMPT_PACKAGE_VERSION := v0.7.0
2023-10-12 14:18:25 +00:00
# renovate: datasource=github-releases depName=golangci/golangci-lint
GOLANGCI_LINT_PACKAGE_VERSION := v1.61.0
2023-10-12 14:18:25 +00:00
EXECUTABLE := git-sv
DIST := dist
DIST_DIRS := $(DIST)
IMPORT := github.com/thegeeklab/$(EXECUTABLE)
GO ?= go
CWD ?= $(shell pwd)
PACKAGES ?= $(shell go list ./...)
SOURCES ?= $(shell find . -name "*.go" -type f)
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@$(GOFUMPT_PACKAGE_VERSION)
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_PACKAGE_VERSION)
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
GOTESTSUM_PACKAGE ?= gotest.tools/gotestsum@latest
2023-10-12 14:18:25 +00:00
GENERATE ?=
XGO_VERSION := go-1.22.x
2024-06-17 13:19:45 +00:00
XGO_TARGETS ?= linux/amd64,linux/arm-6,linux/arm-7,linux/arm64,darwin/amd64,darwin/arm64
2023-10-12 14:18:25 +00:00
TARGETOS ?= linux
TARGETARCH ?= amd64
ifneq ("$(TARGETVARIANT)","")
GOARM ?= $(subst v,,$(TARGETVARIANT))
endif
TAGS ?= netgo,osusergo
ifndef VERSION
ifneq ($(CI_COMMIT_TAG),)
VERSION ?= $(subst v,,$(CI_COMMIT_TAG))
else
VERSION ?= $(shell git rev-parse --short HEAD)
endif
endif
ifndef DATE
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%S%z")
endif
2023-10-12 14:18:25 +00:00
LDFLAGS += -s -w -X "main.BuildVersion=$(VERSION)" -X "main.BuildDate=$(DATE)"
2023-10-12 14:18:25 +00:00
.PHONY: all
all: clean build
2023-10-12 14:18:25 +00:00
.PHONY: clean
clean:
$(GO) clean -i ./...
rm -rf $(DIST_DIRS)
2023-10-12 14:18:25 +00:00
.PHONY: fmt
fmt:
$(GO) run $(GOFUMPT_PACKAGE) -extra -w $(SOURCES)
2019-12-04 23:18:38 +00:00
2023-10-12 14:18:25 +00:00
.PHONY: golangci-lint
golangci-lint:
$(GO) run $(GOLANGCI_LINT_PACKAGE) run
2023-10-12 14:18:25 +00:00
.PHONY: lint
lint: golangci-lint
2023-10-12 14:18:25 +00:00
.PHONY: generate
generate:
$(GO) generate $(GENERATE)
2023-10-12 14:18:25 +00:00
.PHONY: test
test:
$(GO) run $(GOTESTSUM_PACKAGE) --no-color=false -- -coverprofile=coverage.out $(PACKAGES)
2023-10-12 14:18:25 +00:00
.PHONY: build
build: $(DIST)/$(EXECUTABLE)
2023-10-12 14:18:25 +00:00
$(DIST)/$(EXECUTABLE): $(SOURCES)
GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) GOARM=$(GOARM) $(GO) build -v -tags '$(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -o $@ ./cmd/$(EXECUTABLE)
2023-10-12 14:18:25 +00:00
$(DIST_DIRS):
mkdir -p $(DIST_DIRS)
.PHONY: xgo
xgo: | $(DIST_DIRS)
$(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -v -ldflags '-extldflags "-static" $(LDFLAGS)' -tags '$(TAGS)' -targets '$(XGO_TARGETS)' -out $(EXECUTABLE) --pkg cmd/$(EXECUTABLE) .
cp /build/* $(CWD)/$(DIST)
ls -l $(CWD)/$(DIST)
2023-10-12 14:18:25 +00:00
.PHONY: checksum
checksum:
cd $(DIST); $(foreach file,$(wildcard $(DIST)/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
ls -l $(CWD)/$(DIST)
2023-10-12 14:18:25 +00:00
.PHONY: release
release: xgo checksum
2023-10-12 14:18:25 +00:00
.PHONY: deps
deps:
$(GO) mod download
$(GO) install $(GOFUMPT_PACKAGE)
$(GO) install $(GOLANGCI_LINT_PACKAGE)
$(GO) install $(XGO_PACKAGE)
$(GO) install $(GOTESTSUM_PACKAGE)