github.com/nxtrace/NTrace-core@v1.3.1-0.20240513132635-39169291e8c9/.cross_compile.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  set -e
     4  
     5  DIST_PREFIX="nexttrace"
     6  DEBUG_MODE=${2}
     7  TARGET_DIR="dist"
     8  PLATFORMS="darwin/amd64 darwin/arm64 linux/386 linux/amd64 linux/arm64 linux/mips linux/mips64 linux/mipsle linux/mips64le windows/amd64 windows/arm64 openbsd/amd64 openbsd/arm64 freebsd/amd64 freebsd/arm64"
     9  
    10  BUILD_VERSION="$(git describe --tags --always)"
    11  BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
    12  COMMIT_SHA1="$(git rev-parse --short HEAD)"
    13  
    14  rm -rf ${TARGET_DIR}
    15  mkdir ${TARGET_DIR}
    16  
    17  for pl in ${PLATFORMS}; do
    18      export CGO_ENABLED=0
    19      export GOOS=$(echo ${pl} | cut -d'/' -f1)
    20      export GOARCH=$(echo ${pl} | cut -d'/' -f2)
    21      export TARGET=${TARGET_DIR}/${DIST_PREFIX}_${GOOS}_${GOARCH}
    22      if [ "${GOOS}" == "windows" ]; then
    23          export TARGET=${TARGET_DIR}/${DIST_PREFIX}_${GOOS}_${GOARCH}.exe
    24      fi
    25  
    26      echo "build => ${TARGET}"
    27      if [ "${DEBUG_MODE}" == "debug" ]; then
    28          go build -trimpath -gcflags "all=-N -l" -o ${TARGET} \
    29              -ldflags    "-X 'github.com/nxtrace/NTrace-core/config.Version=${BUILD_VERSION}' \
    30                          -X 'github.com/nxtrace/NTrace-core/config.BuildDate=${BUILD_DATE}' \
    31                          -X 'github.com/nxtrace/NTrace-core/config.CommitID=${COMMIT_SHA1}'\
    32                          -w -s"
    33      else
    34          go build -trimpath -o ${TARGET} \
    35              -ldflags    "-X 'github.com/nxtrace/NTrace-core/config.Version=${BUILD_VERSION}' \
    36                          -X 'github.com/nxtrace/NTrace-core/config.BuildDate=${BUILD_DATE}' \
    37                          -X 'github.com/nxtrace/NTrace-core/config.CommitID=${COMMIT_SHA1}'\
    38                          -w -s"
    39      fi
    40  done
    41      export CGO_ENABLED=0
    42      export GOOS='linux'
    43      export GOARCH='arm'
    44      export GOARM='7'
    45      export TARGET=${TARGET_DIR}/${DIST_PREFIX}_${GOOS}_${GOARCH}v7
    46      echo "build => ${TARGET}"
    47      if [ "${DEBUG_MODE}" == "debug" ]; then
    48          go build -trimpath -gcflags "all=-N -l" -o ${TARGET} \
    49              -ldflags    "-X 'github.com/nxtrace/NTrace-core/config.Version=${BUILD_VERSION}' \
    50                          -X 'github.com/nxtrace/NTrace-core/config.BuildDate=${BUILD_DATE}' \
    51                          -X 'github.com/nxtrace/NTrace-core/config.CommitID=${COMMIT_SHA1}'\
    52                          -w -s"
    53      else
    54          go build -trimpath -o ${TARGET} \
    55              -ldflags    "-X 'github.com/nxtrace/NTrace-core/config.Version=${BUILD_VERSION}' \
    56                          -X 'github.com/nxtrace/NTrace-core/config.BuildDate=${BUILD_DATE}' \
    57                          -X 'github.com/nxtrace/NTrace-core/config.CommitID=${COMMIT_SHA1}'\
    58                          -w -s"
    59      fi
    60  
    61