#!/usr/bin/env modbuild

pbuild::prep() { :; }

pbuild::configure() { :; }

pbuild::compile() { :; }

pbuild::install() {
    # BUSTER is licence-gated: the Global Phasing snapshot cannot be wget'd
    # (download needs credentials), so stage it in this module dir first as
    # BUSTER_snapshot_<snapshot-date>.tar.gz (gitignored), then unpack into $PREFIX.
    # V_PKG (not V) so rebuilds as <date>-2, <date>-3 reuse the same staged tarball.
    mkdir -p "${PREFIX}"
    cd "${PREFIX}"
    tar -xf "${BUILDBLOCK_DIR}/BUSTER_snapshot_${V_PKG}.tar.gz" --strip-components=1 || \
        std::die 42 "BUSTER: untar failed - is BUSTER_snapshot_${V_PKG}.tar.gz staged in ${BUILDBLOCK_DIR}?"

    # PSI licence token at the software home ($BDG_home) activates the suite
    cp "${BUILDBLOCK_DIR}/.licence" "${PREFIX}/.licence" || \
        std::die 42 "BUSTER: .licence token missing from module dir"

    # GPhL configure step (doc section 6): no CSD-Core on Ra, so Grade2 and
    # buster-report Mogul validation are disabled. Point BDG_CSD_TOP_DIRECTORY
    # at a CCDC install top dir (contains ccdc-software/) if one ever arrives.
    # The unset clears obsolete pre-May-2024 CSD variables per the doc.
    cat > "${PREFIX}/setup_local.sh" <<'EOF'
export BDG_CSD_TOP_DIRECTORY=none
unset BDG_TOOL_MOGUL CSD_HOME BDG_TOOL_CSD_PYTHON_API
EOF

    [[ -r "${PREFIX}/setup.sh" ]] || \
        std::die 42 "BUSTER: setup.sh missing at PREFIX root - check tarball layout / strip level"
}
