#------------------------------------------------------------- -*- makefile -*-
#
# Makefile for iocp
#
# Basic build, test and install
#   nmake /f makefile.vc INSTALLDIR=c:\tcl
#   nmake /f makefile.vc INSTALLDIR=c:\tcl test
#   nmake /f makefile.vc INSTALLDIR=c:\tcl install
#
# For other build options using OPTS= (debug, static etc.),
# See TIP 477 (https://core.tcl.tk/tips/doc/trunk/tip/477.md) for
# detailed documentation.
#
# To leave out Bluetooth support include nobt in OPTS= command line option.
# To do a debug tracing build include iocpdebug in the OPTS= command line option.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
#------------------------------------------------------------------------------

PROJECT	= iocp

!include "rules-ext.vc"


PRJ_OBJS = \
    $(TMP_DIR)\tclWinIocp.obj \
    $(TMP_DIR)\tclWinIocpThread.obj \
    $(TMP_DIR)\tclPolyfill.obj \
    $(TMP_DIR)\tclWinIocpWinsock.obj \
    $(TMP_DIR)\tclWinIocpTcp.obj \
    $(TMP_DIR)\tclWinIocpBT.obj \
    $(TMP_DIR)\tclWinIocpUtil.obj
# Currently not include because of bloat
#    $(TMP_DIR)\tclWinIocpBTNames.obj \

PRJ_DEFINES = /D_WIN32_WINNT=_WIN32_WINNT_WIN7 /DTCLH_SHORTNAMES

!if [nmakehlp -f $(OPTS) "nobt"]
!message *** Disabling Bluetooth
ENABLE_BLUETOOTH = 0
!else
ENABLE_BLUETOOTH = 1
!endif
PRJ_DEFINES = $(PRJ_DEFINES) /DIOCP_ENABLE_BLUETOOTH=$(ENABLE_BLUETOOTH)

!if [nmakehlp -f $(OPTS) "iocptrace"]
!message *** Doing a tracing build
PRJ_OBJS = $(PRJ_OBJS) $(TMP_DIR)\tclWinIocpTrace.obj
PRJ_DEFINES = $(PRJ_DEFINES) /DIOCP_ENABLE_TRACE
!endif

!if [nmakehlp -f $(OPTS) "iocpdebug"]
!message *** Enabling asserts
PRJ_DEFINES = $(PRJ_DEFINES) /DIOCP_ENABLE_ASSERT /DIOCP_DEBUG
!endif

PRJ_LIBS  = ws2_32.lib rpcrt4.lib

"$(WIN_DIR)\tclWinIocp.h" : "$(WIN_DIR)\tclhPointer.h"
$(PRJ_OBJS) : "$(WIN_DIR)\tclWinIocp.h" "$(WIN_DIR)\makefile.vc"

# We do not use the standard predefined install targets because we want
# to load binaries from platform-specific subdirectories of the package
# directory.
DISABLE_TARGET_install = 1
!include "$(_RULESDIR)\targets.vc"

# Override binary installation directory
!if "$(ARCH)" == "AMD64"
BIN_INSTALL_DIR = $(SCRIPT_INSTALL_DIR)\amd64
!else
BIN_INSTALL_DIR = $(SCRIPT_INSTALL_DIR)\x86
!endif

install:  pkgindex default-install-docs-html
	@echo Installing to '$(SCRIPT_INSTALL_DIR)'
	@if not exist "$(SCRIPT_INSTALL_DIR)" mkdir "$(SCRIPT_INSTALL_DIR)"
	@if not exist "$(BIN_INSTALL_DIR)" mkdir "$(BIN_INSTALL_DIR)"
	@$(CPY) $(PRJLIB) "$(BIN_INSTALL_DIR)" >NUL
!if $(ENABLE_BLUETOOTH)
	@$(CPY) $(LIBDIR)\*.tcl "$(SCRIPT_INSTALL_DIR)"
!endif
	@$(CPY) $(OUT_DIR)\pkgIndex.tcl "$(SCRIPT_INSTALL_DIR)"
	@$(CPY) $(ROOT)\LICENSE "$(SCRIPT_INSTALL_DIR)"
pkgindex:
	@nmakehlp -s << $(ROOT)\pkgIndex.tcl.in > $(OUT_DIR)\pkgIndex.tcl
@PACKAGE_VERSION@    $(DOTVERSION)
@PACKAGE_NAME@       $(PRJ_PACKAGE_TCLNAME)
@PACKAGE_TCLNAME@    $(PRJ_PACKAGE_TCLNAME)
@PKG_LIB_FILE@       $(PRJLIBNAME)
@ENABLE_BLUETOOTH@    $(ENABLE_BLUETOOTH)
<<

