1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/tk/extconf.rb
nagai 3024ffdc3a * ext/tk/*: full update Ruby/Tk to support Ruby(1.9|1.8) and Tc/Tk8.5.
* ext/tk/lib/tkextlib/tile.rb: [incompatible] remove TileWidgets' 
  instate/state/identify method to avoid the conflict with standard
  widget options. Those methods are renamed to ttk_instate/ttk_state/
  ttk_identify (tile_instate/tile_state/tile_identify are available 
  too). Although I don't recommend, if you realy need old methods, 
  please define "Tk::USE_OBSOLETE_TILE_STATE_METHOD = true" before 
  "require 'tkextlib/tile'".

* ext/tk/lib/tkextlib/tile.rb: "Tk::Tile::__Import_Tile_Widgets__!"
  is obsolete. It outputs warning. To control default widget set, 
  use "Tk.default_widget_set = :Ttk".

* ext/tk/lib/tk.rb: __IGNORE_UNKNOWN_CONFIGURE_OPTION__ method and 
  __set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) method are defind 
  as module methods of TkConfigMethod. It may help users to wrap old 
  Ruby/Tk scripts (use standard widgets) to force to use Ttk widgets.
  Ttk widgets don't have some options of standard widgets which are 
  control the view of widgets. When set ignore-mode true, configure 
  method tries to ignoure such unknown options with no exception. 
  Of course, it may raise other troubles on the GUI design. 
  So, those are a little danger methods. 

* ext/tk/lib/tk/itemconfig.rb: __IGNORE_UNKNOWN_CONFIGURE_OPTION__ 
  method and __set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) method 
  are defind as module methods of TkItemConfigMethod as the same 
  purpose as TkConfigMethod's ones.

* ext/tk/sample/ttk_wrapper.rb: A new example. This is a tool for 
  wrapping old Ruby/Tk scripts (which use standard widgets) to use 
  Ttk (Tile) widgets as default.

* ext/tk/sample/tkextlib/tile/demo.rb: use ttk_instate/ttk_state 
  method instead of instate/state method.

* ext/tk/lib/tk/root, ext/tk/lib/tk/namespace.rb,
  ext/tk/lib/tk/text.rb, ext/tk/lib/tkextlib/*: some 'instance_eval's  
  are replaced to "instance_exec(self)".

* ext/tk/lib/tk/event.rb: bug fix on KEY_TBL and PROC_TBL (?x is not 
  a character code on Ruby1.9).

* ext/tk/lib/tk/variable.rb: support new style of operation argument 
  on Tcl/Tk's 'trace' command for variables. 

* ext/tk/sample/demos-jp/widget, ext/tk/sample/demos-en/widget: bug fix

* ext/tk/sammple/demos-jp/textpeer.rb, 
  ext/tk/sammple/demos-en/textpeer.rb: new widget demo.

* ext/tk/tcltklib.c: decrase SEGV troubles (probably)

* ext/tk/lib/tk.rb: remove Thread.critical access if Ruby1.9

* ext/tk/lib/tk/multi-tk.rb: support Ruby1.9 (probably)

* ext/tk/lib/tkextlib/tile.rb: add method to define Tcl/Tk command 
  to make Tcl/Tk theme sources (based on different version of Tile 
  extension) available. 
  (Tk::Tile::__define_LoadImages_proc_for_comaptibility__)

* ext/tk/lib/tk.rb, ext/tk/lib/tk/wm.rb: support dockable frames
  (Tcl/Tk8.5 feature). 'wm' command can treat many kinds of widgets 
  as toplevel widgets.

* ext/tk/lib/tkextlib/tile/style.rb: ditto.
  (Tk::Tile::Style.__define_wrapper_proc_for_compatibility__)

* ext/tk/lib/tk/font.rb: add actual_hash and metrics_hash to get 
  properties as a hash. metrics_hash method returns a boolean value 
  for 'fixed' option. But metrics method returns numeric value 
  (0 or 1) for 'fixed' option, because of backward compatibility. 

* ext/tk/lib/tk/timer.rb: somtimes fail to set callback procedure.

* ext/tk/lib/tk.rb: add Tk.sleep and Tk.wakeup method. Tk.sleep 
  doesn't block the eventloop. It will be better to use the method 
  in event callbacks.

* ext/tk/sample/tksleep_sample.rb: sample script about Tk.sleep.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-29 05:25:12 +00:00

330 lines
10 KiB
Ruby

# extconf.rb for tcltklib
require 'mkmf'
#is_win32 = (/mswin32|mingw|cygwin|bccwin32/ =~ RUBY_PLATFORM)
is_win32 = (/mswin|mingw|cygwin|bccwin|wince/ =~ RUBY_PLATFORM)
#is_macosx = (/darwin/ =~ RUBY_PLATFORM)
def find_framework(tcl_hdr, tk_hdr)
if framework_dir = with_config("tcltk-framework")
paths = [framework_dir]
else
unless tcl_hdr || tk_hdr ||
enable_config("tcltk-framework", false) ||
enable_config("mac-tcltk-framework", false)
return false
end
paths = ["/Library/Frameworks", "/System/Library/Frameworks"]
end
checking_for('Tcl/Tk Framework') {
paths.find{|dir|
dir.strip!
dir.chomp!('/')
(tcl_hdr || FileTest.directory?(dir + "/Tcl.framework/") ) &&
(tk_hdr || FileTest.directory?(dir + "/Tk.framework/") )
}
}
end
tcl_framework_header = with_config("tcl-framework-header")
tk_framework_header = with_config("tk-framework-header")
tcltk_framework = find_framework(tcl_framework_header, tk_framework_header)
unless is_win32
have_library("nsl", "t_open")
have_library("socket", "socket")
have_library("dl", "dlopen")
have_library("m", "log")
end
tk_idir, tk_ldir = dir_config("tk")
tcl_idir, tcl_ldir = dir_config("tcl")
x11_idir, x11_ldir = dir_config("X11")
tk_ldir2 = with_config("tk-lib")
tcl_ldir2 = with_config("tcl-lib")
x11_ldir2 = with_config("X11-lib")
tklib = with_config("tklib")
tcllib = with_config("tcllib")
stubs = enable_config("tcltk_stubs") || with_config("tcltk_stubs")
use_X = with_config("X11", (! is_win32))
def find_tcl(tcllib, stubs, *opt_paths)
default_paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
paths = opt_paths.compact.concat(default_paths)
if stubs
func = "Tcl_InitStubs"
lib = "tclstub"
else
func = "Tcl_FindExecutable"
lib = "tcl"
end
if tcllib
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)
end
end
def find_tk(tklib, stubs, *opt_paths)
default_paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
paths = opt_paths.compact.concat(default_paths)
if stubs
func = "Tk_InitStubs"
lib = "tkstub"
else
func = "Tk_Init"
lib = "tk"
end
if tklib
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)
end
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)
end
def pthread_check()
tcl_major_ver = nil
tcl_minor_ver = nil
# 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 (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 CHECK WARNING:
**
** We cannot check the consistency of pthread support between Ruby
** and the Tcl/Tk library in your environment (are you perhaps
** cross-compiling?). If pthread support for these 2 packages is
** inconsistent you may find you get errors when running Ruby/Tk
** (e.g. hangs or segmentation faults). We strongly recommend
** you to check the consistency manually.
**
*****************************************************************************
')
return true
end
end
if tcl_enable_thread == nil
# tcl-thread is unknown
if try_run(<<EOF)
#include <tcl.h>
int main() {
Tcl_Interp *ip;
ip = Tcl_CreateInterp();
exit((Tcl_Eval(ip, "set tcl_platform(threaded)") == TCL_OK)? 0: 1);
}
EOF
tcl_enable_thread = true
elsif 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
tcl_enable_thread = false
end
end
# check pthread mode
if (macro_defined?('HAVE_NATIVETHREAD', '#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 library
** seems to be compiled without pthread support. Although you can
** create the tcltklib library, this combination may cause errors
** (e.g. hangs or segmentation faults). If you have no reason to
** keep the current pthread support status, we recommend you reconfigure
** and recompile the libraries so that both or neither support pthreads.
**
** 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/Tk 8.1).
**
*****************************************************************************
')
end
# ruby -> enable && tcl -> enable/disable
if tcl_enable_thread
$CPPFLAGS += ' -DWITH_TCL_ENABLE_THREAD=1'
else
$CPPFLAGS += ' -DWITH_TCL_ENABLE_THREAD=0'
end
return true
else
# ruby -> disable
if tcl_enable_thread
# ruby -> disable && tcl -> enable
puts(%Q'\
*****************************************************************************
**
** PTHREAD SUPPORT MODE ERROR:
**
** Ruby is not compiled with --enable-pthread, but your Tcl/Tk
** library seems to be compiled with pthread support. This
** combination may cause frequent hang or segmentation fault
** errors when Ruby/Tk is working. We recommend that you NEVER
** create the library with such a combination of pthread support.
**
** Please recompile Ruby with the "--enable-pthread" configure option
** or recompile Tcl/Tk with the "--disable-threads" configure option.
**
*****************************************************************************
')
$CPPFLAGS += ' -DWITH_TCL_ENABLE_THREAD=1'
return false
else
# ruby -> disable && tcl -> disable
$CPPFLAGS += ' -DWITH_TCL_ENABLE_THREAD=0'
return true
end
end
end
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) ) )
$CPPFLAGS += ' -DUSE_TCL_STUBS -DUSE_TK_STUBS' if stubs
$CPPFLAGS += ' -D_WIN32' if /cygwin/ =~ RUBY_PLATFORM
if tcltk_framework
if tcl_framework_header
$CPPFLAGS += " -I#{tcl_framework_header}"
else
$CPPFLAGS += " -I#{tcltk_framework}/Tcl.framework/Headers"
end
if tk_framework_header
$CPPFLAGS += " -I#{tk_framework_header}"
else
$CPPFLAGS += " -I#{tcltk_framework}/Tk.framework/Headers"
end
$LDFLAGS += ' -framework Tk -framework Tcl'
end
if stubs or pthread_check
# create Makefile
# for SUPPORT_STATUS
$INSTALLFILES ||= []
$INSTALLFILES << ["lib/tkextlib/SUPPORT_STATUS", "$(RUBYLIBDIR)", "lib"]
# create
$defs << %[-DRUBY_VERSION=\\"#{RUBY_VERSION}\\"]
$defs << %[-DRUBY_RELEASE_DATE=\\"#{RUBY_RELEASE_DATE}\\"]
create_makefile("tcltklib")
end
end