use strict;
use ExtUtils::MakeMaker;
    require 'src/';
    import SpeedyMake qw(%write_makefile_common);

print <<END;

Optional mod_speedycgi support.

Mod_speedycgi increases performance under Apache by avoiding the fork/exec
overhead associated with each request under normal SpeedyCGI.  However, it
requires a working copy of "apxs" in your path, Apache with mod_so
support, and additional Apache configuration.

print "Compile mod_speedycgi (default no)? ";

my @dirs = qw(src speedy_backend speedy);
my $macro = $write_makefile_common{macro};
my $apache_module = 0;
if (<STDIN> =~ /y/i) {
    die "ERROR: Command 'apxs -q CC' failed.\n"
	unless $macro->{APACHE_APXS_WORKS};
    print "Compiling for Apache version $macro->{APACHE_VERSION}\n";
    push(@dirs, $macro->{MOD_SPEEDYCGI_DIR});
    $apache_module = 1;

    NAME		=> 'CGI::SpeedyCGI',
    VERSION_FROM	=> 'src/SpeedyCGI.src',
    EXE_FILES		=> [qw(speedy/speedy speedy_backend/speedy_backend)],
    CONFIGURE		=> sub { return {DIR=>\@dirs} },
    PM			=> {'src/'=>'$(INST_LIBDIR)/'},
    MAN1PODS		=> {},
    MAN3PODS		=> {},
    dist		=> {DIST_DEFAULT => 'mydist'},
    realclean		=> {FILES => 'README README.html lib'},

package MY;

use ExtUtils::Embed;

sub postamble {
    my $extra = SpeedyMake->optdefs_cmds('src');
    my $test_install_extra;
    if ($apache_module) {
	my $mod_dir = $macro->{MOD_SPEEDYCGI_DIR};
	$extra .=
	    "\ninstall ::\n\tcd $mod_dir && \$(MAKE) install\n";
	$test_install_extra =
	    "\t\@cd $mod_dir && \$(MAKE) test_install \$(PASTHRU)\n";

	@cd speedy && $(MAKE) test_install $(PASTHRU)
' .
$test_install_extra .

mydist: README README.html lib/CGI/ readable tardist

	chown -R $(USER) .
	chmod -R u+w,go-w,go+r .

README: src/
	cd src && $(PERL) -e "use Pod::Text; pod2text(-80)" < >../README

README.html: src/
	cd src && pod2html >../README.html && $(RM_F) pod2h*

lib/CGI/ src/
	$(MKPATH) lib/CGI
	$(CP) src/ lib/CGI/

MAKE_INDEX = $(PERL) -w ./util/build_index $(VERSION)

rpm: package

rpms: rpm

solpkg: package

sunpkg: solpkg

bsdpkg: package

package: all README README.html
	@echo "*** Package files can be found in the binaries directory"


' . $extra;