summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorpatthoyts <patthoyts@users.sourceforge.net>2006-06-14 15:21:12 (GMT)
committerpatthoyts <patthoyts@users.sourceforge.net>2006-06-14 15:21:12 (GMT)
commit509281cd2ab88a10a9e781f373d5e59f29f3bc79 (patch)
treeb7f93c0f3fad3eccfb16e8fcd337ce453d85e1c7 /win
parent0c32ed9ff184245f1517edf43a56d458a73b871f (diff)
downloadtcl-509281cd2ab88a10a9e781f373d5e59f29f3bc79.zip
tcl-509281cd2ab88a10a9e781f373d5e59f29f3bc79.tar.gz
tcl-509281cd2ab88a10a9e781f373d5e59f29f3bc79.tar.bz2
Enable building Tcl with Microsoft's latest compiler offering
(VS2005). We have to handle a number of oddities as they have deprecated most of the standard C library and now generate manifest files to be linked into the binaries. SF bug #1424909
Diffstat (limited to 'win')
-rw-r--r--win/makefile.vc32
-rw-r--r--win/nmakehlp.c54
-rw-r--r--win/rules.vc120
-rw-r--r--win/tclWinTime.c18
4 files changed, 173 insertions, 51 deletions
diff --git a/win/makefile.vc b/win/makefile.vc
index 7b8fe5f..417b13f 100644
--- a/win/makefile.vc
+++ b/win/makefile.vc
@@ -12,12 +12,13 @@
# Copyright (c) 2001-2002 David Gravereaux.
#
#------------------------------------------------------------------------------
-# RCS: @(#) $Id: makefile.vc,v 1.100.2.7 2005/11/30 00:15:39 hobbs Exp $
+# RCS: @(#) $Id: makefile.vc,v 1.100.2.8 2006/06/14 15:21:14 patthoyts Exp $
#------------------------------------------------------------------------------
# Check to see we are configured to build with MSVC (MSDEVDIR or MSVCDIR)
-# or with the MS Platform SDK (MSSDK)
-!if !defined(MSDEVDIR) && !defined(MSVCDIR) && !defined(MSSDK)
+# or with the MS Platform SDK (MSSDK). Visual Studio .NET 2003 and 2005 define
+# VCINSTALLDIR instead.
+!if !defined(MSDEVDIR) && !defined(MSVCDIR) && !defined(MSSDK) && !defined(VCINSTALLDIR)
MSG = ^
You need to run vcvars32.bat from Developer Studio or setenv.bat from the^
Platform SDK first to setup the environment. Jump to this line to read^
@@ -322,27 +323,20 @@ WINDIR = $(ROOT)\win
!if !$(DEBUG)
!if $(OPTIMIZING)
### This cranks the optimization level to maximize speed
-cdebug = -O2 -Op -Gs
+cdebug = -O2 $(OPTIMIZATIONS)
!else
cdebug =
!endif
!else if "$(MACHINE)" == "IA64"
### Warnings are too many, can't support warnings into errors.
-cdebug = -Z7 -Od
+cdebug = -Z7 -Od $(DEBUGFLAGS)
!else
-cdebug = -Z7 -WX -Od
+cdebug = -Z7 -WX $(DEBUGFLAGS)
!endif
### Declarations common to all compiler options
-cflags = -nologo -c -W3 -YX -Fp$(TMP_DIR)^\
-
-!if $(PENT_0F_ERRATA)
-cflags = $(cflags) -QI0f
-!endif
-
-!if $(ITAN_B_ERRATA)
-cflags = $(cflags) -QIA64_Bx
-!endif
+cwarn = -D _CRT_SECURE_NO_DEPRECATE -D _CRT_NONSTDC_NO_DEPRECATE
+cflags = -nologo -c $(COMPILERFLAGS) $(cwarn) -Fp$(TMP_DIR)^\
!if $(MSVCRT)
!if "$(DBGX)" == ""
@@ -458,6 +452,7 @@ $**
$(baselibs) @<<
$**
<<
+ $(_VC_MANIFEST_EMBED_DLL)
-@del $*.exp
!endif
@@ -466,13 +461,16 @@ $(TCLSTUBLIB): $(TCLSTUBOBJS)
$(TCLSH): $(TCLSHOBJS) $(TCLIMPLIB)
$(link32) $(conlflags) -stack:2300000 -out:$@ $(baselibs) $**
+ $(_VC_MANIFEST_EMBED_EXE)
$(TCLTEST): $(TCLTESTOBJS) $(TCLIMPLIB)
$(link32) $(conlflags) -stack:2300000 -out:$@ $(baselibs) $**
+ $(_VC_MANIFEST_EMBED_EXE)
$(TCLPIPEDLL): $(WINDIR)\stub16.c
$(cc32) $(CON_CFLAGS) -Fo$(TMP_DIR)\ $(WINDIR)\stub16.c
$(link32) $(conlflags) -out:$@ $(TMP_DIR)\stub16.obj $(baselibs)
+ $(_VC_MANIFEST_EMBED_DLL)
!if $(STATIC_BUILD)
$(TCLDDELIB): $(TMP_DIR)\tclWinDde.obj
@@ -481,6 +479,7 @@ $(TCLDDELIB): $(TMP_DIR)\tclWinDde.obj
$(TCLDDELIB): $(TMP_DIR)\tclWinDde.obj $(TCLSTUBLIB)
$(link32) $(dlllflags) -base:@$(WINDIR)\coffbase.txt,tcldde -out:$@ \
$** $(baselibs)
+ $(_VC_MANIFEST_EMBED_DLL)
-@del $*.exp
-@del $*.lib
!endif
@@ -492,6 +491,7 @@ $(TCLREGLIB): $(TMP_DIR)\tclWinReg.obj
$(TCLREGLIB): $(TMP_DIR)\tclWinReg.obj $(TCLSTUBLIB)
$(link32) $(dlllflags) -base:@$(WINDIR)\coffbase.txt,tclreg -out:$@ \
$** $(baselibs)
+ $(_VC_MANIFEST_EMBED_DLL)
-@del $*.exp
-@del $*.lib
!endif
@@ -500,7 +500,7 @@ $(CAT32): $(WINDIR)\cat.c
$(cc32) $(CON_CFLAGS) -Fo$(TMP_DIR)\ $?
$(link32) $(conlflags) -out:$@ -stack:16384 $(TMP_DIR)\cat.obj \
$(baselibs)
-
+ $(_VC_MANIFEST_EMBED_EXE)
#---------------------------------------------------------------------
# Regenerate the stubs files. [Development use only]
diff --git a/win/nmakehlp.c b/win/nmakehlp.c
index 4906303..48b82c4 100644
--- a/win/nmakehlp.c
+++ b/win/nmakehlp.c
@@ -9,9 +9,11 @@
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* ----------------------------------------------------------------------------
- * RCS: @(#) $Id: nmakehlp.c,v 1.1 2002/03/27 21:15:43 davygrvy Exp $
+ * RCS: @(#) $Id: nmakehlp.c,v 1.1.4.1 2006/06/14 15:21:15 patthoyts Exp $
* ----------------------------------------------------------------------------
*/
+
+#define _CRT_SECURE_NO_DEPRECATE
#include <windows.h>
#pragma comment (lib, "user32.lib")
#pragma comment (lib, "kernel32.lib")
@@ -41,6 +43,19 @@ 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 affected by the outside world.
+ */
+
+ SetEnvironmentVariable("CL", "");
+ SetEnvironmentVariable("LINK", "");
+
if (argc > 1 && *argv[1] == '-') {
switch (*(argv[1]+1)) {
case 'c':
@@ -90,11 +105,11 @@ CheckForCompilerFeature (const char *option)
STARTUPINFO si;
PROCESS_INFORMATION pi;
SECURITY_ATTRIBUTES sa;
- DWORD threadID;
+ DWORD threadID, n;
char msg[300];
BOOL ok;
HANDLE hProcess, h, pipeThreads[2];
- char cmdline[100];
+ char cmdline[256];
hProcess = GetCurrentProcess();
@@ -122,11 +137,16 @@ CheckForCompilerFeature (const char *option)
0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
/* base command line */
- strcpy(cmdline, "cl.exe -nologo -c -TC -Fdtemp ");
+ n = GetEnvironmentVariable("CC", cmdline, 255);
+ cmdline[n] = 0;
+ if (n == 0)
+ strcpy(cmdline, "cl.exe");
+ strncat(cmdline, " -nologo -c -TC -Zs -X ", 255);
+
/* 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. */
@@ -175,8 +195,28 @@ CheckForCompilerFeature (const char *option)
CloseHandle(pipeThreads[0]);
CloseHandle(pipeThreads[1]);
- /* look for the commandline warning code in both streams. */
- return !(strstr(Out.buffer, "D4002") != NULL || strstr(Err.buffer, "D4002") != NULL);
+#ifdef _DEBUG
+ {
+ DWORD err = 0;
+ strcat(cmdline, "\n");
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), cmdline,
+ strlen(cmdline), &err, NULL);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), Out.buffer,
+ strlen(Out.buffer), &err,NULL);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), Err.buffer,
+ strlen(Err.buffer), &err,NULL);
+ }
+#endif
+
+ /*
+ * Look for the commandline warning code in both streams.
+ * - in MSVC 6 & 7 we get D4002, in MSVC 8 we get D9002.
+ */
+
+ return !(strstr(Out.buffer, "D4002") != NULL
+ || strstr(Err.buffer, "D4002") != NULL
+ || strstr(Out.buffer, "D9002") != NULL
+ || strstr(Err.buffer, "D9002") != NULL);
}
int
diff --git a/win/rules.vc b/win/rules.vc
index 3cc84b0..05a3062 100644
--- a/win/rules.vc
+++ b/win/rules.vc
@@ -8,9 +8,10 @@
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# Copyright (c) 2001-2002 David Gravereaux.
+# Copyright (c) 2003 Patrick Thoyts
#
#------------------------------------------------------------------------------
-# RCS: @(#) $Id: rules.vc,v 1.11 2003/03/01 01:22:46 hobbs Exp $
+# RCS: @(#) $Id: rules.vc,v 1.11.2.1 2006/06/14 15:21:15 patthoyts Exp $
#------------------------------------------------------------------------------
!ifndef _RULES_VC
@@ -25,7 +26,7 @@ rc32 = $(RC) # built-in default.
### Assume the normal default.
_INSTALLDIR = C:\Program Files\Tcl
!else
-### Fix the path seperators.
+### Fix the path separators.
_INSTALLDIR = $(INSTALLDIR:/=\)
!endif
@@ -61,7 +62,7 @@ RMDIR = deltree /Y
#----------------------------------------------------------
!if !exist(nmakehlp.exe)
-!if [$(cc32) -nologo -ML nmakehlp.c -link -subsystem:console > nul]
+!if [$(cc32) -nologo nmakehlp.c -link -subsystem:console > nul]
!endif
!endif
@@ -70,7 +71,7 @@ RMDIR = deltree /Y
#----------------------------------------------------------
### test for optimizations
-!if [nmakehlp -c -Otip]
+!if [nmakehlp -c -Ot]
!message *** Compiler has 'Optimizations'
OPTIMIZING = 1
!else
@@ -78,15 +79,67 @@ OPTIMIZING = 1
OPTIMIZING = 0
!endif
+OPTIMIZATIONS =
+
+!if [nmakehlp -c -Ot]
+OPTIMIZATIONS = $(OPTIMIZATIONS) -Ot
+!endif
+
+!if [nmakehlp -c -Oi]
+OPTIMIZATIONS = $(OPTIMIZATIONS) -Oi
+!endif
+
+!if [nmakehlp -c -Op]
+OPTIMIZATIONS = $(OPTIMIZATIONS) -Op
+!endif
+
+!if [nmakehlp -c -fp:strict]
+OPTIMIZATIONS = $(OPTIMIZATIONS) -fp:strict
+!endif
+
+!if [nmakehlp -c -Gs]
+OPTIMIZATIONS = $(OPTIMIZATIONS) -Gs
+!endif
+
+!if [nmakehlp -c -GS]
+OPTIMIZATIONS = $(OPTIMIZATIONS) -GS
+!endif
+
+DEBUGFLAGS =
+
+!if [nmakehlp -c -RTC1]
+DEBUGFLAGS = $(DEBUGFLAGS) -RTC1
+!elseif [nmakehlp -c -GZ]
+DEBUGFLAGS = $(DEBUGFLAGS) -GZ
+!endif
+
+COMPILERFLAGS =-W3
+
+!if [nmakehlp -c -YX]
+OPTIMIZATIONS = $(OPTIMIZATIONS) -YX
+!endif
+
!if "$(MACHINE)" == "IX86"
### test for pentium errata
!if [nmakehlp -c -QI0f]
!message *** Compiler has 'Pentium 0x0f fix'
-PENT_0F_ERRATA = 1
+COMPILERFLAGS = $(COMPILERFLAGSS) -QI0f
!else
!message *** Compiler doesn't have 'Pentium 0x0f fix'
-PENT_0F_ERRATA = 0
!endif
+!endif
+
+!if "$(MACHINE)" == "IA64"
+### test for Itanium errata
+!if [nmakehlp -c -QIA64_Bx]
+!message *** Compiler has 'B-stepping errata workarounds'
+COMPILERFLAGS = $(COMPILERFLAGS) -QIA64_Bx
+!else
+!message *** Compiler does not have 'B-stepping errata workarounds'
+!endif
+!endif
+
+!if "$(MACHINE)" == "IX86"
### test for -align:4096, when align:512 will do.
!if [nmakehlp -l -opt:nowin98]
!message *** Linker has 'Win98 alignment problem'
@@ -96,21 +149,26 @@ ALIGN98_HACK = 1
ALIGN98_HACK = 0
!endif
!else
-PENT_0F_ERRATA = 0
ALIGN98_HACK = 0
!endif
-!if "$(MACHINE)" == "IA64"
-### test for Itanium errata
-!if [nmakehlp -c -QIA64_Bx]
-!message *** Compiler has 'B-stepping errata workarounds'
-ITAN_B_ERRATA = 1
-!else
-!message *** Compiler doesn't have 'B-stepping errata workarounds'
-ITAN_B_ERRATA = 0
-!endif
+#----------------------------------------------------------
+# MSVC8 (ships with Visual Studio 2005) generates a manifest
+# file that we should link into the binaries. This is how.
+#----------------------------------------------------------
+
+_VC_MANIFEST_EMBED_EXE=
+_VC_MANIFEST_EMBED_DLL=
+!if ![cl /Zs /Tc NUL 2>&1 | find "Version 12" > NUL]
+VCVER=6
+!elseif ![cl /Zs /Tc NUL 2>&1 | find "Version 13" > NUL]
+VCVER=7
+!elseif ![cl /Zs /Tc NUL 2>&1 | find "Version 14" > NUL]
+VCVER=8
+_VC_MANIFEST_EMBED_EXE=if exist $@.manifest mt -nologo -manifest $@.manifest -outputresource:$@;1
+_VC_MANIFEST_EMBED_DLL=if exist $@.manifest mt -nologo -manifest $@.manifest -outputresource:$@;2
!else
-ITAN_B_ERRATA = 0
+VCVER=0
!endif
#----------------------------------------------------------
@@ -126,6 +184,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 +234,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
@@ -203,6 +268,10 @@ DBGX =
SUFX = $(SUFX:g=)
!endif
+!if $(VCVER) > 6
+BUILDDIRTOP =$(BUILDDIRTOP)_VC$(VCVER)
+!endif
+
TMP_DIRFULL = .\$(BUILDDIRTOP)\$(PROJECT)_ThreadedDynamicStaticX
!if !$(STATIC_BUILD)
@@ -283,6 +352,18 @@ OPTDEFINES = $(OPTDEFINES) -DUSE_THREAD_ALLOC=1
OPTDEFINES = $(OPTDEFINES) -DSTATIC_BUILD
!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" || "$(MACHINE)" == "AMD64"
+OPTDEFINES = $(OPTDEFINES) -DTCL_CFG_DO64BIT
+!endif
+
#----------------------------------------------------------
# Get common info used when building extensions.
@@ -296,7 +377,7 @@ TCLINSTALL = 1
_TCLDIR = $(_INSTALLDIR)
!else
MSG=^
-Don't know where tcl.h is. Set the TCLDIR macro.
+Failed to find tcl.h. Set the TCLDIR macro.
!error $(MSG)
!endif
!else
@@ -307,7 +388,7 @@ TCLINSTALL = 1
TCLINSTALL = 0
!else
MSG =^
-Don't know where tcl.h is. The TCLDIR macro doesn't appear correct.
+Failed to find tcl.h. The TCLDIR macro does not appear correct.
!error $(MSG)
!endif
!endif
@@ -356,5 +437,6 @@ TCLTOOLSDIR = $(_TCLDIR)\tools
!message *** Output directory will be '$(OUT_DIR)'
!message *** Suffix for binaries will be '$(SUFX)'
!message *** Optional defines are '$(OPTDEFINES)'
+!message *** Compiler version $(VCVER) options are '$(OPTIMIZATIONS) $(DEBUGFLAGS)'
!endif
diff --git a/win/tclWinTime.c b/win/tclWinTime.c
index dbb6dbc..842d114 100644
--- a/win/tclWinTime.c
+++ b/win/tclWinTime.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinTime.c,v 1.14.2.8 2005/03/30 05:31:13 hobbs Exp $
+ * RCS: @(#) $Id: tclWinTime.c,v 1.14.2.9 2006/06/14 15:21:15 patthoyts Exp $
*/
#include "tclWinInt.h"
@@ -422,7 +422,7 @@ Tcl_GetTime(timePtr)
timeInfo.fileTimeLastCall.QuadPart = curFileTime;
timeInfo.perfCounterLastCall.QuadPart = curCounter.QuadPart;
usecSincePosixEpoch = ( curFileTime - posixEpoch.QuadPart ) / 10;
- timePtr->sec = (time_t) ( usecSincePosixEpoch / 1000000 );
+ timePtr->sec = (long) ( usecSincePosixEpoch / 1000000 );
timePtr->usec = (unsigned long ) ( usecSincePosixEpoch % 1000000 );
useFtime = 0;
}
@@ -434,7 +434,7 @@ Tcl_GetTime(timePtr)
/* High resolution timer is not available. Just use ftime */
ftime(&t);
- timePtr->sec = t.time;
+ timePtr->sec = (long)t.time;
timePtr->usec = t.millitm * 1000;
}
}
@@ -636,9 +636,9 @@ TclpGetDate(t, useGMT)
}
time /= 24;
- tmPtr->tm_mday += time;
- tmPtr->tm_yday += time;
- tmPtr->tm_wday = (tmPtr->tm_wday + time) % 7;
+ tmPtr->tm_mday += (int)time;
+ tmPtr->tm_yday += (int)time;
+ tmPtr->tm_wday = (tmPtr->tm_wday + (int)time) % 7;
}
} else {
tmPtr = ComputeGMT(tp);
@@ -679,8 +679,8 @@ ComputeGMT(tp)
* Compute the 4 year span containing the specified time.
*/
- tmp = *tp / SECSPER4YEAR;
- rem = *tp % SECSPER4YEAR;
+ tmp = (long)(*tp / SECSPER4YEAR);
+ rem = (LONG)(*tp % SECSPER4YEAR);
/*
* Correct for weird mod semantics so the remainder is always positive.
@@ -746,7 +746,7 @@ ComputeGMT(tp)
* Compute day of week. Epoch started on a Thursday.
*/
- tmPtr->tm_wday = (*tp / SECSPERDAY) + 4;
+ tmPtr->tm_wday = (long)(*tp / SECSPERDAY) + 4;
if ((*tp % SECSPERDAY) < 0) {
tmPtr->tm_wday--;
}