diff --git a/Makefile b/Makefile index 375e1139b0..2a245d027a 100644 --- a/Makefile +++ b/Makefile @@ -47,16 +47,16 @@ GO_LDFLAGS ?= -s -w \ -X $(IMAGES_PKGS).Registry=$(REGISTRY) \ -X $(MGMT_HELPERS_PKG).ArtifactsPath=$(ARTIFACTS) -WITH_RACE ?= -WITH_DEBUG ?= +WITH_RACE ?= false +WITH_DEBUG ?= false -ifneq ($(strip $(WITH_RACE)),) +ifeq ($(shell hack/parsebool.sh $(WITH_RACE); echo $$?), 1) CGO_ENABLED = 1 GO_BUILDFLAGS += -race GO_LDFLAGS += -linkmode=external -extldflags '-static' endif -ifeq ($(WITH_DEBUG), true) +ifeq ($(shell hack/parsebool.sh $(WITH_DEBUG); echo $$?), 1) GO_BUILDFLAGS += -tags sidero.debug endif diff --git a/hack/parsebool.sh b/hack/parsebool.sh new file mode 100755 index 0000000000..5c0e086305 --- /dev/null +++ b/hack/parsebool.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# parsebool.sh exits with code: +# 0 if passed argument is false, FALSE, f, 0, etc +# 1 if passed argument is true, TRUE, t, 1, etc +# 2 if passed argument is absent, an empty string or something else + +set -e + +arg=$(echo $* | tr '[:upper:]' '[:lower:]') + +case $arg in + false|f|0) exit 0 ;; + true|t|1) exit 1 ;; + *) exit 2 ;; +esac