Forráskód Böngészése

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>
AlteredCoder 4 éve
szülő
commit
60740f6279
4 módosított fájl, 13 hozzáadás és 2 törlés
  1. 9 0
      Makefile
  2. 1 1
      cmd/crowdsec-cli/Makefile
  3. 2 0
      cmd/crowdsec-cli/utils.go
  4. 1 1
      cmd/crowdsec/Makefile

+ 9 - 0
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_TIMESTAMP=$(shell date +%F"_"%T)
 BUILD_TAG="$(shell git rev-parse HEAD)"
+
 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.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)"
+
+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)
 
 all: clean test build

+ 1 - 1
cmd/crowdsec-cli/Makefile

@@ -14,7 +14,7 @@ build: clean
 	@$(GOBUILD) $(LD_OPTS) -o $(BINARY_NAME) -v
 
 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
 

+ 2 - 0
cmd/crowdsec-cli/utils.go

@@ -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
 			log.Debugf("Your current crowdsec version seems to be a pre-release (%s)", csVersion)
 			cwhub.HubBranch = "master"
+		} else if csVersion == "" {
+			log.Warningf("Crowdsec version is '', using master branch for the hub")
 		} 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("As a result, you will not be able to use parsers/scenarios/collections added to Crowdsec Hub after CrowdSec %s", latest)

+ 1 - 1
cmd/crowdsec/Makefile

@@ -20,7 +20,7 @@ build: clean
 	$(GOBUILD) $(LD_OPTS) -o $(CROWDSEC_BIN) -v
 
 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:
 	$(GOTEST) -v ./...