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
|
# A debhelper build system class for handling simple Makefile based projects.
#
# Copyright: © 2008 Joey Hess
# © 2008-2009 Modestas Vainius
# License: GPL-2+
package Debian::Debhelper::Buildsystem::makefile;
use strict;
use Debian::Debhelper::Dh_Lib qw(escape_shell get_make_jobserver_status);
use base 'Debian::Debhelper::Buildsystem';
sub get_makecmd_C {
my $this=shift;
my $buildpath = $this->get_buildpath();
if ($buildpath ne '.') {
return $this->{makecmd} . " -C " . escape_shell($buildpath);
}
return $this->{makecmd};
}
sub exists_make_target {
my ($this, $target) = @_;
my $makecmd=$this->get_makecmd_C();
# Use make -n to check to see if the target would do
# anything. There's no good way to test if a target exists.
my $ret=`$makecmd -s -n --no-print-directory $target 2>/dev/null`;
chomp $ret;
return length($ret);
}
sub do_make {
my $this=shift;
# Remove unavailable jobserver options from MAKEFLAGS.
# Always clean MAKEFLAGS from unavailable jobserver options. If parallel
# is enabled, do more extensive clean up from all job control specific
# options
my ($status, $makeflags) = get_make_jobserver_status();
if ($status eq "jobserver-unavailable" || defined $this->get_parallel()) {
if (defined $makeflags) {
$ENV{MAKEFLAGS} = $makeflags;
}
else {
delete $ENV{MAKEFLAGS} if exists $ENV{MAKEFLAGS};
}
}
# Start a new jobserver if parallel building was requested
if (defined $this->get_parallel()) {
unshift @_, "-j" . ($this->get_parallel() > 1 ? $this->get_parallel() : 1);
}
$this->doit_in_builddir($this->{makecmd}, @_);
}
sub make_first_existing_target {
my $this=shift;
my $targets=shift;
foreach my $target (@$targets) {
if ($this->exists_make_target($target)) {
$this->do_make($target, @_);
return $target;
}
}
return undef;
}
sub DESCRIPTION {
"simple Makefile"
}
sub new {
my $class=shift;
my $this=$class->SUPER::new(@_);
$this->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make";
return $this;
}
sub check_auto_buildable {
my $this=shift;
my ($step) = @_;
# Handles build, test, install, clean; configure - next class
if (grep /^\Q$step\E$/, qw{build test install clean}) {
# This is always called in the source directory, but generally
# Makefiles are created (or live) in the the build directory.
return -e $this->get_buildpath("Makefile") ||
-e $this->get_buildpath("makefile") ||
-e $this->get_buildpath("GNUmakefile");
}
return 0;
}
sub build {
my $this=shift;
$this->do_make(@_);
}
sub test {
my $this=shift;
$this->make_first_existing_target(['test', 'check'], @_);
}
sub install {
my $this=shift;
my $destdir=shift;
$this->make_first_existing_target(['install'], "DESTDIR=$destdir", @_);
}
sub clean {
my $this=shift;
if (!$this->rmdir_builddir()) {
$this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_);
}
}
1
|