# python-build definition for prebuilt Python 3.14.7-ubuntu-24.04-x86_64 (Linux/x86_64, ubuntu 24.04).
# Generated by `pyenv binary generate-installer'.

EXPECT_OS=Linux
EXPECT_ARCH=x86_64
EXPECT_LIBC=glibc\ 2.39
BUILD_PREFIX=/home/runner/work/pyenv/pyenv/versions/3.14.7-ubuntu-24.04-x86_64
VERSION=3.14.7-ubuntu-24.04-x86_64
ARCHIVE_URL=https://pyenv.github.io/pythons/binaries/3.14.7-ubuntu-24.04-x86_64.tar.xz
SHA256=b4339308c1cac158dc5d8ecd4af5ced7cd9f7ef7b121a5249788551061b778a1
DEPS=libbz2.so.1.0\ libc.so.6\ libcrypto.so.3\ libffi.so.8\ liblzma.so.5\ libm.so.6\ libncursesw.so.6\ libpanelw.so.6\ libreadline.so.8\ libsqlite3.so.0\ libssl.so.3\ libtcl8.6.so\ libtinfo.so.6\ libtk8.6.so\ libuuid.so.1\ libz.so.1\ libzstd.so.1

os="$(uname -s)"
arch="$(uname -m)"
if [ "$os" != "$EXPECT_OS" ] || [ "$arch" != "$EXPECT_ARCH" ]; then
  echo "pyenv-binary: this archive is for ${EXPECT_OS}/${EXPECT_ARCH}, not ${os}/${arch}" >&2
  exit 1
fi

# Refuse a target whose glibc is older than the one the archive was built on;
# the dynamic loader would reject the binaries.
case "$EXPECT_LIBC" in
"glibc "* )
  build_libc="${EXPECT_LIBC#glibc }"
  target_libc="$(getconf GNU_LIBC_VERSION 2>/dev/null || true)"
  case "$target_libc" in
  "glibc "* )
    target_libc="${target_libc#glibc }"
    older="$(printf '%s\n%s\n' "$build_libc" "$target_libc" | sort -V | head -n1)"
    if [ "$older" = "$target_libc" ] && [ "$target_libc" != "$build_libc" ]; then
      echo "pyenv-binary: archive needs glibc ${build_libc} or newer, but this system has ${target_libc}" >&2
      exit 1
    fi
    ;;
  esac
  ;;
esac

# Required system libraries must already be present on the target. Linux lists
# the soname first; FreeBSD lists it in the resolved path, so normalize that
# path before matching exact names.
cache=""
if command -v ldconfig &>/dev/null; then
  case "$os" in
  FreeBSD )
    cache="$(ldconfig -r 2>/dev/null)" &&
      cache="$(printf '%s\n' "$cache" | awk -F ' *=> *' '{ sub(/^.*\//, "", $2); print $2 }')" \
      || cache=""
    ;;
  * )
    cache="$(ldconfig -p 2>/dev/null)" || cache=""
    ;;
  esac
fi
if [ -n "$cache" ]; then
  missing=""
  for dep in $DEPS; do
    printf '%s\n' "$cache" | awk -v d="$dep" '$1 == d { found = 1 } END { exit !found }' \
      || missing="${missing} ${dep}"
  done
  if [ -n "$missing" ]; then
    echo "pyenv-binary: missing required system libraries:${missing}" >&2
    exit 1
  fi
elif [ -n "$DEPS" ]; then
  echo "pyenv-binary: cannot check required system libraries (ldconfig cache unavailable)" >&2
fi

case "$os" in
Darwin )
  for tool in otool install_name_tool; do
    if ! command -v "$tool" >/dev/null 2>&1; then
      echo "pyenv-binary: need ${tool} to relocate the binary" >&2
      exit 1
    fi
  done
  ;;
* )
  if ! command -v patchelf >/dev/null 2>&1; then
    echo "pyenv-binary: need patchelf to relocate the binary" >&2
    exit 1
  fi
  ;;
esac

build_package_relocate() {
  if [ "$os" = "Darwin" ]; then
    pyenv binary relocate "$PREFIX_PATH" "$BUILD_PREFIX"
  else
    pyenv binary relocate "$PREFIX_PATH"
  fi
}

install_package "Python-${VERSION}-binary" "${ARCHIVE_URL}#${SHA256}" copy relocate

