#
#   
#
# Copyright  1990-2006 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version
# 2 only, as published by the Free Software Foundation. 
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License version 2 for more details (a copy is
# included at /legal/license.txt). 
# 
# You should have received a copy of the GNU General Public License
# version 2 along with this work; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA 
# 
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
# Clara, CA 95054 or visit www.sun.com if you need additional
# information or have any questions. 
#
######################################################################
#
# Module's Component Configuration file
#
# Remember: It is up to the module itself to impose rules of
# how to compile the options. All the global Makefile needs
# is the final def. of Java and native file lists and some
# other def. (like VPATH)
#
######################################################################


# Adds to global SUBSYSTEMS list
#
SUBSYSTEM_JSR_120 = jsr120

# Project speficic definitions
ifndef PROJECT_JSR_120_DIR
PROJECT_JSR_120_DIR=$(JSR_120_DIR)
endif

# Javadoc source path
JSR_120_SOURCEPATH = $(JSR_120_DIR)/src/core/common/classes$(PATHSEP)$(JSR_120_DIR)/src/protocol/cbs/classes$(PATHSEP)$(JSR_120_DIR)/src/protocol/sms/classes

JSR_120_PACKAGES = \
    com.sun.midp.io.j2me.cbs \
    com.sun.midp.io.j2me.sms \
    com.sun.midp.wma         \
    javax.wireless.messaging 

EXTRA_CFLAGS += -DENABLE_JSR_120=1
JPP_DEFS     += -DENABLE_JSR_120

JAVADOC_ALL_SOURCEPATH += $(JSR_120_SOURCEPATH)
JAVADOC_ALL_PACKAGES +=  $(JSR_120_PACKAGES)

ifneq ($(USE_JSR_205), true)
# Do not include JSR120 group if jsr205 is included - it includes both sets of files
#
GROUP_DOC_ALL += \
        -group "JSR120 Wireless Messaging API 1.1" \
	$(shell echo $(JSR_120_PACKAGES) | tr ' ' $(PATHSEP))
endif

SUBSYSTEMS += $(SUBSYSTEM_JSR_120)
SUBSYSTEM_PROTOCOL_MODULES += sms cbs

# Jpp files that need pre-processing
#
$(GENERATED_DIR)/classes/javax/wireless/messaging/MessageConnection.java: \
        $(JSR_120_DIR)/src/core/common/classes/javax/wireless/messaging/MessageConnection.jpp
	@$(call runjpp,$^,$@)

$(GENERATED_DIR)/classes/com/sun/wma/TCKTest.java: \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/wma/TCKTest.jpp
	@$(call runjpp,$^,$@)

$(GENERATED_DIR)/classes/com/sun/tck/wma/MessageConnector.java: \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/MessageConnector.jpp
	@$(call runjpp,$^,$@)

# Java files for the ( jsr_120 ) module
#
MODULE_JSR_120_COMMON_JAVA_FILES = \
    $(JSR_120_DIR)/src/core/common/classes/javax/wireless/messaging/MessageListener.java \
    $(GENERATED_DIR)/classes/javax/wireless/messaging/MessageConnection.java \
    $(JSR_120_DIR)/src/core/common/classes/javax/wireless/messaging/Message.java \
    $(JSR_120_DIR)/src/core/common/classes/javax/wireless/messaging/BinaryMessage.java \
    $(JSR_120_DIR)/src/core/common/classes/javax/wireless/messaging/TextMessage.java

ifneq ($(USE_NATIVE_AMS), true)
MODULE_JSR_120_COMMON_JAVA_FILES += \
    $(JSR_120_DIR)/src/core/common/classes/com/sun/midp/wma/ProtocolPushImpl.java
endif

ifeq ($(DELETE_WMA_MSGS), true)
#
# If messages are to be deleted, include a WMACleanupMonitor implementation
# that will do so.
#
MODULE_JSR_120_COMMON_JAVA_FILES += \
    $(JSR_120_DIR)/src/core/common/classes/com/sun/midp/wma/WMACleanupMonitor.java
else
#
# If message are not to be deleted, then include a stubbed implementation of
# WMACleanupMonitor
#
MODULE_JSR_120_COMMON_JAVA_FILES += \
    $(AMS_JSR_INTERFACE_DIR)/classes/com/sun/midp/wma/WMACleanupMonitor.java
endif

MODULE_JSR_120_SMS_JAVA_FILES = \
    $(JSR_120_DIR)/src/protocol/share/com/sun/midp/io/j2me/ProtocolBase.java \
    $(JSR_120_DIR)/src/protocol/sms/classes/com/sun/midp/io/j2me/sms/BinaryObject.java \
    $(JSR_120_DIR)/src/protocol/sms/classes/com/sun/midp/io/j2me/sms/Protocol.java \
    $(JSR_120_DIR)/src/protocol/sms/classes/com/sun/midp/io/j2me/sms/MessageObject.java \
    $(JSR_120_DIR)/src/protocol/sms/classes/com/sun/midp/io/j2me/sms/TextEncoder.java \
    $(JSR_120_DIR)/src/protocol/sms/classes/com/sun/midp/io/j2me/sms/TextObject.java

MODULE_JSR_120_CBS_JAVA_FILES = \
    $(JSR_120_DIR)/src/protocol/cbs/classes/com/sun/midp/io/j2me/cbs/Protocol.java \
    $(JSR_120_DIR)/src/protocol/cbs/classes/com/sun/midp/io/j2me/cbs/BinaryObject.java \
    $(JSR_120_DIR)/src/protocol/cbs/classes/com/sun/midp/io/j2me/cbs/TextObject.java

# Java files for the (wmatool) module
#
MODULE_TOOL_WMATOOL_JAVA_FILES = \
    $(GENERATED_DIR)/classes/com/sun/wma/TCKTest.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/wma/api/server/CBSServer.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/BinaryMessage.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/Connector.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/Message.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/MessageConnection.java \
    $(GENERATED_DIR)/classes/com/sun/tck/wma/MessageConnector.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/MessageTransportConstants.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/TextMessage.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/PropLoader.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/sms/BinaryObject.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/sms/MessageObject.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/sms/MessagePacket.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/sms/SMSMessageConnection.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/sms/SMSPacket.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/sms/TextObject.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/cbs/CBSMessageConnection.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/cbs/CBSTestServer.java \
    $(JSR_120_DIR)/src/tool/wmatool/classes/com/sun/tck/wma/cbs/CBSPacket.java \
    $(JSR_120_DIR)/src/protocol/sms/classes/com/sun/midp/io/j2me/sms/TextEncoder.java

#
# Native files for JSR 120 subsystem
vpath % $(JSR_120_DIR)/src/protocol/sms/native/share
vpath % $(JSR_120_DIR)/src/protocol/cbs/native/share
vpath % $(JSR_120_DIR)/src/core/common/native/share

SUBSYSTEM_JSR_120_EXTRA_INCLUDES = \
    -I$(JSR_120_DIR)/src/protocol/sms/native/share/inc \
    -I$(JSR_120_DIR)/src/protocol/cbs/native/share/inc \
    -I$(JSR_120_DIR)/src/core/common/native/share/inc

SUBSYSTEM_JSR_120_NATIVE_FILES = \
    bytePackUnpack.c \
    smsProtocol.c \
    cbsProtocol.c \
    jsr120_list_element.c \
    jsr120_sms_listeners.c \
    jsr120_cbs_listeners.c \
    wmaPushRegistry.c

ifeq ($(DELETE_WMA_MSGS), true)
SUBSYSTEM_JSR_120_NATIVE_FILES += \
    jsr120_msg_cleanup.c
endif

# Specify romizer configuration file for the jsr
# and path where the file is located
#
ROMGEN_INCLUDE_PATHS += $(JSR_120_DIR)/src/config/common
ROMGEN_CFG_FILES     += jsr120_rom.cfg

# Platform
#
include $(JSR_120_DIR)/src/config/$(PLATFORM).gmk

# Determines what option we have made and set it
# to some variable that global makefile recognize
#
SUBSYSTEM_JSR_120_JAVA_FILES   = \
    $(MODULE_JSR_120_COMMON_JAVA_FILES) \
    $(MODULE_JSR_120_SMS_JAVA_FILES) \
    $(MODULE_JSR_120_CBS_JAVA_FILES)

#
# Unit testing support for all protocols.
#
ifeq ($(USE_I3_TEST), true)

EXTRA_CFLAGS += -DENABLE_WMA_LOOPBACK=1

MODULE_SMS_I3TEST_JAVA_FILES += \
    $(JSR_120_DIR)/src/protocol/sms/i3test/com/sun/midp/io/j2me/sms/TestSMSOpenClose.java

MODULE_CBS_I3TEST_JAVA_FILES += \
    $(JSR_120_DIR)/src/protocol/cbs/i3test/com/sun/midp/io/j2me/cbs/TestCBSOpenClose.java

SUBSYSTEM_JSR_120_I3TEST_JAVA_FILES += \
    $(MODULE_SMS_I3TEST_JAVA_FILES) \
    $(MODULE_CBS_I3TEST_JAVA_FILES)

endif


#################################################################
# Add java files to classes.zip
$(MIDP_OUTPUT_DIR)/classes.zip:: $(SUBSYSTEM_JSR_120_JAVA_FILES)
	$(appendjavafiles)

# Internal paths for jsr 120 module
#
INTERNAL_JSR_120_CONFIG_DIR= $(JSR_120_DIR)/src/config

ifneq ($(USE_JSR_205), true)
# Include JSR 120 common properties in Configuration
# do not include if building with JSR205 as there are
# conflicting properties there
#
SUBSYSTEM_CONFIGURATION_INPUT_FILES += \
    $(INTERNAL_JSR_120_CONFIG_DIR)/common/properties_jsr120.xml
endif

JTWI_I3TEST_JAVA_FILES	+= $(SUBSYSTEM_JSR_120_I3TEST_JAVA_FILES)
JTWI_NATIVE_FILES	+= $(SUBSYSTEM_JSR_120_NATIVE_FILES)
EXTRA_INCLUDES		+= $(SUBSYSTEM_JSR_120_EXTRA_INCLUDES)
#################################################################

WMATOOL_MAIN_CLASS = com.sun.wma.TCKTest
WMATOOL_MANIFEST_FILE = $(TOOLS_CLASS_DIR)/WMATool.manifest
WMATOOL_JAR_FILE = $(BINDIR)/WMATool.jar

WMATOOL_CLASS_OUTPUT_DIRS += \
	$(TOOLS_CLASS_DIR)/com/sun/midp/io/j2me/sms \
	$(TOOLS_CLASS_DIR)/com/sun/midp/io/j2me/cbs

WMATOOL_CLASS_DIRS += \
	com/sun/midp/io/j2me/sms \
	com/sun/midp/io/j2me/cbs \
	com/sun/wma com/sun/tck

all_tools :: $(WMATOOL_JAR_FILE)

$(WMATOOL_JAR_FILE): $(TOOLS_CLASS_DIR) $(MODULE_TOOL_WMATOOL_JAVA_FILES) $(WMATOOL_MANIFEST_FILE)
	@echo " ... building WMATool " $(LOG)
	@echo +++ $(JAVAC_CMD) -g:none -d $(TOOLS_CLASS_DIR) \
		-classpath "$(TOOLS_CLASSPATH)" \
		$(MODULE_TOOL_WMATOOL_JAVA_FILES) $(LOG_ONLY)
	@($(JAVAC_CMD) -g:none -d $(TOOLS_CLASS_DIR) \
		-classpath "$(TOOLS_CLASSPATH)" \
		$(MODULE_TOOL_WMATOOL_JAVA_FILES)) $(LOG)
	@(mkdir -p $(WMATOOL_CLASS_OUTPUT_DIRS)) $(LOG)
	@(cp $(CLASSBINDIR)/com/sun/midp/io/j2me/sms/TextEncoder.class \
		$(TOOLS_CLASS_DIR)/com/sun/midp/io/j2me/sms) $(LOG)
	@echo " ... $@ " $(LOG)
	@(mkdir -p $(BINDIR)) $(LOG)
	@echo +++ cd $(TOOLS_CLASS_DIR)\; $(JAR_CMD) cfm WMATool.jar \
		WMATool.manifest \
		$(WMATOOL_CLASS_DIRS) $(LOG_ONLY)
	@(cd $(TOOLS_CLASS_DIR); $(JAR_CMD) cfm WMATool.jar \
		WMATool.manifest com/sun/midp/io/j2me/sms \
		com/sun/wma com/sun/tck) $(LOG)
	@(cp -f $(TOOLS_CLASS_DIR)/WMATool.jar $(WMATOOL_JAR_FILE)) $(LOG)

$(WMATOOL_MANIFEST_FILE): 
	@echo " ... $@ " $(LOG)
	@(echo "Main-Class: $(WMATOOL_MAIN_CLASS)" > $@) $(LOG)

clean_tools::
	-@(rm -fr $(WMATOOL_JAR_FILE)) $(LOG)

# Append JSR120 source bundle creation to target
source_bundle:: jsr_120_source_bundle

# Create JSR120 source in subdir 'jsr120/'
JSR_120_SOURCE_OUTPUT_DIR=$(SOURCE_OUTPUT_DIR)/jsr120

# Copy and filter JSR120 source in JSR_120_SOURCE_OUTPUT_DIR
jsr_120_source_bundle: SOURCE_OUTPUT_DIR
	@echo " ... JSR 120 source bundle" $(LOG)
	@$(call re_src_filter,$(JSR_120_DIR),$(JSR_120_SOURCE_OUTPUT_DIR),src)

DOXYGEN_INPUT_LIST += \
	$(JSR_120_DIR)/src/protocol/cbs/native/share/inc/jsr120_cbs_protocol.h \
	$(JSR_120_DIR)/src/core/common/native/share/inc/jsr120_cbs_pool.h \
	$(JSR_120_DIR)/src/protocol/sms/native/share/inc/jsr120_sms_protocol.h \
	$(JSR_120_DIR)/src/core/common/native/share/inc/jsr120_sms_pool.h
 

