Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
python, python3: fix Tk error.
Browse files Browse the repository at this point in the history
Fix RuntimeError: tk.h version (8.6) doesn't match libtk.a version (8.5)

The problem was that CPPFLAGS and LDFLAGS for brewed Tk were specified
to environment variable but Python (seems) prefer the CPPFLAGS in
arguments specified to './configure', mean
"-I#{MacOS.sdk_path}/usr/include" version is used.

Closes #18657.
Closes #41728.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
  • Loading branch information
lambdalisue authored and MikeMcQuaid committed Nov 24, 2015
1 parent f350e07 commit cff239a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
22 changes: 14 additions & 8 deletions Library/Formula/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,20 @@ def install

args << "--without-gcc" if ENV.compiler == :clang

cflags = []
ldflags = []
cppflags = []

unless MacOS::CLT.installed?
# Help Python's build system (setuptools/pip) to build things on Xcode-only systems
# The setup.py looks at "-isysroot" to get the sysroot (and not at --sysroot)
cflags = "CFLAGS=-isysroot #{MacOS.sdk_path}"
ldflags = "LDFLAGS=-isysroot #{MacOS.sdk_path}"
args << "CPPFLAGS=-I#{MacOS.sdk_path}/usr/include" # find zlib
cflags << "-isysroot #{MacOS.sdk_path}"
ldflags << "-isysroot #{MacOS.sdk_path}"
cppflags << "-I#{MacOS.sdk_path}/usr/include" # find zlib
# For the Xlib.h, Python needs this header dir with the system Tk
if build.without? "tcl-tk"
cflags += " -I#{MacOS.sdk_path}/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers"
cflags << "-I#{MacOS.sdk_path}/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers"
end
args << cflags
args << ldflags
end

# Avoid linking to libgcc https://code.activestate.com/lists/python-dev/112195/
Expand Down Expand Up @@ -157,10 +159,14 @@ def install

if build.with? "tcl-tk"
tcl_tk = Formula["homebrew/dupes/tcl-tk"].opt_prefix
ENV.append "CPPFLAGS", "-I#{tcl_tk}/include"
ENV.append "LDFLAGS", "-L#{tcl_tk}/lib"
cppflags << "-I#{tcl_tk}/include"
ldflags << "-L#{tcl_tk}/lib"
end

args << "CFLAGS=#{cflags.join(' ')}" unless cflags.empty?
args << "LDFLAGS=#{ldflags.join(' ')}" unless ldflags.empty?
args << "CPPFLAGS=#{cppflags.join(' ')}" unless cppflags.empty?

system "./configure", *args

# HAVE_POLL is "broken" on OS X. See:
Expand Down
23 changes: 15 additions & 8 deletions Library/Formula/python3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,20 @@ def install

args << "--without-gcc" if ENV.compiler == :clang

cflags = []
ldflags = []
cppflags = []

unless MacOS::CLT.installed?
# Help Python's build system (setuptools/pip) to build things on Xcode-only systems
# The setup.py looks at "-isysroot" to get the sysroot (and not at --sysroot)
cflags = "CFLAGS=-isysroot #{MacOS.sdk_path}"
ldflags = "LDFLAGS=-isysroot #{MacOS.sdk_path}"
args << "CPPFLAGS=-I#{MacOS.sdk_path}/usr/include" # find zlib
cflags << "-isysroot #{MacOS.sdk_path}"
ldflags << "-isysroot #{MacOS.sdk_path}"
cppflags << "-I#{MacOS.sdk_path}/usr/include" # find zlib
# For the Xlib.h, Python needs this header dir with the system Tk
if build.without? "tcl-tk"
cflags += " -I#{MacOS.sdk_path}/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers"
cflags << "-I#{MacOS.sdk_path}/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers"
end
args << cflags
args << ldflags
end
# Avoid linking to libgcc http://code.activestate.com/lists/python-dev/112195/
args << "MACOSX_DEPLOYMENT_TARGET=#{MacOS.version}"
Expand Down Expand Up @@ -150,10 +153,14 @@ def install

if build.with? "tcl-tk"
tcl_tk = Formula["tcl-tk"].opt_prefix
ENV.append "CPPFLAGS", "-I#{tcl_tk}/include"
ENV.append "LDFLAGS", "-L#{tcl_tk}/lib"
cppflags << "-I#{tcl_tk}/include"
ldflags << "-L#{tcl_tk}/lib"
end

args << "CFLAGS=#{cflags.join(' ')}" unless cflags.empty?
args << "LDFLAGS=#{ldflags.join(' ')}" unless ldflags.empty?
args << "CPPFLAGS=#{cppflags.join(' ')}" unless cppflags.empty?

system "./configure", *args

system "make"
Expand Down

0 comments on commit cff239a

Please sign in to comment.