Codebase list libapache2-mod-perl2 / upstream/2.0.5 Makefile.PL
upstream/2.0.5

Tree @upstream/2.0.5 (Download .tar.gz)

Makefile.PL @upstream/2.0.5raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
use 5.006;
use strict;
use warnings FATAL => 'all';

# useful for sub-Makefile.PL's to know whether they are invoked
# directly or via the top level Makefile.PL
$ENV{MOD_PERL_2_BUILD} = 1;

use constant MIN_HTTPD_VERSION_DYNAMIC => '2.0.47';
use constant MIN_HTTPD_VERSION_STATIC  => '2.0.51';

my($old_modperl_version, $old_modperl_pm, $old_Apache2_pm);

BEGIN {
    eval {
        my $old_mp2 = eval { require Apache2 };
        require mod_perl;
        if ($mod_perl::VERSION < 1.999_22 && $old_mp2) {
            $old_modperl_version = $mod_perl::VERSION;
            $old_modperl_pm = delete $INC{'mod_perl.pm'};
            $old_Apache2_pm = delete $INC{'Apache2.pm'};
        }
    };

}

use lib qw(lib Apache-Test/lib);

use Config;
use File::Spec::Functions;
use File::Spec;
use DirHandle ();
use File::Copy 'cp';
use File::Basename qw(basename dirname);
use File::Find ();

use Apache2::Build ();
use Apache::TestSmokePerl ();
use Apache::TestTrace;
use ModPerl::TestReport ();
use ModPerl::TestRun ();
use ModPerl::Code ();
use ModPerl::BuildMM ();

use constant WIN32 => Apache2::Build::WIN32;
use constant BUILD_APREXT => Apache2::Build::BUILD_APREXT;

our $VERSION;

my $build = Apache2::Build->new(init => 1);
my $code  = ModPerl::Code->new;

sub UNATTENDED() { $build->{MP_PROMPT_DEFAULT} || ! -t STDIN }

win32_fetch_apxs() if WIN32;

configure();
perl_version_check($build);

local %ModPerl::BuildMM::PM = (
    'lib/typemap' => 'blib/lib/Apache2/typemap',
);

# these h files need to be installed system-wide so 3rd party XS
# extensions can use them
my @xs_h_files = map catfile("xs", $_),
    qw(modperl_xs_sv_convert.h modperl_xs_typedefs.h modperl_xs_util.h
       APR/PerlIO/modperl_apr_perlio.h);
my @exe_files =  map "bin/$_", qw(mp2bug);

ModPerl::BuildMM::WriteMakefile(
    NAME          => 'mod_perl2',
    VERSION       => $VERSION,
    DISTNAME      => 'mod_perl',
    NO_META       => 1,
    ABSTRACT_FROM => 'lib/mod_perl2.pm',
    EXE_FILES     => \@exe_files,
    DEFINE        => get_DEFINE(),
    macro         => {
        MODPERL_SRC           => $code->path,
        MODPERL_MAKEFILE      => basename($build->default_file('makefile')),
        PERL                  => $build->perl_config('perlpath'),
        MOD_INSTALL           => ModPerl::BuildMM::mod_install(),
        MODPERL_AP_INCLUDEDIR =>
            $build->ap_destdir($build->install_headers_dir),
        MODPERL_XS_H_FILES    => join(" \\\n\t", @xs_h_files),
    },
    clean     => {
        FILES => "@{ clean_files() }",
    },
    dist      => {
        DIST_DEFAULT => 'mydist',
        COMPRESS     => 'gzip -9f', SUFFIX=>'gz',
    },
);

post_configure();

sub get_DEFINE {

    my $opt_define = '';

    # do we have apr libs?
    # XXX: this define is really needed in xs/APR/APR/Makefile.PL, but this 
    # top-level Makefile.PL overrides MY::pasthru, and defines DEFINE= which
    # overrides any local definition, not sure what's the right fix, for
    # now just define it here (should it define PASTHRU_DEFINE instead?)
    $opt_define = '-DMP_HAVE_APR_LIBS' if $build->apru_link_flags;

    # preserve any DEFINE opts from outside and combine them with our
    # local DEFINE
    @ARGV = grep defined,
        map { (/^DEFINE=(.*)/ && ($opt_define .= " $1")) ? undef : $_ } @ARGV;

    return $opt_define;
}

sub configure {

    # mod_perl test suite relies on having Apache-Test bundled with
    # the mod_perl source, since any pre-installed version may not do
    # the right thing
    unless (-d "Apache-Test") {
        error "Can't find a sub-directory Apache-Test. " .
            "Make sure that you are using a complete source distribution";
        exit 1;
    }

    set_modperl_version();

    if ($old_modperl_version) {
        (my $old_modperl_version_str = $old_modperl_version)
            =~ s/(\d\d\d?)(\d\d)/$1_$2/;
        my $vstring = "mod_perl/$old_modperl_version_str";
        print "$vstring installation detected...";

        my $prefix;
        /^PREFIX=(.*)/ && $1 && ($prefix = canonpath glob($1)) for @ARGV;

        # check that it's a full path
        my $path = canonpath $old_modperl_pm;
        # XXX: doesn't handle relative paths yet
        # if PREFIX=/foo/bar is used, and it's not the same as the
        # path where mod_perl < 1.999_22 is installed
        if ($prefix && $path !~ /^$prefix/) {
            print "ok (will install mod_perl/$VERSION into PREFIX=$prefix, " .
                "no collision)\n";
        }
        else {
            my $note = '';
            if ($old_Apache2_pm) {
                $note .= "Conflicting file: $old_Apache2_pm\n";
            }
            if ($path =~ /Apache2/ or $old_modperl_version > 1.99) {
                my $dir = dirname $path;
                # was it installed into the top-level?
                $dir = catdir $dir, 'Apache' unless $path =~ /Apache2/;
                $note .= "Conflicting dir: $dir\n" if -d $dir;
            }

            print " not ok\n\n";
            print <<EOI;
Cannot install mod_perl/$VERSION on top of $vstring
due to a major API change between mod_perl 1.999_21 and 1.999_22.

$note
Please nuke the prior mod_perl installation from your site_lib,
use a different perl to run the installation process, or use the
PREFIX option when creating your Makefile.  See:

  http://perl.apache.org/docs/2.0/rename.html

for more details.

aborting...
EOI
                    exit 1;
        }
    }
    else {
        print "no conflicting prior mod_perl version found - good.\n";

    }

    # On Win32, in order to decouple APR::* from mod_perl.so, we
    # make up a static library MP_APR_LIB of the symbols required from
    # src/modules/perl/*.c (see xs/APR/aprext/Makefile.PL), and
    # then link APR/APR::* against this library. The reason for
    # this is that, unlike Unix, if we had linked APR/APR::* against
    # the mod_perl lib, then use of APR/APR::* would demand mod_perl.so
    # be available, even if these symbols are supplied by another
    # loaded library (which is done for unix by APR.so - see
    # xs/APR/APR/Makefile.PL). This also means we must ensure the
    # MP_APR_LIB lib is built before any of the APR/APR::* modules 
    # (see the aprext target in the MY::top_targets sub below), as 
    # symbols must get resolved at link time.

    if (BUILD_APREXT()) {
        require File::Path;
        #Makefile.PL's in WrapXS/ just need to pass the -e mod_perl.lib test
        #the real mod_perl.lib will be in place when WrapXS/ dll's are
        #actually linked
        # this must also be done for aprext.lib, build in xs/APR/aprext/;
        # we must create a dummy aprext.lib to pass the -e test.
        my $lib1 = catfile qw(src modules perl), 
            $build->{MP_LIBNAME} . $Config{lib_ext};
        my ($apr_blib, $full_libname) = $build->mp_apr_blib();
        my $lib2 = catfile $apr_blib, $full_libname;
        unless (-d $apr_blib) {
            File::Path::mkpath($apr_blib) or die "mkdir $apr_blib failed: $!";
        }
        foreach my $lib ($lib1, $lib2) {
            unless (-e $lib) {
                open my $fh, '>', $lib or die "open $lib: $!";
                print $fh "#this is a dummy file to trick MakeMaker";
                close $fh;
            }
        }
    }

    system_sanity_check();

    my $min_httpd_version = $build->should_build_apache
        ? MIN_HTTPD_VERSION_STATIC
        : MIN_HTTPD_VERSION_DYNAMIC;

    if ($build->{MP_APXS}) {
        debug "Using APXS => $build->{MP_APXS}";
    }
    elsif ($build->{MP_AP_PREFIX}) {
        if (my $reason = $build->ap_prefix_invalid) {
            error "invalid MP_AP_PREFIX: $reason";
            exit 1;
        }
        debug "Using Apache prefix => $build->{MP_AP_PREFIX}";
    }
    else {
        unless ($build->{MP_USE_STATIC}) {
            # may populate $build->{MP_APXS}
            prompt_for_apxs($build);
        }
    }

    unless ($build->{MP_APXS} or $build->{MP_AP_PREFIX}) {
        my $ok = 0;
        for my $path ($build->find) {
            $build->dir($path);
            my $mmn = $build->module_magic_number;
            my $v   = $build->httpd_version;
            next unless $v;
            next if $v lt $min_httpd_version;
            $ok++ if $build->prompt_y("Configure mod_perl with $path?");
            last if $ok;
        }
        until ($ok) {
            my $ask = "Please provide the location of the Apache directory:";
            my $ans = $build->prompt($ask) || "";
            # strip leading/closing spaces
            $ans =~ s/^\s*|\s*$//g;
            if (defined $ans and -d $ans) {
                $build->dir($ans);
                $ok++;
            }
            else {
                error "Can't find dir '$ans'";
                last if UNATTENDED;
            }
        }
    }

    if ($build->should_build_apache) {
        $build->configure_apache();
    }

    my $httpd_version = $build->httpd_version;
    unless ($httpd_version) {
        error 'Unable to determine server version, aborting.';
        if ($build->{MP_APXS} || $build->{MP_AP_PREFIX}) {
            my $what = $build->{MP_APXS} ? 'MP_APXS' : 'MP_AP_PREFIX';
            error "Invalid $what specified?";
        }
        else {
            error 'Please specify MP_APXS or MP_AP_PREFIX.';
        }
        exit(1);
    }

    if ($httpd_version lt $min_httpd_version) {
        error "Apache/$httpd_version not supported, " .
              "$min_httpd_version or higher is required";
        exit(1);
    }

    printf "Configuring Apache/%s mod_perl/%s Perl/v%vd\n",
        $httpd_version, $VERSION, $^V;

    my $apr_config = $build->get_apr_config; #cache it

    # we need to know where apr-config and apu-configs are
    # which sometimes aren't placed into the same dir with apxs/httpd
    # XXX: need to fix that for WIN32
    # XXX: when the source tree is used, there is not much use for apr-config
    unless (WIN32 || $build->apr_config_path || $build->httpd_is_source_tree) {
        error "can't find 'apr-config', please pass " .
            "MP_APR_CONFIG=/full/path/to/apr-config to 'perl Makefile.PL'";
        exit 1;
    }

    for (@{ clean_files() }) {
        debug "unlink...$_" if -e $_ && unlink;
    }

    #ModPerl::BuildMM will use Apache2::BuildConfig in subdir/Makefile.PL's
    $build->save;

    ModPerl::TestRun->generate_script;
    ModPerl::TestReport->generate_script;
    Apache::TestSmokePerl->generate_script;

    my $tables_dir = tables_dir($httpd_version);

    unshift @INC, $tables_dir;

    if ($build->{MP_GENERATE_XS}) {
        debug "generating XS code using $tables_dir...";
        xs_generate($httpd_version);
    }

    install_typemap();
}

sub prompt_for_apxs {
    my $build = shift;

    print <<EOI;

Next we need to know where the 'apxs' script is located. This script
provides a lot of information about the Apache installation, and makes
it easier to find things on your system. Normally it's located in the
same directory as the 'httpd' executable.

If you don't yet have Apache installed you can build Apache against
the Apache source code, but you won't be able to run the test suite (a
very important step). Therefore you may want to install Apache before
proceeding.

EOI

    my $prompt = "\nPlease provide a full path to 'apxs' executable\n" .
        "(press Enter if you don't have it installed):";
    while (1) {
        my $ans = $build->prompt($prompt) || "";

        print "\n\n";

        # strip leading/closing spaces
        $ans =~ s/^\s*|\s*$//g;

        last unless length $ans; # skip

        unless (File::Spec->file_name_is_absolute($ans)) {
            warn "The path '$ans' is not an absolute path. " .
                "Please specify an absolute path.\n";
            next;
        }

        warn("'$ans' doesn't exist.\n"),     next unless -e $ans;
        warn("'$ans' is not a file.\n"),     next unless -f _;
        warn("'$ans' is not executable.\n"), next unless -x _;

        $build->{MP_APXS} = $ans;
        last;
    }
}

sub post_configure {

    #now have any data subdir/Makefile.PL's save, e.g. XS
    $build = Apache2::Build->build_config;

    $build->write_src_makefile;
    $build->save_ldopts;

    $code->generate($build);

    for my $type (qw(DSO STATIC)) {
        next unless $build->{"MP_USE_$type"};
        warning "mod_perl \L$type\E library will be built as ".
          $build->{"MODPERL_LIB_$type"};
    }

    if ($build->is_dynamic) {
        warning
            "You'll need to add the following to httpd.conf:",            "",
            "  LoadModule perl_module modules/$build->{MODPERL_LIB_DSO}", "",
            "depending on your build, mod_perl might not live in",
            "the modules/ directory.\n";
        if ($build->{MP_APXS}) {
            warning 
                "Check the results of",                                   "",
                "  \$ $build->{MP_APXS} -q LIBEXECDIR",                   "",
                "and adjust the LoadModule directive accordingly.\n";
        }
    }

    $build->save;
}

sub tables_dir {
    my $httpd_version = shift;

    my $tables_version = 'current';
    #XXX: support versioning
    #$httpd_version =~ /-dev$/ ? 'current' : $httpd_version;

    my $tables_dir = "xs/tables/$tables_version";
}

sub xs_generate {
    require ModPerl::WrapXS;

    my $xs = ModPerl::WrapXS->new;

    $xs->generate;

    #shift @INC; #ModPerl::Code needs this path too
}

sub install_typemap {
    my $to_file = 'lib/typemap';

    open my $to_fh, ">$to_file" or die "open $to_file: $!";

    for my $from_file (qw(WrapXS/typemap xs/typemap)) {
        open my $from_fh, $from_file or die "open $from_file: $!";
        cp $from_fh, $to_fh;
        close $from_fh;
    }

    close $to_fh or die "close $to_file: $!";
}

sub echo_cmd {
    my $cmd = shift;
    print "$cmd\n";
    system($cmd) == 0 or exit(1);
}

sub clean_files {
    my $path = $code->path;

    my @files = ();
    File::Find::find(sub { push @files, "$File::Find::dir/$_" if -f $_},
                     "WrapXS") if -d "WrapXS";

    push @files, map { "xs/$_.h" }
        qw(modperl_xs_typedefs modperl_xs_sv_convert);

    return [@{ $build->clean_files },
            @files,
            qw(lib/typemap
               lib/ModPerl/MethodLookup.pm
               lib/ModPerl/DummyVersions.pm
               t/htdocs/vhost/error_log
               t/SMOKE
               t/TEST
               t/REPORT
              ),
            <t/htdocs/hooks/startup/open_logs*>,
            <t/htdocs/hooks/startup/post_config*>,
            <xs/*.exp>,
            <xs/*.def>,
            map { "$path/$_"} @{ $code->clean_files }
           ];
}

sub set_modperl_version {
    require './lib/mod_perl2.pm';

    $VERSION = $mod_perl2::VERSION_TRIPLET;

    open my $fh, 'Changes';
    while (<$fh>) {
        if (/^=item.*-(dev|rc\d+)/) {
            $VERSION .= "-$1";
            last;
        }
        last if /^=item/;
    }
    close $fh;

    $build->{VERSION}     = $VERSION;
    $build->{API_VERSION} = $mod_perl2::API_VERSION;
}

# needs to be run after configure() when apxs is setup
sub perl_version_check {
    my $build = shift;

    my $perl_version = $];
    $perl_version =~ s/5.00(\d)(?:00(\d))?/"5.$1." . ($2||0)/e;
    my $perl_threads = Apache2::Build::PERL_HAS_ITHREADS ? "w/" : "w/o";
    my $perl_string = "Using Perl $perl_version $perl_threads ithreads";
    my $mpm = $build->mpm_name();

    # certain mpms require perl 5.8.0+ w/ithreads
    if ($build->mpm_is_threaded()) {
        my @fail;
        push @fail, "Perl 5.8 or higher"
            unless $] >= 5.008;
        push @fail, "Perl built with ithreads (build perl with -Dusethreads)"
            unless Apache2::Build::PERL_HAS_ITHREADS();
        if (@fail) {
            error "$perl_string and '$mpm' mpm httpd.",
                "Failed requirements:",
                join "", map {"  - $_\n"} @fail;
            exit 1;
        }
    }
    else {
        # before 5.8.2, perl_shutdown is incomplete (in the case of ithreads 
        # each PerlInterpreter * gets tossed so it works)
        if ($build->should_build_apache && !Apache2::Build::PERL_HAS_ITHREADS) {
            # before 5.8.2, perl_shutdown is incomplete
            if ($] < 5.008_002) {
                error "static $mpm mpm requires a threaded ".
                      "perl 5.6.1-5.8.1 or any perl 5.8.2+";
                exit 1;
            }
        }
    }

    if ($] < 5.006_001) {
        error "$perl_string. You need at least Perl 5.6.1";
        exit 1;
    }

    if ($] >= 5.007 and $] < 5.008) {
        error "$perl_string.",
            "5.7.x development versions of Perl are no longer supported",
            "Upgrade to Perl 5.8.0 or higher";
        exit 1;
    }

    if ($Config{usemultiplicity} xor $Config{usethreads}) {
        error "mod_perl does not currently support multiplicity without ".
	      "ithreads.";
        if ($build->mpm_is_threaded()) {
	    error "Please recompile Perl with -Duseithreads and ".
	          "-Dusemultiplicity";
        } else {
	    error "Please recompile Perl with either -Duseithreads and ".
	          "-Dusemultiplicity or -Uuseithreads and -Uusemultiplicity";
	}
        exit 1;
    }
}

sub system_sanity_check {
    return if WIN32;

    my $ccflags = $build->perl_config('ccflags');
    for (split /\s+/, $ccflags) {
        next unless s/^-I//;
        my $header = "$_/ap_mmn.h";
        if (-e $header) {
            $build->phat_warn(<<EOF);
Apache headers found in unexpected location: ``$_'', suggestions:
   *) Remove via ``rpm -e apache''
   *) Remove by hand
   *) Complain to your os vendor about their poor layout choice
   *) Complain to your sysadmin about their poor layout choice
EOF
        }
    }

    $build->lib_check('gdbm');
    malloc_check();
    os_check();
}

sub malloc_check {
    return unless $build->is_dynamic;
    return unless $build->perl_config('usemymalloc') eq 'y';

    my $abort = $^O eq 'solaris';

    my $bincompat = $build->perl_config('bincompat5005');

    if ($bincompat) {
             $build->phat_warn(<<EOF, $abort);
Your current configuration will most likely trigger core dumps, suggestions:
   *) Do not configure mod_perl as a DSO
   *) Rebuild Perl without malloc pollution (Configure -Ubincompat5005)
EOF
    }
}

sub os_check {
    my $check = \&{"os_check_$^O"};
    return unless defined &$check;
    $check->()
}

sub os_check_hpux {
    my $ccflags = $build->perl_config('ccflags');
    my $ld = $build->perl_config('ld');

    if ($build->is_dynamic and $ld eq 'ld') {
        unless ($ccflags =~ /\+z/i) {
            $build->phat_warn(<<EOF);
mod_perl is unlikely to link with your libperl, suggestions:
    *) Rebuild Perl with Configure -Accflags=+Z ...
EOF
        }
    }
}

sub win32_fetch_apxs {
    return unless (my $prefix = $build->{MP_AP_PREFIX});
    my $script = catfile($build->{cwd}, 'build', 'win32_fetch_apxs');
    my @args = ($^X, $script, "--with-apache2=$prefix");
    system(@args) == 0 or die "system @args failed: $?";
}


package MY;

use Config;
use constant WIN32 => $^O eq 'MSWin32';
use constant BUILD_APREXT => Apache2::Build::BUILD_APREXT;

sub MY::top_targets {
    my $self = shift;
    my $string = $self->ModPerl::BuildMM::MY::top_targets;

    if (BUILD_APREXT) {
        ModPerl::MM::add_dep(\$string, pure_all => 'aprext');

        # must not import File::Spec functions inside MY, it breaks
        # 5.6.x builds
        my ($apr_blib, $full_libname) = $build->mp_apr_blib();
        my $from = File::Spec->catfile($apr_blib, $full_libname);
        (my $ap_lib = $build->ap_includedir()) =~ s{include$}{lib};
        my $to = File::Spec->catfile($ap_lib, $full_libname);
        my $src_dir = File::Spec->catdir(qw(xs APR), 'aprext');
        $string .= <<"EOF";

aprext:
	cd "$src_dir" && \$(MAKE) all \$(PASTHRU) LINKTYPE="static"

aprext_install:
	\@\$(MKPATH) "$ap_lib"
	\$(CP) "$from" "$to"

EOF
    }

    if ($build->should_build_apache) {
        ModPerl::MM::add_dep(\$string, pure_all => 'ap_build');
        $string .= <<"EOF";
ap_build: modperl_lib
	cd "$build->{MP_AP_PREFIX}" && make

ap_install: ap_build
	cd "$build->{MP_AP_PREFIX}" && make DESTDIR=\$(DESTDIR) install
EOF
    }

    ModPerl::MM::add_dep(\$string, pure_all => 'modperl_lib');

    $string .= <<'EOF';

source_scan:
	$(PERL) build/source_scan.pl

xs_generate:
	$(PERL) build/xs_generate.pl

bugreport:
	$(PERL) bin/mp2bug

etags:
	$(SHELL) build/make_etags

modperl_lib:
	cd "$(MODPERL_SRC)" && $(MAKE)

modperl_lib_install:
	cd "$(MODPERL_SRC)" && $(MAKE) DESTDIR=$(DESTDIR) install

modperl_xs_h_install:
	@$(MKPATH) $(DESTDIR)$(MODPERL_AP_INCLUDEDIR)
	$(CP) $(MODPERL_XS_H_FILES) $(DESTDIR)$(MODPERL_AP_INCLUDEDIR)

modperl_src_clean:
	cd "$(MODPERL_SRC)" && $(MAKE) clean

EOF

    # $(ECHO) was broken before 6.10_01
    # XXX: if ever require 6.11 we can remove this workaround
    require ExtUtils::MakeMaker;
    (my $mm_ver = ExtUtils::MakeMaker->VERSION) =~ s/_\d+//;
    my $say = $mm_ver > 6.10
        ? '@$(ECHO)'
        : '@$(PERL) -le "print shift"';

    $string .= <<"EOF";
modperl_banner:
	$say "+--------------------------------------------------------------+"
	$say "|                                                              |"
	$say "| For details on getting started with mod_perl 2, see:         |"
	$say "|                                                              |"
	$say "|   http://perl.apache.org/docs/2.0/user/intro/start_fast.html |"
	$say "|                                                              |"
	$say "|                                                              |"
	$say "| Found a bug?  File a bug report:                             |"
	$say "|                                                              |"
	$say "|   http://perl.apache.org/bugs/                               |"
	$say "|                                                              |"
	$say "+--------------------------------------------------------------+"

EOF

    $string;
}

sub MY::install {
    my $self = shift;
    my $string = $self->MM::install(@_);

    for my $kind ('', '_site', '_vendor') {
        ModPerl::MM::add_dep(\$string, "pure${kind}_install" => 'ap_install')
	    if $build->should_build_apache;
	ModPerl::MM::add_dep(\$string, "pure${kind}_install" => 'modperl_lib_install');
	ModPerl::MM::add_dep(\$string, "pure${kind}_install" => 'modperl_xs_h_install');
	# ModPerl::MM::add_dep(\$string, "pure${kind}_install" => 'aprext_install')
	#    if BUILD_APREXT;

	ModPerl::MM::add_dep_after(\$string, "install$kind", "doc${kind}_install", 'modperl_banner');

	# glue_pods target must come first
	ModPerl::MM::add_dep(\$string, "pure${kind}_install" => 'glue_pods');
    }

    $string;
}

sub MY::clean {
    my $self = shift;
    my $string = $self->MM::clean(@_);
    ModPerl::MM::add_dep(\$string, clean => 'modperl_src_clean');
    ModPerl::MM::add_dep(\$string, clean => 'test_clean');
    $string;
}

sub MY::test {

    my $preamble;
    if (Apache::TestConfig::WIN32) {
        # need to add the location of Apache's dlls to the PATH
        my $ap_bindir = $build->apr_bindir() || '';
        unless ($ap_bindir) {
            $ap_bindir = File::Spec->catdir($build->{MP_AP_PREFIX}, 'bin')
                if $build->{MP_AP_PREFIX};
        }
        $preamble = <<EOF;
PATH = \$(PATH);$ap_bindir
EOF
    }
    else {
        # PASSENV confuses the Win32 command-line build
        my $env = Apache::TestConfig->passenv_makestr();
        $preamble = <<EOF;
PASSENV = $env
EOF
    }

    return $preamble . <<'EOF';
TEST_VERBOSE = 0
TEST_FILES =

test_clean :
	$(FULLPERL) -I$(INST_ARCHLIB) -I$(INST_LIB) \
	t/TEST -clean

run_tests : test_clean
	$(PASSENV) \
	$(FULLPERL) -I$(INST_ARCHLIB) -I$(INST_LIB) \
	t/TEST -bugreport -verbose=$(TEST_VERBOSE) $(TEST_FILES)
	$(MAKE) -k run_subtests

run_subtests ::
	$(MAKE) -C ModPerl-Registry test

run_subtests ::
	$(MAKE) -C Apache-Reload test

run_subtests ::
	$(MAKE) -C Apache-SizeLimit test

test :: pure_all run_tests test_clean
EOF

}

sub MY::postamble {
    my $self = shift;

    my $string = $self->ModPerl::BuildMM::MY::postamble;

    $string .= <<'EOF';
mydist : Apache-Test/META.yml mod_perl.spec manifest tardist

rpm: dist
	@[ -d $(PWD)/rpm ] || mkdir $(PWD)/rpm
	rpmbuild -ta --define "_rpmdir $(PWD)/rpm" \
                 --define "_srcrpmdir $(PWD)/rpm" \
                 $(DISTVNAME).tar.gz
	@mv $(PWD)/rpm/*/*.rpm $(PWD)/rpm/
	@rm -rf $(PWD)/rpm/*/
    
mod_perl.spec: build/make_rpm_spec
	$(PERL) build/make_rpm_spec

Apache-Test/META.yml:
	cd Apache-Test && make metafile

tag :
	svn copy  https://svn.apache.org/repos/asf/perl/modperl/branches/release/$(VERSION_SYM)  https://svn.apache.org/repos/asf/perl/modperl/tags/$(VERSION_SYM)
	svn copy  https://svn.apache.org/repos/asf/perl/modperl/docs/trunk https://svn.apache.org/repos/asf/perl/modperl/docs/tags/$(VERSION_SYM)
EOF

    return $string;
}

# this is a workaround so that ModPerl::MM will move MY::constants
# away, and Apache-Test/Makefile.PL which has its own MY::constants
# won't get complaints on MY::constants redefined
sub MY::constants {
    shift->ModPerl::BuildMM::MY::constants;
}

sub MY::tool_autosplit {
    '';
}

sub MY::manifypods {
    my $self = shift;
    my $ver = $self->{VERSION} || "";
    local $_ = $self->MM::manifypods(@_);
    s/pod2man\s*$/pod2man --release mod_perl-$ver/m;
    $_;
}

sub MY::pasthru {
    my $self = shift;
    chomp(my $str = $self->MM::pasthru);
    join $/, "$str\\",
    "\t".'PERL="$(PERL)"\\',
    "\t".'DEFINE="$(DEFINE)"',
    "";
}

sub MY::dist_basics {
    my $self = shift;
    my $str = $self->MM::dist_basics;

    $str =~ s/(\"?)-MExtUtils(::Manifest=mkmanifest)/-Ilib $1-MModPerl$2/;

    $str;
}