2021-05-05 06:54:33 +00:00
ROOT = $( shell pwd )
2021-04-23 13:23:46 +00:00
SYSTEM ?= $( shell uname -s | tr '[A-Z]' '[a-z]' )
2021-03-26 16:42:56 +00:00
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
CROWDSEC_FOLDER = "./cmd/crowdsec"
CSCLI_FOLDER = "./cmd/crowdsec-cli/"
2022-01-06 10:20:59 +00:00
2021-08-25 09:43:29 +00:00
HTTP_PLUGIN_FOLDER = "./plugins/notifications/http"
SLACK_PLUGIN_FOLDER = "./plugins/notifications/slack"
SPLUNK_PLUGIN_FOLDER = "./plugins/notifications/splunk"
2022-01-06 10:20:59 +00:00
EMAIL_PLUGIN_FOLDER = "./plugins/notifications/email"
2021-08-25 09:43:29 +00:00
HTTP_PLUGIN_BIN = "notification-http"
SLACK_PLUGIN_BIN = "notification-slack"
SPLUNK_PLUGIN_BIN = "notification-splunk"
2022-01-06 10:20:59 +00:00
EMAIL_PLUGIN_BIN = "notification-email"
2021-08-25 09:43:29 +00:00
HTTP_PLUGIN_CONFIG = "http.yaml"
SLACK_PLUGIN_CONFIG = "slack.yaml"
SPLUNK_PLUGIN_CONFIG = "splunk.yaml"
2022-01-06 10:20:59 +00:00
EMAIL_PLUGIN_CONFIG = "email.yaml"
2020-05-15 09:39:16 +00:00
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
2021-09-14 13:42:34 +00:00
GOOS ?= $( shell go env GOOS)
2021-08-25 13:06:27 +00:00
GOARCH ?= $( shell go env GOARCH)
2020-05-15 09:39:16 +00:00
2022-02-04 12:02:45 +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
2021-12-16 13:39:58 +00:00
MINIMUM_SUPPORTED_GO_MINOR_VERSION = 17
2022-02-15 10:09:58 +00:00
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)
2022-02-04 12:02:45 +00:00
# Current versioning information from env
2022-02-15 10:09:58 +00:00
BUILD_VERSION ?= " $( shell git describe --tags) "
2022-02-04 12:02:45 +00:00
BUILD_GOVERSION = " $( shell go version | cut -d " " -f3 | sed -E '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) "
2022-02-01 16:16:17 +00:00
DEFAULT_CONFIGDIR ?= "/etc/crowdsec"
DEFAULT_DATADIR ?= "/var/lib/crowdsec/data"
2021-04-26 12:45:52 +00:00
2022-02-04 12:02:45 +00:00
LD_OPTS_VARS = \
- 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.Version = $( BUILD_VERSION) \
2021-04-23 13:23:46 +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.System = $( SYSTEM) \
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) \
2022-02-01 09:34:53 +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.GoVersion = $( BUILD_GOVERSION) \
2022-02-01 16:16:17 +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 / csconfig.defaultConfigDir = $( DEFAULT_CONFIGDIR) \
2022-02-04 12:02:45 +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 / csconfig.defaultDataDir = $( DEFAULT_DATADIR)
2021-04-26 12:45:52 +00:00
2022-02-04 12:02:45 +00:00
export LD_OPTS = -ldflags " -s -w $( LD_OPTS_VARS) "
export LD_OPTS_STATIC = -ldflags " -s -w $( LD_OPTS_VARS) -extldflags '-static' "
2021-04-26 12:45:52 +00:00
2022-02-14 21:21:19 +00:00
GOCMD = go
GOTEST = $( GOCMD) test
2020-05-15 09:39:16 +00:00
RELDIR = crowdsec-$( BUILD_VERSION)
2022-02-01 08:22:47 +00:00
.PHONY : build
2021-08-25 09:43:29 +00:00
build : goversion crowdsec cscli plugins
2020-05-15 09:39:16 +00:00
2022-02-18 17:09:19 +00:00
.PHONY : all
all : clean test build
2022-02-01 08:22:47 +00:00
.PHONY : static
2021-08-25 09:43:29 +00:00
static : crowdsec_static cscli_static plugins_static
2022-02-01 08:22:47 +00:00
.PHONY : plugins
2022-01-06 10:20:59 +00:00
plugins : http -plugin slack -plugin splunk -plugin email -plugin
2021-08-25 09:43:29 +00:00
2022-01-06 10:20:59 +00:00
plugins_static : http -plugin_static slack -plugin_static splunk -plugin_static email -plugin_static
2020-05-15 09:39:16 +00:00
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
2022-02-01 08:22:47 +00:00
.PHONY : clean
2022-02-14 21:21:19 +00:00
clean : testclean
2021-01-14 12:04:42 +00:00
@$( MAKE) -C $( CROWDSEC_FOLDER) clean --no-print-directory
@$( MAKE) -C $( CSCLI_FOLDER) clean --no-print-directory
2022-02-01 08:22:47 +00:00
@$( RM) $( CROWDSEC_BIN)
@$( RM) $( CSCLI_BIN)
@$( RM) *.log
@$( RM) crowdsec-release.tgz
@$( RM) $( HTTP_PLUGIN_FOLDER) /$( HTTP_PLUGIN_BIN)
@$( RM) $( SLACK_PLUGIN_FOLDER) /$( SLACK_PLUGIN_BIN)
@$( RM) $( SPLUNK_PLUGIN_FOLDER) /$( SPLUNK_PLUGIN_BIN)
@$( RM) $( EMAIL_PLUGIN_FOLDER) /$( EMAIL_PLUGIN_BIN)
2020-05-15 09:39:16 +00:00
2022-02-14 21:21:19 +00:00
2021-08-25 09:43:29 +00:00
cscli : goversion
2021-07-23 09:02:16 +00:00
@GOARCH= $( GOARCH) GOOS = $( GOOS) $( MAKE) -C $( CSCLI_FOLDER) build --no-print-directory
2020-05-15 09:39:16 +00:00
2021-08-25 09:43:29 +00:00
crowdsec : goversion
2021-07-23 09:02:16 +00:00
@GOARCH= $( GOARCH) GOOS = $( GOOS) $( MAKE) -C $( CROWDSEC_FOLDER) build --no-print-directory
2020-05-15 09:39:16 +00:00
2021-08-25 09:43:29 +00:00
http-plugin : goversion
@GOARCH= $( GOARCH) GOOS = $( GOOS) $( MAKE) -C $( HTTP_PLUGIN_FOLDER) build --no-print-directory
2020-05-15 09:39:16 +00:00
2021-08-25 09:43:29 +00:00
slack-plugin : goversion
@GOARCH= $( GOARCH) GOOS = $( GOOS) $( MAKE) -C $( SLACK_PLUGIN_FOLDER) build --no-print-directory
2020-05-15 09:39:16 +00:00
2021-08-25 09:43:29 +00:00
splunk-plugin : goversion
@GOARCH= $( GOARCH) GOOS = $( GOOS) $( MAKE) -C $( SPLUNK_PLUGIN_FOLDER) build --no-print-directory
2020-05-15 09:39:16 +00:00
2022-01-06 10:20:59 +00:00
email-plugin : goversion
@GOARCH= $( GOARCH) GOOS = $( GOOS) $( MAKE) -C $( EMAIL_PLUGIN_FOLDER) build --no-print-directory
2021-08-25 09:43:29 +00:00
cscli_static : goversion
@GOARCH= $( GOARCH) GOOS = $( GOOS) $( MAKE) -C $( CSCLI_FOLDER) static --no-print-directory
crowdsec_static : goversion
2021-07-23 09:02:16 +00:00
@GOARCH= $( GOARCH) GOOS = $( GOOS) $( MAKE) -C $( CROWDSEC_FOLDER) static --no-print-directory
2020-11-30 09:37:17 +00:00
2021-08-25 09:43:29 +00:00
http-plugin_static : goversion
@GOARCH= $( GOARCH) GOOS = $( GOOS) $( MAKE) -C $( HTTP_PLUGIN_FOLDER) static --no-print-directory
2020-05-15 09:39:16 +00:00
2021-08-25 09:43:29 +00:00
slack-plugin_static : goversion
@GOARCH= $( GOARCH) GOOS = $( GOOS) $( MAKE) -C $( SLACK_PLUGIN_FOLDER) static --no-print-directory
2020-05-15 09:39:16 +00:00
2021-08-25 09:43:29 +00:00
splunk-plugin_static : goversion
@GOARCH= $( GOARCH) GOOS = $( GOOS) $( MAKE) -C $( SPLUNK_PLUGIN_FOLDER) static --no-print-directory
2022-01-06 10:20:59 +00:00
email-plugin_static : goversion
@GOARCH= $( GOARCH) GOOS = $( GOOS) $( MAKE) -C $( EMAIL_PLUGIN_FOLDER) static --no-print-directory
2022-02-14 21:21:19 +00:00
.PHONY : testclean
testclean :
@$( RM) pkg/apiserver/ent
@$( RM) -r pkg/cwhub/hubdir
.PHONY : test
2021-08-25 09:43:29 +00:00
test : goversion
2022-02-14 21:21:19 +00:00
$( GOTEST) $( LD_OPTS) ./...
2021-08-25 09:43:29 +00:00
2022-02-01 08:22:47 +00:00
.PHONY : package
2021-08-25 09:43:29 +00:00
package :
2020-05-15 09:39:16 +00:00
@echo Building Release to dir $( RELDIR)
@mkdir -p $( RELDIR) /cmd/crowdsec
@mkdir -p $( RELDIR) /cmd/crowdsec-cli
2021-08-25 09:43:29 +00:00
@mkdir -p $( RELDIR) /$( subst ./,,$( HTTP_PLUGIN_FOLDER) )
@mkdir -p $( RELDIR) /$( subst ./,,$( SLACK_PLUGIN_FOLDER) )
@mkdir -p $( RELDIR) /$( subst ./,,$( SPLUNK_PLUGIN_FOLDER) )
2022-01-06 10:20:59 +00:00
@mkdir -p $( RELDIR) /$( subst ./,,$( EMAIL_PLUGIN_FOLDER) )
2021-08-25 09:43:29 +00:00
2020-05-15 09:39:16 +00:00
@cp $( CROWDSEC_FOLDER) /$( CROWDSEC_BIN) $( RELDIR) /cmd/crowdsec
@cp $( CSCLI_FOLDER) /$( CSCLI_BIN) $( RELDIR) /cmd/crowdsec-cli
2022-01-06 10:20:59 +00:00
2021-08-25 09:43:29 +00:00
@cp $( HTTP_PLUGIN_FOLDER) /$( HTTP_PLUGIN_BIN) $( RELDIR) /$( subst ./,,$( HTTP_PLUGIN_FOLDER) )
@cp $( SLACK_PLUGIN_FOLDER) /$( SLACK_PLUGIN_BIN) $( RELDIR) /$( subst ./,,$( SLACK_PLUGIN_FOLDER) )
@cp $( SPLUNK_PLUGIN_FOLDER) /$( SPLUNK_PLUGIN_BIN) $( RELDIR) /$( subst ./,,$( SPLUNK_PLUGIN_FOLDER) )
2022-01-06 10:20:59 +00:00
@cp $( EMAIL_PLUGIN_FOLDER) /$( EMAIL_PLUGIN_BIN) $( RELDIR) /$( subst ./,,$( EMAIL_PLUGIN_FOLDER) )
2021-08-25 09:43:29 +00:00
@cp $( HTTP_PLUGIN_FOLDER) /$( HTTP_PLUGIN_CONFIG) $( RELDIR) /$( subst ./,,$( HTTP_PLUGIN_FOLDER) )
@cp $( SLACK_PLUGIN_FOLDER) /$( SLACK_PLUGIN_CONFIG) $( RELDIR) /$( subst ./,,$( SLACK_PLUGIN_FOLDER) )
@cp $( SPLUNK_PLUGIN_FOLDER) /$( SPLUNK_PLUGIN_CONFIG) $( RELDIR) /$( subst ./,,$( SPLUNK_PLUGIN_FOLDER) )
2022-01-06 10:20:59 +00:00
@cp $( EMAIL_PLUGIN_FOLDER) /$( EMAIL_PLUGIN_CONFIG) $( RELDIR) /$( subst ./,,$( EMAIL_PLUGIN_FOLDER) )
2020-05-15 09:39:16 +00:00
@cp -R ./config/ $( RELDIR)
@cp wizard.sh $( RELDIR)
@cp scripts/test_env.sh $( RELDIR)
2021-09-14 13:32:35 +00:00
@tar cvzf crowdsec-release.tgz $( RELDIR)
package_static :
@echo Building Release to dir $( RELDIR)
@mkdir -p $( RELDIR) /cmd/crowdsec
@mkdir -p $( RELDIR) /cmd/crowdsec-cli
@mkdir -p $( RELDIR) /$( subst ./,,$( HTTP_PLUGIN_FOLDER) )
@mkdir -p $( RELDIR) /$( subst ./,,$( SLACK_PLUGIN_FOLDER) )
@mkdir -p $( RELDIR) /$( subst ./,,$( SPLUNK_PLUGIN_FOLDER) )
2022-01-06 10:20:59 +00:00
@mkdir -p $( RELDIR) /$( subst ./,,$( EMAIL_PLUGIN_FOLDER) )
2021-09-14 13:32:35 +00:00
@cp $( CROWDSEC_FOLDER) /$( CROWDSEC_BIN) $( RELDIR) /cmd/crowdsec
@cp $( CSCLI_FOLDER) /$( CSCLI_BIN) $( RELDIR) /cmd/crowdsec-cli
2022-01-06 10:20:59 +00:00
2021-09-14 13:32:35 +00:00
@cp $( HTTP_PLUGIN_FOLDER) /$( HTTP_PLUGIN_BIN) $( RELDIR) /$( subst ./,,$( HTTP_PLUGIN_FOLDER) )
@cp $( SLACK_PLUGIN_FOLDER) /$( SLACK_PLUGIN_BIN) $( RELDIR) /$( subst ./,,$( SLACK_PLUGIN_FOLDER) )
@cp $( SPLUNK_PLUGIN_FOLDER) /$( SPLUNK_PLUGIN_BIN) $( RELDIR) /$( subst ./,,$( SPLUNK_PLUGIN_FOLDER) )
2022-01-06 10:20:59 +00:00
@cp $( EMAIL_PLUGIN_FOLDER) /$( EMAIL_PLUGIN_BIN) $( RELDIR) /$( subst ./,,$( EMAIL_PLUGIN_FOLDER) )
2021-09-14 13:32:35 +00:00
@cp $( HTTP_PLUGIN_FOLDER) /$( HTTP_PLUGIN_CONFIG) $( RELDIR) /$( subst ./,,$( HTTP_PLUGIN_FOLDER) )
@cp $( SLACK_PLUGIN_FOLDER) /$( SLACK_PLUGIN_CONFIG) $( RELDIR) /$( subst ./,,$( SLACK_PLUGIN_FOLDER) )
@cp $( SPLUNK_PLUGIN_FOLDER) /$( SPLUNK_PLUGIN_CONFIG) $( RELDIR) /$( subst ./,,$( SPLUNK_PLUGIN_FOLDER) )
2022-01-06 10:20:59 +00:00
@cp $( EMAIL_PLUGIN_FOLDER) /$( EMAIL_PLUGIN_CONFIG) $( RELDIR) /$( subst ./,,$( EMAIL_PLUGIN_FOLDER) )
2021-09-14 13:32:35 +00:00
@cp -R ./config/ $( RELDIR)
@cp wizard.sh $( RELDIR)
@cp scripts/test_env.sh $( RELDIR)
@tar cvzf crowdsec-release-static.tgz $( RELDIR)
2021-04-07 08:14:39 +00:00
2021-08-25 09:43:29 +00:00
.PHONY : check_release
check_release :
@if [ -d $( RELDIR) ] ; then echo " $( RELDIR) already exists, abort " ; exit 1 ; fi
2022-02-01 08:22:47 +00:00
.PHONY : release
2021-08-25 09:43:29 +00:00
release : check_release build package
2022-02-01 08:22:47 +00:00
.PHONY : release_static
release_static : check_release static package_static