# Copyright 2004, OpenAFS.ORG and others.
# All Rights Reserved.
#
# This software has been released under the terms of the IBM Public
# License.  For details, see the LICENSE file in the top-level source
# directory or online at http://www.openafs.org/dl/license10.html

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

MEDIADIR = $(DESTDIR)\WinInstall
MEDIABINDIR = $(MEDIADIR)\Dll
HEIMREDISTDIR= $(HEIMDALSDKDIR)\redist\$(CPU)

!IFDEF LITECLIENT
LITE=-lite
!ELSE
LITE=
!ENDIF

MSIFILE = $(MEDIADIR)\openafs-$(LANG)$(LITE).msi
!IF ("$(CPU)" == "i386")
BINMSIFILE = $(MEDIADIR)\openafs-32bit-tools-$(LANG)$(LITE).msi
!ENDIF

!IFNDEF MSIDNNLS
!ERROR Please set MSIDNNLS to the directory where Microsoft IDN Mitigation APIs are installed.
# $(MSIDNNLS)\REDIST\idndl.(platform).exe should exist.
!ENDIF

WIXINCLUDES = \
	config.wxi \
	feature.wxi \
	files.wxi \
	language_config.wxi \
	property.wxi \
	registry.wxi \
	lang\$(LANG)\ui.wxi

WIXOBJ = $(OUT)\openafs-$(LANG)$(LITE).wixobj
!IF ("$(CPU)" == "i386")
BINWIXOBJ  = $(OUT)\openafs-32bit-tools-$(LANG)$(LITE).wixobj
!ENDIF
!IFNDEF NOCYGWIN
WIXCYGOPT=-dCygwinArchives
!ELSE
WIXCYGOPT=
!ENDIF

LANGUAGES=en_US de_DE es_ES ja_JP ko_KR pt_BR zh_CN zh_TW

languages:
# Don't bother with non en_US for now.  The other builds comprise of either
# verbatim copies of en_US files, partial translations or doesn't build
# (no languages resources). Someday when OpenAFS 8.1029828419 comes out we'll
# get someone to translate.
#	for %l in ( $(LANGUAGES ) do (
#	$(MAKE) /f NTMakefile /nologo LANG=%l lang
#	)
	$(MAKE) /f NTMakefile /nologo LANG=en_US lang

lang:: lang_clean $(MSIFILE) $(BINMSIFILE)

lang_clean:
	-$(DEL) $(WIXOBJ)
	-$(DEL) $(MSIFILE)
!IF ("$(CPU)" == "i386")
	-$(DEL) $(BINWIXOBJ)
	-$(DEL) $(BINMSIFILE)
!ENDIF

uninst:
        $(CD) uninstall
        $(MAKE) /f NTMakefile /nologo install
        $(CD) ..

customactions:
	$(CD) custom
	$(MAKE) /f NTMakefile /nologo install
	$(CD) ..

install: uninst customactions languages

$(MSIFILE): $(WIXOBJ)
	light -nologo -out $(MSIFILE) \
		-loc lang\$(LANG)\strings.wxl \
		$(WIXOBJ)
	$(CODESIGN_USERLAND)
	dir $(MSIFILE)

$(WIXOBJ): openafs.wxs $(WIXINCLUDES)
	candle -nologo -out $@	\
		"-dCellName=$(CELLNAME_DEFAULT)" \
		-dLanguage=$(LANG) \
		-dNumericVersion=$(AFSPRODUCT_VERSION)	\
		-dVersionMajor=$(AFSPRODUCT_VER_MAJOR)	\
		-dVersionMinor=$(AFSPRODUCT_VER_MINOR)	\
		-dVersionPatch=$(AFSPRODUCT_VER_PATCH)	\
		"-dDestDir=$(DESTDIR)\\" \
		-dCellDbFile=CellServDB \
		"-dIDNMRedistDir=$(MSIDNNLS)\\REDIST" 	\
		"-dKrbCompatRedistDir=$(HEIMREDISTDIR)"	\
!IFDEF LITECLIENT
		-dLiteClient=1 \
!ENDIF
		-v0 \
		-w0 \
		$(WIXCYGOPT) $(AFSDEV_AUXWIXDEFINES)	openafs.wxs

!IF ("$(CPU)" == "i386")
$(BINWIXOBJ): oafwbins.wxs $(WIXINCLUDES)
	candle -nologo -out $@	\
		"-dCellName=$(CELLNAME_DEFAULT)" \
		-dLanguage=$(LANG) \
		-dNumericVersion=$(AFSPRODUCT_VERSION)	\
		-dVersionMajor=$(AFSPRODUCT_VER_MAJOR)	\
		-dVersionMinor=$(AFSPRODUCT_VER_MINOR)	\
		-dVersionPatch=$(AFSPRODUCT_VER_PATCH)	\
		"-dDestDir=$(DESTDIR)\\" \
		-dCellDbFile=CellServDB \
		"-dKrbCompatRedistDir=$(HEIMREDISTDIR)"	\
!IFDEF LITECLIENT
		-dLiteClient=1 \
!ENDIF
		-v0 \
		-w0 \
		-sw1044 \
                $(AFSDEV_AUXWIXDEFINES)	oafwbins.wxs

$(BINMSIFILE): $(BINWIXOBJ)
	light -nologo -out $(BINMSIFILE) \
		-loc lang\en_US\strings.wxl \
		$(BINWIXOBJ)
	$(CODESIGN_USERLAND)
	dir $(BINMSIFILE)
!ENDIF

# Pseudotarget for building lite installer.
!IFNDEF LITECLIENT
lite:
	$(MAKE) /f NTMakefile /nologo install LITECLIENT=1
!ENDIF

# Cleanup
clean::
	for %l in ( $(LANGUAGES) ) do \
		$(MAKE) /f NTMakefile /nologo LANG=%l lang_clean
	$(CD) custom
	$(MAKE) /f NTMakefile /nologo clean
	$(CD) ..
	$(CD) uninstall
	$(MAKE) /f NTMakefile /nologo clean
	$(CD) ..



