github.com/ojongerius/docker@v1.11.2/hack/make/binary (about) 1 #!/bin/bash 2 set -e 3 4 BINARY_NAME="docker-$VERSION" 5 BINARY_EXTENSION="$(binary_extension)" 6 BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION" 7 8 source "${MAKEDIR}/.go-autogen" 9 10 ( 11 export GOGC=${DOCKER_BUILD_GOGC:-1000} 12 13 if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARCH)" ]; then 14 # must be cross-compiling! 15 case "$(go env GOOS)/$(go env GOARCH)" in 16 windows/amd64) 17 export CC=x86_64-w64-mingw32-gcc 18 export CGO_ENABLED=1 19 ;; 20 esac 21 fi 22 23 if [ "$(go env GOOS)" == "linux" ] ; then 24 case "$(go env GOARCH)" in 25 arm*|386) 26 # linking for Linux on arm or x86 needs external linking to avoid 27 # https://github.com/golang/go/issues/9510 until we move to Go 1.6 28 if [ "$IAMSTATIC" == "true" ] ; then 29 export EXTLDFLAGS_STATIC="$EXTLDFLAGS_STATIC -zmuldefs" 30 export LDFLAGS_STATIC_DOCKER="$LDFLAGS_STATIC -extldflags \"$EXTLDFLAGS_STATIC\"" 31 32 else 33 export LDFLAGS="$LDFLAGS -extldflags -zmuldefs" 34 fi 35 ;; 36 esac 37 fi 38 39 if [ "$IAMSTATIC" == "true" ] && [ "$(go env GOHOSTOS)" == "linux" ]; then 40 if [ "${GOOS}/${GOARCH}" == "darwin/amd64" ]; then 41 export CGO_ENABLED=1 42 export CC=o64-clang 43 export LDFLAGS='-linkmode external -s' 44 export LDFLAGS_STATIC_DOCKER='-extld='${CC} 45 else 46 export BUILDFLAGS=( "${BUILDFLAGS[@]/pkcs11 /}" ) # we cannot dlopen in pkcs11 in a static binary 47 fi 48 fi 49 50 echo "Building: $DEST/$BINARY_FULLNAME" 51 go build \ 52 -o "$DEST/$BINARY_FULLNAME" \ 53 "${BUILDFLAGS[@]}" \ 54 -ldflags " 55 $LDFLAGS 56 $LDFLAGS_STATIC_DOCKER 57 " \ 58 ./docker 59 ) 60 61 echo "Created binary: $DEST/$BINARY_FULLNAME" 62 ln -sf "$BINARY_FULLNAME" "$DEST/docker$BINARY_EXTENSION" 63 64 copy_containerd "$DEST" "hash" 65 hash_files "$DEST/$BINARY_FULLNAME"