# Define java Package directory, the tailing '/' is mandatory.
JAVA_PATH = com/entrouvert/lasso/
JDK_INCLUDES = @JDK_INCLUDE@
CLASSPATH = .

javalibdir = $(prefix)/lib/java
javasharedir = $(prefix)/share/java

# Shared library.
if MINGW
javalib_LTLIBRARIES = jlasso.la
else
javalib_LTLIBRARIES = libjlasso.la
endif

jlasso_la_SOURCES =	lasso_wrap.c
jlasso_la_CFLAGS = $(JDK_INCLUDES) $(LASSO_CORE_CFLAGS) -I$(top_srcdir)
jlasso_la_LIBADD =	$(top_builddir)/lasso/liblasso.la $(LASSO_LIBS)
jlasso_la_LDFLAGS =	-no-undefined -avoid-version -module \
                        -Wl,--add-stdcall-alias 

libjlasso_la_SOURCES =	lasso_wrap.c
libjlasso_la_CFLAGS = $(JDK_INCLUDES) $(LASSO_CORE_CFLAGS) -I$(top_srcdir)
libjlasso_la_LIBADD =	$(top_builddir)/lasso/liblasso.la $(LASSO_LIBS)
libjlasso_la_LDFLAGS =	-no-undefined -avoid-version -module

javashare_DATA = lasso.jar

SWIG_OUTPUTS = lasso_wrap.c \
	Defederation.java \
	DowncastableNode.java \
	Federation.java Identity.java \
	lassoConstants.java lasso.java lassoJNI.java Lecp.java \
	LibAssertion.java LibAuthnRequest.java LibAuthnResponse.java \
	LibFederationTerminationNotification.java LibLogoutRequest.java \
	LibLogoutResponse.java LibRegisterNameIdentifierRequest.java \
	LibRegisterNameIdentifierResponse.java LibRequestAuthnContext.java \
	LibStatusResponse.java Login.java Logout.java NameIdentifierMapping.java \
	NameRegistration.java Node.java NodeList.java Provider.java \
	SamlAdvice.java SamlAssertion.java SamlAttributeDesignator.java SamlAttribute.java \
	SamlAttributeStatement.java SamlAttributeValue.java SamlAudienceRestrictionCondition.java \
	SamlAuthenticationStatement.java SamlAuthorityBinding.java \
	SamlConditionAbstract.java SamlConditions.java SamlNameIdentifier.java \
	SamlpRequestAbstract.java SamlpRequest.java SamlpResponseAbstract.java \
	SamlpResponse.java SamlpStatusCode.java SamlpStatus.java SamlStatementAbstract.java \
	SamlSubjectConfirmation.java SamlSubject.java SamlSubjectLocality.java \
	SamlSubjectStatementAbstract.java SamlSubjectStatement.java Server.java \
	Session.java StringList.java SWIGTYPE_p_LassoMdProtocolType.java \
	SWIGTYPE_p_LassoSignatureType.java SWIGTYPE_p_void.java

if WSF_ENABLED
SWIG_WSF_OUTPUTS = Authentication.java \
	DiscoAuthenticateRequester.java \
	DiscoAuthenticateSessionContext.java \
	DiscoAuthorizeRequester.java \
	DiscoCredentials.java \
	DiscoDescription.java \
	DiscoEncryptedResourceID.java \
	DiscoEncryptResourceID.java \
	DiscoGenerateBearerToken.java \
	DiscoInsertEntry.java \
	DiscoModify.java \
	DiscoModifyResponse.java \
	DiscoOptions.java \
	DiscoQuery.java \
	DiscoQueryResponse.java \
	DiscoRemoveEntry.java \
	DiscoRequestedServiceType.java \
	DiscoResourceID.java \
	DiscoResourceOffering.java \
	DiscoSendSingleLogout.java \
	DiscoServiceInstance.java \
	Discovery.java \
	DstData.java \
	DstModification.java \
	DstModify.java \
	DstModifyResponse.java \
	DstNewData.java \
	DstQueryItem.java \
	DstQuery.java \
	DstQueryResponse.java \
	InteractionProfileService.java \
	IsHelp.java \
	IsInquiryElement.java \
	IsInquiry.java \
	IsInteractionRequest.java \
	IsInteractionResponse.java \
	IsInteractionStatement.java \
	IsItem.java \
	IsParameter.java \
	IsRedirectRequest.java \
	IsSelect.java \
	IsText.java \
	IsUserInteraction.java \
	lassoConstants.java \
	ProfileService.java \
	SaCredentials.java \
	SaSASLRequest.java \
	SaSASLResponse.java \
	SoapBindingCorrelation.java \
	SoapBody.java \
	SoapEnvelope.java \
	SoapHeader.java \
	SWIGTYPE_p_LassoSoapBindingProvider.java \
	UserAccount.java \
	UtilityStatus.java \
	WsfProfile.java \
	WsseSecurity.java
endif

JAVA_CRUFT = $(JAVA_PATH)lasso.class lasso_wrap.o lasso.jar $(JAVA_PATH)lasso.java

# The SWIG outputs are included in the distribution so SWIG is not
# required to use the Java interface
EXTRA_DIST = $(SWIG_OUTPUTS) $(SWIG_WSF_OUTPUTS)

CLEANFILES = $(JAVA_CRUFT)
MAINTAINERCLEANFILES = $(SWIG_OUTPUTS) $(SWIG_WSF_OUTPUTS)


lasso_wrap.c lasso.java: $(top_srcdir)/swig/Lasso.i $(top_srcdir)/swig/Lasso-wsf.i \
		$(top_srcdir)/swig/inheritance.h
	$(SWIG) -v -java -module lasso -package com.entrouvert.lasso -o lasso_wrap.c \
		$(top_srcdir)/swig/Lasso.i
	cp lasso_wrap.c lasso_wrap.c.bak
	sed -e 's/} DowncastableNode;/void *fix;} DowncastableNode;/' \
			< lasso_wrap.c.bak > lasso_wrap.c

# FIXME There must be a better way to do this with SWIG
$(JAVA_PATH)lasso.java: lasso.java
	mkdir -p $(JAVA_PATH)
	rm -f $(JAVA_PATH)/*
	cp $(srcdir)/*.java $(JAVA_PATH)

clean-local:
	rm -f *.class
	rm -rf com

all-local: lasso.jar

$(JAVA_PATH)lasso.class: $(JAVA_PATH)lasso.java
	$(JAVAC) $(JAVAC_FLAGS) $(JAVA_PATH)*.java

lasso.jar: $(JAVA_PATH)lasso.class 
	rm -f $@
	$(JAR) cf $@ $(JAVA_PATH)*.class 

