]> git.donarmstrong.com Git - debhelper.git/blob - Debian/Debhelper/Buildsystem/makefile.pm
makefile buildsystem: Chomp output during test for full compatability with debhelper...
[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         # This is always called in the source directory, but generally
73         # Makefiles are created (or live) in the the build directory.
74         return (-e $this->get_buildpath("Makefile") ||
75                 -e $this->get_buildpath("makefile") ||
76                 -e $this->get_buildpath("GNUmakefile")) ? 1 : 0;
77 }
78
79 sub build {
80         my $this=shift;
81         $this->do_make(@_);
82 }
83
84 sub test {
85         my $this=shift;
86         $this->make_first_existing_target(['test', 'check'], @_);
87 }
88
89 sub install {
90         my $this=shift;
91         my $destdir=shift;
92         $this->make_first_existing_target(['install'], "DESTDIR=$destdir", @_);
93 }
94
95 sub clean {
96         my $this=shift;
97         if (!$this->rmdir_builddir()) {
98                 $this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_);
99         }
100 }
101
102 1