#
# Copyright 2003-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.pkcs11
LIBRARY = j2pkcs11
PRODUCT = sun
include $(BUILDDIR)/common/Defs.gmk

#
# C and Java Files
#
include FILES_c.gmk

AUTO_FILES_JAVA_DIRS = sun/security/pkcs11

ifndef OPENJDK
FILES_c += \
    $(CTARGDIR)p11_crypt.c \
    $(CTARGDIR)p11_dual.c
VPATH_C_EXTRA = $(CLOSED_SRC)/share/native/sun/security/pkcs11/wrapper
else # OPENJDK
FILES_c += \
    $(CTARGDIR)p11_crypt_stub.c
endif # OPENJDK

#
# Java files that define native methods
#
FILES_export = \
    sun/security/pkcs11/wrapper/PKCS11.java \
    sun/security/pkcs11/Secmod.java

#
# Find native code
#
vpath %.c \
  $(SHARE_SRC)/native/sun/security/pkcs11/wrapper \
  $(PLATFORM_SRC)/native/sun/security/pkcs11/wrapper \
  $(VPATH_C_EXTRA)

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

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

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

include $(BUILDDIR)/common/Library.gmk

#
# Libraries to link
#
ifeq ($(PLATFORM), windows)
  OTHER_LDLIBS = $(JVMLIB)
else
  OTHER_LDLIBS = -ldl $(JVMLIB)
endif

PKCS11_JAR_SRC = $(BUILDDIR)/closed/tools/crypto/pkcs11/sunpkcs11.jar
PKCS11_JAR_DST = $(EXTDIR)/sunpkcs11.jar
PKCS11_JAR_TMP = $(TEMPDIR)/sunpkcs11.jar

clobber::
	-$(RM) $(PKCS11_JAR_DST) $(PKCS11_JAR_TMP)

all: build $(PKCS11_JAR_DST)

jar: classes
	-$(RM) $(PKCS11_JAR_DST) $(PKCS11_JAR_TMP)
	$(JAR) cf $(PKCS11_JAR_TMP) -C $(CLASSDESTDIR) sun/security/pkcs11 \
	     $(JAR_JFLAGS)
	$(CP) $(PKCS11_JAR_TMP) $(PKCS11_JAR_DST)
	@$(java-vm-cleanup)

ifdef OPENJDK

$(PKCS11_JAR_DST): jar

else # OPENJDK

$(PKCS11_JAR_DST): $(PKCS11_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) $(PKCS11_JAR_DST) $(ALIAS) < $(PASSPHRASE)
	@$(ECHO)
	@$(java-vm-cleanup)

endif # OPENJDK

.PHONY: jar
