fix makefile for static binaries (#764)
* Fix LD_OPTS for static build Co-authored-by: AlteredCoder <AlteredCoder> Co-authored-by: Sebastien Blot <sebastien@crowdsec.net>
This commit is contained in:
parent
b0d4744b15
commit
60740f6279
9
Makefile
9
Makefile
|
@ -33,12 +33,21 @@ BUILD_GOVERSION="$(shell go version | cut -d " " -f3 | sed -r 's/[go]+//g')"
|
||||||
BUILD_CODENAME=$(shell cat RELEASE.json | jq -r .CodeName)
|
BUILD_CODENAME=$(shell cat RELEASE.json | jq -r .CodeName)
|
||||||
BUILD_TIMESTAMP=$(shell date +%F"_"%T)
|
BUILD_TIMESTAMP=$(shell date +%F"_"%T)
|
||||||
BUILD_TAG="$(shell git rev-parse HEAD)"
|
BUILD_TAG="$(shell git rev-parse HEAD)"
|
||||||
|
|
||||||
export LD_OPTS=-ldflags "-s -w -X github.com/crowdsecurity/crowdsec/pkg/cwversion.Version=$(BUILD_VERSION) \
|
export LD_OPTS=-ldflags "-s -w -X github.com/crowdsecurity/crowdsec/pkg/cwversion.Version=$(BUILD_VERSION) \
|
||||||
-X github.com/crowdsecurity/crowdsec/pkg/cwversion.System=$(SYSTEM) \
|
-X github.com/crowdsecurity/crowdsec/pkg/cwversion.System=$(SYSTEM) \
|
||||||
-X github.com/crowdsecurity/crowdsec/pkg/cwversion.BuildDate=$(BUILD_TIMESTAMP) \
|
-X github.com/crowdsecurity/crowdsec/pkg/cwversion.BuildDate=$(BUILD_TIMESTAMP) \
|
||||||
-X github.com/crowdsecurity/crowdsec/pkg/cwversion.Codename=$(BUILD_CODENAME) \
|
-X github.com/crowdsecurity/crowdsec/pkg/cwversion.Codename=$(BUILD_CODENAME) \
|
||||||
-X github.com/crowdsecurity/crowdsec/pkg/cwversion.Tag=$(BUILD_TAG) \
|
-X github.com/crowdsecurity/crowdsec/pkg/cwversion.Tag=$(BUILD_TAG) \
|
||||||
-X github.com/crowdsecurity/crowdsec/pkg/cwversion.GoVersion=$(BUILD_GOVERSION)"
|
-X github.com/crowdsecurity/crowdsec/pkg/cwversion.GoVersion=$(BUILD_GOVERSION)"
|
||||||
|
|
||||||
|
export LD_OPTS_STATIC=-ldflags "-s -w -X github.com/crowdsecurity/crowdsec/pkg/cwversion.Version=$(BUILD_VERSION) \
|
||||||
|
-X github.com/crowdsecurity/crowdsec/pkg/cwversion.BuildDate=$(BUILD_TIMESTAMP) \
|
||||||
|
-X github.com/crowdsecurity/crowdsec/pkg/cwversion.Codename=$(BUILD_CODENAME) \
|
||||||
|
-X github.com/crowdsecurity/crowdsec/pkg/cwversion.Tag=$(BUILD_TAG) \
|
||||||
|
-X github.com/crowdsecurity/crowdsec/pkg/cwversion.GoVersion=$(BUILD_GOVERSION) \
|
||||||
|
-extldflags '-static'"
|
||||||
|
|
||||||
RELDIR = crowdsec-$(BUILD_VERSION)
|
RELDIR = crowdsec-$(BUILD_VERSION)
|
||||||
|
|
||||||
all: clean test build
|
all: clean test build
|
||||||
|
|
|
@ -14,7 +14,7 @@ build: clean
|
||||||
@$(GOBUILD) $(LD_OPTS) -o $(BINARY_NAME) -v
|
@$(GOBUILD) $(LD_OPTS) -o $(BINARY_NAME) -v
|
||||||
|
|
||||||
static: clean
|
static: clean
|
||||||
@$(GOBUILD) -o $(BINARY_NAME) -v -a -tags netgo -ldflags '-w -extldflags "-static"'
|
@$(GOBUILD) $(LD_OPTS_STATIC) -o $(BINARY_NAME) -v -a -tags netgo
|
||||||
|
|
||||||
install: install-conf install-bin
|
install: install-conf install-bin
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,8 @@ func setHubBranch() error {
|
||||||
} else if semver.Compare(csVersion, latest) == 1 { // if current version is greater than the latest we are in pre-release
|
} else if semver.Compare(csVersion, latest) == 1 { // if current version is greater than the latest we are in pre-release
|
||||||
log.Debugf("Your current crowdsec version seems to be a pre-release (%s)", csVersion)
|
log.Debugf("Your current crowdsec version seems to be a pre-release (%s)", csVersion)
|
||||||
cwhub.HubBranch = "master"
|
cwhub.HubBranch = "master"
|
||||||
|
} else if csVersion == "" {
|
||||||
|
log.Warningf("Crowdsec version is '', using master branch for the hub")
|
||||||
} else {
|
} else {
|
||||||
log.Warnf("Crowdsec is not the latest version. Current version is '%s' and the latest stable version is '%s'. Please update it!", csVersion, latest)
|
log.Warnf("Crowdsec is not the latest version. Current version is '%s' and the latest stable version is '%s'. Please update it!", csVersion, latest)
|
||||||
log.Warnf("As a result, you will not be able to use parsers/scenarios/collections added to Crowdsec Hub after CrowdSec %s", latest)
|
log.Warnf("As a result, you will not be able to use parsers/scenarios/collections added to Crowdsec Hub after CrowdSec %s", latest)
|
||||||
|
|
|
@ -20,7 +20,7 @@ build: clean
|
||||||
$(GOBUILD) $(LD_OPTS) -o $(CROWDSEC_BIN) -v
|
$(GOBUILD) $(LD_OPTS) -o $(CROWDSEC_BIN) -v
|
||||||
|
|
||||||
static: clean
|
static: clean
|
||||||
$(GOBUILD) -o $(CROWDSEC_BIN) -v -a -tags netgo -ldflags '-w -extldflags "-static"'
|
$(GOBUILD) $(LD_OPTS_STATIC) -o $(CROWDSEC_BIN) -v -a -tags netgo
|
||||||
|
|
||||||
test:
|
test:
|
||||||
$(GOTEST) -v ./...
|
$(GOTEST) -v ./...
|
||||||
|
|
Loading…
Reference in a new issue