1# makefile.vc -- -*- Makefile -*- 2# 3# Microsoft Visual C++ makefile for use with nmake.exe v1.62+ (VC++ 5.0+) 4# 5# This makefile is based upon the Tcl 8.4 Makefile.vc and modified to 6# make it suitable as a general package makefile. Look for the word EDIT 7# which marks sections that may need modification. As a minumum you will 8# need to change the PROJECT, DOTVERSION and DLLOBJS variables to values 9# relevant to your package. 10# 11# See the file "license.terms" for information on usage and redistribution 12# of this file, and for a DISCLAIMER OF ALL WARRANTIES. 13# 14# Copyright (c) 1995-1996 Sun Microsystems, Inc. 15# Copyright (c) 1998-2000 Ajuba Solutions. 16# Copyright (c) 2001 ActiveState Corporation. 17# Copyright (c) 2001-2002 David Gravereaux. 18# Copyright (c) 2003-2006 Pat Thoyts 19# 20#------------------------------------------------------------------------- 21# RCS: @(#)$Id: makefile.vc,v 1.19 2007/10/03 11:16:08 rolf Exp $ 22#------------------------------------------------------------------------- 23 24# Check to see we are configured to build with MSVC (MSDEVDIR or MSVCDIR) 25# or with the MS Platform SDK (MSSDK). Visual Studio .NET 2003 and 2005 define 26# VCINSTALLDIR instead. The MSVC Toolkit release defines yet another. 27!if !defined(MSDEVDIR) && !defined(MSVCDIR) && !defined(MSSDK) && !defined(VCINSTALLDIR) && !defined(VCToolkitInstallDir) 28MSG = ^ 29You need to run vcvars32.bat from Developer Studio or setenv.bat from the^ 30Platform SDK first to setup the environment. Jump to this line to read^ 31the build instructions. 32!error $(MSG) 33!endif 34 35#------------------------------------------------------------------------------ 36# HOW TO USE this makefile: 37# 38# 1) It is now necessary to have %MSVCDir% set in the environment. This is 39# used as a check to see if vcvars32.bat had been run prior to running 40# nmake or during the installation of Microsoft Visual C++, MSVCDir had 41# been set globally and the PATH adjusted. Either way is valid. 42# 43# You'll need to run vcvars32.bat contained in the MsDev's vc(98)/bin 44# directory to setup the proper environment, if needed, for your current 45# setup. This is a needed bootstrap requirement and allows the swapping of 46# different environments to be easier. 47# 48# 2) To use the Platform SDK (not expressly needed), run setenv.bat after 49# vcvars32.bat according to the instructions for it. This can also turn on 50# the 64-bit compiler, if your SDK has it. 51# 52# 3) Targets are: 53# all -- Builds everything. 54# <project> -- Builds the project (eg: nmake sample) 55# test -- Builds and runs the test suite. 56# install -- Installs the built binaries and libraries to $(INSTALLDIR) 57# in an appropriate subdirectory. 58# clean/realclean/distclean -- varying levels of cleaning. 59# 60# 4) Macros usable on the commandline: 61# INSTALLDIR=<path> 62# Sets where to install Tcl from the built binaries. 63# C:\Progra~1\Tcl is assumed when not specified. 64# 65# OPTS=static,msvcrt,staticpkg,threads,symbols,profile,loimpact,none 66# Sets special options for the core. The default is for none. 67# Any combination of the above may be used (comma separated). 68# 'none' will over-ride everything to nothing. 69# 70# static = Builds a static library of the core instead of a 71# dll. The shell will be static (and large), as well. 72# msvcrt = Effects the static option only to switch it from 73# using libcmt(d) as the C runtime [by default] to 74# msvcrt(d). This is useful for static embedding 75# support. 76# staticpkg = Effects the static option only to switch 77# tclshXX.exe to have the dde and reg extension linked 78# inside it. 79# nothreads = Turns off multithreading support (not recommended) 80# thrdalloc = Use the thread allocator (shared global free pool). 81# symbols = Adds symbols for step debugging. 82# profile = Adds profiling hooks. Map file is assumed. 83# loimpact = Adds a flag for how NT treats the heap to keep memory 84# in use, low. This is said to impact alloc performance. 85# 86# STATS=memdbg,compdbg,none 87# Sets optional memory and bytecode compiler debugging code added 88# to the core. The default is for none. Any combination of the 89# above may be used (comma separated). 'none' will over-ride 90# everything to nothing. 91# 92# memdbg = Enables the debugging memory allocator. 93# compdbg = Enables byte compilation logging. 94# 95# MACHINE=(IX86|IA64|ALPHA|AMD64) 96# Set the machine type used for the compiler, linker, and 97# resource compiler. This hook is needed to tell the tools 98# when alternate platforms are requested. IX86 is the default 99# when not specified. If the CPU environment variable has been 100# set (ie: recent Platform SDK) then MACHINE is set from CPU. 101# 102# TMP_DIR=<path> 103# OUT_DIR=<path> 104# Hooks to allow the intermediate and output directories to be 105# changed. $(OUT_DIR) is assumed to be 106# $(BINROOT)\(Release|Debug) based on if symbols are requested. 107# $(TMP_DIR) will de $(OUT_DIR)\<buildtype> by default. 108# 109# TESTPAT=<file> 110# Reads the tests requested to be run from this file. 111# 112# CFG_ENCODING=encoding 113# name of encoding for configuration information. Defaults 114# to cp1252 115# 116# 5) Examples: 117# 118# Basic syntax of calling nmake looks like this: 119# nmake [-nologo] -f makefile.vc [target|macrodef [target|macrodef] [...]] 120# 121# Standard (no frills) 122# c:\tcl_src\win\>c:\progra~1\micros~1\vc98\bin\vcvars32.bat 123# Setting environment for using Microsoft Visual C++ tools. 124# c:\tcl_src\win\>nmake -f makefile.vc all 125# c:\tcl_src\win\>nmake -f makefile.vc install INSTALLDIR=c:\progra~1\tcl 126# 127# Building for Win64 128# c:\tcl_src\win\>c:\progra~1\micros~1\vc98\bin\vcvars32.bat 129# Setting environment for using Microsoft Visual C++ tools. 130# c:\tcl_src\win\>c:\progra~1\platfo~1\setenv.bat /pre64 /RETAIL 131# Targeting Windows pre64 RETAIL 132# c:\tcl_src\win\>nmake -f makefile.vc MACHINE=IA64 133# 134#------------------------------------------------------------------------------ 135#============================================================================== 136############################################################################### 137#------------------------------------------------------------------------------ 138 139!if !exist("makefile.vc") 140MSG = ^ 141You must run this makefile only from the directory it is in.^ 142Please `cd` to its location first. 143!error $(MSG) 144!endif 145 146#------------------------------------------------------------------------- 147# Project specific information (EDIT) 148# 149# You should edit this with the name and version of your project. This 150# information is used to generate the name of the package library and 151# it's install location. 152# 153# For example, the sample extension is going to build sample04.dll and 154# would install it into $(INSTALLDIR)\lib\sample04 155# 156# You need to specify the object files that need to be linked into your 157# binary here. 158# 159#------------------------------------------------------------------------- 160 161PROJECT = tdom 162!include "rules.vc" 163 164DOTVERSION = 0.8.3 165VERSION = $(DOTVERSION:.=) 166STUBPREFIX = $(PROJECT)stub 167 168DLLOBJS = \ 169 $(TMP_DIR)\xmlrole.obj \ 170 $(TMP_DIR)\xmltok.obj \ 171 $(TMP_DIR)\xmlparse.obj \ 172 $(TMP_DIR)\xmlsimple.obj \ 173 $(TMP_DIR)\utf8conv.obj \ 174 $(TMP_DIR)\dom.obj \ 175 $(TMP_DIR)\domalloc.obj \ 176 $(TMP_DIR)\domhtml.obj \ 177 $(TMP_DIR)\domxslt.obj \ 178 $(TMP_DIR)\nodecmd.obj \ 179 $(TMP_DIR)\domxpath.obj \ 180 $(TMP_DIR)\domlock.obj \ 181 $(TMP_DIR)\tclexpat.obj \ 182 $(TMP_DIR)\tcldom.obj \ 183 $(TMP_DIR)\tdomStubInit.obj\ 184 $(TMP_DIR)\tdomStubLib.obj \ 185 $(TMP_DIR)\tdominit.obj \ 186!if !$(STATIC_BUILD) 187 $(TMP_DIR)\tdom.res 188!endif 189 190PRJSTUBOBJS = \ 191 $(TMP_DIR)\tdomStubLib.obj 192 193#------------------------------------------------------------------------- 194# Target names and paths ( shouldn't need changing ) 195#------------------------------------------------------------------------- 196 197BINROOT = . 198ROOT = .. 199 200PRJIMPLIB = $(OUT_DIR)\$(PROJECT)$(VERSION)$(SUFX).lib 201PRJLIBNAME = $(PROJECT)$(VERSION)$(SUFX).$(EXT) 202PRJLIB = $(OUT_DIR)\$(PRJLIBNAME) 203 204PRJSTUBLIBNAME = $(STUBPREFIX)$(VERSION).lib 205PRJSTUBLIB = $(OUT_DIR)\$(PRJSTUBLIBNAME) 206 207### Make sure we use backslash only. 208PRJ_INSTALL_DIR = $(_INSTALLDIR)\$(PROJECT)$(DOTVERSION) 209LIB_INSTALL_DIR = $(PRJ_INSTALL_DIR) 210BIN_INSTALL_DIR = $(PRJ_INSTALL_DIR) 211DOC_INSTALL_DIR = $(PRJ_INSTALL_DIR) 212SCRIPT_INSTALL_DIR = $(PRJ_INSTALL_DIR) 213INCLUDE_INSTALL_DIR = $(_TCLDIR)\include 214 215### The following paths CANNOT have spaces in them. 216GENERICDIR = $(ROOT)\generic 217WINDIR = $(ROOT)\win 218LIBDIR = $(ROOT)\lib 219DOCDIR = $(ROOT)\doc 220TOOLSDIR = $(ROOT)\tools 221COMPATDIR = $(ROOT)\compat 222EXPATDIR = $(ROOT)\expat 223 224#--------------------------------------------------------------------- 225# Compile flags 226#--------------------------------------------------------------------- 227 228!if !$(DEBUG) 229!if $(OPTIMIZING) 230### This cranks the optimization level to maximize speed 231cdebug = $(OPTIMIZATIONS) 232!else 233cdebug = 234!endif 235!else if "$(MACHINE)" == "IA64" || "$(MACHINE)" == "AMD64" 236### Warnings are too many, can't support warnings into errors. 237cdebug = -Zi -Od $(DEBUGFLAGS) 238!else 239cdebug = -Zi -WX $(DEBUGFLAGS) 240!endif 241 242### Declarations common to all compiler options 243cwarn = -D _CRT_SECURE_NO_DEPRECATE -D _CRT_NONSTDC_NO_DEPRECATE 244cflags = -nologo -c $(COMPILERFLAGS) $(cwarn) -Fp$(TMP_DIR)^\ 245 246# Warning level 247!if $(FULLWARNINGS) 248cflags = $(cflags) -W4 249!else 250cflags = $(cflags) -W3 251!endif 252 253!if $(MSVCRT) 254!if $(DEBUG) && !$(UNCHECKED) 255crt = -MDd 256!else 257crt = -MD 258!endif 259!else 260!if $(DEBUG) && !$(UNCHECKED) 261crt = -MTd 262!else 263crt = -MT 264!endif 265!endif 266 267!if !$(STATIC_BUILD) 268cflags = $(cflags) -DUSE_TCL_STUBS 269!if defined(TKSTUBLIB) 270cflags = $(cflags) -DUSE_TK_STUBS 271!endif 272!endif 273 274DEFS =-DHAVE_MEMMOVE -DXML_DTD -DXML_NS -DTDOM_NO_UNKNOWN_CMD 275DEFS_EXPAT =-DXMLIMPORT=__declspec(dllexport) 276INCLUDES = -I"$(WINDIR)" -I"$(GENERICDIR)" -I"$(EXPATDIR)" $(TCL_INCLUDES) 277BASE_CFLAGS = $(cflags) $(cdebug) $(crt) $(INCLUDES) 278CON_CFLAGS = $(cflags) $(cdebug) $(crt) -DCONSOLE 279TCL_CFLAGS = -DPACKAGE_NAME="\"$(PROJECT)\"" \ 280 -DPACKAGE_VERSION="\"$(DOTVERSION)\"" \ 281 $(BASE_CFLAGS) $(OPTDEFINES) $(DEFS) $(DEFS_EXPAT) 282 283#--------------------------------------------------------------------- 284# Link flags 285#--------------------------------------------------------------------- 286 287!if $(DEBUG) 288ldebug = -debug:full -debugtype:cv 289!if $(MSVCRT) 290ldebug = $(ldebug) -nodefaultlib:msvcrt 291!endif 292!else 293ldebug = -release -opt:ref -opt:icf,3 294!endif 295 296### Declarations common to all linker options 297lflags = -nologo -machine:$(MACHINE) $(LINKERFLAGS) $(ldebug) 298 299!if $(FULLWARNINGS) 300lflags = $(lflags) -warn:3 301!endif 302 303!if $(PROFILE) 304lflags = $(lflags) -profile 305!endif 306 307!if $(ALIGN98_HACK) && !$(STATIC_BUILD) 308### Align sections for PE size savings. 309lflags = $(lflags) -opt:nowin98 310!else if !$(ALIGN98_HACK) && $(STATIC_BUILD) 311### Align sections for speed in loading by choosing the virtual page size. 312lflags = $(lflags) -align:4096 313!endif 314 315!if $(LOIMPACT) 316lflags = $(lflags) -ws:aggressive 317!endif 318 319dlllflags = $(lflags) -dll 320conlflags = $(lflags) -subsystem:console 321guilflags = $(lflags) -subsystem:windows 322!if !$(STATIC_BUILD) 323baselibs = $(TCLSTUBLIB) 324!if defined(TKSTUBLIB) 325baselibs = $(baselibs) $(TKSTUBLIB) 326!endif 327!endif 328 329# Avoid 'unresolved external symbol __security_cookie' errors. 330# c.f. http://support.microsoft.com/?id=894573 331!if "$(MACHINE)" == "IA64" || "$(MACHINE)" == "AMD64" 332baselibs = $(baselibs) bufferoverflowU.lib 333!endif 334 335#--------------------------------------------------------------------- 336# TclTest flags 337#--------------------------------------------------------------------- 338 339!IF "$(TESTPAT)" != "" 340TESTFLAGS = $(TESTFLAGS) -file $(TESTPAT) 341!ENDIF 342 343#--------------------------------------------------------------------- 344# Project specific targets (EDIT) 345#--------------------------------------------------------------------- 346 347all: setup $(PROJECT) 348$(PROJECT): setup $(PRJLIB) $(PRJSTUBLIB) 349install: install-binaries install-libraries install-docs 350 351# Tests need to ensure we load the right dll file we 352# have to handle the output differently on Win9x. 353# 354!if "$(OS)" == "Windows_NT" || "$(MSVCDIR)" == "IDE" 355test: setup $(PROJECT) 356 set TCL_LIBRARY=$(ROOT)/library 357 $(TCLSH) << 358load $(PRJLIB:\=/) 359source [file join $(LIBDIR:\=/) tdom.tcl] 360cd "$(ROOT)/tests" 361set argv "$(TESTFLAGS)" 362source all.tcl 363<< 364!else 365test: setup $(PROJECT) 366 echo Please wait while the test results are collected 367 set TCL_LIBRARY=$(ROOT)/library 368 $(TCLSH) << >tests.log 369load $(PRJLIB:\=/) 370source [file join $(LIBDIR:\=/) tdom.tcl] 371cd "$(ROOT)/tests" 372set argv "$(TESTFLAGS)" 373source all.tcl 374<< 375 type tests.log | more 376!endif 377 378setup: 379 @if not exist $(OUT_DIR)\nul mkdir $(OUT_DIR) 380 @if not exist $(TMP_DIR)\nul mkdir $(TMP_DIR) 381 382# See <tcl>/win/coffbase.txt for extension base addresses. 383$(PRJLIB): $(DLLOBJS) 384!if $(STATIC_BUILD) 385 $(lib32) -nologo -out:$@ @<< 386$** 387<< 388!else 389 $(link32) $(dlllflags) -base:0x109E0000 -out:$@ $(baselibs) @<< 390$** 391<< 392 $(_VC_MANIFEST_EMBED_DLL) 393 -@del $*.exp 394!endif 395 396$(PRJSTUBLIB): $(PRJSTUBOBJS) 397 $(lib32) -nologo -out:$@ $(PRJSTUBOBJS) 398 399#--------------------------------------------------------------------- 400# Implicit rules 401#--------------------------------------------------------------------- 402 403{$(WINDIR)}.c{$(TMP_DIR)}.obj:: 404 $(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ @<< 405$< 406<< 407 408{$(GENERICDIR)}.c{$(TMP_DIR)}.obj:: 409 $(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ @<< 410$< 411<< 412 413{$(COMPATDIR)}.c{$(TMP_DIR)}.obj:: 414 $(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ @<< 415$< 416<< 417 418{$(EXPATDIR)}.c{$(TMP_DIR)}.obj:: 419 $(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ @<< 420$< 421<< 422 423{$(WINDIR)}.rc{$(TMP_DIR)}.res: 424 $(rc32) -fo $@ -r -i "$(GENERICDIR)" -D__WIN32__ \ 425 -DCOMMAVERSION=$(DOTVERSION:.=,),0 \ 426 -DDOTVERSION=\"$(DOTVERSION)\" \ 427 -DVERSION=\"$(VERSION)$(SUFX)\" \ 428!if $(DEBUG) 429 -d DEBUG \ 430!endif 431!if $(TCL_THREADS) 432 -d TCL_THREADS \ 433!endif 434!if $(STATIC_BUILD) 435 -d STATIC_BUILD \ 436!endif 437 $< 438 439.SUFFIXES: 440.SUFFIXES:.c .rc 441 442#------------------------------------------------------------------------- 443# Explicit dependency rules 444# 445#------------------------------------------------------------------------- 446 447$(OUT_DIR)\pkgIndex.tcl: $(ROOT)\pkgIndex.tcl.in 448 nmakehlp -s << $** > $@ 449@PACKAGE_VERSION@ $(DOTVERSION) 450@PACKAGE_NAME@ $(PROJECT) 451@PKG_LIB_FILE@ $(PRJLIBNAME) 452<< 453 454#--------------------------------------------------------------------- 455# Installation. (EDIT) 456# 457# You may need to modify this section to reflect the final distribution 458# of your files and possibly to generate documentation. 459# 460#--------------------------------------------------------------------- 461 462install-binaries: 463 @echo Installing binaries to '$(SCRIPT_INSTALL_DIR)' 464 @if not exist "$(SCRIPT_INSTALL_DIR)" mkdir "$(SCRIPT_INSTALL_DIR)" 465 @$(CPY) $(PRJLIB) "$(SCRIPT_INSTALL_DIR)" >NUL 466 @$(CPY) $(PRJSTUBLIB) "$(SCRIPT_INSTALL_DIR)" >NUL 467 468install-libraries: 469 @echo Installing libraries to '$(SCRIPT_INSTALL_DIR)' 470 @if exist $(LIBDIR)\NUL $(CPY) $(LIBDIR)\*.tcl "$(SCRIPT_INSTALL_DIR)" >NUL 471 @echo Installing package index in '$(SCRIPT_INSTALL_DIR)' 472 @type << >"$(SCRIPT_INSTALL_DIR)\pkgIndex.tcl" 473if {[info exists ::tcl_platform(debug)]} { 474 package ifneeded $(PROJECT) $(DOTVERSION) "[list load [file join $$dir $(PROJECT)$(VERSION)g.$(EXT)] tdom]; [list source [file join $$dir tdom.tcl]]" 475} else { 476 package ifneeded $(PROJECT) $(DOTVERSION) "[list load [file join $$dir $(PROJECT)$(VERSION).$(EXT)] tdom]; [list source [file join $$dir tdom.tcl]]" 477} 478<< 479 480install-docs: 481# @echo Installing documentation files to '$(DOC_INSTALL_DIR)' 482# @if exist $(DOCDIR) $(CPY) $(DOCDIR)\*.n "$(DOC_INSTALL_DIR)" 483 484#--------------------------------------------------------------------- 485# Clean up 486#--------------------------------------------------------------------- 487 488clean: 489 @if exist $(TMP_DIR)\nul $(RMDIR) $(TMP_DIR) 490 @if exist $(WINDIR)\version.vc del $(WINDIR)\version.vc 491 @if exist $(WINDIR)\vercl.i del $(WINDIR)\vercl.i 492 @if exist $(WINDIR)\vercl.x del $(WINDIR)\vercl.x 493 @if exist $(WINDIR)\_junk.pch del $(WINDIR)\_junk.pch 494 495realclean: clean 496 @if exist $(OUT_DIR)\nul $(RMDIR) $(OUT_DIR) 497 498distclean: realclean 499 @if exist $(WINDIR)\nmakehlp.exe del $(WINDIR)\nmakehlp.exe 500 @if exist $(WINDIR)\nmakehlp.obj del $(WINDIR)\nmakehlp.obj 501