1 # Defines base debhelper buildsystem class interface.
3 # Copyright: © 2008-2009 Modestas Vainius
6 package Debian::Debhelper::Dh_Buildsystem_Basic;
10 use Debian::Debhelper::Dh_Lib;
12 # Build system name. Defaults to the last component of the package
13 # name. Do not override this method unless you know what you are
17 my $cls = ref($self) || $self;
18 return ($cls =~ m/^.+::([^:]+)$/) ? $1 : "[invalid package name]";
21 # Description of the build system to be shown to the users.
23 "basic debhelper build system class";
27 my ($cls, $builddir) = @_;
28 my $self = bless({ builddir => $builddir }, $cls);
29 if (!defined($builddir) || $builddir eq ".") {
30 $self->{builddir} = undef;
35 # This instance method is called to check if the build system is capable
36 # to build a source package. Additional argument $action describes which
37 # operation the caller is going to perform first (either configure,
38 # build, test, install or clean). You must override this method for the
39 # build system module to be ever picked up automatically.
41 # This method is supposed to be called with source root directory being
42 # working directory. Use $self->get_buildpath($path) method to get full
43 # path to the files in the build directory.
50 # Derived class can call this method in its constructor
51 # to enforce in-source building even if the user
52 # requested otherwise.
53 sub enforce_in_source_building {
55 if ($self->{builddir}) {
56 warning("warning: ".$self->NAME()." buildsystem does not support building outside-source. In-source build enforced.");
57 $self->{builddir} = undef;
63 return $self->{builddir};
67 my ($self, $path) = @_;
68 if ($self->get_builddir()) {
69 return File::Spec->catfile($self->get_builddir(), $path);
72 return File::Spec->catfile('.', $path);
80 return $self->$method(@_);
83 # The instance methods below provide support for configuring,
84 # building, testing, install and cleaning source packages.
85 # These methods are wrappers around respective *_impl() methods
86 # which are supposed to do real buildsystem specific work.
90 return $self->invoke_impl('configure_impl', @_);
95 return $self->invoke_impl('build_impl', @_);
100 return $self->invoke_impl('test_impl', @_);
105 return $self->invoke_impl('install_impl', @_);
110 return $self->invoke_impl('clean_impl', @_);
113 # The instance methods below should be overriden by derived classes
114 # to implement buildsystem specific actions needed to build the
115 # source. Arbitary number of custom action arguments might be passed.
116 # Default implementations do nothing.
133 # destdir parameter specifies where to install files.
145 package Debian::Debhelper::Dh_Buildsystem_Option;
147 use Debian::Debhelper::Dh_Buildsystems qw( DEFAULT_BUILD_DIRECTORY );
148 use base 'Debian::Debhelper::Dh_Buildsystem_Basic';
150 # Derived class can call this method in its constructor to enforce
151 # outside-source building even if the user didn't request it.
152 sub enforce_outside_source_building {
153 my ($self, $builddir) = @_;
154 if (!defined $self->{builddir}) {
155 $self->{builddir} = ($builddir && $builddir ne ".") ? $builddir : DEFAULT_BUILD_DIRECTORY;
159 # Constructs option to be passed to the source package buildsystem to
160 # change build directory. Returns nothing by default.
161 sub get_builddir_option {
170 if ($self->get_builddir_option()) {
171 return $self->SUPER::invoke_impl($method, $self->get_builddir_option(), @_);
174 return $self->SUPER::invoke_impl($method, @_);
178 package Debian::Debhelper::Dh_Buildsystem_Chdir;
182 use Debian::Debhelper::Dh_Lib;
183 use base 'Debian::Debhelper::Dh_Buildsystem_Option';
187 my $self=$cls->SUPER::new(@_);
188 $self->{topdir} = '.';
193 my ($cls, $dir) = @_;
194 verbose_print("cd '$dir'");
196 chdir $dir or error("error: unable to chdir to $dir");
201 my ($cls, $dir) = @_;
202 if (-e $dir && ! -d $dir) {
203 error("error: unable to create '$dir': object already exists and is not a directory");
206 verbose_print("mkdir '$dir'");
208 mkdir($dir, 0755) or error("error: unable to create '$dir': $!");
217 if (defined $self->{builddir} && $self->{topdir} ne ".") {
218 return File::Spec->catfile($self->{topdir}, $self->{builddir});
220 return $self->SUPER::get_builddir();
225 if ($self->{topdir} ne ".") {
226 return File::Spec->abs2rel($self->{topdir});
228 return $self->{topdir};
232 my ($self, $path) = @_;
233 return File::Spec->catfile($self->get_topdir(), $path);
238 if ($self->get_builddir() && $self->{topdir} ne ".") {
239 $self->_cd($self->get_topdir());
240 $self->{topdir} = ".";
248 if ($self->get_builddir() && $self->{topdir} eq ".") {
249 $self->{topdir} = getcwd();
250 $self->_cd($self->get_builddir());
261 if ($self->get_topdir() ne ".") {
264 $self->cd_to_builddir();
272 # *_impl() is run with current working directory changed to the
273 # build directory if requested.
279 $self->cd_to_builddir();
280 $ret = $self->$method(@_);
287 if ($self->get_builddir()) {
288 $self->_mkdir($self->get_builddir());
290 return $self->SUPER::configure(@_);
293 # If outside-source tree building is done, whole build directory
294 # gets wiped out by default. Otherwise, clean_impl() is called.
297 if ($self->get_builddir()) {
298 if (-d $self->get_builddir()) {
300 doit("rm", "-rf", $self->get_builddir());
304 return $self->SUPER::clean(@_);