~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to ext/tk/extconf.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum, Daigo Moriwaki, Lucas Nussbaum
  • Date: 2011-07-25 20:27:20 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20110725202720-9qfs7iam0ml7e1kc
Tags: 1.9.2.290-1
[ Daigo Moriwaki ]
* New upstream release.
* Removed debian/patches/110411_disable_osslv2.patch, which has been applied
  by the upstream.
* Added a patch: debian/patches/debian/patches/110716-bigdecimal,
  which was backported from the upstream (r30993)
  (CVE-2011-0188; Closes: 628450)

[ Lucas Nussbaum ]
* Build-depend on tcl-dev and tk-dev instead of {tcl,tk}8.4-dev.
* Update Lucas' email address.
* Add 110825-ossl-config.diff: backport changes to the OpenSSL
  extension to fix test failure.
* Add patch 110720_tcltk_disable_rpath.diff: disable rpath in tcltk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
require 'mkmf'
6
6
 
7
7
TkLib_Config = {}
8
 
TkLib_Config['search_versions'] = 
 
8
TkLib_Config['search_versions'] =
9
9
  # %w[8.9 8.8 8.7 8.6 8.5 8.4 8.3 8.2 8.1 8.0 7.6 4.2]
10
10
  # %w[8.7 8.6 8.5 8.4 8.3 8.2 8.1 8.0]
11
11
  %w[8.7 8.6 8.5 8.4 8.0] # to shorten search steps
12
12
 
 
13
TkLib_Config['major_nums'] = '87'
 
14
 
13
15
 
14
16
##############################################################
15
17
# use old extconf.rb ?
23
25
##############################################################
24
26
# check configs
25
27
##############################################################
26
 
$cleanfiles << 'config_list'
 
28
($cleanfiles ||= "") << 'config_list'
27
29
config_list_file = 'config_list'
28
30
config_list_file_source = File.join(File.dirname(__FILE__),'config_list.in')
29
 
if !File.exist?(config_list_file) || 
 
31
if !File.exist?(config_list_file) ||
30
32
    File.ctime(config_list_file_source) > File.ctime(config_list_file)
31
33
  old_config_list_file = config_list_file_source
32
34
else
92
94
 
93
95
else
94
96
  makefile = 'Makefile'
95
 
  if File.exist?(makefile) && 
 
97
  if File.exist?(makefile) &&
96
98
      File.ctime(config_list_file) > File.ctime(makefile)
97
99
    # no need to update Makefile
98
100
    exit
111
113
 /darwin/ =~ RUBY_PLATFORM
112
114
end
113
115
 
 
116
def maybe_64bit?
 
117
  /64|universal/ =~ RUBY_PLATFORM
 
118
end
 
119
 
114
120
def check_tcltk_version(version)
115
121
  return [nil, nil] unless version.kind_of? String
116
122
 
117
 
  version = version.strip
118
 
 
119
 
  tclver = version.dup
120
 
  tkver  = version.dup
 
123
  tclver, tkver = version.split(',')
 
124
  tclver = tclver.strip
 
125
  return [tclver, tkver.strip] if tkver
121
126
 
122
127
  dot = major = minor_dot = minor = plvl_dot = plvl = ext = nil
123
 
 
124
 
  if version =~ /^(\d)(\.?)(\d)(\.?)(\d*)(.*)$/
 
128
  if tclver =~ /^(\d)(\.?)(\d)(\.?)(\d*)(.*)$/
125
129
    major = $1; minor_dot = $2; minor = $3; plvl_dot = $4; plvl = $5; ext = $6
126
130
    dot = ! minor_dot.empty?
127
131
    if plvl_dot.empty? && ! plvl.empty?
128
132
      minor << plvl
129
133
    end
130
 
  elsif version =~ /^(\d)(\.?)(\d?)(.*)$/
 
134
  elsif tclver =~ /^(\d)(\.?)(\d?)(.*)$/
131
135
    major = $1; minor_dot = $2; minor = $3; ext = $4
132
136
    dot = ! minor_dot.empty?
133
137
  else # unknown -> believe user
140
144
    tkver  = "4" + ((dot)? ".": "") + ((minor.empty)? "": "2") + ext
141
145
  elsif major == "4" # Tk4.2 ( not support Tkversion < 4.2 )
142
146
    # Tcl7.6
 
147
    tkver = tclver
143
148
    tclver = "7" + ((dot)? ".": "") + ((minor.empty)? "": "6") + ext
144
149
  end
145
150
 
 
151
  tkver = tclver unless tkver
 
152
 
146
153
  [tclver, tkver]
147
154
end
148
155
 
187
194
  if CROSS_COMPILING
188
195
  elsif is_win32?
189
196
    if TkLib_Config["ActiveTcl"]
190
 
      path_head.concat ["c:/ActiveTcl", "c:/Program Files/ActiveTcl"]
 
197
      path_head.concat ["c:/ActiveTcl", "c:/Program Files/ActiveTcl",
 
198
                        "c:/Program Files (x86)/ActiveTcl"]
191
199
    end
192
200
    path_head.concat [
193
 
      "c:/Tcl", "c:/Program Files/Tcl",
194
 
      "/Tcl", "/Program Files/Tcl"
 
201
      "c:/Tcl", "c:/Program Files/Tcl", "c:/Program Files (x86)/Tcl",
 
202
      "/Tcl", "/Program Files/Tcl", "/Program Files (x86)/Tcl"
195
203
    ]
196
 
    path_head.each{|dir| path_dirs << "#{dir}"}
 
204
    path_head.uniq!
 
205
    #path_head.each{|dir| path_dirs << dir.dup if File.directory? dir}
 
206
    path_head.each{|dir| path_dirs << File.expand_path(dir) if File.directory? dir}
 
207
 
 
208
    # for MinGW
 
209
    ["/usr/local/lib64", "/usr/lib64", "/usr/local/lib", "/usr/lib"].each{|dir|
 
210
      #path_dirs << dir if File.directory? dir
 
211
      path_dirs << File.expand_path(dir) if File.directory? dir
 
212
    }
 
213
    path_dirs |= ENV['LIBRARY_PATH'].split(';').find_all{|dir| File.directory? dir}.map{|dir| File.expand_path(dir)} if ENV['LIBRARY_PATH']
 
214
    path_dirs |= ENV['PATH'].split(';').find_all{|dir| File.directory? dir}.map{|dir| File.expand_path(dir)} if ENV['PATH']
197
215
 
198
216
  else
199
217
    [
200
 
      '/opt', '/pkg', '/share', 
 
218
      '/opt', '/pkg', '/share',
201
219
      '/usr/local/opt', '/usr/local/pkg', '/usr/local/share', '/usr/local',
202
220
      '/usr/opt', '/usr/pkg', '/usr/share', '/usr/contrib', '/usr'
203
221
    ].each{|dir|
204
222
      next unless File.directory?(dir)
205
223
 
 
224
      path_dirs << "#{dir}/lib64" if maybe_64bit?
206
225
      path_dirs << "#{dir}/lib"
207
226
      path_dirs << "#{dir}" unless Dir.glob("#{dir}/lib*.*", File::FNM_CASEFOLD).empty?
208
227
 
268
287
  end
269
288
 
270
289
  # framework is disabled?
271
 
  if with_config("tcltk-framework") == false || 
 
290
  if with_config("tcltk-framework") == false ||
272
291
      enable_config("tcltk-framework") == false
273
292
   return false
274
293
  end
276
295
  use_framework ||= (framework_dir = with_config("tcltk-framework"))
277
296
  if framework_dir.kind_of? String
278
297
    TkLib_Config["tcltk-framework"] = framework_dir.strip.chomp('/')
279
 
    return [File.join(TkLib_Config["tcltk-framework"], 'Tcl.framework'), 
 
298
    return [File.join(TkLib_Config["tcltk-framework"], 'Tcl.framework'),
280
299
            File.join(TkLib_Config["tcltk-framework"], 'Tk.framework')]
281
300
  end
282
301
 
287
306
  end
288
307
 
289
308
  paths = [
290
 
    #"~/Library/Frameworks", 
 
309
    #"~/Library/Frameworks",
291
310
    "/Library/Frameworks",
292
311
    "/Network/Library/Frameworks", "/System/Library/Frameworks"
293
312
  ]
305
324
 
306
325
def collect_tcltk_defs(tcl_defs_str, tk_defs_str)
307
326
  conflicts = [
308
 
    'PACKAGE_NAME', 'PACKAGE_TARNAME', 'PACKAGE_VERSION', 
 
327
    'PACKAGE_NAME', 'PACKAGE_TARNAME', 'PACKAGE_VERSION',
309
328
    'PACKAGE_STRING', 'PACKAGE_BUGREPORT'
310
329
  ]
311
330
 
347
366
 
348
367
  defs.delete_if{|name,value|
349
368
    conflicts.include?(name) ||
350
 
      ( (vtcl = tcl_defs.assoc(name)) && (vtk = tk_defs.assoc(name)) && 
 
369
      ( (vtcl = tcl_defs.assoc(name)) && (vtk = tk_defs.assoc(name)) &&
351
370
          vtcl != vtk )
352
371
  }
353
372
 
354
 
  defs.map{|ary| s = ary.join(''); (s.strip.empty?)? "": "-D" << s}.join(' ')
 
373
  defs.map{|ary| s = ary.join(''); (s.strip.empty?)? "": "-D" << s}
355
374
end
356
375
 
357
376
def parse_tclConfig(file)
371
390
end
372
391
 
373
392
def get_libpath(lib_flag, lib_spec)
374
 
  # get libpath fro {TCL,Tk}_LIB_FLAG and {TCL,Tk}_LIB_SPEC
375
 
  libpath = lib_spec.gsub(/(#{lib_flag}|-L)/, "").strip
 
393
  # get libpath from {TCL,Tk}_LIB_FLAG and {TCL,Tk}_LIB_SPEC
 
394
  lib_spec.gsub(/(#{lib_flag}|-L)/, "").strip
376
395
end
377
396
 
378
397
def get_tclConfig_dirs
387
406
      end
388
407
      dirs.concat [
389
408
        "c:/ActiveTcl*/lib", "c:/Tcl*/lib",
390
 
        "c:/Program Files/ActiveTcl*/lib", "c:/Program Files/Tcl*/lib",
 
409
        "c:/Program Files*/ActiveTcl*/lib", "c:/Program Files*/Tcl*/lib",
391
410
        "/ActiveTcl*/lib", "/Tcl*/lib",
392
 
        "/Program Files/ActiveTcl*/lib", "/Program Files/Tcl*/lib"
 
411
        "/Program Files*/ActiveTcl*/lib", "/Program Files*/Tcl*/lib"
393
412
      ]
394
413
    else
395
414
      dirs = [
396
 
        "c:/Tcl*/lib", "c:/Program Files/Tcl*/lib",
397
 
        "/Tcl*/lib", "/Program Files/Tcl*/lib"
 
415
        "c:/Tcl*/lib", "c:/Program Files*/Tcl*/lib",
 
416
        "/Tcl*/lib", "/Program Files*/Tcl*/lib"
398
417
      ]
399
418
    end
400
 
    dirs.collect{|d| Dir.glob(d, File::FNM_CASEFOLD)}.flatten!
401
 
    dirs |= dirs
 
419
    dirs = dirs.collect{|d| Dir.glob(d, File::FNM_CASEFOLD)}.flatten.uniq
 
420
 
 
421
    dirs |= ENV['LIBRARY_PATH'].split(';')  if ENV['LIBRARY_PATH']
 
422
    dirs |= ENV['PATH'].split(';')  if ENV['PATH']
402
423
 
403
424
    exeext = RbConfig::CONFIG['EXEEXT']
404
425
    ENV['PATH'].split(File::PATH_SEPARATOR).each{|dir|
433
454
          File.join(base, 'Tk.framework', 'Versions', 'Current')
434
455
        ]
435
456
 
436
 
        Dir.glob(File.join(base, 'Tcl.framework', 
 
457
        Dir.glob(File.join(base, 'Tcl.framework',
437
458
                           'Versions', '*')).sort.reverse.each{|dir|
438
459
          next if dir =~ /Current/
439
460
          config_dir << [dir, dir.gsub(/Tcl/, 'Tk')]
443
464
      end
444
465
    end
445
466
 
446
 
    config_dir.concat [
447
 
      RbConfig::CONFIG['libdir'],
448
 
      File.join(RbConfig::CONFIG['exec_prefix'], 'lib'),
449
 
      File.join(RbConfig::CONFIG['prefix'], 'lib'), 
450
 
      "/usr/local/opt/lib", "/usr/local/pkg/lib", "/usr/local/share/lib", 
451
 
      "/usr/local/lib", "/usr/opt/lib", "/usr/pkg/lib", 
452
 
      "/usr/share/lib", "/usr/contrib/lib", "/usr/lib"
453
 
    ]
454
 
 
455
 
    config_dir.concat [
456
 
      '/opt', '/pkg', '/share', 
 
467
    config_dir << RbConfig::CONFIG['libdir']
 
468
 
 
469
    ((maybe_64bit?)? ['lib64', 'lib']: ['lib']).each{|dir|
 
470
      config_dir.concat [
 
471
        File.join(RbConfig::CONFIG['exec_prefix'], dir),
 
472
        File.join(RbConfig::CONFIG['prefix'], dir),
 
473
        "/usr/local/opt/#{dir}", "/usr/local/pkg/#{dir}",
 
474
        "/usr/local/share/#{dir}", "/usr/local/#{dir}",
 
475
        "/usr/opt/#{dir}", "/usr/pkg/#{dir}", "/usr/share/#{dir}",
 
476
        "/usr/contrib/#{dir}", "/usr/#{dir}"
 
477
      ]
 
478
    }
 
479
 
 
480
    config_dir.concat [
 
481
      '/opt', '/pkg', '/share',
457
482
      '/usr/local/opt', '/usr/local/pkg', '/usr/local/share', '/usr/local',
458
483
      '/usr/opt', '/usr/pkg', '/usr/share', '/usr/contrib', '/usr'
459
484
    ].map{|dir|
460
 
      Dir.glob(dir + '/{tcltk,tcl,tk}[87]*/lib', File::FNM_CASEFOLD)
461
 
      Dir.glob(dir + '/{tcltk,tcl,tk}[87]*', File::FNM_CASEFOLD)
 
485
      Dir.glob(dir + "/{tcltk,tcl,tk}[#{TkLib_Config['major_nums']}*/lib",
 
486
               File::FNM_CASEFOLD)
 
487
      Dir.glob(dir + "/{tcltk,tcl,tk}[#{TkLib_Config['major_nums']}*",
 
488
               File::FNM_CASEFOLD)
462
489
      Dir.glob(dir + '/{tcltk,tcl,tk}/lib', File::FNM_CASEFOLD)
463
490
      Dir.glob(dir + '/{tcltk,tcl,tk}', File::FNM_CASEFOLD)
464
491
    }.flatten!
483
510
    }
484
511
 
485
512
    paths = [
486
 
      #"~/Library/Frameworks", 
 
513
      #"~/Library/Frameworks",
487
514
      "/Library/Frameworks",
488
515
      "/Network/Library/Frameworks", "/System/Library/Frameworks"
489
516
    ]
490
517
    paths.reverse! unless TkLib_Config["ActiveTcl"]
491
518
 
492
 
    paths.each{|framework|
493
 
      base = File.expand_path(framework)
 
519
    paths.each{|frmwk|
 
520
      base = File.expand_path(frmwk)
494
521
      config_dir << [
495
522
        File.join(base, 'Tcl.framework'), File.join(base, 'Tk.framework')
496
523
      ]
500
527
        File.join(base, 'Tk.framework', 'Versions', 'Current')
501
528
      ]
502
529
 
503
 
      Dir.glob(File.join(base, 'Tcl.framework', 
 
530
      Dir.glob(File.join(base, 'Tcl.framework',
504
531
                         'Versions', '*')).sort.reverse.each{|dir|
505
532
        next if dir =~ /Current/
506
533
        config_dir << [dir, dir.gsub(/Tcl/, 'Tk')]
511
538
  config_dir
512
539
end
513
540
 
514
 
def libcheck_for_tclConfig(dir, tclconf, tkconf)
 
541
def get_ext_list()
 
542
  exts = [CONFIG['DLEXT']]
 
543
  exts.concat %w(dll lib) if is_win32?
 
544
  exts.concat %w(bundle dylib) if is_macosx? || /nextstep|openstep|rhapsody/ =~ RUBY_PLATFORM
 
545
 
 
546
  if enable_config("shared") == false
 
547
    [CONFIG['LIBEXT'], "a"].concat exts
 
548
  else
 
549
    exts.concat [CONFIG['LIBEXT'], "a"]
 
550
  end
 
551
 
 
552
  if is_win32?
 
553
    exts.map!{|ext| [ext.downcase, ext.upcase]}.flatten!
 
554
  end
 
555
 
 
556
  exts
 
557
end
 
558
 
 
559
def libcheck_for_tclConfig(tcldir, tkdir, tclconf, tkconf)
515
560
  tcllib_ok = tklib_ok = false
516
561
 
517
562
  if TkLib_Config["tcltk-stubs"]
524
569
    tkfunc  = "Tk_Init"
525
570
  end
526
571
 
527
 
  libpath = $LIBPATH
 
572
  incflags = ($INCFLAGS ||= "").dup
 
573
  libpath = ($LIBPATH ||= []).dup
 
574
  libs_param = ($libs ||= "").dup
528
575
  tcllibs = nil
529
 
 
530
 
  begin
531
 
    tcllib_ok ||= Dir.glob(File.join(dir, "*tcl#{stub}#{tclconf['TCL_MAJOR_VERSION']}{.,}#{tclconf['TCL_MINOR_VERSION']}*.*"), File::FNM_CASEFOLD).find{|file|
532
 
      if file =~ /^.*(tcl#{stub}#{tclconf['TCL_MAJOR_VERSION']}(\.|)#{tclconf['TCL_MINOR_VERSION']}.*)\.[^.]*$/
533
 
        #puts "check #{file} #{$1} #{tclfunc} #{dir}"
534
 
        #find_library($1, tclfunc, dir)
535
 
        tcllibs = append_library($libs, $1)
536
 
        $LIBPATH = libpath | [dir]
537
 
        try_func(tclfunc, tcllibs)
538
 
      end
539
 
    }
540
 
    tklib_ok ||= Dir.glob(File.join(dir, "*tk#{stub}#{tkconf['TK_MAJOR_VERSION']}{.,}#{tkconf['TK_MINOR_VERSION']}*.*"), File::FNM_CASEFOLD).find{|file|
541
 
      if file =~ /^.*(tk#{stub}#{tkconf['TK_MAJOR_VERSION']}(\.|)#{tkconf['TK_MINOR_VERSION']}.*)\.[^.]*$/
542
 
        #puts "check #{file} #{$1} #{tkfunc} #{dir}"
543
 
        # find_library($1, tkfunc, dir)
544
 
        tklibs = append_library(tcllibs, $1)
545
 
        $LIBPATH = libpath | [dir]
546
 
        try_func(tkfunc, tklibs)
547
 
      end
548
 
    }
549
 
  ensure
550
 
    $LIBPATH = libpath
551
 
  end
 
576
  mkmf_param = nil
 
577
 
 
578
  tclver, tkver = TkLib_Config["tcltkversion"]
 
579
  exts = "(" + get_ext_list.join('|') + ")"
 
580
 
 
581
  if tclver
 
582
    tcl_glob = "*tcl#{stub}#{tclver}.*"
 
583
    tcl_regexp = /^.*(tcl#{stub}#{tclver}.*)\.(#{exts}).*$/
 
584
  elsif tclconf
 
585
    tcl_glob = "*tcl#{stub}#{tclconf['TCL_MAJOR_VERSION']}{.,}#{tclconf['TCL_MINOR_VERSION']}*.*"
 
586
    tcl_regexp = /^.*(tcl#{stub}#{tclconf['TCL_MAJOR_VERSION']}(?:\.|)#{tclconf['TCL_MINOR_VERSION']}.*)\.(#{exts}).*$/
 
587
  end
 
588
  if tkver
 
589
    tk_glob = "*tk#{stub}#{tkver}.*"
 
590
    tk_regexp = /^.*(tk#{stub}#{tkver}.*)\.(#{exts}).*$/
 
591
  elsif tkconf
 
592
    tk_glob = "*tk#{stub}#{tkconf['TK_MAJOR_VERSION']}{.,}#{tkconf['TK_MINOR_VERSION']}*.*"
 
593
    tk_regexp = /^.*(tk#{stub}#{tkconf['TK_MAJOR_VERSION']}(?:\.|)#{tkconf['TK_MINOR_VERSION']}.*)\.#{exts}.*$/
 
594
  end
 
595
 
 
596
  tcllib_ok ||= !tclconf || Dir.glob(File.join(tcldir, tcl_glob), File::FNM_CASEFOLD).find{|file|
 
597
    if file =~ tcl_regexp
 
598
      libname = $1
 
599
      ext = $2.downcase
 
600
      begin
 
601
        $INCFLAGS = incflags.dup << " " << tclconf["TCL_INCLUDE_SPEC"]
 
602
        #puts "check #{file} #{$1} #{tclfunc} #{tcldir}"
 
603
        #find_library($1, tclfunc, tcldir)
 
604
        if (tclconf && tclconf["TCL_SHARED_BUILD"] == "0") ||
 
605
            (ext != CONFIG['DLEXT'] && ext == CONFIG['LIBEXT']) || ext == "a"
 
606
          # static link
 
607
          tcllibs = $libs + " -DSTATIC_BUILD " + file.quote
 
608
 
 
609
          # FIX ME: avoid pathname trouble (fail to find) on MinGW.
 
610
          #   e.g. TCL_INCLUDE_SPEC describes "-I/usr/local/include",
 
611
          #        but compiler can find "-IC:/msys/1.0/local/include" only.
 
612
          $INCFLAGS << " -I" << File.join(File.dirname(File.dirname(file)),"include") if is_win32?
 
613
        else
 
614
          tcllibs = append_library($libs, libname)
 
615
          tcllibs = "-L#{tcldir.quote} " + tcllibs
 
616
 
 
617
          # FIX ME: avoid pathname trouble (fail to find) on MinGW.
 
618
          $INCFLAGS << " -I" << File.join(File.dirname(tcldir),"include") if is_win32?
 
619
        end
 
620
 
 
621
        $LIBPATH = libpath | [tcldir]
 
622
        try_func(tclfunc, tcllibs, ["tcl.h"]) ||
 
623
          ( try_func(tclfunc, tcllibs << " " << tclconf['TCL_LIBS'], ["tcl.h"]) if tclconf['TCL_LIBS'] )
 
624
 
 
625
      ensure
 
626
        mkmf_param = {
 
627
          'PATH' => file,
 
628
          'LIBNAME' => libname,
 
629
          'libs' => tcllibs.dup,
 
630
          'INCFLAGS' => $INCFLAGS.dup,
 
631
          'LIBPATH' => $LIBPATH.dup,
 
632
        }
 
633
        $LIBPATH = libpath.dup
 
634
        $libs = libs_param.dup
 
635
      end
 
636
    end
 
637
  }
 
638
  tclconf['MKMF_PARAMS'] = mkmf_param if tclconf && tcllib_ok
 
639
 
 
640
  tklib_ok ||= !tkconf || Dir.glob(File.join(tkdir, tk_glob), File::FNM_CASEFOLD).find{|file|
 
641
    if file =~ tk_regexp
 
642
      libname = $1
 
643
      ext = $2.downcase
 
644
      begin
 
645
        #puts "check #{file} #{$1} #{tkfunc} #{tkdir}"
 
646
        # find_library($1, tkfunc, tkdir)
 
647
        if (tkconf && tkconf["TCL_SHARED_BUILD"] == "0") ||
 
648
            (ext != CONFIG['DLEXT'] && ext == CONFIG['LIBEXT']) || ext == "a"
 
649
          # static link
 
650
          tklibs = " -DSTATIC_BUILD " + file.quote
 
651
 
 
652
          # FIX ME: avoid pathname trouble (fail to find) on MinGW.
 
653
          $INCFLAGS << " -I" << File.join(File.dirname(File.dirname(file)),"include") if is_win32?
 
654
        else
 
655
          tklibs = append_library("", libname)
 
656
          #tklibs = append_library("", $1)
 
657
          tklibs = "-L#{tkdir.quote} " + tklibs
 
658
 
 
659
          # FIX ME: avoid pathname trouble (fail to find) on MinGW.
 
660
          $INCFLAGS << " -I" << File.join(File.dirname(tcldir),"include") if is_win32?
 
661
        end
 
662
 
 
663
        tklibs << " " <<  tcllibs if tcllibs
 
664
        tmp_tklibs = tklibs.dup
 
665
        $LIBPATH = libpath | [tkdir]
 
666
        try_func(tkfunc, tklibs, ["tcl.h", "tk.h"]) ||
 
667
          ( try_func(tkfunc, tklibs << " " << tkconf['TK_LIBS'], ["tcl.h", "tk.h"]) if tkconf['TK_LIBS'] ) ||
 
668
          ( try_func(tkfunc, (tklibs = tmp_tklibs.dup) << " " << tkconf['TK_XLIBSW'], ["tcl.h", "tk.h"]) if tkconf['TK_XLIBSW'] ) ||
 
669
          ( try_func(tkfunc, tklibs << " " << tkconf['TK_LIBS'], ["tcl.h", "tk.h"]) if tkconf['TK_LIBS'] )
 
670
 
 
671
      ensure
 
672
        mkmf_param = {
 
673
          'PATH' => file,
 
674
          'LIBNAME' => libname,
 
675
          'libs' => tklibs.dup,
 
676
          'INCFLAGS' => $INCFLAGS.dup,
 
677
          'LIBPATH' => $LIBPATH.dup,
 
678
        }
 
679
        $LIBPATH = libpath.dup
 
680
        $libs = libs_param.dup
 
681
      end
 
682
    end
 
683
  }
 
684
 
 
685
  $INCFLAGS = incflags.dup
 
686
  tkconf['MKMF_PARAMS'] = mkmf_param if tkconf && tklib_ok
552
687
 
553
688
  [tcllib_ok, tklib_ok]
554
689
end
559
694
  paths.compact!
560
695
  if paths.empty?
561
696
    config_dir = get_tclConfig_dirs
 
697
  elsif paths.length == 1 && !paths[0][0] && !paths[0][1]
 
698
    config_dir = get_tclConfig_dirs.map{|dir|
 
699
      if dir.kind_of? Array
 
700
        [ (paths[0][0] == false)? nil: dir[0],
 
701
          (paths[0][1] == false)? nil: dir[1] ]
 
702
      else
 
703
        [ (paths[0][0] == false)? nil: dir,
 
704
          (paths[0][1] == false)? nil: dir ]
 
705
      end
 
706
    }
562
707
  else
563
708
    # fixed tclConfig
564
709
    config_dir = []
573
718
  end
574
719
 
575
720
  tclver, tkver = TkLib_Config['tcltkversion']
 
721
  if tclver && tclver =~ /^\D*(\d)\.?(\d)?/  # ignore PATCH_LEVEL
 
722
    tclver_major = $1
 
723
    tclver_minor = $2
 
724
  else
 
725
    tclver_major = nil
 
726
    tclver_minor = nil
 
727
  end
 
728
  if tkver && tkver =~ /^\D*(\d)\.?(\d)?/  # ignore PATCH_LEVEL
 
729
    tkver_major = $1
 
730
    tkver_minor = $2
 
731
  else
 
732
    tkver_major = nil
 
733
    tkver_minor = nil
 
734
  end
 
735
 
576
736
  conf = nil
577
737
 
578
738
  config_dir.uniq!
579
739
  config_dir.map{|dir|
580
740
    if dir.kind_of? Array
581
 
      [dir[0].strip.chomp('/'), dir[1].strip.chomp('/')]
 
741
      [ (dir[0])? dir[0].strip.chomp('/'): nil,
 
742
        (dir[1])? dir[1].strip.chomp('/'): nil ]
582
743
    else
583
744
      dir.strip.chomp('/')
584
745
    end
593
754
 
594
755
    tails = ['Config-shared.sh', 'config-shared.sh', 'Config.sh', 'config.sh']
595
756
 
596
 
    if File.file?(tcldir)
597
 
      tclcfg_files = [tcldir] * tails.length
598
 
    else
599
 
      tclcfg_files = tails.map{|f| File.join(tcldir, 'tcl' << f)}
600
 
    end
601
 
 
602
 
    if File.file?(tkdir)
603
 
      tkcfg_files = [tkdir] * tails.length
604
 
    else
605
 
      tkcfg_files = tails.map{|f| File.join(tkdir, 'tk' << f)}
606
 
    end
607
 
 
608
 
    tclcfg_files.zip(tkcfg_files).uniq.each{|tclpath, tkpath|
609
 
      next if !File.exist?(tclpath) || !File.exist?(tkpath)
 
757
    if tcldir
 
758
      if File.file?(tcldir)
 
759
        tclcfg_files = [tcldir] * tails.length
 
760
      else
 
761
        tclcfg_files = tails.map{|f| File.join(tcldir, 'tcl' << f)}
 
762
      end
 
763
    else
 
764
      tclcfg_files = [nil] * tails.length
 
765
    end
 
766
 
 
767
    if tkdir
 
768
      if File.file?(tkdir)
 
769
        tkcfg_files = [tkdir] * tails.length
 
770
      else
 
771
        tkcfg_files = tails.map{|f| File.join(tkdir, 'tk' << f)}
 
772
      end
 
773
    else
 
774
      tkcfg_files = [nil] * tails.length
 
775
    end
 
776
 
 
777
    tclcfg_files.zip(tkcfg_files).map{|tclpath, tkpath|
 
778
      [ (tclpath && File.exist?(tclpath))? File.expand_path(tclpath): tclpath,
 
779
        (tkpath && File.exist?(tkpath))? File.expand_path(tkpath): tkpath ]
 
780
    }.uniq.each{|tclpath, tkpath|
 
781
      next if tclpath && !File.exist?(tclpath)
 
782
      next if tkpath && !File.exist?(tkpath)
610
783
 
611
784
      # parse tclConfig.sh/tkConfig.sh
612
 
      tclconf = parse_tclConfig(tclpath)
613
 
      next if tclver && tclver !~ /^#{tclconf['TCL_MAJOR_VERSION']}(\.?)#{tclconf['TCL_MINOR_VERSION']}/
614
 
      tkconf = parse_tclConfig(tkpath)
615
 
      next if tkver && tkver !~ /^#{tkconf['TK_MAJOR_VERSION']}(\.?)#{tkconf['TK_MINOR_VERSION']}/
 
785
      tclconf = (tclpath)? parse_tclConfig(tclpath): nil
 
786
      next if tclconf && tclver && ((tclver_major && tclver_major != tclconf['TCL_MAJOR_VERSION']) || (tclver_minor && tclver_minor != tclconf['TCL_MINOR_VERSION']))
 
787
 
 
788
      tkconf = (tkpath)? parse_tclConfig(tkpath): nil
 
789
      next if tkconf && tkver && ((tkver_major && tkver_major != tkconf['TK_MAJOR_VERSION']) || (tkver_minor && tkver_minor != tkconf['TK_MINOR_VERSION']))
616
790
 
617
791
      # nativethread check
618
 
      if !TkLib_Config["ruby_with_thread"] && tclconf['TCL_THREADS'] == '1'
619
 
        puts "\nWARNING: found #{tclpath.inspect}, but it WITH nativethread-support under ruby WITHOUT nativethread-support. So, ignore it."
620
 
        TkLib_Config["tcltk-NG-path"] << File.dirname(tclpath)
621
 
        next
 
792
      if !TkLib_Config["ruby_with_thread"]
 
793
        if tclconf
 
794
          if tclconf['TCL_THREADS'] == '1'
 
795
            puts "\nWARNING: found #{tclpath.inspect}, but it WITH nativethread-support under ruby WITHOUT nativethread-support. So, ignore it."
 
796
            TkLib_Config["tcl-NG-path"] << File.dirname(tclpath)
 
797
            next
 
798
          end
 
799
        else
 
800
          puts "\nWARNING: When not refer tclConfig.sh, cannot check native-thread support on Tcl/Tk libraries. Ruby, which is used now, does NOT support native-thread. So, if Tcl/Tk libraries support native-thread, it will NOT work properly."
 
801
        end
622
802
      end
623
803
 
624
804
      # find tclConfig.sh & tkConfig.sh
629
809
        # if use framework, not check (believe it is installed properly)
630
810
        tcllib_ok = tklib_ok = true
631
811
      else
632
 
        tcllib_ok, tklib_ok = libcheck_for_tclConfig(File.dirname(tclpath),
633
 
                                                      tclconf, tkconf)
634
 
=begin
635
 
        tcllib_ok = tklib_ok = false
636
 
        if TkLib_Config["tcltk-stubs"]
637
 
          stub = "stub"
638
 
          tclfunc = "Tcl_InitStubs"
639
 
          tkfunc  = "Tk_InitStubs"
640
 
        else
641
 
          stub = ""
642
 
          tclfunc = "Tcl_FindExecutable"
643
 
          tkfunc  = "Tk_Init"
644
 
        end
645
 
        dir = File.dirname(tclpath)
646
 
        libpath = $LIBPATH
647
 
        tcllibs = nil
648
 
 
649
 
        begin
650
 
          tcllib_ok ||= Dir.glob(File.join(dir, "*tcl#{stub}#{tclconf['TCL_MAJOR_VERSION']}{.,}#{tclconf['TCL_MINOR_VERSION']}*.*"), File::FNM_CASEFOLD).find{|file|
651
 
            if file =~ /^.*(tcl#{stub}#{tclconf['TCL_MAJOR_VERSION']}(\.|)#{tclconf['TCL_MINOR_VERSION']}.*)\.[^.]*$/
652
 
              #puts "check #{file} #{$1} #{tclfunc} #{dir}"
653
 
              #find_library($1, tclfunc, dir)
654
 
              tcllibs = append_library($libs, $1)
655
 
              $LIBPATH = libpath | [dir]
656
 
              try_func(tclfunc, tcllibs)
657
 
            end
658
 
          }
659
 
          tklib_ok ||= Dir.glob(File.join(dir, "*tk#{stub}#{tkconf['TK_MAJOR_VERSION']}{.,}#{tkconf['TK_MINOR_VERSION']}*.*"), File::FNM_CASEFOLD).find{|file|
660
 
            if file =~ /^.*(tk#{stub}#{tkconf['TK_MAJOR_VERSION']}(\.|)#{tkconf['TK_MINOR_VERSION']}.*)\.[^.]*$/
661
 
              #puts "check #{file} #{$1} #{tkfunc} #{dir}"
662
 
              # find_library($1, tkfunc, dir)
663
 
              tklibs = append_library(tcllibs, $1)
664
 
              $LIBPATH = libpath | [dir]
665
 
              try_func(tkfunc, tklibs)
666
 
            end
667
 
          }
668
 
        ensure
669
 
          $LIBPATH = libpath
670
 
        end
671
 
=end
 
812
        tcllib_ok, tklib_ok =
 
813
          libcheck_for_tclConfig((tclpath)? File.dirname(tclpath): nil,
 
814
                                 (tkpath)? File.dirname(tkpath): nil,
 
815
                                 tclconf, tkconf)
672
816
      end
673
817
 
674
818
      unless tcllib_ok && tklib_ok
675
 
        puts "\nWARNING: found #{tclpath.inspect}, but cannot find valid Tcl/Tk libraries on the same directory. So, ignore it."
676
 
        TkLib_Config["tcltk-NG-path"] << File.dirname(tclpath)
 
819
        unless tcllib_ok
 
820
          puts "\nWARNING: found #{tclpath.inspect}, but cannot find valid Tcl library for the tclConfig.sh. So, ignore it."
 
821
          TkLib_Config["tcl-NG-path"] << File.dirname(tclpath)
 
822
        end
 
823
        unless tklib_ok
 
824
          puts "\nWARNING: found #{tkpath.inspect}, but cannot find valid Tk library for the tkConfig.sh. So, ignore it."
 
825
          TkLib_Config["tk-NG-path"] << File.dirname(tkpath)
 
826
        end
677
827
        next
678
828
      end
679
829
 
702
852
end
703
853
 
704
854
def get_tclConfig(tclConfig_file, tkConfig_file, tclConfig_dir, tkConfig_dir)
705
 
  use_tclConfig = (tclConfig_file != false) && (tkConfig_file != false) && 
706
 
    (tclConfig_dir != false) && (tkConfig_dir != false)
 
855
  use_tclConfig = tclConfig_file != false && tclConfig_dir != false
 
856
  use_tkConfig  = tkConfig_file  != false && tkConfig_dir  != false
707
857
 
708
 
  unless use_tclConfig
 
858
  unless use_tclConfig || use_tkConfig
709
859
    puts("Don't use [tclConfig.sh, tkConfig.sh]")
710
860
    return [nil, nil]
711
861
  end
715
865
  tclConfig_dir = nil unless tclConfig_dir.kind_of? String
716
866
  tkConfig_dir = nil unless tkConfig_dir.kind_of? String
717
867
 
718
 
  unless tclConfig_dir
 
868
  if use_tclConfig && !tclConfig_dir
719
869
    if tclConfig_file
720
870
      tclConfig_dir = File.dirname(tclConfig_file)
721
871
    elsif tkConfig_dir
722
872
      tclConfig_dir = tkConfig_dir
723
873
    end
724
874
  end
725
 
  unless tkConfig_dir
 
875
  if use_tkConfig && !tkConfig_dir
726
876
    if tkConfig_file
727
877
      tkConfig_dir = File.dirname(tkConfig_file)
728
878
    elsif tclConfig_dir
731
881
  end
732
882
  tkConfig_dir ||= tclConfig_dir
733
883
 
734
 
  TkLib_Config["tclConfig-file"] = tclConfig_file
735
 
  TkLib_Config["tkConfig-file"] = tkConfig_file
736
 
  TkLib_Config["tclConfig-dir"] = tclConfig_dir
737
 
  TkLib_Config["tkConfig-dir"] = tkConfig_dir
738
 
 
739
 
  print("Search tclConfig.sh", (tclConfig_dir)? " (in #{tclConfig_dir})": "", 
740
 
        " and tkConfig.sh", (tkConfig_dir)? " (in #{tkConfig_dir})": "", ".")
741
 
  if tclConfig_dir
742
 
    tclConfig, tkConfig = 
743
 
      search_tclConfig([ ((tclConfig_file)? tclConfig_file: tclConfig_dir), 
 
884
  if use_tclConfig
 
885
    TkLib_Config["tclConfig-file"] = tclConfig_file
 
886
    TkLib_Config["tclConfig-dir"] = tclConfig_dir
 
887
  else
 
888
    tclConfig_file = false
 
889
    tclConfig_dir = false
 
890
  end
 
891
  if use_tkConfig
 
892
    TkLib_Config["tkConfig-file"] = tkConfig_file
 
893
    TkLib_Config["tkConfig-dir"] = tkConfig_dir
 
894
  else
 
895
    tkConfig_file = false
 
896
    tkConfig_dir = false
 
897
  end
 
898
 
 
899
  print ("Don't use tclConfig.sh (specified by configure option).\n") unless use_tclConfig
 
900
  print ("Don't use tkConfig.sh (specified by configure option).\n") unless use_tkConfig
 
901
  print("Search ")
 
902
  print("tclConfig.sh", (tclConfig_dir)? " (in #{tclConfig_dir})": "") if use_tclConfig
 
903
  print((use_tclConfig)? " and ": "", "tkConfig.sh", (tkConfig_dir)? " (in #{tkConfig_dir})": "") if use_tkConfig
 
904
  print(".")
 
905
 
 
906
  if tclConfig_dir || tkConfig_dir || !use_tclConfig || !use_tkConfig
 
907
    tclConfig, tkConfig =
 
908
      search_tclConfig([ ((tclConfig_file)? tclConfig_file: tclConfig_dir),
744
909
                         ((tkConfig_file)?  tkConfig_file:  tkConfig_dir) ])
745
910
  else
746
911
    tclConfig, tkConfig = search_tclConfig()
749
914
  # TclConfig_Info = TkLib_Config["tclConfig_info"]
750
915
  # TkConfig_Info  = TkLib_Config["tkConfig_info"]
751
916
 
752
 
  if tclConfig && tkConfig
 
917
  if tclConfig || tkConfig
753
918
    dirs = TkLib_Config["tclConfig_paths"].map{|tclpath, tkpath|
754
 
      File.dirname(tclpath)
 
919
      [ (tclpath)? File.dirname(tclpath): nil,
 
920
        (tkpath)? File.dirname(tkpath): nil ]
755
921
    }
756
922
    dirs |= dirs
757
 
    puts("Valid tclConfig.sh and tkConfig.sh are found in #{dirs.inspect}")
758
 
    puts("Use [tclConfig.sh,tkConfig.sh] == ['#{tclConfig}','#{tkConfig}']")
759
 
    $LIBPATH |= [File.dirname(tclConfig)]
760
 
    $LIBPATH |= [File.dirname(tkConfig)]
 
923
    puts("Valid [tclConfig.sh, tkConfig.sh] are found in #{dirs.inspect}")
 
924
    puts("Use [tclConfig.sh, tkConfig.sh] == #{[tclConfig, tkConfig].inspect}")
 
925
    $LIBPATH ||= []
 
926
    $LIBPATH |= [File.dirname(tclConfig)] if tclConfig
 
927
    $LIBPATH |= [File.dirname(tkConfig)]  if tkConfig
761
928
    #TkLib_Config["tclConfig_paths"].each{|tclcfg, tkcfg|
762
929
    #  $LIBPATH |= [File.dirname(tclcfg)] | [File.dirname(tkcfg)]
763
930
    #}
768
935
  [tclConfig, tkConfig]
769
936
end
770
937
 
 
938
def check_tcl_NG_path(path_list)
 
939
  path_list.find_all{|path| not TkLib_Config["tcl-NG-path"].include?(path) }
 
940
end
 
941
 
 
942
def check_tk_NG_path(path_list)
 
943
  path_list.find_all{|path| not TkLib_Config["tk-NG-path"].include?(path) }
 
944
end
 
945
 
771
946
def check_NG_path(path_list)
772
 
  path_list.find_all{|path| not TkLib_Config["tcltk-NG-path"].include?(path) }
 
947
  path_list.find_all{|path|
 
948
    not (TkLib_Config["tcl-NG-path"].include?(path) &&
 
949
         TkLib_Config["tk-NG-path"].include?(path))
 
950
  }
773
951
end
774
952
 
775
953
def check_shlib_search_path(paths)
830
1008
  end
831
1009
 
832
1010
  # keep paths for searching dynamic libs
833
 
  $LIBPATH |= path_list
 
1011
  #$LIBPATH |= path_list
 
1012
  path_list.uniq
834
1013
end
835
1014
 
836
1015
def search_vers_on_path(vers, path, *heads)
837
 
  if enable_config("shared") == false
838
 
    exts = CONFIG['LIBEXT'] + ',' + CONFIG['DLEXT']
839
 
  else
840
 
    exts = CONFIG['DLEXT'] + ',' + CONFIG['LIBEXT']
841
 
  end
842
 
  exts << ",dll,lib" if is_win32?
843
 
  exts << ",bundle,dylib" if is_macosx? || /nextstep|openstep|rhapsody/ =~ RUBY_PLATFORM
 
1016
  exts = get_ext_list.join(',')
844
1017
  files = Dir.glob(File.join(path, "*{#{heads.join(',')}}*.{#{exts}}"), File::FNM_CASEFOLD)
845
1018
  vers.find_all{|ver| files.find{|f| f =~ /(#{ver}|#{ver.delete('.')})/} }
846
1019
end
847
1020
 
848
1021
def find_tcl(tcllib, stubs, version, *opt_paths)
 
1022
  if TclConfig_Info['MKMF_PARAMS']
 
1023
    # already checked existence of tcl library based on tclConfig.sh
 
1024
    ($INCFLAGS ||= "") << " " << TclConfig_Info['MKMF_PARAMS']['INCFLAGS']
 
1025
    $LIBPATH ||= []; $LIBPATH |= TclConfig_Info['MKMF_PARAMS']['LIBPATH']
 
1026
    ($libs ||= "") << " " << TclConfig_Info['MKMF_PARAMS']['libs']
 
1027
    return [true, nil, nil, nil]
 
1028
  end
 
1029
  # else, no available tclConfig.sh on the system
 
1030
 
849
1031
  print "Search Tcl library"
850
1032
 
851
1033
  if stubs
877
1059
 
878
1060
  if !CROSS_COMPILING and is_win32?
879
1061
    default_paths.concat [
880
 
      "c:/Tcl/lib", "c:/Program Files/Tcl/lib",
881
 
      "/Tcl/lib", "/Program Files/Tcl/lib"
882
 
    ].find_all{|dir| File.directory?(dir)}
 
1062
      "c:/Tcl/lib","c:/Program Files/Tcl/lib","c:/Program Files (x86)/Tcl/lib",
 
1063
      "/Tcl/lib","/Program Files/Tcl/lib","/Program Files (x86)/Tcl/lib"
 
1064
    ].find_all{|dir| File.directory?(dir)}.map{|dir| File.expand_path(dir)}
 
1065
 
 
1066
    # for MinGW
 
1067
    ["/usr/local/lib64", "/usr/lib64", "/usr/local/lib", "/usr/lib"].each{|dir|
 
1068
      default_paths << File.expand_path(dir) if File.directory? dir
 
1069
    }
 
1070
 
 
1071
    default_paths |= ENV['LIBRARY_PATH'].split(';').find_all{|dir| File.directory? dir}.map{|dir| File.expand_path(dir)} if ENV['LIBRARY_PATH']
 
1072
    default_paths |= ENV['PATH'].split(';').find_all{|dir| File.directory? dir}.map{|dir| File.expand_path(dir)} if ENV['PATH']
883
1073
  end
884
1074
 
 
1075
  default_paths |= TkLib_Config["checked_shlib_dirs"]
 
1076
 
885
1077
  unless TkLib_Config["space-on-tk-libpath"]
886
1078
    default_paths.delete_if{|path| path =~ / /}
887
1079
  end
888
1080
 
889
1081
  if (paths = opt_paths.compact).empty?
890
 
    unless TclConfig_Info['config_file_path']
891
 
      paths = check_NG_path(default_paths)
892
 
 
893
 
    else
894
 
      # use definisions on tclConfig.sh
895
 
      TclConfig_Info['TCL_LIB_SPEC'].sub(TclConfig_Info['TCL_LIB_FLAG'],"").strip.sub("-L","") =~ /("|'|)([^"']+)\1/
896
 
      $LIBPATH |= [$2] unless $2.empty?
897
 
 
898
 
      if stubs
899
 
        if TclConfig_Info['TCL_SUPPORTS_STUBS'] == '0' ||
900
 
            TclConfig_Info['TCL_STUB_LIB_SPEC'].strip.empty?
901
 
          print(".\n") # progress
902
 
          puts "#{TclConfig_Info['config_file_path']} tells us that your Tcl/Tk library doesn't support stub."
903
 
          return false
904
 
        else
905
 
          #*** Probably, TCL_LIBS is a subset of TK_LIBS. ***
906
 
          unless is_win32? # ignore tclConfig on Windows
907
 
            # $LDFLAGS << ' ' << TclConfig_Info['TCL_LIBS']
908
 
            # $DLDFLAGS << ' ' << TclConfig_Info['TCL_LIBS']
909
 
            $LDFLAGS << ' ' << TclConfig_Info['TCL_STUB_LIB_SPEC']
910
 
          end
 
1082
    paths = check_tcl_NG_path(default_paths)
 
1083
  end
 
1084
 
 
1085
  incflags = ($INCFLAGS ||= "").dup
 
1086
  libpath = ($LIBPATH ||= []).dup
 
1087
  libs_param = ($libs ||= "").dup
 
1088
  tcllibs = nil
 
1089
 
 
1090
  exts = "(" + get_ext_list.join('|') + ")"
 
1091
 
 
1092
  paths.map{|path|
 
1093
    lib_w_sufx = lib
 
1094
    begin
 
1095
      $LIBPATH |= [path]
 
1096
      inc = [File.join(File.dirname(path),"include"), File.dirname(path)]
 
1097
      inc.each{|f| $INCFLAGS << " -I" << f }
 
1098
 
 
1099
      if tcllib
 
1100
        print(".")
 
1101
        if have_library(tcllib, func, ["tcl.h"])
 
1102
          return [true, path, lib_w_sufx, nil, *inc]
911
1103
        end
912
1104
      else
913
 
        #*** Probably, TCL_LIBS is a subset of TK_LIBS. ***
914
 
        unless is_win32? # ignore tclConfig on Windows
915
 
          # $LDFLAGS << ' ' << TclConfig_Info['TCL_LIBS']
916
 
          # $DLDFLAGS << ' ' << TclConfig_Info['TCL_LIBS']
917
 
          $LDFLAGS << ' ' << TclConfig_Info['TCL_LIB_SPEC']
 
1105
        sufx_list = ['', 't', 'g', 's', 'x']
 
1106
        search_vers_on_path(versions, path, lib, 'tcl').find{|ver|
 
1107
          dir_enum = Dir.foreach(path)
 
1108
          no_dot_ver = ver.delete('.')
 
1109
          libnames = ["#{lib}#{ver}", "#{lib}#{no_dot_ver}"]
 
1110
          libnames << "tcl#{ver}" << "tcl#{no_dot_ver}"  if lib != "tcl"
 
1111
          libnames.find{|libname|
 
1112
            sufx_list.find{|sufx|
 
1113
              print(".")
 
1114
              dir_enum.map{|fname|
 
1115
                if fname =~ /^.*(#{libname}.*#{sufx})\.(#{exts}).*$/
 
1116
                  [fname, $1, $2]
 
1117
                end
 
1118
              }.compact.find{|fname, lib_w_sufx, ext|
 
1119
                ext.downcase!
 
1120
                if (ext != CONFIG['DLEXT'] && ext == CONFIG['LIBEXT']) ||
 
1121
                    ext == "a"
 
1122
                  # static link
 
1123
                  tcllibs = libs_param + " -DSTATIC_BUILD " + fname.quote
 
1124
                else
 
1125
                  tcllibs = append_library($libs, lib_w_sufx)
 
1126
                  tcllibs = "-L#{path.quote} " + tcllibs
 
1127
                end
 
1128
                if try_func(func, tcllibs, ["tcl.h"])
 
1129
                  return [true, path, nil, tcllibs, *inc]
 
1130
                end
 
1131
              }
 
1132
            }
 
1133
          }
 
1134
        }
 
1135
        if (!version && (print(".");try_func(func, libs_param, ["tcl.h"])))
 
1136
          return [true, path, lib_w_sufx, nil, *inc]
918
1137
        end
919
1138
      end
920
 
 
921
 
      paths = [File.dirname(TclConfig_Info['config_file_path'])]
922
 
      versions = [TclConfig_Info['TCL_VERSION']]
923
 
    end
924
 
  end
925
 
 
926
 
  ret = paths.map{|path|
927
 
    if tcllib
928
 
      print(".")
929
 
      [path, find_library(tcllib, func, path)]
930
 
    else
931
 
      st = search_vers_on_path(versions, path, lib, 'tcl').find{|ver|
932
 
        (print(".");find_library("#{lib}#{ver}", func, path)) or
933
 
          (print(".");find_library("#{lib}#{ver.delete('.')}", func, path)) or
934
 
          (print(".");find_library("#{lib}#{ver}g", func, path)) or
935
 
          (print(".");find_library("#{lib}#{ver.delete('.')}g", func, path)) or
936
 
          (print(".");find_library("tcl#{ver}", func, path)) or
937
 
          (print(".");find_library("tcl#{ver.delete('.')}", func, path)) or
938
 
          (print(".");find_library("tcl#{ver}g", func, path)) or
939
 
          (print(".");find_library("tcl#{ver.delete('.')}g", func, path))
940
 
      } || (!version && (print(".");find_library(lib, func, path)))
941
 
      [path, st]
 
1139
    ensure
 
1140
      $LIBPATH = libpath.dup
 
1141
      $libs = libs_param.dup
 
1142
      $INCFLAGS = incflags.dup
942
1143
    end
943
1144
  }
944
1145
 
945
1146
  print("\n") # progress
946
 
  ret
 
1147
  [false, nil, nil, nil]
947
1148
end
948
1149
 
949
1150
def parse_TK_LIBS(tklibs)
962
1163
end
963
1164
 
964
1165
def find_tk(tklib, stubs, version, *opt_paths)
 
1166
  if TkConfig_Info['MKMF_PARAMS']
 
1167
    # already checked existence of tcl library based on tkConfig.sh
 
1168
    ($INCFLAGS ||= "") << " " << TkConfig_Info['MKMF_PARAMS']['INCFLAGS']
 
1169
    $LIBPATH ||= []; $LIBPATH |= TkConfig_Info['MKMF_PARAMS']['LIBPATH']
 
1170
    ($libs ||= "") << " " << TkConfig_Info['MKMF_PARAMS']['libs']
 
1171
    return [true, nil, nil, nil]
 
1172
  end
 
1173
  # else, no available tkConfig.sh on the system
 
1174
 
965
1175
  print "Search Tk library"
966
1176
 
967
1177
  if stubs
989
1199
 
990
1200
  if !CROSS_COMPILING and is_win32?
991
1201
    default_paths.concat [
992
 
      "c:/Tcl/lib", "c:/Program Files/Tcl/lib",
993
 
      "/Tcl/lib", "/Program Files/Tcl/lib"
 
1202
      "c:/Tcl/lib","c:/Program Files/Tcl/lib","c:/Program Files (x86)/Tcl/lib",
 
1203
      "/Tcl/lib","/Program Files/Tcl/lib","/Program Files (x86)/Tcl/lib"
994
1204
    ].find_all{|dir| File.directory?(dir)}
 
1205
 
 
1206
    # for MinGW
 
1207
    ["/usr/local/lib64", "/usr/lib64", "/usr/local/lib", "/usr/lib"].each{|dir|
 
1208
      default_paths << File.expand_path(dir) if File.directory? dir
 
1209
    }
 
1210
 
 
1211
    default_paths |= ENV['LIBRARY_PATH'].split(';').find_all{|dir| File.directory? dir}.map{|dir| File.expand_path(dir)} if ENV['LIBRARY_PATH']
 
1212
    default_paths |= ENV['PATH'].split(';').find_all{|dir| File.directory? dir}.map{|dir| File.expand_path(dir)} if ENV['PATH']
995
1213
  end
996
1214
 
 
1215
  default_paths |= TkLib_Config["checked_shlib_dirs"]
 
1216
 
997
1217
  unless TkLib_Config["space-on-tk-libpath"]
998
1218
    default_paths.delete_if{|path| path =~ / /}
999
1219
  end
1000
1220
 
1001
1221
  if (paths = opt_paths.compact).empty?
1002
 
    unless TkConfig_Info['config_file_path']
1003
 
      paths = check_NG_path(default_paths)
1004
 
 
1005
 
    else
1006
 
      # use definisions on tkConfig.sh
1007
 
      TkConfig_Info['TK_LIB_SPEC'].sub(TkConfig_Info['TK_LIB_FLAG'],"").strip.sub("-L","") =~ /("|'|)([^"']+)\1/
1008
 
      $LIBPATH |= [$2] unless $2.empty?
1009
 
 
1010
 
      if stubs
1011
 
        if TkConfig_Info['TK_STUB_LIB_SPEC'].strip.empty?
1012
 
          print(".\n") # progress
1013
 
          puts "#{TkConfig_Info['config_file_path']} tells us that your Tcl/Tk library doesn't support stub."
1014
 
          return false
1015
 
        else
1016
 
          unless is_win32? # ignore tclConfig on Windows
1017
 
            # $LDFLAGS << ' ' << parse_TK_LIBS(TkConfig_Info['TK_LIBS'])
1018
 
            $LDFLAGS << ' ' << TkConfig_Info['TK_LIBS']
1019
 
            # $DLDFLAGS << ' ' << parse_TK_LIBS(TkConfig_Info['TK_LIBS'])
1020
 
            $LDFLAGS << ' ' << TkConfig_Info['TK_STUB_LIB_SPEC']
1021
 
          end
 
1222
    paths = check_tk_NG_path(default_paths)
 
1223
  end
 
1224
 
 
1225
  incflags = ($INCFLAGS ||= "").dup
 
1226
  libpath = ($LIBPATH ||= []).dup
 
1227
  libs_param = ($libs ||= "").dup
 
1228
  tcllibs = nil
 
1229
 
 
1230
  exts = "(" + get_ext_list.join('|') + ")"
 
1231
 
 
1232
  paths.map{|path|
 
1233
    lib_w_sufx = lib
 
1234
    begin
 
1235
      $LIBPATH |= [path]
 
1236
      inc = [File.join(File.dirname(path),"include"), File.dirname(path)]
 
1237
      inc.each{|f| $INCFLAGS << " -I" << f }
 
1238
 
 
1239
      if tklib
 
1240
        print(".")
 
1241
        if have_library(tklib, func, ["tcl.h", "tk.h"])
 
1242
          return [true, path, lib_w_sufx, nil, *inc]
1022
1243
        end
1023
1244
      else
1024
 
        unless is_win32? # ignore tclConfig on Windows
1025
 
          # $LDFLAGS << ' ' << parse_TK_LIBS(TkConfig_Info['TK_LIBS'])
1026
 
          $LDFLAGS << ' ' << TkConfig_Info['TK_LIBS'] unless is_win32?
1027
 
          # $DLDFLAGS << ' ' << parse_TK_LIBS(TkConfig_Info['TK_LIBS'])
1028
 
          $LDFLAGS << ' ' << TkConfig_Info['TK_LIB_SPEC'] unless is_win32?
 
1245
        sufx_list = ['', 't', 'g', 's', 'x']
 
1246
        search_vers_on_path(versions, path, lib, 'tk').find{|ver|
 
1247
          dir_enum = Dir.foreach(path)
 
1248
          no_dot_ver = ver.delete('.')
 
1249
          libnames = ["#{lib}#{ver}", "#{lib}#{no_dot_ver}"]
 
1250
          libnames << "tk#{ver}" << "tk#{no_dot_ver}"  if lib != "tk"
 
1251
          libnames.find{|libname|
 
1252
            sufx_list.find{|sufx|
 
1253
              print(".")
 
1254
              dir_enum.map{|fname|
 
1255
                if fname =~ /^.*(#{libname}.*#{sufx})\.(#{exts}).*$/
 
1256
                  [fname, $1, $2]
 
1257
                end
 
1258
              }.compact.find{|fname, lib_w_sufx, ext|
 
1259
                if (ext != CONFIG['DLEXT'] && ext == CONFIG['LIBEXT']) ||
 
1260
                    ext == "a"
 
1261
                  # static link
 
1262
                  tklibs = libs_param + " -DSTATIC_BUILD " + fname.quote
 
1263
                else
 
1264
                  tklibs = append_library($libs, lib_w_sufx)
 
1265
                  tklibs = "-L#{path.quote} " + tklibs
 
1266
                end
 
1267
                if try_func(func, tklibs, ["tcl.h", "tk.h"])
 
1268
                  return [true, path, nil, tklibs, *inc]
 
1269
                end
 
1270
              }
 
1271
            }
 
1272
          }
 
1273
        }
 
1274
        if (!version && (print(".");try_func(func, libs_param, ["tcl.h", "tk.h"])))
 
1275
          return [true, path, lib_w_sufx, nil, *inc]
1029
1276
        end
1030
1277
      end
1031
 
 
1032
 
      paths = [File.dirname(TkConfig_Info['config_file_path'])]
1033
 
      versions = [TkConfig_Info['TK_VERSION']]
1034
 
    end
1035
 
  end
1036
 
 
1037
 
  ret = paths.map{|path|
1038
 
    if tklib
1039
 
      print(".")
1040
 
      [path, find_library(tklib, func, path)]
1041
 
    else
1042
 
      st = search_vers_on_path(versions, path, lib, 'tk').find{|ver|
1043
 
        (print(".");find_library("#{lib}#{ver}", func, path)) or
1044
 
          (print(".");find_library("#{lib}#{ver.delete('.')}", func, path)) or
1045
 
          (print(".");find_library("#{lib}#{ver}g", func, path)) or
1046
 
          (print(".");find_library("#{lib}#{ver.delete('.')}g", func, path)) or
1047
 
          (print(".");find_library("tk#{ver}", func, path)) or
1048
 
          (print(".");find_library("tk#{ver.delete('.')}", func, path)) or
1049
 
          (print(".");find_library("tk#{ver}g", func, path)) or
1050
 
          (print(".");find_library("tk#{ver.delete('.')}g", func, path))
1051
 
      } || (!version && (print(".");find_library(lib, func, path)))
1052
 
      [path, st]
 
1278
    ensure
 
1279
      $LIBPATH = libpath
 
1280
      $libs = libs_param
 
1281
      $INCFLAGS = incflags.dup
1053
1282
    end
1054
1283
  }
1055
1284
 
1056
1285
  print("\n") # progress
1057
 
  ret
 
1286
  [false, nil, nil, nil]
1058
1287
end
1059
1288
 
1060
 
def find_tcltk_library(tcllib, tklib, stubs, tclversion, tkversion, 
 
1289
def find_tcltk_library(tcllib, tklib, stubs, tclversion, tkversion,
1061
1290
                       tcl_opt_paths, tk_opt_paths)
1062
 
  ret = find_tcl(tcllib, stubs, tclversion, *tcl_opt_paths)
1063
 
  unless ret && ret.find{|path, val| val}
1064
 
    puts("Warning:: cannot find Tcl library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options.")
 
1291
  st,path,lib,libs,*inc = find_tcl(tcllib, stubs, tclversion, *tcl_opt_paths)
 
1292
  unless st
 
1293
    puts("Warning:: cannot find Tcl library. tcltklib will not be compiled (tcltklib is disabled on your Ruby. That is, Ruby/Tk will not work). Please check configure options.")
1065
1294
    return false
 
1295
  else
 
1296
    ($LIBPATH ||= []; $LIBPATH |= [path]) if path
 
1297
    $libs = append_library($libs, lib) if lib
 
1298
    ($libs ||= "") << " " << libs if libs
 
1299
    $INCFLAGS ||= ""
 
1300
    inc.each{|f| $INCFLAGS << " -I" << f}
1066
1301
  end
1067
1302
 
1068
 
  ret = find_tk(tklib, stubs, tkversion, *tk_opt_paths)
1069
 
  unless ret && ret.find{|path, val| val}
1070
 
    puts("Warning:: cannot find Tk library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options.")
 
1303
  st,path,lib,libs,*inc = find_tk(tklib, stubs, tkversion, *tk_opt_paths)
 
1304
  unless st
 
1305
    puts("Warning:: cannot find Tk library. tcltklib will not be compiled (tcltklib is disabled on your Ruby. That is, Ruby/Tk will not work). Please check configure options.")
1071
1306
    return false
 
1307
  else
 
1308
    ($LIBPATH ||= []; $LIBPATH |= [path]) if path
 
1309
    $libs = append_library($libs, lib) if lib && !lib.empty?
 
1310
    ($libs ||= "") << " " << libs if libs
 
1311
    $INCFLAGS ||= ""
 
1312
    inc.each{|f| $INCFLAGS << " -I" << f}
1072
1313
  end
1073
1314
 
1074
1315
  true
1081
1322
    File.join(RbConfig::CONFIG['prefix'], 'include'),
1082
1323
    "/usr/local/include", "/usr/pkg/include", "/usr/contrib/include",
1083
1324
    "/usr/include"
1084
 
  ].find_all{|dir| File.directory?(dir)}
 
1325
  ].find_all{|dir| File.directory?(dir)}.map{|dir| File.expand_path(dir)}
1085
1326
 
1086
1327
  if !CROSS_COMPILING && is_win32?
1087
1328
    base_dir.concat [
1088
 
      "c:/Tcl/include", "c:/Program Files/Tcl/include",
1089
 
      "/Tcl/include", "/Program Files/Tcl/include"
1090
 
    ].find_all{|dir| File.directory?(dir)}
 
1329
      "c:/Tcl/include","c:/Program Files/Tcl/include",
 
1330
      "c:/Program Files (x86)/Tcl/include",
 
1331
      "/Tcl/include","/Program Files/Tcl/include",
 
1332
      "/Program Files (x86)/Tcl/include"
 
1333
    ].find_all{|dir| File.directory?(dir)}.map{|dir| File.expand_path(dir)}
 
1334
 
 
1335
    if ENV['CPATH']
 
1336
      base_dir |= ENV['CPATH'].split(';').find_all{|dir| File.directory?(dir)}.map{|dir| File.expand_path(dir)}
 
1337
    end
1091
1338
  end
1092
1339
 
 
1340
  base_dir |= TkLib_Config["checked_shlib_dirs"]
 
1341
 
1093
1342
  unless TkLib_Config["space-on-tk-libpath"]
1094
1343
    base_dir.delete_if{|path| path =~ / /}
1095
1344
  end
1096
1345
 
1097
 
  if TclConfig_Info['TCL_INCLUDE_SPEC'] && 
1098
 
      have_tcl_h = try_cpp('#include <tcl.h>', TclConfig_Info['TCL_INCLUDE_SPEC'])
1099
 
    $INCFLAGS << " " << TclConfig_Info['TCL_INCLUDE_SPEC']
1100
 
  elsif have_tcl_h = have_header('tcl.h')
1101
 
    # find
1102
 
  else
1103
 
    if tclver && ! tclver.empty?
1104
 
      versions = [tclver]
1105
 
    else
1106
 
      versions = TkLib_Config['search_versions']
1107
 
    end
1108
 
    paths = base_dir.dup
1109
 
    versions.each{|ver| 
1110
 
      paths.concat(base_dir.map{|dir|
1111
 
                     [dir + '/tcl' + ver, dir + '/tcl' + ver.delete('.')]
1112
 
                   }.flatten)
1113
 
    }
1114
 
    have_tcl_h = find_header('tcl.h', *paths)
1115
 
  end
1116
 
 
1117
 
  if TkConfig_Info['TK_INCLUDE_SPEC'] && 
1118
 
      have_tk_h = try_cpp('#include <tk.h>', TkConfig_Info['TK_INCLUDE_SPEC'])
1119
 
    $INCFLAGS << " " << TkConfig_Info['TK_INCLUDE_SPEC']
1120
 
  elsif have_tk_h = have_header('tk.h')
1121
 
    # find
1122
 
  else
1123
 
    if tkver && ! tkver.empty?
1124
 
      versions = [tkver]
1125
 
    else
1126
 
      versions = TkLib_Config['search_versions']
1127
 
    end
1128
 
    paths = base_dir.dup
1129
 
    versions.each{|ver| 
1130
 
      paths.concat(base_dir.map{|dir|
1131
 
                     [dir + '/tk' + ver, dir + '/tk' + ver.delete('.')]
1132
 
                   }.flatten)
1133
 
    }
1134
 
    have_tk_h = find_header('tk.h', *paths)
1135
 
  end
1136
 
 
 
1346
  # tcl.h
 
1347
  if TclConfig_Info['MKMF_PARAMS']
 
1348
    # already checked existence of tcl headers based on tclConfig.sh
 
1349
    have_tcl_h = true
 
1350
  else
 
1351
    print "\nSearch tcl.h"
 
1352
    if enable_config("tcl-h-ver-check", true) &&
 
1353
        tclver && tclver =~ /^\D*(\d)\.?(\d)/
 
1354
      major = $1; minor = $2
 
1355
    else
 
1356
      major = minor = nil
 
1357
    end
 
1358
    print(".") # progress
 
1359
    if major && minor
 
1360
      # version check on tcl.h
 
1361
      have_tcl_h = try_cpp("#include <tcl.h>\n#if TCL_MAJOR_VERSION != #{major} || TCL_MINOR_VERSION != #{minor}\n#error VERSION does not match\n#endif")
 
1362
    else
 
1363
      have_tcl_h = have_header('tcl.h')
 
1364
    end
 
1365
    unless have_tcl_h
 
1366
      if tclver && ! tclver.empty?
 
1367
        versions = [tclver]
 
1368
      else
 
1369
        versions = TkLib_Config['search_versions']
 
1370
      end
 
1371
      paths = base_dir.dup
 
1372
      (versions + [""]).each{|ver|
 
1373
        paths.concat(base_dir.map{|dir|
 
1374
                       [
 
1375
                        dir + '/tcl' + ver,
 
1376
                        dir + '/tcl' + ver + '/include',
 
1377
                        dir + '/tcl' + ver.delete('.'),
 
1378
                        dir + '/tcl' + ver.delete('.') + '/include'
 
1379
                       ]
 
1380
                     }.flatten)
 
1381
      }
 
1382
      paths = paths.map{|dir|
 
1383
        (File.directory?(dir))? File.expand_path(dir): nil
 
1384
      }.compact.uniq
 
1385
 
 
1386
      code = "#include <tcl.h>\n"
 
1387
      code << "#if TCL_MAJOR_VERSION != #{major}\n#error MAJOR_VERSION does not match\n#endif\n" if major
 
1388
      code << "#if TCL_MINOR_VERSION != #{minor}\n#error MINOR_VERSION does not match\n#endif\n" if minor
 
1389
      have_tcl_h = paths.find{|path|
 
1390
        print(".") # progress
 
1391
        inc_opt = " -I#{path.quote}"
 
1392
        if try_cpp(code, inc_opt)
 
1393
          ($INCFLAGS ||= "") << inc_opt
 
1394
          true
 
1395
        else
 
1396
          false
 
1397
        end
 
1398
      }
 
1399
    end
 
1400
  end
 
1401
 
 
1402
  # tk.h
 
1403
  if TkConfig_Info['MKMF_PARAMS']
 
1404
    # already checked existence of tk headers based on tkConfig.sh
 
1405
    have_tk_h = true
 
1406
  else
 
1407
    print "\nSearch tk.h"
 
1408
    if enable_config("tk-h-ver-check", true) &&
 
1409
        tkver && tkver =~ /^\D*(\d)\.?(\d)/
 
1410
      major = $1; minor = $2
 
1411
    else
 
1412
      major = minor = nil
 
1413
    end
 
1414
    print(".") # progress
 
1415
    if major && minor
 
1416
      # version check on tk.h
 
1417
      have_tk_h = try_cpp("#include <tk.h>\n#if TK_MAJOR_VERSION != #{major} || TK_MINOR_VERSION != #{minor}\n#error VERSION does not match\n#endif")
 
1418
    else
 
1419
      have_tk_h = have_header('tk.h')
 
1420
    end
 
1421
    unless have_tk_h
 
1422
      if tkver && ! tkver.empty?
 
1423
        versions = [tkver]
 
1424
      else
 
1425
        versions = TkLib_Config['search_versions']
 
1426
      end
 
1427
      paths = base_dir.dup
 
1428
      (versions + [""]).each{|ver|
 
1429
        paths.concat(base_dir.map{|dir|
 
1430
                       [
 
1431
                        dir + '/tk' + ver,
 
1432
                        dir + '/tk' + ver + '/include',
 
1433
                        dir + '/tk' + ver.delete('.'),
 
1434
                        dir + '/tk' + ver.delete('.') + '/include'
 
1435
                       ]
 
1436
                     }.flatten)
 
1437
      }
 
1438
      paths = paths.map{|dir|
 
1439
        (File.directory?(dir))? File.expand_path(dir): nil
 
1440
      }.compact.uniq
 
1441
 
 
1442
      code = "#include <tcl.h>\n#include <tk.h>\n"
 
1443
      code << "#if TK_MAJOR_VERSION != #{major}\n#error MAJOR_VERSION does not match\n#endif\n" if major
 
1444
      code << "#if TK_MINOR_VERSION != #{minor}\n#error MINOR_VERSION does not match\n#endif\n" if minor
 
1445
      have_tk_h = paths.find{|path|
 
1446
        print(".") # progress
 
1447
        inc_opt = " -I#{path.quote}"
 
1448
        if try_cpp(code, inc_opt)
 
1449
          ($INCFLAGS ||= "") << inc_opt
 
1450
          true
 
1451
        else
 
1452
          false
 
1453
        end
 
1454
      }
 
1455
    end
 
1456
  end
 
1457
 
 
1458
  puts "Can't find \"tcl.h\"." unless have_tcl_h
 
1459
  puts "Can't find \"tk.h\"."  unless have_tk_h
1137
1460
  have_tcl_h && have_tk_h
1138
1461
end
1139
1462
 
1140
1463
def setup_for_macosx_framework(tclver, tkver)
1141
1464
  # use framework, but no tclConfig.sh
1142
 
  unless $LDFLAGS.include?('-framework')
1143
 
    $LDFLAGS << ' -framework Tk -framework Tcl'
 
1465
  unless $LDFLAGS && $LDFLAGS.include?('-framework')
 
1466
    ($LDFLAGS ||= "") << ' -framework Tk -framework Tcl'
1144
1467
  end
1145
1468
 
1146
1469
  if TkLib_Config["tcl-framework-header"]
1147
 
    TclConfig_Info['TCL_INCLUDE_SPEC'] <<
1148
 
      "-I#{TkLib_Config["tcl-framework-header"].quote} "
 
1470
    TclConfig_Info['TCL_INCLUDE_SPEC'][0,0] =
 
1471
      " -I#{TkLib_Config["tcl-framework-header"].quote} "
1149
1472
  else
1150
 
    TclConfig_Info['TCL_INCLUDE_SPEC'] = ""
1151
 
 
1152
1473
    tcl_base = File.join(TkLib_Config["tcltk-framework"], 'Tcl.framework')
1153
1474
    if tclver
1154
1475
      TclConfig_Info['TCL_INCLUDE_SPEC'] <<
1155
 
        "-I#{File.join(tcl_base, 'Versions', tclver, 'Headers').quote} "
 
1476
        " -I#{File.join(tcl_base, 'Versions', tclver, 'Headers').quote} "
1156
1477
    end
1157
1478
 
1158
1479
    TclConfig_Info['TCL_INCLUDE_SPEC'] << File.join(tcl_base, 'Headers')
1159
1480
 
1160
1481
    unless tclver
1161
 
      dir = Dir.glob(File.join(tcl_base, 'Versions', '*', 'Headers'), 
 
1482
      dir = Dir.glob(File.join(tcl_base, 'Versions', '*', 'Headers'),
1162
1483
                     File::FNM_CASEFOLD).sort.reverse[0]
1163
1484
      TclConfig_Info['TCL_INCLUDE_SPEC'] << "-I#{dir.quote} " if dir
1164
1485
    end
1165
1486
  end
1166
1487
 
1167
1488
  if TkLib_Config["tk-framework-header"]
1168
 
    TkConfig_Info['TK_INCLUDE_SPEC'] = 
1169
 
      "-I#{TkLib_Config["tk-framework-header"].quote} "
 
1489
    TkConfig_Info['TK_INCLUDE_SPEC'][0,0] =
 
1490
      " -I#{TkLib_Config["tk-framework-header"].quote} "
1170
1491
  else
1171
 
    TkConfig_Info['TK_INCLUDE_SPEC'] = ""
1172
 
 
1173
1492
    tk_base  = File.join(TkLib_Config["tcltk-framework"], 'Tk.framework')
1174
1493
    if tkver
1175
1494
      TkConfig_Info['TK_INCLUDE_SPEC'] <<
1176
 
        "-I#{File.join(tk_base, 'Versions', tkver, 'Headers').quote} "
 
1495
        " -I#{File.join(tk_base, 'Versions', tkver, 'Headers').quote} "
1177
1496
    end
1178
1497
 
1179
1498
    TkConfig_Info['TK_INCLUDE_SPEC'] << File.join(tk_base, 'Headers')
1180
1499
 
1181
1500
    unless tkver
1182
 
      dir = Dir.glob(File.join(tk_base, 'Versions', '*', 'Headers'), 
 
1501
      dir = Dir.glob(File.join(tk_base, 'Versions', '*', 'Headers'),
1183
1502
                     File::FNM_CASEFOLD).sort.reverse[0]
1184
1503
      TkConfig_Info['TK_INCLUDE_SPEC'] << "-I#{dir.quote} " if dir
1185
1504
    end
1194
1513
  defaults.compact.each{|path| paths.concat(Dir.glob(path.strip.chomp('/'), File::FNM_CASEFOLD))}
1195
1514
  st = find_library("X11", "XOpenDisplay", *paths)
1196
1515
  unless st
1197
 
    puts("Warning:: cannot find X11 library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options. If your Tcl/Tk don't require X11, please try --without-X11.")
 
1516
    puts("Warning:: cannot find X11 library. tcltklib will not be compiled (tcltklib is disabled on your Ruby. That is, Ruby/Tk will not work). Please check configure options. If your Tcl/Tk don't require X11, please try --without-X11.")
1198
1517
  end
1199
1518
  st
1200
1519
end
1201
1520
 
1202
1521
def search_X_libraries
 
1522
  use_tkConfig = false
1203
1523
  if TkConfig_Info['config_file_path']
1204
1524
    # use definitions on tkConfig.sh
1205
 
    if TkConfig_Info['TK_XINCLUDES'] && TkConfig_Info['TK_XLIBSW'] &&
1206
 
        !TkConfig_Info['TK_XINCLUDES'].strip.empty? &&
1207
 
        !TkConfig_Info['TK_XLIBSW'].strip.empty?
 
1525
    if (TkConfig_Info['TK_XINCLUDES'] &&
 
1526
        !TkConfig_Info['TK_XINCLUDES'].strip.empty?) ||
 
1527
        (TkConfig_Info['TK_XLIBSW'] && !TkConfig_Info['TK_XLIBSW'].strip.empty?)
 
1528
      use_tkConfig = true
1208
1529
      #use_X = true && with_config("X11", ! is_win32?)
1209
1530
      use_X = with_config("X11", true)
1210
1531
    else
1216
1537
    use_X = with_config("X11", !(is_win32? || TkLib_Config["tcltk-framework"]))
1217
1538
  end
1218
1539
 
 
1540
  if TkConfig_Info['TK_XINCLUDES'] &&
 
1541
      !TkConfig_Info['TK_XINCLUDES'].strip.empty?
 
1542
    ($INCFLAGS ||= "") << " " << TkConfig_Info['TK_XINCLUDES'].strip
 
1543
  end
 
1544
 
1219
1545
  if use_X
1220
 
    puts("Use X11 libraries.")
 
1546
    puts("Use X11 libraries (or use TK_XINCLUDES/TK_XLIBSW information on tkConfig.sh).")
1221
1547
    x11_idir, x11_ldir = dir_config("X11")
1222
1548
    x11_ldir2 = with_config("X11-lib")
1223
1549
    unless find_X11(x11_ldir2, x11_ldir)
1224
 
      puts("Can't find X11 libraries. So, can't make tcltklib.so which is required by Ruby/Tk.")
1225
 
      exit
 
1550
      puts("Can't find X11 libraries. ")
 
1551
      if use_tkConfig &&
 
1552
          TkConfig_Info['TK_XLIBSW'] && !TkConfig_Info['TK_XLIBSW'].strip.empty?
 
1553
        puts("But, try to use TK_XLIBSW information (believe tkCOnfig.sh).")
 
1554
        ($libs ||= "") << " " << TkConfig_Info['TK_XLIBSW'] << " "
 
1555
      else
 
1556
        puts("So, can't make tcltklib.so which is required by Ruby/Tk.")
 
1557
        exit
 
1558
      end
1226
1559
    end
1227
1560
  end
1228
1561
 
1229
 
  if TkConfig_Info['TK_XINCLUDES'] &&
1230
 
      !TkConfig_Info['TK_XINCLUDES'].strip.empty?
1231
 
    $INCFLAGS << " " << TkConfig_Info['TK_XINCLUDES'].strip
1232
 
  end
1233
 
 
1234
1562
  use_X
1235
1563
end
1236
1564
 
1272
1600
        else
1273
1601
          puts("Warning: '#{TclConfig_Info['config_file_path']}' may not be a tclConfig file.")
1274
1602
        end
1275
 
        tclConfig = false
 
1603
        #tclConfig = false
1276
1604
      end
1277
1605
    end
1278
1606
  end
1280
1608
  if tcl_enable_thread == nil && !TclConfig_Info['config_file_path']
1281
1609
    # tcl-thread is unknown and tclConfig is unavailable
1282
1610
    begin
1283
 
      try_run_available = try_run("int main() { exit(0); }")
 
1611
      try_run("int main() { exit(0); }")
1284
1612
    rescue Exception
1285
1613
      # cannot try_run. Is CROSS-COMPILE environment?
1286
1614
      puts(%Q'\
1288
1616
**
1289
1617
** NATIVETHREAD SUPPORT CHECK WARNING:
1290
1618
**
1291
 
**   We cannot check the consistency of nativethread support between 
 
1619
**   We cannot check the consistency of nativethread support between
1292
1620
**   Ruby and the Tcl/Tk library in your environment (are you perhaps
1293
 
**   cross-compiling?). If nativethread support for these 2 packages 
 
1621
**   cross-compiling?). If nativethread support for these 2 packages
1294
1622
**   is inconsistent you may find you get errors when running Ruby/Tk
1295
1623
**   (e.g. hangs or segmentation faults).  We strongly recommend
1296
1624
**   you to check the consistency manually.
1325
1653
 
1326
1654
  # check pthread mode
1327
1655
  if (TkLib_Config["ruby_with_thread"])
 
1656
    $CPPFLAGS ||= ""
 
1657
 
1328
1658
    # ruby -> enable
1329
1659
    unless tcl_enable_thread
1330
1660
      # ruby -> enable && tcl -> disable
1333
1663
**
1334
1664
** NATIVETHREAD SUPPORT MODE WARNING:
1335
1665
**
1336
 
**   Ruby is compiled with --enable-pthread, but your Tcl/Tk library 
1337
 
**   seems to be compiled without nativethread support. Although you can 
1338
 
**   create the tcltklib library, this combination may cause errors (e.g. 
1339
 
**   hangs or segmentation faults). If you have no reason to keep the 
1340
 
**   current nativethread support status, we recommend you reconfigure and 
 
1666
**   Ruby is compiled with --enable-pthread, but your Tcl/Tk library
 
1667
**   seems to be compiled without nativethread support. Although you can
 
1668
**   create the tcltklib library, this combination may cause errors (e.g.
 
1669
**   hangs or segmentation faults). If you have no reason to keep the
 
1670
**   current nativethread support status, we recommend you reconfigure and
1341
1671
**   recompile the libraries so that both or neither support nativethreads.
1342
1672
**
1343
1673
**   If you want change the status of nativethread support, please recompile
1344
1674
**   Ruby without "--enable-pthread" configure option (If you use Ruby 1.9.x
1345
1675
**   or later, you cannot remove this option, because it requires native-
1346
 
**   thread support.) or recompile Tcl/Tk with "--enable-threads" configure 
 
1676
**   thread support.) or recompile Tcl/Tk with "--enable-threads" configure
1347
1677
**   option (if your Tcl/Tk is later than or equal to Tcl/Tk 8.1).
1348
1678
**
1349
1679
*****************************************************************************
1431
1761
  have_library("m", "log", "math.h")
1432
1762
  print("\n") # progress
1433
1763
end
 
1764
$CPPFLAGS ||= ""
1434
1765
$CPPFLAGS += ' -D_WIN32' if /cygwin/ =~ RUBY_PLATFORM
1435
1766
 
1436
1767
# Does ruby have nativethread ?
1437
 
TkLib_Config["ruby_with_thread"] = 
 
1768
TkLib_Config["ruby_with_thread"] =
1438
1769
  macro_defined?('HAVE_NATIVETHREAD', '#include "ruby.h"')
1439
1770
 
1440
1771
 
1441
1772
#---------------------------------------------------
 
1773
TclConfig_Info = {}
 
1774
TkConfig_Info  = {}
 
1775
 
 
1776
# use Tcl/Tk build dir?  (has highest priority)
 
1777
TkLib_Config["tcl-build-dir"] = with_config("tcl-build-dir")
 
1778
TkLib_Config["tk-build-dir"]  = with_config("tk-build-dir")
 
1779
if TkLib_Config["tcl-build-dir"]
 
1780
  puts("use Tcl build (pre-install) dir \"#{TkLib_Config["tcl-build-dir"]}\"")
 
1781
  TkLib_Config["tcl-build-dir"] = File.expand_path(TkLib_Config["tcl-build-dir"])
 
1782
  base = File.dirname(TkLib_Config["tcl-build-dir"])
 
1783
  ($INCFLAGS ||= "") << " -I#{File.join(base, "generic").quote} -I#{TkLib_Config["tcl-build-dir"].quote}"
 
1784
  $LIBPATH ||= []; $LIBPATH |= [TkLib_Config["tcl-build-dir"]]
 
1785
end
 
1786
if TkLib_Config["tk-build-dir"]
 
1787
  puts("use Tk build (pre-install) dir \"#{TkLib_Config["tk-build-dir"]}\"")
 
1788
  TkLib_Config["tk-build-dir"] = File.expand_path(TkLib_Config["tk-build-dir"])
 
1789
  base = File.dirname(TkLib_Config["tk-build-dir"])
 
1790
  ($INCFLAGS ||= "") << " -I#{File.join(base, "generic").quote} -I#{TkLib_Config["tk-build-dir"].quote}"
 
1791
  $LIBPATH ||= []; $LIBPATH |= [TkLib_Config["tk-build-dir"]]
 
1792
end
 
1793
 
1442
1794
# check requirement of Tcl/tk version
1443
1795
tcltk_version = with_config("tcltkversion")
1444
 
tclver, tkver = 
1445
 
  TkLib_Config["tcltkversion"] = check_tcltk_version(tcltk_version)
1446
 
puts("Specified Tcl/Tk version is #{[tclver, tkver].inspect}") if tclver&&tkver
 
1796
TkLib_Config["tcltkversion"] = check_tcltk_version(tcltk_version)
 
1797
 
 
1798
if TkLib_Config["tcl-build-dir"]
 
1799
  if (cfgfile = with_config("tclConfig-file", Dir.glob(File.join(TkLib_Config["tcl-build-dir"], "tclConfig*.sh"), File::FNM_CASEFOLD)[0]))
 
1800
    TclConfig_Info['config_file_path'] = cfgfile
 
1801
    TkLib_Config["tclConfig_info"] = cfginfo = parse_tclConfig(cfgfile)
 
1802
    if tclver = TkLib_Config["tcltkversion"][0]
 
1803
      TkLib_Config["tcltkversion"][0].sub!(/\d(\.?)\d/, "#{cfginfo['TCL_MAJOR_VERSION']}\\1#{cfginfo['TCL_MINOR_VERSION']}")
 
1804
    else
 
1805
      TkLib_Config["tcltkversion"][0] = "#{cfginfo['TCL_MAJOR_VERSION']}.#{cfginfo['TCL_MINOR_VERSION']}"
 
1806
    end
 
1807
  end
 
1808
end
 
1809
if TkLib_Config["tk-build-dir"]
 
1810
  if (cfgfile = with_config("tkConfig-file", Dir.glob(File.join(TkLib_Config["tk-build-dir"], "tkConfig*.sh"), File::FNM_CASEFOLD)[0]))
 
1811
    TkConfig_Info['config_file_path'] = cfgfile
 
1812
    TkLib_Config["tkConfig_info"] = cfginfo = parse_tclConfig(cfgfile)
 
1813
    if TkLib_Config["tcltkversion"][1]
 
1814
      TkLib_Config["tcltkversion"][1].sub!(/\d(\.?)\d/, "#{cfginfo['TK_MAJOR_VERSION']}\\1#{cfginfo['TK_MINOR_VERSION']}")
 
1815
    else
 
1816
      TkLib_Config["tcltkversion"][1] = "#{cfginfo['TK_MAJOR_VERSION']}.#{cfginfo['TK_MINOR_VERSION']}"
 
1817
    end
 
1818
  end
 
1819
end
 
1820
 
 
1821
tclver, tkver = TkLib_Config["tcltkversion"]
 
1822
puts("Specified Tcl/Tk version is #{[tclver, tkver].inspect}") if tclver||tkver
1447
1823
 
1448
1824
# use ActiveTcl ?
1449
1825
#if activeTcl = with_config("ActiveTcl")
1450
 
if activeTcl = with_config("ActiveTcl", true)
 
1826
#if activeTcl = with_config("ActiveTcl", true)
 
1827
if activeTcl = with_config("ActiveTcl", !(TkLib_Config["tcl-build-dir"] && TkLib_Config["tk-build-dir"]))
1451
1828
  puts("Use ActiveTcl libraries (if available).")
1452
1829
  unless activeTcl.kind_of? String
1453
1830
    # set default ActiveTcl path
1464
1841
TkLib_Config["ActiveTcl"] = activeTcl
1465
1842
 
1466
1843
# allow space chars on a libpath
1467
 
TkLib_Config["space-on-tk-libpath"] = 
 
1844
TkLib_Config["space-on-tk-libpath"] =
1468
1845
  enable_config("space-on-tk-libpath", ! is_win32?)
1469
1846
 
1470
1847
# enable Tcl/Tk stubs?
1471
1848
=begin
1472
 
if TclConfig_Info['TCL_STUB_LIB_SPEC'] && TkConfig_Info['TK_STUB_LIB_SPEC'] && 
 
1849
if TclConfig_Info['TCL_STUB_LIB_SPEC'] && TkConfig_Info['TK_STUB_LIB_SPEC'] &&
1473
1850
    !TclConfig_Info['TCL_STUB_LIB_SPEC'].strip.empty? &&
1474
1851
    !TkConfig_Info['TK_STUB_LIB_SPEC'].strip.empty?
1475
1852
  stubs = true
1486
1863
stubs = enable_config("tcltk-stubs") || with_config("tcltk-stubs")
1487
1864
if (TkLib_Config["tcltk-stubs"] = stubs)
1488
1865
  puts("Compile with Tcl/Tk stubs.")
1489
 
  $CPPFLAGS += ' -DUSE_TCL_STUBS -DUSE_TK_STUBS'
 
1866
  $CPPFLAGS ||= ""; $CPPFLAGS += ' -DUSE_TCL_STUBS -DUSE_TK_STUBS'
1490
1867
end
1491
1868
 
1492
1869
# directory configuration of Tcl/Tk libraries
1493
 
tk_idir,  tk_ldir  = dir_config("tk")
1494
 
tcl_idir, tcl_ldir = dir_config("tcl")
 
1870
if TkLib_Config["tcl-build-dir"]
 
1871
  tcl_idir = File.join(File.dirname(TkLib_Config["tcl-build-dir"]),"generic")
 
1872
  tcl_ldir = TkLib_Config["tcl-build-dir"]
 
1873
else
 
1874
  tcl_idir, tcl_ldir = dir_config("tcl")
 
1875
end
 
1876
if TkLib_Config["tk-build-dir"]
 
1877
  tk_idir = File.join(File.dirname(TkLib_Config["tk-build-dir"]),"generic")
 
1878
  tk_ldir = TkLib_Config["tk-build-dir"]
 
1879
else
 
1880
  tk_idir, tk_ldir = dir_config("tk")
 
1881
end
1495
1882
 
1496
1883
tcl_idir = tk_idir unless tcl_idir
1497
1884
tcl_ldir = tk_ldir unless tcl_ldir
1498
1885
tk_idir = tcl_idir unless tk_idir
1499
1886
tk_ldir = tcl_ldir unless tk_ldir
1500
1887
 
 
1888
TclConfig_Info['TCL_INCLUDE_SPEC'] ||= ""
 
1889
TkConfig_Info['TK_INCLUDE_SPEC']   ||= ""
 
1890
TclConfig_Info['TCL_INCLUDE_SPEC'][0,0] = "-I#{tcl_idir.quote} " if tcl_idir
 
1891
TkConfig_Info['TK_INCLUDE_SPEC'][0,0]   = "-I#{tk_idir.quote} "  if tk_idir
 
1892
 
1501
1893
# get tclConfig.sh/tkConfig.sh
1502
 
TkLib_Config["tcltk-NG-path"] = []
1503
 
tclcfg, tkcfg = get_tclConfig(with_config("tclConfig-file", true),
1504
 
                              with_config("tkConfig-file", true),
1505
 
                              with_config("tclConfig-dir", tcl_ldir || true),
1506
 
                              with_config("tkConfig-dir", tk_ldir || true))
1507
 
TclConfig_Info = TkLib_Config["tclConfig_info"] || {}
1508
 
TkConfig_Info  = TkLib_Config["tkConfig_info"] || {}
1509
 
TclConfig_Info['config_file_path'] = tclcfg
1510
 
TkConfig_Info['config_file_path'] = tkcfg
1511
 
 
1512
 
TclConfig_Info['TCL_INCLUDE_SPEC'] = "-I#{tcl_idir.quote}" if tcl_idir
1513
 
TkConfig_Info['TK_INCLUDE_SPEC']   = "-I#{tk_idir.quote}"  if tk_idir
 
1894
TkLib_Config["tcl-NG-path"] = []
 
1895
TkLib_Config["tk-NG-path"] = []
 
1896
tclcfg, tkcfg =
 
1897
  get_tclConfig(
 
1898
    TclConfig_Info['config_file_path'] || with_config("tclConfig-file", true),
 
1899
    TkConfig_Info['config_file_path']  || with_config("tkConfig-file", true),
 
1900
    (TclConfig_Info['config_file_path'])?
 
1901
                File.dirname(TclConfig_Info['config_file_path']) :
 
1902
                with_config("tclConfig-dir", tcl_ldir || true),
 
1903
    (TkConfig_Info['config_file_path'])?
 
1904
                File.dirname(TkConfig_Info['config_file_path']) :
 
1905
                with_config("tkConfig-dir", tk_ldir || true)
 
1906
  )
 
1907
TclConfig_Info.merge!(TkLib_Config["tclConfig_info"]) if TkLib_Config["tclConfig_info"]
 
1908
TkConfig_Info.merge!(TkLib_Config["tkConfig_info"]) if TkLib_Config["tkConfig_info"]
 
1909
TclConfig_Info['config_file_path'] ||= tclcfg
 
1910
TkConfig_Info['config_file_path'] ||= tkcfg
1514
1911
 
1515
1912
tk_cfg_dir  = File.dirname(TkConfig_Info['config_file_path'])  rescue nil
1516
1913
tcl_cfg_dir = File.dirname(TclConfig_Info['config_file_path']) rescue nil
1517
1914
 
1518
 
tk_ldir_list  = [tk_ldir,  tk_cfg_dir]
1519
 
tcl_ldir_list = [tcl_ldir, tcl_cfg_dir]
 
1915
tk_ldir_list  = [tk_ldir,  tk_cfg_dir].uniq
 
1916
tcl_ldir_list = [tcl_ldir, tcl_cfg_dir].uniq
 
1917
 
 
1918
if TkConfig_Info['config_file_path']
 
1919
  if TkLib_Config["tk-build-dir"]
 
1920
    spec_dir = get_libpath(TkConfig_Info['TK_LIB_FLAG'], TkConfig_Info['TK_BUILD_LIB_SPEC'])
 
1921
  else
 
1922
    spec_dir = get_libpath(TkConfig_Info['TK_LIB_FLAG'], TkConfig_Info['TK_LIB_SPEC'])
 
1923
  end
 
1924
  tk_ldir_list << spec_dir if File.directory?(spec_dir)
 
1925
end
 
1926
if TclConfig_Info['config_file_path']
 
1927
  if TkLib_Config["tcl-build-dir"]
 
1928
    spec_dir = get_libpath(TclConfig_Info['TCL_LIB_FLAG'], TclConfig_Info['TCL_BUILD_LIB_SPEC'])
 
1929
  else
 
1930
    spec_dir = get_libpath(TclConfig_Info['TCL_LIB_FLAG'], TclConfig_Info['TCL_LIB_SPEC'])
 
1931
  end
 
1932
  tcl_ldir_list << spec_dir if File.directory?(spec_dir)
 
1933
end
1520
1934
 
1521
1935
# check tk_shlib_search_path
1522
 
check_shlib_search_path(with_config('tk-shlib-search-path'))
 
1936
TkLib_Config["checked_shlib_dirs"] =
 
1937
  check_shlib_search_path(with_config('tk-shlib-search-path'))
1523
1938
 
1524
1939
# set TCL_DEFS and TK_DEFS
 
1940
$CPPFLAGS ||= ""
1525
1941
# $CPPFLAGS += " #{TclConfig_Info['TCL_DEFS']}"
1526
1942
# $CPPFLAGS += " #{TkConfig_Info['TK_DEFS']}"
1527
 
$CPPFLAGS += collect_tcltk_defs(TclConfig_Info['TCL_DEFS'], TkConfig_Info['TK_DEFS'])
 
1943
$defs += collect_tcltk_defs(TclConfig_Info['TCL_DEFS'], TkConfig_Info['TK_DEFS'])
1528
1944
 
1529
1945
# MacOS X Frameworks?
1530
1946
if TkLib_Config["tcltk-framework"]
1531
1947
  puts("Use MacOS X Frameworks.")
 
1948
  ($LDFLAGS ||= "") << " -L#{TkLib_Config["tcl-build-dir"].quote}" if TkLib_Config["tcl-build-dir"]
 
1949
 
1532
1950
  if tcl_cfg_dir
1533
 
    $INCFLAGS << ' ' << TclConfig_Info['TCL_INCLUDE_SPEC']
 
1951
    TclConfig_Info['TCL_LIBS'] ||= ""
 
1952
    ($INCFLAGS ||= "") << ' ' << TclConfig_Info['TCL_INCLUDE_SPEC']
1534
1953
    $LDFLAGS  << ' ' << TclConfig_Info['TCL_LIBS']
1535
1954
    if stubs
1536
 
      $LDFLAGS << ' ' << TclConfig_Info['TCL_STUB_LIB_SPEC']
 
1955
      if TkLib_Config["tcl-build-dir"] &&
 
1956
          TclConfig_Info['TCL_BUILD_STUB_LIB_SPEC'] &&
 
1957
          !TclConfig_Info['TCL_BUILD_STUB_LIB_SPEC'].strip.empty?
 
1958
        $LDFLAGS << ' ' << TclConfig_Info['TCL_BUILD_STUB_LIB_SPEC']
 
1959
      else
 
1960
        $LDFLAGS << ' ' << TclConfig_Info['TCL_STUB_LIB_SPEC']
 
1961
      end
1537
1962
    else
1538
 
      $LDFLAGS << ' ' << TclConfig_Info['TCL_LIB_SPEC']
 
1963
      if TkLib_Config["tcl-build-dir"] &&
 
1964
          TclConfig_Info['TCL_BUILD_LIB_SPEC'] &&
 
1965
          !TclConfig_Info['TCL_BUILD_LIB_SPEC'].strip.empty?
 
1966
        $LDFLAGS << ' ' << TclConfig_Info['TCL_BUILD_LIB_SPEC']
 
1967
      else
 
1968
        $LDFLAGS << ' ' << TclConfig_Info['TCL_LIB_SPEC']
 
1969
      end
1539
1970
    end
1540
1971
  end
 
1972
 
 
1973
  $LDFLAGS  << " -L#{TkLib_Config["tk-build-dir"].quote}" if TkLib_Config["tk-build-dir"]
 
1974
 
1541
1975
  if tk_cfg_dir
1542
 
    $INCFLAGS << ' ' << TkConfig_Info['TK_INCLUDE_SPEC']
 
1976
    TkConfig_Info['TK_LIBS'] ||= ""
 
1977
    ($INCFLAGS ||= "") << ' ' << TkConfig_Info['TK_INCLUDE_SPEC']
1543
1978
    $LDFLAGS  << ' ' << TkConfig_Info['TK_LIBS']
1544
1979
    if stubs
1545
 
      $LDFLAGS << ' ' << TkConfig_Info['TK_STUB_LIB_SPEC']
 
1980
      if TkLib_Config["tk-build-dir"] &&
 
1981
          TclConfig_Info['TK_BUILD_STUB_LIB_SPEC'] &&
 
1982
          !TclConfig_Info['TK_BUILD_STUB_LIB_SPEC'].strip.empty?
 
1983
        $LDFLAGS << ' ' << TkConfig_Info['TK_BUILD_STUB_LIB_SPEC']
 
1984
      else
 
1985
        $LDFLAGS << ' ' << TkConfig_Info['TK_STUB_LIB_SPEC']
 
1986
      end
1546
1987
    else
1547
 
      $LDFLAGS << ' ' << TkConfig_Info['TK_LIB_SPEC']
 
1988
      if TkLib_Config["tk-build-dir"] &&
 
1989
          TclConfig_Info['TK_BUILD_LIB_SPEC'] &&
 
1990
          !TclConfig_Info['TK_BUILD_LIB_SPEC'].strip.empty?
 
1991
        $LDFLAGS << ' ' << TkConfig_Info['TK_BUILD_LIB_SPEC']
 
1992
      else
 
1993
        $LDFLAGS << ' ' << TkConfig_Info['TK_LIB_SPEC']
 
1994
      end
1548
1995
    end
1549
1996
  end
1550
1997
  setup_for_macosx_framework(tclver, tkver) if tcl_cfg_dir && tk_cfg_dir
1559
2006
 
1560
2007
 
1561
2008
#---------------------------------------------------
1562
 
 
1563
2009
if (TkLib_Config["tcltk-framework"] ||
1564
2010
      ( find_tcltk_header(tclver, tkver) &&
1565
 
          find_tcltk_library(tcllib, tklib, stubs, tclver, tkver, 
 
2011
          find_tcltk_library(tcllib, tklib, stubs, tclver, tkver,
1566
2012
                             tcl_ldir_list, tk_ldir_list) ) ) &&
1567
2013
    (stubs || pthread_check())
1568
2014
  # create Makefile
1572
2018
  $INSTALLFILES << ["lib/tkextlib/SUPPORT_STATUS", "$(RUBYLIBDIR)", "lib"]
1573
2019
 
1574
2020
  # create
1575
 
  $CPPFLAGS << %[ -DRUBY_VERSION=\\"#{RUBY_VERSION}\\"]
1576
 
  $CPPFLAGS << %[ -DRUBY_RELEASE_DATE=\\"#{RUBY_RELEASE_DATE}\\"]
 
2021
  $defs << %[-DRUBY_VERSION=\\"#{RUBY_VERSION}\\"]
 
2022
  $defs << %[-DRUBY_RELEASE_DATE=\\"#{RUBY_RELEASE_DATE}\\"]
 
2023
 
 
2024
  # remove harmful definitions.
 
2025
  $defs.delete_if{|x|/^-Du?intptr_t=/ =~ x}
1577
2026
 
1578
2027
  create_makefile("tcltklib")
1579
2028
 
1580
 
  puts "Find Tcl/Tk libraries. Make tcltklib.so which is required by Ruby/Tk."
 
2029
  puts "\nFind Tcl/Tk libraries. Make tcltklib.so which is required by Ruby/Tk."
1581
2030
else
1582
 
  puts "Can't find proper Tcl/Tk libraries. So, can't make tcltklib.so which is required by Ruby/Tk."
 
2031
  puts "\nCan't find proper Tcl/Tk libraries. So, can't make tcltklib.so which is required by Ruby/Tk."
1583
2032
end