github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/hack/make/.binary (about) 1 #!/usr/bin/env bash 2 set -e 3 4 # a helper to provide ".exe" when it's appropriate 5 binary_extension() { 6 if [ "$(go env GOOS)" = 'windows' ]; then 7 echo -n '.exe' 8 fi 9 } 10 11 GO_PACKAGE='github.com/docker/docker/cmd/dockerd' 12 BINARY_SHORT_NAME='dockerd' 13 BINARY_NAME="$BINARY_SHORT_NAME-$VERSION" 14 BINARY_EXTENSION="$(binary_extension)" 15 BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION" 16 17 source "${MAKEDIR}/.go-autogen" 18 19 hash_files() { 20 while [ $# -gt 0 ]; do 21 f="$1" 22 shift 23 dir="$(dirname "$f")" 24 base="$(basename "$f")" 25 for hashAlgo in md5 sha256; do 26 if command -v "${hashAlgo}sum" &> /dev/null; then 27 ( 28 # subshell and cd so that we get output files like: 29 # $HASH docker-$VERSION 30 # instead of: 31 # $HASH /go/src/github.com/.../$VERSION/binary/docker-$VERSION 32 cd "$dir" 33 "${hashAlgo}sum" "$base" > "$base.$hashAlgo" 34 ) 35 fi 36 done 37 done 38 } 39 40 ( 41 export GOGC=${DOCKER_BUILD_GOGC:-1000} 42 43 if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARCH)" ]; then 44 # must be cross-compiling! 45 case "$(go env GOOS)/$(go env GOARCH)" in 46 windows/amd64) 47 export CC="${CC:-x86_64-w64-mingw32-gcc}" 48 export CGO_ENABLED=1 49 ;; 50 linux/arm) 51 case "${GOARM}" in 52 5 | "") 53 export CC="${CC:-arm-linux-gnueabi-gcc}" 54 export CGO_ENABLED=1 55 ;; 56 7) 57 export CC="${CC:-arm-linux-gnueabihf-gcc}" 58 export CGO_ENABLED=1 59 ;; 60 esac 61 ;; 62 linux/arm64) 63 export CC="${CC:-aarch64-linux-gnu-gcc}" 64 export CGO_ENABLED=1 65 ;; 66 linux/amd64) 67 export CC="${CC:-x86_64-linux-gnu-gcc}" 68 export CGO_ENABLED=1 69 ;; 70 esac 71 fi 72 73 # -buildmode=pie not supported when -race is enabled 74 if [[ " $BUILDFLAGS " != *" -race "* ]]; then 75 # -buildmode=pie is not supported on Windows and Linux on mips and riscv64. 76 case "$(go env GOOS)/$(go env GOARCH)" in 77 windows/* | linux/mips* | linux/riscv*) ;; 78 79 *) 80 BUILDFLAGS+=("-buildmode=pie") 81 ;; 82 esac 83 fi 84 85 echo "Building: $DEST/$BINARY_FULLNAME" 86 echo "GOOS=\"${GOOS}\" GOARCH=\"${GOARCH}\" GOARM=\"${GOARM}\"" 87 go build \ 88 -o "$DEST/$BINARY_FULLNAME" \ 89 "${BUILDFLAGS[@]}" \ 90 -ldflags " 91 $LDFLAGS 92 $LDFLAGS_STATIC_DOCKER 93 $DOCKER_LDFLAGS 94 " \ 95 ${GO_PACKAGE} 96 ) 97 98 echo "Created binary: $DEST/$BINARY_FULLNAME" 99 ln -sf "$BINARY_FULLNAME" "$DEST/$BINARY_SHORT_NAME$BINARY_EXTENSION" 100 101 hash_files "$DEST/$BINARY_FULLNAME"