Skip to content

Commit e58dff8

Browse files
committed
update configure file
1 parent 041adfe commit e58dff8

1 file changed

Lines changed: 92 additions & 1 deletion

File tree

configure

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ set var(PROFILE) {}
3838
set var(LIBS) {}
3939
set var(SCIDFLAGS) {}
4040
set var(SHAREDIR) /usr/local/share/scidCommunity
41-
set var(TCL_VERSION) 8.6
41+
set var(TCL_VERSION) 8.6 ;# fallback if auto-detection finds nothing
4242
set var(WARNINGS) "-Wall -Wno-deprecated-declarations"
4343
set var(MAKEFILE) Makefile.conf
4444
set var(INSTALL) {install_scid install_engines}
@@ -253,6 +253,84 @@ proc findTclTkPaths {} {
253253
return $success
254254
}
255255

256+
# detectTclHeaderVersions:
257+
# Scan header directories for tcl.h and extract version numbers.
258+
#
259+
proc detectTclHeaderVersions {} {
260+
set headerPath {
261+
/usr/local/include
262+
/usr/include
263+
/usr/local/tcl/include
264+
/usr/X11/include
265+
/usr/X11R6/include
266+
/usr/local/X11/include
267+
/opt/tcltk/include
268+
/usr/X11R/include
269+
}
270+
set versions {}
271+
foreach dir $headerPath {
272+
foreach f [glob -nocomplain [file join $dir tcl.h]] {
273+
if {[catch {set fh [open $f r]}]} continue
274+
while {[gets $fh line] >= 0} {
275+
if {[regexp {TCL_VERSION\s+("?)(\d+\.\d+)\1} $line -> _ ver]} {
276+
lappend versions $ver
277+
}
278+
}
279+
close $fh
280+
}
281+
}
282+
return $versions
283+
}
284+
285+
# detectTclLibVersions:
286+
# Scan library directories for Tcl shared libraries and extract version numbers.
287+
#
288+
proc detectTclLibVersions {} {
289+
set searchPath {
290+
/usr/local/include
291+
/usr/include
292+
/usr/local/tcl/include
293+
/usr/X11/include
294+
/usr/X11R6/include
295+
/usr/local/X11/include
296+
/opt/tcltk/include
297+
/usr/X11R/include
298+
/usr/lib
299+
/usr/lib64
300+
/usr/local/tcl/lib
301+
/usr/local/lib
302+
/usr/X11R6/lib
303+
/opt/tcltk/lib
304+
}
305+
if {[info exists ::tcl_library]} {
306+
lappend searchPath [file dirname $::tcl_library]
307+
}
308+
set versions {}
309+
foreach dir $searchPath {
310+
foreach f [glob -nocomplain [file join $dir libtcl*]] {
311+
if {[regexp {libtcl(\d+\.\d+)} [file tail $f] -> ver]} {
312+
lappend versions $ver
313+
} elseif {[regexp {libtcl(\d+)} [file tail $f] -> ver]} {
314+
lappend versions $ver
315+
}
316+
}
317+
}
318+
return $versions
319+
}
320+
321+
# detectLatestTclVersion:
322+
# Find the highest Tcl/Tk version available on the system.
323+
#
324+
proc detectLatestTclVersion {} {
325+
set versions {}
326+
foreach v [detectTclHeaderVersions] { dict set versions $v 1 }
327+
foreach v [detectTclLibVersions] { dict set versions $v 1 }
328+
set vlist [dict keys $versions]
329+
if {[llength $vlist] == 0} { return "" }
330+
set vlist [lsort -decreasing $vlist]
331+
return [lindex $vlist 0]
332+
}
333+
256334
# writeMakefile:
257335
# Creates the Makefile using Makefile.conf and the configured
258336
# settings.
@@ -344,6 +422,7 @@ puts "configure: Makefile configuration program for ScidCommunity"
344422
345423
# Parse command-line arguments:
346424
set default 0
425+
set user_set_tcl_version 0
347426
348427
foreach arg $argv {
349428
if {![string compare "default" $arg]} {
@@ -354,6 +433,7 @@ foreach arg $argv {
354433
set temp_var [string range $arg 0 [expr $temp_idx - 1]]
355434
set temp_value [string range $arg [expr $temp_idx + 1] end]
356435
set var($temp_var) $temp_value
436+
if {$temp_var eq "TCL_VERSION"} { set user_set_tcl_version 1 }
357437
} else {
358438
puts "Invalid argument: $arg"
359439
usage
@@ -363,6 +443,17 @@ foreach arg $argv {
363443
364444
if {![info exists var(LINK)]} { set var(LINK) "$var(COMPILE)" }
365445
446+
# Auto-detect Tcl/Tk version unless user explicitly set TCL_VERSION:
447+
if {!$user_set_tcl_version} {
448+
set detected [detectLatestTclVersion]
449+
if {$detected ne ""} {
450+
set var(TCL_VERSION) $detected
451+
puts " Auto-detected Tcl/Tk version: $detected"
452+
} else {
453+
puts " No Tcl/Tk installation found, using default: $var(TCL_VERSION)"
454+
}
455+
}
456+
366457
if {$default} {
367458
writeMakefile default
368459
exit 0

0 commit comments

Comments
 (0)