]> git.donarmstrong.com Git - debhelper.git/blob - Debian/Debhelper/Buildsystem/makefile.pm
misc minor changes
[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);
11 use base 'Debian::Debhelper::Buildsystem';
12
13 sub get_makecmd_C {
14         my $this=shift;
15         my $buildpath = $this->get_buildpath();
16         if ($buildpath ne '.') {
17                 return $this->{makecmd} . " -C " . escape_shell($buildpath);
18         }
19         return $this->{makecmd};
20 }
21
22 sub exists_make_target {
23         my ($this, $target) = @_;
24         my $makecmd=$this->get_makecmd_C();
25
26         # Use make -n to check to see if the target would do
27         # anything. There's no good way to test if a target exists.
28         my $ret=`$makecmd -s -n --no-print-directory $target 2>/dev/null`;
29         chomp $ret;
30         return length($ret);
31 }
32
33 sub make_first_existing_target {
34         my $this=shift;
35         my $targets=shift;
36
37         foreach my $target (@$targets) {
38                 if ($this->exists_make_target($target)) {
39                         $this->doit_in_builddir($this->{makecmd}, $target, @_);
40                         return $target;
41                 }
42         }
43         return undef;
44 }
45
46 sub DESCRIPTION {
47         "simple Makefile"
48 }
49
50 sub new {
51         my $class=shift;
52         my $this=$class->SUPER::new(@_);
53         $this->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make";
54         return $this;
55 }
56
57 sub check_auto_buildable {
58         my $this=shift;
59         my ($step) = @_;
60
61         # Handles build, test, install, clean; configure - next class
62         if (grep /^\Q$step\E$/, qw{build test install clean}) {
63                 # This is always called in the source directory, but generally
64                 # Makefiles are created (or live) in the the build directory.
65                 return -e $this->get_buildpath("Makefile") ||
66                        -e $this->get_buildpath("makefile") ||
67                        -e $this->get_buildpath("GNUmakefile");
68         }
69         return 0;
70 }
71
72 sub build {
73         my $this=shift;
74         $this->doit_in_builddir($this->{makecmd}, @_);
75 }
76
77 sub test {
78         my $this=shift;
79         $this->make_first_existing_target(['test', 'check'], @_);
80 }
81
82 sub install {
83         my $this=shift;
84         my $destdir=shift;
85         $this->make_first_existing_target(['install'], "DESTDIR=$destdir", @_);
86 }
87
88 sub clean {
89         my $this=shift;
90         if (!$this->rmdir_builddir()) {
91                 $this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_);
92         }
93 }
94
95 1