# Visual C++ 2.x and 4.0 makefile
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# 
# Copyright (c) 1995-1996 Sun Microsystems, Inc.
# SCCS: @(#) makefile.vc 1.82 97/11/20 15:14:01

# Does not depend on the presence of any environment variables in
# order to compile tcl; all needed information is derived from 
# location of the compiler directories.

#
# Project directories
#
# ROOT    = top of source tree
#
# TMPDIR  = location where .obj files should be stored during build
#
# TOOLS32 = location of VC++ 32-bit development tools. Note that the
#	    VC++ 2.0 header files are broken, so you need to use the
#	    ones that come with the developer network CD's, or later
#	    versions of VC++.
#
# IDE32	  = With VC++ 5.0 the resource compiler is in a separate directory
#
# TOOLS16 = location of VC++ 1.5 16-bit tools, needed to build thunking
#	    library.  This information is optional; if the 16-bit compiler
#	    is not available, then the 16-bit code will not be built.  
#	    Tcl will still run without the 16-bit code, but...
#		A. Under Windows 3.X you will any calls to the exec command
#	           will return an error.
#		B. A 16-bit program to test the behavior of the exec
#		   command under NT and 95 will not be built.
#
# DESTDIR = Root directory of install hierarchy
#
# VENDOR  = Vendor for root directory registry key
#

ROOT		= ..
TMPDIR		= .
TOOLS32		= c:\progra~1\micros~3\vc98
IDE32		= c:\progra~1\micros~3\common\MSDev98
TOOLS16		= c:\msvc
DESTDIR		= c:\progra~1\CSLU\tcl80
VENDOR		=
VENDORREG	= CSLU

# Set this to the appropriate value of /MACHINE: for your platform
MACHINE	= IX86

# Comment the following line to compile with symbols
NODEBUG=1

# uncomment one of the following lines to compile with TCL_MEM_DEBUG, 
# TCL_MEM_DEBUG, or TCL_COMPILE_DEBUG
#DEBUGDEFINES = -DUSE_TCLALLOC=0
#DEBUGDEFINES	= -DTCL_MEM_DEBUG
#DEBUGDEFINES	= -DTCL_MEM_DEBUG -DTCL_COMPILE_DEBUG
#DEBUGDEFINES	= -DTCL_MEM_DEBUG -DTCL_COMPILE_STATS
#DEBUGDEFINES	= -DTCL_MEM_DEBUG -DTCL_COMPILE_DEBUG -DTCL_COMPILE_STATS

######################################################################
# Do not modify below this line
######################################################################

VERSION = 80
TCL_VERSION = 8.0

INST_BIN = $(DESTDIR)\bin
INST_INCLUDE = $(DESTDIR)\include
INST_LIB = $(DESTDIR)\lib
INST_RUNTIME = $(INST_LIB)\tcl$(TCL_VERSION)

TCLLIB		= $(VENDOR)tcl$(VERSION).lib
TCLDLL		= $(VENDOR)tcl$(VERSION).dll
TCLPLUGINLIB	= $(VENDOR)tcl$(VERSION)p.lib
TCLPLUGINDLL	= $(VENDOR)tcl$(VERSION)p.dll
TCL16DLL	= tcl16$(VERSION).dll
TCLSH		= tclsh$(VERSION).exe
TCLSHP		= tclshp$(VERSION).exe
TCLTEST		= tcltest.exe
DUMPEXTS	= $(TMPDIR)\dumpexts.exe
TCLPIPEDLL	= $(VENDOR)tclpip$(VERSION).dll
TCLREGDLL	= tclreg$(VERSION).dll
CAT16		= cat16.exe
CAT32		= cat32.exe

TCLSHOBJS = \
	$(TMPDIR)\tclAppInit.obj

TCLTESTOBJS = \
	$(TMPDIR)\tclTest.obj \
	$(TMPDIR)\tclTestObj.obj \
	$(TMPDIR)\tclWinTest.obj \
	$(TMPDIR)\testMain.obj

TCLOBJS = \
	$(TMPDIR)\panic.obj \
	$(TMPDIR)\regexp.obj \
	$(TMPDIR)\strftime.obj \
	$(TMPDIR)\tclAlloc.obj \
	$(TMPDIR)\tclAsync.obj \
	$(TMPDIR)\tclBasic.obj \
	$(TMPDIR)\tclBinary.obj \
	$(TMPDIR)\tclCkalloc.obj \
	$(TMPDIR)\tclClock.obj \
	$(TMPDIR)\tclCmdAH.obj \
	$(TMPDIR)\tclCmdIL.obj \
	$(TMPDIR)\tclCmdMZ.obj \
	$(TMPDIR)\tclCompExpr.obj \
	$(TMPDIR)\tclCompile.obj \
	$(TMPDIR)\tclDate.obj \
	$(TMPDIR)\tclEnv.obj \
	$(TMPDIR)\tclEvent.obj \
	$(TMPDIR)\tclExecute.obj \
	$(TMPDIR)\tclFCmd.obj \
	$(TMPDIR)\tclFileName.obj \
	$(TMPDIR)\tclGet.obj \
	$(TMPDIR)\tclHash.obj \
	$(TMPDIR)\tclHistory.obj \
	$(TMPDIR)\tclIndexObj.obj \
	$(TMPDIR)\tclInterp.obj \
	$(TMPDIR)\tclIO.obj \
	$(TMPDIR)\tclIOCmd.obj \
	$(TMPDIR)\tclIOSock.obj \
	$(TMPDIR)\tclIOUtil.obj \
	$(TMPDIR)\tclLink.obj \
	$(TMPDIR)\tclListObj.obj \
	$(TMPDIR)\tclLoad.obj \
	$(TMPDIR)\tclMain.obj \
	$(TMPDIR)\tclNamesp.obj \
	$(TMPDIR)\tclNotify.obj \
	$(TMPDIR)\tclObj.obj \
	$(TMPDIR)\tclParse.obj \
	$(TMPDIR)\tclPipe.obj \
	$(TMPDIR)\tclPkg.obj \
	$(TMPDIR)\tclPosixStr.obj \
	$(TMPDIR)\tclPreserve.obj \
	$(TMPDIR)\tclProc.obj \
	$(TMPDIR)\tclStringObj.obj \
	$(TMPDIR)\tclTimer.obj \
	$(TMPDIR)\tclUtil.obj \
	$(TMPDIR)\tclVar.obj \
	$(TMPDIR)\tclWin32Dll.obj \
	$(TMPDIR)\tclWinChan.obj \
	$(TMPDIR)\tclWinError.obj \
	$(TMPDIR)\tclWinFCmd.obj \
	$(TMPDIR)\tclWinFile.obj \
	$(TMPDIR)\tclWinInit.obj \
	$(TMPDIR)\tclWinLoad.obj \
	$(TMPDIR)\tclWinMtherr.obj \
	$(TMPDIR)\tclWinNotify.obj \
	$(TMPDIR)\tclWinPipe.obj \
	$(TMPDIR)\tclWinSock.obj \
	$(TMPDIR)\tclWinTime.obj 

cc32		= "$(TOOLS32)\bin\cl.exe"
link32		= "$(TOOLS32)\bin\link.exe"
rc32		= "$(IDE32)\bin\rc.exe"
include32	= -I"$(TOOLS32)\include"

cc16		= $(TOOLS16)\bin\cl.exe
link16		= $(TOOLS16)\bin\link.exe
rc16		= $(TOOLS16)\bin\rc.exe
include16	= -I$(TOOLS16)\include

WINDIR          = $(ROOT)\win
GENERICDIR	= $(ROOT)\generic

TCL_INCLUDES	= -I$(WINDIR) -I$(GENERICDIR)
TCL_DEFINES	= -D__WIN32__ $(DEBUGDEFINES) -DVENDORREG=\"$(VENDORREG)\"

TCL_CFLAGS	= $(cdebug) $(cflags) $(cvarsdll) $(include32) \
			$(TCL_INCLUDES) $(TCL_DEFINES)
CON_CFLAGS	= $(cdebug) $(cflags) $(cvars) $(include32) -DCONSOLE
DOS_CFLAGS	= $(cdebug) $(cflags) $(include16) -AL 
DLL16_CFLAGS	= $(cdebug) $(cflags) $(include16) -ALw

######################################################################
# Link flags
######################################################################

!IFDEF NODEBUG
ldebug = /RELEASE
!ELSE
ldebug = -debug:full -debugtype:cv
!ENDIF

# declarations common to all linker options
lcommon = /NODEFAULTLIB /RELEASE /NOLOGO

# declarations for use on Intel i386, i486, and Pentium systems
!IF "$(MACHINE)" == "IX86"
DLLENTRY = @12
lflags   = $(lcommon) -align:0x1000 /MACHINE:$(MACHINE)
!ELSE
lflags   = $(lcommon) /MACHINE:$(MACHINE)
!ENDIF

conlflags = $(lflags) -subsystem:console -entry:mainCRTStartup
guilflags = $(lflags) -subsystem:windows -entry:WinMainCRTStartup
dlllflags = $(lflags) -entry:_DllMainCRTStartup$(DLLENTRY) -dll

!IF "$(MACHINE)" == "PPC"
libc = libc.lib
libcdll = crtdll.lib
!ELSE
libc = libc.lib oldnames.lib
libcdll = msvcrt.lib oldnames.lib
!ENDIF

baselibs   = kernel32.lib $(optlibs) advapi32.lib user32.lib
winlibs    = $(baselibs) gdi32.lib comdlg32.lib winspool.lib

guilibs	   = $(libc) $(winlibs)
conlibs	   = $(libc) $(baselibs)
guilibsdll = $(libcdll) $(winlibs)
conlibsdll = $(libcdll) $(baselibs)

######################################################################
# Compile flags
######################################################################

!IFDEF NODEBUG
cdebug = -Ox -Oy- -Gs -GD
!ELSE
cdebug = -Z7 -Od -WX
!ENDIF

# declarations common to all compiler options
ccommon = -c -W3 -nologo -YX -Dtry=__try -Dexcept=__except

!IF "$(MACHINE)" == "IX86"
cflags = $(ccommon) -D_X86_=1
!ELSE
!IF "$(MACHINE)" == "MIPS"
cflags = $(ccommon) -D_MIPS_=1
!ELSE
!IF "$(MACHINE)" == "PPC"
cflags = $(ccommon) -D_PPC_=1
!ELSE
!IF "$(MACHINE)" == "ALPHA"
cflags = $(ccommon) -D_ALPHA_=1
!ENDIF
!ENDIF
!ENDIF
!ENDIF

cvars      = -DWIN32 -D_WIN32
cvarsmt    = $(cvars) -D_MT
cvarsdll   = $(cvarsmt) -D_DLL

######################################################################
# Project specific targets
######################################################################

release:    $(TCLSH) dlls
dlls:	    $(TCL16DLL) $(TCLPIPEDLL) $(TCLREGDLL)
all:	    $(TCLSH) dlls $(CAT16) $(CAT32) 
tcltest:    $(TCLTEST) dlls $(CAT16) $(CAT32)
plugin:	    $(TCLPLUGINDLL) $(TCLSHP)
test:	    $(TCLTEST) dlls $(CAT16) $(CAT32) 
	$(TCLTEST) <<
		cd ../tests
		source all
<<

$(DUMPEXTS): $(WINDIR)\winDumpExts.c
	$(cc32) $(CON_CFLAGS) -Fo$(TMPDIR)\ $?
	set LIB="$(TOOLS32)\lib"
	$(link32) $(ldebug) $(conlflags) $(guilibs) -out:$@ \
		$(TMPDIR)\winDumpExts.obj 

$(TCLLIB): $(TCLDLL)

$(TCLDLL): $(TCLOBJS) $(TMPDIR)\tcl.def $(TMPDIR)\tcl.res
	set LIB="$(TOOLS32)\lib"
	$(link32) $(ldebug) $(dlllflags) -def:$(TMPDIR)\tcl.def \
		-out:$@ $(TMPDIR)\tcl.res $(guilibsdll) @<<
$(TCLOBJS)
<<

$(TCLPLUGINLIB): $(TCLPLUGINDLL)

$(TCLPLUGINDLL): $(TCLOBJS) $(TMPDIR)\plugin.def $(TMPDIR)\tcl.res
	set LIB="$(TOOLS32)\lib"
	$(link32) $(ldebug) $(dlllflags) -def:$(TMPDIR)\plugin.def \
		-out:$@ $(TMPDIR)\tcl.res $(guilibsdll) @<<
$(TCLOBJS)
<<

$(TCLSH): $(TCLSHOBJS) $(TCLLIB) $(TMPDIR)\tclsh.res
	set LIB="$(TOOLS32)\lib"
	$(link32) $(ldebug) $(conlflags) $(TMPDIR)\tclsh.res -stack:2300000 \
		-out:$@ $(conlibsdll) $(TCLLIB) $(TCLSHOBJS) 

$(TCLSHP): $(TCLSHOBJS) $(TCLPLUGINLIB) $(TMPDIR)\tclsh.res
	set LIB="$(TOOLS32)\lib"
	$(link32) $(ldebug) $(conlflags) $(TMPDIR)\tclsh.res -stack:2300000 \
		-out:$@ $(conlibsdll) $(TCLPLUGINLIB) $(TCLSHOBJS) 

$(TCLTEST): $(TCLTESTOBJS) $(TCLLIB) $(TMPDIR)\tclsh.res
	set LIB="$(TOOLS32)\lib"
	$(link32) $(ldebug) $(conlflags) $(TMPDIR)\tclsh.res -stack:2300000 \
		 -out:$@ $(conlibsdll) $(TCLLIB) $(TCLTESTOBJS)

$(TCL16DLL):  $(WINDIR)\tcl16.rc $(WINDIR)\tclWin16.c
	if exist $(cc16) $(cc16) @<<
$(DLL16_CFLAGS) -Fo$(TMPDIR)\ $(WINDIR)\tclWin16.c
<<                         
	@copy << $(TMPDIR)\tclWin16.def > nul
LIBRARY $(@B);dll
EXETYPE WINDOWS
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE SINGLE
HEAPSIZE 1024 
EXPORTS
	WEP @1 RESIDENTNAME
	UTPROC @2 
<< 
	if exist $(cc16) $(link16) /NOLOGO /ONERROR:NOEXE /NOE @<<
$(TMPDIR)\tclWin16.obj
$@
nul
$(TOOLS16)\lib\ ldllcew oldnames libw toolhelp
$(TMPDIR)\tclWin16.def
<<
	if exist $(cc16) $(rc16) -i $(GENERICDIR) $(TCL_DEFINES) $(WINDIR)\tcl16.rc $@

$(TCLPIPEDLL): $(WINDIR)\stub16.c
	$(cc32) $(CON_CFLAGS) -Fo$(TMPDIR)\ $(WINDIR)\stub16.c
	set LIB="$(TOOLS32)\lib"
	$(link32) $(ldebug) $(conlflags) -out:$@ $(TMPDIR)\stub16.obj $(guilibs)

$(TCLREGDLL): $(TMPDIR)\tclWinReg.obj
	set LIB="$(TOOLS32)\lib"
	$(link32) $(ldebug) $(dlllflags) -out:$@ $(TMPDIR)\tclWinReg.obj \
		$(conlibsdll) $(TCLLIB)

$(CAT32): $(WINDIR)\cat.c
	$(cc32) $(CON_CFLAGS) -Fo$(TMPDIR)\ $?
	set LIB="$(TOOLS32)\lib"
	$(link32) $(conlflags) -out:$@ -stack:16384 $(TMPDIR)\cat.obj $(conlibs)

$(CAT16): $(WINDIR)\cat.c
	if exist $(cc16) $(cc16) $(DOS_CFLAGS) -Fo$(TMPDIR)\ $?
	set LIB=$(TOOLS16)\lib
	if exist $(cc16) $(link16) /NOLOGO /ONERROR:NOEXE /NOI /STACK:16384 \
		$(TMPDIR)\cat.obj,$@,nul,llibce.lib,nul

$(TMPDIR)\tcl.def: $(DUMPEXTS) $(TCLOBJS)
	$(DUMPEXTS) -o $@ $(TCLDLL) @<<
$(TCLOBJS)
<<

$(TMPDIR)\plugin.def: $(DUMPEXTS) $(TCLOBJS)
	$(DUMPEXTS) -o $@ $(TCLPLUGINDLL) @<<
$(TCLOBJS)
<<

#
# Special case object file targets
#

$(TMPDIR)\testMain.obj: $(WINDIR)\tclAppInit.c
	$(cc32) $(TCL_CFLAGS) -DTCL_TEST -Fo$(TMPDIR)\testMain.obj $?

#
# Implicit rules
#

{$(WINDIR)}.c{$(TMPDIR)}.obj:
    $(cc32) $(TCL_CFLAGS) -Fo$(TMPDIR)\ $<

{$(GENERICDIR)}.c{$(TMPDIR)}.obj:
    $(cc32) $(TCL_CFLAGS) -Fo$(TMPDIR)\ $<

{$(ROOT)\compat}.c{$(TMPDIR)}.obj:
    $(cc32) $(TCL_CFLAGS) -Fo$(TMPDIR)\ $<

{$(WINDIR)}.rc{$(TMPDIR)}.res:
	$(rc32) -fo $@ -r -i $(GENERICDIR) -i $(WINDIR) -D__WIN32__ \
		$(TCL_DEFINES) $<

clean:
        -@del *.exp 
	-@del *.lib 
	-@del *.dll 
	-@del *.exe
	-@del *.pdb
	-@del *.pch
        -@del $(TMPDIR)\*.obj
        -@del $(TMPDIR)\*.res
        -@del $(TMPDIR)\*.def

install:
	@echo Creating installation directory hierarchy
	@if not exist "$(INST_LIB)" mkdir "$(INST_LIB)"
	@if not exist "$(INST_RUNTIME)" mkdir "$(INST_RUNTIME)"
	@if not exist "$(INST_RUNTIME)\http2.0" mkdir "$(INST_RUNTIME)\http2.0"
	@if not exist "$(INST_RUNTIME)\http1.0" mkdir "$(INST_RUNTIME)\http1.0"
	@if not exist "$(INST_RUNTIME)\opt0.1" mkdir "$(INST_RUNTIME)\opt0.1"
	@if not exist "$(INST_RUNTIME)\msgcat1.0" mkdir "$(INST_RUNTIME)\msgcat1.0"
	@if not exist "$(INST_BIN)" mkdir "$(INST_BIN)"
	@if not exist "$(INST_INCLUDE)" mkdir "$(INST_INCLUDE)"
	xcopy "$(ROOT)\library" "$(INST_RUNTIME)"
	xcopy "$(ROOT)\library\http1.0" "$(INST_RUNTIME)\http1.0"
	xcopy "$(ROOT)\library\http2.0" "$(INST_RUNTIME)\http2.0"
	xcopy "$(ROOT)\library\opt0.1" "$(INST_RUNTIME)\opt0.1"
	xcopy "$(ROOT)\library\msgcat1.0" "$(INST_RUNTIME)\msgcat1.0"
	copy "$(ROOT)\generic\tcl.h" "$(INST_INCLUDE)"
	copy $(TCLDLL) "$(INST_BIN)"
	copy $(TCLPIPEDLL) "$(INST_BIN)"
	copy $(TCLREGDLL) "$(INST_BIN)"
	copy $(TCLSH) "$(INST_BIN)"
	copy $(TCLLIB) "$(INST_LIB)"
	@echo Creating pkgIndex.tcl in "$(INST_RUNTIME)"
	@copy << "$(INST_RUNTIME)\pkgIndex.tcl"
package ifneeded registry 1.0 "load [list $$dir/../../bin/$(TCLREGDLL)] registry"
<<
	@echo Installing registry setup script
	@copy << "$(INST_LIB)\setup.tcl"

	    if {$$argc != 1} {
		error "Usage: $$argv0 <TclRootDir>"
	    }
	    set root [lindex $$argv 0]
	    if {![file exists [file join $$root bin tclsh$(VERSION).exe]]} {
		error "No tclsh$(VERSION) in [file join $$root bin]"
	    }

	    package require registry

	    puts {Updating location of Tcl installation directory in registry}
	    set kp "HKEY_LOCAL_MACHINE\\Software\\$(VENDORREG)"
	    set key "$$kp\\Tcl\\$(TCL_VERSION)"
	    registry set $$key Root $$root expand_sz

	    puts {Defining desktop actions for .tcl files}
	    set kp "HKEY_LOCAL_MACHINE\\Software\\Classes"

	    #
	    # Associate .tcl files with TclScript file type,
	    # and application/x-tcl MIME type.
	    #
	    set key "$$kp\\.tcl"
	    registry set $$key "" TclScript expand_sz
	    registry set $$key {Content Type} application/x-tcl expand_sz
	    set key "$$kp\\MIME\\Database\\Content Type\\application/x-tcl"
	    registry set $$key Extension .tcl expand_sz

	    #
	    # Give the file type a user friendly name
	    #
	    set kp "$$kp\\TclScript"
	    registry set $$kp "" {Tcl/Tk Script} expand_sz
	    # What uses this?
	    registry set $$key EditFlags [binary format H* 00000000] binary

	    #
	    # Display "Tk" icon for scripts.
	    #
	    set key "$$kp\\DefaultIcon"
	    set p [file nativename [file join $$root bin tk$(VERSION).dll]]
	    registry set $$key "" "$$p,0" expand_sz

	    #
	    # Default "shell" for .tcl files is Wish
	    #
	    set kp "$$kp\\Shell"
	    registry set $$kp "" Wish$(VERSION) expand_sz

	    #
	    # Pass script pathname to Wish (invoked from desktop)
	    #
	    set key "$$kp\\Wish$(VERSION)\\command"
	    set p [file nativename [file join $$root bin wish$(VERSION).exe]]
	    registry set $$key "" "\"$$p\" \"%1\"" expand_sz

	    #
	    # Pass script pathname to Tclsh (invoked from desktop)
	    #
	    set key "$$kp\\Tclsh$(VERSION)\\command"
	    set p [file nativename [file join $$root bin tclsh$(VERSION).exe]]
	    registry set $$key "" "\"$$p\" \"%1\"" expand_sz

	    #
	    # Pass script and remaining args to Tclsh, when tcl scripts are
	    # invoked via (DOS) shell.
	    #
	    set key "$$kp\\open\\command"
	    set p [file nativename [file join $$root bin tclsh$(VERSION).exe]]
	    registry set $$key "" "\"$$p\" \"%1\" %*" expand_sz
<<
