#------------------------------------------------------------- -*- makefile -*-
#
# Makefile for TCL UDP Extension
#
# Basic build, test and install
#   nmake /f makefile.vc INSTALLDIR=c:\path\to\tcl TCLDIR=c:\path\to\tcl\sources
#   nmake /f makefile.vc INSTALLDIR=c:\path\to\tcl TCLDIR=c:\path\to\tcl\sources test
#   nmake /f makefile.vc INSTALLDIR=c:\path\to\tcl TCLDIR=c:\path\to\tcl\sources 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 specific information
#-------------------------------------------------------------------------

# The name of the package
PROJECT = udp

!include "rules-ext.vc"


# Define the object files and resource file that make up the extension.
# Note the resource file does not makes sense if doing a static library build
# hence it is under that condition. TMP_DIR is the output directory
# defined by rules for object files.
PRJ_OBJS = $(TMP_DIR)\udp_tcl.obj

# Define any additional project include flags
PRJ_INCLUDES = -I"$(TMP_DIR)"

# Define any additional compiler flags that might be required for the project
PRJ_DEFINES = -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS -D_WIN32

# Define any additional project needed libraries
PRJ_LIBS = WS2_32.Lib Iphlpapi.Lib

# Define the standard targets which calls rules.vc
!include "targets.vc"

.SUFFIXES: .c .obj .res .man

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

# Implicit rule to generate html from man files
# NOTE: this requires doctools from tcllib hence it is not intended
# to be run during install. Rather, use it to generate a new version
# of HTML docs to be stored in the repository.
DTPLITE = "$(_INSTALLDIR)\..\bin\dtplite.tcl"

make-docs-html:
!IF EXIST($(DTPLITE))
	"$(TCLSH_NATIVE)" "$(DTPLITE)" -o "$(ROOT)\doc\$(PROJECT).html" html "$(ROOT)\doc\$(PROJECT).man"
!ENDIF

make-docs-n:
!IF EXIST($(DTPLITE))
	"$(TCLSH_NATIVE)" "$(DTPLITE)" -o "$(ROOT)\doc\$(PROJECT).n" nroff "$(ROOT)\doc\$(PROJECT).man"
!ENDIF

make-docs:
!IF EXIST($(DTPLITE))
	"$(TCLSH_NATIVE)" "$(DTPLITE)" -o "$DOCDIR" html "$(ROOT)\doc"
	"$(TCLSH_NATIVE)" "$(DTPLITE)" -o "$DOCDIR" nroff "$(ROOT)\doc"
!ENDIF

docs: make-docs-n make-docs-html

all: setup default-target

clean: default-clean

realclean: default-hose

# Explicit dependency rules
$(GENERICDIR)\udp_tcl.c: $(TMP_DIR)\udpUuid.h

# We must define a pkgindex target that will create a pkgIndex.tcl
# file in the $(OUT_DIR) directory. We can just redirect to the
# default-pkgindex target for our sample extension.
pkgindex: default-pkgindex-tea

# Use manifest file which defines fossil/git commit id for build-info command
$(TMP_DIR)\manifest.uuid:
!IF EXIST($(ROOT)\manifest.uuid)
	@copy "$(ROOT)\manifest.uuid" "$(TMP_DIR)\manifest.uuid"
!ELSE
!IF EXIST($(ROOT)\.git)
	@copy "$(WIN_DIR)\gitmanifest.in" "$(TMP_DIR)\manifest.uuid"
	@git rev-parse HEAD >>$(TMP_DIR)\manifest.uuid || echo unknown >>$(TMP_DIR)\manifest.uuid
!ELSE
	@echo unknown >$(TMP_DIR)\manifest.uuid
!ENDIF
!ENDIF

$(TMP_DIR)\udpUuid.h:	$(TMP_DIR)\manifest.uuid
	@copy $(WIN_DIR)\udpUuid.h.in+$(TMP_DIR)\manifest.uuid $(TMP_DIR)\udpUuid.h
	@echo: >>$(TMP_DIR)\udpUuid.h


# The default install target only installs binaries and scripts so add
# an additional target for our documentation. Note this *adds* a target
# since no commands are listed after it. The original targets for
# install (from targets.vc) will remain.
install: pkgindex default-install default-install-docs-html default-install-demos

# Test package
test: default-test

