永井@知能.九工大です.

From: WATANABE Hirofumi <eban / os.rim.or.jp>
Subject: [ruby-dev:23576] Re: try_run in ext/tcltklib/extconf.rb
Date: Sun, 23 May 2004 14:30:08 +0900
Message-ID: <20040523143006.158139.eban / os.rim.or.jp>
> ええと、To: ebanは必要ないです。

ごめんなさい.
返信時にメーラが勝手に付けてしまうのを度々消し忘れてしまうんです.

# 「メーラの設定を調整しろ!」というのはもっともなのですが.;^_^;

> これに近いです。チェックはしないで外から指定できるだけでいい
> と思います。
> 
> --enable-tcl-threadなら有効、--disable-tcl-threadなら無効、
> なにも指定しないときはチェックする、という処理ならこんな感じで。

この考えに基づいて,先の修正案にさらに修正を加えてみました.

  ・--enable-tcl-thread/--disable-tcl-thread が指定されていたならば
    それを採用し,Tcl/Tk ライブラリのチェックはしない.

  ・--with-tclConfig-file=<tclConfig.shのパス> が指定されたならば,
    そのファイル中の TCL_THREADS=(0|1) の行から情報を得る.
    ただし,--enable/disable-tcl-thread が指定されていた場合には
    このオプションは無視される.
    tclConfig.sh には,TCL_THREADS= の行が存在しさえすればいいので,
    Tcl/Tk の正式な tclConfig.sh ファイルである必要はない.
    この行が存在せず,TCL_MAJOR_VERSION= の行と TCL_MINOR_VERSION= 
    の行との情報から Tcl のバージョンが 7.x または 8.0 であるなら
    disable-tcl-thread (TCL_THREADS=0) と見なす.
    そうでなければ tclConfig.sh の指定は無効なものとして無視される.
    このファイルによって tcl-thread のモードが判定された場合には
    それを採用し,Tcl/Tk ライブラリのチェックは行わない.

というところではいかがでしょうか?

Index: extconf.rb =================================================================== RCS file: /src/ruby/ext/tcltklib/extconf.rb,v retrieving revision 1.16 diff -u -r1.16 extconf.rb --- extconf.rb 1 May 2004 16:08:58 -0000 1.16 +++ extconf.rb 23 May 2004 15:53:25 -0000 @@ -49,50 +49,105 @@ 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(<<EOF) -#include <tcl.h> -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 tcl_enable_thread = nil && (tclConfig = with_config("tclConfig-file")) + # 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 + tclConfig = false + 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: -** -** 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. +** PTHREAD SUPPORT CHECK WARNING: ** -** 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(<<EOF) +#include <tcl.h> +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 +165,50 @@ ** 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
-- 永井 秀利 (九工大 知能情報) nagai / ai.kyutech.ac.jp