]> git.donarmstrong.com Git - debhelper.git/blob - Debian/Debhelper/Buildsystem/makefile.pm
debhelper: Fix minor source comment typos.
[debhelper.git] / Debian / Debhelper / Buildsystem / makefile.pm
1 # A debhelper build system class for handling simple Makefile based projects.
2 #
3 # Copyright: © 2008 Joey Hess
4 #            © 2008-2009 Modestas Vainius
5 # License: GPL-2+
6
7 package Debian::Debhelper::Buildsystem::makefile;
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib qw(escape_shell clean_jobserver_makeflags);
11 use base 'Debian::Debhelper::Buildsystem';
12
13 sub exists_make_target {
14         my ($this, $target) = @_;
15
16         # Use make -n to check to see if the target would do
17         # anything. There's no good way to test if a target exists.
18         my @opts=("-s", "-n", "--no-print-directory");
19         my $buildpath = $this->get_buildpath();
20         unshift @opts, "-C", $buildpath if $buildpath ne ".";
21         open(SAVEDERR, ">&STDERR");
22         open(STDERR, ">/dev/null");
23         open(MAKE, "-|", $this->{makecmd}, @opts, $target);
24         my $output=<MAKE>;
25         chomp $output;
26         close MAKE;
27         open(STDERR, ">&SAVEDERR");
28         return defined $output && length $output;
29 }
30
31 sub do_make {
32         my $this=shift;
33
34         # Avoid possible warnings about unavailable jobserver,
35         # and force make to start a new jobserver.
36         clean_jobserver_makeflags();
37
38         # Note that this will override any -j settings in MAKEFLAGS.
39         unshift @_, "-j" . ($this->get_parallel() > 0 ? $this->get_parallel() : "");
40
41         $this->doit_in_builddir($this->{makecmd}, @_);
42 }
43
44 sub make_first_existing_target {
45         my $this=shift;
46         my $targets=shift;
47
48         foreach my $target (@$targets) {
49                 if ($this->exists_make_target($target)) {
50                         $this->do_make($target, @_);
51                         return $target;
52                 }
53         }
54         return undef;
55 }
56
57 sub DESCRIPTION {
58         "simple Makefile"
59 }
60
61 sub new {
62         my $class=shift;
63         my $this=$class->SUPER::new(@_);
64         $this->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make";
65         return $this;
66 }
67
68 sub check_auto_buildable {
69         my $this=shift;
70         my ($step) = @_;
71
72         if (-e $this->get_buildpath("Makefile") ||
73             -e $this->get_buildpath("makefile") ||
74             -e $this->get_buildpath("GNUmakefile"))
75         {
76                 # This is always called in the source directory, but generally
77                 # Makefiles are created (or live) in the build directory.
78                 return 1;
79         } elsif ($step eq "clean" && defined $this->get_builddir() &&
80                  $this->check_auto_buildable("configure"))
81         {
82                 # Assume that the package can be cleaned (i.e. the build directory can
83                 # be removed) as long as it is built out-of-source tree and can be
84                 # configured. This is useful for derivative buildsystems which
85                 # generate Makefiles.
86                 return 1;
87         }
88         return 0;
89 }
90
91 sub build {
92         my $this=shift;
93         $this->do_make(@_);
94 }
95
96 sub test {
97         my $this=shift;
98         $this->make_first_existing_target(['test', 'check'], @_);
99 }
100
101 sub install {
102         my $this=shift;
103         my $destdir=shift;
104         $this->make_first_existing_target(['install'],
105                 "DESTDIR=$destdir",
106                 "AM_UPDATE_INFO_DIR=no", @_);
107 }
108
109 sub clean {
110         my $this=shift;
111         if (!$this->rmdir_builddir()) {
112                 $this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_);
113         }
114 }
115
116 1