From b4e783e45a77d57ac3e8d3b49300bf378abd192e Mon Sep 17 00:00:00 2001 From: patthoyts Date: Wed, 12 Sep 2007 14:23:06 +0000 Subject: Use nmakehlp to substitute values for tclConfig.sh (helps cross-compiling). --- ChangeLog | 5 ++ win/makefile.vc | 128 ++++++++++++++++++++++------------------------- win/nmakehlp.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- win/rules.vc | 16 ++++-- 4 files changed, 223 insertions(+), 76 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70240cc..b7b0a41 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-09-12 Pat Thoyts + + * win/makefile.vc, win/rules.vc, win/nmakehlp.c: Use nmakehlp to + substitute values for tclConfig.sh (helps cross-compiling). + 2007-09-11 Don Porter * library/tcltest/tcltest.tcl: Accept underscores and colons in diff --git a/win/makefile.vc b/win/makefile.vc index 77b3538..7e1b5c6 100644 --- a/win/makefile.vc +++ b/win/makefile.vc @@ -12,7 +12,7 @@ # Copyright (c) 2001-2004 David Gravereaux. # #------------------------------------------------------------------------------ -# RCS: @(#) $Id: makefile.vc,v 1.162 2007/07/31 14:03:30 msofer Exp $ +# RCS: @(#) $Id: makefile.vc,v 1.163 2007/09/12 14:23:08 patthoyts Exp $ #------------------------------------------------------------------------------ # Check to see we are configured to build with MSVC (MSDEVDIR or MSVCDIR) @@ -736,77 +736,65 @@ install-docs: # Build tclConfig.sh for the TEA build system. #--------------------------------------------------------------------- -tclConfig: -!if !exist($(TCLSH)) - @echo Build tclsh first! -!else +tclConfig: $(OUT_DIR)\tclConfig.sh + +$(OUT_DIR)\tclConfig.sh: $(WINDIR)\tclConfig.sh.in @echo Creating tclConfig.sh - @set TCL_LIBRARY=$(ROOT)/library - @$(TCLSH) << - set debug $(DEBUG) - set thread $(TCL_THREADS) - set static $(STATIC_BUILD) - set config(@TCL_DLL_FILE@) {$(TCLLIBNAME)} - set config(@TCL_VERSION@) [info tcl] - set config(@TCL_MAJOR_VERSION@) [lindex [split [info tclversion] .] 0] - set config(@TCL_MINOR_VERSION@) [lindex [split [info tclversion] .] 1] - set config(@TCL_PATCH_LEVEL@) [string range [info patchlevel] [string length [info tclversion]] end] - set config(@CC@) {$(CC)} - set config(@DEFS@) {} - if {$$static} {lappend config(@DEFS@) "-DSTATIC_BUILD=1"} - if {$$thread} {lappend config(@DEFS@) "-DTHREAD=1"} - set config(@TCL_DBGX@) {$(DBGX)} - set config(@CFLAGS_DEBUG@) {-nologo -c -W3 -YX -Fp$(TMP_DIR)\ -MDd} - set config(@CFLAGS_OPTIMIZE@) {-nologo -c -W3 -YX -Fp$(TMP_DIR)\ -MD} - set config(@LDFLAGS_DEBUG@) {-nologo -machine:$(MACHINE) -debug:full -debugtype:cv} - set config(@LDFLAGS_OPTIMIZE@) {-nologo -machine:$(MACHINE) -release -opt:ref -opt:icf,3} - set config(@TCL_SHARED_BUILD@) [expr {$$static ? 0 : 1}] - set config(@TCL_LIB_FILE@) {$(PROJECT)$(VERSION)$(SUFX).lib} - set config(@TCL_NEEDS_EXP_FILE@) {} - set config(@CFG_TCL_EXPORT_FILE_SUFFIX@) {$${NODOT_VERSION}$${DBGX}.lib} - set config(@LIBS@) {$(baselibs)} - set config(@prefix@) {$(_INSTALLDIR)} - set config(@exec_prefix@) {$(BIN_INSTALL_DIR)} - set config(@SHLIB_CFLAGS@) {} - set config(@STLIB_CFLAGS@) {} - set config(@CFLAGS_WARNING@) {-W3} - set config(@EXTRA_CFLAGS@) {-YX} - set config(@SHLIB_LD@) {$(link32) $(dlllflags)} - set config(@STLIB_LD@) {$(lib32) -nologo} - set config(@SHLIB_LD_LIBS@) {$(baselibs)} - set config(@SHLIB_SUFFIX@) {.dll} - set config(@DL_LIBS@) {} - set config(@LDFLAGS@) {} - set config(@TCL_LD_SEARCH_FLAGS@) {} - set config(@LIBOBJS@) {} - set config(@RANLIB@) {} - set config(@TCL_LIB_FLAG@) {} - set config(@TCL_BUILD_LIB_SPEC@) {} - set config(@TCL_LIB_SPEC@) {$(LIB_INSTALL_DIR)\$(PROJECT)$(VERSION)$(SUFX).lib} - set config(@TCL_INCLUDE_SPEC@) {-I$(INCLUDE_INSTALL_DIR)} - set config(@TCL_LIB_VERSIONS_OK@) {} - set config(@CFG_TCL_SHARED_LIB_SUFFIX@) {$${NODOT_VERSION}$${DBGX}.dll} - set config(@CFG_TCL_UNSHARED_LIB_SUFFIX@) {$${NODOT_VERSION}$${DBGX}.lib} - set config(@TCL_SRC_DIR@) [file nativename [file normalize {$(ROOT)}]] - set config(@TCL_PACKAGE_PATH@) {} - set config(@TCL_STUB_LIB_FILE@) {$(TCLSTUBLIBNAME)} - set config(@TCL_STUB_LIB_FLAG@) {$(TCLSTUBLIBNAME)} - set config(@TCL_BUILD_STUB_LIB_SPEC@) "-L[file nativename [file normalize {$(OUT_DIR)}]] $(TCLSTUBLIBNAME)" - set config(@TCL_STUB_LIB_SPEC@) {-L$(LIB_INSTALL_DIR) $(TCLSTUBLIBNAME)} - set config(@TCL_BUILD_STUB_LIB_PATH@) [file nativename [file normalize {$(TCLSTUBLIB)}]] - set config(@TCL_STUB_LIB_PATH@) [file nativename [file normalize {$(LIB_INSTALL_DIR)\\$(TCLSTUBLIBNAME)}]] - set config(@TCL_THREADS@) {$(TCL_THREADS)} - set f [open tclConfig.sh.in r] - set data [read $$f] - close $$f - foreach {anchor subst} [array get config] { - regsub -all $$anchor $$data $$subst data - } - set f [open [file join [file normalize {$(OUT_DIR)}] tclConfig.sh] w] - puts $$f $$data - close $$f -<< + @nmakehlp -s << $** >$@ +@TCL_DLL_FILE@ $(TCLLIBNAME) +@TCL_VERSION@ $(DOTVERSION) +@TCL_MAJOR_VERSION@ $(TCL_MAJOR_VERSION) +@TCL_MINOR_VERSION@ $(TCL_MINOR_VERSION) +@TCL_PATCH_LEVEL@ $(TCL_PATCH_LEVEL) +@CC@ $(CC) +@DEFS@ $(TCL_CFLAGS) +@CFLAGS_DEBUG@ -nologo -c -W3 -YX -Fp$(TMP_DIR)\ -MDd +@CFLAGS_OPTIMIZE@ -nologo -c -W3 -YX -Fp$(TMP_DIR)\ -MD +@LDFLAGS_DEBUG@ -nologo -machine:$(MACHINE) -debug:full -debugtype:cv +@LDFLAGS_OPTIMIZE@ -nologo -machine:$(MACHINE) -release -opt:ref -opt:icf,3 +@TCL_DBGX@ $(SUFX) +@TCL_LIB_FILE@ $(PROJECT)$(VERSION)$(SUFX).lib +@TCL_NEEDS_EXP_FILE@ +@LIBS@ $(baselibs) +@prefix@ $(_INSTALLDIR) +@exec_prefix@ $(BIN_INSTALL_DIR) +@SHLIB_CFLAGS@ +@STLIB_CFLAGS@ +@CFLAGS_WARNING@ -W3 +@EXTRA_CFLAGS@ -YX +@SHLIB_LD@ $(link32) $(dlllflags) +@STLIB_LD@ $(lib32) -nologo +@SHLIB_LD_LIBS@ $(baselibs) +@SHLIB_SUFFIX@ .dll +@DL_LIBS@ +@LDFLAGS@ +@TCL_LD_SEARCH_FLAGS@ +@LIBOBJS@ +@RANLIB@ +@TCL_LIB_FLAG@ +@TCL_BUILD_LIB_SPEC@ +@TCL_LIB_SPEC@ $(LIB_INSTALL_DIR)\$(PROJECT)$(VERSION)$(SUFX).lib +@TCL_INCLUDE_SPEC@ -I$(INCLUDE_INSTALL_DIR) +@TCL_LIB_VERSIONS_OK@ +@TCL_SRC_DIR@ $(ROOT) +@TCL_PACKAGE_PATH@ +@TCL_STUB_LIB_FILE@ $(TCLSTUBLIBNAME) +@TCL_STUB_LIB_FLAG@ $(TCLSTUBLIBNAME) +@TCL_STUB_LIB_SPEC@ -L$(LIB_INSTALL_DIR) $(TCLSTUBLIBNAME) +@TCL_THREADS@ $(TCL_THREADS) +@TCL_BUILD_STUB_LIB_SPEC@ -L$(OUT_DIR) $(TCLSTUBLIBNAME) +@TCL_BUILD_STUB_LIB_PATH@ $(TCLSTUBLIB) +@TCL_STUB_LIB_PATH@ $(LIB_INSTALL_DIR)\$(TCLSTUBLIBNAME) +@CFG_TCL_EXPORT_FILE_SUFFIX@ $(VERSION)$(SUFX).lib +@CFG_TCL_SHARED_LIB_SUFFIX@ $(VERSION)$(SUFX).dll +@CFG_TCL_UNSHARED_LIB_SUFFIX@ $(VERSION)$(SUFX).lib +!if $(STATIC_BUILD) +@TCL_SHARED_BUILD@ 0 +!else +@TCL_SHARED_BUILD@ 1 !endif +<< + # The following target generates the file generic/tclDate.c # from the yacc grammar found in generic/tclGetDate.y. This is diff --git a/win/nmakehlp.c b/win/nmakehlp.c index 5fb7917..6a7fc96 100644 --- a/win/nmakehlp.c +++ b/win/nmakehlp.c @@ -11,7 +11,7 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. * * ---------------------------------------------------------------------------- - * RCS: @(#) $Id: nmakehlp.c,v 1.17 2007/05/04 18:04:18 patthoyts Exp $ + * RCS: @(#) $Id: nmakehlp.c,v 1.18 2007/09/12 14:23:08 patthoyts Exp $ * ---------------------------------------------------------------------------- */ @@ -38,6 +38,7 @@ 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); @@ -133,6 +134,18 @@ main( return 2; } return GrepForDefine(argv[2], argv[3]); + case 's': + if (argc == 2) { + chars = snprintf(msg, sizeof(msg) - 1, + "usage: %s -s \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 = snprintf(msg, sizeof(msg) - 1, @@ -558,6 +571,141 @@ GetVersionFromFile( } return szResult; } + +/* + * 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); + } +} + +/* + * 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 +SubstituteFile( + const char *substitutions, + const char *filename) +{ + 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); + } + fclose(fp); + return 0; +} /* * Local variables: diff --git a/win/rules.vc b/win/rules.vc index 22208d2..e0c472e 100644 --- a/win/rules.vc +++ b/win/rules.vc @@ -11,7 +11,7 @@ # Copyright (c) 2003-2006 Patrick Thoyts # #------------------------------------------------------------------------------ -# RCS: @(#) $Id: rules.vc,v 1.29 2007/02/04 00:01:54 mistachkin Exp $ +# RCS: @(#) $Id: rules.vc,v 1.30 2007/09/12 14:23:08 patthoyts Exp $ #------------------------------------------------------------------------------ !ifndef _RULES_VC @@ -401,7 +401,7 @@ FULLWARNINGS = 0 # Set our defines now armed with our options. #---------------------------------------------------------- -OPTDEFINES = -DTCL_CFGVAL_ENCODING=$(CFG_ENCODING) +OPTDEFINES = -DTCL_CFGVAL_ENCODING=$(CFG_ENCODING) -DSTDC_HEADERS !if $(TCL_MEM_DEBUG) OPTDEFINES = $(OPTDEFINES) -DTCL_MEM_DEBUG @@ -536,9 +536,15 @@ TCLTOOLSDIR = $(_TCLDIR)\tools !if [echo REM = This file is generated from rules.vc > versions.vc] !endif # Note we can do the Tcl and/or Tk version extraction -#!if [echo TCL_DOTVERSION = \>> versions.vc] \ -# && [nmakehlp -V ..\generic\tcl.h TCL_VERSION >> versions.vc] -#!endif +!if [echo TCL_MAJOR_VERSION = \>> versions.vc] \ + && [nmakehlp -V ..\generic\tcl.h TCL_MAJOR_VERSION >> versions.vc] +!endif +!if [echo TCL_MINOR_VERSION = \>> versions.vc] \ + && [nmakehlp -V ..\generic\tcl.h TCL_MINOR_VERSION >> versions.vc] +!endif +!if [echo TCL_PATCH_LEVEL = \>> versions.vc] \ + && [nmakehlp -V ..\generic\tcl.h TCL_PATCH_LEVEL >> versions.vc] +!endif !if [echo PKG_HTTP_VER = \>> versions.vc] \ && [nmakehlp -V ..\library\http\pkgIndex.tcl http >> versions.vc] !endif -- cgit v0.12