github.com/skf/moby@v1.13.1/hack/make/.binary (about)

     1  #!/bin/bash
     2  set -e
     3  
     4  BINARY_NAME="$BINARY_SHORT_NAME-$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 [ "$IAMSTATIC" == "true" ] && [ "$(go env GOHOSTOS)" == "linux" ]; then
    24  	if  [ "${GOOS}/${GOARCH}" == "darwin/amd64" ]; then
    25  		export CGO_ENABLED=1
    26  		export CC=o64-clang
    27  		export LDFLAGS='-linkmode external -s'
    28  		export LDFLAGS_STATIC_DOCKER='-extld='${CC}
    29  	else
    30  		export BUILDFLAGS=( "${BUILDFLAGS[@]/pkcs11 /}" ) # we cannot dlopen in pkcs11 in a static binary
    31  	fi
    32  fi
    33  
    34  echo "Building: $DEST/$BINARY_FULLNAME"
    35  go build \
    36  	-o "$DEST/$BINARY_FULLNAME" \
    37  	"${BUILDFLAGS[@]}" \
    38  	-ldflags "
    39  		$LDFLAGS
    40  		$LDFLAGS_STATIC_DOCKER
    41  	" \
    42  	$GO_PACKAGE
    43  )
    44  
    45  echo "Created binary: $DEST/$BINARY_FULLNAME"
    46  ln -sf "$BINARY_FULLNAME" "$DEST/$BINARY_SHORT_NAME$BINARY_EXTENSION"
    47  
    48  hash_files "$DEST/$BINARY_FULLNAME"