#!/usr/bin/env bash
set -euo pipefail

# 此脚本用于 binutils-gdb 在host是windows系统的时候 使用的  单独添加选项 --with-python=/ae/sysroots/mingw64/python_gdb.bash 即可使用
# C:\msys64
# C:\msys64\var\cache\pacman\pkg 存放下载安装好的mingw包
# C:\msys64\mingw64 是系统根目录

root="/ae/sysroots/mingw64"
lib="${root}/lib"
include="${root}/include"

case "${2:-${1:-}}" in
--includes|--cflags)
  printf '%s\n' "-I${include}/python3.12"
  ;;
--ldflags|--libs)
  if [ -f "${lib}/libpython3.12.dll.a" ]; then
    printf '%s\n' "${lib}/libpython3.12.dll.a"
  elif [ -f "${lib}/libpython3.dll.a" ]; then
    printf '%s\n' "${lib}/libpython3.dll.a"
  elif [ -f "${lib}/libpython3.12.a" ]; then
    printf '%s\n' "${lib}/libpython3.12.a"
  elif [ -f "${lib}/libpython3.a" ]; then
    printf '%s\n' "${lib}/libpython3.a"
  else
    echo "no usable libpython found in ${lib}" >&2
    exit 1
  fi
  ;;
--exec-prefix)
  printf '%s\n' "${root}"
  ;;
*)
  echo "unsupported args: $*" >&2
  exit 1
  ;;
esac

