Tcl Extension Architecture (TEA) Sample Extension

Check-in [1f353b37cb]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Update to latest rules from Tcl. In particular, use targets.vc
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | vc-reform
Files: files | file ages | folders
SHA1:1f353b37cbc05ad506c85cf04fd490cb03bb9c1e
User & Date: ashok 2017-10-07 14:47:14
Context
2017-10-08
15:28
Replace sample.rc with default resource template check-in: 46bab6aa51 user: ashok tags: vc-reform
2017-10-07
14:47
Update to latest rules from Tcl. In particular, use targets.vc check-in: 1f353b37cb user: ashok tags: vc-reform
14:46
Ignore emacs backup and tclconfig check-in: cd51f31301 user: ashok tags: vc-reform
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Added win/rules-ext.vc.

            1  +# This file should only be included in makefiles for Tcl extensions,
            2  +# NOT in the makefile for Tcl itself.
            3  +
            4  +!ifndef _RULES_EXT_VC
            5  +
            6  +!if !exist("rules-ext.vc")
            7  +MSG = ^
            8  +You must run this makefile only from the directory it is in.^
            9  +Please `cd` to its location first.
           10  +!error $(MSG)
           11  +!endif
           12  +
           13  +!if "$(PROJECT)" == "tcl"
           14  +!error The rules-ext.vc file is not intended for Tcl itself.
           15  +!endif
           16  +
           17  +# First locate the Tcl directory that we are working with.
           18  +!ifdef TCLDIR
           19  +
           20  +_RULESDIR = $(TCLDIR:/=\)
           21  +
           22  +!else
           23  +
           24  +# If an installation path is specified, that is also the Tcl directory.
           25  +# Also, tk never builds against an installed Tcl, it needs Tcl sources
           26  +!if defined(INSTALLDIR) && "$(PROJECT)" != "tk"
           27  +_RULESDIR=$(INSTALLDIR:/=\)
           28  +!else
           29  +_RULESDIR = ..\..\tcl
           30  +!endif
           31  +
           32  +!endif # ifndef TCLDIR
           33  +
           34  +# Now look for the rules.vc file under the Tcl root
           35  +!if exist("$(_RULESDIR)\lib\nmake\rules.vc") # Building against installed Tcl
           36  +_RULESDIR = $(_RULESDIR)\lib\nmake
           37  +!elseif exist("$(_RULESDIR)\win\rules.vc")   # Building against Tcl sources
           38  +_RULESDIR = $(_RULESDIR)\win
           39  +!else
           40  +# If we have not located Tcl's rules file, most likely we are compiling
           41  +# against an older version of Tcl and so must use our own support files.
           42  +_RULESDIR = .
           43  +!endif
           44  +
           45  +!if "$(_RULESDIR)" != "."
           46  +# Potentially using Tcl's support files. Need to compare the versions.
           47  +# We extract version numbers using the nmakehlp program. For this
           48  +# purpose, we use the version of nmakehlp that we have. 
           49  +!if [$(CC) -nologo nmakehlp.c -link -subsystem:console > nul]
           50  +!endif
           51  +
           52  +!if [echo TCL_RULES_MAJOR = \> versions.vc] \
           53  +   && [nmakehlp -V "$(_RULESDIR)\rules.vc" RULES_VERSION_MAJOR >> versions.vc]
           54  +!endif
           55  +!if [echo TCL_RULES_MINOR = \>> versions.vc] \
           56  +   && [nmakehlp -V "$(_RULESDIR)\rules.vc" RULES_VERSION_MINOR >> versions.vc]
           57  +!endif
           58  +
           59  +!if [echo OUR_RULES_MAJOR = \>> versions.vc] \
           60  +   && [nmakehlp -V "rules.vc" RULES_VERSION_MAJOR >> versions.vc]
           61  +!endif
           62  +!if [echo OUR_RULES_MINOR = \>> versions.vc] \
           63  +   && [nmakehlp -V "rules.vc" RULES_VERSION_MINOR >> versions.vc]
           64  +!endif
           65  +!include versions.vc
           66  +# We have a newer version of the support files, use them
           67  +!if ($(TCL_RULES_MAJOR) != $(OUR_RULES_MAJOR)) || ($(TCL_RULES_MINOR) < $(OUR_RULES_MINOR))
           68  +_RULESDIR = .
           69  +!endif
           70  +
           71  +!endif # $(_RULESDIR) != "."
           72  +
           73  +# Let rules.vc know what copy of nmakehlp.c to use.
           74  +NMAKEHLPC = $(_RULESDIR)\nmakehlp.c
           75  +
           76  +# Get rid of our internal defines before calling rules.vc
           77  +!undef TCL_RULES_MAJOR
           78  +!undef TCL_RULES_MINOR
           79  +!undef OUR_RULES_MAJOR
           80  +!undef OUR_RULES_MINOR
           81  +
           82  +!message *** Using $(_RULESDIR)\rules.vc
           83  +!include "$(_RULESDIR)\rules.vc"
           84  +
           85  +!endif # _RULES_EXT_VC

Changes to win/rules.vc.

    33     33   !endif
    34     34   
    35     35   ################################################################
    36     36   # Nmake is a pretty weak environment in syntax and capabilities
    37     37   # so this file is necessarily verbose. It's broken down into
    38     38   # the following parts.
    39     39   #
    40         -# 0. Sanity check that compiler environment is set up.
           40  +# 0. Sanity check that compiler environment is set up and initialize
           41  +#    any built-in settings from the parent makefile
    41     42   # 1. First define the external tools used for compiling, copying etc.
    42     43   #    as this is independent of everything else.
    43     44   # 2. Figure out our build structure in terms of the directory, whether
    44     45   #    we are building Tcl or an extension, etc.
    45     46   # 3. Determine the compiler and linker versions
    46     47   # 4. Build the nmakehlp helper application
    47     48   # 5. Determine the supported compiler options and features
................................................................................
    69     70   # VCINSTALLDIR) or with the MS Platform SDK (MSSDK or WindowsSDKDir)
    70     71   
    71     72   !if !defined(MSDEVDIR) && !defined(MSVCDIR) && !defined(VCINSTALLDIR) && !defined(MSSDK) && !defined(WINDOWSSDKDIR)
    72     73   MSG = ^
    73     74   Visual C++ compiler environment not initialized.
    74     75   !error $(MSG)
    75     76   !endif
           77  +
           78  +# Defaults for built-in internal settings defined in parent makefile
           79  +!ifndef DISABLE_STANDARD_TARGETS
           80  +DISABLE_STANDARD_TARGETS = 0
           81  +!endif
           82  +!ifndef DISABLE_CLEAN_TARGETS
           83  +DISABLE_CLEAN_TARGETS = 0
           84  +!endif
    76     85   
    77     86   ################################################################
    78     87   # 1. Define external programs being used
    79     88   
    80     89   #----------------------------------------------------------
    81     90   # Set the proper copy method to avoid overwrite questions
    82     91   # to the user when copying files and selecting the right
................................................................................
   404    413   # copy of Tcl's nmakehlp.c if there is one and their own version
   405    414   # otherwise. In the latter case, they would also be using their own
   406    415   # rules.vc. Note that older versions of Tcl do not install nmakehlp.c
   407    416   # or rules.vc.
   408    417   #
   409    418   # Extensions built against Tcl sources will use the one from the Tcl source.
   410    419   #
   411         -# This can all be overridden by defining the NMAKEHLPC macro to point
   412         -# to the nmakehlp.c file to be used, either from the command line or
   413         -# the containing makefile.
          420  +# When building an extension using a sufficiently new version of Tcl,
          421  +# rules-ext.vc will define NMAKEHLPC appropriately to point to the
          422  +# copy of nmakehlp.c to be used.
   414    423   
   415    424   !ifndef NMAKEHLPC
   416    425   # Default to the one in the current directory (the extension's own nmakehlp.c)
   417    426   NMAKEHLPC = nmakehlp.c
   418    427   
   419    428   !if !$(DOING_TCL)
   420    429   !if $(TCLINSTALL)
................................................................................
   849    858   
   850    859   !else # Doing a non-Tk extension
   851    860   
   852    861   # If parent makefile has not defined DOTVERSION, try to get it from TEA
   853    862   # first from a configure.in file, and then from configure.ac
   854    863   !ifndef DOTVERSION
   855    864   !if [echo DOTVERSION = \> versions.vc] \
   856         -   && [nmakehlp -V ..\configure.in AC_INIT >> versions.vc]
   857         -!elseif [echo DOTVERSION = \> versions.vc] \
   858         -   && [nmakehlp -V ..\configure.ac AC_INIT >> versions.vc]
   859         -!else
          865  +   || [nmakehlp -V ..\configure.in AC_INIT >> versions.vc]
          866  +!if [echo DOTVERSION = \> versions.vc] \
          867  +   || [nmakehlp -V ..\configure.ac AC_INIT >> versions.vc]
   860    868   !error *** Could not figure out extension version. Please define DOTVERSION in parent makefile before including rules.vc.
   861    869   !endif
   862         -!include "versions.vc"
          870  +!endif
          871  +!include versions.vc
   863    872   !endif # DOTVERSION
   864    873   
   865    874   !endif # $(DOING_TCL) ... etc.
   866    875   
   867    876   ################################################################
   868    877   # 10. Construct output directory and file paths
   869    878   # Figure-out how to name our intermediate and output directories.
................................................................................
   878    887   #
   879    888   # The following macros are set in this section:
   880    889   # SUFX - the suffix to use for binaries based on above naming convention
   881    890   # BUILDDIRTOP - the toplevel default output directory
   882    891   #      is of the form {Release,Debug}[_AMD64][_COMPILERVERSION]
   883    892   # TMP_DIR - directory where object files are created
   884    893   # OUT_DIR - directory where output executables are created
   885         -# STUBPREFIX - name of the stubs library for this project
   886    894   # Both TMP_DIR and OUT_DIR are defaulted only if not defined by the
   887    895   # parent makefile (or command line). The default values are
   888    896   # based on BUILDDIRTOP.
          897  +# STUBPREFIX - name of the stubs library for this project
          898  +# PRJIMPLIB - output path of the generated project import library
          899  +# PRJLIBNAME - name of generated project library
          900  +# PRJLIB     - output path of generated project library
          901  +# PRJSTUBLIBNAME - name of the generated project stubs library
          902  +# PRJSTUBLIB - output path of the generated project stubs library
   889    903   
   890    904   SUFX	    = tsgx
   891    905   
   892    906   !if $(DEBUG)
   893    907   BUILDDIRTOP = Debug
   894    908   !else
   895    909   BUILDDIRTOP = Release
................................................................................
  1029   1043   TKIMPLIB	= $(_TKDIR)\win\$(BUILDDIRTOP)\$(TKIMPLIBNAME)
  1030   1044   TK_INCLUDES     = -I"$(_TKDIR)\generic" -I"$(_TKDIR)\win" -I"$(_TKDIR)\xlib"
  1031   1045   !endif # TKINSTALL
  1032   1046   
  1033   1047   !endif # $(DOING_TK)
  1034   1048   !endif # $(DOING_TK) || PROJECT_REQUIRES_TK
  1035   1049   
         1050  +# Various output paths
         1051  +PRJIMPLIB	= $(OUT_DIR)\$(PROJECT)$(VERSION)$(SUFX).lib
         1052  +PRJLIBNAME	= $(PROJECT)$(VERSION)$(SUFX).$(EXT)
         1053  +PRJLIB		= $(OUT_DIR)\$(PRJLIBNAME)
         1054  +
         1055  +PRJSTUBLIBNAME	= $(STUBPREFIX)$(VERSION).lib
         1056  +PRJSTUBLIB	= $(OUT_DIR)\$(PRJSTUBLIBNAME)
         1057  +
  1036   1058   ###################################################################
  1037   1059   # 11. Construct the paths for the installation directories
  1038   1060   # The following macros get defined in this section:
  1039   1061   # LIB_INSTALL_DIR - where libraries should be installed
  1040   1062   # BIN_INSTALL_DIR - where the executables should be installed
  1041   1063   # DOC_INSTALL_DIR - where documentation should be installed
  1042   1064   # SCRIPT_INSTALL_DIR - where scripts should be installed
................................................................................
  1136   1158   !if $(VCVERSION) < 1300
  1137   1159   OPTDEFINES	= $(OPTDEFINES) -DNO_STRTOI64
  1138   1160   !endif
  1139   1161   
  1140   1162   # _ATL_XP_TARGETING - Newer SDK's need this to build for XP
  1141   1163   COMPILERFLAGS  = /D_ATL_XP_TARGETING
  1142   1164   
  1143         -
  1144   1165   # Following is primarily for the benefit of extensions. Tcl 8.5 builds
  1145   1166   # Tcl without /DUNICODE, while 8.6 builds with it defined. When building
  1146   1167   # an extension, it is advisable (but not mandated) to use the same Windows
  1147   1168   # API as the Tcl build. This is accordingly defaulted below. A particular
  1148   1169   # extension can override this by pre-definining USE_WIDECHAR_API.
  1149   1170   !ifndef USE_WIDECHAR_API
  1150   1171   !if $(TCL_VERSION) > 85
................................................................................
  1153   1174   USE_WIDECHAR_API = 0
  1154   1175   !endif
  1155   1176   !endif
  1156   1177   
  1157   1178   !if $(USE_WIDECHAR_API)
  1158   1179   COMPILERFLAGS = $(COMPILERFLAGS) /DUNICODE /D_UNICODE 
  1159   1180   !endif
         1181  +
         1182  +# Like the TEA system only set this non empty for non-Tk extensions
         1183  +!if !$(DOING_TCL) && !$(DOING_TK)
         1184  +PKGNAMEFLAGS = -DPACKAGE_NAME="\"$(PROJECT)\"" \
         1185  +               -DPACKAGE_VERSION="\"$(DOTVERSION)\"" \
         1186  +               -DMODULE_SCOPE=extern 
         1187  +!endif
  1160   1188   
  1161   1189   # crt picks the C run time based on selected OPTS
  1162   1190   !if $(MSVCRT)
  1163   1191   !if $(DEBUG) && !$(UNCHECKED)
  1164   1192   crt = -MDd
  1165   1193   !else
  1166   1194   crt = -MD
................................................................................
  1216   1244   # object files (e.g. tclsh, or wish) pkgcflags contains $(cflags) plus
  1217   1245   # flags used for building shared object files The two differ in the
  1218   1246   # BUILD_$(PROJECT) macro which should be defined only for the shared
  1219   1247   # library *implementation* and not for its caller interface
  1220   1248   
  1221   1249   appcflags = $(cflags) $(crt) $(TCL_INCLUDES) $(TK_INCLUDES) $(PRJ_INCLUDES) $(TCL_DEFINES) $(PRJ_DEFINES) $(OPTDEFINES) $(USE_STUBS_DEFS)
  1222   1250   appcflags_nostubs = $(cflags) $(crt) $(TCL_INCLUDES) $(TK_INCLUDES) $(PRJ_INCLUDES) $(TCL_DEFINES) $(PRJ_DEFINES) $(OPTDEFINES)
  1223         -pkgcflags = $(appcflags) -DBUILD_$(PROJECT)
  1224         -pkgcflags_nostubs = $(appcflags_nostubs) -DBUILD_$(PROJECT)
         1251  +pkgcflags = $(appcflags) $(PKGNAMEFLAGS) -DBUILD_$(PROJECT)
         1252  +pkgcflags_nostubs = $(appcflags_nostubs) $(PKGNAMEFLAGS) -DBUILD_$(PROJECT)
  1225   1253   
  1226   1254   # stubscflags contains $(cflags) plus flags used for building a stubs
  1227   1255   # library for the package.  Note: -DSTATIC_BUILD is defined in
  1228   1256   # $(OPTDEFINES) only if the OPTS configuration indicates a static
  1229   1257   # library. However the stubs library is ALWAYS static hence included
  1230   1258   # here irrespective of the OPTS setting.
  1231   1259   
................................................................................
  1303   1331   !else
  1304   1332   MAKEBINCMD = $(MAKEDLLCMD)
  1305   1333   !endif
  1306   1334   MAKECONCMD = $(link32) $(conlflags) -out:$@ $(baselibs) $(tcllibs)
  1307   1335   MAKEGUICMD = $(link32) $(guilflags) -out:$@ $(baselibs) $(tcllibs)
  1308   1336   MAKERESCMD  = $(rc32) -fo $@ -r -i "$(GENERICDIR)" -i "$(TMP_DIR)" \
  1309   1337   	    $(TCL_INCLUDES) \
  1310         -	    -d DEBUG=$(DEBUG) -d UNCHECKED=$(UNCHECKED) \
  1311         -	    -d TCL_THREADS=$(TCL_THREADS) \
  1312         -	    -d STATIC_BUILD=$(STATIC_BUILD) \
         1338  +	    -DDEBUG=$(DEBUG) -d UNCHECKED=$(UNCHECKED) \
         1339  +	    -DTCL_THREADS=$(TCL_THREADS) \
         1340  +	    -DSTATIC_BUILD=$(STATIC_BUILD) \
         1341  +	    -DCOMMAVERSION=$(DOTVERSION:.=,),0 \
         1342  +	    -DDOTVERSION=\"$(DOTVERSION)\" \
         1343  +	    -DVERSION=\"$(VERSION)\" \
         1344  +	    -DSUFX=\"$(SUFX)\" \
  1313   1345   	    $<
  1314   1346   
  1315         -!ifndef DISABLE_DEFAULT_TARGETS
  1316   1347   
  1317   1348   !ifndef DEFAULT_BUILD_TARGET
  1318         -DEFAULT_BUILD_TARGET = all
         1349  +DEFAULT_BUILD_TARGET = $(PROJECT)
  1319   1350   !endif
  1320   1351   
  1321         -default_target: $(DEFAULT_BUILD_TARGET)
         1352  +default-target: $(DEFAULT_BUILD_TARGET)
  1322   1353   
  1323         -setup:
  1324         -	@if not exist $(OUT_DIR)\nul mkdir $(OUT_DIR)
  1325         -	@if not exist $(TMP_DIR)\nul mkdir $(TMP_DIR)
         1354  +default-pkgindex:
         1355  +	@echo package ifneeded $(PROJECT) $(DOTVERSION) \
         1356  +	    [list load [file join $$dir $(PRJLIBNAME)]] >> $(OUT_DIR)\pkgIndex.tcl
  1326   1357   
  1327         -clean:
         1358  +default-pkgindex-tea:
         1359  +	@if exist $(ROOT)\pkgIndex.tcl.in nmakehlp -s << $(ROOT)\pkgIndex.tcl.in > $(OUT_DIR)\pkgIndex.tcl
         1360  +@PACKAGE_VERSION@    $(DOTVERSION)
         1361  +@PACKAGE_NAME@       $(PROJECT)
         1362  +@PKG_LIB_FILE@       $(PRJLIBNAME)
         1363  +<<
         1364  +
         1365  +
         1366  +default-install: default-install-binaries default-install-libraries
         1367  +
         1368  +default-install-binaries: $(PRJLIB)
         1369  +	@echo Installing binaries to '$(SCRIPT_INSTALL_DIR)'
         1370  +	@if not exist "$(SCRIPT_INSTALL_DIR)" mkdir "$(SCRIPT_INSTALL_DIR)"
         1371  +	@$(CPY) $(PRJLIB) "$(SCRIPT_INSTALL_DIR)" >NUL
         1372  +
         1373  +default-install-libraries: $(OUT_DIR)\pkgIndex.tcl
         1374  +	@echo Installing libraries to '$(SCRIPT_INSTALL_DIR)'
         1375  +	@if exist $(LIBDIR) $(CPY) $(LIBDIR)\*.tcl "$(SCRIPT_INSTALL_DIR)"
         1376  +	@echo Installing package index in '$(SCRIPT_INSTALL_DIR)'
         1377  +	@$(CPY) $(OUT_DIR)\pkgIndex.tcl $(SCRIPT_INSTALL_DIR)
         1378  +
         1379  +default-clean:
  1328   1380   	@echo Cleaning $(TMP_DIR)\* ...
  1329   1381   	@if exist $(TMP_DIR)\nul $(RMDIR) $(TMP_DIR)
  1330   1382   	@echo Cleaning $(WINDIR)\nmakehlp.obj, nmakehlp.exe ...
  1331   1383   	@if exist $(WINDIR)\nmakehlp.obj del $(WINDIR)\nmakehlp.obj
  1332   1384   	@if exist $(WINDIR)\nmakehlp.exe del $(WINDIR)\nmakehlp.exe
  1333   1385   	@echo Cleaning $(WINDIR)\_junk.pch ...
  1334   1386   	@if exist $(WINDIR)\_junk.pch del $(WINDIR)\_junk.pch
................................................................................
  1335   1387   	@echo Cleaning $(WINDIR)\vercl.x, vercl.i ...
  1336   1388   	@if exist $(WINDIR)\vercl.x del $(WINDIR)\vercl.x
  1337   1389   	@if exist $(WINDIR)\vercl.i del $(WINDIR)\vercl.i
  1338   1390   	@echo Cleaning $(WINDIR)\versions.vc, version.vc ...
  1339   1391   	@if exist $(WINDIR)\versions.vc del $(WINDIR)\versions.vc
  1340   1392   	@if exist $(WINDIR)\version.vc del $(WINDIR)\version.vc
  1341   1393   
  1342         -realclean: hose
  1343         -
  1344         -hose:
         1394  +default-hose:
  1345   1395   	@echo Hosing $(OUT_DIR)\* ...
  1346   1396   	@if exist $(OUT_DIR)\nul $(RMDIR) $(OUT_DIR)
  1347   1397   
  1348         -!endif
         1398  +default-distclean: default-hose
         1399  +	@if exist $(WINDIR)\nmakehlp.exe del $(WINDIR)\nmakehlp.exe
         1400  +	@if exist $(WINDIR)\nmakehlp.obj del $(WINDIR)\nmakehlp.obj
         1401  +
         1402  +default-setup:
         1403  +	@if not exist $(OUT_DIR)\nul mkdir $(OUT_DIR)
         1404  +	@if not exist $(TMP_DIR)\nul mkdir $(TMP_DIR)
  1349   1405   
  1350   1406   !ifndef DISABLE_IMPLICIT_RULES
  1351   1407   # Implicit rule definitions - only for building library objects. For stubs and
  1352   1408   # main application, the master makefile should define explicit rules.
  1353   1409   
  1354   1410   {$(WINDIR)}.c{$(TMP_DIR)}.obj::
  1355   1411   	$(cc32) $(pkgcflags) -Fo$(TMP_DIR)\ @<<

Added win/targets.vc.

            1  +#------------------------------------------------------------- -*- makefile -*-
            2  +
            3  +$(PROJECT): setup pkgindex $(PRJLIB)
            4  +
            5  +!if "$(PROJECT)" != "tcl" && "$(PROJECT)" != "tk"
            6  +# MAKEBINCMD will do shared, static and debug links as appropriate
            7  +# _VC_MANIFEST_EMBED_DLL embeds the manifest for shared libraries
            8  +# and is a no-op for static libraries
            9  +$(PRJLIB): $(PRJ_OBJS)
           10  +       $(MAKEBINCMD) $**
           11  +       $(_VC_MANIFEST_EMBED_DLL)
           12  +       -@del $*.exp
           13  +!endif
           14  +
           15  +setup: default-setup
           16  +install: default-install
           17  +clean: default-clean
           18  +realclean: hose
           19  +hose: default-hose
           20  +distclean: realclean default-distclean
           21  +