Support buiding against Tcl/Tk 9

Tct/Tk 9 changes the name of the Tk library
Use tkConfig.sh for future-proofing
This commit is contained in:
Ivan Pozdeev 2025-10-08 22:25:14 +03:00
parent 8087e811cd
commit 08a23a13b0

View File

@ -1887,19 +1887,12 @@ use_homebrew_tcltk() {
for tcltk in ${PYTHON_BUILD_TCLTK_FORMULA:-tcl-tk@8 tcl-tk}; do
local tcltk_libdir="$(brew --prefix "${tcltk}" 2>/dev/null || true)"
if [ -d "$tcltk_libdir" ]; then
echo "python-build: use tcl-tk from homebrew"
local tcltk_version="$(sh -c '. '"$tcltk_libdir"'/lib/tclConfig.sh; echo $TCL_VERSION')"
local tcltk_includes tcltk_libs
echo "python-build: use ${PYTHON_BUILD_TCLTK_FORMULA} from homebrew"
# In Homebrew Tcl/Tk 8.6.13, headers have been moved to the 'tcl-tk' subdir.
# We're not using tclConfig.sh here 'cuz it produces the version-specific path to <brew prefix>/Cellar
# and we'd rather have rpath set to <brew prefix>/opt/<...> to allow micro release upgrades without rebuilding
# XXX: do use tclConfig.sh and translate the paths if more shenanigans appear in later releases
if [ -d "$tcltk_libdir/include/tcl-tk" ]; then
tcltk_includes="-I$tcltk_libdir/include/tcl-tk"
else
tcltk_includes="-I$tcltk_libdir/include"
fi
tcltk_libs="-L$tcltk_libdir/lib -ltcl$tcltk_version -ltk$tcltk_version"
local tcltk_includes="$(sh -c '. '"$tcltk_libdir"'/lib/tkConfig.sh; echo "$TCL_INCLUDE_SPEC $TK_INCLUDE_SPEC"')"
# Tcl/Tk is not keg-only so it's safe to use -L with Cellar path; rpath would be of Homebrew
# and would not break with version upgrades
local tcltk_libs="$(sh -c '. '"$tcltk_libdir"'/lib/tkConfig.sh; echo "$TCL_LIB_SPEC $TK_LIB_SPEC"')"
# Since 2.7.6, 3.3.3, 3.4.0 (Issue #1584): --with-tcltk-includes + --with-tcltk-libs Configure options
# Since 3.11.0 (bpo-45847): `pkg-config` call, TCLTK_CFLAGS + TCLTK_LIBS override
if [[ -n "$PYTHON_BUILD_TCLTK_USE_PKGCONFIG" ]]; then