diff options
Diffstat (limited to 'ext/tk/extconf.rb')
-rw-r--r-- | ext/tk/extconf.rb | 140 |
1 files changed, 110 insertions, 30 deletions
diff --git a/ext/tk/extconf.rb b/ext/tk/extconf.rb index 4311aecce0..4807ea7b40 100644 --- a/ext/tk/extconf.rb +++ b/ext/tk/extconf.rb @@ -48,15 +48,60 @@ tk_ldir2 = with_config("tk-lib") tcl_ldir2 = with_config("tcl-lib") x11_ldir2 = with_config("X11-lib") +tk_ldir_list = [tk_ldir2, tk_ldir] +tcl_ldir_list = [tcl_ldir2, tcl_ldir] + tklib = with_config("tklib") tcllib = with_config("tcllib") stubs = enable_config("tcltk_stubs") || with_config("tcltk_stubs") +tcltk_version = with_config("tcltkversion") + use_X = with_config("X11", (! is_win32)) -def find_tcl(tcllib, stubs, *opt_paths) +def check_tcltk_version(version) + return [nil, nil] unless version + + version = version.strip + + tclver = version.dup + tkver = version.dup + + major = dot = minor = dot = plvl = ext = nil + + if version =~ /^(\d)(\.?)(\d)(\.?)(\d*)(.*)$/ + major = $1; minor_dot = $2; minor = $3; plvl_dot = $4; plvl = $5; ext = $6 + dot = ! minor_dot.empty? + if plvl_dot.empty? && ! plvl.empty? + minor << plvl + end + elsif version =~ /^(\d)(\.?)(\d?)(.*)$/ + major = $1; minor_dot = $2; minor = $3; ext = $4 + dot = ! minor_dot.empty? + else # unknown -> believe user + return [tclver, tkver] + end + + # check Tcl7.6 / Tk4.2 ? + if major == "7" # Tcl7.6 ( not support Tclversion < 7.6 ) + # Tk4.2 + tkver = "4" + ((dot)? ".": "") + ((minor.empty)? "": "2") + ext + elsif major == "4" # Tk4.2 ( not support Tkversion < 4.2 ) + # Tcl7.6 + tclver = "7" + ((dot)? ".": "") + ((minor.empty)? "": "6") + ext + end + + [tclver, tkver] +end + +def find_tcl(tcllib, stubs, version, *opt_paths) default_paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"] - paths = opt_paths.compact.concat(default_paths) + default_paths << "/Tcl/lib" # default for ActiveTcl + + if (paths = opt_paths.compact).empty? + paths = default_paths + end + if stubs func = "Tcl_InitStubs" lib = "tclstub" @@ -64,25 +109,42 @@ def find_tcl(tcllib, stubs, *opt_paths) func = "Tcl_FindExecutable" lib = "tcl" end + + if version && ! version.empty? + versions = [version] + else + versions = %w[8.6 8.5 8.4 8.3 8.2 8.1 8.0 7.6] + end + if tcllib - find_library(tcllib, func, *paths) + st = find_library(tcllib, func, *paths) else - %w[8.6 8.5 8.4 8.3 8.2 8.1 8.0 7.6].find { |ver| - find_library("#{lib}#{ver}", func, *paths) or - find_library("#{lib}#{ver.delete('.')}", func, *paths) or - find_library("#{lib}#{ver}g", func, *paths) or - find_library("#{lib}#{ver.delete('.')}g", func, *paths) or - find_library("tcl#{ver}", func, *paths) or - find_library("tcl#{ver.delete('.')}", func, *paths) or - find_library("tcl#{ver}g", func, *paths) or - find_library("tcl#{ver.delete('.')}g", func, *paths) - } || find_library(lib, func, *paths) + st = versions.find { |ver| + find_library("#{lib}#{ver}", func, *paths) or + find_library("#{lib}#{ver.delete('.')}", func, *paths) or + find_library("#{lib}#{ver}g", func, *paths) or + find_library("#{lib}#{ver.delete('.')}g", func, *paths) or + find_library("tcl#{ver}", func, *paths) or + find_library("tcl#{ver.delete('.')}", func, *paths) or + find_library("tcl#{ver}g", func, *paths) or + find_library("tcl#{ver.delete('.')}g", func, *paths) + } || (!version && find_library(lib, func, *paths)) + end + + unless st + puts("Warning:: cannot find Tcl library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options.") end + st end -def find_tk(tklib, stubs, *opt_paths) +def find_tk(tklib, stubs, version, *opt_paths) default_paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"] - paths = opt_paths.compact.concat(default_paths) + default_paths << "/Tcl/lib" # default for ActiveTcl + + if (paths = opt_paths.compact).empty? + paths = default_paths + end + if stubs func = "Tk_InitStubs" lib = "tkstub" @@ -90,27 +152,43 @@ def find_tk(tklib, stubs, *opt_paths) func = "Tk_Init" lib = "tk" end + + if version && ! version.empty? + versions = [version] + else + versions = %w[8.6 8.5 8.4 8.3 8.2 8.1 8.0 4.2] + end + if tklib - find_library(tklib, func, *paths) + st = find_library(tklib, func, *paths) else - %w[8.6 8.5 8.4 8.3 8.2 8.1 8.0 4.2].find { |ver| - find_library("#{lib}#{ver}", func, *paths) or - find_library("#{lib}#{ver.delete('.')}", func, *paths) or - find_library("#{lib}#{ver}g", func, *paths) or - find_library("#{lib}#{ver.delete('.')}g", func, *paths) or - find_library("tk#{ver}", func, *paths) or - find_library("tk#{ver.delete('.')}", func, *paths) or - find_library("tk#{ver}g", func, *paths) or - find_library("tk#{ver.delete('.')}g", func, *paths) - } || find_library(lib, func, *paths) + st = versions.find { |ver| + find_library("#{lib}#{ver}", func, *paths) or + find_library("#{lib}#{ver.delete('.')}", func, *paths) or + find_library("#{lib}#{ver}g", func, *paths) or + find_library("#{lib}#{ver.delete('.')}g", func, *paths) or + find_library("tk#{ver}", func, *paths) or + find_library("tk#{ver.delete('.')}", func, *paths) or + find_library("tk#{ver}g", func, *paths) or + find_library("tk#{ver.delete('.')}g", func, *paths) + } || (!version && find_library(lib, func, *paths)) end + + unless st + puts("Warning:: cannot find Tk library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options.") + end + st end def find_X11(*opt_paths) default_paths = [ "/usr/X11/lib", "/usr/lib/X11", "/usr/X11R6/lib", "/usr/openwin/lib" ] paths = opt_paths.compact.concat(default_paths) - find_library("X11", "XOpenDisplay", *paths) + st = find_library("X11", "XOpenDisplay", *paths) + unless st + puts("Warning:: cannot find X11 library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options. If your Tcl/Tk don't require X11, please try --without-X11.") + end + st end def pthread_check() @@ -291,11 +369,13 @@ EOF end end -if have_header("tcl.h") && have_header("tk.h") && +tclver, tkver = check_tcltk_version(tcltk_version) + +if have_header("tcl.h") && have_header("tk.h") && ( tcltk_framework || ( ( !use_X || find_X11(x11_ldir2, x11_ldir) ) && - find_tcl(tcllib, stubs, tcl_ldir2, tcl_ldir) && - find_tk(tklib, stubs, tk_ldir2, tk_ldir) ) ) + find_tcl(tcllib, stubs, tclver, *tcl_ldir_list) && + find_tk(tklib, stubs, tkver, *tk_ldir_list) ) ) $CPPFLAGS += ' -DUSE_TCL_STUBS -DUSE_TK_STUBS' if stubs $CPPFLAGS += ' -D_WIN32' if /cygwin/ =~ RUBY_PLATFORM |