Index: src/makemake.tcl ================================================================== --- src/makemake.tcl +++ src/makemake.tcl @@ -424,11 +424,11 @@ TCLINCDIR = $(TCLDIR)/include TCLLIBDIR = $(TCLDIR)/lib #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)? # -LIBTCL = -ltcl86 +LIBTCL = -ltclstub86 #### C Compile and options for use in building executables that # will run on the target platform. This is usually the same # as BCC, unless you are cross-compiling. This C compiler builds # the finished binary for fossil. The BCC compiler above is used @@ -462,13 +462,13 @@ ifdef FOSSIL_ENABLE_SSL TCC += -DFOSSIL_ENABLE_SSL=1 RCC += -DFOSSIL_ENABLE_SSL=1 endif -# With Tcl support (statically linked) +# With Tcl support ifdef FOSSIL_ENABLE_TCL -TCC += -DFOSSIL_ENABLE_TCL=1 -DSTATIC_BUILD +TCC += -DFOSSIL_ENABLE_TCL=1 -DUSE_TCL_STUBS RCC += -DFOSSIL_ENABLE_TCL=1 endif # With JSON support ifdef FOSSIL_ENABLE_JSON Index: src/th_tcl.c ================================================================== --- src/th_tcl.c +++ src/th_tcl.c @@ -35,10 +35,16 @@ ** Tcl_EvalObjv instead of invoking the objProc directly. */ #define USE_TCL_EVALOBJV 1 #endif +#ifdef _WIN32 +# include <windows.h> +#else +# include <dlfcn.h> +#endif + /* ** These macros are designed to reduce the redundant code required to marshal ** arguments from TH1 to Tcl. */ #define USE_ARGV_TO_OBJV() \ @@ -445,10 +451,28 @@ ){ struct TclContext *tclContext = (struct TclContext *)pContext; int argc; char **argv; char *argv0 = 0; +#ifdef USE_TCL_STUBS +#ifdef _WIN32 + WCHAR lib[] = L"tcl87.dll"; +#define minver lib[4] +#define dlopen(a,b) (void *)LoadLibraryW(a); +#define dlsym(a,b) GetProcAddress((HANDLE)(a),b); +#else +#ifdef __CYGWIN__ + char lib[] = "libtcl8.7.dll"; +#else + char lib[] = "libtcl8.7.so"; +#endif +#define minver lib[8] +#endif + void *handle = NULL; + void (*findExecutable)(const char *) = 0; + Tcl_Interp *(*createInterp)() = 0; +#endif /* USE_TCL_STUBS */ Tcl_Interp *tclInterp; if ( !tclContext ){ Th_ErrorMessage(interp, "Invalid Tcl context", (const char *)"", 0); @@ -460,17 +484,44 @@ argc = tclContext->argc; argv = tclContext->argv; if( argc>0 && argv ){ argv0 = argv[0]; } +#ifdef USE_TCL_STUBS + while( --minver>'3' ){ + handle = dlopen(lib, RTLD_NOW | RTLD_LOCAL); + if( handle ) { + const char *sym = "_Tcl_FindExecutable"; + findExecutable = (void (*)(const char *)) dlsym(handle, sym+1); + if (!findExecutable) + findExecutable = (void (*)(const char *)) dlsym(handle, sym); + sym = "_Tcl_CreateInterp"; + createInterp = (Tcl_Interp * (*)(void)) dlsym(handle, sym+1); + if (!createInterp) + createInterp = (Tcl_Interp * (*)(void)) dlsym(handle, sym); + break; + } + } + if( !handle ){ + Th_ErrorMessage(interp, + "Could not create Tcl interpreter", (const char *)"", 0); + return TH_ERROR; + } +# undef Tcl_FindExecutable +# define Tcl_FindExecutable findExecutable +# undef Tcl_CreateInterp +# define Tcl_CreateInterp createInterp +#endif /* USE_TCL_STUBS */ Tcl_FindExecutable(argv0); - tclInterp = tclContext->interp = Tcl_CreateInterp(); - if( !tclInterp || Tcl_InterpDeleted(tclInterp) ){ + tclInterp = Tcl_CreateInterp(); + if( !tclInterp || !Tcl_InitStubs(tclInterp, "8.4", 0) + || Tcl_InterpDeleted(tclInterp) ){ Th_ErrorMessage(interp, "Could not create Tcl interpreter", (const char *)"", 0); return TH_ERROR; } + tclContext->interp = tclInterp; if( Tcl_Init(tclInterp)!=TCL_OK ){ Th_ErrorMessage(interp, "Tcl initialization error:", Tcl_GetStringResult(tclInterp), -1); Tcl_DeleteInterp(tclInterp); tclContext->interp = tclInterp = 0; Index: win/Makefile.mingw ================================================================== --- win/Makefile.mingw +++ win/Makefile.mingw @@ -96,11 +96,11 @@ TCLINCDIR = $(TCLDIR)/include TCLLIBDIR = $(TCLDIR)/lib #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)? # -LIBTCL = -ltcl86 +LIBTCL = -ltclstub86 #### C Compile and options for use in building executables that # will run on the target platform. This is usually the same # as BCC, unless you are cross-compiling. This C compiler builds # the finished binary for fossil. The BCC compiler above is used @@ -134,13 +134,13 @@ ifdef FOSSIL_ENABLE_SSL TCC += -DFOSSIL_ENABLE_SSL=1 RCC += -DFOSSIL_ENABLE_SSL=1 endif -# With Tcl support (statically linked) +# With Tcl support ifdef FOSSIL_ENABLE_TCL -TCC += -DFOSSIL_ENABLE_TCL=1 -DSTATIC_BUILD +TCC += -DFOSSIL_ENABLE_TCL=1 -DUSE_TCL_STUBS RCC += -DFOSSIL_ENABLE_TCL=1 endif # With JSON support ifdef FOSSIL_ENABLE_JSON Index: win/Makefile.mingw.mistachkin ================================================================== --- win/Makefile.mingw.mistachkin +++ win/Makefile.mingw.mistachkin @@ -96,11 +96,11 @@ TCLINCDIR = $(TCLDIR)/include TCLLIBDIR = $(TCLDIR)/lib #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)? # -LIBTCL = -ltcl86 +LIBTCL = -ltclstub86 #### C Compile and options for use in building executables that # will run on the target platform. This is usually the same # as BCC, unless you are cross-compiling. This C compiler builds # the finished binary for fossil. The BCC compiler above is used @@ -134,13 +134,13 @@ ifdef FOSSIL_ENABLE_SSL TCC += -DFOSSIL_ENABLE_SSL=1 RCC += -DFOSSIL_ENABLE_SSL=1 endif -# With Tcl support (statically linked) +# With Tcl support ifdef FOSSIL_ENABLE_TCL -TCC += -DFOSSIL_ENABLE_TCL=1 -DSTATIC_BUILD +TCC += -DFOSSIL_ENABLE_TCL=1 -DUSE_TCL_STUBS RCC += -DFOSSIL_ENABLE_TCL=1 endif # With JSON support ifdef FOSSIL_ENABLE_JSON