5555 'linux2-mips' : ['/usr/local' , '/usr' ],
5656 'linux2-sparc' : ['/usr/local' , '/usr' ],
5757 'linux2' : ['/usr/local' , '/usr' ],
58+ 'linux3' : ['/usr/local' , '/usr' ],
5859 'linux' : ['/usr/local' , '/usr' ,],
5960 'cygwin' : ['/usr/local' , '/usr' ,],
6061 '_darwin' : ['/sw/lib/freetype2' , '/sw/lib/freetype219' , '/usr/local' ,
@@ -834,9 +835,11 @@ def query_tcltk():
834835def parse_tcl_config (tcl_lib_dir , tk_lib_dir ):
835836 import Tkinter
836837 tcl_poss = [tcl_lib_dir ,
838+ os .path .normpath (os .path .join (tcl_lib_dir , '..' )),
837839 "/usr/lib/tcl" + str (Tkinter .TclVersion ),
838840 "/usr/lib" ]
839841 tk_poss = [tk_lib_dir ,
842+ os .path .normpath (os .path .join (tk_lib_dir , '..' )),
840843 "/usr/lib/tk" + str (Tkinter .TkVersion ),
841844 "/usr/lib" ]
842845 for ptcl , ptk in zip (tcl_poss , tk_poss ):
@@ -847,50 +850,31 @@ def parse_tcl_config(tcl_lib_dir, tk_lib_dir):
847850 if not (os .path .exists (tcl_config ) and os .path .exists (tk_config )):
848851 return None
849852
850- # These files are shell scripts that set a bunch of
851- # environment variables. To actually get at the
852- # values, we use ConfigParser, which supports almost
853- # the same format, but requires at least one section.
854- # So, we push a "[default]" section to a copy of the
855- # file in a StringIO object.
856- try :
857- tcl_vars_str = StringIO ("[default]\n " + open (tcl_config , "r" ).read ())
858- tk_vars_str = StringIO ("[default]\n " + open (tk_config , "r" ).read ())
859- except IOError :
860- # if we can't read the file, that's ok, we'll try
861- # to guess instead
862- return None
863-
864- tcl_vars_str .seek (0 )
865- tcl_vars = configparser .RawConfigParser ()
866- tk_vars_str .seek (0 )
867- tk_vars = configparser .RawConfigParser ()
868- try :
869- tcl_vars .readfp (tcl_vars_str )
870- tk_vars .readfp (tk_vars_str )
871- except configparser .ParsingError :
872- # if we can't read the file, that's ok, we'll try
873- # to guess instead
874- return None
875-
876- try :
877- tcl_lib = tcl_vars .get ("default" , "TCL_LIB_SPEC" )[1 :- 1 ].split ()[0 ][2 :]
878- tcl_inc = tcl_vars .get ("default" , "TCL_INCLUDE_SPEC" )[3 :- 1 ]
879-
880- tk_lib = tk_vars .get ("default" , "TK_LIB_SPEC" )[1 :- 1 ].split ()[0 ][2 :]
881- if tk_vars .has_option ("default" , "TK_INCLUDE_SPEC" ):
882- # On Ubuntu 8.04
883- tk_inc = tk_vars .get ("default" , "TK_INCLUDE_SPEC" )[3 :- 1 ]
884- else :
885- # On RHEL4
886- tk_inc = tcl_inc
887- except (configparser .NoSectionError , configparser .NoOptionError ):
888- return None
853+ def get_var (file , varname ):
854+ p = subprocess .Popen (
855+ '. %s ; eval echo ${%s}' % (file , varname ),
856+ shell = True ,
857+ executable = "/bin/sh" ,
858+ stdout = subprocess .PIPE )
859+ result = p .communicate ()[0 ]
860+ return result
861+
862+ tcl_lib_dir = get_var (tcl_config , 'TCL_LIB_SPEC' ).split ()[0 ][2 :]
863+ tcl_inc_dir = get_var (tcl_config , 'TCL_INCLUDE_SPEC' )[2 :]
864+ tcl_lib = get_var (tcl_config , 'TCL_LIB_FLAG' )[2 :].strip ()
865+
866+ tk_lib_dir = get_var (tk_config , 'TK_LIB_SPEC' ).split ()[0 ][2 :]
867+ tk_inc_dir = get_var (tk_config , 'TK_INCLUDE_SPEC' ).strip ()
868+ if tk_inc_dir == '' :
869+ tk_inc_dir = tcl_inc_dir
870+ else :
871+ tk_inc_dir = tk_inc_dir [2 :]
872+ tk_lib = get_var (tk_config , 'TK_LIB_FLAG' )[2 :].strip ()
889873
890- if not os .path .exists (os .path .join (tk_inc , 'tk.h' )):
874+ if not os .path .exists (os .path .join (tk_inc_dir , 'tk.h' )):
891875 return None
892876
893- return tcl_lib , tcl_inc , tk_lib , tk_inc
877+ return tcl_lib_dir , tcl_inc_dir , tcl_lib , tk_lib_dir , tk_inc_dir , tk_lib
894878
895879def guess_tcl_config (tcl_lib_dir , tk_lib_dir , tk_ver ):
896880 if not (os .path .exists (tcl_lib_dir ) and os .path .exists (tk_lib_dir )):
@@ -925,14 +909,14 @@ def guess_tcl_config(tcl_lib_dir, tk_lib_dir, tk_ver):
925909 if not os .path .exists (os .path .join (tk_inc , 'tk.h' )):
926910 return None
927911
928- return tcl_lib , tcl_inc , tk_lib , tk_inc
912+ return tcl_lib , tcl_inc , 'tcl' + tk_ver , tk_lib , tk_inc , 'tk' + tk_ver
929913
930914def hardcoded_tcl_config ():
931915 tcl_inc = "/usr/local/include"
932916 tk_inc = "/usr/local/include"
933917 tcl_lib = "/usr/local/lib"
934918 tk_lib = "/usr/local/lib"
935- return tcl_lib , tcl_inc , tk_lib , tk_inc
919+ return tcl_lib , tcl_inc , 'tcl' , tk_lib , tk_inc , 'tk'
936920
937921def add_tk_flags (module ):
938922 'Add the module flags to build extensions which use tk'
@@ -1033,10 +1017,10 @@ def add_tk_flags(module):
10331017 result = hardcoded_tcl_config ()
10341018
10351019 # Add final versions of directories and libraries to module lists
1036- tcl_lib , tcl_inc , tk_lib , tk_inc = result
1037- module .include_dirs .extend ([tcl_inc , tk_inc ])
1038- module .library_dirs .extend ([tcl_lib , tk_lib ])
1039- module .libraries .extend (['tk' + tk_ver , 'tcl' + tk_ver ])
1020+ tcl_lib_dir , tcl_inc_dir , tcl_lib , tk_lib_dir , tk_inc_dir , tk_lib = result
1021+ module .include_dirs .extend ([tcl_inc_dir , tk_inc_dir ])
1022+ module .library_dirs .extend ([tcl_lib_dir , tk_lib_dir ])
1023+ module .libraries .extend ([tcl_lib , tk_lib ])
10401024
10411025 return message
10421026
0 commit comments