|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Exit on undefined variable and error. |
| 4 | +set -u -e -o pipefail |
| 5 | + |
| 6 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" |
| 7 | +WORK_DIR="${PWD}" |
| 8 | +DOWNLOAD_DIR="${WORK_DIR}/download_cache" |
| 9 | + |
| 10 | +# This should match the SAIGOSDK_VERSION in CMakeLists.txt. |
| 11 | +# This is mostly to ensure the path the files end up at if you build deps yourself |
| 12 | +# are the same as the ones when extracting from the downloaded packages. |
| 13 | +SAIGOSDK_VERSION=20261030 |
| 14 | +# Can be a tag like v${SAIGOSDK_VERSION}, or a full commit hash |
| 15 | +SAIGOSDK_REF="v${SAIGOSDK_VERSION}" |
| 16 | + |
| 17 | +REPO_BASENAME=saigo-nacl-sdk |
| 18 | +REPO_URL="https://github.com/DaemonEngine/${REPO_BASENAME}" |
| 19 | +ARCHIVE_PATH="${DOWNLOAD_DIR}/saigosdk-${SAIGOSDK_REF}.tar.gz" |
| 20 | + |
| 21 | +usage() { |
| 22 | + cat <<-EOF |
| 23 | + Usage: $0 <os>-<arch> (build | install | package | wipe)... |
| 24 | + <os>-<arch> should normally be your current native platform. |
| 25 | + For a list of supported platforms see ${REPO_URL}/tree/master/tools/release/conf |
| 26 | + Actions: |
| 27 | + build - build all tools and libraries in the SDK |
| 28 | + install - install final build products to ${WORK_DIR}/saigosdk-<os>-<arch>_${SAIGOSDK_VERSION}/ |
| 29 | + wipe - delete build products (except download cache) AND install directory |
| 30 | + If you want to build only a subset of packages, prefer using the |
| 31 | + ${REPO_URL} CMake build directly. |
| 32 | + Some global configuration options are available via environment |
| 33 | + variables; see ${REPO_URL}/tree/master/tools/release/build |
| 34 | + EOF |
| 35 | +} |
| 36 | + |
| 37 | +download() { |
| 38 | + test -f "${ARCHIVE_PATH}" && return |
| 39 | + mkdir -p "${DOWNLOAD_DIR}" |
| 40 | + curl --fail -L "${DOWNLOAD_URL}" -o "${ARCHIVE_PATH}" |
| 41 | +} |
| 42 | + |
| 43 | +if [ "$#" -lt 2 ] |
| 44 | +then |
| 45 | + usage |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | + |
| 49 | +PLATFORM="$1" |
| 50 | +shift |
| 51 | + |
| 52 | +if grep -q -E '^[0-9a-f]{40}$' <<< "${SAIGOSDK_REF}" |
| 53 | +then |
| 54 | + DOWNLOAD_URL="https://github.com/DaemonEngine/saigo-nacl-sdk/archive/${SAIGOSDK_REF}.tar.gz" |
| 55 | + TARBALL_OUTER_DIR="${REPO_BASENAME}-${SAIGOSDK_REF}" |
| 56 | +elif grep -q -E '^v[0-9]' <<< "${SAIGOSDK_REF}" |
| 57 | +then |
| 58 | + # The 'v' from the tag name is mysteriously removed??? |
| 59 | + TARBALL_OUTER_DIR="${REPO_BASENAME}-${SAIGOSDK_REF:1}" |
| 60 | + DOWNLOAD_URL="https://github.com/DaemonEngine/saigo-nacl-sdk/archive/refs/tags/${SAIGOSDK_REF}.tar.gz" |
| 61 | +fi |
| 62 | + |
| 63 | +INSTALL_DIR="${WORK_DIR}/saigosdk-${PLATFORM}_${SAIGOSDK_VERSION}" |
| 64 | +BUILD_DIR="${WORK_DIR}/build-saigosdk_${SAIGOSDK_VERSION}" |
| 65 | +REPO_DIR="${BUILD_DIR}/${TARBALL_OUTER_DIR}" |
| 66 | + |
| 67 | +for target in "$@" |
| 68 | +do |
| 69 | + case "${target}" in |
| 70 | + build) |
| 71 | + download |
| 72 | + mkdir -p "${BUILD_DIR}" |
| 73 | + tar xzf "${ARCHIVE_PATH}" -C "${BUILD_DIR}" |
| 74 | + ( |
| 75 | + cd "${REPO_DIR}" |
| 76 | + tools/release/build "${PLATFORM}" |
| 77 | + ) |
| 78 | + ;; |
| 79 | + install) |
| 80 | + cp -R "${REPO_DIR}/build/${PLATFORM}/install/." "${INSTALL_DIR}/" |
| 81 | + ;; |
| 82 | + wipe) |
| 83 | + rm -rf "${BUILD_DIR}" "${INSTALL_DIR}" |
| 84 | + ;; |
| 85 | + *) |
| 86 | + usage |
| 87 | + exit 1 |
| 88 | + ;; |
| 89 | + esac |
| 90 | +done |
0 commit comments