1998-01-16 07:19:09 -05:00
|
|
|
# extconf.rb for tcltklib
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
require 'mkmf'
|
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
is_win32 = (/mswin32|mingw|cygwin|bccwin32/ =~ RUBY_PLATFORM)
|
2004-06-12 11:25:49 -04:00
|
|
|
is_macosx = (/darwin/ =~ RUBY_PLATFORM)
|
2004-05-01 12:09:54 -04:00
|
|
|
|
|
|
|
unless is_win32
|
2000-05-13 12:13:31 -04:00
|
|
|
have_library("nsl", "t_open")
|
|
|
|
have_library("socket", "socket")
|
|
|
|
have_library("dl", "dlopen")
|
|
|
|
have_library("m", "log")
|
|
|
|
end
|
1998-01-16 07:19:09 -05:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
dir_config("tk")
|
|
|
|
dir_config("tcl")
|
|
|
|
dir_config("X11")
|
1998-01-16 07:19:09 -05:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
tklib = with_config("tklib")
|
|
|
|
tcllib = with_config("tcllib")
|
2000-08-08 01:06:24 -04:00
|
|
|
stubs = enable_config("tcltk_stubs") || with_config("tcltk_stubs")
|
1998-01-16 07:19:09 -05:00
|
|
|
|
2000-08-08 01:06:24 -04:00
|
|
|
def find_tcl(tcllib, stubs)
|
2002-01-11 04:18:54 -05:00
|
|
|
paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
|
2000-08-08 01:06:24 -04:00
|
|
|
func = stubs ? "Tcl_InitStubs" : "Tcl_FindExecutable"
|
1999-08-13 01:37:52 -04:00
|
|
|
if tcllib
|
|
|
|
find_library(tcllib, func, *paths)
|
2002-12-31 06:13:44 -05:00
|
|
|
elsif find_library("tcl", func, *paths)
|
2003-03-07 06:45:01 -05:00
|
|
|
true
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2004-05-01 12:09:54 -04:00
|
|
|
%w[8.5 8.4 8.3 8.2 8.1 8.0 7.6].find { |ver|
|
2002-12-31 06:13:44 -05:00
|
|
|
find_library("tcl#{ver}", func, *paths) or
|
|
|
|
find_library("tcl#{ver.delete('.')}", func, *paths)
|
|
|
|
}
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
1998-01-16 07:19:09 -05:00
|
|
|
|
2000-08-08 01:06:24 -04:00
|
|
|
def find_tk(tklib, stubs)
|
2002-01-11 04:18:54 -05:00
|
|
|
paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
|
2000-08-08 01:06:24 -04:00
|
|
|
func = stubs ? "Tk_InitStubs" : "Tk_Init"
|
1999-08-13 01:37:52 -04:00
|
|
|
if tklib
|
|
|
|
find_library(tklib, func, *paths)
|
2002-12-31 06:13:44 -05:00
|
|
|
elsif find_library("tk", func, *paths)
|
2003-03-07 06:45:01 -05:00
|
|
|
true
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2004-05-01 12:09:54 -04:00
|
|
|
%w[8.5 8.4 8.3 8.2 8.1 8.0 4.2].find { |ver|
|
2002-12-31 06:13:44 -05:00
|
|
|
find_library("tk#{ver}", func, *paths) or
|
|
|
|
find_library("tk#{ver.delete('.')}", func, *paths)
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
end
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
|
|
|
|
2004-05-24 04:33:45 -04:00
|
|
|
def pthread_check()
|
|
|
|
tcl_major_ver = nil
|
|
|
|
tcl_minor_ver = nil
|
2004-05-01 12:09:54 -04:00
|
|
|
|
2004-05-24 04:33:45 -04:00
|
|
|
# Is tcl-thread given by user ?
|
|
|
|
case enable_config("tcl-thread")
|
|
|
|
when true
|
2004-05-01 12:09:54 -04:00
|
|
|
tcl_enable_thread = true
|
2004-05-24 04:33:45 -04:00
|
|
|
when false
|
2004-05-01 12:09:54 -04:00
|
|
|
tcl_enable_thread = false
|
2004-05-24 04:33:45 -04:00
|
|
|
else
|
|
|
|
tcl_enable_thread = nil
|
2004-05-01 12:09:54 -04:00
|
|
|
end
|
|
|
|
|
2004-05-24 04:33:45 -04:00
|
|
|
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?
|
2004-05-01 12:09:54 -04:00
|
|
|
puts(%Q'\
|
|
|
|
*****************************************************************************
|
|
|
|
**
|
2004-05-24 04:33:45 -04:00
|
|
|
** PTHREAD SUPPORT CHECK WARNING:
|
2004-05-01 12:09:54 -04:00
|
|
|
**
|
2004-05-24 04:33:45 -04:00
|
|
|
** 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.
|
2004-05-01 12:09:54 -04:00
|
|
|
**
|
|
|
|
*****************************************************************************
|
|
|
|
')
|
2004-05-24 04:33:45 -04:00
|
|
|
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
|
2004-05-01 12:09:54 -04:00
|
|
|
else
|
2004-05-24 04:33:45 -04:00
|
|
|
tcl_enable_thread = false
|
2004-05-01 12:09:54 -04:00
|
|
|
end
|
2004-05-24 04:33:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# check pthread mode
|
|
|
|
if (macro_defined?('HAVE_LIBPTHREAD', '#include "ruby.h"'))
|
|
|
|
# ruby -> enable
|
2004-05-01 12:09:54 -04:00
|
|
|
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
|
2004-05-24 04:33:45 -04:00
|
|
|
** than or equal to Tcl/Tk8.1).
|
2004-05-01 12:09:54 -04:00
|
|
|
**
|
|
|
|
*****************************************************************************
|
|
|
|
')
|
|
|
|
end
|
2004-05-24 04:33:45 -04:00
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
# ruby -> enable && tcl -> enable/disable
|
2004-05-24 04:33:45 -04:00
|
|
|
return true
|
2004-05-01 12:09:54 -04:00
|
|
|
|
2004-05-24 04:33:45 -04:00
|
|
|
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
|
2004-05-01 12:09:54 -04:00
|
|
|
end
|
1998-01-16 07:19:09 -05:00
|
|
|
end
|
2004-05-24 04:33:45 -04:00
|
|
|
|
2004-06-12 11:25:49 -04:00
|
|
|
if is_macosx ||
|
|
|
|
(have_header("tcl.h") && have_header("tk.h") &&
|
2004-05-24 04:33:45 -04:00
|
|
|
(is_win32 || find_library("X11", "XOpenDisplay",
|
|
|
|
"/usr/X11/lib", "/usr/lib/X11", "/usr/X11R6/lib", "/usr/openwin/lib")) &&
|
|
|
|
find_tcl(tcllib, stubs) &&
|
2004-06-12 11:25:49 -04:00
|
|
|
find_tk(tklib, stubs))
|
2004-05-24 04:33:45 -04:00
|
|
|
$CPPFLAGS += ' -DUSE_TCL_STUBS -DUSE_TK_STUBS' if stubs
|
|
|
|
$CPPFLAGS += ' -D_WIN32' if /cygwin/ =~ RUBY_PLATFORM
|
|
|
|
|
2004-06-12 11:25:49 -04:00
|
|
|
if is_macosx
|
|
|
|
$CPPFLAGS += ' -I/Library/Frameworks/Tcl.framework/headers -I/Library/Frameworks/Tk.framework/Headers'
|
|
|
|
$LDFLAGS += ' -framework Tk -framework Tcl'
|
|
|
|
end
|
|
|
|
|
2004-05-24 04:33:45 -04:00
|
|
|
create_makefile("tcltklib") if pthread_check
|
|
|
|
end
|