1use 5.005;
2
3use lib qw(lib);
4use Apache::Test5005compat;
5
6use strict;
7use warnings;
8
9# was this file invoked directly via perl, or via the top-level
10# (mp2) Makefile.PL? if top-level, this env var will be set
11use constant TOP_LEVEL => $ENV{MOD_PERL_2_BUILD};
12
13if (!TOP_LEVEL) {
14    # see if we are building from within mp root, add src lib if we are
15    eval { require File::Spec };
16    unless ($@) {
17        if ( -e File::Spec->catdir('..', 'lib') ) {
18
19            # building A-T from mp subdirectory, use the mp lib
20            unshift @INC, File::Spec->catdir('..', 'lib');
21        }
22    }
23}
24
25use ExtUtils::MakeMaker;
26use Symbol;
27use File::Find qw(finddepth);
28
29use Apache::TestMM qw(test clean); #enable 'make test and make clean'
30use Apache::TestRun;
31use Apache::TestTrace;
32use Apache::TestReport;
33use Apache::TestConfig ();
34use Apache::TestRunPerl;
35
36my $VERSION;
37set_version();
38
39Apache::TestMM::filter_args();
40
41my @scripts = qw(t/TEST);
42
43finddepth(sub {
44    return if $_ eq 'Apache-TestItSelf';
45    return unless /(.*?\.pl)\.PL$/;
46    push @scripts, "$File::Find::dir/$1";
47}, '.');
48
49for (@scripts) {
50    Apache::TestMM::generate_script($_);
51}
52Apache::TestReport->generate_script;
53
54my @clean_files =
55    qw(.mypacklist
56       t/TEST
57       t/REPORT
58       Makefile.old
59      );
60
61my %prereq = (
62    'File::Spec' => '0.8',
63    'Cwd'        => '2.06',
64);
65
66# Apache::TestServer uses Win32::Process on Windows.
67if ($^O =~ /MSWin32/i) {
68    $prereq{'Win32::Process'} = '0'
69}
70
71# Apache-Test/META.yml is excluded from mp2 distro to make PAUSE
72# indexer happy, but then perl Makefile.PL complains about a missing
73# META.yml, so autogenerate it if it wasn't in the distro
74my $no_meta = TOP_LEVEL ? 1 : 0;
75
76WriteMakefile(
77    NAME      => 'Apache::Test',
78    VERSION   => $VERSION,
79    PREREQ_PM => \%prereq,
80    NO_META   => $no_meta,
81    dist      => {
82        COMPRESS => 'gzip -9f', SUFFIX => 'gz',
83        PREOP   => 'find $(DISTVNAME) -type d -print|xargs chmod 0755 && ' .
84                   'find $(DISTVNAME) -type f -print|xargs chmod 0644',
85        TO_UNIX => 'find $(DISTVNAME) -type f -print|xargs dos2unix'
86    },
87    clean     => {
88        FILES => "@clean_files",
89    },
90);
91
92# after CPAN/CPANPLUS had a chance to satisfy the requirements,
93# enforce those (for those who run things manually)
94check_prereqs();
95
96sub check_prereqs {
97    my %fail = ();
98    for (sort keys %prereq) {
99        unless (chk_version($_, $prereq{$_})) {
100            $fail{$_} = $prereq{$_};
101        }
102    }
103    if (%fail) {
104        error "\nThe following Apache-Test dependencies aren't satisfied:",
105            map { "\t$_: $fail{$_}" } sort keys %fail;
106        error "Install those from http://search.cpan.org and try again";
107        exit 0;
108    }
109}
110
111sub chk_version {
112    my($pkg, $wanted) = @_;
113
114    no strict 'refs';
115    local $| = 1;
116
117    print "Checking for $pkg...";
118    (my $p = $pkg . ".pm") =~ s#::#/#g;
119    eval { require $p;};
120    print("not ok\n$@"), return if $@;
121
122    my $vstr = ${"${pkg}::VERSION"} ? "found v" . ${"${pkg}::VERSION"}
123        : "not found";
124    my $vnum = eval(${"${pkg}::VERSION"}) || 0;
125
126    print $vnum >= $wanted ? "ok\n" : " " . $vstr . "\n";
127
128    $vnum >= $wanted;
129}
130
131sub set_version {
132    $VERSION = $Apache::Test::VERSION;
133
134    my $fh = Symbol::gensym();
135    open $fh, 'Changes' or die "Can't open Changes: $!";
136    while (<$fh>) {
137        if(/^=item.*-(dev|rc\d+)/) {
138            $VERSION .= "-$1";
139            last;
140        }
141        last if /^=item/;
142    }
143    close $fh;
144}
145
146sub add_dep {
147    my($string, $targ, $add) = @_;
148    $$string =~ s/($targ\s+::)/$1 $add/;
149}
150
151no warnings 'redefine';
152sub MY::postamble {
153    my $self = shift;
154
155    my $q = ($^O =~ /MSWin32/i ? '"' : "'");
156
157    my $string = $self->MM::postamble;
158
159    $string .= <<"EOF";
160tag :
161	svn copy -m $q\$(VERSION_SYM) tag$q https://svn.apache.org/repos/asf/perl/Apache-Test/trunk https://svn.apache.org/repos/asf/perl/Apache-Test/tags/\$(VERSION_SYM)
162EOF
163
164    return $string;
165}
166
167
168
169sub MY::test {
170    my $self = shift;
171
172    # run tests normally if non root user
173    return $self->Apache::TestMM::test(@_) if (($> != 0) # root user
174        or (Apache::TestConfig::WINFU)); # win users
175        # or win32
176
177    return <<EOF
178test::
179\t\@echo
180\t\@echo Apache::Test tests cannot be run as the root user.
181\t\@echo Apache cannot spawn child processes as 'root', therefore
182\t\@echo the test suite must be run with a non privileged user.
183\t\@echo Please build Apache::Test as a non-privileged user to
184\t\@echo run the test suite.
185\t\@echo
186EOF
187}
188
189sub MY::constants {
190    my $self = shift;
191
192    my $string = $self->MM::constants;
193
194    # mp2 installs this into INSTALLSITEARCH, so in order to avoid
195    # problems when users forget 'make install UNINST=1', trick MM into
196    # installing pure perl modules to the sitearch location, when this is
197    # not installed as a part of mp2 build
198    if (!$ENV{MOD_PERL_2_BUILD}) {
199        $string .= <<'EOI';
200
201# install into the same location as mod_perl 2.0
202INSTALLSITELIB = $(INSTALLSITEARCH)
203DESTINSTALLSITELIB = $(DESTINSTALLSITEARCH)
204EOI
205    }
206
207    $string;
208}
209