From 0427ff47360c2d169d95f8430bfb9d61a2f29950 Mon Sep 17 00:00:00 2001 From: nagai Date: Mon, 24 May 2004 08:33:45 +0000 Subject: * ext/tcltklib/extconf.rb: add --enable-tcl-thread configure option and --with-tclConfig-file= configure option git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tcltklib/README.1st | 14 ++++- ext/tcltklib/extconf.rb | 163 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 144 insertions(+), 33 deletions(-) (limited to 'ext/tcltklib') diff --git a/ext/tcltklib/README.1st b/ext/tcltklib/README.1st index 48e3a2b668..84a7826fdb 100644 --- a/ext/tcltklib/README.1st +++ b/ext/tcltklib/README.1st @@ -35,7 +35,19 @@ When your Tcl/Tk libraries are compiled with "pthread support", Ruby/Tk may cause "Hang-up" or "Segmentation Fault" frequently. If you have such a trouble, please try to use the '--enable-pthread' option of the 'configure' command and re-compile Ruby sources. -It may help you to avoid this trouble. +It may help you to avoid this trouble. The following configure +options may be useful. + + --enable-tcl-thread/--disable-tcl-thread + --with-tclConfig-file= + +It is not need that 'tclConfig.sh' is a normal Tcl/Tk's tclConfig.sh. +But the file is expected to include the line "TCL_THREADS=0" or "...=1". +When no "TCL_THREADS=?" line, if Tcl version is 7.x or 8.0 which is +given by "TCL_MAJOR_VERSION=?" line and "TCL_MINOR_VERSION=?" line, +then --disable-tcl-thread is expected. Else, ignore the 'tclConfig.sh'. +If --enable-tcl-thread or --disable-tcl-thread option is given, then +--with-tclConfig-file option is ignored. ========================================================== Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) diff --git a/ext/tcltklib/extconf.rb b/ext/tcltklib/extconf.rb index 6b2fcdd4ac..ac3c68e926 100644 --- a/ext/tcltklib/extconf.rb +++ b/ext/tcltklib/extconf.rb @@ -49,50 +49,112 @@ def find_tk(tklib, stubs) end end -if have_header("tcl.h") && have_header("tk.h") && - (is_win32 || find_library("X11", "XOpenDisplay", - "/usr/X11/lib", "/usr/lib/X11", "/usr/X11R6/lib", "/usr/openwin/lib")) && - find_tcl(tcllib, stubs) && - find_tk(tklib, stubs) - $CPPFLAGS += ' -DUSE_TCL_STUBS -DUSE_TK_STUBS' if stubs - $CPPFLAGS += ' -D_WIN32' if /cygwin/ =~ RUBY_PLATFORM - - pthread_enabled = macro_defined?('HAVE_LIBPTHREAD', '#include "ruby.h"') +def pthread_check() + tcl_major_ver = nil + tcl_minor_ver = nil - if try_run(< -static Tcl_ThreadDataKey dataKey; -int main() { exit((Tcl_GetThreadData(&dataKey, 1) == dataKey)? 1: 0); } -EOF + # Is tcl-thread given by user ? + case enable_config("tcl-thread") + when true tcl_enable_thread = true - else + when false tcl_enable_thread = false + else + tcl_enable_thread = nil end - unless pthread_enabled - if tcl_enable_thread - # ruby -> disable && tcl -> enable + if (tclConfig = with_config("tclConfig-file")) + if tcl_enable_thread == true + puts("Warning: --with-tclConfig-file option is ignored, because --enable-tcl-thread option is given.") + elsif tcl_enable_thread == false + puts("Warning: --with-tclConfig-file option is ignored, because --disable-tcl-thread option is given.") + else + # tcl-thread is unknown and tclConfig.sh is given + begin + open(tclConfig, "r") do |cfg| + while line = cfg.gets() + if line =~ /^\s*TCL_THREADS=(0|1)/ + tcl_enable_thread = ($1 == "1") + break + end + + if line =~ /^\s*TCL_MAJOR_VERSION=("|')(\d+)\1/ + tcl_major_ver = $2 + if tcl_major_ver =~ /^[1-7]$/ + tcl_enable_thread = false + break + end + if tcl_major_ver == "8" && tcl_minor_ver == "0" + tcl_enable_thread = false + break + end + end + + if line =~ /^\s*TCL_MINOR_VERSION=("|')(\d+)\1/ + tcl_minor_ver = $2 + if tcl_major_ver == "8" && tcl_minor_ver == "0" + tcl_enable_thread = false + break + end + end + end + end + + if tcl_enable_thread == nil + # not find definition + if tcl_major_ver + puts("Warning: '#{tclConfig}' doesn't include TCL_THREADS definition.") + else + puts("Warning: '#{tclConfig}' may not be a tclConfig file.") + end + tclConfig = false + end + rescue Exception + puts("Warning: fail to read '#{tclConfig}'!! --> ignore the file") + tclConfig = false + end + end + end + + if tcl_enable_thread == nil && !tclConfig + # tcl-thread is unknown and tclConfig is unavailable + begin + try_run_available = try_run("int main() { exit(0); }") + rescue Exception + # cannot try_run. Is CROSS-COMPILE environment? puts(%Q'\ ***************************************************************************** ** -** PTHREAD SUPPORT MODE ERRROR: +** PTHREAD SUPPORT CHECK WARNING: ** -** Ruby is not compiled with --enable-pthread, but your Tcl/Tk -** libararies seems to be compiled with "pthread support". This -** combination possibly cause "Hang-up" or "Segmentation Fault" -** frequently when Ruby/Tk is working. We NEVER recommend you to -** create the library under such combination of pthread support. -** -** Please recompile Ruby with "--enable-pthread" configure option -** or recompile Tcl/Tk with "--disable-threads" configure option. +** We cannot check the consistency of pthread support between Ruby +** and Tcl/Tk library on your environment (do coss-compile?). If the +** consistency is not kept, some memory troubles (e.g. "Hang-up" or +** "Segmentation Fault") may bother you. We strongly you to check the +** consistency by your own hand. ** ***************************************************************************** ') + return true + end + end + + if tcl_enable_thread == nil + # tcl-thread is unknown + if try_run(< +static Tcl_ThreadDataKey dataKey; +int main() { exit((Tcl_GetThreadData(&dataKey, 1) == dataKey)? 1: 0); } +EOF + tcl_enable_thread = true else - # ruby -> disable && tcl -> disable - create_makefile("tcltklib") + tcl_enable_thread = false end - else + end + + # check pthread mode + if (macro_defined?('HAVE_LIBPTHREAD', '#include "ruby.h"')) + # ruby -> enable unless tcl_enable_thread # ruby -> enable && tcl -> disable puts(%Q'\ @@ -110,13 +172,50 @@ EOF ** If you want change the status of pthread support, please recompile ** Ruby without "--enable-pthread" configure option or recompile Tcl/Tk ** with "--enable-threads" configure option (if your Tcl/Tk is later -** than Tcl/Tk8.1). +** than or equal to Tcl/Tk8.1). ** ***************************************************************************** ') end + # ruby -> enable && tcl -> enable/disable + return true - create_makefile("tcltklib") + else + # ruby -> disable + if tcl_enable_thread + # ruby -> disable && tcl -> enable + puts(%Q'\ +***************************************************************************** +** +** PTHREAD SUPPORT MODE ERRROR: +** +** Ruby is not compiled with --enable-pthread, but your Tcl/Tk +** libararies seems to be compiled with "pthread support". This +** combination possibly cause "Hang-up" or "Segmentation Fault" +** frequently when Ruby/Tk is working. We NEVER recommend you to +** create the library under such combination of pthread support. +** +** Please recompile Ruby with "--enable-pthread" configure option +** or recompile Tcl/Tk with "--disable-threads" configure option. +** +***************************************************************************** +') + return false + else + # ruby -> disable && tcl -> disable + return true + end end end + +if have_header("tcl.h") && have_header("tk.h") && + (is_win32 || find_library("X11", "XOpenDisplay", + "/usr/X11/lib", "/usr/lib/X11", "/usr/X11R6/lib", "/usr/openwin/lib")) && + find_tcl(tcllib, stubs) && + find_tk(tklib, stubs) + $CPPFLAGS += ' -DUSE_TCL_STUBS -DUSE_TK_STUBS' if stubs + $CPPFLAGS += ' -D_WIN32' if /cygwin/ =~ RUBY_PLATFORM + + create_makefile("tcltklib") if pthread_check +end -- cgit v1.2.3