Skip to content

Commit

Permalink
chore: parse "boolean" variables
Browse files Browse the repository at this point in the history
Makes `make WITH_DEBUG=1` work.

Refs #3534.

Signed-off-by: Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
  • Loading branch information
AlekSi authored and talos-bot committed May 13, 2021
1 parent c81cfb2 commit 9b1338d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions hack/parsebool.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9b1338d

Please sign in to comment.