From 3cd73d42bf155fe9953db8705f9f3f9671479a11 Mon Sep 17 00:00:00 2001
From: davygrvy <davygrvy@noemail.net>
Date: Wed, 27 Oct 2004 00:36:33 +0000
Subject: * win/makefile.vc:  Backport to the most recent * win/rules.vc:    
 changes on the HEAD. * win/nmakehlp.c:

FossilOrigin-Name: e79198cc2fb38268ca4dc33eeadec7a86762cb9c
---
 win/makefile.vc |  26 ++++++++++---
 win/nmakehlp.c  |  80 ++++++++++++++++++++++++++++++++------
 win/rules.vc    | 117 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 3 files changed, 191 insertions(+), 32 deletions(-)

diff --git a/win/makefile.vc b/win/makefile.vc
index dd06325..8b162bb 100644
--- a/win/makefile.vc
+++ b/win/makefile.vc
@@ -12,10 +12,10 @@
 # Copyright (c) 2001-2002 David Gravereaux.
 #
 #------------------------------------------------------------------------------
-# RCS: @(#) $Id: makefile.vc,v 1.67.2.6 2004/05/10 08:30:30 patthoyts Exp $
+# RCS: @(#) $Id: makefile.vc,v 1.67.2.7 2004/10/27 00:36:33 davygrvy Exp $
 #------------------------------------------------------------------------------
 
-!if "$(MSVCDIR)" == ""
+!if !defined(MSDEVDIR) && !defined(MSVCDIR)
 MSG = ^
 You'll need to run vcvars32.bat from Developer Studio, first, to setup^
 the environment.  Jump to this line to read the new instructions.
@@ -165,16 +165,26 @@ PROJECT	= tk
 !endif
 
 STUBPREFIX = $(PROJECT)stub
-DOTVERSION = 8.4
+!if [nmakehlp -g ../generic/tk.h TK_VERSION] == 84
+DOTVERSION	= 8.5
+!elseif [nmakehlp -g ../generic/tk.h TK_VERSION] == 85
+DOTVERSION	= 8.5
+!elseif [nmakehlp -g ../generic/tk.h TK_VERSION] == 86
+DOTVERSION	= 8.6
+!elseif [nmakehlp -g ../generic/tk.h TK_VERSION] == 90
+DOTVERSION	= 9.0
+!elseif [nmakehlp -g ../generic/tk.h TK_VERSION] == 0
+MSG =^
+Can't get version string from ../generic/tk.h
+!error $(MSG)
+!endif
 VERSION = $(DOTVERSION:.=)
 WISHNAMEPREFIX = wish
 
 BINROOT		= .
 ROOT		= ..
 
-#TCLIMPLIBNAME	= tcl$(VERSION)$(SUFX).lib
-#TCLLIB	= tcl$(VERSION)$(SUFX).$(EXT)
-#TCLSTUBLIBNAME	= tclstub$(VERSION).lib
+TK_LIBRARY	= $(ROOT)\library
 
 TKIMPLIB	= "$(OUT_DIR)\$(PROJECT)$(VERSION)$(SUFX).lib"
 TKLIBNAME	= $(PROJECT)$(VERSION)$(SUFX).$(EXT)
@@ -452,6 +462,7 @@ tktest:	  setup $(TKTEST) $(CAT32)
 
 test: setup $(TKTEST) $(TKLIB) $(CAT32)
 	set TCL_LIBRARY=$(TCL_LIBRARY)
+	set TK_LIBRARY=$(TK_LIBRARY)
 !if $(TCLINSTALL)
 	set PATH=$(_TCLDIR)\bin;$(PATH)
 !else
@@ -465,6 +476,7 @@ test: setup $(TKTEST) $(TKLIB) $(CAT32)
 
 runtest: setup $(TKTEST) $(TKLIB) $(CAT32)
 	set TCL_LIBRARY=$(TCL_LIBRARY)
+	set TK_LIBRARY=$(TK_LIBRARY)
 !if $(TCLINSTALL)
 	set PATH=$(_TCLDIR)\bin;$(PATH)
 !else
@@ -555,6 +567,7 @@ install-libraries:
 #---------------------------------------------------------------------
 
 genstubs:
+	set TCL_LIBRARY=$(TCL_LIBRARY)
 	$(TCLSH) $(_TCLDIR)\tools\genStubs.tcl $(GENERICDIR) \
 		$(GENERICDIR)\$(PROJECT).decls $(GENERICDIR)\$(PROJECT)Int.decls
 
@@ -567,6 +580,7 @@ depend:
 !if !exist($(TCLSH))
 	@echo Build tclsh first!
 !else
+	set TCL_LIBRARY=$(TCL_LIBRARY)
 	$(TCLSH) $(TOOLSDIR:\=/)/mkdepend.tcl -vc32 -out:"$(OUT_DIR)\depend.mk" \
 		-passthru:"-DBUILD_tcl $(TK_INCLUDES:"="")" $(GENERICDIR) \
 		$(COMPATDIR) $(WINDIR) @<<
diff --git a/win/nmakehlp.c b/win/nmakehlp.c
index 9a27028..ff0bfd9 100644
--- a/win/nmakehlp.c
+++ b/win/nmakehlp.c
@@ -9,23 +9,27 @@
  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  *
  * ----------------------------------------------------------------------------
- * RCS: @(#) $Id: nmakehlp.c,v 1.1 2002/03/28 23:23:03 davygrvy Exp $
+ * RCS: @(#) $Id: nmakehlp.c,v 1.1.6.1 2004/10/27 00:36:34 davygrvy Exp $
  * ----------------------------------------------------------------------------
  */
 #include <windows.h>
 #pragma comment (lib, "user32.lib")
 #pragma comment (lib, "kernel32.lib")
+#include <stdio.h>
 
 /* protos */
 int CheckForCompilerFeature (const char *option);
 int CheckForLinkerFeature (const char *option);
 int IsIn (const char *string, const char *substring);
+int GrepForDefine (const char *file, const char *string);
 DWORD WINAPI ReadFromPipe (LPVOID args);
 
 /* globals */
+#define CHUNK	25
+#define STATICBUFFERSIZE    1000
 typedef struct {
     HANDLE pipe;
-    char buffer[1000];
+    char buffer[STATICBUFFERSIZE];
 } pipeinfo;
 
 pipeinfo Out = {INVALID_HANDLE_VALUE, '\0'};
@@ -41,6 +45,13 @@ main (int argc, char *argv[])
     DWORD dwWritten;
     int chars;
 
+    /* make sure children (cl.exe and link.exe) are kept quiet. */
+    SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
+
+    /* Make sure the compiler and linker aren't effected by the outside world. */
+    SetEnvironmentVariable("CL", "");
+    SetEnvironmentVariable("LINK", "");
+
     if (argc > 1 && *argv[1] == '-') {
 	switch (*(argv[1]+1)) {
 	case 'c':
@@ -74,6 +85,15 @@ main (int argc, char *argv[])
 	    } else {
 		return IsIn(argv[2], argv[3]);
 	    }
+	case 'g':
+	    if (argc == 2) {
+		chars = wsprintf(msg, "usage: %s -g <file> <string>\n"
+		    "grep for a #define\n"
+		    "exitcodes: integer of the found string (no decimals)\n", argv[0]);
+		WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars, &dwWritten, NULL);
+		return 2;
+	    }
+	    return GrepForDefine(argv[2], argv[3]);
 	}
     }
     chars = wsprintf(msg, "usage: %s -c|-l|-f ...\n"
@@ -122,11 +142,11 @@ CheckForCompilerFeature (const char *option)
 	    0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
 
     /* base command line */
-    strcpy(cmdline, "cl.exe -nologo -c -TC -Fdtemp ");
+    strcpy(cmdline, "cl.exe -nologo -c -TC -Zs -X ");
     /* append our option for testing */
     strcat(cmdline, option);
     /* filename to compile, which exists, but is nothing and empty. */
-    strcat(cmdline, " nul");
+    strcat(cmdline, " .\\nul");
 
     ok = CreateProcess(
 	    NULL,	    /* Module name. */
@@ -166,10 +186,6 @@ CheckForCompilerFeature (const char *option)
     WaitForSingleObject(pi.hProcess, INFINITE);
     CloseHandle(pi.hProcess);
 
-    /* clean up temporary files before returning */
-    DeleteFile("temp.idb");
-    DeleteFile("temp.pdb");
-
     /* wait for our pipe to get done reading, should it be a little slow. */
     WaitForMultipleObjects(2, pipeThreads, TRUE, 500);
     CloseHandle(pipeThreads[0]);
@@ -220,8 +236,6 @@ CheckForLinkerFeature (const char *option)
     strcpy(cmdline, "link.exe -nologo ");
     /* append our option for testing */
     strcat(cmdline, option);
-    /* filename to compile, which exists, but is nothing and empty. */
-//    strcat(cmdline, " nul");
 
     ok = CreateProcess(
 	    NULL,	    /* Module name. */
@@ -279,7 +293,11 @@ ReadFromPipe (LPVOID args)
     BOOL ok;
 
 again:
-    ok = ReadFile(pi->pipe, lastBuf, 25, &dwRead, 0L);
+    if (lastBuf - pi->buffer + CHUNK > STATICBUFFERSIZE) {
+	CloseHandle(pi->pipe);
+	return -1;
+    }
+    ok = ReadFile(pi->pipe, lastBuf, CHUNK, &dwRead, 0L);
     if (!ok || dwRead == 0) {
 	CloseHandle(pi->pipe);
 	return 0;
@@ -295,3 +313,43 @@ IsIn (const char *string, const char *substring)
 {
     return (strstr(string, substring) != NULL);
 }
+
+/*
+ *  Find a specified #define by name.
+ *
+ *  If the line is '#define TCL_VERSION "8.5"', it returns
+ *  85 as the result.
+ */
+
+int
+GrepForDefine (const char *file, const char *string)
+{
+    FILE *f;
+    char s1[51], s2[51], s3[51];
+    int r = 0;
+    double d1;
+
+    f = fopen(file, "rt");
+    if (f == NULL) {
+	return 0;
+    }
+
+    do {
+	r = fscanf(f, "%50s", s1);
+	if (r == 1 && !strcmp(s1, "#define")) {
+	    /* get next two words */
+	    r = fscanf(f, "%50s %50s", s2, s3);
+	    if (r != 2) continue;
+	    /* is the first word what we're looking for? */
+	    if (!strcmp(s2, string)) {
+		fclose(f);
+		/* add 1 past first double quote char. "8.5" */
+		d1 = atof(s3 + 1);		  /*    8.5  */
+		return ((int) (d1 * 10) & 0xFF);  /*    85   */
+	    }
+	}
+    } while (!feof(f));
+
+    fclose(f);
+    return 0;
+}
diff --git a/win/rules.vc b/win/rules.vc
index fd4c1c7..deb75bd 100644
--- a/win/rules.vc
+++ b/win/rules.vc
@@ -7,10 +7,10 @@
 # See the file "license.terms" for information on usage and redistribution
 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 # 
-# Copyright (c) 2001-2002 David Gravereaux.
+# Copyright (c) 2001-2003 David Gravereaux.
 #
 #------------------------------------------------------------------------------
-# RCS: @(#) $Id: rules.vc,v 1.5.2.1 2003/03/23 02:25:22 kennykb Exp $
+# RCS: @(#) $Id: rules.vc,v 1.5.2.2 2004/10/27 00:36:34 davygrvy Exp $
 #------------------------------------------------------------------------------
 
 !ifndef _RULES_VC
@@ -33,6 +33,9 @@ _INSTALLDIR	= $(INSTALLDIR:/=\)
 MACHINE		= IX86
 !endif
 
+!ifndef CFG_ENCODING
+CFG_ENCODING	= \"cp1252\"
+!endif
 
 #----------------------------------------------------------
 # Set the proper copy method to avoid overwrite questions
@@ -126,6 +129,7 @@ MSVCRT		= 0
 LOIMPACT	= 0
 TCL_USE_STATIC_PACKAGES	= 0
 USE_THREAD_ALLOC = 0
+UNCHECKED	= 0
 !else
 !if [nmakehlp -f $(OPTS) "static"]
 !message *** Doing static
@@ -175,6 +179,12 @@ USE_THREAD_ALLOC = 1
 !else
 USE_THREAD_ALLOC = 0
 !endif
+!if [nmakehlp -f $(OPTS) "unchecked"]
+!message *** Doing unchecked
+UNCHECKED = 1
+!else
+UNCHECKED = 0
+!endif
 !endif
 
 
@@ -192,14 +202,25 @@ TCL_USE_STATIC_PACKAGES = 0
 # by accident.
 #----------------------------------------------------------
 
+#----------------------------------------
+# Naming convention:
+#   t = full thread support.
+#   s = static library (as opposed to an
+#	import library)
+#   g = linked to the debug enabled C
+#	run-time.
+#   x = special static build when it
+#	links to the dynamic C run-time.
+#----------------------------------------
 SUFX	    = tsgx
 
 !if $(DEBUG)
 BUILDDIRTOP = Debug
-DBGX	    = g
 !else
 BUILDDIRTOP = Release
-DBGX	    =
+!endif
+
+!if !$(DEBUG) || $(DEBUG) && $(UNCHECKED)
 SUFX	    = $(SUFX:g=)
 !endif
 
@@ -263,12 +284,36 @@ TCL_COMPILE_DEBUG   = 0
 
 
 #----------------------------------------------------------
+# Decode the checks requested.
+#----------------------------------------------------------
+
+!if "$(CHECKS)" == "" || [nmakehlp -f "$(CHECKS)" "none"]
+TCL_NO_DEPRECATED	    = 0
+FULLWARNINGS		    = 0
+!else
+!if [nmakehlp -f $(CHECKS) "nodep"]
+!message *** Doing nodep check
+TCL_NO_DEPRECATED	    = 1
+!else
+TCL_NO_DEPRECATED	    = 0
+!endif
+!if [nmakehlp -f $(CHECKS) "fullwarn"]
+!message *** Doing full warnings check
+FULLWARNINGS		    = 1
+!else
+FULLWARNINGS		    = 0
+!endif
+!endif
+
+
+#----------------------------------------------------------
 # Set our defines now armed with our options.
 #----------------------------------------------------------
 
-OPTDEFINES	=
+OPTDEFINES	= -DTCL_CFGVAL_ENCODING=$(CFG_ENCODING)
+
 !if $(TCL_MEM_DEBUG)
-OPTDEFINES	= -DTCL_MEM_DEBUG
+OPTDEFINES	= $(OPTDEFINES) -DTCL_MEM_DEBUG
 !endif
 !if $(TCL_COMPILE_DEBUG)
 OPTDEFINES	= $(OPTDEFINES) -DTCL_COMPILE_DEBUG -DTCL_COMPILE_STATS
@@ -282,6 +327,21 @@ OPTDEFINES	= $(OPTDEFINES) -DUSE_THREAD_ALLOC=1
 !if $(STATIC_BUILD)
 OPTDEFINES	= $(OPTDEFINES) -DSTATIC_BUILD
 !endif
+!if $(TCL_NO_DEPRECATED)
+OPTDEFINES	= $(OPTDEFINES) -DTCL_NO_DEPRECATED
+!endif
+
+!if $(DEBUG)
+OPTDEFINES	= $(OPTDEFINES) -DTCL_CFG_DEBUG
+!elseif $(OPTIMIZING)
+OPTDEFINES	= $(OPTDEFINES) -DTCL_CFG_OPTIMIZED
+!endif
+!if $(PROFILE)
+OPTDEFINES	= $(OPTDEFINES) -DTCL_CFG_PROFILED
+!endif
+!if "$(MACHINE)" == "IA64"
+OPTDEFINES	= $(OPTDEFINES) -DTCL_CFG_DO64BIT
+!endif
 
 
 #----------------------------------------------------------
@@ -292,6 +352,7 @@ OPTDEFINES	= $(OPTDEFINES) -DSTATIC_BUILD
 
 !if !defined(TCLDIR)
 !if exist("$(_INSTALLDIR)\include\tcl.h")
+TCLH		= "$(_INSTALLDIR)\include\tcl.h"
 TCLINSTALL	= 1
 _TCLDIR		= $(_INSTALLDIR)
 !else
@@ -302,8 +363,10 @@ Don't know where tcl.h is.  Set the TCLDIR macro.
 !else
 _TCLDIR	= $(TCLDIR:/=\)
 !if exist("$(_TCLDIR)\include\tcl.h")
+TCLH		= "$(_TCLDIR)\include\tcl.h"
 TCLINSTALL	= 1
 !elseif exist("$(_TCLDIR)\generic\tcl.h")
+TCLH		= "$(_TCLDIR)\generic\tcl.h"
 TCLINSTALL	= 0
 !else
 MSG =^
@@ -312,19 +375,43 @@ Don't know where tcl.h is.  The TCLDIR macro doesn't appear correct.
 !endif
 !endif
 
-### TODO: add a command to nmakehlp.c to grep for Tcl's version from tcl.h.
-### Because nmake can't return a string, we'll need to play games with return
-### codes.  It might look something like this:
-#!if [nmakehlp -g $(TCL.H)] == 81
-#TCL_DOTVERSION	= 8.1
-#!elseif [nmakehlp -g $(TCL.H)] == 82
-#TCL_DOTVERSION	= 8.2
-#...
-#!endif
+#----------------------------------------------------------
+# Get the version from the header file.  Try all possibles
+# even though some aren't fully valid.
+#----------------------------------------------------------
 
+!if [nmakehlp -g $(TCLH) TCL_VERSION] == 76
+TCL_DOTVERSION	= 7.6
+!elseif [nmakehlp -g $(TCLH) TCL_VERSION] == 80
+TCL_DOTVERSION	= 8.0
+!elseif [nmakehlp -g $(TCLH) TCL_VERSION] == 81
+TCL_DOTVERSION	= 8.1
+!elseif [nmakehlp -g $(TCLH) TCL_VERSION] == 82
+TCL_DOTVERSION	= 8.2
+!elseif [nmakehlp -g $(TCLH) TCL_VERSION] == 83
+TCL_DOTVERSION	= 8.3
+!elseif [nmakehlp -g $(TCLH) TCL_VERSION] == 84
 TCL_DOTVERSION	= 8.4
+!elseif [nmakehlp -g $(TCLH) TCL_VERSION] == 85
+TCL_DOTVERSION	= 8.5
+!elseif [nmakehlp -g $(TCLH) TCL_VERSION] == 86
+TCL_DOTVERSION	= 8.6
+!elseif [nmakehlp -g $(TCLH) TCL_VERSION] == 90
+TCL_DOTVERSION	= 9.0
+!elseif [nmakehlp -g $(TCLH) TCL_VERSION] == 0
+MSG =^
+Can't get version string from $(TCLH)
+!error $(MSG)
+!endif
+
 TCL_VERSION	= $(TCL_DOTVERSION:.=)
 
+!if $(TCL_VERSION) < 81
+TCL_DOES_STUBS	= 0
+!else
+TCL_DOES_STUBS	= 1
+!endif
+
 !if $(TCLINSTALL)
 TCLSH		= "$(_INSTALLDIR)\bin\tclsh$(TCL_VERSION)$(SUFX).exe"
 TCLSTUBLIB	= "$(_INSTALLDIR)\lib\tclstub$(TCL_VERSION).lib"
-- 
cgit v0.12