2021-03-26 16:42:56 +00:00
ROOT = $( shell git rev-parse --show-toplevel)
SYSTEM = $( shell uname -s | tr '[A-Z]' '[a-z]' )
i f n e q ( "$(wildcard $(ROOT)/platform/$(SYSTEM).mk)" , "" )
include $( ROOT) /platform/$( SYSTEM) .mk
e l s e
include $( ROOT) /platform/linux.mk
e n d i f
2020-05-15 09:39:16 +00:00
PREFIX ?= "/tmp/crowdsec/"
CFG_PREFIX = $( PREFIX) "/etc/crowdsec/"
BIN_PREFIX = $( PREFIX) "/usr/local/bin/"
DATA_PREFIX = $( PREFIX) "/var/run/crowdsec/"
PID_DIR = $( PREFIX) "/var/run/"
CROWDSEC_FOLDER = "./cmd/crowdsec"
CSCLI_FOLDER = "./cmd/crowdsec-cli/"
CROWDSEC_BIN = "crowdsec"
CSCLI_BIN = "cscli"
2021-01-14 12:04:42 +00:00
BUILD_CMD = "build"
2020-05-15 09:39:16 +00:00
GOARCH = amd64
2020-11-30 09:37:17 +00:00
#Golang version info
2020-10-29 09:07:03 +00:00
GO_MAJOR_VERSION = $( shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
GO_MINOR_VERSION = $( shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
MINIMUM_SUPPORTED_GO_MINOR_VERSION = 13
GO_VERSION_VALIDATION_ERR_MSG = Golang version ( $( BUILD_GOVERSION) ) is not supported, please use least $( MINIMUM_SUPPORTED_GO_MAJOR_VERSION) .$( MINIMUM_SUPPORTED_GO_MINOR_VERSION)
2020-11-30 09:37:17 +00:00
#Current versioning information from env
2020-09-01 12:32:45 +00:00
BUILD_VERSION ?= " $( shell git describe --tags ` git rev-list --tags --max-count= 1` ) "
2020-06-10 12:24:02 +00:00
BUILD_GOVERSION = " $( shell go version | cut -d " " -f3 | sed -r 's/[go]+//g' ) "
BUILD_CODENAME = $( shell cat RELEASE.json | jq -r .CodeName)
BUILD_TIMESTAMP = $( shell date +%F"_" %T)
BUILD_TAG = " $( shell git rev-parse HEAD) "
2020-07-29 15:36:59 +00:00
export LD_OPTS = -ldflags " -s -w -X github.com/crowdsecurity/crowdsec/pkg/cwversion.Version= $( BUILD_VERSION) \
2020-05-15 09:39:16 +00:00
- X g i t h u b . c o m / c r o w d s e c u r i t y / c r o w d s e c / p k g / cwversion.BuildDate = $( BUILD_TIMESTAMP) \
- X g i t h u b . c o m / c r o w d s e c u r i t y / c r o w d s e c / p k g / cwversion.Codename = $( BUILD_CODENAME) \
- X g i t h u b . c o m / c r o w d s e c u r i t y / c r o w d s e c / p k g / cwversion.Tag = $( BUILD_TAG) \
- X g i t h u b . c o m / c r o w d s e c u r i t y / c r o w d s e c / p k g / cwversion.GoVersion = $( BUILD_GOVERSION) "
RELDIR = crowdsec-$( BUILD_VERSION)
all : clean test build
2020-11-30 09:37:17 +00:00
build : goversion crowdsec cscli
2020-05-15 09:39:16 +00:00
static : goversion crowdsec_static cscli_static
goversion :
2020-10-29 09:07:03 +00:00
@if [ $( GO_MAJOR_VERSION) -gt $( MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ] ; then \
2020-11-30 09:37:17 +00:00
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
2020-06-11 13:03:43 +00:00
2020-05-15 09:39:16 +00:00
clean :
2021-01-14 12:04:42 +00:00
@$( MAKE) -C $( CROWDSEC_FOLDER) clean --no-print-directory
@$( MAKE) -C $( CSCLI_FOLDER) clean --no-print-directory
2020-05-15 09:39:16 +00:00
@rm -f $( CROWDSEC_BIN)
@rm -f $( CSCLI_BIN)
@rm -f *.log
2020-12-14 16:48:32 +00:00
@rm -f crowdsec-release.tgz
2020-05-15 09:39:16 +00:00
2020-11-30 09:37:17 +00:00
cscli :
i f e q ( $( lastword $ ( RESPECT_VERSION ) ) , $( CURRENT_GOVERSION ) )
2021-01-14 12:04:42 +00:00
@$( MAKE) -C $( CSCLI_FOLDER) build --no-print-directory
2020-11-30 09:37:17 +00:00
e l s e
@echo " Required golang version is $( REQUIRE_GOVERSION) . The current one is $( CURRENT_GOVERSION) . Exiting.. "
@exit 1;
e n d i f
2020-05-15 09:39:16 +00:00
2020-11-30 09:37:17 +00:00
crowdsec :
i f e q ( $( lastword $ ( RESPECT_VERSION ) ) , $( CURRENT_GOVERSION ) )
2021-01-14 12:04:42 +00:00
@$( MAKE) -C $( CROWDSEC_FOLDER) build --no-print-directory
2020-11-30 09:37:17 +00:00
e l s e
@echo " Required golang version is $( REQUIRE_GOVERSION) . The current one is $( CURRENT_GOVERSION) . Exiting.. "
@exit 1;
e n d i f
2020-05-15 09:39:16 +00:00
2020-11-30 09:37:17 +00:00
cscli_static :
i f e q ( $( lastword $ ( RESPECT_VERSION ) ) , $( CURRENT_GOVERSION ) )
2021-01-14 12:04:42 +00:00
@$( MAKE) -C $( CSCLI_FOLDER) static --no-print-directory
2020-11-30 09:37:17 +00:00
e l s e
@echo " Required golang version is $( REQUIRE_GOVERSION) . The current one is $( CURRENT_GOVERSION) . Exiting.. "
@exit 1;
e n d i f
2020-05-15 09:39:16 +00:00
2020-11-30 09:37:17 +00:00
crowdsec_static :
i f e q ( $( lastword $ ( RESPECT_VERSION ) ) , $( CURRENT_GOVERSION ) )
2021-01-14 12:04:42 +00:00
@$( MAKE) -C $( CROWDSEC_FOLDER) static --no-print-directory
2020-11-30 09:37:17 +00:00
e l s e
@echo " Required golang version is $( REQUIRE_GOVERSION) . The current one is $( CURRENT_GOVERSION) . Exiting.. "
@exit 1;
e n d i f
2020-05-15 09:39:16 +00:00
#.PHONY: test
test :
2020-11-30 09:37:17 +00:00
i f e q ( $( lastword $ ( RESPECT_VERSION ) ) , $( CURRENT_GOVERSION ) )
2021-01-14 12:04:42 +00:00
@$( MAKE) -C $( CROWDSEC_FOLDER) test --no-print-directory
2020-11-30 09:37:17 +00:00
e l s e
@echo " Required golang version is $( REQUIRE_GOVERSION) . The current one is $( CURRENT_GOVERSION) . Exiting.. "
@exit 1;
e n d i f
2020-05-15 09:39:16 +00:00
.PHONY : check_release
check_release :
@if [ -d $( RELDIR) ] ; then echo " $( RELDIR) already exists, abort " ; exit 1 ; fi
.PHONY :
release : check_release build
@echo Building Release to dir $( RELDIR)
@mkdir -p $( RELDIR) /cmd/crowdsec
@mkdir -p $( RELDIR) /cmd/crowdsec-cli
@cp $( CROWDSEC_FOLDER) /$( CROWDSEC_BIN) $( RELDIR) /cmd/crowdsec
@cp $( CSCLI_FOLDER) /$( CSCLI_BIN) $( RELDIR) /cmd/crowdsec-cli
@cp -R ./config/ $( RELDIR)
@cp wizard.sh $( RELDIR)
@cp scripts/test_env.sh $( RELDIR)
@tar cvzf crowdsec-release.tgz $( RELDIR)
2021-04-07 08:14:39 +00:00
.PHONY :
release_static : check_release static
@echo Building Release to dir $( RELDIR)
@mkdir -p $( RELDIR) /cmd/crowdsec
@mkdir -p $( RELDIR) /cmd/crowdsec-cli
@cp $( CROWDSEC_FOLDER) /$( CROWDSEC_BIN) $( RELDIR) /cmd/crowdsec
@cp $( CSCLI_FOLDER) /$( CSCLI_BIN) $( RELDIR) /cmd/crowdsec-cli
@cp -R ./config/ $( RELDIR)
@cp wizard.sh $( RELDIR)
@cp scripts/test_env.sh $( RELDIR)
@tar cvzf crowdsec-release-static.tgz $( RELDIR)