# $Id: Portfile 82547 2011-08-15 16:46:16Z jmr@macports.org $

PortSystem                      1.0
PortGroup                       perl5 1.0

perl5.setup                     CGI-SpeedyCGI 2.22
revision			            11
maintainers                     markd openmaintainer
description                     Speed up perl CGI scripts by running them persistently
long_description                SpeedyCGI is a way to run perl scripts persistently, \
				which can make them run much more quickly. A script \
				can be made to to run persistently by changing the \
				interpreter line at the top of a script from: \
				  '#!/_prefix_/bin/perl' to '#!/_prefix_/bin/speedy'

platforms                       darwin
checksums                       md5 2f80df78874e3efa80f180923c4967a1
use_parallel_build              no

if {${perl5.major} != ""} {
patchfiles			patch-Makefile.PL \
				patch-mod_speedycgi2.c \
				patch-src-SpeedyMake.pl \
				patch-src_speedy_main.c \
				patch-mod_speedycgi-Makefile.tmpl \
				patch-src-speedy_perl.h \
				patch-src-speedy_backend_main.h \
				patch-src-speedy_perl.c

depends_lib-append			port:apache2

variant apple_apache description {Configures SpeedyCGI to use Apple's built-in Apache instead of MacPorts Apache} {
	depends_lib-delete	port:apache2
	patchfiles-delete	patch-mod_speedycgi-Makefile.tmpl
}

post-patch {
if { [variant_isset apple_apache]} {
# Do nothing

} else {
# Patch for MacPorts Apache 2
	reinplace "s|apxs -q|${prefix}/apache2/bin/apxs -q|g" \
		${worksrcpath}/src/SpeedyMake.pl \
		${worksrcpath}/Makefile.PL

	reinplace "s|__PREFIX__|${prefix}|g" \
		${worksrcpath}/mod_speedycgi/Makefile.tmpl \
	}
}

post-destroot {
	xinstall -m 4755 ${worksrcpath}/speedy/speedy ${destroot}${prefix}/bin/speedy_suidperl
	xinstall -m 755 -d ${destroot}${prefix}/share/doc/speedycgi
	eval xinstall -m 644 [glob ${worksrcpath}/docs/*] ${destroot}${prefix}/share/doc/speedycgi
	xinstall -m 644 ${worksrcpath}/README ${destroot}${prefix}/share/doc/speedycgi

if { [variant_isset apple_apache]} {
# Install module for Apple's Apache outside of ${prefix} and let user copy it.
	xinstall -m 644 ${worksrcpath}/mod_speedycgi2/mod_speedycgi.so ${destroot}${prefix}/share/doc/speedycgi

} else {
# Install module for MacPorts Apache2
	xinstall -m 755 -d ${destroot}${prefix}/apache2/modules
	xinstall -m 644 ${worksrcpath}/mod_speedycgi2/.libs/mod_speedycgi.so \
		${destroot}${prefix}/apache2/modules
	}
}
}

notes \
"#### To complete SpeedyCGI installation for MacPorts Apache2 (default install) ####

Enable mod_speedycgi.so in httpd.conf

-Edit MacPorts Apache 2 ${prefix}/apache2/conf/httpd.conf and add this line:
        LoadModule speedycgi_module modules/mod_speedycgi.so


See ${prefix}/share/doc/speedycgi/README for further details.



#### To complete SpeedyCGI installation for Apple's Apache2 (+apple_apache variant)  ####
        
Copy mod_speedycgi.so and enable it in httpd.conf

-Copy ${prefix}/share/doc/speedycgi/mod_speedycgi.so to /usr/libexec/apache2

-Edit Apple's Apache /etc/apache2/httpd.conf and add this line:
        LoadModule speedycgi_module libexec/apache2/mod_speedycgi.so

NOTE: If using the apple_apache variant on the 10.5 PPC platform, modify the file
  /usr/sbin/apachectl as follows:

    From:  HTTPD='/usr/sbin/httpd'
    To:    HTTPD='arch -ppc /usr/sbin/httpd'


See ${prefix}/share/doc/speedycgi/README for further details."
