# $Id: Portfile 92864 2012-05-09 07:10:03Z jmr@macports.org $

PortSystem 1.0

name				mod_jk2
version				5.5.4
revision			1
categories			www java
maintainers			nomaintainer
platforms			darwin

description			Apache mod_jk2 remote server connector (from Tomcat).
long_description	mod_jk2 provides a connection between apache2 and a remote \
					server. It passes incoming requests on to the remote server \
 					for handling. Configurations may be mixed such that each \
					server handles a particular type of request. mod_jk2 comes \
					from the Java based Tomcat server, and is usually used with it. \
					As of Nov, 2004, mod_jk2 has been officially 'unsupported' by apache. \
					mod_jk, which jk2 once superceeded, has once again become the golden \
					child. Please refer to the mod_jk port, and to apache2.1, where a new \
					core module, proxy_ajp, replaces mod_jk2.
homepage			http://jakarta.apache.org/tomcat/connectors-doc/

distname			jakarta-tomcat-${version}-src
master_sites		apache:tomcat/tomcat-5/archive/v${version}/src/
checksums			md5 2fdfb34df8f670af2669d02fb6103a45

patch.dir           ${worksrcpath}/jakarta-tomcat-connectors/jk
patchfiles			patch-workers2.properties.minimal.diff

depends_build		path:apache2/bin/httpd:apache2
depends_lib			lib:pcre:pcre

worksrcdir			${distname}/jakarta-tomcat-connectors/jk/native2


# Try to determine a reasonable JAVA_HOME value
if { [llength [array get env "JAVA_HOME"]] > 0 } {
	set javahome $env(JAVA_HOME)
} else {
	set javahome ""
}
if { ![file isdirectory ${javahome}] } {
	if { ${os.platform} == "darwin" } {
		if { [file isdirectory "/System/Library/Frameworks/JavaVM.framework/Home"] } {
			set javahome "/System/Library/Frameworks/JavaVM.framework/Home"
		}
	}
}
if { ![file isdirectory ${javahome}] } {
    pre-fetch {
	    error "This port needs a reasonable value for JAVA_HOME, but couldn't automatically determine one: please set the environment variable."
    }
}


post-patch {
	# Clean up the the buildconf script
	reinplace s|libtoolize|glibtoolize| ${worksrcpath}/buildconf.sh

	# Fix link
	reinplace s|-lcrypt|| ${worksrcpath}/server/apache2/Makefile.in
}

pre-configure {
	# Check to be sure the apache2 port has been updated, and
	# warn the user if it hasn't been.
	# In port versions prior to 2.0.52_1, apxs didn't know where libdir was.
	# That information is needed by the jk2 configure script.
	set apxs ${prefix}/apache2/bin/apxs
	if { [file executable ${apxs}] } {
		set libdir [exec ${apxs} -q LIBDIR]
		if { 0 == [string length ${libdir}] || ![file isdirectory ${libdir}] } {
			error "Your apache2 installation doesn't know where its library directory is. Please update your apache2 port."
		}
	}
	
	# Build the jk2 configure file
	file attributes ${worksrcpath}/buildconf.sh -permissions ug+x
	system "cd ${worksrcpath} && ./buildconf.sh"	
}

configure.args		--with-pcre \
					--with-apxs2=${prefix}/apache2/bin/apxs \
					--with-jni \
					--with-java-home=${javahome}

destroot {
	# Install the jk2 connector for apache2
	xinstall -m 755 -d \
		${destroot}${prefix}/apache2/modules \
		${destroot}${prefix}/apache2/conf
		
	xinstall -m 644 \
		${worksrcpath}/../build/jk2/apache2/mod_jk2.so \
		${worksrcpath}/../build/jk2/apache2/libjkjni.so \
		${destroot}${prefix}/apache2/modules
		
	xinstall -m 644 ${worksrcpath}/../conf/workers2.properties.minimal \
		${destroot}${prefix}/apache2/conf/workers2.properties.sample
}


post-install {
	ui_msg "#"
	ui_msg "# Example file ${prefix}/apache2/conf/workers2.properties.sample has"
	ui_msg "# been installed to illustrate use of the jk2 connector between "
	ui_msg "# apache2 and tomcat over a unix domain socket."
	ui_msg "#"
	ui_msg "# You will want to create a working copy of this file as workers2.properties"
	ui_msg "# and configure the uri mappings within it, or using JkUriSet in httpd.conf."
	ui_msg "#"
	ui_msg "# If you're using Tomcat, note that you also need to configure the file"
	ui_msg "# jk2.properties in tomcat5/conf (Tomcat should have installed a copy of this"
	ui_msg "# file as jk2.properties.sample), or add appropriate attributes to the Connector"
	ui_msg "# element in server.xml. Note that if you are going to use jk2.properties, you"
	ui_msg "# now need to specify this in the Connector element in server.xml:"
	ui_msg "#"
	ui_msg "#       <Connector protocol='AJP/1.3' port='8009'"
    ui_msg "#                  enableLookups='false' redirectPort='8443'"
    ui_msg "#                  propertiesFile='conf/jk2.properties'"
    ui_msg "#                  />"
	ui_msg "#"
	ui_msg "# Be sure to also add the following line to your httpd.conf:"
	ui_msg "#"
	ui_msg "#     LoadModule jk2_module modules/mod_jk2.so"
	ui_msg "#"
}
