github.com/Finschia/ostracon@v1.1.5/scripts/dist.sh (about)

     1  #!/usr/bin/env bash
     2  set -e
     3  
     4  # WARN: non hermetic build (people must run this script inside docker to
     5  # produce deterministic binaries).
     6  
     7  if [ -z "$VERSION" ]; then
     8  	echo "Please specify a version."
     9  	exit 1
    10  fi
    11  echo "==> Building version $VERSION..."
    12  
    13  # Delete the old dir
    14  echo "==> Removing old directory..."
    15  rm -rf build/pkg
    16  mkdir -p build/pkg
    17  
    18  GIT_IMPORT="github.com/Finschia/ostracon/version"
    19  
    20  # Determine the arch/os combos we're building for
    21  XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
    22  XC_OS=${XC_OS:-"solaris darwin freebsd linux windows"}
    23  XC_EXCLUDE=${XC_EXCLUDE:-" darwin/arm solaris/amd64 solaris/386 solaris/arm freebsd/amd64 windows/arm linux/arm "}
    24  
    25  # Make sure build tools are available.
    26  #make tools # XXX Should remove "make tools": https://github.com/Finschia/ostracon/commit/c6e0d20d4bf062921fcc1eb5b2399447a7d2226e#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52
    27  
    28  # Build!
    29  # ldflags: -s Omit the symbol table and debug information.
    30  #	         -w Omit the DWARF symbol table.
    31  echo "==> Building..."
    32  IFS=' ' read -ra arch_list <<< "$XC_ARCH"
    33  IFS=' ' read -ra os_list <<< "$XC_OS"
    34  for arch in "${arch_list[@]}"; do
    35  	for os in "${os_list[@]}"; do
    36  		if [[ "$XC_EXCLUDE" !=  *" $os/$arch "* ]]; then
    37  			echo "--> $os/$arch"
    38  			GOOS=${os} GOARCH=${arch} go build -ldflags "-s -w -X ${GIT_IMPORT}.OCCoreSemVer=${VERSION}" -tags="${BUILD_TAGS}" -o "build/pkg/${os}_${arch}/ostracon" ./cmd/ostracon
    39  		fi
    40  	done
    41  done
    42  
    43  # Zip all the files.
    44  echo "==> Packaging..."
    45  for PLATFORM in $(find ./build/pkg -mindepth 1 -maxdepth 1 -type d); do
    46  	OSARCH=$(basename "${PLATFORM}")
    47  	echo "--> ${OSARCH}"
    48  
    49  	pushd "$PLATFORM" >/dev/null 2>&1
    50  	zip "../${OSARCH}.zip" ./*
    51  	popd >/dev/null 2>&1
    52  done
    53  
    54  # Add "ostracon" and $VERSION prefix to package name.
    55  rm -rf ./build/dist
    56  mkdir -p ./build/dist
    57  for FILENAME in $(find ./build/pkg -mindepth 1 -maxdepth 1 -type f); do
    58  	FILENAME=$(basename "$FILENAME")
    59  	cp "./build/pkg/${FILENAME}" "./build/dist/ostracon_${VERSION}_${FILENAME}"
    60  done
    61  
    62  # Make the checksums.
    63  pushd ./build/dist
    64  shasum -a256 ./* > "./ostracon_${VERSION}_SHA256SUMS"
    65  popd
    66  
    67  # Done
    68  echo
    69  echo "==> Results:"
    70  ls -hl ./build/dist
    71  
    72  exit 0