# ***** 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
RESFILE         = MozActiveX.res
DEFFILE         = npmozax.def
GRE_MODULE	= 1

REQUIRES = \
    xpcom \
    java \
    plugin \
    string \
    dom \
    content \
    layout \
    widget \
    gfx \
    js \
    pref \
    xpconnect \
    docshell \
    webshell \
    necko \
    windowwatcher \
    ax_common \
    $(NULL)

ifdef XPC_IDISPATCH_SUPPORT
REQUIRES += \
	caps \
	string \
	$(NULL)
endif
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

############
# LiveConnect settings

# MOZ_ACTIVEX_PLUGIN_LIVECONNECT = 1

# Settings that specify where the PluginSDK, Java compiler (javac or oldjavac),
# Java header file generator (javah) and classes live.
#
# You need the Netscape PluginSDK:
#
#   http://home.netscape.com/comprod/development_partners/plugin_api/index.html
#
# You also need a JDK with the old java compiler. Anything from 1.3
# downwards should do. See here for various JDK releases:
#
#   http://java.sun.com/products/archive/index.html
#
# You should use the javah found in the plugin SDK because this generates
# the JRI stubs.

ifdef MOZ_ACTIVEX_PLUGIN_LIVECONNECT
PLUGINSDK = c:/m/PluginSDK
SDK_JAVADIR = c:/jdk1.02
SDK_JAVAH = $(PLUGINSDK)/bin/win32/javah
SDK_JAVAC = $(SDK_JAVADIR)/bin/javac
SDK_CLASSES = $(PLUGINSDK)/classes/java_30.zip
SDK_CLASSPATH = "$(subst /,\,$(SDK_CLASSES));."
endif

############
# 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 += LiveConnect.cpp $(_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

OS_LIBS += \
    comdlg32.lib                   \
    ole32.lib                      \
    oleaut32.lib                   \
    uuid.lib                       \
    shell32.lib                    \
    $(NULL)

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

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

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

# LiveConnect links to XPCOM glue
ifdef MOZ_ACTIVEX_PLUGIN_LIVECONNECT
EXTRA_DSO_LDOPTS += \
    $(DIST)/lib/$(LIB_PREFIX)string_s.$(LIB_SUFFIX) \
    $(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX)
LIBS += \
    $(DIST)/lib/$(LIB_PREFIX)string_s.$(LIB_SUFFIX) \
    $(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX)
endif

# 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
	$(INSTALL) $< $(DIST)/bin/defaults/pref

ifdef MOZ_USE_ACTIVEX_PLUGIN
PACKAGE_FILE = axplugin.pkg
PACKAGE_VARS += \
	MOZ_ACTIVEX_PLUGIN_LIVECONNECT \
	MOZ_ACTIVEX_PLUGIN_XPCONNECT \
	XPC_IDISPATCH_SUPPORT \
	$(NULL)

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" >> $@

ifdef MOZ_ACTIVEX_PLUGIN_LIVECONNECT
./MozAxPlugin.class: ./MozAxPlugin.java
	$(SDK_JAVAC) -classpath $(SDK_CLASSPATH) MozAxPlugin.java

./_java/MozAxPlugin.h \
./_java/MozAxPlugin.c: ./MozAxPlugin.class
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java MozAxPlugin
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java MozAxPlugin

./_java/java_lang_Object.h \
./_java/java_lang_Object.c : $(SDK_CLASSES)
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java java.lang.Object
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java java.lang.Object

./_java/java_lang_Error.h \
./_java/java_lang_Error.c : $(SDK_CLASSES)
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java java.lang.Error
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java java.lang.Error

./_java/java_lang_Throwable.h \
./_java/java_lang_Throwable.c : $(SDK_CLASSES)
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java java.lang.Throwable
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java java.lang.Throwable

./_java/java_lang_String.h \
./_java/java_lang_String.c : $(SDK_CLASSES)
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java java.lang.String
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java java.lang.String

./_java/java_lang_Boolean.h \
./_java/java_lang_Boolean.c : $(SDK_CLASSES)
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java java.lang.Boolean
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java java.lang.Boolean

./_java/java_lang_Number.h \
./_java/java_lang_Number.c : $(SDK_CLASSES)
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java java.lang.Number
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java java.lang.Number

./_java/java_lang_Integer.h \
./_java/java_lang_Integer.c : $(SDK_CLASSES)
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java java.lang.Integer
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java java.lang.Integer

./_java/java_lang_Short.h \
./_java/java_lang_Short.c : $(SDK_CLASSES)
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java java.lang.Short
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java java.lang.Short

./_java/java_lang_Long.h \
./_java/java_lang_Long.c : $(SDK_CLASSES)
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java java.lang.Long
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java java.lang.Long

./_java/java_lang_Double.h \
./_java/java_lang_Double.c : $(SDK_CLASSES)
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java java.lang.Double
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java java.lang.Double

./_java/java_lang_Float.h \
./_java/java_lang_Float.c : $(SDK_CLASSES)
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java java.lang.Float
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java java.lang.Float

./_java/java_lang_Byte.h \
./_java/java_lang_Byte.c : $(SDK_CLASSES)
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java java.lang.Byte
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java java.lang.Byte

./_java/java_lang_Character.h \
./_java/java_lang_Character.c : $(SDK_CLASSES)
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java java.lang.Character
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java java.lang.Character

./_java/netscape_plugin_Plugin.h \
./_java/netscape_plugin_Plugin.c : $(SDK_CLASSES)
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -d _java netscape.plugin.Plugin
	$(SDK_JAVAH) -classpath $(SDK_CLASSPATH) -jri -stubs -d _java netscape.plugin.Plugin

javastubs.c : \
    ./MozAxPlugin.class             \
    ./_java/MozAxPlugin.c \
    ./_java/netscape_plugin_Plugin.c \
    ./_java/java_lang_Object.c     \
    ./_java/java_lang_Throwable.c  \
    ./_java/java_lang_Error.c      \
    ./_java/java_lang_String.c     \
    ./_java/java_lang_Boolean.c    \
    ./_java/java_lang_Number.c     \
    ./_java/java_lang_Integer.c    \
    ./_java/java_lang_Long.c       \
    ./_java/java_lang_Double.c     \
    ./_java/java_lang_Float.c      \
    ./_java/java_lang_Character.c  \
    $(NULL)

LiveConnect.cpp: StdAfx.h \
    ./MozAxPlugin.class             \
    ./_java/MozAxPlugin.h \
    ./_java/netscape_plugin_Plugin.h \
    ./_java/java_lang_Object.h       \
    ./_java/java_lang_Throwable.h    \
    ./_java/java_lang_Error.h        \
    ./_java/java_lang_String.h       \
    ./_java/java_lang_Boolean.h      \
    ./_java/java_lang_Number.h       \
    ./_java/java_lang_Integer.h      \
    ./_java/java_lang_Long.h         \
    ./_java/java_lang_Double.h       \
    ./_java/java_lang_Float.h        \
    ./_java/java_lang_Character.h    \
    $(NULL)
endif

