#!/bin/bash
# Build script for Mercurial (CPython application).
# Builds against the `python` zport; installs /usr/local/bin/hg.

set -e
cd "$SRCDIR"

PYTHON="$PREFIX/bin/python3"

# Mercurial's setup.py imports setuptools_scm (only needed for VCS/dev builds);
# a release tarball has __version__ baked in. Patch out the import.
sed -i 's/import setuptools_scm/setuptools_scm = None  # release tarball/' setup.py

# setup.py needs setuptools — Python 3.13's ensurepip ships pip only. pip works
# against the base OpenSSL 3.5, so fetch setuptools from PyPI over HTTPS.
"$PYTHON" -m pip install --quiet setuptools

# Build + install the C extensions and pure-Python modules; hg gets an
# absolute #!$PREFIX/bin/python3 shebang.
"$PYTHON" setup.py build
"$PYTHON" setup.py install --prefix="$PREFIX" --root="$PKGDIR"
