Make: extract "goversion.mk" to reuse it in bouncers (#2101)

This commit is contained in:
mmetc 2023-03-07 11:46:52 +01:00 committed by GitHub
parent 16a3be49e2
commit 0a748d324e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 54 additions and 61 deletions

View file

@ -1,24 +1,4 @@
ifeq ($(OS), Windows_NT)
SHELL := pwsh.exe
.SHELLFLAGS := -NoProfile -Command
CS_ROOT = $(shell (Get-Location).Path)
SYSTEM = windows
EXT = .exe
else
CS_ROOT ?= $(shell pwd)
SYSTEM ?= $(shell uname -s | tr '[A-Z]' '[a-z]')
endif
ifneq ("$(wildcard $(CURDIR)/platform/$(SYSTEM).mk)", "")
include $(CURDIR)/platform/$(SYSTEM).mk
else
include $(CURDIR)/platform/linux.mk
endif
ifneq ($(OS), Windows_NT)
include $(CS_ROOT)/platform/unix_common.mk
endif
include mk/platform.mk
CROWDSEC_FOLDER = ./cmd/crowdsec
CSCLI_FOLDER = ./cmd/crowdsec-cli/
@ -44,14 +24,6 @@ CROWDSEC_BIN = crowdsec$(EXT)
CSCLI_BIN = cscli$(EXT)
BUILD_CMD = build
MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
MINIMUM_SUPPORTED_GO_MINOR_VERSION = 20
go_major_minor = $(subst ., ,$(BUILD_GOVERSION))
GO_MAJOR_VERSION = $(word 1, $(go_major_minor))
GO_MINOR_VERSION = $(word 2, $(go_major_minor))
GO_VERSION_VALIDATION_ERR_MSG = Golang version ($(BUILD_GOVERSION)) is not supported, please use at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION)
GO_MODULE_NAME = github.com/crowdsecurity/crowdsec
LD_OPTS_VARS= \
@ -84,23 +56,6 @@ all: clean test build
.PHONY: plugins
plugins: http-plugin slack-plugin splunk-plugin email-plugin dummy-plugin
.PHONY: goversion
goversion:
ifneq ($(OS), Windows_NT)
@if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
exit 0 ;\
elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
exit 1; \
elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
exit 1; \
fi
else
# This needs Set-ExecutionPolicy -Scope CurrentUser Unrestricted
@$(CS_ROOT)/scripts/check_go_version.ps1 $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) $(MINIMUM_SUPPORTED_GO_MINOR_VERSION)
endif
.PHONY: clean
clean: testclean
@$(MAKE) -C $(CROWDSEC_FOLDER) clean --no-print-directory RM="$(RM)" WIN_IGNORE_ERR="$(WIN_IGNORE_ERR)" CP="$(CP)" CPR="$(CPR)" MKDIR="$(MKDIR)"
@ -223,3 +178,5 @@ bats-clean:
else
include test/bats.mk
endif
include mk/goversion.mk

28
mk/goversion.mk Normal file
View file

@ -0,0 +1,28 @@
BUILD_REQUIRE_GO_MAJOR ?= 1
BUILD_REQUIRE_GO_MINOR ?= 20
BUILD_GOVERSION = $(subst go,,$(shell go env GOVERSION))
go_major_minor = $(subst ., ,$(BUILD_GOVERSION))
GO_MAJOR_VERSION = $(word 1, $(go_major_minor))
GO_MINOR_VERSION = $(word 2, $(go_major_minor))
GO_VERSION_VALIDATION_ERR_MSG = Golang version ($(BUILD_GOVERSION)) is not supported, please use at least $(BUILD_REQUIRE_GO_MAJOR).$(BUILD_REQUIRE_GO_MINOR)
.PHONY: goversion
goversion:
ifneq ($(OS), Windows_NT)
@if [ $(GO_MAJOR_VERSION) -gt $(BUILD_REQUIRE_GO_MAJOR) ]; then \
exit 0; \
elif [ $(GO_MAJOR_VERSION) -lt $(BUILD_REQUIRE_GO_MAJOR) ]; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
exit 1; \
elif [ $(GO_MINOR_VERSION) -lt $(BUILD_REQUIRE_GO_MINOR) ] ; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
exit 1; \
fi
else
# This needs Set-ExecutionPolicy -Scope CurrentUser Unrestricted
@$(CURDIR)/mk/check_go_version.ps1 $(BUILD_REQUIRE_GO_MAJOR) $(BUILD_REQUIRE_GO_MINOR)
endif

15
mk/platform.mk Normal file
View file

@ -0,0 +1,15 @@
ifeq ($(OS), Windows_NT)
SHELL := pwsh.exe
.SHELLFLAGS := -NoProfile -Command
SYSTEM = windows
EXT = .exe
else
SYSTEM ?= $(shell uname -s | tr '[A-Z]' '[a-z]')
include mk/platform/unix_common.mk
endif
ifneq ("$(wildcard mk/platform/$(SYSTEM).mk)", "")
include mk/platform/$(SYSTEM).mk
else
include mk/platform/linux.mk
endif

5
mk/platform/freebsd.mk Normal file
View file

@ -0,0 +1,5 @@
# FreeBSD specific
MAKE=gmake
$(info building for FreeBSD)

View file

@ -1,6 +1,5 @@
# OpenBSD specific
#
Make=gmake
MAKE=gmake
$(info building for OpenBSD)

View file

@ -8,8 +8,6 @@ MKDIR=mkdir -p
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
BUILD_GOVERSION=$(shell go env GOVERSION | sed s/go//)
#Current versioning information from env
BUILD_VERSION?=$(shell git describe --tags)
BUILD_CODENAME="alphaga"

View file

@ -1,5 +1,4 @@
# Windows specific
#
MAKE=make
GOOS=windows
@ -12,7 +11,6 @@ GOARCH ?= $(shell go env GOARCH)
#BUILD_VERSION?=$(shell (Invoke-WebRequest -UseBasicParsing -Uri https://api.github.com/repos/crowdsecurity/crowdsec/releases/latest).Content | jq -r '.tag_name')
#hardcode it till i find a workaround
BUILD_VERSION?=$(shell git describe --tags $$(git rev-list --tags --max-count=1))
BUILD_GOVERSION?=$(shell (go env GOVERSION).replace("go",""))
BUILD_CODENAME?=alphaga
BUILD_TIMESTAMP?=$(shell Get-Date -Format "yyyy-MM-dd_HH:mm:ss")
BUILD_TAG?=$(shell git rev-parse HEAD)
@ -26,5 +24,4 @@ CPR=Copy-Item -Recurse
MKDIR=New-Item -ItemType directory
WIN_IGNORE_ERR=; exit 0
$(info Building for windows)

View file

@ -1,6 +0,0 @@
# FreeBSD specific
#
Make=gmake
$(info building for FreeBSD)