#!/usr/bin/env modbuild

# Prebuilt single binary from adxv.scripps.edu (CentOS7 build, runs on RHEL8;
# needs system Motif/X11 libs at runtime). Default pbuild::prep downloads +
# sha-verifies + copies it into SRC_DIR (unpacker: none).

pbuild::pre_prep() {
    # adxv.scripps.edu serves an incomplete cert chain -> Ra's curl fails verify
    # ("unable to get local issuer certificate"). Fetch with --insecure into the
    # distfiles cache; integrity comes from the pinned sha256 in config.yaml,
    # which the default prep still enforces. On sha mismatch: rm this file, re-run.
    local -r f="${PMODULES_DISTFILESDIR}/adxv-${V_PKG}.x86_64CentOS7"
    [[ -s "$f" ]] && return 0
    mkdir -p "${PMODULES_DISTFILESDIR}"
    curl --insecure --location --fail -o "$f" \
        "https://adxv.scripps.edu/adxv/adxv_${V_PKG}/adxv.x86_64CentOS7" || \
        std::die 42 "adxv: download failed - pre-stage the binary by hand at $f"
}

pbuild::configure() {
    :
}

pbuild::compile() {
    :
}

pbuild::install() {
    mkdir -p "$PREFIX/bin"
    install -m 755 "$SRC_DIR/adxv-${V_PKG}.x86_64CentOS7" "$PREFIX/bin/adxv" || \
        std::die 42 "adxv binary missing from SRC_DIR - download failed?"
}
