#
#   
#
# 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
#
SUBSYSTEMS += satsa

# Add my verify and display commands
verify: jsr177_verify
display: jsr177_display

# Way to specify an space as an argument  for subst
# Copied from genlibrary.make
JSR177_EMPTY=
JSR177_SPACECHAR=$(JSR177_EMPTY) $(JSR177_EMPTY)

# Variable for config errors
JSR_177_ERRORS :=

# Try to include platform's defaults
-include $(JSR_177_DIR)/src/config/$(TARGET_PLATFORM).gmk

# Default values for options
#
# ACL from another implementation text files={true|false}
ifeq ($(USE_JSR_177_ACL_TEXT),)
USE_JSR_177_ACL_TEXT = false
endif

# APDUManager={carddevice|simple}
ifeq ($(JSR_177_APDU_MANAGER),)
JSR_177_APDU_MANAGER=simple
endif

# CardDevice={simulator|platformcarddevice}
ifeq ($(JSR_177_APDU_CARDDEVICE),)
JSR_177_APDU_CARDDEVICE=simulator
endif

# PlatformAPI={simulator|stubs|any other lib}
ifeq ($(JSR_177_APDU_PLATFORM_API),)
JSR_177_APDU_PLATFORM_API=simulator
endif

# Build CAPs and eprom images for CREF?
ifeq ($(JSR_177_APDU_CARDDEVICE),simulator)
USE_JSR_177_EMULATOR = true
else
ifeq ($(JSR_177_APDU_PLATFORM_API),simulator)
USE_JSR_177_EMULATOR = true
else
USE_JSR_177_EMULATOR = false
endif
endif

# Javadoc source path
#
SUBSYSTEM_SATSA_SOURCEPATH = $(JSR_177_DIR)/src/satsa/classes \
  $(JSR_177_DIR)/src/protocol/jcrmi/classes \
  $(JSR_177_DIR)/src/pki/classes \
  $(JSR_177_DIR)/src/crypto/classes \
  $(JSR_177_DIR)/src/protocol/acl/common/classes \
  $(JSR_177_DIR)/src/common/classes

ifeq ($(USE_JSR_177_ACL_TEXT), true)
SUBSYSTEM_SATSA_SOURCEPATH += \
  $(JSR_177_DIR)/src/protocol/acl/text_file/classes
else
SUBSYSTEM_SATSA_SOURCEPATH += \
  $(JSR_177_DIR)/src/protocol/acl/octet_file/classes
endif

ifeq ($(JSR_177_APDU_MANAGER),simple)
SUBSYSTEM_SATSA_SOURCEPATH += \
  $(JSR_177_DIR)/src/protocol/apdu/simple/classes
else
SUBSYSTEM_SATSA_SOURCEPATH += \
  $(JSR_177_DIR)/src/protocol/apdu/classes
endif

SUBSYSTEM_SATSA_PACKAGES = \
  com.sun.midp.io.j2me.apdu \
  com.sun.midp.io.j2me.jcrmi \
  com.sun.satsa.acl \
  com.sun.satsa.util \
  com.sun.satsa.util.pkcs15 \
  com.sun.satsa.pki \
  com.sun.cardreader \
  java.rmi \
  javacard.framework \
  javacard.framework.service \
  javacard.security \
  javax.microedition.apdu \
  javax.microedition.jcrmi \
  javax.microedition.securityservice 

ifeq ($(USE_RESTRICTED_CRYPTO), true)
SUBSYSTEM_SATSA_PACKAGES += \
  javax.crypto \
  javax.crypto.spec \
  java.security \
  java.security.spec \
  com.sun.satsa.crypto
endif

JAVADOC_ALL_SOURCEPATH += \
    $(subst $(JSR177_SPACECHAR),$(PATHSEP),$(SUBSYSTEM_SATSA_SOURCEPATH))

JAVADOC_ALL_PACKAGES +=  $(SUBSYSTEM_SATSA_PACKAGES)

GROUP_DOC_ALL += \
	-group "JSR177 SATSA" \
    $(subst $(JSR177_SPACECHAR),$(PATHSEP),$(SUBSYSTEM_SATSA_PACKAGES)) 

# Source files for the ( satsa ) module
#
JSR_177_COMMON = $(JSR_177_DIR)/src/common

MODULE_SATSA_COMMON_JAVA_FILES = \
    $(JSR_177_COMMON)/classes/com/sun/satsa/security/SecurityInitializer.java \
    $(JSR_177_COMMON)/classes/com/sun/satsa/util/pkcs15/PKCS15File.java \
    $(JSR_177_COMMON)/classes/com/sun/satsa/util/pkcs15/AODF.java \
    $(JSR_177_COMMON)/classes/com/sun/satsa/util/pkcs15/DODF.java \
    $(JSR_177_COMMON)/classes/com/sun/satsa/util/pkcs15/ODF.java \
    $(JSR_177_COMMON)/classes/com/sun/satsa/util/pkcs15/DIRF.java \
    $(JSR_177_COMMON)/classes/com/sun/satsa/util/TLV.java \
    $(JSR_177_COMMON)/classes/com/sun/satsa/util/TLVException.java \
    $(JSR_177_COMMON)/classes/com/sun/satsa/util/Utils.java \
    $(JSR_177_COMMON)/classes/com/sun/satsa/util/Connection.java \
    $(JSR_177_COMMON)/classes/com/sun/satsa/util/FileSystemAbstract.java \
    $(JSR_177_COMMON)/classes/com/sun/satsa/util/Location.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/microedition/jcrmi/RemoteStub.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/microedition/jcrmi/RemoteRef.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/microedition/jcrmi/JavaCardRMIConnection.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/microedition/pki/UserCredentialManagerException.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/microedition/pki/UserCredentialManager.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/microedition/securityservice/CMSMessageSignatureService.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/microedition/securityservice/CMSMessageSignatureServiceException.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/microedition/apdu/APDUConnection.java \
    $(JSR_177_DIR)/src/satsa/classes/java/lang/UnsupportedOperationException.java \
    $(JSR_177_DIR)/src/satsa/classes/javacard/framework/service/ServiceException.java \
    $(JSR_177_DIR)/src/satsa/classes/javacard/framework/ISOException.java \
    $(JSR_177_DIR)/src/satsa/classes/javacard/framework/APDUException.java \
    $(JSR_177_DIR)/src/satsa/classes/javacard/framework/CardException.java \
    $(JSR_177_DIR)/src/satsa/classes/javacard/framework/CardRuntimeException.java \
    $(JSR_177_DIR)/src/satsa/classes/javacard/framework/PINException.java \
    $(JSR_177_DIR)/src/satsa/classes/javacard/framework/TransactionException.java \
    $(JSR_177_DIR)/src/satsa/classes/javacard/framework/SystemException.java \
    $(JSR_177_DIR)/src/satsa/classes/javacard/framework/UserException.java \
    $(JSR_177_DIR)/src/satsa/classes/javacard/security/CryptoException.java

# Same classes are included in JSR 172 as well.
# Avoid double inclusion.
ifneq ($(USE_JSR_172), true)
MODULE_SATSA_COMMON_JAVA_FILES += \
    $(JSR_177_DIR)/src/satsa/classes/java/rmi/Remote.java \
    $(JSR_177_DIR)/src/satsa/classes/java/rmi/RemoteException.java
endif

JSR_177_ACL_COMMON_DIR = $(JSR_177_DIR)/src/protocol/acl/common
JSR_177_ACL_CLASSES_DIR = classes/com/sun/satsa/acl
JSR_177_ACL_TEXT_DIR = $(JSR_177_DIR)/src/protocol/acl/text_file
JSR_177_ACL_OCTET_DIR = $(JSR_177_DIR)/src/protocol/acl/octet_file
ifeq ($(USE_JSR_177_ACL_TEXT), true)
JSR_177_ACL_IMPL_DIR = $(JSR_177_ACL_TEXT_DIR)
MODULE_SATSA_ACL_JAVA_FILES = \
    $(JSR_177_ACL_IMPL_DIR)/$(JSR_177_ACL_CLASSES_DIR)/ACLFileReader.java
else
JSR_177_ACL_IMPL_DIR = $(JSR_177_ACL_OCTET_DIR)
MODULE_SATSA_ACL_JAVA_FILES = \
    $(JSR_177_ACL_IMPL_DIR)/$(JSR_177_ACL_CLASSES_DIR)/AclFileSystem.java \
    $(JSR_177_ACL_IMPL_DIR)/$(JSR_177_ACL_CLASSES_DIR)/ACIF.java
endif

MODULE_SATSA_ACL_JAVA_FILES += \
    $(JSR_177_ACL_IMPL_DIR)/$(JSR_177_ACL_CLASSES_DIR)/ACEntry.java \
    $(JSR_177_ACL_IMPL_DIR)/$(JSR_177_ACL_CLASSES_DIR)/ACList.java \
    $(JSR_177_ACL_IMPL_DIR)/$(JSR_177_ACL_CLASSES_DIR)/ACSlot.java \
    $(JSR_177_ACL_IMPL_DIR)/$(JSR_177_ACL_CLASSES_DIR)/PINAttributes.java \
	$(JSR_177_ACL_COMMON_DIR)/$(JSR_177_ACL_CLASSES_DIR)/JCRMIPermission.java \
	$(JSR_177_ACL_IMPL_DIR)/$(JSR_177_ACL_CLASSES_DIR)/AccessControlManager.java \
	$(JSR_177_ACL_COMMON_DIR)/$(JSR_177_ACL_CLASSES_DIR)/ACLPermissions.java \
	$(JSR_177_ACL_COMMON_DIR)/$(JSR_177_ACL_CLASSES_DIR)/APDUPermissions.java \
	$(JSR_177_ACL_COMMON_DIR)/$(JSR_177_ACL_CLASSES_DIR)/JCRMIPermissions.java \
	$(JSR_177_ACL_COMMON_DIR)/$(JSR_177_ACL_CLASSES_DIR)/PINData.java \
	$(JSR_177_ACL_COMMON_DIR)/$(JSR_177_ACL_CLASSES_DIR)/PINEntryDialog.java

# Define APDU sources which depend on options
#
# JSR_177_APDU_MANAGER=simple
ifeq ($(JSR_177_APDU_MANAGER),simple)
MODULE_SATSA_APDU_JAVA_FILES = \
    $(JSR_177_DIR)/src/protocol/apdu/simple/classes/com/sun/midp/io/j2me/apdu/Protocol.java \
    $(JSR_177_DIR)/src/protocol/apdu/simple/classes/com/sun/midp/io/j2me/apdu/APDUManager.java \
    $(JSR_177_DIR)/src/protocol/apdu/simple/classes/com/sun/midp/io/j2me/apdu/Handle.java \
    $(JSR_177_DIR)/src/protocol/apdu/simple/classes/com/sun/midp/io/j2me/apdu/Slot.java \
    $(JSR_177_DIR)/src/protocol/apdu/simple/classes/com/sun/cardreader/CardDeviceException.java
vpath % $(JSR_177_DIR)/src/protocol/apdu/simple/native
MODULE_SATSA_APDU_NATIVE_FILES += \
	apdu_manager_kni.c 
JSR_177_PLATFORM_API_NEEDED=true
else

# JSR_177_APDU_MANAGER=carddevice
ifeq ($(JSR_177_APDU_MANAGER),carddevice)
MODULE_SATSA_APDU_JAVA_FILES = \
    $(JSR_177_DIR)/src/protocol/apdu/classes/com/sun/midp/io/j2me/apdu/Protocol.java \
    $(JSR_177_DIR)/src/protocol/apdu/classes/com/sun/midp/io/j2me/apdu/APDUManager.java \
    $(JSR_177_DIR)/src/protocol/apdu/classes/com/sun/midp/io/j2me/apdu/Cad.java \
    $(JSR_177_DIR)/src/protocol/apdu/classes/com/sun/midp/io/j2me/apdu/Handle.java \
    $(JSR_177_DIR)/src/protocol/apdu/classes/com/sun/midp/io/j2me/apdu/TLP224Message.java \
    $(JSR_177_DIR)/src/protocol/apdu/classes/com/sun/cardreader/CardDevice.java \
    $(JSR_177_DIR)/src/protocol/apdu/classes/com/sun/cardreader/CardSlot.java \
    $(JSR_177_DIR)/src/protocol/apdu/classes/com/sun/cardreader/SlotFactory.java \
    $(JSR_177_DIR)/src/protocol/apdu/classes/com/sun/cardreader/CardDeviceException.java

# JSR_177_APDU_MANAGER=carddevice & JSR_177_APDU_CARDDEVICE=simulator
ifeq ($(JSR_177_APDU_CARDDEVICE),simulator)
MODULE_SATSA_APDU_JAVA_FILES += \
    $(JSR_177_DIR)/src/protocol/apdu/classes/com/sun/midp/io/j2me/apdu/Simulator.java
JSR_177_PLATFORM_API_NEEDED=false
else

# JSR_177_APDU_MANAGER=carddevice & JSR_177_APDU_CARDDEVICE=platformcarddevice
ifeq ($(JSR_177_APDU_CARDDEVICE),platformcarddevice)
MODULE_SATSA_APDU_JAVA_FILES += \
    $(JSR_177_DIR)/src/protocol/apdu/classes/com/sun/cardreader/PlatformCardDevice.java
vpath % $(JSR_177_DIR)/src/protocol/apdu/native/share
MODULE_SATSA_APDU_NATIVE_FILES += \
	carddevice_kni.c
JSR_177_PLATFORM_API_NEEDED=true
else
# error - bad JSR_177_APDU_CARDDEVICE
JSR_177_ERRORS += \
    (echo "ERROR: JSR_177_APDU_CARDDEVICE is not properly set ($(JSR_177_APDU_CARDDEVICE))") $(LOG);

# end of JSR_177_APDU_CARDDEVICE platformcarddevice
endif
# end of JSR_177_APDU_CARDDEVICE simulator
endif
else
# error - bad JSR_177_APDU_MANAGER
JSR_177_ERRORS += \
    (echo "ERROR: JSR_177_APDU_MANAGER is not properly set ($(JSR_177_APDU_MANAGER))") $(LOG);

# end of JSR_177_APDU_MANAGER simple
endif
# end of JSR_177_APDU_MANAGER carddevice
endif
# END OF Define APDU sources

# Add device driver
ifeq ($(JSR_177_PLATFORM_API_NEEDED), true)
MODULE_SATSA_APDU_EXTRA_INCLUDES += \
    -I$(JSR_177_DIR)/src/protocol/apdu/platform_api/include
# JSR_177_APDU_PLATFORM_API=simulator
ifeq ($(JSR_177_APDU_PLATFORM_API),simulator)
MODULE_SATSA_APDU_EXTRA_INCLUDES += \
    -I$(JSR_177_DIR)/src/protocol/apdu/platform_api/simulator/include
vpath % $(JSR_177_DIR)/src/protocol/apdu/platform_api/simulator/native
MODULE_SATSA_APDU_NATIVE_FILES += \
	apdu_errors.c \
	apdu_simulator.c
else
# JSR_177_APDU_PLATFORM_API=javacall
ifeq ($(JSR_177_APDU_PLATFORM_API),javacall)
vpath % $(JSR_177_DIR)/src/protocol/apdu/platform_api/javacall/native
MODULE_SATSA_APDU_NATIVE_FILES += \
	javacall_carddevice.c
else
# JSR_177_APDU_PLATFORM_API=stubs
ifeq ($(JSR_177_APDU_PLATFORM_API),stubs)
vpath % $(JSR_177_DIR)/src/protocol/apdu/platform_api/stubs/native
MODULE_SATSA_APDU_NATIVE_FILES += \
	stubs_carddevice.c
else
# unknown JSR_177_APDU_PLATFORM_API - link with library
ifeq ($(TARGET_OS),win32)
    LIBS += $(JSR_177_DIR)/src/protocol/apdu/platform_api/driver_lib/$(JSR_177_APDU_PLATFORM_API).lib
else
    LIBS += -L$(JSR_177_DIR)/src/protocol/apdu/platform_api/driver_lib -l$(JSR_177_APDU_PLATFORM_API)
endif
# end of JSR_177_APDU_PLATFORM_API=stubs
endif
# end of JSR_177_APDU_PLATFORM_API=javacall
endif
# end of JSR_177_APDU_PLATFORM_API=simulator
endif

endif

MODULE_SATSA_JCRMI_JAVA_FILES = \
    $(JSR_177_DIR)/src/protocol/jcrmi/classes/com/sun/midp/io/j2me/jcrmi/Protocol.java \
    $(JSR_177_DIR)/src/protocol/jcrmi/classes/com/sun/midp/io/j2me/jcrmi/Reference.java

MODULE_SATSA_PKI_JAVA_FILES = \
    $(JSR_177_DIR)/src/pki/classes/com/sun/satsa/pki/Certificate.java \
    $(JSR_177_DIR)/src/pki/classes/com/sun/satsa/pki/Dialog.java \
    $(JSR_177_DIR)/src/pki/classes/com/sun/satsa/pki/MessageDialog.java \
    $(JSR_177_DIR)/src/pki/classes/com/sun/satsa/pki/PKIManager.java \
    $(JSR_177_DIR)/src/pki/classes/com/sun/satsa/pki/PrivateKey.java \
    $(JSR_177_DIR)/src/pki/classes/com/sun/satsa/pki/RFC2253Name.java \
    $(JSR_177_DIR)/src/pki/classes/com/sun/satsa/pki/PublicKey.java \
    $(JSR_177_DIR)/src/pki/classes/com/sun/satsa/pki/WimFileSystem.java \
    $(JSR_177_DIR)/src/pki/classes/com/sun/satsa/pki/WIMApplication.java

MODULE_SATSA_CRYPTO_JAVA_FILES += \
    $(JSR_177_DIR)/src/satsa/classes/java/security/Signature.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/Key.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/MessageDigest.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/NoSuchAlgorithmException.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/InvalidKeyException.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/PublicKey.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/KeyException.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/KeyFactory.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/SignatureException.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/DigestException.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/GeneralSecurityException.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/InvalidAlgorithmParameterException.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/spec/KeySpec.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/spec/EncodedKeySpec.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/spec/InvalidKeySpecException.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/spec/X509EncodedKeySpec.java \
    $(JSR_177_DIR)/src/satsa/classes/java/security/spec/AlgorithmParameterSpec.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/crypto/BadPaddingException.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/crypto/Cipher.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/crypto/IllegalBlockSizeException.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/crypto/NoSuchPaddingException.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/crypto/ShortBufferException.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/crypto/spec/SecretKeySpec.java \
    $(JSR_177_DIR)/src/satsa/classes/javax/crypto/spec/IvParameterSpec.java \
    $(JSR_177_DIR)/src/crypto/classes/com/sun/satsa/crypto/RSAPublicKey.java

JCRMIC_SOURCES = \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/attributes/JAttribute.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/attributes/JExceptionsAttr.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/constants/JConstant.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/constants/JConstantClass.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/constants/JConstantDouble.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/constants/JConstantFloat.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/constants/JConstantFieldRef.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/constants/JConstantInteger.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/constants/JConstantUtf8.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/constants/JConstantInterfaceMethodRef.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/constants/JConstantMethodRef.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/constants/JConstantNameAndType.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/constants/JConstantLong.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/constants/JConstantPool.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/constants/JConstantString.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/Loader.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/JClass.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/classfile/JMethod.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/utils/IndentingWriter.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/utils/Notifier.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/utils/StreamReader.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/Main.java \
    $(JSR_177_DIR)/src/tool/jcrmic/com/sun/satsa/jcrmic/RemoteMethod.java

SIM_TOOLKIT_SOURCES = \
    $(JSR_177_DIR)/src/tool/javacard/sim/toolkit/AccessSAT.java \
    $(JSR_177_DIR)/src/tool/javacard/sim/toolkit/SATBaseApplet.java \
    $(JSR_177_DIR)/src/tool/javacard/sim/toolkit/EditHandler.java \
    $(JSR_177_DIR)/src/tool/javacard/sim/toolkit/EnvelopeHandler.java \
    $(JSR_177_DIR)/src/tool/javacard/sim/toolkit/MEProfile.java \
    $(JSR_177_DIR)/src/tool/javacard/sim/toolkit/ViewHandler.java \
    $(JSR_177_DIR)/src/tool/javacard/sim/toolkit/EnvelopeResponseHandler.java \
    $(JSR_177_DIR)/src/tool/javacard/sim/toolkit/ProactiveHandler.java \
    $(JSR_177_DIR)/src/tool/javacard/sim/toolkit/ToolkitConstants.java \
    $(JSR_177_DIR)/src/tool/javacard/sim/toolkit/ToolkitException.java \
    $(JSR_177_DIR)/src/tool/javacard/sim/toolkit/ProactiveResponseHandler.java \
    $(JSR_177_DIR)/src/tool/javacard/sim/toolkit/ToolkitInterface.java \
    $(JSR_177_DIR)/src/tool/javacard/sim/toolkit/ToolkitRegistry.java

JC_SAT_APPLET_SOURCES = \
    $(JSR_177_DIR)/src/tool/javacard/com/sun/satsa/satapplet/SATApplet.java \
    $(JSR_177_DIR)/src/tool/javacard/com/sun/satsa/gsmapplet/AccessSATImpl.java \
    $(JSR_177_DIR)/src/tool/javacard/com/sun/satsa/gsmapplet/GSMApplet.java

JC_PKI_APPLET_SOURCES = \
    $(JSR_177_DIR)/src/tool/javacard/com/sun/satsa/pkiapplet/Parser.java \
    $(JSR_177_DIR)/src/tool/javacard/com/sun/satsa/pkiapplet/PKIApplet.java \
    $(JSR_177_DIR)/src/tool/javacard/com/sun/satsa/pkiapplet/Data.java \
    $(JSR_177_DIR)/src/tool/javacard/com/sun/satsa/pkiapplet/File.java

JC_ACL_APPLET_SOURCES = \
    $(JSR_177_DIR)/src/tool/javacard/com/sun/satsa/aclapplet/Parser.java \
    $(JSR_177_DIR)/src/tool/javacard/com/sun/satsa/aclapplet/ACLApplet.java \
    $(JSR_177_DIR)/src/tool/javacard/com/sun/satsa/aclapplet/Data.java \
    $(JSR_177_DIR)/src/tool/javacard/com/sun/satsa/aclapplet/File.java

# Determines what option we have made and set it
# to some variable that global makefile recognize
#
SUBSYSTEM_SATSA_JAVA_FILES   = $(MODULE_SATSA_COMMON_JAVA_FILES) \
			       $(MODULE_SATSA_APDU_JAVA_FILES) \
			       $(MODULE_SATSA_JCRMI_JAVA_FILES) \
			       $(MODULE_SATSA_PKI_JAVA_FILES) \
			       $(MODULE_SATSA_ACL_JAVA_FILES) \
			       $(MODULE_SATSA_CRYPTO_JAVA_FILES)

# JSR 177 internal paths
INTERNAL_JSR_177_CONFIG_DIR = $(JSR_177_DIR)/src/config

# Include jsr 177 common properties in Configuration
#
SUBSYSTEM_CONFIGURATION_INPUT_FILES += \
	$(INTERNAL_JSR_177_CONFIG_DIR)/common/i18n_constants_jsr177.xml \
	$(INTERNAL_JSR_177_CONFIG_DIR)/common/l10n/en-US_jsr177.xml

# Include properties that depend on build options
ifeq ($(JSR_177_APDU_MANAGER),carddevice)
    ifeq ($(JSR_177_APDU_CARDDEVICE),simulator)
        SUBSYSTEM_CONFIGURATION_INPUT_FILES += \
            $(INTERNAL_JSR_177_CONFIG_DIR)/common/properties_jsr177_simulator_class.xml \
            $(INTERNAL_JSR_177_CONFIG_DIR)/common/properties_jsr177_simulator.xml
    else
        ifeq ($(JSR_177_APDU_CARDDEVICE),platformcarddevice)
            SUBSYSTEM_CONFIGURATION_INPUT_FILES += \
                $(INTERNAL_JSR_177_CONFIG_DIR)/common/properties_jsr177_platform.xml
            ifeq ($(JSR_177_APDU_PLATFORM_API),javacall)
                SUBSYSTEM_CONFIGURATION_INPUT_FILES += \
                    $(INTERNAL_JSR_177_CONFIG_DIR)/common/properties_jsr177_simulator.xml
            endif
        endif
    endif
else
    ifeq ($(JSR_177_APDU_MANAGER),simple)
        ifeq ($(JSR_177_APDU_PLATFORM_API),simulator)
            SUBSYSTEM_CONFIGURATION_INPUT_FILES += \
                $(INTERNAL_JSR_177_CONFIG_DIR)/common/properties_jsr177_simulator.xml
        endif
        ifeq ($(JSR_177_APDU_PLATFORM_API),javacall)
            SUBSYSTEM_CONFIGURATION_INPUT_FILES += \
                $(INTERNAL_JSR_177_CONFIG_DIR)/common/properties_jsr177_simulator.xml
        endif
    endif
endif

# Include common properties
SUBSYSTEM_CONFIGURATION_INPUT_FILES += \
	$(INTERNAL_JSR_177_CONFIG_DIR)/common/properties_jsr177.xml

# Java card constants
#
ifndef JC_DIR
JC_DIR = /java/re/jcdevkit/2.2.1/archive/fcs/binaries/domestic/linux/java_card_kit-2_2_1
endif
JC_API = $(JC_DIR)/lib/api.jar
JC_CONVERTER = $(JC_DIR)/lib/converter.jar
JC_VERIFIER=$(JC_DIR)/lib/offcardverifier.jar
JC_SCRIPTGEN=$(JC_DIR)/lib/scriptgen.jar
JC_APDUTOOL_CLASSPATH="$(JC_DIR)/lib/apduio.jar$(PATHSEP)$(JC_DIR)/lib/apdutool.jar"
JC_EEPROM_IMAGE = $(BINDIR)/jc_eeprom_image

JAVACARD_CLASSES = $(MIDP_OUTPUT_DIR)/javacard_classes
SAT_SCRIPT_PATH = $(JAVACARD_CLASSES)/jcscripts
STUBS_PATH = $(JAVACARD_CLASSES)/stubs
JCRMIC_PROPERTIES = com/sun/satsa/jcrmic/jcrmic.properties
JCRMIC_MANIFEST_FILE = jcrmic.manifest
JCRMIC_ARCHIVE = jcrmic.jar

# i3test for jsr 177
#
ifeq ($(USE_I3_TEST), true)
SUBSYSTEM_JSR_177_I3TEST_JAVA_FILES += \
	$(JSR_177_DIR)/src/test/i3test/com/sun/satsa/utils/TestIA5.java 
ifeq ($(USE_RESTRICTED_CRYPTO), true)
SUBSYSTEM_JSR_177_I3TEST_JAVA_FILES += \
	$(JSR_177_DIR)/src/test/i3test/com/sun/satsa/crypto/TestRC4.java 
endif
ifeq ($(USE_JSR_177_EMULATOR), false)
SUBSYSTEM_JSR_177_I3TEST_JAVA_FILES += \
	$(JSR_177_DIR)/src/test/i3test/com/sun/satsa/pki/TestPKI.java
ifeq ($(JSR_177_APDU_MANAGER),carddevice)
SUBSYSTEM_JSR_177_I3TEST_JAVA_FILES += \
	$(JSR_177_DIR)/src/test/i3test/com/sun/midp/io/j2me/apdu/TestCad.java \
	$(JSR_177_DIR)/src/test/i3test/com/sun/cardreader/TestSlotFactory.java

ifeq ($(JSR_177_APDU_CARDDEVICE),platformcarddevice)
SUBSYSTEM_JSR_177_I3TEST_JAVA_FILES += \
	$(JSR_177_DIR)/src/test/i3test/com/sun/cardreader/TestGemplus1.java
endif
endif
endif
JTWI_I3TEST_JAVA_FILES	+= $(SUBSYSTEM_JSR_177_I3TEST_JAVA_FILES)
endif
#

SUBSYSTEM_SATSA_NATIVE_FILES = \
    $(MODULE_SATSA_APDU_NATIVE_FILES)

SUBSYSTEM_SATSA_EXTRA_INCLUDES = \
    $(MODULE_SATSA_APDU_EXTRA_INCLUDES)

EXTRA_INCLUDES += $(SUBSYSTEM_SATSA_EXTRA_INCLUDES)
EXTRA_CFLAGS += -DENABLE_JSR_177
JPP_DEFS += -DENABLE_JSR_177

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

# Native documentation to include in porting interfaces
DOXYGEN_INPUT_LIST += \
	$(JSR_177_DIR)/src/protocol/apdu/platform_api/include/carddevice.h


# Tools and applets
#
ifeq ($(USE_JSR_177_EMULATOR), true)
all_tools :: jcrmic sim
else
all_tools :: jcrmic
endif

jcrmic: $(JAVACARD_CLASSES) $(BINDIR)
	@echo " ..." $@
	@$(JAVAC_CMD) -d $(JAVACARD_CLASSES) $(JCRMIC_SOURCES)
	@cp -f $(JSR_177_DIR)/src/tool/jcrmic/$(JCRMIC_PROPERTIES) $(JAVACARD_CLASSES)/$(JCRMIC_PROPERTIES)
	@cp -f $(JSR_177_DIR)/src/tool/jcrmic/$(JCRMIC_MANIFEST_FILE) $(JAVACARD_CLASSES)/$(JCRMIC_MANIFEST_FILE)
	@(cd $(JAVACARD_CLASSES) ; $(JAR_CMD) cfm $(JCRMIC_ARCHIVE) $(JCRMIC_MANIFEST_FILE) com/sun/satsa/jcrmic )
	@mv $(JAVACARD_CLASSES)/$(JCRMIC_ARCHIVE) $(BINDIR)/$(JCRMIC_ARCHIVE)

ifeq ($(USE_JSR_177_EMULATOR), true)
sim: $(JAVACARD_CLASSES)
	@echo " ..." $@
	@echo " ... compiling SIM Toolkit"
	@$(JAVAC_CMD) -g -d $(JAVACARD_CLASSES) -classpath $(JC_API) $(SIM_TOOLKIT_SOURCES)
	@echo " ... compiling applets"
	@$(JAVAC_CMD) -g -d $(JAVACARD_CLASSES) -classpath $(JAVACARD_CLASSES)$(PATHSEP)$(JC_API) $(JC_SAT_APPLET_SOURCES)
	@$(JAVAC_CMD) -g -d $(JAVACARD_CLASSES) -classpath $(JC_API) $(JC_PKI_APPLET_SOURCES)
	@$(JAVAC_CMD) -g -d $(JAVACARD_CLASSES) -classpath $(JC_API) $(JC_ACL_APPLET_SOURCES)
	@cp -f $(JSR_177_DIR)/src/tool/javacard/*.opt $(JAVACARD_CLASSES)/
	@cp -f $(JSR_177_DIR)/src/tool/javacard/*.scr $(JAVACARD_CLASSES)/
	@cp -r -f $(JC_DIR)/api_export_files $(JAVACARD_CLASSES)/
	@echo " ... preparing SIM Toolkit"
	@(cd $(JAVACARD_CLASSES) ; $(JAVA_CMD) -classpath $(JC_VERIFIER)$(PATHSEP)$(JC_CONVERTER) com.sun.javacard.converter.Converter -config simtoolkit.opt )
	@mkdir -p $(JAVACARD_CLASSES)/api_export_files/sim/toolkit/javacard/
	@cp $(JAVACARD_CLASSES)/sim/toolkit/javacard/toolkit.exp $(JAVACARD_CLASSES)/api_export_files/sim/toolkit/javacard/
	@echo " ... preparing applets"
	@(cd $(JAVACARD_CLASSES) ; $(JAVA_CMD) -classpath $(JC_VERIFIER)$(PATHSEP)$(JC_CONVERTER) com.sun.javacard.converter.Converter -config gsmapplet.opt )
	@(cd $(JAVACARD_CLASSES) ; $(JAVA_CMD) -classpath $(JC_VERIFIER)$(PATHSEP)$(JC_CONVERTER) com.sun.javacard.converter.Converter -config satapplet.opt )
	@(cd $(JAVACARD_CLASSES) ; $(JAVA_CMD) -classpath $(JC_VERIFIER)$(PATHSEP)$(JC_CONVERTER) com.sun.javacard.converter.Converter -config pkiapplet.opt )
	@(cd $(JAVACARD_CLASSES) ; $(JAVA_CMD) -classpath $(JC_VERIFIER)$(PATHSEP)$(JC_CONVERTER) com.sun.javacard.converter.Converter -config aclapplet.opt )
	@(cd $(JAVACARD_CLASSES) ; $(JAVA_CMD) -classpath $(JC_SCRIPTGEN) com.sun.javacard.scriptgen.Main -o toolkit.scr -nobanner sim/toolkit/javacard/toolkit.cap )
	@(cd $(JAVACARD_CLASSES) ; $(JAVA_CMD) -classpath $(JC_SCRIPTGEN) com.sun.javacard.scriptgen.Main -o gsmapplet.scr -nobanner com/sun/satsa/gsmapplet/javacard/gsmapplet.cap )
	@(cd $(JAVACARD_CLASSES) ; $(JAVA_CMD) -classpath $(JC_SCRIPTGEN) com.sun.javacard.scriptgen.Main -o satapplet.scr -nobanner com/sun/satsa/satapplet/javacard/satapplet.cap )
	@(cd $(JAVACARD_CLASSES) ; $(JAVA_CMD) -classpath $(JC_SCRIPTGEN) com.sun.javacard.scriptgen.Main -o pkiapplet.scr -nobanner com/sun/satsa/pkiapplet/javacard/pkiapplet.cap )
	@(cd $(JAVACARD_CLASSES) ; $(JAVA_CMD) -classpath $(JC_SCRIPTGEN) com.sun.javacard.scriptgen.Main -o aclapplet.scr -nobanner com/sun/satsa/aclapplet/javacard/aclapplet.cap )
	@(cd $(JAVACARD_CLASSES) ; cat header.scr toolkit.scr gsmapplet.scr satapplet.scr pkiapplet.scr aclapplet.scr footer.scr > satsimulator.scr)
	@echo " ... loading applets (be patient)"
	@$(JC_DIR)/bin/cref -o $(JC_EEPROM_IMAGE) -nobanner -nomeminfo -s &
	-@sleep 1
	@(cd $(JAVACARD_CLASSES) ; $(JAVA_CMD) -classpath $(JC_APDUTOOL_CLASSPATH) com.sun.javacard.apdutool.Main -h 127.0.0.1 -nobanner satsimulator.scr)
	@(cd $(JAVACARD_CLASSES) ; mkdir -p jc_script ; mv -f satsimulator.scr jc_script/ ; rm -f *.opt ; rm -f *.scr ; rm -fr api_export_files)
	@echo " ..." $@ " done"
endif

$(JAVACARD_CLASSES):
	@echo " ... creating directories" $@
	@mkdir -p $@

$(STUBS_PATH): $(JAVACARD_CLASSES)
	@echo " ... creating directories" $@
	@mkdir -p $@

# Append SATSA source bundle creation to target
source_bundle:: satsa_source_bundle

# Create SATSA source in subdir 'jsr177/'
SATSA_SOURCE_OUTPUT_DIR=$(SOURCE_OUTPUT_DIR)/jsr177

# Copy and filter SATSA source in SATSA_SOURCE_OUTPUT_DIR
satsa_source_bundle: JSR_177_DIR SOURCE_OUTPUT_DIR
	@echo " ... JSR 177 source bundle" $(LOG)
	@$(call re_src_filter,$(JSR_177_DIR),$(SATSA_SOURCE_OUTPUT_DIR),src)

# Subsystem verify rules
#
ifeq ($(JSR_177_ERRORS),)
jsr177_verify:
else
jsr177_verify:
	@$(JSR_177_ERRORS)
	@exit -1
endif

# Display subsystem information
#
jsr177_display:
	@echo   "" $(LOG)
	@echo   "==========================" $(LOG)
	@echo   "JSR177 Build Configuration" $(LOG)
	@echo   "==========================" $(LOG)
	@echo   "" $(LOG)
	@echo   "TARGET_PLATFORM             = ""$(TARGET_PLATFORM)" $(LOG)
	@echo   "JSR_177_DIR                 = ""$(JSR_177_DIR)" $(LOG)
	@echo   "JC_DIR                      = ""$(JC_DIR)" $(LOG)
	@echo   "USE_JSR_177_ACL_TEXT        = ""$(USE_JSR_177_ACL_TEXT)" $(LOG)
	@echo   "JSR_177_APDU_MANAGER        = ""$(JSR_177_APDU_MANAGER)" $(LOG)
	@echo   "JSR_177_APDU_CARDDEVICE     = ""$(JSR_177_APDU_CARDDEVICE)" $(LOG)
	@echo   "JSR_177_APDU_PLATFORM_API   = ""$(JSR_177_APDU_PLATFORM_API)" $(LOG)
	@echo   "" $(LOG)

