#
# Copyright 2005-2007 Sun Microsystems, Inc.  All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code 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.  Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code 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 in the LICENSE file that
# accompanied this code).
#
# 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 USA or visit www.sun.com if you need additional information or
# have any questions.
#

BUILDDIR = ../../..
PACKAGE = sun.security.mscapi
LIBRARY = sunmscapi
PRODUCT = sun
include $(BUILDDIR)/common/Defs.gmk

CPLUSPLUSLIBRARY=true

#
# C++ and Java Files
#
include FILES_cpp.gmk

AUTO_FILES_JAVA_DIRS = sun/security/mscapi

#
# Java files that define native methods
#
FILES_export = \
    sun/security/mscapi/KeyStore.java \
    sun/security/mscapi/Key.java \
    sun/security/mscapi/PRNG.java \
    sun/security/mscapi/RSACipher.java \
    sun/security/mscapi/RSAPublicKey.java \
    sun/security/mscapi/RSASignature.java \
    sun/security/mscapi/RSAKeyPairGenerator.java

#
# Find native code
#
vpath %.cpp \
  $(PLATFORM_SRC)/native/sun/security/mscapi

#
# Find include files
#
OTHER_INCLUDES += \
  -I$(PLATFORM_SRC)/native/sun/security/mscapi

# Skip the unexportable source files during an OpenJDK build
ifdef OPENJDK
MSCAPI_EXCLUDE = \
    sun/security/mscapi/RSACipher.java

FILES_java := $(filter-out $(MSCAPI_EXCLUDE),$(FILES_java))
FILES_export := $(filter-out $(MSCAPI_EXCLUDE),$(FILES_export))
endif

#
# Rules
#
CLASSDESTDIR = $(TEMPDIR)/classes

include $(BUILDDIR)/common/Mapfile-vers.gmk

include $(BUILDDIR)/common/Library.gmk

#
# Libraries to link
#
ifeq ($(PLATFORM), windows)
  OTHER_LDLIBS += $(JVMLIB) Crypt32.Lib
endif

MSCAPI_JAR_SRC = $(BUILDDIR)/closed/tools/crypto/mscapi/sunmscapi.jar
MSCAPI_JAR_DST = $(EXTDIR)/sunmscapi.jar
MSCAPI_JAR_TMP = $(TEMPDIR)/sunmscapi.jar

clobber::
	-$(RM) $(MSCAPI_JAR_DST) $(MSCAPI_JAR_TMP)

all: build $(MSCAPI_JAR_DST)

jar: classes
	-$(RM) $(MSCAPI_JAR_DST) $(MSCAPI_JAR_TMP)
	$(JAR) cf $(MSCAPI_JAR_TMP) -C $(CLASSDESTDIR) sun/security/mscapi \
	     $(JAR_JFLAGS)
	$(CP) $(MSCAPI_JAR_TMP) $(MSCAPI_JAR_DST)
	@$(java-vm-cleanup)

ifdef OPENJDK

$(MSCAPI_JAR_DST): jar

else # OPENJDK

$(MSCAPI_JAR_DST): $(MSCAPI_JAR_SRC)
	$(install-file)

# testing only
KEY_LOCATION	= /security/ws/JCE-jdk7/src
KEYSTORE	= $(KEY_LOCATION)/JCEKeyStore.ks
PASSPHRASE	= $(KEY_LOCATION)/passPhrase
ALIAS		= jce_rsa

sign: jar signonly

signonly:
	$(BOOTDIR)/bin/jarsigner -keystore $(KEYSTORE) $(MSCAPI_JAR_DST) $(ALIAS) < $(PASSPHRASE)
	@$(ECHO)
	@$(java-vm-cleanup)

endif # OPENJDK

.PHONY: jar
