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,27 +49,140 @@ 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 +def pthread_check() + tcl_major_ver = nil + tcl_minor_ver = nil - pthread_enabled = macro_defined?('HAVE_LIBPTHREAD', '#include "ruby.h"') + # Is tcl-thread given by user ? + case enable_config("tcl-thread") + when true + tcl_enable_thread = true + when false + tcl_enable_thread = false + else + tcl_enable_thread = nil + end - if try_run(< 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 CHECK WARNING: +** +** 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 - tcl_enable_thread = false + tcl_enable_thread = true + else + tcl_enable_thread = false + end end - unless pthread_enabled + # check pthread mode + if (macro_defined?('HAVE_LIBPTHREAD', '#include "ruby.h"')) + # ruby -> enable + unless tcl_enable_thread + # ruby -> enable && tcl -> disable + puts(%Q'\ +***************************************************************************** +** +** PTHREAD SUPPORT MODE WARNING: +** +** Ruby is compiled with --enable-pthread, but your Tcl/Tk libraries +** seems to be compiled without "pthread support". Although You can +** create tcltklib library, this combination may cause memory trouble +** (e.g. "Hang-up" or "Segmentation Fault"). If you have no reason you +** must have to keep current pthread support status, we recommend you +** to make both or neither libraries to support pthread. +** +** 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 or equal to Tcl/Tk8.1). +** +***************************************************************************** +') + end + + # ruby -> enable && tcl -> enable/disable + return true + + else + # ruby -> disable if tcl_enable_thread # ruby -> disable && tcl -> enable puts(%Q'\ @@ -88,35 +201,21 @@ EOF ** ***************************************************************************** ') + return false else # ruby -> disable && tcl -> disable - create_makefile("tcltklib") + return true end - else - unless tcl_enable_thread - # ruby -> enable && tcl -> disable - puts(%Q'\ -***************************************************************************** -** -** PTHREAD SUPPORT MODE WARNING: -** -** Ruby is compiled with --enable-pthread, but your Tcl/Tk libraries -** seems to be compiled without "pthread support". Although You can -** create tcltklib library, this combination may cause memory trouble -** (e.g. "Hang-up" or "Segmentation Fault"). If you have no reason you -** must have to keep current pthread support status, we recommend you -** to make both or neither libraries to support pthread. -** -** 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). -** -***************************************************************************** -') - end - # ruby -> enable && tcl -> enable/disable - - create_makefile("tcltklib") 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