diff --git a/Makefile b/Makefile index d9b05519..9d480601 100644 --- a/Makefile +++ b/Makefile @@ -23,8 +23,6 @@ ANDROID_BUILD := $(ANDROID_BUILD_DIR)/Lndmobile.aar COMMIT := $(shell git describe --abbrev=40 --dirty) COMMIT_HASH := $(shell git rev-parse HEAD) -LDFLAGS := -ldflags "-X $(PKG)/build.Commit=$(COMMIT) \ - -X $(PKG)/build.CommitHash=$(COMMIT_HASH)" BTCD_COMMIT := $(shell cat go.mod | \ grep $(BTCD_PKG) | \ @@ -53,6 +51,14 @@ include make/testing_flags.mk DEV_TAGS := $(if ${tags},$(DEV_TAGS) ${tags},$(DEV_TAGS)) +make_ldflags = $(shell echo -ldflags \"-X $(PKG)/build.Commit=$(COMMIT) \ + -X $(PKG)/build.CommitHash=$(COMMIT_HASH) \ + -X $(PKG)/build.RawTags=$(shell echo $(1) | sed -e 's/ /,/g')\") + +LDFLAGS := $(call make_ldflags, ${tags}) +DEV_LDFLAGS := $(call make_ldflags, $(DEV_TAGS)) +ITEST_LDFLAGS := $(call make_ldflags, $(ITEST_TAGS)) + # Linting uses a lot of memory, so keep it under control by limiting the number # of workers if requested. ifneq ($(workers),) @@ -97,13 +103,13 @@ btcd: build: @$(call print, "Building debug lnd and lncli.") - $(GOBUILD) -tags="$(DEV_TAGS)" -o lnd-debug $(LDFLAGS) $(PKG)/cmd/lnd - $(GOBUILD) -tags="$(DEV_TAGS)" -o lncli-debug $(LDFLAGS) $(PKG)/cmd/lncli + $(GOBUILD) -tags="$(DEV_TAGS)" -o lnd-debug $(DEV_LDFLAGS) $(PKG)/cmd/lnd + $(GOBUILD) -tags="$(DEV_TAGS)" -o lncli-debug $(DEV_LDFLAGS) $(PKG)/cmd/lncli build-itest: @$(call print, "Building itest lnd and lncli.") - $(GOBUILD) -tags="$(ITEST_TAGS)" -o lnd-itest $(LDFLAGS) $(PKG)/cmd/lnd - $(GOBUILD) -tags="$(ITEST_TAGS)" -o lncli-itest $(LDFLAGS) $(PKG)/cmd/lncli + $(GOBUILD) -tags="$(ITEST_TAGS)" -o lnd-itest $(ITEST_LDFLAGS) $(PKG)/cmd/lnd + $(GOBUILD) -tags="$(ITEST_TAGS)" -o lncli-itest $(ITEST_LDFLAGS) $(PKG)/cmd/lncli install: @$(call print, "Installing lnd and lncli.") diff --git a/build/version.go b/build/version.go index 3e3a147f..d863adab 100644 --- a/build/version.go +++ b/build/version.go @@ -20,6 +20,10 @@ var ( // CommitHash stores the current commit hash of this build, this should // be set using the -ldflags during compilation. CommitHash string + + // RawTags contains the raw set of build tags, separated by commas. This + // should be set using -ldflags during compilation. + RawTags string ) // semanticAlphabet is the set of characters that are permitted for use in an @@ -74,3 +78,12 @@ func Version() string { return version } + +// Tags returns the list of build tags that were compiled into the executable. +func Tags() []string { + if len(RawTags) == 0 { + return nil + } + + return strings.Split(RawTags, ",") +}