# 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) 1993-1998 Lucent Technologies, Inc.
# RCS: $Id: makefile.vc,v 1.1.1.1 1999/03/31 20:39:48 damon Exp $

# Does not depend on the presence of any environment variables in
# order to compile itcl; all needed information is derived from 
# location of the compiler directories.
#
# NOTE: Be sure to modify the "makefile.vc" file in the toplevel directory
#   for the itcl distribution.  Include the location of your VC++ development
#   tools and the installation directory.

!include "..\..\makefile.vc"


# ROOT    = top of source tree
# TMPDIR  = location where .obj files should be stored during build

ROOT		= ..

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

NAMEPREFIX = itcl
DOTVERSION = 3.0
VERSION = 30

BINROOT		= .
!IF "$(NODEBUG)" == "1"
TMPDIR		= $(BINROOT)\Release
DBGX		=
!ELSE
TMPDIR		= $(BINROOT)\Debug
DBGX		= d
!ENDIF
OUTDIR		= $(TMPDIR)

ITCLLIB		= $(OUTDIR)\$(NAMEPREFIX)$(VERSION)$(DBGX).lib
ITCLDLLNAME	= $(NAMEPREFIX)$(VERSION)$(DBGX).dll
ITCLDLL		= $(OUTDIR)\$(ITCLDLLNAME)
ITCLSH		= $(OUTDIR)\$(NAMEPREFIX)sh$(VERSION)$(DBGX).exe
DUMPEXTS 	= $(TMPDIR)\dumpexts.exe

TCLLIB		= $(TCLDIR)\win\$(OUTDIR)\tcl80$(DBGX).lib
TCLDLL		= $(TCLDIR)\win\$(OUTDIR)\tcl80$(DBGX).dll

LIB_INSTALL_DIR	= $(INSTALLDIR)\lib
BIN_INSTALL_DIR	= $(INSTALLDIR)\bin
SCRIPT_INSTALL_DIR	= $(INSTALLDIR)\lib\itcl$(DOTVERSION)
INCLUDE_INSTALL_DIR	= $(INSTALLDIR)\include

ITCLSHOBJS = \
	$(TMPDIR)\tclAppInit.obj

ITCLOBJS = \
	$(TMPDIR)\itcl_bicmds.obj \
	$(TMPDIR)\itcl_class.obj \
	$(TMPDIR)\itcl_cmds.obj \
	$(TMPDIR)\itcl_ensemble.obj \
	$(TMPDIR)\itcl_linkage.obj \
	$(TMPDIR)\itcl_migrate.obj \
	$(TMPDIR)\itcl_methods.obj \
	$(TMPDIR)\itcl_objects.obj \
	$(TMPDIR)\itcl_obsolete.obj \
	$(TMPDIR)\itcl_parse.obj \
	$(TMPDIR)\itcl_util.obj \
	$(TMPDIR)\dllEntryPoint.obj

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

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

ITCL_INCLUDES	= -I$(WINDIR) -I$(GENERICDIR) -I$(TCLDIR)\generic
ITCL_DEFINES	= -D__WIN32__ -DBUILD_itcl $(DEBUGDEFINES)

ITCL_CFLAGS	= $(cdebug) $(cflags) $(cvarsdll) $(include32) \
			$(ITCL_INCLUDES) $(ITCL_DEFINES)

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

!IF "$(NODEBUG)" == "1"
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) /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
######################################################################

!IF "$(NODEBUG)" == "1"
!IF "$(MACHINE)" == "ALPHA"
# MSVC on Alpha doesn't understand -Ot
cdebug = -O2i -Gs -GD
!ELSE
cdebug = -Oti -Gs -GD
!ENDIF
!ELSE
cdebug = -Z7 -Od -WX
!ENDIF

# declarations common to all compiler options
ccommon = -c -W3 -nologo -YX -Fp$(TMPDIR)\ -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

!IF "$(NODEBUG)" == "1"
cvarsdll   = $(cvars) -MD
!ELSE
cvarsdll   = $(cvars) -MDd
!ENDIF

CON_CFLAGS	= $(cdebug) $(cflags) $(cvars) $(include32) -DCONSOLE

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

release:    setup $(ITCLSH)
all:	    setup $(ITCLSH)
test:	    setup $(ITCLSH)
	-@copy $(TCLDLL) $(TMPDIR)
	$(ITCLSH) <<
		cd ../tests
		source all
<<

setup:
	if not exist $(TMPDIR) mkdir $(TMPDIR)
	if not exist $(OUTDIR) mkdir $(OUTDIR)

$(ITCLLIB): $(ITCLDLL)

$(ITCLDLL): $(ITCLOBJS) $(TCLLIB) $(TMPDIR)\itclvc.def $(TMPDIR)\itcl.res
	set LIB=$(TOOLS32)\lib
	$(link32) $(ldebug) $(dlllflags) -def:$(TMPDIR)\itclvc.def \
		-out:$@ $(TMPDIR)\itcl.res $(guilibsdll) @<<
$(ITCLOBJS) $(TCLLIB)
<<

$(ITCLSH): $(ITCLSHOBJS) $(ITCLLIB) $(TCLLIB) $(TMPDIR)\itclsh.res
	set LIB=$(TOOLS32)\lib
	$(link32) $(ldebug) $(conlflags) $(TMPDIR)\itclsh.res -stack:2300000 \
		-out:$@ $(conlibsdll) $(ITCLLIB) $(TCLLIB) $(ITCLSHOBJS)

$(TMPDIR)\itclvc.def: $(DUMPEXTS) $(ITCLOBJS)
	$(DUMPEXTS) -o $@ $(ITCLDLLNAME) @<<
$(ITCLOBJS)
<<

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

install: all
	if not exist $(INSTALLDIR) mkdir $(INSTALLDIR)
	if not exist $(BIN_INSTALL_DIR) mkdir $(BIN_INSTALL_DIR)
	if not exist $(LIB_INSTALL_DIR) mkdir $(LIB_INSTALL_DIR)
	if not exist $(SCRIPT_INSTALL_DIR) mkdir $(SCRIPT_INSTALL_DIR)
	if not exist $(INCLUDE_INSTALL_DIR) mkdir $(INCLUDE_INSTALL_DIR)
	copy $(ITCLSH) "$(BIN_INSTALL_DIR)"
	copy $(ITCLDLL) "$(BIN_INSTALL_DIR)"
	copy $(ROOT)\generic\itcl.h "$(INCLUDE_INSTALL_DIR)"
	copy $(ROOT)\library\*.* "$(SCRIPT_INSTALL_DIR)"
	copy $(ROOT)\win\*.tcl "$(SCRIPT_INSTALL_DIR)"

#
# Special case object file targets
#

$(TMPDIR)\tclAppInit.obj : $(WINDIR)\tclAppInit.c
	$(cc32) -DBUILD_tcl $(ITCL_CFLAGS) -Fo$@ $?

#
# Implicit rules
#

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

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

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

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

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