1 # A debhelper build system class for handling simple Makefile based projects.
3 # Copyright: © 2008 Joey Hess
4 # © 2008-2009 Modestas Vainius
7 package Debian::Debhelper::Buildsystem::makefile;
11 B<makefile> - make (Makefile)
15 B<dh_auto_*> [B<--buildsystem>=I<makefile>] ...
19 Makefile based projects use C<make> to control build process. C<make> utility
20 is the most popular tool on *NIX for building & installing packages from
21 source. It is also a basis for most other popular build systems. For example,
22 GNU Autoconf (autoconf) or CMake (cmake) generate F<Makefile>s during I<configure>
23 step and leave the rest of build process for C<make> to handle.
27 Since C<make> itself does not strictly define standard target names, a couple
28 of the most popular targets are tried for each building step. Whichever first
29 of them is discovered to exist, it is run. If neither of the tried targets
30 exist in the actual, the building step is assumed to have completed
31 successfully. However, if executed C<make> target fails, the respective dh_auto
32 program will fail too.
34 If MAKE environment variable is set, its value is executed rather than default
37 Both in source (default) and out of source tree building modes are supported.
38 Either F<Makefile>, F<makefile> or F<GNUmakefile> file should be present in the
39 build directory for this debhelper build system to work.
49 Do nothing (auto-selection continues).
51 =item I<Auto-selection>
53 It will never be auto-selected at this step.
60 use Debian::Debhelper::Dh_Lib qw(escape_shell);
61 use base 'Debian::Debhelper::Buildsystem';
65 my $buildpath = $this->get_buildpath();
66 if ($buildpath ne '.') {
67 return $this->{makecmd} . " -C " . escape_shell($buildpath);
69 return $this->{makecmd};
72 sub exists_make_target {
73 my ($this, $target) = @_;
74 my $makecmd=$this->get_makecmd_C();
76 # Use make -n to check to see if the target would do
77 # anything. There's no good way to test if a target exists.
78 my $ret=`$makecmd -s -n --no-print-directory $target 2>/dev/null`;
83 sub make_first_existing_target {
87 foreach my $target (@$targets) {
88 if ($this->exists_make_target($target)) {
89 $this->doit_in_builddir($this->{makecmd}, $target, @_);
102 my $this=$class->SUPER::new(@_);
103 $this->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make";
107 sub check_auto_buildable {
111 # Handles build, test, install, clean; configure - next class
112 if (grep /^\Q$step\E$/, qw{build test install clean}) {
113 # This is always called in the source directory, but generally
114 # Makefiles are created (or live) in the the build directory.
115 return -e $this->get_buildpath("Makefile") ||
116 -e $this->get_buildpath("makefile") ||
117 -e $this->get_buildpath("GNUmakefile");
128 Execute C<make> (without arguments) with working directory changed to the build
131 =item I<Auto-selection>
133 If either F<Makefile>, F<makefile> or F<GNUmakefile> exists in the build
134 directory, but F<Makefile.PL> does not exist in the source directory.
141 $this->doit_in_builddir($this->{makecmd}, @_);
150 Try to C<make> either I<test> or I<check> target (the first existing one) with
151 working directory changed to the build directory.
153 =item I<Auto-selection>
155 If either F<Makefile>, F<makefile> or F<GNUmakefile> exists in the build
156 directory, but F<Makefile.PL> does not exist in the source directory.
163 $this->make_first_existing_target(['test', 'check'], @_);
172 Try to run C<make install DESTDIR=$destdir> with working directory changed to
173 the build directory. $desdir is the path to the appropriate temporary
174 installation directory under debian/ (see L<dh_auto_install(1)>).
176 =item I<Auto-selection>
178 If either F<Makefile>, F<makefile> or F<GNUmakefile> exists in the build
179 directory, but F<Makefile.PL> does not exist in the source directory.
187 $this->make_first_existing_target(['install'], "DESTDIR=$destdir", @_);
196 When building in source, try to C<make> either I<distclean>, I<realclean> or
197 I<clean> target (the first existing one) in the source directory. When building
198 out of source tree, recursively remove the whole build directory.
200 =item I<Auto-selection>
202 If either F<Makefile>, F<makefile> or F<GNUmakefile> exists in the build
203 directory, but F<Makefile.PL> does not exist in the source directory.
210 if (!$this->rmdir_builddir()) {
211 $this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_);
221 Joey Hess <joeyh@debian.org>
222 Modestas Vainius <modestas@vainius.eu>