|
| 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=20260925 |
| 14 | +# Can be a tag like v${SAIGOSDK_VERSION}, or a full commit hash |
| 15 | +SAIGOSDK_REF=cbd46205f43ed956382f6bcd88e51ccd9aeb12ee |
| 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 | + echo "Usage: $0 <os>-<arch> (build | install | package | wipe)..." |
| 23 | + echo "<os>-<arch> should normally be your current native platform." |
| 24 | + echo "For a list of supported platforms see ${REPO_URL}/tree/master/tools/release/conf" |
| 25 | + echo "Actions:" |
| 26 | + echo " build - build all tools and libraries in the SDK" |
| 27 | + echo " install - install final build products to ${WORK_DIR}/saigosdk-<os>-<arch>_${SAIGOSDK_VERSION}/" |
| 28 | + echo " wipe - delete build products (except download cache) AND install directory" |
| 29 | + echo "If you want to build only a subset of packages, prefer using the" |
| 30 | + echo "${REPO_URL} CMake build directly." |
| 31 | + echo "Some global configuration options are available via environment" |
| 32 | + echo "variables; see ${REPO_URL}/tree/master/tools/release/build" |
| 33 | +} |
| 34 | + |
| 35 | +download() { |
| 36 | + test -f "${ARCHIVE_PATH}" && return |
| 37 | + mkdir -p "${DOWNLOAD_DIR}" |
| 38 | + if grep -q -E '^[0-9a-f]{40}$' <<< "${SAIGOSDK_REF}" |
| 39 | + then |
| 40 | + DOWNLOAD_URL="https://github.com/DaemonEngine/saigo-nacl-sdk/archive/${SAIGOSDK_REF}.tar.gz" |
| 41 | + elif grep -q -E '^v[0-9]' <<< "${SAIGOSDK_REF}" |
| 42 | + then |
| 43 | + DOWNLOAD_URL="https://github.com/DaemonEngine/saigo-nacl-sdk/archive/refs/tags/${SAIGOSDK_REF}.tar.gz" |
| 44 | + fi |
| 45 | + curl --fail -L "${DOWNLOAD_URL}" -o "${ARCHIVE_PATH}" |
| 46 | +} |
| 47 | + |
| 48 | +if [ "$#" -lt 2 ] |
| 49 | +then |
| 50 | + usage |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | + |
| 54 | +PLATFORM="$1" |
| 55 | +shift |
| 56 | + |
| 57 | +INSTALL_DIR="${WORK_DIR}/saigosdk-${PLATFORM}_${SAIGOSDK_VERSION}" |
| 58 | +BUILD_DIR="${WORK_DIR}/build-saigosdk_${SAIGOSDK_VERSION}" |
| 59 | +REPO_DIR="${BUILD_DIR}/${REPO_BASENAME}-${SAIGOSDK_REF}" # stupid wrapping directory in the tarball... |
| 60 | + |
| 61 | +for target in "$@" |
| 62 | +do |
| 63 | + case "${target}" in |
| 64 | + build) |
| 65 | + download |
| 66 | + mkdir -p "${BUILD_DIR}" |
| 67 | + tar xzf "${ARCHIVE_PATH}" -C "${BUILD_DIR}" |
| 68 | + ( |
| 69 | + cd "${REPO_DIR}" |
| 70 | + tools/release/build "${PLATFORM}" |
| 71 | + ) |
| 72 | + ;; |
| 73 | + install) |
| 74 | + cp -R "${REPO_DIR}/build/${PLATFORM}/install/." "${INSTALL_DIR}/" |
| 75 | + ;; |
| 76 | + wipe) |
| 77 | + rm -rf "${BUILD_DIR}" "${INSTALL_DIR}" |
| 78 | + ;; |
| 79 | + *) |
| 80 | + usage |
| 81 | + exit 1 |
| 82 | + ;; |
| 83 | + esac |
| 84 | +done |
0 commit comments