Version 6 of Finding out tclConfig.sh

Updated 2004-11-14 13:07:06

Lets exchange here our solutions to finding out tclConfig.sh.


DGP Let's put the correct solution first:

  package require Tcl 8.5
  set d [::tcl::pkgconfig get libdir,install]
  puts [file join $d tclConfig.sh]
  exit

For the large number of people not yet using Tcl 8.5, continue...


Googie My first candidate is following code:

 foreach d [concat \
     [list $tcl_library \
           [lindex $tcl_pkgPath 0]] \
     $auto_path \
     [list [file dirname $tcl_library] \
           [file dirname [lindex $tcl_pkgPath 0]] \
           [file dirname [file dirname $tcl_library]] \
           [file dirname [file dirname [lindex $tcl_pkgPath 0]]] \
           [file dirname [file dirname [file dirname $tcl_library]]] \
           [file dirname [file dirname [file dirname [lindex $tcl_pkgPath 0]]]]] \
 ] {
     if {[file exists [file join $d tclConfig.sh]]} {
         puts "[file join $d tclConfig.sh]"
         exit
     }
 }

 puts "none"

We can put it into the one tcl script file and execute from a shell to get info, if we can find tclConfig.sh (returns path pointing to it) or we can't (returns "none"). I use few levels of file dirname for $tcl_library and $tcl_pkgPath, because of some problems on MacOS (tclConfig.sh is places few levels upper than $tcl_library).

BR Carefull with those spaces. Better to use list handling functions for lists instead of string concatenation. Also, what is the significance of the order of directories? And why are you looking into $auto_path and $tcl_pkgPath? The only interesting member of those should be $tcl_library, right? The other entries in $auto_path and $tcl_pkgPath would point to other versions of Tcl at the most, I think, and if there is a tclConfig.sh in those that would counter-productive. So I'd rather do:

  proc tclConfigFile {} {

      set d [info library]
      set f [file join $d "tclConfig.sh"]
      if {[file exists $f]} {return $f}

      set d [file dirname $d]
      set f [file join $d "tclConfig.sh"]
      if {[file exists $f]} {return $f}

      set d [file dirname $d]
      set f [file join $d "tclConfig.sh"]
      if {[file exists $f]} {return $f}

      set d [file dirname $d]
      set f [file join $d "tclConfig.sh"]
      if {[file exists $f]} {return $f}

      error "tclConfig.sh not found"
 }