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

print <<END;

Optional mod_persistentperl support.

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

print "Compile mod_persistentperl (default no)? ";

my @dirs = qw(src perperl_backend perperl);
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_PERSISTENTPERL_DIR});
    $apache_module = 1;

    NAME		=> 'PersistentPerl',
    VERSION_FROM	=> 'src/PersistentPerl.src',
    EXE_FILES		=> [qw(perperl/perperl perperl_backend/perperl_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 = PersistentMake->optdefs_cmds('src');
    my $test_install_extra;
    if ($apache_module) {
	my $mod_dir = $macro->{MOD_PERSISTENTPERL_DIR};
	$extra .=
	    "\ninstall ::\n\tcd $mod_dir && \$(MAKE) install\n";
	$test_install_extra =
	    "\t\@cd $mod_dir && \$(MAKE) test_install \$(PASTHRU)\n";

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

mydist: README README.html lib/ 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/ src/
	$(MKPATH) lib/CGI
	$(CP) src/ lib/

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;