Make: extract "goversion.mk" to reuse it in bouncers (#2101)
This commit is contained in:
parent
16a3be49e2
commit
0a748d324e
10 changed files with 54 additions and 61 deletions
49
Makefile
49
Makefile
|
@ -1,24 +1,4 @@
|
||||||
|
include mk/platform.mk
|
||||||
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
|
|
||||||
|
|
||||||
CROWDSEC_FOLDER = ./cmd/crowdsec
|
CROWDSEC_FOLDER = ./cmd/crowdsec
|
||||||
CSCLI_FOLDER = ./cmd/crowdsec-cli/
|
CSCLI_FOLDER = ./cmd/crowdsec-cli/
|
||||||
|
@ -44,14 +24,6 @@ CROWDSEC_BIN = crowdsec$(EXT)
|
||||||
CSCLI_BIN = cscli$(EXT)
|
CSCLI_BIN = cscli$(EXT)
|
||||||
BUILD_CMD = build
|
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
|
GO_MODULE_NAME = github.com/crowdsecurity/crowdsec
|
||||||
|
|
||||||
LD_OPTS_VARS= \
|
LD_OPTS_VARS= \
|
||||||
|
@ -84,23 +56,6 @@ all: clean test build
|
||||||
.PHONY: plugins
|
.PHONY: plugins
|
||||||
plugins: http-plugin slack-plugin splunk-plugin email-plugin dummy-plugin
|
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
|
.PHONY: clean
|
||||||
clean: testclean
|
clean: testclean
|
||||||
@$(MAKE) -C $(CROWDSEC_FOLDER) clean --no-print-directory RM="$(RM)" WIN_IGNORE_ERR="$(WIN_IGNORE_ERR)" CP="$(CP)" CPR="$(CPR)" MKDIR="$(MKDIR)"
|
@$(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
|
else
|
||||||
include test/bats.mk
|
include test/bats.mk
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
include mk/goversion.mk
|
||||||
|
|
|
@ -15,5 +15,5 @@ elseif ($goversion_major -lt $min_major) {
|
||||||
}
|
}
|
||||||
elseif ($goversion_minor -lt $min_minor) {
|
elseif ($goversion_minor -lt $min_minor) {
|
||||||
Write-Output $(GO_VERSION_VALIDATION_ERR_MSG);
|
Write-Output $(GO_VERSION_VALIDATION_ERR_MSG);
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
28
mk/goversion.mk
Normal file
28
mk/goversion.mk
Normal 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
15
mk/platform.mk
Normal 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
5
mk/platform/freebsd.mk
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# FreeBSD specific
|
||||||
|
|
||||||
|
MAKE=gmake
|
||||||
|
|
||||||
|
$(info building for FreeBSD)
|
|
@ -1,6 +1,5 @@
|
||||||
# OpenBSD specific
|
# OpenBSD specific
|
||||||
#
|
|
||||||
|
|
||||||
Make=gmake
|
MAKE=gmake
|
||||||
|
|
||||||
$(info building for OpenBSD)
|
$(info building for OpenBSD)
|
|
@ -8,8 +8,6 @@ MKDIR=mkdir -p
|
||||||
GOOS ?= $(shell go env GOOS)
|
GOOS ?= $(shell go env GOOS)
|
||||||
GOARCH ?= $(shell go env GOARCH)
|
GOARCH ?= $(shell go env GOARCH)
|
||||||
|
|
||||||
BUILD_GOVERSION=$(shell go env GOVERSION | sed s/go//)
|
|
||||||
|
|
||||||
#Current versioning information from env
|
#Current versioning information from env
|
||||||
BUILD_VERSION?=$(shell git describe --tags)
|
BUILD_VERSION?=$(shell git describe --tags)
|
||||||
BUILD_CODENAME="alphaga"
|
BUILD_CODENAME="alphaga"
|
|
@ -1,5 +1,4 @@
|
||||||
# Windows specific
|
# Windows specific
|
||||||
#
|
|
||||||
|
|
||||||
MAKE=make
|
MAKE=make
|
||||||
GOOS=windows
|
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')
|
#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
|
#hardcode it till i find a workaround
|
||||||
BUILD_VERSION?=$(shell git describe --tags $$(git rev-list --tags --max-count=1))
|
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_CODENAME?=alphaga
|
||||||
BUILD_TIMESTAMP?=$(shell Get-Date -Format "yyyy-MM-dd_HH:mm:ss")
|
BUILD_TIMESTAMP?=$(shell Get-Date -Format "yyyy-MM-dd_HH:mm:ss")
|
||||||
BUILD_TAG?=$(shell git rev-parse HEAD)
|
BUILD_TAG?=$(shell git rev-parse HEAD)
|
||||||
|
@ -26,5 +24,4 @@ CPR=Copy-Item -Recurse
|
||||||
MKDIR=New-Item -ItemType directory
|
MKDIR=New-Item -ItemType directory
|
||||||
WIN_IGNORE_ERR=; exit 0
|
WIN_IGNORE_ERR=; exit 0
|
||||||
|
|
||||||
|
|
||||||
$(info Building for windows)
|
$(info Building for windows)
|
|
@ -1,6 +0,0 @@
|
||||||
# FreeBSD specific
|
|
||||||
#
|
|
||||||
|
|
||||||
Make=gmake
|
|
||||||
|
|
||||||
$(info building for FreeBSD)
|
|
Loading…
Reference in a new issue