]> git.donarmstrong.com Git - debhelper.git/blob - Debian/Debhelper/Buildsystem/perl_makemaker.pm
Pass CPPFLAGS and LDFLAGS to Makefile.PL and Build.PL
[debhelper.git] / Debian / Debhelper / Buildsystem / perl_makemaker.pm
1 # A debhelper build system class for handling Perl MakeMaker based projects.
2 #
3 # Copyright: © 2008-2009 Joey Hess
4 #            © 2008-2009 Modestas Vainius
5 # License: GPL-2+
6
7 package Debian::Debhelper::Buildsystem::perl_makemaker;
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib qw(compat);
11 use base 'Debian::Debhelper::Buildsystem::makefile';
12 use Config;
13
14 sub DESCRIPTION {
15         "Perl ExtUtils::MakeMaker (Makefile.PL)"
16 }
17
18 sub check_auto_buildable {
19         my $this=shift;
20         my ($step)=@_;
21
22         # Handles everything if Makefile.PL exists. Otherwise - next class.
23         if (-e $this->get_sourcepath("Makefile.PL")) {
24                 if ($step eq "configure") {
25                         return 1;
26                 }
27                 else {
28                         return $this->SUPER::check_auto_buildable(@_);
29                 }
30         }
31         return 0;
32 }
33
34 sub new {
35         my $class=shift;
36         my $this=$class->SUPER::new(@_);
37         $this->enforce_in_source_building();
38         return $this;
39 }
40
41 sub configure {
42         my $this=shift;
43         my @flags;
44         # If set to a true value then MakeMaker's prompt function will
45         # # always return the default without waiting for user input.
46         $ENV{PERL_MM_USE_DEFAULT}=1;
47         # This prevents  Module::Install from interactive behavior.
48         $ENV{PERL_AUTOINSTALL}="--skipdeps";
49
50         if ($ENV{CFLAGS} && ! compat(8)) {
51                 push @flags, "OPTIMIZE=$ENV{CFLAGS} $ENV{CPPFLAGS}";
52         }
53         if ($ENV{LDFLAGS} && ! compat(8)) {
54                 push @flags, "LD=$Config{ld} $ENV{LDFLAGS}";
55         }
56
57         $this->doit_in_sourcedir("perl", "Makefile.PL", "INSTALLDIRS=vendor",
58                 # if perl_build is not tested first, need to pass packlist
59                 # option to handle fallthrough case
60                 (compat(7) ? "create_packlist=0" : ()),
61                 @flags, @_);
62 }
63
64 sub install {
65         my $this=shift;
66         my $destdir=shift;
67
68         # Special case for Makefile.PL that uses
69         # Module::Build::Compat. PREFIX should not be passed
70         # for those; it already installs into /usr by default.
71         my $makefile=$this->get_sourcepath("Makefile");
72         if (system(qq{grep -q "generated automatically by MakeMaker" $makefile}) != 0) {
73                 $this->SUPER::install($destdir, @_);
74         }
75         else {
76                 $this->SUPER::install($destdir, "PREFIX=/usr", @_);
77         }
78 }
79
80 1