Browse code

Use code generation to set IAMSTATIC instead of -X

Signed-off-by: Michael Hudson-Doyle <michael.hudson@linaro.org>

Michael Hudson-Doyle authored on 2014/10/01 09:37:30
Showing 4 changed files
... ...
@@ -27,3 +27,4 @@ docs/AWS_S3_BUCKET
27 27
 docs/GIT_BRANCH
28 28
 docs/VERSION
29 29
 docs/GITCOMMIT
30
+dockerversion/static.go
... ...
@@ -94,6 +94,8 @@ if [ -z "$DOCKER_CLIENTONLY" ]; then
94 94
 	DOCKER_BUILDTAGS+=" daemon"
95 95
 fi
96 96
 
97
+rm -f dockerversion/static.go
98
+
97 99
 # Use these flags when compiling the tests and final binary
98 100
 LDFLAGS='
99 101
 	-w
... ...
@@ -115,7 +117,6 @@ TESTFLAGS+=" -test.timeout=${TIMEOUT}"
115 115
 EXTLDFLAGS_STATIC_DOCKER="$EXTLDFLAGS_STATIC -lpthread -Wl,--unresolved-symbols=ignore-in-object-files"
116 116
 LDFLAGS_STATIC_DOCKER="
117 117
 	$LDFLAGS_STATIC
118
-	-X $DOCKER_PKG/dockerversion.IAMSTATIC true
119 118
 	-extldflags \"$EXTLDFLAGS_STATIC_DOCKER\"
120 119
 "
121 120
 
... ...
@@ -3,6 +3,17 @@ set -e
3 3
 
4 4
 DEST=$1
5 5
 
6
+: ${IAMSTATIC:=true}
7
+
8
+cat > dockerversion/static.go <<EOF
9
+// AUTOGENERATED FILE; see hack/make/binary and hack/make/dynbinary
10
+package dockerversion
11
+
12
+func init() {
13
+	IAMSTATIC = $IAMSTATIC
14
+}
15
+EOF
16
+
6 17
 go build \
7 18
 	-o "$DEST/docker-$VERSION" \
8 19
 	"${BUILDFLAGS[@]}" \
... ...
@@ -5,6 +5,14 @@ DEST=$1
5 5
 
6 6
 if [ -z "$DOCKER_CLIENTONLY" ]; then
7 7
 	# dockerinit still needs to be a static binary, even if docker is dynamic
8
+	cat > dockerversion/static.go <<EOF
9
+// AUTOGENERATED FILE; see hack/make/binary and hack/make/dynbinary
10
+package dockerversion
11
+
12
+func init() {
13
+	IAMSTATIC = true
14
+}
15
+EOF
8 16
 	go build \
9 17
 		-o "$DEST/dockerinit-$VERSION" \
10 18
 		"${BUILDFLAGS[@]}" \
... ...
@@ -40,6 +48,7 @@ fi
40 40
 
41 41
 (
42 42
 	export LDFLAGS_STATIC_DOCKER="-X $DOCKER_PKG/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" -X $DOCKER_PKG/dockerversion.INITPATH \"$DOCKER_INITPATH\""
43
+	export IAMSTATIC=false
43 44
 	export BUILDFLAGS=( "${BUILDFLAGS[@]/netgo /}" ) # disable netgo, since we don't need it for a dynamic binary
44 45
 	source "$(dirname "$BASH_SOURCE")/binary"
45 46
 )