RELDIR=WINNT\install\NSIS
!INCLUDE ..\..\..\config\NTMakefile.$(SYS_NAME)
!INCLUDE ..\..\..\config\NTMakefile.version

EXEDIR = $(DESTDIR)\WinInstall\Config
NSISDIR = C:\Program Files\NSIS

# Revise the rule for compiling sources to use static libraries
C2OBJ   = $(cc) /Fo$@ /Fd$*.pdb $(cflags) $(cdebug) $(cvars) $(afscflags) $(afscdefs) /c

LOOPBACK_LIBS = wbemuuid.lib setupapi.lib msi.lib ole32.lib shell32.lib oleaut32.lib user32.lib

$(OUT)\Service.obj: Service.cpp
	   $(C2OBJ) Service.cpp

$(EXEDIR)\Service.exe: $(OUT)\Service.obj
      $(EXECONLINK) $(OUT)\Service.obj
        $(_VC_MANIFEST_EMBED_EXE)

$(OUT)\Killer.obj: Killer.cpp
      $(C2OBJ) Killer.cpp

$(EXEDIR)\Killer.exe: $(OUT)\Killer.obj
      $(EXECONLINK) $(OUT)\Killer.obj
        $(_VC_MANIFEST_EMBED_EXE)

$(OUT)\AdminGroup.obj: AdminGroup.cpp
      $(C2OBJ) AdminGroup.cpp

$(EXEDIR)\AdminGroup.exe: $(OUT)\AdminGroup.obj
      $(EXECONLINK) $(OUT)\AdminGroup.obj
        $(_VC_MANIFEST_EMBED_EXE)

prebuild:
!IF ("$(AFSDEV_BUILDTYPE)" == "FREE")
!IF ("$(AFSVER_CL)"=="1400")
   $(COPY) %SystemRoot%\System32\Msvcr80.dll $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MFC80.DLL $(EXEDIR)
!ELSE IF ("$(AFSVER_CL)"=="1310")
   $(COPY) %SystemRoot%\System32\Msvcr71.dll $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MFC71.DLL $(EXEDIR)
!ELSE IF ("$(AFSVER_CL)"=="1300")
   $(COPY) %SystemRoot%\System32\Msvcp70.dll $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MSVCRT.DLL $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MFC70.DLL $(EXEDIR)
!ELSE IF ("$(AFSVER_CL)"=="1200")
   $(COPY) %SystemRoot%\System32\MSVCRT.DLL $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MFC42.DLL $(EXEDIR)
!ELSE
!ERROR Unknown Compiler Version
!ENDIF
!ELSE # NOT FREE - CHECKED
!IF ("$(AFSVER_CL)"=="1400")
   $(COPY) %SystemRoot%\System32\Msvcr80d.dll $(EXEDIR)
   $(COPY) %SystemRoot%\System32\Msvcr80d.pdb $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MFC80D.DLL $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MFC80D.pdb $(EXEDIR)
!ELSE IF ("$(AFSVER_CL)"=="1310")
   $(COPY) %SystemRoot%\System32\Msvcr71d.dll $(EXEDIR)
   $(COPY) %SystemRoot%\System32\Msvcr71d.pdb $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MFC71D.DLL $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MFC71D.pdb $(EXEDIR)
!ELSE IF ("$(AFSVER_CL)"=="1300")
   $(COPY) %SystemRoot%\System32\Msvcp70d.dll $(EXEDIR)
   $(COPY) %SystemRoot%\System32\Msvcp70d.pdb $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MSVCRTD.DLL $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MSVCRTD.pdb $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MFC70D.DLL $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MFC70D.pdb $(EXEDIR)
!ELSE IF ("$(AFSVER_CL)"=="1200")
   $(COPY) %SystemRoot%\System32\MSVCRTD.DLL $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MSVCRTD.pdb $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MFC42D.DLL $(EXEDIR)
   $(COPY) %SystemRoot%\System32\MFC42D.pdb $(EXEDIR)
!ELSE
!ERROR Unknown Compiler Version
!ENDIF
!ENDIF
   $(DEL) $(OUT)\nsi-includes.nsi
   echo !define AFS_DESTDIR $(DESTDIR) > $(OUT)\nsi-includes.nsi
   echo !define AFS_VERSION $(AFSPRODUCT_VERSION) >> $(OUT)\nsi-includes.nsi
   echo !define AFS_MAJORVERSION $(AFSPRODUCT_VER_MAJOR) >>$(OUT)\nsi-includes.nsi
   echo !define AFS_MINORVERSION $(AFSPRODUCT_VER_MINOR) >>$(OUT)\nsi-includes.nsi
   echo !define AFS_PATCHLEVEL $(AFSPRODUCT_VER_PATCH) >>$(OUT)\nsi-includes.nsi
   $(DESTDIR)\bin\util_cr.exe _echo "!define " >>$(OUT)\nsi-includes.nsi 
   "$(NSISDIR)\makensis.exe" /VERSION >>$(OUT)\nsi-includes.nsi          
   echo. >>$(OUT)\nsi-includes.nsi                                       
!if ("$(AFSVER_CL)" == "1400")
   echo !define CL_1310 1 >> $(OUT)\nsi-includes.nsi
!else if ("$(AFSVER_CL)" == "1310")
   echo !define CL_1310 1 >> $(OUT)\nsi-includes.nsi
!else if ("$(AFSVER_CL)" == "1300")
   echo !define CL_1300 1 >> $(OUT)\nsi-includes.nsi
!endif
!if ("$(AFSIFS)" == "TRUE")
   echo !define AFSIFS 1 >> $(OUT)\nsi-includes.nsi
!endif
!if ("$(AFSDEV_BUILDTYPE)" == "CHECKED")
   echo !define DEBUG 1 >>$(OUT)\nsi-includes.nsi
!endif

build: prebuild
   "C:\Program Files\NSIS\makensis.exe" /DINCLUDEDIR=$(OUT) OpenAFS.nsi

install: $(OUT)\Service.obj $(EXEDIR)\Service.exe $(OUT)\Killer.obj $(EXEDIR)\Killer.exe $(EXEDIR)\AdminGroup.exe build

#clean:
#   $(DEL) $(OUT)\Service.obj
#   $(DEL) $(EXEDIR)\Service.exe
#   $(DEL) $(EXEDIR)\Msvcr71.dll
#   $(DEL) $(EXEDIR)\MFC42.DLL
#   $(DEL) OpenAFSforWindows.exe
#   $(DEL) nsi-include.nsi

