github.com/XiaoMi/Gaea@v1.2.5/gen_ldflags.sh (about) 1 #!/bin/bash 2 3 VERBOSE=${VERBOSE:-"0"} 4 V="" 5 if [[ "${VERBOSE}" == "1" ]];then 6 V="-x" 7 set -x 8 fi 9 10 ROOT="$(pwd)" 11 12 OUT=${1:?"output path"} 13 VERSION_PACKAGE=${2:?"version go package"} # istio.io/istio/pkg/version 14 BUILDPATH=${3:?"path to build"} 15 16 set -e 17 18 GOOS=${GOOS:-linux} 19 GOARCH=${GOARCH:-amd64} 20 GOBINARY=${GOBINARY:-go} 21 GOPKG="$GOPATH/pkg" 22 BUILDINFO=${BUILDINFO:-""} 23 STATIC=${STATIC:-1} 24 LDFLAGS="-extldflags -static" 25 GOBUILDFLAGS=${GOBUILDFLAGS:-""} 26 GCFLAGS=${GCFLAGS:-} 27 export CGO_ENABLED=0 28 29 if [[ "${STATIC}" != "1" ]];then 30 LDFLAGS="" 31 fi 32 33 # gather buildinfo if not already provided 34 # For a release build BUILDINFO should be produced 35 # at the beginning of the build and used throughout 36 if [[ -z ${BUILDINFO} ]];then 37 BUILDINFO=$(mktemp) 38 ${ROOT}/gen_version.sh > ${BUILDINFO} 39 fi 40 41 # BUILD LD_VERSIONFLAGS 42 LD_VERSIONFLAGS="" 43 while read line; do 44 read SYMBOL VALUE < <(echo $line) 45 LD_VERSIONFLAGS=${LD_VERSIONFLAGS}" -X ${VERSION_PACKAGE}.${SYMBOL}=${VALUE}" 46 done < "${BUILDINFO}" 47 48 echo -pkgdir=${GOPKG}/${GOOS}_${GOARCH} -ldflags "\"${LDFLAGS} ${LD_VERSIONFLAGS}\"" ${BUILDPATH}