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.33 2009/05/04 22:46:17 patthoyts 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 = thread 162 163# Uncomment the following line if this is a Tk extension. 164#PROJECT_REQUIRES_TK=1 165!include "rules.vc" 166 167!include "pkg.vc" 168 169DOTVERSION = $(PACKAGE_VERSION:"=) #" 170VERSION = $(PACKAGE_MAJOR)$(PACKAGE_MINOR) 171STUBPREFIX = $(PROJECT)stub 172 173DLLOBJS = \ 174 $(TMP_DIR)\threadCmd.obj \ 175 $(TMP_DIR)\threadSvCmd.obj \ 176 $(TMP_DIR)\threadSpCmd.obj \ 177 $(TMP_DIR)\threadPoolCmd.obj \ 178 $(TMP_DIR)\psGdbm.obj \ 179 $(TMP_DIR)\threadSvListCmd.obj \ 180 $(TMP_DIR)\threadSvKeylistCmd.obj \ 181 $(TMP_DIR)\tclXkeylist.obj \ 182 $(TMP_DIR)\threadWin.obj \ 183!if !$(STATIC_BUILD) 184 $(TMP_DIR)\thread.res 185!endif 186 187PRJHEADERS = 188 189#------------------------------------------------------------------------- 190# Target names and paths ( shouldn't need changing ) 191#------------------------------------------------------------------------- 192 193BINROOT = . 194ROOT = ..\.. 195 196PRJIMPLIB = $(OUT_DIR)\$(PROJECT)$(VERSION)$(SUFX).lib 197PRJLIBNAME = $(PROJECT)$(VERSION)$(SUFX).$(EXT) 198PRJLIB = $(OUT_DIR)\$(PRJLIBNAME) 199 200PRJSTUBLIBNAME = $(STUBPREFIX)$(VERSION).lib 201PRJSTUBLIB = $(OUT_DIR)\$(PRJSTUBLIBNAME) 202 203### Make sure we use backslash only. 204PRJ_INSTALL_DIR = $(_INSTALLDIR)\$(PROJECT)$(DOTVERSION) 205LIB_INSTALL_DIR = $(PRJ_INSTALL_DIR) 206BIN_INSTALL_DIR = $(PRJ_INSTALL_DIR) 207DOC_INSTALL_DIR = $(PRJ_INSTALL_DIR) 208SCRIPT_INSTALL_DIR = $(PRJ_INSTALL_DIR) 209INCLUDE_INSTALL_DIR = $(_TCLDIR)\include 210 211### The following paths CANNOT have spaces in them. 212GENERICDIR = $(ROOT)\generic 213WINDIR = $(ROOT)\win 214LIBDIR = $(ROOT)\lib 215DOCDIR = $(ROOT)\doc 216TOOLSDIR = $(ROOT)\tools 217COMPATDIR = $(ROOT)\compat 218 219#--------------------------------------------------------------------- 220# Compile flags 221#--------------------------------------------------------------------- 222 223!if !$(DEBUG) 224!if $(OPTIMIZING) 225### This cranks the optimization level to maximize speed 226cdebug = $(OPTIMIZATIONS) 227!else 228cdebug = 229!endif 230!else if "$(MACHINE)" == "IA64" #|| "$(MACHINE)" == "AMD64" 231### Warnings are too many, can't support warnings into errors. 232cdebug = -Zi -Od $(DEBUGFLAGS) 233!else 234cdebug = -Zi -W3 $(DEBUGFLAGS) 235!endif 236 237### Declarations common to all compiler options 238cwarn = $(WARNINGS) -D _CRT_SECURE_NO_DEPRECATE -D _CRT_NONSTDC_NO_DEPRECATE 239cflags = -nologo -c $(COMPILERFLAGS) $(cwarn) -Fp$(TMP_DIR)^\ 240 241!if $(MSVCRT) 242!if $(DEBUG) && !$(UNCHECKED) 243crt = -MDd 244!else 245crt = -MD 246!endif 247!else 248!if $(DEBUG) && !$(UNCHECKED) 249crt = -MTd 250!else 251crt = -MT 252!endif 253!endif 254 255!if !$(STATIC_BUILD) 256cflags = $(cflags) -DUSE_TCL_STUBS 257!if defined(TKSTUBLIB) 258cflags = $(cflags) -DUSE_TK_STUBS 259!endif 260!endif 261 262INCLUDES = $(TCL_INCLUDES) -I"$(WINDIR)" -I"$(GENERICDIR)" 263BASE_CFLAGS = $(cflags) $(cdebug) $(crt) $(INCLUDES) 264CON_CFLAGS = $(cflags) $(cdebug) $(crt) -DCONSOLE 265TCL_CFLAGS = -DPACKAGE_NAME="\"$(PROJECT)\"" \ 266 -DPACKAGE_VERSION="\"$(DOTVERSION)\"" \ 267 -DBUILD_$(PROJECT) \ 268 $(BASE_CFLAGS) $(OPTDEFINES) 269 270#--------------------------------------------------------------------- 271# Link flags 272#--------------------------------------------------------------------- 273 274!if $(DEBUG) 275ldebug = -debug:full -debugtype:cv 276!if $(MSVCRT) 277ldebug = $(ldebug) -nodefaultlib:msvcrt 278!endif 279!else 280ldebug = -release -opt:ref -opt:icf,3 281!endif 282 283### Declarations common to all linker options 284lflags = -nologo -machine:$(MACHINE) $(LINKERFLAGS) $(ldebug) 285 286!if $(PROFILE) 287lflags = $(lflags) -profile 288!endif 289 290!if $(ALIGN98_HACK) && !$(STATIC_BUILD) 291### Align sections for PE size savings. 292lflags = $(lflags) -opt:nowin98 293!else if !$(ALIGN98_HACK) && $(STATIC_BUILD) 294### Align sections for speed in loading by choosing the virtual page size. 295lflags = $(lflags) -align:4096 296!endif 297 298!if $(LOIMPACT) 299lflags = $(lflags) -ws:aggressive 300!endif 301 302dlllflags = $(lflags) -dll 303conlflags = $(lflags) -subsystem:console 304guilflags = $(lflags) -subsystem:windows 305!if !$(STATIC_BUILD) 306baselibs = $(TCLSTUBLIB) 307!if defined(TKSTUBLIB) 308baselibs = $(baselibs) $(TKSTUBLIB) 309!endif 310!endif 311 312# Avoid 'unresolved external symbol __security_cookie' errors. 313# c.f. http://support.microsoft.com/?id=894573 314!if "$(MACHINE)" == "IA64" || "$(MACHINE)" == "AMD64" 315!if $(VCVERSION) >= 1400 && $(VCVERSION) < 1500 316baselibs = $(baselibs) bufferoverflowU.lib 317!endif 318!endif 319 320#--------------------------------------------------------------------- 321# TclTest flags 322#--------------------------------------------------------------------- 323 324!IF "$(TESTPAT)" != "" 325TESTFLAGS = $(TESTFLAGS) -file $(TESTPAT) 326!ENDIF 327 328#--------------------------------------------------------------------- 329# Project specific targets (EDIT) 330#--------------------------------------------------------------------- 331 332all: setup $(PROJECT) 333$(PROJECT): setup pkgIndex $(PRJLIB) 334install: install-binaries install-libraries install-docs 335pkgIndex: $(OUT_DIR)\pkgIndex.tcl 336 337test: setup $(PROJECT) 338 @set TCL_LIBRARY=$(TCL_LIBRARY:\=/) 339 @set TCLLIBPATH=$(OUT_DIR_PATH:\=/) 340 @$(CPY) $(LIBDIR)\*.tcl $(OUT_DIR) 341!if $(TCLINSTALL) 342 @set PATH=$(_TCLDIR)\bin;$(PATH) 343!else 344 @set PATH=$(_TCLDIR)\win\$(BUILDDIRTOP);$(PATH) 345!endif 346!if "$(OS)" == "Windows_NT" || "$(MSVCDIR)" == "IDE" 347 $(DEBUGGER) $(TCLSH) "$(ROOT)/tests/all.tcl" $(TESTFLAGS) 348!else 349 @echo Please wait while the tests are collected... 350 $(DEBUGGER) $(TCLSH) "$(ROOT)/tests/all.tcl" $(TESTFLAGS) > tests.log 351 type tests.log | more 352!endif 353 354shell: setup $(PROJECT) 355 @set VLERQ_LIBRARY=$(LIBDIR:\=/) 356 @set TCL_LIBRARY=$(TCL_LIBRARY:\=/) 357 @set TCLLIBPATH=$(OUT_DIR:\=/) 358 @$(CPY) $(LIBDIR)\*.tcl $(OUT_DIR) 359!if $(TCLINSTALL) 360 @set PATH=$(_TCLDIR)\bin;$(PATH) 361!else 362 @set PATH=$(_TCLDIR)\win\$(BUILDDIRTOP);$(PATH) 363!endif 364 $(DEBUGGER) $(TCLSH) $(SCRIPT) 365 366setup: 367 @if not exist $(OUT_DIR)\nul mkdir $(OUT_DIR) 368 @if not exist $(TMP_DIR)\nul mkdir $(TMP_DIR) 369 370# See <tcl>/win/coffbase.txt for extension base addresses. 371$(PRJLIB): $(DLLOBJS) 372!if $(STATIC_BUILD) 373 $(lib32) -nologo -out:$@ @<< 374$** 375<< 376!else 377 $(link32) $(dlllflags) -base:0x10C80000 -out:$@ $(baselibs) @<< 378$** 379<< 380 $(_VC_MANIFEST_EMBED_DLL) 381 -@del $*.exp 382!endif 383 384$(PRJSTUBLIB): $(PRJSTUBOBJS) 385 $(lib32) -nologo -out:$@ $(PRJSTUBOBJS) 386 387#--------------------------------------------------------------------- 388# Implicit rules 389#--------------------------------------------------------------------- 390 391{$(WINDIR)}.c{$(TMP_DIR)}.obj:: 392 $(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ @<< 393$< 394<< 395 396{$(GENERICDIR)}.c{$(TMP_DIR)}.obj:: 397 $(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ @<< 398$< 399<< 400 401{$(COMPATDIR)}.c{$(TMP_DIR)}.obj:: 402 $(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ @<< 403$< 404<< 405 406{$(WINDIR)}.rc{$(TMP_DIR)}.res: 407 $(rc32) -fo $@ -r -i "$(GENERICDIR)" $(TCL_INCLUDES) \ 408 -D__WIN32__ \ 409 -DCOMMAVERSION=$(DOTVERSION:.=,),0 \ 410 -DDOTVERSION=\"$(DOTVERSION)\" \ 411 -DVERSION=\"$(VERSION)$(SUFX)\" \ 412 -DDEBUG=$(DEBUG) \ 413 -DPACKAGE_MAJOR=$(PACKAGE_MAJOR) \ 414 -DPACKAGE_MINOR=$(PACKAGE_MINOR) \ 415 -DPACKAGE_VERSION=\"$(PACKAGE_VERSION)\" \ 416!if $(DEBUG) 417 -d DEBUG \ 418!endif 419!if $(TCL_THREADS) 420 -d TCL_THREADS \ 421!endif 422!if $(STATIC_BUILD) 423 -d STATIC_BUILD \ 424!endif 425 $< 426 427.SUFFIXES: 428.SUFFIXES:.c .rc 429 430#------------------------------------------------------------------------- 431# Explicit dependency rules 432# 433#------------------------------------------------------------------------- 434 435#{$(WINDIR)}.c{$(TMP_DIR)}.obj :: 436$(GENERICDIR)\psGdbm.c: $(GENERICDIR)\psGdbm.h 437$(GENERICDIR)\threadSpCmd.c : $(GENERICDIR)\tclThread.h 438$(GENERICDIR)\threadSvCmd.c : $(GENERICDIR)\tclThread.h 439$(GENERICDIR)\threadPoolCmd.c : $(GENERICDIR)\tclThread.h 440$(GENERICDIR)\threadSvListCmd.c : $(GENERICDIR)\tclThread.h 441$(GENERICDIR)\threadSvKeylistCmd.c : $(GENERICDIR)\tclThread.h 442 443.PHONY: $(OUT_DIR)\pkgIndex.tcl 444 445$(OUT_DIR)\pkgIndex.tcl: $(ROOT)\pkgIndex.tcl.in 446 @nmakehlp -s << $** > $@ 447@PACKAGE_NAME@ thread 448@PACKAGE_VERSION@ $(DOTVERSION) 449@PKG_LIB_FILE@ $(PRJLIBNAME) 450<< 451 452#--------------------------------------------------------------------- 453# Installation. (EDIT) 454# 455# You may need to modify this section to reflect the final distribution 456# of your files and possibly to generate documentation. 457# 458#--------------------------------------------------------------------- 459 460install-binaries: 461 @echo Installing binaries to '$(SCRIPT_INSTALL_DIR)' 462 @if not exist "$(SCRIPT_INSTALL_DIR)" mkdir "$(SCRIPT_INSTALL_DIR)" 463 @$(CPY) $(PRJLIB) "$(SCRIPT_INSTALL_DIR)" >NUL 464 465install-libraries: 466 @echo Installing library files to '$(SCRIPT_INSTALL_DIR)' 467 @if exist $(LIBDIR) $(CPY) $(LIBDIR)\*.tcl "$(SCRIPT_INSTALL_DIR)" 468 @$(CPY) $(OUT_DIR)\pkgIndex.tcl "$(SCRIPT_INSTALL_DIR)" 469 470install-docs: 471 @echo Installing documentation files to '$(DOC_INSTALL_DIR)' 472 @if exist $(DOCDIR)\man $(CPY) $(DOCDIR)\man\*.n "$(DOC_INSTALL_DIR)" 473 474#--------------------------------------------------------------------- 475# Clean up 476#--------------------------------------------------------------------- 477 478clean: 479 @if exist $(TMP_DIR)\nul $(RMDIR) $(TMP_DIR) 480 @if exist $(WINDIR)\version.vc del $(WINDIR)\version.vc 481 @if exist $(WINDIR)\vercl.i del $(WINDIR)\vercl.i 482 @if exist $(WINDIR)\vercl.x del $(WINDIR)\vercl.x 483 @if exist $(WINDIR)\_junk.pch del $(WINDIR)\_junk.pch 484 485realclean: clean 486 @if exist $(OUT_DIR)\nul $(RMDIR) $(OUT_DIR) 487 488distclean: realclean 489 @if exist $(WINDIR)\nmakehlp.exe del $(WINDIR)\nmakehlp.exe 490 @if exist $(WINDIR)\nmakehlp.obj del $(WINDIR)\nmakehlp.obj 491