Skip to content

Commit

Permalink
Update to latest rules.vc/nmakehlp.c
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.nijtmans committed Nov 10, 2023
1 parent 1d9d691 commit d617e5f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
42 changes: 22 additions & 20 deletions win/nmakehlp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* This is used to fix limitations within nmake and the environment.
*
* Copyright (c) 2002 by David Gravereaux.
* Copyright (c) 2006 by Pat Thoyts
* Copyright (c) 2002 David Gravereaux.
* Copyright (c) 2006 Pat Thoyts
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
Expand All @@ -19,7 +19,6 @@
#pragma comment (lib, "kernel32.lib")
#endif
#include <stdio.h>
#include <math.h>

/*
* This library is required for x64 builds with _some_ versions of MSVC
Expand All @@ -31,7 +30,7 @@
#endif

/* ISO hack for dumb VC++ */
#ifdef _MSC_VER
#if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1900
#define snprintf _snprintf
#endif

Expand Down Expand Up @@ -207,25 +206,25 @@ CheckForCompilerFeature(

hProcess = GetCurrentProcess();

ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
ZeroMemory(&si, sizeof(STARTUPINFO));
memset(&pi, 0, sizeof(PROCESS_INFORMATION));
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdInput = INVALID_HANDLE_VALUE;

ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES));
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = FALSE;

/*
* Create a non-inheritible pipe.
* Create a non-inheritable pipe.
*/

CreatePipe(&Out.pipe, &h, &sa, 0);

/*
* Dupe the write side, make it inheritible, and close the original.
* Dupe the write side, make it inheritable, and close the original.
*/

DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput, 0, TRUE,
Expand Down Expand Up @@ -272,7 +271,7 @@ CheckForCompilerFeature(
if (!ok) {
DWORD err = GetLastError();
int chars = snprintf(msg, sizeof(msg) - 1,
"Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
"Tried to launch: \"%s\", but got error [%lu]: ", cmdline, err);

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPSTR)&msg[chars],
Expand Down Expand Up @@ -343,13 +342,13 @@ CheckForLinkerFeature(

hProcess = GetCurrentProcess();

ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
ZeroMemory(&si, sizeof(STARTUPINFO));
memset(&pi, 0, sizeof(PROCESS_INFORMATION));
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdInput = INVALID_HANDLE_VALUE;

ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES));
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
Expand All @@ -361,7 +360,7 @@ CheckForLinkerFeature(
CreatePipe(&Out.pipe, &h, &sa, 0);

/*
* Dupe the write side, make it inheritible, and close the original.
* Dupe the write side, make it inheritable, and close the original.
*/

DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput, 0, TRUE,
Expand Down Expand Up @@ -406,7 +405,7 @@ CheckForLinkerFeature(
if (!ok) {
DWORD err = GetLastError();
int chars = snprintf(msg, sizeof(msg) - 1,
"Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
"Tried to launch: \"%s\", but got error [%lu]: ", cmdline, err);

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPSTR)&msg[chars],
Expand Down Expand Up @@ -593,7 +592,7 @@ list_free(list_item_t **listPtrPtr)
* 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
* e.g. 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:
Expand All @@ -619,7 +618,7 @@ SubstituteFile(
if (fp != NULL) {

/*
* Build a list of substutitions from the first filename
* Build a list of substitutions from the first filename
*/

sp = fopen(substitutions, "rt");
Expand Down Expand Up @@ -727,11 +726,13 @@ static int LocateDependencyHelper(const char *dir, const char *keypath)
int keylen, ret;
WIN32_FIND_DATA finfo;

if (dir == NULL || keypath == NULL)
if (dir == NULL || keypath == NULL) {
return 2; /* Have no real error reporting mechanism into nmake */
}
dirlen = strlen(dir);
if ((dirlen + 3) > sizeof(path))
if (dirlen > sizeof(path) - 3) {
return 2;
}
strncpy(path, dir, dirlen);
strncpy(path+dirlen, "\\*", 3); /* Including terminating \0 */
keylen = strlen(keypath);
Expand Down Expand Up @@ -797,8 +798,9 @@ static int LocateDependency(const char *keypath)

for (i = 0; i < (sizeof(paths)/sizeof(paths[0])); ++i) {
ret = LocateDependencyHelper(paths[i], keypath);
if (ret == 0)
if (ret == 0) {
return ret;
}
}
return ret;
}
Expand Down
6 changes: 5 additions & 1 deletion win/rules.vc
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,11 @@ TKIMPLIBNAME = tk$(TK_VERSION)$(SUFX).lib
TKLIBNAME = tcl9tk$(TK_VERSION)$(SUFX).$(EXT)
TKIMPLIBNAME = tcl9tk$(TK_VERSION)$(SUFX).lib
!endif
!if $(TK_MAJOR_VERSION) == 8
TKSTUBLIBNAME = tkstub$(TK_VERSION).lib
!else
TKSTUBLIBNAME = tkstub.lib
!endif

!if $(DOING_TK)
WISH = $(OUT_DIR)\$(WISHNAME)
Expand Down Expand Up @@ -1532,7 +1536,7 @@ cflags = -nologo -c $(COMPILERFLAGS) $(carch) $(cwarn) -Fp$(TMP_DIR)^\ $(cdebug)

!if $(TCL_MAJOR_VERSION) == 8 && $(TCL_MINOR_VERSION) < 7
cflags = $(cflags) -DTcl_Size=int
1endif
!endif

# appcflags contains $(cflags) and flags for building the application
# object files (e.g. tclsh, or wish) pkgcflags contains $(cflags) plus
Expand Down

0 comments on commit d617e5f

Please sign in to comment.