# $Id: Portfile 66285 2010-04-08 08:09:09Z jmr@macports.org $

PortSystem 1.0

name				mod_jk
version				1.2.27

categories			www java
maintainers			jberry openmaintainer
platforms			darwin

description			Apache mod_jk remote server connector
long_description	mod_jk is the connector supported by apache for communication between \
					the apache server and tomcat. mod_jk2, which had for some time superceeded mod_jk, \
					has now become officially 'unsupported' by the Apache group. \
					mod_jk allows apache to be used refer some request for processing by tomcat or any \
					other server that also supports the ajp13 protocol. \
					Apache 2.1 will contain a replacement for mod_jk(2) called mod_proxy_ajp. \
					At this time (this) mod_jk port supports only apache2, not apache 1.x.
homepage			http://tomcat.apache.org/connectors-doc/

distname			tomcat-connectors-${version}-src
master_sites		http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/source/jk-${version}	

checksums           md5     a15cc9e3813ef5b081c7de10e6a1fbed \
                    sha1    361f8aaa1844ac76a5dda741152968190b34347b \
                    rmd160  cb872030d4325ba15d0038c6c7b298213768300a

depends_build		path:apache2/bin/httpd:apache2
worksrcdir			${distname}/native


configure.args		--with-apxs=${prefix}/apache2/bin/apxs

set apachedir       apache2

# Determine a valid value for javahome
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}] } {
	error "This port needs a reasonable value for JAVA_HOME, but couldn't automatically determine one: please set the environment variable."
}

variant jni description {Build jni_connect.so and enable jni_worker} {
	configure.args-append --with-java-home=${javahome} --enable-jni
}

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 jk configure script.
	set apxs ${prefix}/${apachedir}/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."
		}
	}
}

destroot {
	# Install the connector for apache2
	xinstall -m 755 -d \
		${destroot}${prefix}/${apachedir}/modules \
		${destroot}${prefix}/${apachedir}/conf
		
	xinstall -m 644 \
		${worksrcpath}/apache-2.0/mod_jk.so \
		${destroot}${prefix}/${apachedir}/modules
		
	if {[variant_isset jni]} {
		xinstall -m 644 \
			${worksrcpath}/jni/jk_jnicb.so \
			${destroot}${prefix}/${apachedir}/modules
	}
		
	xinstall -m 644 ${worksrcpath}/../conf/workers.properties.minimal \
		${destroot}${prefix}/${apachedir}/conf/workers.properties.sample
}


post-install {
	ui_msg "#"
	ui_msg "# Example file ${prefix}/${apachedir}/conf/workers.properties.sample has"
	ui_msg "# been installed to illustrate use of the jk connector between "
	ui_msg "# apache2 and tomcat."
	ui_msg "#"
	ui_msg "# You will want to create a working copy of this file as workers.properties"
	ui_msg "# and configure the uri mappings within it, or by using directives within httpd.conf."
	ui_msg "#"
	ui_msg "# Be sure to also add the following line to your httpd.conf:"
	ui_msg "#"
	ui_msg "#     LoadModule jk_module modules/mod_jk.so"
	ui_msg "#"
}

variant apache20 description "install for apache 2.0.x" {
    global apachedir
    set apachedir apache20
    depends_build-delete	path:apache2/bin/httpd:apache2
    depends_build-append	path:apache20/bin/httpd:apache20
    configure.args-delete	--with-apxs=${prefix}/apache2/bin/apxs
    configure.args-append	--with-apxs=${prefix}/apache20/bin/apxs
}

livecheck.type  regex
livecheck.regex "tomcat-connectors-(\\d+\\.\\d+(\\.\\d+)?)-src.tar.gz"

