github.com/docker/libcompose@v0.4.1-0.20210616120443-2a046c0bdbf2/hack/cross-binary (about)

     1  #!/usr/bin/env bash
     2  set -e
     3  
     4  if [ -z "$1" ]; then
     5      # Remove windows platform because of
     6      # https://github.com/mailgun/log/issues/10
     7      OS_PLATFORM_ARG=(linux windows darwin)
     8  else
     9      OS_PLATFORM_ARG=($1)
    10  fi
    11  
    12  if [ -z "$2" ]; then
    13      OS_ARCH_ARG=(386 amd64 arm)
    14  else
    15      OS_ARCH_ARG=($2)
    16  fi
    17  
    18  # Get rid of existing binaries
    19  rm -f bundles/libcompose-cli*
    20  
    21  BUILDTIME=$(date --rfc-3339 ns | sed -e 's/ /T/') &> /dev/null
    22  GITCOMMIT=$(git rev-parse --short HEAD)
    23  
    24  # Build binaries
    25  for OS in ${OS_PLATFORM_ARG[@]}; do
    26      for ARCH in ${OS_ARCH_ARG[@]}; do
    27          OUTPUT_BIN="bundles/libcompose-cli_$OS-$ARCH"
    28          if test "$ARCH" = "arm"; then
    29              if test "$OS" = "windows" || test "$OS" = "darwin"; then
    30                  # windows/arm and darwin/arm does not compile without cgo :-|
    31                  continue
    32              fi
    33          fi
    34          if test "$OS" = "windows"; then
    35              OUTPUT_BIN="${OUTPUT_BIN}.exe"
    36          fi
    37          echo "Building binary for $OS/$ARCH..."
    38          GOARCH=$ARCH GOOS=$OS CGO_ENABLED=0 go build \
    39                -ldflags="-w -X github.com/docker/libcompose/version.GITCOMMIT=${GITCOMMIT} -X github.com/docker/libcompose/version.BUILDTIME=${BUILDTIME} -X github.com/docker/libcompose/version.SHOWWARNING=${SHOWWARNING}" \
    40                -o ${OUTPUT_BIN} ./cli/main
    41      done
    42  done