github.com/fcwu/docker@v1.4.2-0.20150115145920-2a69ca89f0df/project/make/dynbinary (about)

     1  #!/bin/bash
     2  set -e
     3  
     4  DEST=$1
     5  
     6  if [ -z "$DOCKER_CLIENTONLY" ]; then
     7  	# dockerinit still needs to be a static binary, even if docker is dynamic
     8  	go build \
     9  		-o "$DEST/dockerinit-$VERSION" \
    10  		"${BUILDFLAGS[@]}" \
    11  		-ldflags "
    12  			$LDFLAGS
    13  			$LDFLAGS_STATIC
    14  			-extldflags \"$EXTLDFLAGS_STATIC\"
    15  		" \
    16  		./dockerinit
    17  	echo "Created binary: $DEST/dockerinit-$VERSION"
    18  	ln -sf "dockerinit-$VERSION" "$DEST/dockerinit"
    19  	
    20  	hash_files "$DEST/dockerinit-$VERSION"
    21  	
    22  	sha1sum=
    23  	if command -v sha1sum &> /dev/null; then
    24  		sha1sum=sha1sum
    25  	elif command -v shasum &> /dev/null; then
    26  		# Mac OS X - why couldn't they just use the same command name and be happy?
    27  		sha1sum=shasum
    28  	else
    29  		echo >&2 'error: cannot find sha1sum command or equivalent'
    30  		exit 1
    31  	fi
    32  	
    33  	# sha1 our new dockerinit to ensure separate docker and dockerinit always run in a perfect pair compiled for one another
    34  	export DOCKER_INITSHA1="$($sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)"
    35  else
    36  	# DOCKER_CLIENTONLY must be truthy, so we don't need to bother with dockerinit :)
    37  	export DOCKER_INITSHA1=""
    38  fi
    39  # exported so that "dyntest" can easily access it later without recalculating it
    40  
    41  (
    42  	export LDFLAGS_STATIC_DOCKER="-X $DOCKER_PKG/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" -X $DOCKER_PKG/dockerversion.INITPATH \"$DOCKER_INITPATH\""
    43  	export BUILDFLAGS=( "${BUILDFLAGS[@]/netgo /}" ) # disable netgo, since we don't need it for a dynamic binary
    44  	source "$(dirname "$BASH_SOURCE")/binary"
    45  )