github.com/afbjorklund/moby@v20.10.5+incompatible/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 is not supported on Windows and Linux on mips and riscv64.
    74  	case "$(go env GOOS)/$(go env GOARCH)" in
    75  		windows/* | linux/mips* | linux/riscv*) ;;
    76  
    77  		*)
    78  			BUILDFLAGS+=("-buildmode=pie")
    79  			;;
    80  	esac
    81  
    82  	echo "Building: $DEST/$BINARY_FULLNAME"
    83  	echo "GOOS=\"${GOOS}\" GOARCH=\"${GOARCH}\" GOARM=\"${GOARM}\""
    84  	go build \
    85  		-o "$DEST/$BINARY_FULLNAME" \
    86  		"${BUILDFLAGS[@]}" \
    87  		-ldflags "
    88  		$LDFLAGS
    89  		$LDFLAGS_STATIC_DOCKER
    90  		$DOCKER_LDFLAGS
    91  	" \
    92  		${GO_PACKAGE}
    93  )
    94  
    95  echo "Created binary: $DEST/$BINARY_FULLNAME"
    96  ln -sf "$BINARY_FULLNAME" "$DEST/$BINARY_SHORT_NAME$BINARY_EXTENSION"
    97  
    98  hash_files "$DEST/$BINARY_FULLNAME"