# $Id: Makefile.PL,v 1.8.4.2 2002/06/10 11:41:44 jwalt Exp $ package AxKit; # file Makefile.PL use strict; use ExtUtils::MakeMaker; use Text::Wrap (); use Cwd; use Config; use vars qw($DEBUG $is_Win32 $DEVNULL); require 5.005; sub wrap ($) { my $text = shift; $text =~ s/^\s+//; $text =~ s/\s+$//; Text::Wrap::wrap('', '', $text) . "\n\n"; } my @DIRS = ('./lib/Apache/AxKit'); my $from_dir = cwd; ###################################################### # Standard bits required for have_library and friends my %config; $|=1; # flush output while($_ = shift @ARGV) { my ($k, $v) = split /=/, $_, 2; $config{$k} = $v; } $DEBUG = delete $config{DEBUG}; ###################################################### if (!have_module('mod_perl', '1.17')) { die wrap(<new->inc; if ($DEBUG) { print "calling WriteMakefile with config:\n"; foreach my $k (keys %config) { print "$k = $config{$k}\n"; } } my %prereq_pm = %{delete $config{PREREQ_PM}||{}}; unless ($Apache::MyConfig::Setup{PERL_USELARGEFILES} == 1) { $config{CCFLAGS} = strip_lfs($config{CCFLAGS}); } foreach my $k (keys %config) { push @ARGV, "$k=$config{$k}"; } %config = () if $] > 5.00560; rm_f($DEVNULL) if $is_Win32; WriteMakefile( 'NAME' => __PACKAGE__, 'VERSION_FROM' => 'lib/AxKit.pm', 'AUTHOR' => 'AxKit.com Limited - http://axkit.com/', 'ABSTRACT' => 'AxKit is an XML Application Server for mod_perl', 'DIR' => [ @DIRS ], 'OBJECT' => '$(O_FILES)', %config, PREREQ_PM => \%prereq_pm, ); ################################################################# # Functions ################################################################# use Config; use Cwd; use Symbol; use File::Spec; use vars qw/$DEVNULL $is_Win32 $RUNNING_UNDER_CPAN/; BEGIN { $is_Win32 = ($^O =~ /Win32/); if ($is_Win32) { $DEVNULL = 'DEVNULL'; } else { $DEVNULL = eval { File::Spec->devnull }; if ($@) { $DEVNULL = '/dev/null' } } my $cwd = cwd(); if ($cwd =~ /cpan/i) { $RUNNING_UNDER_CPAN = 1; } else { $RUNNING_UNDER_CPAN = $ENV{RUNNING_UNDER_CPAN} || 0; } } sub strip_lfs { my($cflags) = @_; return $cflags unless $Config{uselargefiles}; my $lf = $Config{ccflags_uselargefiles} || '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'; $cflags =~ s/$lf//; $cflags; } sub rm_f { my @files = @_; my @realfiles; foreach (@files) { push @realfiles, glob($_); } if (@realfiles) { chmod(0777, @realfiles); unlink(@realfiles); } } sub rm_fr { my @files = @_; my @realfiles; foreach (@files) { push @realfiles, glob($_); } foreach my $file (@realfiles) { if (-d $file) { # warn("$file is a directory\n"); rm_fr("$file/*"); rm_fr("$file/.exists"); rmdir($file) || die "Couldn't remove $file: $!"; } else { # warn("removing $file\n"); chmod(0777, $file); unlink($file); } } } sub xsystem { my $command = shift; if ($DEBUG) { print $command, "\n"; if (system($command) != 0) { die "system call to '$command' failed"; } return 1; } open(OLDOUT, ">&STDOUT"); open(OLDERR, ">&STDERR"); open(STDOUT, ">$DEVNULL"); open(STDERR, ">$DEVNULL"); my $retval = system($command); open(STDOUT, ">&OLDOUT"); open(STDERR, ">&OLDERR"); if ($retval != 0) { die "system call to '$command' failed"; } return 1; } sub backtick { my $command = shift; if ($DEBUG) { print $command, "\n"; my $results = `$command`; chomp $results; if ($? != 0) { die "backticks call to '$command' failed"; } return $results; } open(OLDOUT, ">&STDOUT"); open(OLDERR, ">&STDERR"); open(STDOUT, ">$DEVNULL"); open(STDERR, ">$DEVNULL"); my $results = `$command`; my $retval = $?; open(STDOUT, ">&OLDOUT"); open(STDERR, ">&OLDERR"); if ($retval != 0) { die "backticks call to '$command' failed"; } chomp $results; return $results; } sub try_link0 { my ($src, $opt) = @_; my $cfile = gensym(); # local $config{LIBS}; # $config{LIBS} .= $opt; unless (mkdir(".testlink", 0777)) { rm_fr(".testlink"); mkdir(".testlink", 0777) || die "Cannot create .testlink dir: $!"; } chdir(".testlink"); open($cfile, ">Conftest.xs") || die "Cannot write to file Conftest.xs: $!"; print $cfile < #include #include #ifdef __cplusplus } #endif EOT print $cfile $src; print $cfile <Conftest.pm") || die "Cannot write to file Conftest.pm: $!"; print $cfile <<'EOT'; package Conftest; $VERSION = 1.0; require DynaLoader; @ISA = ('DynaLoader'); bootstrap Conftest $VERSION; 1; EOT close($cfile); open($cfile, ">Makefile.PL") || die "Cannot write to file Makefile.PL: $!"; print $cfile <<'EOT'; use ExtUtils::MakeMaker; my %config; while($_ = shift @ARGV) { my ($k, $v) = split /=/, $_, 2; $config{$k} = $v; } WriteMakefile(NAME => "Conftest", VERSION_FROM => "Conftest.pm", %config); EOT close($cfile); open($cfile, ">test.pl") || die "Cannot write to file test.pl: $!"; print $cfile < 1; } END { ok(\$loaded) } use Conftest; \$loaded++; EOT close($cfile); xsystem("$^X Makefile.PL " . join(' ', map { "'$_=$config{$_}'" } keys %config)); xsystem("$Config{make} test 'OTHERLDFLAGS=$opt'"); } sub try_link { my $start_dir = cwd(); my $result = eval { try_link0(@_); }; warn $@ if $DEBUG && $@; chdir($start_dir); rm_fr(".testlink"); return $result; } sub have_library { my ($lib, $func) = (@_, "blank"); printf("checking for %s() in -l%s... ", $func, $lib) if $func ne "blank"; printf("looking for -l%s... ", $lib) if $func eq "blank"; my $result; if ($func) { my $libs = $is_Win32 ? " $lib.lib " : "-l$lib"; if ($is_Win32) { $result = try_link(<<"SRC", $libs); #include #include blank() { return 0; } int t() { ${func}(); return 0; } SRC unless ($result) { $result = try_link(<<"SRC", $libs); #include #include blank() { return 0; } int t() { void ((*p)()); p = (void ((*)()))${func}; return 0; } SRC } } else { $result = try_link(<<"SRC", $libs); blank() { return 0; } int t() { ${func}(); return 0; } SRC } } unless ($result) { print "no\n"; return 0; } if ($func ne "main") { $config{DEFINE} .= uc(" -Dhave_$func"); } print "yes\n"; return 1; } sub have_module { my ($module, $version) = (@_, 0); printf("checking for module %s >= version %s... ", $module, $version); print "eval(\"package Foo; use $module $version;\")\n" if $DEBUG; eval "package Foo; use $module $version;"; if ($@) { print $@ if $DEBUG; print "no\n"; return 0; } print "yes\n"; return 1; } sub test_module { my ($module, $version, $reason) = @_; unless (have_module($module, $version)) { if ($RUNNING_UNDER_CPAN) { if (prompt("Add $module to list of modules to install?", 'Y') =~ /^y/i) { $config{PREREQ_PM}{$module} = $version; return 1; } } else { print wrap($reason); return 0; } } return 1; } sub is_apache { my $path = shift; return unless $path; if (-e $path && -x _) { my $version = eval { backtick("$path -v") }; if (!$@) { $version =~ /Server version: Apache/ && return 1; } } warn("No apache httpd found at $path\n"); return; }