Skip to content

Commit

Permalink
Plumb linker flags through from the Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
crawford committed Aug 6, 2015
1 parent 7c9bbef commit 79f1482
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ GODEPS_PKG_DIR = Godeps/_workspace/pkg
KUBE_GOFLAGS = $(GOFLAGS)
export KUBE_GOFLAGS

KUBE_GOLDFLAGS = $(GOLDFLAGS)
export KUBE_GOLDFLAGS

# Build code.
#
# Args:
# WHAT: Directory names to build. If any of these directories has a 'main'
# package, the build will produce executable files under $(OUT_DIR)/go/bin.
# If not specified, "everything" will be built.
# GOFLAGS: Extra flags to pass to 'go' when building.
# GOLDFLAGS: Extra linking flags to pass to 'go' when building.
#
# Example:
# make
Expand All @@ -35,6 +39,7 @@ all:
# directories will be run. If not specified, "everything" will be tested.
# TESTS: Same as WHAT.
# GOFLAGS: Extra flags to pass to 'go' when building.
# GOLDFLAGS: Extra linking flags to pass to 'go' when building.
#
# Example:
# make check
Expand Down Expand Up @@ -78,6 +83,7 @@ clean:
# vetted.
# TESTS: Same as WHAT.
# GOFLAGS: Extra flags to pass to 'go' when building.
# GOLDFLAGS: Extra linking flags to pass to 'go' when building.
#
# Example:
# make vet
Expand Down
17 changes: 7 additions & 10 deletions hack/lib/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,15 @@ kube::golang::build_binaries_for_platform() {
local outfile=$(kube::golang::output_filename_for_binary "${binary}" "${platform}")
CGO_ENABLED=0 go build -o "${outfile}" \
"${goflags[@]:+${goflags[@]}}" \
-ldflags "${version_ldflags}" \
-ldflags "${goldflags}" \
"${binary}"
kube::log::progress "*"
done
for binary in "${nonstatics[@]:+${nonstatics[@]}}"; do
local outfile=$(kube::golang::output_filename_for_binary "${binary}" "${platform}")
go build -o "${outfile}" \
"${goflags[@]:+${goflags[@]}}" \
-ldflags "${version_ldflags}" \
-ldflags "${goldflags}" \
"${binary}"
kube::log::progress "*"
done
Expand All @@ -386,12 +386,12 @@ kube::golang::build_binaries_for_platform() {
# Use go install.
if [[ "${#nonstatics[@]}" != 0 ]]; then
go install "${goflags[@]:+${goflags[@]}}" \
-ldflags "${version_ldflags}" \
-ldflags "${goldflags}" \
"${nonstatics[@]:+${nonstatics[@]}}"
fi
if [[ "${#statics[@]}" != 0 ]]; then
CGO_ENABLED=0 go install -installsuffix cgo "${goflags[@]:+${goflags[@]}}" \
-ldflags "${version_ldflags}" \
-ldflags "${goldflags}" \
"${statics[@]:+${statics[@]}}"
fi
fi
Expand All @@ -405,7 +405,7 @@ kube::golang::build_binaries_for_platform() {
pushd "$(dirname ${outfile})" >/dev/null
go test -c \
"${goflags[@]:+${goflags[@]}}" \
-ldflags "${version_ldflags}" \
-ldflags "${goldflags}" \
"$(dirname ${test})"
popd >/dev/null
done
Expand Down Expand Up @@ -447,16 +447,13 @@ kube::golang::build_binaries() {
# Check for `go` binary and set ${GOPATH}.
kube::golang::setup_env

# Fetch the version.
local version_ldflags
version_ldflags=$(kube::version::ldflags)

local host_platform
host_platform=$(kube::golang::host_platform)

# Use eval to preserve embedded quoted strings.
local goflags
local goflags goldflags
eval "goflags=(${KUBE_GOFLAGS:-})"
goldflags="${KUBE_GOLDFLAGS:-} $(kube::version::ldflags)"

local use_go_build
local -a targets=()
Expand Down

0 comments on commit 79f1482

Please sign in to comment.