#------------------------------------------------------------- -*- makefile -*-
#
# Makefile for ITcl
#
# Basic build, test and install
#   nmake /f makefile.vc INSTALLDIR=c:\path\to\installdir TCLDIR=c:\path\to\tcl\source
#   nmake /f makefile.vc INSTALLDIR=c:\path\to\installdir TCLDIR=c:\path\to\tcl\source test
#   nmake /f makefile.vc INSTALLDIR=c:\path\to\installdir TCLDIR=c:\path\to\tcl\source install
#
# For other build options (debug, static etc.),
# See TIP 477 (https://core.tcl-lang.org/tips/doc/main/tip/477.md) for
# detailed documentation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
#------------------------------------------------------------------------------

PROJECT         = itcl
NEED_TCL_SOURCE = 1
RCFILE      = itcl.rc

PRJ_DEFINES = $(PRJ_DEFINES)
PRJ_DEFINES = $(PRJ_DEFINES) -I$(TMP_DIR)

!include "rules-ext.vc"

PRJ_OBJS = \
	$(TMP_DIR)\itcl2TclOO.obj \
	$(TMP_DIR)\itclBase.obj \
	$(TMP_DIR)\itclBuiltin.obj \
	$(TMP_DIR)\itclClass.obj \
	$(TMP_DIR)\itclCmd.obj \
	$(TMP_DIR)\itclEnsemble.obj \
	$(TMP_DIR)\itclHelpers.obj \
	$(TMP_DIR)\itclInfo.obj \
	$(TMP_DIR)\itclLinkage.obj \
	$(TMP_DIR)\itclMethod.obj \
	$(TMP_DIR)\itclMigrate2TclCore.obj \
	$(TMP_DIR)\itclObject.obj \
	$(TMP_DIR)\itclParse.obj \
	$(TMP_DIR)\itclResolve.obj \
	$(TMP_DIR)\itclStubs.obj \
	$(TMP_DIR)\itclStubInit.obj \
	$(TMP_DIR)\itclTclIntStubsFcn.obj \
	$(TMP_DIR)\itclUtil.obj \
!if !$(STATIC_BUILD)
	$(TMP_DIR)\dllEntryPoint.obj \
!endif

PRJ_STUBOBJS = $(TMP_DIR)\itclStubLib.obj

PRJ_DEFINES = $(PRJ_DEFINES) /D_CRT_SECURE_NO_WARNINGS
!if $(DEBUG)
PRJ_DEFINES = $(PRJ_DEFINES) /DITCL_DEBUG
!endif

PRJ_HEADERS_PUBLIC = \
	$(GENERICDIR)\itcl.h \
	$(GENERICDIR)\itclDecls.h

(ROOT)\manifest.uuid:
   copy $(WIN_DIR)\gitmanifest.in $(ROOT)\manifest.uuid
   git rev-parse HEAD >>$(ROOT)\manifest.uuid

$(TMP_DIR)\itclUuid.h:	$(ROOT)\manifest.uuid
	copy $(WIN_DIR)\itclUuid.h.in+$(ROOT)\manifest.uuid $(TMP_DIR)\itclUuid.h

(TMP_DIR)\itclBase.obj: $(TMP_DIR)\itclUuid.h

# Define the standard targets except we have a custom test target
DISABLE_TARGET_test = 1
!include "$(_RULESDIR)\targets.vc"

pkgindex:   $(OUT_DIR)\pkgIndex.tcl
$(OUT_DIR)\pkgIndex.tcl:
	@$(COPY) << "$(OUT_DIR)\pkgIndex.tcl"
# -*- tcl -*-
# Tcl package index file, version 1.1
#

if {![package vsatisfies [package provide Tcl] 8.6-]} {return}

if {[package vsatisfies [package provide Tcl] 9.0]} {
    package ifneeded itcl $(DOTVERSION) \
	    [list load [file join $$dir tcl9itcl$(VERSION).dll] Itcl]
} else {
    package ifneeded itcl $(DOTVERSION) \
	    [list load [file join $$dir itcl$(VERSION)$(SUFX).dll] Itcl]
}
package ifneeded Itcl $(DOTVERSION) [list package require -exact itcl $(DOTVERSION)]
<<

!if $(STATIC_BUILD)
test :
	@echo test target not supported for a static library.
!else
test : setup $(PROJECT)
	$(TCLSH) ..\tests\all.tcl $(TESTFLAGS) -loadfile <<
	set env(ITCL_LIBRARY) [file normalize [file join $(MAKEDIR:\=/) .. library]]
	package ifneeded $(PROJECT) $(DOTVERSION) [list load [file normalize [file join $(MAKEDIR:\=/) $(PRJLIB:\=/)]]]
<<
!endif

genstubs:
!if $(TCLINSTALL)
	@echo Need the source distribution to regenerate the Stubs table.
!else
	$(TCLSH) $(TOOLSDIR)\genStubs.tcl $(GENERICDIR) \
	       $(GENERICDIR)\$(PROJECT).decls $(GENERICDIR)\$(PROJECT)Int.decls
!endif

# Explicit dependency rules
$(GENERICDIR)\itclBase.c : $(GENERICDIR)\itclInt.h $(TMP_DIR)\itclUuid.h
