Skip to content

Commit d202794

Browse files
authored
bpo-42603: Use pkg-config to get TCL/TK paths for tkinter. (GH-23721)
1 parent a8e2615 commit d202794

File tree

4 files changed

+61
-18
lines changed

4 files changed

+61
-18
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Make configure script use pkg-config to detect the location of Tcl/Tk
2+
headers and libraries, used to build tkinter.
3+
4+
On macOS, a Tcl/Tk configuration provided by pkg-config will be preferred
5+
over Tcl/Tk frameworks installed in ``/{System/,}Library/Frameworks``.
6+
If both exist and the latter is preferred, the appropriate
7+
``--with-tcltk-*`` configuration options need to be explicitly set.

configure

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10714,8 +10714,13 @@ then
1071410714
then
1071510715
as_fn_error $? "use both --with-tcltk-includes='...' and --with-tcltk-libs='...' or neither" "$LINENO" 5
1071610716
fi
10717-
TCLTK_INCLUDES=""
10718-
TCLTK_LIBS=""
10717+
if test -n "$PKG_CONFIG" && "$PKG_CONFIG" --exists tcl tk; then
10718+
TCLTK_INCLUDES="`"$PKG_CONFIG" tcl tk --cflags-only-I 2>/dev/null`"
10719+
TCLTK_LIBS="`"$PKG_CONFIG" tcl tk --libs 2>/dev/null`"
10720+
else
10721+
TCLTK_INCLUDES=""
10722+
TCLTK_LIBS=""
10723+
fi
1071910724
else
1072010725
TCLTK_INCLUDES="$with_tcltk_includes"
1072110726
TCLTK_LIBS="$with_tcltk_libs"

configure.ac

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,8 +3157,13 @@ then
31573157
then
31583158
AC_MSG_ERROR([use both --with-tcltk-includes='...' and --with-tcltk-libs='...' or neither])
31593159
fi
3160-
TCLTK_INCLUDES=""
3161-
TCLTK_LIBS=""
3160+
if test -n "$PKG_CONFIG" && "$PKG_CONFIG" --exists tcl tk; then
3161+
TCLTK_INCLUDES="`"$PKG_CONFIG" tcl tk --cflags-only-I 2>/dev/null`"
3162+
TCLTK_LIBS="`"$PKG_CONFIG" tcl tk --libs 2>/dev/null`"
3163+
else
3164+
TCLTK_INCLUDES=""
3165+
TCLTK_LIBS=""
3166+
fi
31623167
else
31633168
TCLTK_INCLUDES="$with_tcltk_includes"
31643169
TCLTK_LIBS="$with_tcltk_libs"

setup.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,18 +1879,34 @@ def detect_modules(self):
18791879
self.add(Extension('xxlimited', ['xxlimited.c']))
18801880
self.add(Extension('xxlimited_35', ['xxlimited_35.c']))
18811881

1882-
def detect_tkinter_explicitly(self):
1883-
# Build _tkinter using explicit locations for Tcl/Tk.
1882+
def detect_tkinter_fromenv(self):
1883+
# Build _tkinter using the Tcl/Tk locations specified by
1884+
# the _TCLTK_INCLUDES and _TCLTK_LIBS environment variables.
1885+
# This method is meant to be invoked by detect_tkinter().
18841886
#
1885-
# This is enabled when both arguments are given to ./configure:
1887+
# The variables can be set via one of the following ways.
18861888
#
1889+
# - Automatically, at configuration time, by using pkg-config.
1890+
# The tool is called by the configure script.
1891+
# Additional pkg-config configuration paths can be set via the
1892+
# PKG_CONFIG_PATH environment variable.
1893+
#
1894+
# PKG_CONFIG_PATH=".../lib/pkgconfig" ./configure ...
1895+
#
1896+
# - Explicitly, at configuration time by setting both
1897+
# --with-tcltk-includes and --with-tcltk-libs.
1898+
#
1899+
# ./configure ... \
18871900
# --with-tcltk-includes="-I/path/to/tclincludes \
18881901
# -I/path/to/tkincludes"
18891902
# --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
18901903
# -L/path/to/tklibs -ltkm.n"
18911904
#
1892-
# These values can also be specified or overridden via make:
1893-
# make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
1905+
# - Explicitly, at compile time, by passing TCLTK_INCLUDES and
1906+
# TCLTK_LIBS to the make target.
1907+
# This will override any configuration-time option.
1908+
#
1909+
# make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
18941910
#
18951911
# This can be useful for building and testing tkinter with multiple
18961912
# versions of Tcl/Tk. Note that a build of Tk depends on a particular
@@ -1914,6 +1930,7 @@ def detect_tkinter_explicitly(self):
19141930

19151931
def detect_tkinter_darwin(self):
19161932
# Build default _tkinter on macOS using Tcl and Tk frameworks.
1933+
# This method is meant to be invoked by detect_tkinter().
19171934
#
19181935
# The macOS native Tk (AKA Aqua Tk) and Tcl are most commonly
19191936
# built and installed as macOS framework bundles. However,
@@ -1932,16 +1949,20 @@ def detect_tkinter_darwin(self):
19321949
# search only the SDK's /Library/Frameworks (normally empty)
19331950
# and /System/Library/Frameworks.
19341951
#
1935-
# Any other use case should be able to be handled explicitly by
1936-
# using the options described above in detect_tkinter_explicitly().
1937-
# In particular it would be good to handle here the case where
1952+
# Any other use cases are handled either by detect_tkinter_fromenv(),
1953+
# or detect_tkinter(). The former handles non-standard locations of
1954+
# Tcl/Tk, defined via the _TCLTK_INCLUDES and _TCLTK_LIBS environment
1955+
# variables. The latter handles any Tcl/Tk versions installed in
1956+
# standard Unix directories.
1957+
#
1958+
# It would be desirable to also handle here the case where
19381959
# you want to build and link with a framework build of Tcl and Tk
19391960
# that is not in /Library/Frameworks, say, in your private
19401961
# $HOME/Library/Frameworks directory or elsewhere. It turns
19411962
# out to be difficult to make that work automatically here
19421963
# without bringing into play more tools and magic. That case
19431964
# can be handled using a recipe with the right arguments
1944-
# to detect_tkinter_explicitly().
1965+
# to detect_tkinter_fromenv().
19451966
#
19461967
# Note also that the fallback case here is to try to use the
19471968
# Apple-supplied Tcl and Tk frameworks in /System/Library but
@@ -2041,12 +2062,17 @@ def detect_tkinter_darwin(self):
20412062

20422063
def detect_tkinter(self):
20432064
# The _tkinter module.
2065+
#
2066+
# Detection of Tcl/Tk is attempted in the following order:
2067+
# - Through environment variables.
2068+
# - Platform specific detection of Tcl/Tk (currently only macOS).
2069+
# - Search of various standard Unix header/library paths.
2070+
#
2071+
# Detection stops at the first successful method.
20442072

2045-
# Check whether --with-tcltk-includes and --with-tcltk-libs were
2046-
# configured or passed into the make target. If so, use these values
2047-
# to build tkinter and bypass the searches for Tcl and TK in standard
2048-
# locations.
2049-
if self.detect_tkinter_explicitly():
2073+
# Check for Tcl and Tk at the locations indicated by _TCLTK_INCLUDES
2074+
# and _TCLTK_LIBS environment variables.
2075+
if self.detect_tkinter_fromenv():
20502076
return True
20512077

20522078
# Rather than complicate the code below, detecting and building

0 commit comments

Comments
 (0)