# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

include $(MOZILLA_SRCDIR)/toolkit/mozapps/installer/package-name.mk

CONFIG_DIR = instgen
SFX_MODULE = $(topsrcdir)/other-licenses/7zstub/binoc/7zSD.sfx

INSTALLER_FILES = \
	app.tag \
	nsis/installer.nsi \
	nsis/uninstaller.nsi \
	nsis/shared.nsh \
	$(NULL)

BRANDING_FILES = \
	branding.nsi \
	wizHeader.bmp \
	wizHeaderRTL.bmp \
	wizWatermark.bmp \
	$(NULL)

ifdef MOZ_UPDATER
DEFINES += -DMOZ_UPDATER=1
endif

include $(topsrcdir)/config/config.mk

OVERRIDE_DEFAULT_GOAL := installer
installer::
	$(MAKE) -C .. installer-stage
	$(MAKE) $(CONFIG_DIR)/setup.exe

# For building the uninstaller during the application build so it can be
# included for mar file generation.
uninstaller::
	$(RM) -r $(CONFIG_DIR) && mkdir $(CONFIG_DIR)
	$(INSTALL) $(addprefix $(srcdir)/,$(INSTALLER_FILES)) $(CONFIG_DIR)
	$(INSTALL) $(addprefix $(DIST)/branding/,$(BRANDING_FILES)) $(CONFIG_DIR)
	$(call py_action,preprocessor,-Fsubstitution $(DEFINES) $(ACDEFINES) \
	  $(srcdir)/nsis/defines.nsi.in -o $(CONFIG_DIR)/defines.nsi)
	$(PYTHON) $(MOZILLA_SRCDIR)/toolkit/mozapps/installer/windows/nsis/preprocess-locale.py \
	  --preprocess-locale $(MOZILLA_SRCDIR) \
	  $(topsrcdir)/navigator/installer/windows/locale $(AB_CD) $(CONFIG_DIR)

$(CONFIG_DIR)/setup.exe::
	$(RM) -r $(CONFIG_DIR) && mkdir $(CONFIG_DIR)
	$(INSTALL) $(addprefix $(srcdir)/,$(INSTALLER_FILES)) $(CONFIG_DIR)
	$(INSTALL) $(addprefix $(DIST)/branding/,$(BRANDING_FILES)) $(CONFIG_DIR)

	$(PYTHON) $(MOZILLA_SRCDIR)/toolkit/mozapps/installer/windows/nsis/preprocess-locale.py \
	  --convert-utf8-utf16le $(DIST)/branding/license.txt $(CONFIG_DIR)/license.txt

	$(call py_action,preprocessor,-Fsubstitution $(DEFINES) $(ACDEFINES) \
	  $(srcdir)/nsis/defines.nsi.in -o $(CONFIG_DIR)/defines.nsi)

	$(PYTHON) $(MOZILLA_SRCDIR)/toolkit/mozapps/installer/windows/nsis/preprocess-locale.py \
	  --preprocess-locale $(MOZILLA_SRCDIR) \
	  $(topsrcdir)/navigator/installer/windows/locale $(AB_CD) $(CONFIG_DIR)

include $(topsrcdir)/config/rules.mk
include $(MOZILLA_SRCDIR)/toolkit/mozapps/installer/windows/nsis/makensis.mk
