2022-05-17 10:14:59 +00:00
i f e q ( $( OS ) , W i n d o w s _ N T )
SHELL := pwsh.exe
.SHELLFLAGS := -NoProfile -Command
ROOT = $( shell ( Get-Location) .Path)
SYSTEM = windows
EXT = .exe
e l s e
ROOT ?= $( shell pwd )
2021-04-23 13:23:46 +00:00
SYSTEM ?= $( shell uname -s | tr '[A-Z]' '[a-z]' )
2022-05-17 10:14:59 +00:00
e n d i f
2021-03-26 16:42:56 +00:00
2022-03-15 10:19:35 +00:00
i f n e q ( "$(wildcard $(CURDIR)/platform/$(SYSTEM).mk)" , "" )
include $( CURDIR) /platform/$( SYSTEM) .mk
2021-03-26 16:42:56 +00:00
e l s e
2022-03-15 10:19:35 +00:00
include $( CURDIR) /platform/linux.mk
2021-03-26 16:42:56 +00:00
e n d i f
2022-05-17 10:14:59 +00:00
i f n e q ( $( OS ) , W i n d o w s _ N T )
include $( ROOT) /platform/unix_common.mk
e n d i f
2022-01-06 10:20:59 +00:00
2022-05-17 10:14:59 +00:00
CROWDSEC_FOLDER = ./cmd/crowdsec
CSCLI_FOLDER = ./cmd/crowdsec-cli/
2022-01-06 10:20:59 +00:00
2022-05-17 10:14:59 +00:00
HTTP_PLUGIN_FOLDER = ./plugins/notifications/http
SLACK_PLUGIN_FOLDER = ./plugins/notifications/slack
SPLUNK_PLUGIN_FOLDER = ./plugins/notifications/splunk
EMAIL_PLUGIN_FOLDER = ./plugins/notifications/email
DUMMY_PLUGIN_FOLDER = ./plugins/notifications/dummy
2022-01-06 10:20:59 +00:00
2022-05-17 10:14:59 +00:00
HTTP_PLUGIN_BIN = notification-http$( EXT)
SLACK_PLUGIN_BIN = notification-slack$( EXT)
SPLUNK_PLUGIN_BIN = notification-splunk$( EXT)
EMAIL_PLUGIN_BIN = notification-email$( EXT)
DUMMY_PLUGIN_BIN = notification-dummy$( EXT)
2022-01-06 10:20:59 +00:00
2022-05-17 10:14:59 +00:00
HTTP_PLUGIN_CONFIG = http.yaml
SLACK_PLUGIN_CONFIG = slack.yaml
SPLUNK_PLUGIN_CONFIG = splunk.yaml
EMAIL_PLUGIN_CONFIG = email.yaml
CROWDSEC_BIN = crowdsec$( EXT)
CSCLI_BIN = cscli$( EXT)
BUILD_CMD = build
2020-05-15 09:39:16 +00:00
2020-10-29 09:07:03 +00:00
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
LD_OPTS_VARS = \
2022-05-31 08:01:30 +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 / c m d / crowdsec.bincoverTesting = $( BINCOVER_TESTING) \
- 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 / c m d / crowdsec-cli.bincoverTesting = $( BINCOVER_TESTING) \
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 / 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) \
2022-03-14 10:29:34 +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.Codename = $( BUILD_CODENAME) \
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.Tag = $( BUILD_TAG) \
2022-05-17 10:14:59 +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) \
- X 'github.com/crowdsecurity/crowdsec/pkg/csconfig.defaultConfigDir=$(DEFAULT_CONFIGDIR)' \
- X 'github.com/crowdsecurity/crowdsec/pkg/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-03-16 08:30:04 +00:00
plugins : http -plugin slack -plugin splunk -plugin email -plugin dummy -plugin
2021-08-25 09:43:29 +00:00
2022-03-16 08:30:04 +00:00
plugins_static : http -plugin_static slack -plugin_static splunk -plugin_static email -plugin_static dummy -plugin_static
2020-05-15 09:39:16 +00:00
goversion :
2022-05-17 10:14:59 +00:00
i f n e q ( $( OS ) , W i n d o w s _ N T )
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
2022-05-17 10:14:59 +00:00
e l s e
#This needs Set-ExecutionPolicy -Scope CurrentUser Unrestricted
@$( ROOT) /scripts/check_go_version.ps1 $( MINIMUM_SUPPORTED_GO_MAJOR_VERSION) $( MINIMUM_SUPPORTED_GO_MINOR_VERSION)
e n d i f
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
2022-05-17 10:14:59 +00:00
@$( MAKE) -C $( CROWDSEC_FOLDER) clean --no-print-directory RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
@$( MAKE) -C $( CSCLI_FOLDER) clean --no-print-directory RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
@$( RM) $( CROWDSEC_BIN) $( WIN_IGNORE_ERR)
@$( RM) $( CSCLI_BIN) $( WIN_IGNORE_ERR)
@$( RM) *.log $( WIN_IGNORE_ERR)
@$( RM) crowdsec-release.tgz $( WIN_IGNORE_ERR)
@$( RM) crowdsec-release-static.tgz $( WIN_IGNORE_ERR)
@$( RM) $( HTTP_PLUGIN_FOLDER) /$( HTTP_PLUGIN_BIN) $( WIN_IGNORE_ERR)
@$( RM) $( SLACK_PLUGIN_FOLDER) /$( SLACK_PLUGIN_BIN) $( WIN_IGNORE_ERR)
@$( RM) $( SPLUNK_PLUGIN_FOLDER) /$( SPLUNK_PLUGIN_BIN) $( WIN_IGNORE_ERR)
@$( RM) $( EMAIL_PLUGIN_FOLDER) /$( EMAIL_PLUGIN_BIN) $( WIN_IGNORE_ERR)
@$( RM) $( DUMMY_PLUGIN_FOLDER) /$( DUMMY_PLUGIN_BIN) $( WIN_IGNORE_ERR)
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
2022-05-17 10:14:59 +00:00
@$( MAKE) -C $( CSCLI_FOLDER) build --no-print-directory GOARCH = $( GOARCH) GOOS = $( GOOS) RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
2020-05-15 09:39:16 +00:00
2022-04-01 09:17:45 +00:00
cscli-bincover : goversion
@GOARCH= $( GOARCH) GOOS = $( GOOS) $( MAKE) -C $( CSCLI_FOLDER) build-bincover --no-print-directory
2021-08-25 09:43:29 +00:00
crowdsec : goversion
2022-05-17 10:14:59 +00:00
@$( MAKE) -C $( CROWDSEC_FOLDER) build --no-print-directory GOARCH = $( GOARCH) GOOS = $( GOOS) RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
2020-05-15 09:39:16 +00:00
2022-04-01 09:17:45 +00:00
crowdsec-bincover : goversion
@GOARCH= $( GOARCH) GOOS = $( GOOS) $( MAKE) -C $( CROWDSEC_FOLDER) build-bincover --no-print-directory
2021-08-25 09:43:29 +00:00
http-plugin : goversion
2022-05-17 10:14:59 +00:00
@$( MAKE) -C $( HTTP_PLUGIN_FOLDER) build --no-print-directory GOARCH = $( GOARCH) GOOS = $( GOOS) RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
2020-05-15 09:39:16 +00:00
2021-08-25 09:43:29 +00:00
slack-plugin : goversion
2022-05-17 10:14:59 +00:00
@$( MAKE) -C $( SLACK_PLUGIN_FOLDER) build --no-print-directory GOARCH = $( GOARCH) GOOS = $( GOOS) RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
2020-05-15 09:39:16 +00:00
2021-08-25 09:43:29 +00:00
splunk-plugin : goversion
2022-05-17 10:14:59 +00:00
@$( MAKE) -C $( SPLUNK_PLUGIN_FOLDER) build --no-print-directory GOARCH = $( GOARCH) GOOS = $( GOOS) RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
2020-05-15 09:39:16 +00:00
2022-01-06 10:20:59 +00:00
email-plugin : goversion
2022-05-17 10:14:59 +00:00
@$( MAKE) -C $( EMAIL_PLUGIN_FOLDER) build --no-print-directory GOARCH = $( GOARCH) GOOS = $( GOOS) RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
2021-08-25 09:43:29 +00:00
2022-03-16 08:30:04 +00:00
dummy-plugin : goversion
2022-05-17 10:14:59 +00:00
$( MAKE) -C $( DUMMY_PLUGIN_FOLDER) build --no-print-directory GOARCH = $( GOARCH) GOOS = $( GOOS) RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
2022-03-16 08:30:04 +00:00
2021-08-25 09:43:29 +00:00
cscli_static : goversion
2022-05-17 10:14:59 +00:00
@$( MAKE) -C $( CSCLI_FOLDER) static --no-print-directory GOARCH = $( GOARCH) GOOS = $( GOOS) RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
2021-08-25 09:43:29 +00:00
crowdsec_static : goversion
2022-05-17 10:14:59 +00:00
@$( MAKE) -C $( CROWDSEC_FOLDER) static --no-print-directory GOARCH = $( GOARCH) GOOS = $( GOOS) RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
2020-11-30 09:37:17 +00:00
2021-08-25 09:43:29 +00:00
http-plugin_static : goversion
2022-05-17 10:14:59 +00:00
@$( MAKE) -C $( HTTP_PLUGIN_FOLDER) static --no-print-directory GOARCH = $( GOARCH) GOOS = $( GOOS) RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
2020-05-15 09:39:16 +00:00
2021-08-25 09:43:29 +00:00
slack-plugin_static : goversion
2022-05-17 10:14:59 +00:00
@$( MAKE) -C $( SLACK_PLUGIN_FOLDER) static --no-print-directory GOARCH = $( GOARCH) GOOS = $( GOOS) RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
2020-05-15 09:39:16 +00:00
2021-08-25 09:43:29 +00:00
splunk-plugin_static : goversion
2022-05-17 10:14:59 +00:00
@$( MAKE) -C $( SPLUNK_PLUGIN_FOLDER) static --no-print-directory GOARCH = $( GOARCH) GOOS = $( GOOS) RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
2021-08-25 09:43:29 +00:00
2022-01-06 10:20:59 +00:00
email-plugin_static : goversion
2022-05-17 10:14:59 +00:00
@$( MAKE) -C $( EMAIL_PLUGIN_FOLDER) static --no-print-directory GOARCH = $( GOARCH) GOOS = $( GOOS) RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
2022-01-06 10:20:59 +00:00
2022-03-16 08:30:04 +00:00
dummy-plugin_static : goversion
2022-05-17 10:14:59 +00:00
$( MAKE) -C $( DUMMY_PLUGIN_FOLDER) static --no-print-directory GOARCH = $( GOARCH) GOOS = $( GOOS) RM = " $( RM) " WIN_IGNORE_ERR = " $( WIN_IGNORE_ERR) " CP = " $( CP) " CPR = " $( CPR) " MKDIR = " $( MKDIR) "
2022-03-16 08:30:04 +00:00
2022-02-14 21:21:19 +00:00
.PHONY : testclean
2022-03-09 13:45:36 +00:00
testclean : bats -clean
2022-05-17 10:14:59 +00:00
@$( RM) pkg/apiserver/ent $( WIN_IGNORE_ERR)
@$( RM) pkg/cwhub/hubdir $( WIN_IGNORE_ERR)
2022-05-17 13:54:52 +00:00
@$( RM) pkg/cwhub/install $( WIN_IGNORE_ERR)
@$( RM) pkg/types/example.txt $( WIN_IGNORE_ERR)
2022-02-14 21:21:19 +00:00
.PHONY : test
2022-05-17 13:54:52 +00:00
test : export AWS_ENDPOINT_FORCE =http ://localhost :4566
2021-08-25 09:43:29 +00:00
test : goversion
2022-06-16 14:13:48 +00:00
@echo 'NOTE: You need Docker, docker-compose and run "make localstack" in a separate shell ("make localstack-stop" to terminate it)'
2022-02-14 21:21:19 +00:00
$( GOTEST) $( LD_OPTS) ./...
2021-08-25 09:43:29 +00:00
2022-05-17 13:54:52 +00:00
.PHONY : localstack
localstack :
docker-compose -f tests/localstack/docker-compose.yml up
2022-06-16 14:13:48 +00:00
.PHONY : localstack -stop
localstack-stop :
docker-compose -f tests/localstack/docker-compose.yml down
2022-03-15 10:19:35 +00:00
package-common :
2022-05-17 10:14:59 +00:00
@echo " Building Release to dir $( RELDIR) "
@$( MKDIR) $( RELDIR) /cmd/crowdsec
@$( MKDIR) $( RELDIR) /cmd/crowdsec-cli
@$( MKDIR) $( RELDIR) /$( subst ./,,$( HTTP_PLUGIN_FOLDER) )
@$( MKDIR) $( RELDIR) /$( subst ./,,$( SLACK_PLUGIN_FOLDER) )
@$( MKDIR) $( RELDIR) /$( subst ./,,$( SPLUNK_PLUGIN_FOLDER) )
@$( MKDIR) $( RELDIR) /$( subst ./,,$( EMAIL_PLUGIN_FOLDER) )
@$( CP) $( CROWDSEC_FOLDER) /$( CROWDSEC_BIN) $( RELDIR) /cmd/crowdsec
@$( CP) $( CSCLI_FOLDER) /$( CSCLI_BIN) $( RELDIR) /cmd/crowdsec-cli
@$( 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) )
@$( CP) $( EMAIL_PLUGIN_FOLDER) /$( EMAIL_PLUGIN_BIN) $( RELDIR) /$( subst ./,,$( EMAIL_PLUGIN_FOLDER) )
@$( 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) )
@$( CP) $( EMAIL_PLUGIN_FOLDER) /$( EMAIL_PLUGIN_CONFIG) $( RELDIR) /$( subst ./,,$( EMAIL_PLUGIN_FOLDER) )
@$( CPR) ./config $( RELDIR)
@$( CP) wizard.sh $( RELDIR)
@$( CP) scripts/test_env.sh $( RELDIR)
@$( CP) scripts/test_env.ps1 $( RELDIR)
2021-09-14 13:32:35 +00:00
2022-03-15 10:19:35 +00:00
.PHONY : package
package : package -common
@tar cvzf crowdsec-release.tgz $( RELDIR)
2022-01-06 10:20:59 +00:00
2022-03-15 10:19:35 +00:00
package_static : package -common
2021-09-14 13:32:35 +00:00
@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 :
2022-05-17 10:14:59 +00:00
i f n e q ( $( OS ) , W i n d o w s _ N T )
2021-08-25 09:43:29 +00:00
@if [ -d $( RELDIR) ] ; then echo " $( RELDIR) already exists, abort " ; exit 1 ; fi
2022-05-17 10:14:59 +00:00
e l s e
@if ( Test-Path -Path $( RELDIR) ) { echo " $( RELDIR) already exists, abort " ; exit 1 ; }
e n d i f
2021-08-25 09:43:29 +00:00
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
2022-03-09 13:45:36 +00:00
2022-05-17 10:14:59 +00:00
.PHONY : windows_installer
windows_installer : build
@.\m ake_installer.ps1 -version $( BUILD_VERSION)
.PHONY : chocolatey
chocolatey : windows_installer
@.\m ake_chocolatey.ps1 -version $( BUILD_VERSION)
2022-03-09 13:45:36 +00:00
2022-05-17 13:54:52 +00:00
i n c l u d e t e s t s / b a t s . m k