1
0
woodpecker-yc-autoscaler/Makefile
2024-07-30 00:54:43 +03:00

83 lines
2.0 KiB
Makefile

#!/usr/bin/make -f
# SPDX-License-Identifier: Apache-2.0
# (c) 2024, Konstantin Demin
SHELL :=/bin/sh
.SHELLFLAGS :=-ec
.NOTPARALLEL:
OUTDIR ?= .
OUTSFX ?=
export GO ?= go
## "purego" - pure go implementation of https://github.com/cespare/xxhash
## "noasm" - pure go implementation of https://github.com/klauspost/compress
TAGS ?= purego,noasm
GO_BUILDFLAGS ?= -trimpath -buildmode=pie
LDFLAGS ?=
PKG := $(shell awk '/^module /{print $$2;exit}' go.mod)
CMD := $(notdir $(wildcard ./cmd/*))
export CGO_ENABLED := 0
empty :=
space :=$(empty) $(empty)
comma :=,
OUTDIR :=$(strip $(OUTDIR))
OUTSFX :=$(strip $(OUTSFX))
OUTBIN :=$(foreach b,$(strip $(CMD)),$(OUTDIR)/$(b)$(OUTSFX))
TAGS :=$(subst $(space),$(comma),$(strip $(TAGS)))
GO_LDFLAGS :=$(strip -w $(LDFLAGS))
ifeq ($(RELMODE),1)
## "grpcnotrace" - disable grpc tracing: https://github.com/grpc/grpc-go/releases/tag/v1.62.0
TAGS := $(if $(TAGS),$(TAGS)$(comma))grpcnotrace
GO_LDFLAGS += -s
endif
.PHONY: all
all: build
.PHONY: clean build dev-build ci-clean
clean:
$(if $(wildcard $(OUTBIN)),rm -fv $(OUTBIN),:)
build: $(OUTBIN)
test_git = git -c log.showsignature=false show -s --format=%H:%ct
$(OUTDIR)/%$(OUTSFX):
@:; \
GO_BUILDFLAGS='$(strip $(GO_BUILDFLAGS))' ; \
if ! $(test_git) >/dev/null 2>&1 ; then \
echo "!!! git information is asbent !!!" >&2 ; \
GO_BUILDFLAGS="-buildvcs=false $${GO_BUILDFLAGS}" ; \
fi ; \
for i in $$(seq 1 3) ; do \
if $(GO) get ; then break ; fi ; \
done ; \
$(GO) build -o $@ \
$${GO_BUILDFLAGS} \
$(if $(strip $(TAGS)),-tags '$(strip $(TAGS))') \
$(if $(strip $(GO_LDFLAGS)),-ldflags '$(strip $(GO_LDFLAGS))') \
$(if $(VERBOSE),-v) \
$(PKG)/cmd/$* ; \
$(GO) version -m $@
dev-build: GO_BUILDFLAGS := -race $(GO_BUILDFLAGS)
dev-build: CGO_ENABLED := 1
dev-build: RELMODE := 0
dev-build: build
ci-clean:
for d in '$(shell $(GO) env GOCACHE)' '$(shell $(GO) env GOMODCACHE)' ; do \
[ -n "$$d" ] || continue ; \
[ -d "$$d" ] || continue ; \
rm -rf "$$d" ; \
done