summaryrefslogtreecommitdiff
path: root/build.bash
diff options
context:
space:
mode:
authorJakob Unterwurzacher2020-04-18 16:55:41 +0200
committerJakob Unterwurzacher2020-04-18 17:09:25 +0200
commit5da5e9fdf2db0f3c709a6662604d768865462068 (patch)
tree6c70447704e0d27e39956bc7a8cfd419d4405eb8 /build.bash
parentf6b1c680b3f7c7d5cd842cca3117f5ee2f0f2fad (diff)
build.bash: don't enable -buildmode=pie for static builds
Causes warnings: $ ./build-without-openssl.bash # github.com/rfjakob/gocryptfs loadinternal: cannot find runtime/cgo # github.com/rfjakob/gocryptfs/gocryptfs-xray loadinternal: cannot find runtime/cgo # github.com/rfjakob/gocryptfs/contrib/statfs loadinternal: cannot find runtime/cgo gocryptfs v1.7.1-48-gf6b1c68 without_openssl; go-fuse v1.0.1-0.20190319092520-161a16484456; 2020-04-18 go1.13.6 linux/amd64 https://github.com/golang/go/issues/30986
Diffstat (limited to 'build.bash')
-rwxr-xr-xbuild.bash29
1 files changed, 19 insertions, 10 deletions
diff --git a/build.bash b/build.bash
index afccb72..c19e789 100755
--- a/build.bash
+++ b/build.bash
@@ -63,16 +63,25 @@ if [[ -n ${SOURCE_DATE_EPOCH:-} ]] ; then
BUILDDATE=$(date --utc --date="@${SOURCE_DATE_EPOCH}" +%Y-%m-%d)
fi
-# For reproducible builds, we get rid of $HOME references in the binary
-# using "-trimpath".
-# Also, Fedora and Arch want pie enabled, so enable it.
-# * https://fedoraproject.org/wiki/Changes/golang-buildmode-pie
-# * https://github.com/rfjakob/gocryptfs/pull/460
-# However, -trimpath needs Go 1.13+, and we support Go 1.11 and Go 1.12
-# too. So don't add it there.
-GV=$(go version)
-if [[ $GV != *"1.11"* && $GV != *"1.12"* ]] ; then
- export GOFLAGS="${GOFLAGS:--trimpath -buildmode=pie}"
+# Only set GOFLAGS if it is not already set by the user
+if [[ -z ${GOFLAGS:-} ]] ; then
+ GOFLAGS=""
+ # For reproducible builds, we get rid of $HOME references in the
+ # binary using "-trimpath".
+ # However, -trimpath needs Go 1.13+, and we support Go 1.11 and Go 1.12
+ # too. So don't add it there.
+ GV=$(go version)
+ if [[ $GV != *"1.11"* && $GV != *"1.12"* ]] ; then
+ GOFLAGS="-trimpath"
+ fi
+ # Also, Fedora and Arch want pie enabled, so enable it.
+ # * https://fedoraproject.org/wiki/Changes/golang-buildmode-pie
+ # * https://github.com/rfjakob/gocryptfs/pull/460
+ # But not with CGO_ENABLED=0 (https://github.com/golang/go/issues/30986)!
+ if [[ ${CGO_ENABLED:-1} -ne 0 ]] ; then
+ GOFLAGS="$GOFLAGS -buildmode=pie"
+ fi
+ export GOFLAGS
fi
GO_LDFLAGS="-X main.GitVersion=$GITVERSION -X main.GitVersionFuse=$GITVERSIONFUSE -X main.BuildDate=$BUILDDATE"