From 80488a8ee9c3da19ecc18a01c7162342d869a7b9 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Mon, 5 Oct 2020 01:34:53 -0400 Subject: [PATCH] Have magic.tcl look for the shared library in the script directory Rather than having the build process embed an absolute path. The first of a couple of steps to make the magic build relocatable. --- tcltk/Makefile | 2 +- tcltk/magic.tcl.in | 25 +++++++++++++------------ tcltk/tclmagic.c | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/tcltk/Makefile b/tcltk/Makefile index 8c2d9af9..f79924c9 100644 --- a/tcltk/Makefile +++ b/tcltk/Makefile @@ -63,7 +63,7 @@ magic.tcl: magic.tcl.in ${MAGICDIR}/defs.mak ${MAGICDIR}/VERSION sed -e /TCL_DIR/s%TCL_DIR%${TCLDIR}%g \ -e /MAGIC_VERSION/s%MAGIC_VERSION%${MAGIC_VERSION}%g \ -e /MAGIC_REVISION/s%MAGIC_REVISION%${MAGIC_REVISION}%g \ - -e /SHDLIB_EXT/s%SHDLIB_EXT%${SHDLIB_EXT}%g magic.tcl.in > magic.tcl + -e /SHDLIB_EXT/s%SHDLIB_EXT%${SHDLIB_EXT}%g magic.tcl.in > magic.tcl magic.sh: magic.sh.in ${MAGICDIR}/defs.mak sed -e /TCL_DIR/s%TCL_DIR%${TCLDIR}%g \ diff --git a/tcltk/magic.tcl.in b/tcltk/magic.tcl.in index dfc9755c..a7f0dd8e 100755 --- a/tcltk/magic.tcl.in +++ b/tcltk/magic.tcl.in @@ -1,19 +1,20 @@ # Wishrc startup for ToolScript (magic) # # For installation: Put this file and also magicwrap.so into -# directory TCL_DIR, and set the "load" line below -# to point to the location of magicwrap.so. Also see comments -# in shell script "magic.sh". +# the same directory. Also see comments in shell script "magic.sh". global Opts - + # If we called magic via the non-console script, then we want to reset # the environment variable HOME to its original value. - + +variable MAGIC_TCL_DIR [file dirname [file normalize [info script]]] +variable CAD_ROOT_DEFAULT [file normalize [file join $MAGIC_TCL_DIR ../..]] + if {${tcl_version} >= 8.6} { - load -lazy TCL_DIR/tclmagicSHDLIB_EXT + load -lazy [file join $MAGIC_TCL_DIR tclmagic[info sharedlibextension]] } else { - load TCL_DIR/tclmagicSHDLIB_EXT + load [file join $MAGIC_TCL_DIR tclmagic[info sharedlibextension]] } # It is important to make sure no magic commands overlap with Tcl built-in @@ -30,8 +31,8 @@ proc pushnamespace { name } { foreach v $y { regsub -all {\*} $v {\\*} i set x [namespace tail $i] - if {[lsearch $z $x] < 0} { - namespace import $i + if {[lsearch $z $x] < 0} { + namespace import $i } } } @@ -124,7 +125,7 @@ proc xcircuit { args } { # execute script in the scope of magic, because its variable space is # not modularized. set argv $args - set argc [llength $args] + set argc [llength $args] uplevel #0 source $xcircscript } } @@ -143,7 +144,7 @@ proc netgen { args } { puts stderr "\"source /netgen.tcl\"." } else { set argv $args - set argc [llength $args] + set argc [llength $args] uplevel #0 source $netgenscript } } @@ -151,7 +152,7 @@ proc netgen { args } { # Add the "echo" command proc echo {args} { - puts stdout $args + puts stdout $args } # Parse argument list for "-c[onsole]" and "-now[rapper]". diff --git a/tcltk/tclmagic.c b/tcltk/tclmagic.c index f039b875..0acf56ea 100644 --- a/tcltk/tclmagic.c +++ b/tcltk/tclmagic.c @@ -1224,7 +1224,7 @@ Tclmagic_Init(interp) /* Set $CAD_ROOT as a Tcl variable */ cadroot = getenv("CAD_ROOT"); - if (cadroot == NULL) cadroot = CAD_DIR; + if (cadroot == NULL) cadroot = Tcl_GetVar(interp, "CAD_ROOT_DEFAULT", TCL_GLOBAL_ONLY); Tcl_SetVar(interp, "CAD_ROOT", cadroot, TCL_GLOBAL_ONLY);