@@ -914,9 +914,11 @@ def query_tcltk():
914
914
def parse_tcl_config (tcl_lib_dir , tk_lib_dir ):
915
915
import Tkinter
916
916
tcl_poss = [tcl_lib_dir ,
917
+ os .path .normpath (os .path .join (tcl_lib_dir , '..' )),
917
918
"/usr/lib/tcl" + str (Tkinter .TclVersion ),
918
919
"/usr/lib" ]
919
920
tk_poss = [tk_lib_dir ,
921
+ os .path .normpath (os .path .join (tk_lib_dir , '..' )),
920
922
"/usr/lib/tk" + str (Tkinter .TkVersion ),
921
923
"/usr/lib" ]
922
924
for ptcl , ptk in zip (tcl_poss , tk_poss ):
@@ -927,52 +929,29 @@ def parse_tcl_config(tcl_lib_dir, tk_lib_dir):
927
929
if not (os .path .exists (tcl_config ) and os .path .exists (tk_config )):
928
930
return None
929
931
930
- # These files are shell scripts that set a bunch of
931
- # environment variables. To actually get at the
932
- # values, we use ConfigParser, which supports almost
933
- # the same format, but requires at least one section.
934
- # So, we push a "[default]" section to a copy of the
935
- # file in a StringIO object.
936
- try :
937
- tcl_vars_str = cStringIO .StringIO (
938
- "[default]\n " + open (tcl_config , "r" ).read ())
939
- tk_vars_str = cStringIO .StringIO (
940
- "[default]\n " + open (tk_config , "r" ).read ())
941
- except IOError :
942
- # if we can't read the file, that's ok, we'll try
943
- # to guess instead
944
- return None
945
-
946
- tcl_vars_str .seek (0 )
947
- tcl_vars = ConfigParser .RawConfigParser ()
948
- tk_vars_str .seek (0 )
949
- tk_vars = ConfigParser .RawConfigParser ()
950
- try :
951
- tcl_vars .readfp (tcl_vars_str )
952
- tk_vars .readfp (tk_vars_str )
953
- except ConfigParser .ParsingError :
954
- # if we can't read the file, that's ok, we'll try
955
- # to guess instead
956
- return None
957
-
958
- try :
959
- tcl_lib = tcl_vars .get ("default" , "TCL_LIB_SPEC" )[1 :- 1 ].split ()[0 ][2 :]
960
- tcl_inc = tcl_vars .get ("default" , "TCL_INCLUDE_SPEC" )[3 :- 1 ]
961
-
962
- tk_lib = tk_vars .get ("default" , "TK_LIB_SPEC" )[1 :- 1 ].split ()[0 ][2 :]
963
- if tk_vars .has_option ("default" , "TK_INCLUDE_SPEC" ):
964
- # On Ubuntu 8.04
965
- tk_inc = tk_vars .get ("default" , "TK_INCLUDE_SPEC" )[3 :- 1 ]
966
- else :
967
- # On RHEL4
968
- tk_inc = tcl_inc
969
- except (ConfigParser .NoSectionError , ConfigParser .NoOptionError ):
970
- return None
932
+ def get_var (file , varname ):
933
+ p = subprocess .Popen (
934
+ 'source %s ; eval echo ${%s}' % (file , varname ),
935
+ shell = True , stdout = subprocess .PIPE )
936
+ result = p .communicate ()[0 ]
937
+ return result
938
+
939
+ tcl_lib_dir = get_var (tcl_config , 'TCL_LIB_SPEC' ).split ()[0 ][2 :]
940
+ tcl_inc_dir = get_var (tcl_config , 'TCL_INCLUDE_SPEC' )[2 :]
941
+ tcl_lib = get_var (tcl_config , 'TCL_LIB_FLAG' )[2 :].strip ()
942
+
943
+ tk_lib_dir = get_var (tk_config , 'TK_LIB_SPEC' ).split ()[0 ][2 :]
944
+ tk_inc_dir = get_var (tk_config , 'TK_INCLUDE_SPEC' ).strip ()
945
+ if tk_inc_dir == '' :
946
+ tk_inc_dir = tcl_inc_dir
947
+ else :
948
+ tk_inc_dir = tk_inc_dir [2 :]
949
+ tk_lib = get_var (tk_config , 'TK_LIB_FLAG' )[2 :].strip ()
971
950
972
- if not os .path .exists (os .path .join (tk_inc , 'tk.h' )):
951
+ if not os .path .exists (os .path .join (tk_inc_dir , 'tk.h' )):
973
952
return None
974
953
975
- return tcl_lib , tcl_inc , tk_lib , tk_inc
954
+ return tcl_lib_dir , tcl_inc_dir , tcl_lib , tk_lib_dir , tk_inc_dir , tk_lib
976
955
977
956
def guess_tcl_config (tcl_lib_dir , tk_lib_dir , tk_ver ):
978
957
if not (os .path .exists (tcl_lib_dir ) and os .path .exists (tk_lib_dir )):
@@ -1007,14 +986,14 @@ def guess_tcl_config(tcl_lib_dir, tk_lib_dir, tk_ver):
1007
986
if not os .path .exists (os .path .join (tk_inc , 'tk.h' )):
1008
987
return None
1009
988
1010
- return tcl_lib , tcl_inc , tk_lib , tk_inc
989
+ return tcl_lib , tcl_inc , 'tcl' + tk_ver , tk_lib , tk_inc , 'tk' + tk_ver
1011
990
1012
991
def hardcoded_tcl_config ():
1013
992
tcl_inc = "/usr/local/include"
1014
993
tk_inc = "/usr/local/include"
1015
994
tcl_lib = "/usr/local/lib"
1016
995
tk_lib = "/usr/local/lib"
1017
- return tcl_lib , tcl_inc , tk_lib , tk_inc
996
+ return tcl_lib , tcl_inc , 'tcl' , tk_lib , tk_inc , 'tk'
1018
997
1019
998
def add_tk_flags (module ):
1020
999
'Add the module flags to build extensions which use tk'
@@ -1115,10 +1094,10 @@ def add_tk_flags(module):
1115
1094
result = hardcoded_tcl_config ()
1116
1095
1117
1096
# Add final versions of directories and libraries to module lists
1118
- tcl_lib , tcl_inc , tk_lib , tk_inc = result
1119
- module .include_dirs .extend ([tcl_inc , tk_inc ])
1120
- module .library_dirs .extend ([tcl_lib , tk_lib ])
1121
- module .libraries .extend (['tk' + tk_ver , 'tcl' + tk_ver ])
1097
+ tcl_lib_dir , tcl_inc_dir , tcl_lib , tk_lib_dir , tk_inc_dir , tk_lib = result
1098
+ module .include_dirs .extend ([tcl_inc_dir , tk_inc_dir ])
1099
+ module .library_dirs .extend ([tcl_lib_dir , tk_lib_dir ])
1100
+ module .libraries .extend ([tcl_lib , tk_lib ])
1122
1101
1123
1102
return message
1124
1103
0 commit comments