diff --git a/makefile b/makefile index 6f2682ea..400d1e33 100644 --- a/makefile +++ b/makefile @@ -5,10 +5,16 @@ DIRECTORY = $(sort $(dir $(wildcard ./test/*/))) VERSION = $(shell git describe --tags --dirty) BUILDTIME := $(shell date '+%Y-%m-%dT%T%z') + GOLDFLAGS += -X main.Version=$(VERSION) GOLDFLAGS += -X main.Buildtime=$(BUILDTIME) GOFLAGS = -ldflags "$(GOLDFLAGS)" + +LINKERFLAGS = $(GOLDFLAGS) +LINKERFLAGS += -s -w +GORELEASEFLAGS = -ldflags "$(LINKERFLAGS)" + swagger: mkdir -p swaggerdocs swag init -o swaggerdocs @@ -35,9 +41,9 @@ clean: compile: swagger echo "Compiling for every OS and Platform" - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-linux-amd64 $(GOFLAGS) main.go - CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/${BINARY_NAME}-${VERSION}-darwin-arm64 $(GOFLAGS) main.go - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-windows-amd64 $(GOFLAGS) main.go + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-linux-amd64 $(GORELEASEFLAGS) main.go + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/${BINARY_NAME}-${VERSION}-darwin-arm64 $(GORELEASEFLAGS) main.go + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-windows-amd64 $(GORELEASEFLAGS) main.go sbom: echo "Generating SBOMs" @@ -47,7 +53,7 @@ sbom: CGO_ENABLED=0 GOOS=windows GOARCH=amd64 cyclonedx-gomod app -json -licenses -output bin/${BINARY_NAME}-${VERSION}-windows-amd64.bom.json pre-docker-build: swagger - GOOS=linux GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-linux-amd64 $(GOFLAGS) main.go + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-linux-amd64 $(GOFLAGS) main.go docker: pre-docker-build docker build --no-cache -t soarca:${VERSION} --build-arg="VERSION=${VERSION}" .