# Copyright (c) 1998-2000 Ajuba Solutions.
# Copyright (c) 2001 ActiveState Corporation.
# Copyright (c) 2001-2002 David Gravereaux.
-# Copyright (c) 2003 Pat Thoyts
+# Copyright (c) 2003-2006 Pat Thoyts
#
#-------------------------------------------------------------------------
# RCS: @(#)$Id$
#-------------------------------------------------------------------------
-!if !defined(MSDEVDIR) && !defined(MSVCDIR) && !defined(VCToolkitInstallDir)
+# Check to see we are configured to build with MSVC (MSDEVDIR or MSVCDIR)
+# or with the MS Platform SDK (MSSDK). Visual Studio .NET 2003 and 2005 define
+# VCINSTALLDIR instead. The MSVC Toolkit release defines yet another.
+!if !defined(MSDEVDIR) && !defined(MSVCDIR) && !defined(MSSDK) && !defined(VCINSTALLDIR) && !defined(VCToolkitInstallDir)
MSG = ^
-You will need to run vcvars32.bat from Developer Studio, first, to setup^
-the environment. Jump to this line to read the new instructions.
+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^
+the build instructions.
!error $(MSG)
!endif
# staticpkg = Effects the static option only to switch
# tclshXX.exe to have the dde and reg extension linked
# inside it.
-# threads = Turns on full multithreading support.
+# nothreads = Turns off multithreading support (not recommended)
# thrdalloc = Use the thread allocator (shared global free pool).
# symbols = Adds symbols for step debugging.
# profile = Adds profiling hooks. Map file is assumed.
# memdbg = Enables the debugging memory allocator.
# compdbg = Enables byte compilation logging.
#
-# MACHINE=(IX86|IA64|ALPHA)
+# MACHINE=(IX86|IA64|ALPHA|AMD64)
# Set the machine type used for the compiler, linker, and
# resource compiler. This hook is needed to tell the tools
# when alternate platforms are requested. IX86 is the default
-# when not specified.
+# when not specified. If the CPU environment variable has been
+# set (ie: recent Platform SDK) then MACHINE is set from CPU.
#
# TMP_DIR=<path>
# OUT_DIR=<path>
#-------------------------------------------------------------------------
PROJECT = tclstorage
+
+# If your project uses Tk then you should uncomment the next line
+# USES_TK = 1
+
!include "rules.vc"
-DOTVERSION = 1.2.0
+DOTVERSION = 1.3.0
VERSION = $(DOTVERSION:.=)
STUBPREFIX = $(PROJECT)stub
!if !$(DEBUG)
!if $(OPTIMIZING)
### This cranks the optimization level to maximize speed
-cdebug = -O2 -Op -Gs
+cdebug = -Zi $(OPTIMIZATIONS)
!else
-cdebug =
+cdebug = -Zi
!endif
-!else if "$(MACHINE)" == "IA64"
+!else if "$(MACHINE)" == "IA64" || "$(MACHINE)" == "AMD64"
### Warnings are too many, can't support warnings into errors.
-cdebug = -Z7 -Od -GZ
+cdebug = -Zi -Od $(DEBUGFLAGS)
!else
-cdebug = -Z7 -WX -Od -GZ
+cdebug = -Zi -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 = $(WARNINGS) -D _CRT_SECURE_NO_DEPRECATE -D _CRT_NONSTDC_NO_DEPRECATE
+cflags = -nologo -c $(COMPILERFLAGS) $(cwarn) -Fp$(TMP_DIR)^\
!if $(MSVCRT)
-!if $(DEBUG)
+!if $(DEBUG) && !$(UNCHECKED)
crt = -MDd
!else
crt = -MD
!endif
!else
-!if $(DEBUG)
+!if $(DEBUG) && !$(UNCHECKED)
crt = -MTd
!else
crt = -MT
!endif
!endif
+!if !$(STATIC_BUILD)
+cflags = $(cflags) -DUSE_TCL_STUBS
+!if defined(TKSTUBLIB)
+cflags = $(cflags) -DUSE_TK_STUBS
+!endif
+!endif
+
INCLUDES = $(TCL_INCLUDES) -I"$(WINDIR)" -I"$(GENERICDIR)"
-BASE_CLFAGS = $(cflags) $(cdebug) $(crt) $(INCLUDES)
+BASE_CFLAGS = $(cflags) $(cdebug) $(crt) $(INCLUDES)
CON_CFLAGS = $(cflags) $(cdebug) $(crt) -DCONSOLE
-TCL_CFLAGS = -DUSE_TCL_STUBS -DPACKAGE_VERSION="\"$(DOTVERSION)\"" \
- $(BASE_CLFAGS) $(OPTDEFINES)
+TCL_CFLAGS = -DPACKAGE_NAME="\"Storage\"" \
+ -DPACKAGE_VERSION="\"$(DOTVERSION)\"" \
+ $(BASE_CFLAGS) $(OPTDEFINES)
+
+### Stubs files should not be compiled with -GL
+STUB_CFLAGS = $(cflags) $(cdebug:-GL=) $(TK_DEFINES)
#---------------------------------------------------------------------
# Link flags
#---------------------------------------------------------------------
!if $(DEBUG)
-ldebug = -debug:full -debugtype:cv
+ldebug = -debug
+!if $(MSVCRT)
+ldebug = $(ldebug) -nodefaultlib:msvcrt
+!endif
!else
-ldebug = -release -opt:ref -opt:icf,3
+ldebug = -debug -opt:ref -opt:icf,3
!endif
### Declarations common to all linker options
-lflags = -nologo -machine:$(MACHINE) $(ldebug)
+lflags = -nologo -machine:$(MACHINE) $(LINKERFLAGS) $(ldebug)
!if $(PROFILE)
lflags = $(lflags) -profile
dlllflags = $(lflags) -dll
conlflags = $(lflags) -subsystem:console
guilflags = $(lflags) -subsystem:windows
-baselibs = $(TCLSTUBLIB) ole32.lib advapi32.lib
+!if !$(STATIC_BUILD)
+baselibs = $(TCLSTUBLIB)
+!if defined(TKSTUBLIB)
+baselibs = $(baselibs) $(TKSTUBLIB)
+!endif
+!endif
+
+# Avoid 'unresolved external symbol __security_cookie' errors.
+# c.f. http://support.microsoft.com/?id=894573
+!if "$(MACHINE)" == "IA64" || "$(MACHINE)" == "AMD64"
+baselibs = $(baselibs) bufferoverflowU.lib
+!endif
#---------------------------------------------------------------------
# TclTest flags
#---------------------------------------------------------------------
all: setup $(PROJECT)
-$(PROJECT): setup $(PRJLIB)
-install: install-binaries install-libraries install-docs
+$(PROJECT): setup $(PRJLIB) pkgIndex
+install: install-binaries install-libraries install-docs install-demos
+pkgIndex: setup $(OUT_DIR)\pkgIndex.tcl
docs: $(HTMLDOCS)
-# Tests need to ensure we load the right dll file we
-# have to handle the output differently on Win9x.
-#
-!if "$(OS)" == "Windows_NT" || "$(MSVCDIR)" == "IDE"
test: setup $(PROJECT)
- set TCL_LIBRARY=$(ROOT)/library
- $(TCLSH) <<
-load $(PRJLIB:\=/) Storage
-cd "$(ROOT)/tests"
-set argv "$(TESTFLAGS)"
-source all.tcl
-<<
-!else
-test: setup $(PROJECT)
- echo Please wait while the test results are collected
- set TCL_LIBRARY=$(ROOT)/library
- $(TCLSH) << >tests.log
-load $(PRJLIB:\=/) Storage
-cd "$(ROOT)/tests"
-set argv "$(TESTFLAGS)"
-source all.tcl
-<<
- type tests.log | more
-!endif
+ @set TCL_LIBRARY=$(TCL_LIBRARY:\=/)
+ @set PATH=$(_TCLBINDIR);$(PATH)
+ @set TCLLIBPATH=$(OUT_DIR:\=/) $(LIBDIR:\=/)
+ $(DEBUGGER) $(TCLSH) "$(ROOT)/tests/all.tcl" $(TESTFLAGS)
+
+shell: setup $(PROJECT)
+ @set TCL_LIBRARY=$(TCL_LIBRARY:\=/)
+ @set PATH=$(_TCLBINDIR);$(PATH)
+ @set TCLLIBPATH=$(OUT_DIR:\=/) $(LIBDIR:\=/)
+ $(DEBUGGER) $(TCLSH) $(SCRIPT)
setup:
@if not exist $(OUT_DIR)\nul mkdir $(OUT_DIR)
@if not exist $(TMP_DIR)\nul mkdir $(TMP_DIR)
-$(PRJLIB): $(DLLOBJS) $(RCRES)
- $(link32) $(dlllflags) -out:$@ $(baselibs) @<<
+$(PRJLIB): $(DLLOBJS)
+!if $(STATIC_BUILD)
+ $(lib32) -nologo -out:$@ @<<
+$**
+<<
+!else
+ $(link32) $(dlllflags) -base:0x14110000 -out:$@ $(baselibs) @<<
$**
<<
+ $(_VC_MANIFEST_EMBED_DLL)
-@del $*.exp
+!endif
$(PRJSTUBLIB): $(PRJSTUBOBJS)
$(lib32) -nologo -out:$@ $(PRJSTUBOBJS)
.SUFFIXES:
.SUFFIXES:.c .rc .man
+#-------------------------------------------------------------------------
+# Explicit dependency rules
+#
+#-------------------------------------------------------------------------
+
+$(OUT_DIR)\pkgIndex.tcl: $(ROOT)\pkgIndex.tcl.in
+ @nmakehlp -s << $** > $@
+@PACKAGE_VERSION@ $(DOTVERSION)
+@PACKAGE_NAME@ $(PROJECT)
+@PKG_LIB_FILE@ $(PRJLIBNAME)
+<<
+
#---------------------------------------------------------------------
# Installation. (EDIT)
#
@if not exist "$(SCRIPT_INSTALL_DIR)" mkdir "$(SCRIPT_INSTALL_DIR)"
@$(CPY) $(PRJLIB) "$(SCRIPT_INSTALL_DIR)" >NUL
-install-libraries:
+install-libraries: pkgIndex
@echo Installing libraries to '$(SCRIPT_INSTALL_DIR)'
- @if exist $(LIBDIR) $(CPY) $(LIBDIR)\*.tcl "$(SCRIPT_INSTALL_DIR)" >NUL
+ @if exist $(LIBDIR) $(CPY) $(LIBDIR)\*.tcl "$(SCRIPT_INSTALL_DIR)"
@echo Installing package index in '$(SCRIPT_INSTALL_DIR)'
- @type << >"$(SCRIPT_INSTALL_DIR)\pkgIndex.tcl"
-# Hand-crafted pkgIndex.tcl
-if {![package vsatisfies [package provide Tcl] 8]} {return}
-if {[string compare $$::tcl_platform(platform) windows]} {return}
-if {[info exists ::tcl_platform(debug)]} {
- package ifneeded Storage $(DOTVERSION) \
- [list load [file join $$dir $(PROJECT)$(VERSION)_g.$(EXT)] Storage]
-} else {
- package ifneeded Storage $(DOTVERSION) \
- [list load [file join $$dir $(PROJECT)$(VERSION).$(EXT)] Storage]
-}
-package ifneeded vfs::stg $(DOTVERSION) [list source [file join $$dir stgvfs.tcl]]
-package ifneeded stgvfs $(DOTVERSION) [list source [file join $$dir stgvfs.tcl]]
-<<
+ @$(CPY) $(OUT_DIR)\pkgIndex.tcl "$(SCRIPT_INSTALL_DIR)"
install-docs:
@echo Installing documentation files to '$(DOC_INSTALL_DIR)'
@if exist $(DOCDIR) $(CPY) $(DOCDIR)\*.html "$(DOC_INSTALL_DIR)" >NUL
@if exist $(DOCDIR) $(CPY) $(DOCDIR)\*.css "$(DOC_INSTALL_DIR)" >NUL
+install-demos:
+ #@echo Installing sample applications in '$(DEMO_INSTALL_DIR)\demos'
+ #@if not exist "$(DEMO_INSTALL_DIR)\demos" mkdir "$(DEMO_INSTALL_DIR)\demos"
+ #@$(CPY) "$(ROOT)\demos" "$(DEMO_INSTALL_DIR)\demos" >NUL
+
#---------------------------------------------------------------------
# Clean up
#---------------------------------------------------------------------
clean:
@if exist $(TMP_DIR)\nul $(RMDIR) $(TMP_DIR)
- @if exist $(WINDIR)\version.vc del $(WINDIR)\version.vc
+ @if exist $(WINDIR)\versions.vc del $(WINDIR)\versions.vc
+ @if exist $(WINDIR)\vercl.i del $(WINDIR)\vercl.i
+ @if exist $(WINDIR)\vercl.x del $(WINDIR)\vercl.x
+ @if exist $(WINDIR)\_junk.pch del $(WINDIR)\_junk.pch
realclean: clean
@if exist $(OUT_DIR)\nul $(RMDIR) $(OUT_DIR)
-/* ----------------------------------------------------------------------------
+/*
+ * ----------------------------------------------------------------------------
* nmakehlp.c --
*
* This is used to fix limitations within nmake and the environment.
*
* Copyright (c) 2002 by David Gravereaux.
- * Copyright (c) 2003 by Patrick Thoyts
+ * Copyright (c) 2006 by Pat Thoyts
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* ----------------------------------------------------------------------------
- * RCS: @(#) $Id$
+ * RCS: @(#) $Id: nmakehlp.c,v 1.21 2007/12/14 02:27:11 patthoyts Exp $
* ----------------------------------------------------------------------------
*/
+
+#define _CRT_SECURE_NO_DEPRECATE
#include <windows.h>
-#include <stdio.h>
#pragma comment (lib, "user32.lib")
#pragma comment (lib, "kernel32.lib")
+#include <stdio.h>
+#include <math.h>
+
+/*
+ * This library is required for x64 builds with _some_ versions of MSVC
+ */
+#if defined(_M_IA64) || defined(_M_AMD64)
+#if _MSC_VER >= 1400 && _MSC_VER < 1500
+#pragma comment(lib, "bufferoverflowU")
+#endif
+#endif
+
+/* ISO hack for dumb VC++ */
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#endif
+
+
/* protos */
-int CheckForCompilerFeature (const char *option);
-int CheckForLinkerFeature (const char *option);
-int IsIn (const char *string, const char *substring);
-DWORD WINAPI ReadFromPipe (LPVOID args);
-int GetVersionFromHeader(const char *tclh, const char *tkh);
+
+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);
+int SubstituteFile(const char *substs, const char *filename);
+const char * GetVersionFromFile(const char *filename, const char *match);
+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'};
pipeinfo Err = {INVALID_HANDLE_VALUE, '\0'};
+\f
+/*
+ * exitcodes: 0 == no, 1 == yes, 2 == error
+ */
-
-
-/* exitcodes: 0 == no, 1 == yes, 2 == error */
int
-main (int argc, char *argv[])
+main(
+ int argc,
+ char *argv[])
{
char msg[300];
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':
if (argc != 3) {
- chars = wsprintf(msg, "usage: %s -c <compiler option>\n"
+ chars = snprintf(msg, sizeof(msg) - 1,
+ "usage: %s -c <compiler option>\n"
"Tests for whether cl.exe supports an option\n"
"exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars, &dwWritten, NULL);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+ &dwWritten, NULL);
return 2;
}
return CheckForCompilerFeature(argv[2]);
case 'l':
if (argc != 3) {
- chars = wsprintf(msg, "usage: %s -l <linker option>\n"
+ chars = snprintf(msg, sizeof(msg) - 1,
+ "usage: %s -l <linker option>\n"
"Tests for whether link.exe supports an option\n"
"exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars, &dwWritten, NULL);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+ &dwWritten, NULL);
return 2;
}
return CheckForLinkerFeature(argv[2]);
case 'f':
if (argc == 2) {
- chars = wsprintf(msg, "usage: %s -f <string> <substring>\n"
- "Find a substring within another\n"
- "exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars, &dwWritten, NULL);
+ chars = snprintf(msg, sizeof(msg) - 1,
+ "usage: %s -f <string> <substring>\n"
+ "Find a substring within another\n"
+ "exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+ &dwWritten, NULL);
return 2;
} else if (argc == 3) {
- /* if the string is blank, there is no match */
+ /*
+ * If the string is blank, there is no match.
+ */
+
return 0;
} else {
return IsIn(argv[2], argv[3]);
}
- case 'v':
+ case 'g':
+ if (argc == 2) {
+ chars = snprintf(msg, sizeof(msg) - 1,
+ "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]);
+ case 's':
+ if (argc == 2) {
+ chars = snprintf(msg, sizeof(msg) - 1,
+ "usage: %s -s <substitutions file> <file>\n"
+ "Perform a set of string map type substutitions on a file\n"
+ "exitcodes: 0\n",
+ argv[0]);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+ &dwWritten, NULL);
+ return 2;
+ }
+ return SubstituteFile(argv[2], argv[3]);
+ case 'V':
if (argc != 4) {
- chars = wsprintf(msg, "usage: %s -v <tcl.h> <tk.h>\n"
- "Search for versions from the tcl and tk headers.",
+ chars = snprintf(msg, sizeof(msg) - 1,
+ "usage: %s -V filename matchstring\n"
+ "Extract a version from a file:\n"
+ "eg: pkgIndex.tcl \"package ifneeded http\"",
argv[0]);
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars, &dwWritten, NULL);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+ &dwWritten, NULL);
return 0;
}
- return GetVersionFromHeader(argv[2], argv[3]);
+ printf("%s\n", GetVersionFromFile(argv[2], argv[3]));
+ return 0;
}
}
- chars = wsprintf(msg, "usage: %s -c|-l|-f ...\n"
+ chars = snprintf(msg, sizeof(msg) - 1,
+ "usage: %s -c|-l|-f|-g|-V ...\n"
"This is a little helper app to equalize shell differences between WinNT and\n"
"Win9x and get nmake.exe to accomplish its job.\n",
argv[0]);
WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars, &dwWritten, NULL);
return 2;
}
-
+\f
int
-CheckForCompilerFeature (const char *option)
+CheckForCompilerFeature(
+ const char *option)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = FALSE;
- /* create a non-inheritible pipe. */
+ /*
+ * Create a non-inheritible pipe.
+ */
+
CreatePipe(&Out.pipe, &h, &sa, 0);
- /* dupe the write side, make it inheritible, and close the original. */
- DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput,
- 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ /*
+ * Dupe the write side, make it inheritible, and close the original.
+ */
+
+ DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput, 0, TRUE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+
+ /*
+ * Same as above, but for the error side.
+ */
- /* Same as above, but for the error side. */
CreatePipe(&Err.pipe, &h, &sa, 0);
- DuplicateHandle(hProcess, h, hProcess, &si.hStdError,
- 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ DuplicateHandle(hProcess, h, hProcess, &si.hStdError, 0, TRUE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+
+ /*
+ * Base command line.
+ */
+
+ lstrcpy(cmdline, "cl.exe -nologo -c -TC -Zs -X -Fp.\\_junk.pch ");
+
+ /*
+ * Append our option for testing
+ */
+
+ lstrcat(cmdline, option);
+
+ /*
+ * Filename to compile, which exists, but is nothing and empty.
+ */
- /* base command line */
- strcpy(cmdline, "cl.exe -nologo -c -TC -Fdtemp ");
- /* append our option for testing */
- strcat(cmdline, option);
- /* filename to compile, which exists, but is nothing and empty. */
- strcat(cmdline, " nul");
+ lstrcat(cmdline, " .\\nul");
ok = CreateProcess(
NULL, /* Module name. */
if (!ok) {
DWORD err = GetLastError();
- int chars = wsprintf(msg, "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
+ int chars = snprintf(msg, sizeof(msg) - 1,
+ "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
- FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID) &msg[chars],
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
+ FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID)&msg[chars],
(300-chars), 0);
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, strlen(msg), &err, NULL);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg,lstrlen(msg), &err,NULL);
return 2;
}
- /* close our references to the write handles that have now been inherited. */
+ /*
+ * Close our references to the write handles that have now been inherited.
+ */
+
CloseHandle(si.hStdOutput);
CloseHandle(si.hStdError);
WaitForInputIdle(pi.hProcess, 5000);
CloseHandle(pi.hThread);
- /* start the pipe reader threads. */
+ /*
+ * Start the pipe reader threads.
+ */
+
pipeThreads[0] = CreateThread(NULL, 0, ReadFromPipe, &Out, 0, &threadID);
pipeThreads[1] = CreateThread(NULL, 0, ReadFromPipe, &Err, 0, &threadID);
- /* block waiting for the process to end. */
+ /*
+ * Block waiting for the process to end.
+ */
+
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.
+ */
- /* wait for our pipe to get done reading, should it be a little slow. */
WaitForMultipleObjects(2, pipeThreads, TRUE, 500);
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);
+ /*
+ * 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
+ || strstr(Out.buffer, "D2021") != NULL
+ || strstr(Err.buffer, "D2021") != NULL);
}
-
+\f
int
-CheckForLinkerFeature (const char *option)
+CheckForLinkerFeature(
+ const char *option)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
- /* create a non-inheritible pipe. */
+ /*
+ * Create a non-inheritible pipe.
+ */
+
CreatePipe(&Out.pipe, &h, &sa, 0);
- /* dupe the write side, make it inheritible, and close the original. */
- DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput,
- 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ /*
+ * Dupe the write side, make it inheritible, and close the original.
+ */
+
+ DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput, 0, TRUE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+
+ /*
+ * Same as above, but for the error side.
+ */
- /* Same as above, but for the error side. */
CreatePipe(&Err.pipe, &h, &sa, 0);
- DuplicateHandle(hProcess, h, hProcess, &si.hStdError,
- 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ DuplicateHandle(hProcess, h, hProcess, &si.hStdError, 0, TRUE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
- /* base command line */
- 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");
+ /*
+ * Base command line.
+ */
+
+ lstrcpy(cmdline, "link.exe -nologo ");
+
+ /*
+ * Append our option for testing.
+ */
+
+ lstrcat(cmdline, option);
ok = CreateProcess(
NULL, /* Module name. */
if (!ok) {
DWORD err = GetLastError();
- int chars = wsprintf(msg, "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
+ int chars = snprintf(msg, sizeof(msg) - 1,
+ "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
- FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID) &msg[chars],
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
+ FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID)&msg[chars],
(300-chars), 0);
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, strlen(msg), &err, NULL);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg,lstrlen(msg), &err,NULL);
return 2;
}
- /* close our references to the write handles that have now been inherited. */
+ /*
+ * Close our references to the write handles that have now been inherited.
+ */
+
CloseHandle(si.hStdOutput);
CloseHandle(si.hStdError);
WaitForInputIdle(pi.hProcess, 5000);
CloseHandle(pi.hThread);
- /* start the pipe reader threads. */
+ /*
+ * Start the pipe reader threads.
+ */
+
pipeThreads[0] = CreateThread(NULL, 0, ReadFromPipe, &Out, 0, &threadID);
pipeThreads[1] = CreateThread(NULL, 0, ReadFromPipe, &Err, 0, &threadID);
- /* block waiting for the process to end. */
+ /*
+ * Block waiting for the process to end.
+ */
+
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
- /* wait for our pipe to get done reading, should it be a little slow. */
+ /*
+ * Wait for our pipe to get done reading, should it be a little slow.
+ */
+
WaitForMultipleObjects(2, pipeThreads, TRUE, 500);
CloseHandle(pipeThreads[0]);
CloseHandle(pipeThreads[1]);
- /* look for the commandline warning code in the stderr stream. */
- return !(strstr(Out.buffer, "LNK1117") != NULL || strstr(Err.buffer, "LNK1117") != NULL);
-}
+ /*
+ * Look for the commandline warning code in the stderr stream.
+ */
+ return !(strstr(Out.buffer, "LNK1117") != NULL ||
+ strstr(Err.buffer, "LNK1117") != NULL ||
+ strstr(Out.buffer, "LNK4044") != NULL ||
+ strstr(Err.buffer, "LNK4044") != NULL);
+}
+\f
DWORD WINAPI
-ReadFromPipe (LPVOID args)
+ReadFromPipe(
+ LPVOID args)
{
pipeinfo *pi = (pipeinfo *) args;
char *lastBuf = pi->buffer;
DWORD dwRead;
BOOL ok;
-again:
- ok = ReadFile(pi->pipe, lastBuf, 25, &dwRead, 0L);
+ again:
+ if (lastBuf - pi->buffer + CHUNK > STATICBUFFERSIZE) {
+ CloseHandle(pi->pipe);
+ return (DWORD)-1;
+ }
+ ok = ReadFile(pi->pipe, lastBuf, CHUNK, &dwRead, 0L);
if (!ok || dwRead == 0) {
CloseHandle(pi->pipe);
return 0;
return 0; /* makes the compiler happy */
}
-
+\f
int
-IsIn (const char *string, const char *substring)
+IsIn(
+ const char *string,
+ const char *substring)
{
return (strstr(string, substring) != NULL);
}
+\f
+/*
+ * Find a specified #define by name.
+ *
+ * If the line is '#define TCL_VERSION "8.5"', it returns 85 as the result.
+ */
-
-static double
-ReadVersionFromHeader(const char *file, const char *macro)
+int
+GrepForDefine(
+ const char *file,
+ const char *string)
{
- double d = 0.0;
- CHAR szBuffer[100];
- LPSTR p;
- DWORD cbBuffer = 100;
- FILE *fp = fopen(file, "r");
+ char s1[51], s2[51], s3[51];
+ FILE *f = fopen(file, "rt");
+
+ if (f == NULL) {
+ return 0;
+ }
+
+ do {
+ int 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)) {
+ double d1;
+
+ fclose(f);
+
+ /*
+ * Add 1 past first double quote char. "8.5"
+ */
+
+ d1 = atof(s3 + 1); /* 8.5 */
+ while (floor(d1) != d1) {
+ d1 *= 10.0;
+ }
+ return ((int) d1); /* 85 */
+ }
+ }
+ } while (!feof(f));
+
+ fclose(f);
+ return 0;
+}
+\f
+/*
+ * GetVersionFromFile --
+ * Looks for a match string in a file and then returns the version
+ * following the match where a version is anything acceptable to
+ * package provide or package ifneeded.
+ */
+
+const char *
+GetVersionFromFile(
+ const char *filename,
+ const char *match)
+{
+ size_t cbBuffer = 100;
+ static char szBuffer[100];
+ char *szResult = NULL;
+ FILE *fp = fopen(filename, "rt");
+
if (fp != NULL) {
+ /*
+ * Read data until we see our match string.
+ */
+
while (fgets(szBuffer, cbBuffer, fp) != NULL) {
- if ((p = strstr(szBuffer, macro)) != NULL) {
- while (*p && !isdigit(*p)) ++p;
- d = strtod(p, NULL);
+ LPSTR p, q;
+
+ p = strstr(szBuffer, match);
+ if (p != NULL) {
+ /*
+ * Skip to first digit.
+ */
+
+ while (*p && !isdigit(*p)) {
+ ++p;
+ }
+
+ /*
+ * Find ending whitespace.
+ */
+
+ q = p;
+ while (*q && (isalnum(*q) || *q == '.')) {
+ ++q;
+ }
+
+ memcpy(szBuffer, p, q - p);
+ szBuffer[q-p] = 0;
+ szResult = szBuffer;
break;
}
}
fclose(fp);
}
- return d;
+ return szResult;
+}
+\f
+/*
+ * List helpers for the SubstituteFile function
+ */
+
+typedef struct list_item_t {
+ struct list_item_t *nextPtr;
+ char * key;
+ char * value;
+} list_item_t;
+
+/* insert a list item into the list (list may be null) */
+static list_item_t *
+list_insert(list_item_t **listPtrPtr, const char *key, const char *value)
+{
+ list_item_t *itemPtr = malloc(sizeof(list_item_t));
+ if (itemPtr) {
+ itemPtr->key = strdup(key);
+ itemPtr->value = strdup(value);
+ itemPtr->nextPtr = NULL;
+
+ while(*listPtrPtr) {
+ listPtrPtr = &(*listPtrPtr)->nextPtr;
+ }
+ *listPtrPtr = itemPtr;
+ }
+ return itemPtr;
+}
+
+static void
+list_free(list_item_t **listPtrPtr)
+{
+ list_item_t *tmpPtr, *listPtr = *listPtrPtr;
+ while (listPtr) {
+ tmpPtr = listPtr;
+ listPtr = listPtr->nextPtr;
+ free(tmpPtr->key);
+ free(tmpPtr->value);
+ free(tmpPtr);
+ }
}
+\f
+/*
+ * SubstituteFile --
+ * As windows doesn't provide anything useful like sed and it's unreliable
+ * to use the tclsh you are building against (consider x-platform builds -
+ * eg compiling AMD64 target from IX86) we provide a simple substitution
+ * option here to handle autoconf style substitutions.
+ * The substitution file is whitespace and line delimited. The file should
+ * consist of lines matching the regular expression:
+ * \s*\S+\s+\S*$
+ *
+ * Usage is something like:
+ * nmakehlp -S << $** > $@
+ * @PACKAGE_NAME@ $(PACKAGE_NAME)
+ * @PACKAGE_VERSION@ $(PACKAGE_VERSION)
+ * <<
+ */
int
-GetVersionFromHeader(const char *tclh, const char *tkh)
+SubstituteFile(
+ const char *substitutions,
+ const char *filename)
{
- double dTcl = 0.0, dTk = 0.0;
-
- if (tclh != NULL)
- dTcl = ReadVersionFromHeader(tclh, "TCL_VERSION");
- if (tkh != NULL)
- dTk = ReadVersionFromHeader(tkh, "TK_VERSION");
-
- if (dTcl > 0 || dTk > 0) {
- FILE *ofp = fopen("version.vc", "w");
- if (dTcl > 0)
- fprintf(ofp, "TCL_DOTVERSION\t= %0.1f\nTCL_VERSION\t= %u\n",
- dTcl, (int)(dTcl * 10.0));
- if (dTk > 0)
- fprintf(ofp, "TK_DOTVERSION\t= %0.1f\nTK_VERSION\t= %u\n",
- dTk, (int)(dTk * 10.0));
- fclose(ofp);
- return 0;
+ size_t cbBuffer = 1024;
+ static char szBuffer[1024], szCopy[1024];
+ char *szResult = NULL;
+ list_item_t *substPtr = NULL;
+ FILE *fp, *sp;
+
+ fp = fopen(filename, "rt");
+ if (fp != NULL) {
+
+ /*
+ * Build a list of substutitions from the first filename
+ */
+
+ sp = fopen(substitutions, "rt");
+ if (sp != NULL) {
+ while (fgets(szBuffer, cbBuffer, sp) != NULL) {
+ char *ks, *ke, *vs, *ve;
+ ks = szBuffer;
+ while (ks && *ks && isspace(*ks)) ++ks;
+ ke = ks;
+ while (ke && *ke && !isspace(*ke)) ++ke;
+ vs = ke;
+ while (vs && *vs && isspace(*vs)) ++vs;
+ ve = vs;
+ while (ve && *ve && !(*ve == '\r' || *ve == '\n')) ++ve;
+ *ke = 0, *ve = 0;
+ list_insert(&substPtr, ks, vs);
+ }
+ fclose(sp);
+ }
+
+ /* debug: dump the list */
+#ifdef _DEBUG
+ {
+ int n = 0;
+ list_item_t *p = NULL;
+ for (p = substPtr; p != NULL; p = p->nextPtr, ++n) {
+ fprintf(stderr, "% 3d '%s' => '%s'\n", n, p->key, p->value);
+ }
+ }
+#endif
+
+ /*
+ * Run the substitutions over each line of the input
+ */
+
+ while (fgets(szBuffer, cbBuffer, fp) != NULL) {
+ list_item_t *p = NULL;
+ for (p = substPtr; p != NULL; p = p->nextPtr) {
+ char *m = strstr(szBuffer, p->key);
+ if (m) {
+ char *cp, *op, *sp;
+ cp = szCopy;
+ op = szBuffer;
+ while (op != m) *cp++ = *op++;
+ sp = p->value;
+ while (sp && *sp) *cp++ = *sp++;
+ op += strlen(p->key);
+ while (*op) *cp++ = *op++;
+ *cp = 0;
+ memcpy(szBuffer, szCopy, sizeof(szCopy));
+ }
+ }
+ printf(szBuffer);
+ }
+
+ list_free(&substPtr);
}
- return 1;
+ fclose(fp);
+ return 0;
}
+
+/*
+ * Local variables:
+ * mode: c
+ * c-basic-offset: 4
+ * fill-column: 78
+ * indent-tabs-mode: t
+ * tab-width: 8
+ * End:
+ */
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# Copyright (c) 2001-2002 David Gravereaux.
-# Copyright (c) 2003 Patrick Thoyts
+# Copyright (c) 2003-2005 Patrick Thoyts
#
#------------------------------------------------------------------------------
-# RCS: @(#) $Id$
+# RCS: @(#) $Id: rules.vc,v 1.7 2007/09/06 21:12:38 patthoyts Exp $
#------------------------------------------------------------------------------
!ifndef _RULES_VC
!endif
!ifndef MACHINE
+!if "$(CPU)" == "" || "$(CPU)" == "i386"
MACHINE = IX86
+!else
+MACHINE = $(CPU)
+!endif
!endif
!ifndef CFG_ENCODING
!if "$(OS)" == "Windows_NT"
RMDIR = rmdir /S /Q
+ERRNULL = 2>NUL
!if ![ver | find "4.0" > nul]
-CPY = echo y | xcopy /i
+CPY = echo y | xcopy /i >NUL
+COPY = copy >NUL
!else
-CPY = xcopy /i /y
+CPY = xcopy /i /y >NUL
+COPY = copy /y >NUL
!endif
-!else
-CPY = xcopy /i
+!else # "$(OS)" != "Windows_NT"
+CPY = xcopy /i >_JUNK.OUT # On Win98 NUL does not work here.
+COPY = copy >_JUNK.OUT # On Win98 NUL does not work here.
RMDIR = deltree /Y
+NULL = \NUL # Used in testing directory existence
+ERRNULL = >NUL # Win9x shell cannot redirect stderr
!endif
-
+MKDIR = mkdir
!message ===============================================================================
#----------------------------------------------------------
!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
#----------------------------------------------------------
### test for optimizations
-!if [nmakehlp -c -Otip]
+!if [nmakehlp -c -Ot]
!message *** Compiler has 'Optimizations'
OPTIMIZING = 1
!else
-!message *** Compiler doesn't have 'Optimizations'
+!message *** Compiler does not have 'Optimizations'
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
+
+!if [nmakehlp -c -GL]
+OPTIMIZATIONS = $(OPTIMIZATIONS) -GL
+!endif
+
+DEBUGFLAGS =
+
+!if [nmakehlp -c -RTC1]
+DEBUGFLAGS = $(DEBUGFLAGS) -RTC1
+!elseif [nmakehlp -c -GZ]
+DEBUGFLAGS = $(DEBUGFLAGS) -GZ
+!endif
+
+COMPILERFLAGS =-W3
+
+# In v13 -GL and -YX are incompatible.
+!if [nmakehlp -c -YX]
+!if ![nmakehlp -c -GL]
+OPTIMIZATIONS = $(OPTIMIZATIONS) -YX
+!endif
+!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
+!message *** Compiler does not have 'Pentium 0x0f fix'
!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'
ALIGN98_HACK = 1
!else
-!message *** Linker doesn't have 'Win98 alignment problem'
+!message *** Linker does not have 'Win98 alignment problem'
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
+LINKERFLAGS =
+
+!if [nmakehlp -l -ltcg]
+LINKERFLAGS =-ltcg
!endif
-!else
-ITAN_B_ERRATA = 0
+
+#----------------------------------------------------------
+# 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=
+VCVER=0
+!if ![echo VCVERSION=_MSC_VER > vercl.x] \
+ && ![cl -nologo -TC -P vercl.x $(ERRNULL)]
+!include vercl.i
+!if $(VCVERSION) >= 1500
+VCVER=9
+!elseif $(VCVERSION) >= 1400
+VCVER=8
+!elseif $(VCVERSION) >= 1300
+VCVER=7
+!elseif $(VCVERSION) >= 1200
+VCVER=6
+!endif
+!endif
+
+# Since MSVC8 we must deal with manifest resources.
+!if $(VCVERSION) >= 1400
+_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
!endif
#----------------------------------------------------------
!if "$(OPTS)" == "" || [nmakehlp -f "$(OPTS)" "none"]
STATIC_BUILD = 0
-TCL_THREADS = 0
+TCL_THREADS = 1
DEBUG = 0
PROFILE = 0
MSVCRT = 0
LOIMPACT = 0
TCL_USE_STATIC_PACKAGES = 0
-USE_THREAD_ALLOC = 0
+USE_THREAD_ALLOC = 1
+USE_THREAD_STORAGE = 1
+UNCHECKED = 0
!else
!if [nmakehlp -f $(OPTS) "static"]
!message *** Doing static
!else
TCL_USE_STATIC_PACKAGES = 0
!endif
-!if [nmakehlp -f $(OPTS) "threads"]
-!message *** Doing threads
-TCL_THREADS = 1
-!else
+!if [nmakehlp -f $(OPTS) "nothreads"]
+!message *** Compile explicitly for non-threaded tcl
TCL_THREADS = 0
+!else
+TCL_THREADS = 1
!endif
!if [nmakehlp -f $(OPTS) "symbols"]
!message *** Doing symbols
!else
USE_THREAD_ALLOC = 0
!endif
+!if [nmakehlp -f $(OPTS) "thrdstorage"]
+!message *** Doing thrdstorage
+USE_THREAD_STORAGE = 1
+!else
+USE_THREAD_STORAGE = 0
+!endif
+!if [nmakehlp -f $(OPTS) "unchecked"]
+!message *** Doing unchecked
+UNCHECKED = 1
+!else
+UNCHECKED = 0
+!endif
!endif
# by accident.
#----------------------------------------------------------
-SUFX = tsgx
+#----------------------------------------
+# 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 = sgx
!if $(DEBUG)
BUILDDIRTOP = Debug
-DBGX = g
!else
BUILDDIRTOP = Release
-DBGX =
+!endif
+
+!if "$(MACHINE)" != "IX86"
+BUILDDIRTOP =$(BUILDDIRTOP)_$(MACHINE)
+!endif
+!if $(VCVER) > 6
+BUILDDIRTOP =$(BUILDDIRTOP)_VC$(VCVER)
+!endif
+
+!if !$(DEBUG) || $(DEBUG) && $(UNCHECKED)
SUFX = $(SUFX:g=)
!endif
!endif
+#----------------------------------------------------------
+# Decode the checks requested.
+#----------------------------------------------------------
+
+!if "$(CHECKS)" == "" || [nmakehlp -f "$(CHECKS)" "none"]
+TCL_NO_DEPRECATED = 0
+WARNINGS = -W3
+!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
+WARNINGS = -W4
+!if [nmakehlp -l -warn:3]
+LINKERFLAGS = $(LINKERFLAGS) -warn:3
+!endif
+!else
+WARNINGS = -W3
+!endif
+!if [nmakehlp -f $(CHECKS) "64bit"] && [nmakehlp -c -Wp64]
+!message *** Doing 64bit portability warnings
+WARNINGS = $(WARNINGS) -Wp64
+!endif
+!endif
+
#----------------------------------------------------------
# Set our defines now armed with our options.
#----------------------------------------------------------
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
!if $(USE_THREAD_ALLOC)
OPTDEFINES = $(OPTDEFINES) -DUSE_THREAD_ALLOC=1
!endif
+!if $(USE_THREAD_STORAGE)
+OPTDEFINES = $(OPTDEFINES) -DUSE_THREAD_STORAGE=1
+!endif
!endif
!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
!if $(PROFILE)
OPTDEFINES = $(OPTDEFINES) -DTCL_CFG_PROFILED
!endif
-!if "$(MACHINE)" == "IA64"
+!if "$(MACHINE)" == "IA64" || "$(MACHINE)" == "AMD64"
OPTDEFINES = $(OPTDEFINES) -DTCL_CFG_DO64BIT
!endif
#----------------------------------------------------------
-# Get common info used when building extensions.
+# Locate the Tcl headers to build against
#----------------------------------------------------------
-!if "$(PROJECT)" != "tcl"
+!if "$(PROJECT)" == "tcl"
+
+_TCL_H = ..\generic\tcl.h
+
+!else
# If INSTALLDIR set to tcl root dir then reset to the lib dir.
!if exist("$(_INSTALLDIR)\include\tcl.h")
!error $(MSG)
!endif
!endif
+!endif
-!if [nmakehlp -v $(_TCL_H) ""] == 0
-!include version.vc
+#--------------------------------------------------------------
+# Extract various version numbers from tcl headers
+# The generated file is then included in the makefile.
+#--------------------------------------------------------------
+
+!if [echo REM = This file is generated from rules.vc > versions.vc]
+!endif
+!if [echo TCL_MAJOR_VERSION = \>> versions.vc] \
+ && [nmakehlp -V "$(_TCL_H)" TCL_MAJOR_VERSION >> versions.vc]
+!endif
+!if [echo TCL_MINOR_VERSION = \>> versions.vc] \
+ && [nmakehlp -V "$(_TCL_H)" TCL_MINOR_VERSION >> versions.vc]
+!endif
+!if [echo TCL_PATCH_LEVEL = \>> versions.vc] \
+ && [nmakehlp -V "$(_TCL_H)" TCL_PATCH_LEVEL >> versions.vc]
+!endif
+
+# If building the tcl core then we need additional package versions
+!if "$(PROJECT)" == "tcl"
+!if [echo PKG_HTTP_VER = \>> versions.vc] \
+ && [nmakehlp -V ..\library\http\pkgIndex.tcl http >> versions.vc]
+!endif
+!if [echo PKG_TCLTEST_VER = \>> versions.vc] \
+ && [nmakehlp -V ..\library\tcltest\pkgIndex.tcl tcltest >> versions.vc]
+!endif
+!if [echo PKG_MSGCAT_VER = \>> versions.vc] \
+ && [nmakehlp -V ..\library\msgcat\pkgIndex.tcl msgcat >> versions.vc]
+!endif
+!if [echo PKG_PLATFORM_VER = \>> versions.vc] \
+ && [nmakehlp -V ..\library\platform\pkgIndex.tcl "platform " >> versions.vc]
+!endif
+!if [echo PKG_SHELL_VER = \>> versions.vc] \
+ && [nmakehlp -V ..\library\platform\pkgIndex.tcl "platform::shell" >> versions.vc]
+!endif
+!endif
+
+!include versions.vc
+
+#--------------------------------------------------------------
+# Setup tcl version dependent stuff headers
+#--------------------------------------------------------------
+
+!if "$(PROJECT)" != "tcl"
+
+TCL_VERSION = $(TCL_MAJOR_VERSION)$(TCL_MINOR_VERSION)
+
+!if $(TCL_VERSION) < 81
+TCL_DOES_STUBS = 0
!else
-TCL_DOTVERSION = 8.5
-TCL_VERSION = $(TCL_DOTVERSION:.=)
+TCL_DOES_STUBS = 1
!endif
!if $(TCLINSTALL)
-TCLSH = "$(_TCLDIR)\bin\tclsh$(TCL_VERSION)$(SUFX).exe"
+_TCLBINDIR = "$(_TCLDIR)\bin"
+TCLSH = "$(_TCLBINDIR)\tclsh$(TCL_VERSION)$(SUFX).exe"
+!if !exist($(TCLSH)) && $(TCL_THREADS)
+TCLSH = "$(_TCLBINDIR)\tclsh$(TCL_VERSION)t$(SUFX).exe"
+!endif
TCLSTUBLIB = "$(_TCLDIR)\lib\tclstub$(TCL_VERSION).lib"
TCLIMPLIB = "$(_TCLDIR)\lib\tcl$(TCL_VERSION)$(SUFX).lib"
TCL_LIBRARY = $(_TCLDIR)\lib
+TCLREGLIB = "$(_TCLDIR)\lib\tclreg11$(SUFX:t=).lib"
+TCLDDELIB = "$(_TCLDIR)\lib\tcldde12$(SUFX:t=).lib"
+COFFBASE = \must\have\tcl\sources\to\build\this\target
+TCLTOOLSDIR = \must\have\tcl\sources\to\build\this\target
TCL_INCLUDES = -I"$(_TCLDIR)\include"
!else
-TCLSH = "$(_TCLDIR)\win\$(BUILDDIRTOP)\tclsh$(TCL_VERSION)$(SUFX).exe"
+_TCLBINDIR = $(_TCLDIR)\win\$(BUILDDIRTOP)
+TCLSH = "$(_TCLBINDIR)\tclsh$(TCL_VERSION)$(SUFX).exe"
+!if !exist($(TCLSH)) && $(TCL_THREADS)
+TCLSH = "$(_TCLBINDIR)\tclsh$(TCL_VERSION)t$(SUFX).exe"
+!endif
TCLSTUBLIB = "$(_TCLDIR)\win\$(BUILDDIRTOP)\tclstub$(TCL_VERSION).lib"
TCLIMPLIB = "$(_TCLDIR)\win\$(BUILDDIRTOP)\tcl$(TCL_VERSION)$(SUFX).lib"
TCL_LIBRARY = $(_TCLDIR)\library
+TCLREGLIB = "$(_TCLDIR)\win\$(BUILDDIRTOP)\tclreg11$(SUFX:t=).lib"
+TCLDDELIB = "$(_TCLDIR)\win\$(BUILDDIRTOP)\tcldde12$(SUFX:t=).lib"
+COFFBASE = "$(_TCLDIR)\win\coffbase.txt"
+TCLTOOLSDIR = $(_TCLDIR)\tools
TCL_INCLUDES = -I"$(_TCLDIR)\generic" -I"$(_TCLDIR)\win"
!endif
!endif
-#----------------------------------------------------------
-# Get Tk info for building extensions.
-#----------------------------------------------------------
+#-------------------------------------------------------------------------
+# Locate the Tk headers to build against
+#-------------------------------------------------------------------------
-!if "$(PROJECT)" != "tcl" && "$(PROJECT)" != "tk"
+!if "$(PROJECT)" == "tk"
+_TK_H = ..\generic\tk.h
+!endif
+!ifdef PROJECT_REQUIRES_TK
!if !defined(TKDIR)
!if exist("$(_INSTALLDIR)\..\include\tk.h")
TKINSTALL = 1
_TKDIR = $(_TCLDIR)
_TK_H = $(_TKDIR)\include\tk.h
TKDIR = $(_TKDIR)
-!else
-MSG =^
-Failed to find tk.h. Set the TKDIR macro.
-!error $(MSG)
!endif
!else
_TKDIR = $(TKDIR:/=\)
!error $(MSG)
!endif
!endif
+!endif
-!if [nmakehlp -v $(_TCL_H) $(_TK_H)] == 0
-!include version.vc
-!else
-TK_DOTVERSION = 8.5
-TK_VERSION = $(TK_DOTVERSION:.=)
+#-------------------------------------------------------------------------
+# Extract Tk version numbers
+#-------------------------------------------------------------------------
+
+!if defined(PROJECT_REQUIRES_TK) || "$(PROJECT)" == "tk"
+
+!if [echo TK_MAJOR_VERSION = \>> versions.vc] \
+ && [nmakehlp -V $(_TK_H) TK_MAJOR_VERSION >> versions.vc]
+!endif
+!if [echo TK_MINOR_VERSION = \>> versions.vc] \
+ && [nmakehlp -V $(_TK_H) TK_MINOR_VERSION >> versions.vc]
+!endif
+!if [echo TK_PATCH_LEVEL = \>> versions.vc] \
+ && [nmakehlp -V $(_TK_H) TK_PATCH_LEVEL >> versions.vc]
!endif
+!include versions.vc
+
+TK_DOTVERSION = $(TK_MAJOR_VERSION).$(TK_MINOR_VERSION)
+TK_VERSION = $(TK_MAJOR_VERSION)$(TK_MINOR_VERSION)
+
+!if "$(PROJECT)" != "tk"
!if $(TKINSTALL)
-WISH = "$(_TKDIR)\bin\wish$(TK_VERSION)$(SUFX).exe"
+_TKBINDIR = $(_TKDIR)\bin
+WISH = "$(_TKBINDIR)\wish$(TK_VERSION)$(SUFX).exe"
+!if !exist($(WISH)) && $(TCL_THREADS)
+WISH = "$(_TKBINDIR)\wish$(TK_VERSION)t$(SUFX).exe"
+!endif
TKSTUBLIB = "$(_TKDIR)\lib\tkstub$(TK_VERSION).lib"
+TK_LIBRARY = $(_TKDIR)\lib
TKIMPLIB = "$(_TKDIR)\lib\tk$(TK_VERSION)$(SUFX).lib"
TK_INCLUDES = -I"$(_TKDIR)\include"
!else
-WISH = "$(_TKDIR)\win\$(BUILDDIRTOP)\wish$(TCL_VERSION)$(SUFX).exe"
+_TKBINDIR = $(_TKDIR)\win\$(BUILDDIRTOP)
+WISH = "$(_TKBINDIR)\wish$(TCL_VERSION)$(SUFX).exe"
+!if !exist($(WISH)) && $(TCL_THREADS)
+WISH = "$(_TKBINDIR)\wish$(TCL_VERSION)t$(SUFX).exe"
+!endif
TKSTUBLIB = "$(_TKDIR)\win\$(BUILDDIRTOP)\tkstub$(TCL_VERSION).lib"
TKIMPLIB = "$(_TKDIR)\win\$(BUILDDIRTOP)\tk$(TCL_VERSION)$(SUFX).lib"
+TK_LIBRARY = $(_TKDIR)\library
TK_INCLUDES = -I"$(_TKDIR)\generic" -I"$(_TKDIR)\win" -I"$(_TKDIR)\xlib"
!endif
-
!endif
-
+!endif
#----------------------------------------------------------
# Display stats being used.
!message *** Output directory will be '$(OUT_DIR)'
!message *** Suffix for binaries will be '$(SUFX)'
!message *** Optional defines are '$(OPTDEFINES)'
+!message *** Compiler version $(VCVER). Target machine is $(MACHINE)
+!message *** Compiler options '$(COMPILERFLAGS) $(OPTIMIZATIONS) $(DEBUGFLAGS) $(WARNINGS)'
+!message *** Link options '$(LINKERFLAGS)'
!endif