Skip to content

Commit c490376

Browse files
committed
install: derive tclsh from --with-tcl when --with-tclsh is not set
When Tcl is installed in a non-default location, the extension library is built against the tclConfig.sh designated by --with-tcl whereas the installed scripts run with the first tclsh found in PATH unless --with-tclsh is also passed. Such mismatch is not reported at build time and only shows up later through a library load failure or behavior differences. Look for the Tcl interpreter shell in the Tcl installation designated by --with-tcl before searching PATH: in the bin directory of the exec prefix recorded in tclConfig.sh, or in the bin directory sibling to the directory holding this script when it cannot be read. A version-suffixed tclsh is tried first as some installations do not provide the generic name. If no interpreter is found there, a warning is reported and the PATH lookup applies. An explicit --with-tclsh still takes precedence so both options can be decoupled when needed. The version-specific names tried by the PATH lookup now cover Tcl 9.0 and no longer Tcl 8.4, which is not supported anymore. Fixes #717 Assisted-by: Claude:claude-fable-5-1 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
1 parent c42c58e commit c490376

3 files changed

Lines changed: 93 additions & 5 deletions

File tree

‎INSTALL.rst‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,21 @@ instance :instopt:`--without-modulepath<--with-modulepath>`):
15961596
compile Modules Tcl extension library if this file cannot be automatically
15971597
found in default locations.
15981598

1599+
Unless :instopt:`--with-tclsh` is set, the Tcl interpreter shell is also
1600+
looked for in the Tcl installation designated by this option: ``tclsh`` is
1601+
searched in the ``bin`` directory of the installation prefix recorded in
1602+
``tclConfig.sh`` (or in the ``bin`` directory sibling of the directory
1603+
holding this script when it cannot be read). This way :file:`modulecmd.tcl`
1604+
and other installed scripts run with the same Tcl the extension library is
1605+
built against. If no interpreter shell is found there, a warning is reported
1606+
and ``tclsh`` is looked for in standard binary paths.
1607+
1608+
.. only:: html or latex
1609+
1610+
.. versionchanged:: 5.8
1611+
Tcl interpreter shell is looked for in designated Tcl installation
1612+
unless :instopt:`--with-tclsh` is set
1613+
15991614
.. instopt:: --with-tclinclude
16001615

16011616
Directory containing the Tcl header files. Useful to compile Modules Tcl
@@ -1606,10 +1621,20 @@ instance :instopt:`--without-modulepath<--with-modulepath>`):
16061621

16071622
Name or full path of Tcl interpreter shell (default=\ ``tclsh``)
16081623

1624+
When this option is not set, ``tclsh`` is looked for in the Tcl installation
1625+
designated by :instopt:`--with-tcl` if this option is set, then in standard
1626+
binary paths. Set this option to decouple the interpreter shell running the
1627+
installed scripts from the Tcl installation the extension library is built
1628+
against.
1629+
16091630
.. only:: html or latex
16101631

16111632
.. versionadded:: 4.0
16121633

1634+
.. versionchanged:: 5.8
1635+
Default interpreter shell is looked for in the Tcl installation
1636+
designated by :instopt:`--with-tcl`
1637+
16131638
.. instopt:: --with-tcl-linter=BIN
16141639

16151640
Name or full path of program to use to lint modulefile through the

‎NEWS.rst‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ Release notes
66
This file describes changes in recent versions of Modules. It primarily
77
documents those changes that are of interest to users and admins.
88

9+
.. _5.8 release notes:
10+
11+
Modules 5.8.0 (not yet released)
12+
--------------------------------
13+
14+
* Install: look for the Tcl interpreter shell in the Tcl installation
15+
designated by :instopt:`--with-tcl` when :instopt:`--with-tclsh` is not set,
16+
so that installed scripts run with the same Tcl the extension library is
17+
built against. (fix issue #717)
18+
19+
920
.. _5.7 release notes:
1021

1122
Modules 5.7.0 (2026-09-21)

‎configure‎

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pathentryreorder=n
8888
loadedmodules=
8989
quarantinevars=
9090
binsearchpath=/usr/bin:/bin:/usr/local/bin
91+
tcldir=
9192
TCLSH=tclsh
9293
PYTHON=python
9394
SPHINXBUILD=sphinx-build
@@ -522,13 +523,16 @@ Optional Packages:
522523
TAGLIST is a tag name or abbreviation (elements in
523524
TAGLIST are separated by \`:') [$tagcolorname]
524525
--with-tcl directory containing the Tcl configuration script
525-
tclConfig.sh.
526+
tclConfig.sh. Tcl interpreter shell is also looked
527+
for in this Tcl installation (see --with-tclsh).
526528
--with-tcl-linter=BIN name of full path of program to use to lint Tcl
527529
modulefiles [$tcllinter]
528530
--with-tcl-linter-opts=OPTLIST
529531
settings to apply to tcl linter program [$tcllinteropts]
530532
--with-tclinclude directory containing the Tcl header files.
531-
--with-tclsh=BIN name or full path of Tcl interpreter shell [tclsh]
533+
--with-tclsh=BIN name or full path of Tcl interpreter shell. Unless
534+
set, tclsh is looked for in the Tcl installation
535+
designated by --with-tcl then in PATH [tclsh]
532536
--with-terminal-background=VALUE
533537
terminal background color which determines the color
534538
set to apply by default between the \`dark' background
@@ -611,6 +615,13 @@ check_requirement() {
611615
fi
612616
}
613617

618+
# get value of a variable defined in Tcl configuration script
619+
get_tclconfig_value() {
620+
# source script in a subshell to keep its variables out of our environment
621+
# shellcheck disable=SC1090
622+
(. "$1" >/dev/null 2>&1; echo "${!2}")
623+
}
624+
614625
# parse optional argument to find if feature is enabled or disabled
615626
get_feature_value() {
616627
typeset val="${1#*=}"
@@ -986,7 +997,10 @@ for arg in "$@"; do
986997
--with-tcl-linter-opts=*|--without-tcl-linter-opts)
987998
# shellcheck disable=SC2034
988999
tcllinteropts=$(get_package_value "$arg" "") ;;
989-
--with-tcl=*|--without-tcl|--with-tclinclude=*|--without-tclinclude)
1000+
--with-tcl=*|--without-tcl)
1001+
tcldir=$(get_package_value "$arg")
1002+
libarglist+=("$arg") ;;
1003+
--with-tclinclude=*|--without-tclinclude)
9901004
libarglist+=("$arg") ;;
9911005
--with-python=*|--without-python)
9921006
pythonbin=$(get_package_value "$arg") ;;
@@ -1112,8 +1126,46 @@ fi
11121126
if [ -n "$tclshbin" ]; then
11131127
check_requirement "$tclshbin" '' "PATH=$binsearchpath"
11141128
else
1115-
# also check version-specific names in case no generic tclsh binary exists
1116-
check_requirement $TCLSH '' "PATH=$binsearchpath" 'tclsh8.6' 'tclsh8.5' 'tclsh8.4'
1129+
reqpath=''
1130+
# look first in the Tcl installation designated by --with-tcl, so that
1131+
# installed scripts run with the Tcl the extension library is built
1132+
# against rather than with whatever tclsh comes first in PATH
1133+
if [ -n "$tcldir" ]; then
1134+
# accept tclConfig.sh file path like extension library configure does
1135+
tcldir=${tcldir%/tclConfig.sh}
1136+
# the configuration script records where Tcl binaries are installed and
1137+
# the version suffix of the interpreter shell
1138+
if [ -f "$tcldir/tclConfig.sh" ]; then
1139+
tclexecprefix=$(get_tclconfig_value "$tcldir/tclConfig.sh" \
1140+
TCL_EXEC_PREFIX)
1141+
tclversion=$(get_tclconfig_value "$tcldir/tclConfig.sh" TCL_VERSION)
1142+
else
1143+
tclexecprefix=''
1144+
tclversion=''
1145+
fi
1146+
if [ -n "$tclexecprefix" ]; then
1147+
tclbinsearchpath="$tclexecprefix/bin"
1148+
else
1149+
# assume tclConfig.sh lies in a lib directory sibling to bin
1150+
tclbinsearchpath=$(cd "$tcldir/../bin" 2>/dev/null && pwd \
1151+
|| echo "$tcldir/../bin")
1152+
fi
1153+
if [ -n "$tclversion" ]; then
1154+
check_requirement "tclsh$tclversion" '-' "PATH=$tclbinsearchpath" \
1155+
'tclsh'
1156+
else
1157+
check_requirement 'tclsh' '-' "PATH=$tclbinsearchpath" 'tclsh9.0' \
1158+
'tclsh8.6' 'tclsh8.5'
1159+
fi
1160+
if [ -z "$reqpath" ]; then
1161+
echo_warning "No Tcl interpreter shell found in \`$tclbinsearchpath' \
1162+
from Tcl installation designated by \`--with-tcl', looking in standard PATHs"
1163+
fi
1164+
fi
1165+
if [ -z "$reqpath" ]; then
1166+
# also check version-specific names in case no generic tclsh binary exists
1167+
check_requirement $TCLSH '' "PATH=$binsearchpath" 'tclsh9.0' 'tclsh8.6' 'tclsh8.5'
1168+
fi
11171169
fi
11181170
TCLSH=$reqpath
11191171

0 commit comments

Comments
 (0)