diff options
Diffstat (limited to 'unix/tcl.m4')
-rw-r--r-- | unix/tcl.m4 | 134 |
1 files changed, 131 insertions, 3 deletions
diff --git a/unix/tcl.m4 b/unix/tcl.m4 index 2f114d7..99f5d29 100644 --- a/unix/tcl.m4 +++ b/unix/tcl.m4 @@ -336,6 +336,8 @@ AC_DEFUN([SC_LOAD_TCLCONFIG], [ eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\"" eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\"" + SC_TCL_FIND_SOURCES() + AC_SUBST(TCL_VERSION) AC_SUBST(TCL_PATCH_LEVEL) AC_SUBST(TCL_BIN_DIR) @@ -432,6 +434,134 @@ AC_DEFUN([SC_LOAD_TKCONFIG], [ AC_SUBST(TK_STUB_LIB_SPEC) ]) + +#------------------------------------------------------------------------ +# SC_TCL_FIND_SOURCES +# Find a directory containing Tcl sources that match the version required by +# tclConfig.sh. The sources indicated by tclConfig.sh are preferred. +# +# Arguments: +# none +# +# Results: +# Substitutes the following vars: +# TCL_SOURCE_MAJOR_VERSION +# TCL_SOURCE_MINOR_VERSION +# TCL_ACTUAL_SRC_DIR +#------------------------------------------------------------------------ + +AC_DEFUN([SC_TCL_FIND_SOURCES],[ + [TCL_ACTUAL_SRC_DIR=` <<-'EOF' "$TCLSH_PROG" - "$srcdir" "$TCL_SRC_DIR" \ + "$TCL_MAJOR_VERSION" "$TCL_MINOR_VERSION" + + proc cat fname { + set chan [open $fname] + try { + read $chan + } finally { + close $chan + } + } + + proc main {argv0 argv} { + try { + lassign $argv -> srcdir tcl_src_dir majortarget minortarget + lappend candidates $tcl_src_dir + set srcdir [file dirname [file normalize $srcdir/...]] + set topsrcdir [file dirname $srcdir] + set sources [file dirname $topsrcdir] + foreach dirname [glob -nocomplain -directory $sources *] { + if {$dirname ni $candidates} { + lappend candidates $dirname + } + } + foreach candidate $candidates { + set res [check $candidate $majortarget $minortarget] + if {$res eq {}} continue else { + puts -nonewline $res + break + } + } + set status 0 + } on error {tres topts} { + puts stderr [dict get $topts -errorinfo] + set status 1 + } + exit $status + } + + proc check {candidate majortarget minortarget} { + set tclh $candidate/generic/tcl.h + + if {![file exists $tclh]} { + return {} + } + + set version [tclhversion [cat $tclh]] + if {[llength $version]} { + lassign $version major minor + if {[package vcompare $major.$minor \ + $majortarget.$minortarget] >= 0} { + return [list $candidate $major $minor] + } + } + + return {} + } + + proc tclhversion data { + if {[regexp -line {^#define\s+_TCL} $data]} { + if {[ + regexp -line {^#define\s+TCL_VERSION\s+\"([^.])+\.([^.\"]+)} \ + $data -> major minor + ]} { + return [list $major $minor] + } + } + return {} + } + main $argv0 $argv + EOF + ] + ` + + if test "x${TCL_ACTUAL_SRC_DIR}" = x; then + AC_MSG_ERROR([could not find Tcl sources]) + else + TCL_SOURCE_MAJOR_VERSION=SC_TCL_LINDEX([$TCL_ACTUAL_SRC_DIR] ,1) + AC_SUBST(TCL_SOURCE_MAJOR_VERSION) + TCL_SOURCE_MINOR_VERSION=SC_TCL_LINDEX([$TCL_ACTUAL_SRC_DIR] ,2) + AC_SUBST(TCL_SOURCE_MINOR_VERSION) + TCL_ACTUAL_SRC_DIR=SC_TCL_LINDEX([$TCL_ACTUAL_SRC_DIR] ,0) + AC_SUBST(TCL_ACTUAL_SRC_DIR) + fi +]) + + +#------------------------------------------------------------------------ +# SC_TCL_LINDEX +#------------------------------------------------------------------------ + +AC_DEFUN([SC_TCL_LINDEX], + [[` <<-'EOF' "$TCLSH_PROG" - "$1" "$2" + proc main {argv0 argv} { + try { + lassign $argv -> list index + puts -nonewline [lindex $list $index] + set status 0 + } on error {tres topts} { + puts stderr [dict get $topts -errorinfo] + set status 1 + } + exit $status + } + main $argv0 $argv + EOF + ` + ]] + +) + #------------------------------------------------------------------------ # SC_PROG_TCLSH # Locate a tclsh shell installed on the system path. This macro @@ -473,9 +603,7 @@ AC_DEFUN([SC_PROG_TCLSH], [ TCLSH_PROG="$ac_cv_path_tclsh" AC_MSG_RESULT([$TCLSH_PROG]) else - # It is not an error if an installed version of Tcl can't be located. - TCLSH_PROG="" - AC_MSG_RESULT([No tclsh found on PATH]) + AC_MSG_RESULT([No tclsh avaliable]) fi AC_SUBST(TCLSH_PROG) ]) |