# makefile
#
# for IIRF,  Iconic's Isapi Rewriting Filter.
#
#
#  Copyright (c) Microsoft Corporation, 2005, 2006, 2007.  All rights reserved.
#
# This file is released under the License for IIRF.  See the License.txt file 
# for full details. 
#


## Instructions: 
## To use this makefile you may have to change some of the macro definitions, below:

## Set VC8 to the location of Visual-C++ v8. Under $(VC)\bin we should find the cl.exe compiler.
## You can get this with Visual studio 2005, or with Visual-C++ 2005 Express.  
## The default install path is often something like 
##         C:\Program Files\Microsoft Visual Studio 8\VC
## whether you have full Visual Studio install, or an install of
## the Express version.

VC=c:\vc8

## Set PSDK to point to the Windows Platform SDK, the latest version.  The one I use currently is the 
## Windows Server 2003 R2 Platform SDK, available for download at:  
##  http://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB
## But you can also use the Microsoft Windows Vista SDK, v6.0. 
## (NB:  I haven't tested  binaries produced against the Windows Vista Platform SDK, running on
## Windows Server). 
## The Platform SDK is required for header files and libraries for the binaries.  
## The install location is often $(VC)\PlatformSDK, but not always.  
##

#PSDK=$(VC)\PlatformSDK
PSDK=C:\Progra~1\MI2578~1\Windows\v6.0

## Set CC to the Cl.exe compiler, and set LINK to refer to the linker.  
## This is almost always going to be, $(VC)\bin\cl.exe and $(VC)\bin\link.exe

CC=$(VC)\bin\cl.exe
LINK=$(VC)\bin\link.exe


## Set PCRESOURCE to the directory that contains the source
## distribution of PCRE, if you have one. Note: IIRF is built
## against v5.0 of PCRE.  You do not need a source distribution
## of PCRE in order to build IIRF.  All you really need is a
## binary distribution of PCRE: the pcre.h file and the pcre.lib
## static library, which is included in the IIRF distribution.  

#PCRESOURCE=c:\dinoch\dev\pcre\pcre-5.0
PCRE=..\3rdParty

## You can set this directory if you want the "install" make target to work.
## Otherwise, ignore it.  If you set this and you run "make install" then it will
## copy the IsapiRewrite4.dll and the ini file into the install directory.
## Handle with care, it can overwrite your ini files!

INSTALL_DIR=c:\Windows\system32\inetsrv

## ZIPIT refers to a directory zipping utility that is not included in the IIRF.  Ignore this setting. 

ZIPIT=c:\users\dinoch\bin\backdir.bat

## Version refers to the version of IIRF.  This version string defined here is used only in 
## the names of the zip files created by the ZIPIT tool, therefore you do not need to set it
## if you do not have that tool. 

Version=IonicIsapiRewriter-1.2.14


## set the compiler optimization flag.   

Optimize=/Od  /DEBUG 
#Optimize=/O2
#Optimize=/O2 /Ob1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_VC80_UPGRADE=0x0600" /D "_WINDLL" /GF /EHsc /MT /Gy /W3


# =======================================================

all: TestDriver.exe TestParse.exe IsapiRewrite4.dll IirfVersion.exe

IsapiRewrite4.dll: IsapiRewrite4.c RewriteRule.h IirfConfig.h IirfConstants.h IirfRequestContext.h  makefile $(PCRE)\pcre.h $(PCRE)\pcre.lib makefile $(PCRE)\pcre.lib 
	$(CC) /Zi $(Optimize)  -I$(VC)\Include -I$(PSDK)\Include  -I$(PCRE)  -DPCRE_STATIC  -LDd IsapiRewrite4.c  $(PSDK)\Lib\kernel32.lib  $(PCRE)\pcre.lib   -FeIsapiRewrite4.dll  -link /VERBOSE:LIB /LIBPATH:$(VC)\Lib /LIBPATH:$(PSDK)\Lib    /SUBSYSTEM:CONSOLE /EXPORT:GetFilterVersion /EXPORT:GetIirfVersion /EXPORT:HttpFilterProc /EXPORT:IsapiFilterTestSetup /EXPORT:TerminateFilter /EXPORT:ApplyRules /NODEFAULTLIB:libc  /NODEFAULTLIB:libcmt.lib


TestDriver.exe: TestDriver.c RewriteRule.h IsapiRewrite4.dll makefile
	$(CC) /c /Zi $(Optimize) -I$(VC)\Include -I$(PSDK)\Include -I$(PCRE) TestDriver.c 
	$(LINK) /DEBUG TestDriver.obj IsapiRewrite4.lib $(PCRE)\pcre.lib  /LIBPATH:$(VC)\Lib /LIBPATH:$(PSDK)\Lib   /SUBSYSTEM:CONSOLE  

IirfVersion.exe: IirfVersion.c RewriteRule.h IsapiRewrite4.dll makefile
	$(CC) /c /Zi $(Optimize) -I$(VC)\Include -I$(PSDK)\Include -I$(PCRE) IirfVersion.c 
	$(LINK) /DEBUG IirfVersion.obj IsapiRewrite4.lib $(PCRE)\pcre.lib  /LIBPATH:$(VC)\Lib /LIBPATH:$(PSDK)\Lib   /SUBSYSTEM:CONSOLE  

TestParse.exe: TestParse.c IirfConfig.h IsapiRewrite4.dll makefile
	$(CC) /c /Zi $(Optimize) -I$(VC)\Include -I$(PSDK)\Include -I$(PCRE) TestParse.c 
	$(LINK) /DEBUG TestParse.obj  IsapiRewrite4.lib $(PCRE)\pcre.lib  /LIBPATH:$(VC)\Lib /LIBPATH:$(PSDK)\Lib   /SUBSYSTEM:CONSOLE  



install: $(INSTALL_DIR)\IsapiRewrite4.dll $(INSTALL_DIR)\IsapiRewrite4.ini

rebuild: IsapiRewrite4.dll
	net stop w3svc
	copy /y  IsapiRewrite4.dll $(INSTALL_DIR)
	net start w3svc

$(INSTALL_DIR)\IsapiRewrite4.dll: IsapiRewrite4.dll
	copy /y  IsapiRewrite4.dll $(INSTALL_DIR)

$(INSTALL_DIR)\IsapiRewrite4.ini: IsapiRewrite4.ini
	copy /y  IsapiRewrite4.ini $(INSTALL_DIR)\IsapiRewrite4.ini


# $(PCRE)\pcre.h $(PCRE)\pcre.lib: 
# 	-mkdir $(PCRE)
# 	copy $(PCRESOURCE)\pcre.h $(PCRE)
# 	copy $(PCRESOURCE)\pcre.lib $(PCRE)
# 	copy $(PCRESOURCE)\Makefile $(PCRE)
# 	copy $(PCRESOURCE)\LICENCE $(PCRE)


# Rule for creating ZIP files.
# Note: this will not work for you if you do not have the ZIPIT
# tool

zip: srczip binzip

srczip: $(Version)-src.zip 

$(Version)-src.zip: IsapiRewrite4.dll ..\Readme-1.2.txt ..\ReleaseNotes.txt makefile TestDriver.exe ..\License.IIRF.txt IirfVersion.exe
	-rd /s /q $(Version)
	mkdir $(Version)
	copy ..\Readme-1.2.txt $(Version)
	copy ..\ReleaseNotes.txt $(Version)
	copy ..\License.IIRF.txt $(Version)
	mkdir $(Version)\Source
	copy makefile $(Version)\Source
	copy TestParse.c $(Version)\Source
	copy TestDriver.c $(Version)\Source
	copy TestDriver.exe $(Version)\Source
	copy IirfVersion.c $(Version)\Source
	copy IirfConstants.h $(Version)\Source
	copy IirfRequestContext.h $(Version)\Source
	copy IirfConfig.h $(Version)\Source
	copy RewriteRule.h $(Version)\Source
	copy IsapiRewrite4.c $(Version)\Source
	mkdir $(Version)\3rdParty
	copy $(PCRE)\License.PCRE.txt $(Version)\License.PCRE.txt
	xcopy /s $(PCRE) $(Version)\3rdParty
	mkdir $(Version)\Source\tests
	xcopy /s tests $(Version)\Source\tests
	mkdir $(Version)\ExampleIni
	xcopy /s ..\ExampleIni $(Version)\ExampleIni

	$(ZIPIT) $(Version) $(Version)-src.zip 
	rd /s /q $(Version)


$(Version)-debug.zip: IsapiRewrite4.dll Readme-1.2.txt ReleaseNotes.txt makefile TestDriver.exe SampleUrls.txt License.txt IirfVersion.exe
	-rd /s /q $(Version)
	mkdir $(Version)
	mkdir $(Version)\tests
	xcopy /s tests $(Version)\tests
	mkdir $(Version)\examples
	xcopy /s examples $(Version)\examples
	copy makefile $(Version)
	copy Readme-1.2.txt $(Version)
	copy ReleaseNotes.txt $(Version)
	copy License.txt $(Version)
	copy TestDriver.c $(Version)
	copy TestDriver.pdb $(Version)
	copy TestDriver.exe $(Version)
	copy IirfConstants.h $(Version)
	copy IirfRequestContext.h $(Version)
	copy IirfConfig.h $(Version)
	copy RewriteRule.h $(Version)
	copy SampleUrls.txt $(Version)
	copy IsapiRewrite4.ini $(Version)
	copy IsapiRewrite4.pdb $(Version)
	copy IsapiRewrite4.dll $(Version)
	copy IsapiRewrite4.c $(Version)
	mkdir $(Version)\pcre
	copy $(PCRE)\License.PCRE.txt $(Version)\License.PCRE.txt
	xcopy /s $(PCRE) $(Version)\pcre

	$(ZIPIT) $(Version) $(Version)-debug.zip 
	rd /s /q $(Version)


binzip: $(Version)-bin.zip

$(Version)-bin.zip: IsapiRewrite4.dll IsapiRewrite4.pdb ..\Readme-1.2.txt ..\ReleaseNotes.txt TestDriver.exe TestParse.exe ..\License.IIRF.txt IirfVersion.exe 
	-rd /s /q $(Version)
	mkdir $(Version)
	mkdir $(Version)\lib
	copy IsapiRewrite4.dll $(Version)\lib
	copy IsapiRewrite4.pdb $(Version)\lib
	mkdir $(Version)\bin
	copy TestDriver.exe $(Version)\bin
	copy TestParse.exe $(Version)\bin
	copy IirfVersion.exe $(Version)\bin
	mkdir $(Version)\tests
	xcopy /s tests $(Version)\tests
	mkdir $(Version)\ExampleIni
	xcopy /s ..\ExampleIni $(Version)\ExampleIni
	copy ..\Readme-1.2.txt $(Version)
	copy ..\ReleaseNotes.txt $(Version)
	copy ..\License.IIRF.txt $(Version)
	copy $(PCRE)\License.PCRE.txt $(Version)

	$(ZIPIT) $(Version) $(Version)-bin.zip
	rd /s /q $(Version)



clean: 
	-del IsapiRewrite4.dll
	-del IonicIsapiRewriter.zip 
	-del IsapiRewrite4.obj
	-del IsapiRewrite4.pdb
	-del IsapiRewrite4.lib
	-del IsapiRewrite4.exp
	-del IsapiRewrite4.ilk
	-del IirfVersion.exe
	-del IirfVersion.obj
	-del IirfVersion.ilk
	-del IirfVersion.pdb
	-del TestDriver.exe
	-del TestDriver.obj
	-del TestDriver.ilk
	-del TestDriver.pdb
	-del TestParse.exe
	-del TestParse.obj
	-del TestParse.ilk
	-del TestParse.pdb
	-del vc80.pdb
