# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#   Adam Lock <adamlock@netscape.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****

###############################################################################
# CUSTOMISE SETTINGS IN THIS SECTION AS APPROPRIATE FOR YOUR BUILD SYSTEM!

DEPTH           = ../../../../..
topsrcdir       = @top_srcdir@
srcdir          = @srcdir@
VPATH           = @srcdir@

include $(DEPTH)/config/autoconf.mk

MODULE          = npmozax
LIBRARY_NAME    = npmozax

ifdef WINCE
MOZ_FLASH_ACTIVEX_PATCH = 1
endif

ifdef MOZ_FLASH_ACTIVEX_PATCH
RESFILE         = MozActiveX-flash.res
else
RESFILE         = MozActiveX.res
endif

DEFFILE         = npmozax.def
GRE_MODULE	= 1


XPIFILE         = mozactivex.xpi

FORCE_SHARED_LIB = 1
NO_DIST_INSTALL	= 1
NO_INSTALL = 1

# Path to the Mozilla ActiveX common dir (some files are copied from there)
AXCOMMONSRC=$(srcdir)/../common

############
# XPConnect settings

MOZ_ACTIVEX_PLUGIN_XPCONNECT = 1

# XPConnect support in (Netscape 6.1+/Mozilla)

# Uncomment this line to install the plugin & policy
MOZ_USE_ACTIVEX_PLUGIN = 1

# Settings will also be read from this supplemental file if it exists
-include $(srcdir)/plugin.mk

###############################################################################

ifdef MOZ_ACTIVEX_PLUGIN_XPCONNECT
XPIDLSRCS = \
    ./nsIMozAxPlugin.idl \
    $(NULL)
endif

GARBAGE	+= $(DEFFILE)

CPPSRCS = \
    StdAfx.cpp             \
    LegacyPlugin.cpp       \
    MozActiveX.cpp         \
    npwin.cpp              \
    $(NULL)

ifdef MOZ_ACTIVEX_PLUGIN_XPCONNECT
CPPSRCS += XPConnect.cpp XPCDocument.cpp XPCBrowser.cpp
endif

ifdef MOZ_ACTIVEX_PLUGIN_LIVECONNECT
_AXCOMMON_CPPSRCS = \
    ActiveScriptSite.cpp \
    ControlEventSink.cpp \
    ControlSite.cpp \
    ControlSiteIPFrame.cpp \
    ItemContainer.cpp \
    PropertyBag.cpp \
    $(NULL)
CPPSRCS += $(_AXCOMMON_CPPSRCS)
CSRCS += javastubs.c
endif

ifdef XPC_IDISPATCH_SUPPORT
CPPSRCS += PrefObserver.cpp
endif

LOCAL_INCLUDES = -I$(srcdir) -I$(AXCOMMONSRC)

ifdef MOZ_ACTIVEX_PLUGIN_LIVECONNECT
LOCAL_INCLUDES += -I./_java
endif

ifdef MOZ_ACTIVEX_PLUGIN_XPCONNECT
LOCAL_INCLUDES += -I$(XPIDL_GEN_DIR)
endif

ifdef WINCE
OS_LIBS += \
	coredll.lib \
	ole32.lib \
	oleaut32.lib \
	uuid.lib \
	ceshell.lib \
	corelibc.lib \
	atls.lib \
	atlce400.lib \
	urlmon.lib \
	libcmt.lib \
	comsuppw.lib \
	$(NULL)
else
OS_LIBS += \
    comdlg32.lib                   \
    ole32.lib                      \
    oleaut32.lib                   \
    uuid.lib                       \
    shell32.lib                    \
    $(NULL)
endif

ifdef MOZ_ACTIVEX_PLUGIN_LIVECONNECT
DEFINES += -DMOZ_ACTIVEX_PLUGIN_LIVECONNECT -DXPCOM_GLUE
endif

ifdef MOZ_ACTIVEX_PLUGIN_XPCONNECT
DEFINES += -DMOZ_ACTIVEX_PLUGIN_XPCONNECT
endif

ifdef XPC_IDISPATCH_SUPPORT
DEFINES += -DXPC_IDISPATCH_SUPPORT
endif

ifdef MOZ_FLASH_ACTIVEX_PATCH
DEFINES += -DMOZ_FLASH_ACTIVEX_PATCH
endif

EXTRA_DSO_LDOPTS = \
    $(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
    $(MOZ_COMPONENT_LIBS) \
    $(NSPR_LIBS) \
    $(NULL)

LIBS = \
    $(NSPR_LIBS) \
    $(NULL)

# XPConnect links to XPCOM and the shared activex lib
ifdef XPC_IDISPATCH_SUPPORT
EXTRA_DSO_LDOPTS += \
    ../common/$(LIB_PREFIX)ax_common_s.$(LIB_SUFFIX) \
    $(MOZ_JS_LIBS) \
    $(XPCOM_LIBS) \
    $(NULL)
endif

SRCS_IN_OBJDIR	= 1

ENABLE_CXX_EXCEPTIONS = 1

include $(topsrcdir)/config/rules.mk

ifdef MOZ_ACTIVEX_PLUGIN_LIVCONNECT
copy-sources: $(addprefix $(MOZCTLSRC)/,$(_CONTROL_CPPSRCS))
	$(INSTALL) $^ .

export:: copy-sources
endif

install-plugin: $(SHARED_LIBRARY)
ifdef SHARED_LIBRARY
	$(INSTALL) $< $(DIST)/bin/plugins
endif

install-class: MozAxPlugin.class
	$(INSTALL) $< $(DIST)/bin/plugins

install-typelib: $(XPIDL_GEN_DIR)/nsIMozAxPlugin.xpt
	$(INSTALL) $< $(DIST)/bin/plugins

install-securitypolicy: nsAxSecurityPolicy.js
	$(INSTALL) $< $(DIST)/bin/components

install-prefs: activex.js $(FLASHLITE_PREFS_JS)
	$(INSTALL) $^ $(DIST)/bin/defaults/pref

ifdef MOZ_USE_ACTIVEX_PLUGIN
libs:: install-plugin install-prefs

ifdef MOZ_ACTIVEX_PLUGIN_LIVECONNECT
libs:: install-class
endif

ifdef MOZ_ACTIVEX_PLUGIN_XPCONNECT
libs:: install-typelib
endif

ifdef XPC_IDISPATCH_SUPPORT
libs:: install-securitypolicy
endif
endif

## Note: Ensure you create the redist dir containing the correct runtime dlls

xpi:: install.js $(SHARED_LIBRARY)
	$(ZIP) -9 -j $(DIST)/bin/$(XPIFILE) $<
	$(ZIP) -9 -j $(DIST)/bin/$(XPIFILE) $(SHARED_LIBRARY)
	$(ZIP) -9 -j $(DIST)/bin/$(XPIFILE) $(topsrcdir)/../redist/microsoft/system/msvcrt.dll
	$(ZIP) -9 -j $(DIST)/bin/$(XPIFILE) $(topsrcdir)/../redist/microsoft/system/msvcp60.dll
ifdef MOZ_ACTIVEX_PLUGIN_LIVECONNECT
	$(ZIP) -9 -j $(DIST)/bin/$(XPIFILE) MozAxPlugin.class
endif
ifdef MOZ_ACTIVEX_PLUGIN_XPCONNECT
	$(ZIP) -9 -j $(DIST)/bin/$(XPIFILE) $(XPIDL_GEN_DIR)/nsIMozAxPlugin.xpt
endif
ifdef XPC_IDISPATCH_SUPPORT
	$(ZIP) -9 -j $(DIST)/bin/$(XPIFILE) activex.js
	$(ZIP) -9 -j $(DIST)/bin/$(XPIFILE) nsAxSecurityPolicy.js
endif

$(SHARED_LIBRARY) : $(DEFFILE)

$(DEFFILE):
	-rm -f $@
	@echo "; npmozax.def : Declares the module parameters." >> $@
	@echo "; This file was autogenerated by mkctldef.bat!" >> $@
	@echo "" >> $@
	@echo "LIBRARY      "npmozax.DLL"" >> $@
	@echo "EXPORTS" >> $@
	@echo "; Plugin exports" >> $@
	@echo "NP_GetEntryPoints   @1" >> $@
	@echo "NP_Initialize       @2" >> $@
	@echo "NP_Shutdown         @3" >> $@
