github.com/iotexproject/iotex-core@v1.14.1-rc1/tools/xctl/buildcli.sh (about)

     1  #!/bin/sh
     2  
     3  initOS() {
     4      OS=$(uname | tr '[:upper:]' '[:lower:]')
     5      OS_CYGWIN=0
     6      if [ -n "$DEP_OS" ]; then
     7          echo "Using DEP_OS"
     8          OS="$DEP_OS"
     9      fi
    10      case "$OS" in
    11          darwin) OS='darwin';;
    12          linux) OS='linux';;
    13          freebsd) OS='freebsd';;
    14          mingw*) OS='windows';;
    15          msys*) OS='windows';;
    16  	cygwin*)
    17  	    OS='windows'
    18  	    OS_CYGWIN=1
    19  	    ;;
    20          *) echo "OS ${OS} is not supported by this installation script"; exit 1;;
    21      esac
    22      echo "OS = $OS"
    23  }
    24  
    25  initVersion() {
    26      PACKAGE_VERSION=$(git describe --tags)
    27      PACKAGE_COMMIT_ID=$(git rev-parse HEAD)
    28      GIT_STATUS=$(git status --porcelain)
    29      if ! [ -z "$GIT_STATUS" ];then
    30      #if git_status=$(git status --porcelain) && [[ -z ${git_status} ]]; then
    31          GIT_STATUS="dirty"
    32      else
    33      	GIT_STATUS="clean"
    34      fi
    35      GO_VERSION=$(go version)
    36      BUILD_TIME=$(date +%F-%Z/%T)
    37      VersionImportPath='github.com/iotexproject/iotex-core/pkg/version'
    38      PackageFlags="-X '${VersionImportPath}.PackageVersion=${PACKAGE_VERSION}' "
    39      ## Ubuntu PackageFlags+="-X " have fault
    40      if [ "$OS" = "linux" ]; then
    41      	PackageFlags=${PackageFlags}"-X '${VersionImportPath}.PackageCommitID=${PACKAGE_COMMIT_ID}' "
    42      	PackageFlags=${PackageFlags}"-X '${VersionImportPath}.GitStatus=${GIT_STATUS}' "
    43      	PackageFlags=${PackageFlags}"-X '${VersionImportPath}.GoVersion=${GO_VERSION}' "
    44      	PackageFlags=${PackageFlags}"-X '${VersionImportPath}.BuildTime=${BUILD_TIME}' "
    45      	PackageFlags=${PackageFlags}"-s -w"
    46      else
    47      	PackageFlags+="-X '${VersionImportPath}.PackageCommitID=${PACKAGE_COMMIT_ID}' "
    48      	PackageFlags+="-X '${VersionImportPath}.GitStatus=${GIT_STATUS}' "
    49      	PackageFlags+="-X '${VersionImportPath}.GoVersion=${GO_VERSION}' "
    50      	PackageFlags+="-X '${VersionImportPath}.BuildTime=${BUILD_TIME}' "
    51      	PackageFlags+="-s -w"
    52     fi
    53  }
    54  initOS
    55  initVersion
    56  project_name="xctl"
    57  
    58  release_dir=./release
    59  rm -rf $release_dir/*
    60  mkdir -p $release_dir
    61  
    62  cd  $(dirname $0)
    63  
    64  gofmt -w ./
    65  
    66  CGO_ENABLED=1 GOARCH=amd64 go build -ldflags "${PackageFlags}" -o $release_dir/$project_name-$OS-amd64 -v .
    67  #CGO_ENABLED=1 GOARCH=386 go build -o $release_dir/$project_name-$OS-386 -v .