# TODO: Not tested
[source]
tar = "https://www.python.org/ftp/python/3.15.0/Python-3.15.0a8.tar.xz"
blake3 = "b1e24434fc15b352b07222e44e6ff12ce14bbbe8535928a13123ee6a49fa6541"
patches = [
    "redox.patch"
]

[build]
template = "custom"
dependencies = [
    "target:bzip2",
    "target:libffi",
    "target:openssl3",
    "target:ncursesw",
    "target:readline",
    "target:sqlite3",
    "target:zlib",
    "target:xz",
    "target:zstd",
]
dev-dependencies = [
    "host:python315"
]
script = """
DYNAMIC_INIT

export PYTHONDONTWRITEBYTECODE=1
ARCH="${TARGET%%-*}"
OS=$(echo "${TARGET}" | cut -d - -f3-4)

if [ "$TARGET" != "$COOKBOOK_HOST_TARGET" ]; then
    COOKBOOK_CONFIGURE_FLAGS=(
        --prefix=/usr
        --disable-ipv6
        --host=${GNU_TARGET}
        --build="$ARCH"
        --with-build-python="${COOKBOOK_TOOLCHAIN}/usr/bin/python3.15"
        --with-ensurepip=install
        --disable-test-modules
        --with-ssl-default-suites=openssl
        ac_cv_file__dev_ptmx=no
        ac_cv_file__dev_ptc=no
    )
else
    COOKBOOK_CONFIGURE_FLAGS=(--prefix=/usr)
fi

if [ "${COOKBOOK_DYNAMIC}" != "1" ]; then
    export MODULE_BUILDTYPE=static
    COOKBOOK_CONFIGURE_FLAGS+=( --enable-shared )
fi

cookbook_configure

# A same file to save 73MB
(cd "${COOKBOOK_STAGE}/usr/lib/python3.15/config-3.15" && \
    rm -f libpython3.15.a && ln -s ../../libpython3.15.a)
"""

[[optional-packages]]
name = "dev"
files = [
    "usr/lib/python3.15/config-*/**",
    "usr/lib/libpython*.a"
]
