]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Buildsystem.pm
misc minor changes
[debhelper.git] / Debian / Debhelper / Buildsystem.pm
index ca43391fa607b08d0d2e796ea075dba7cc16c1e3..c63f8153b5358457f7d59c7dfea7965e3933d39e 100644 (file)
@@ -1,4 +1,4 @@
-# Defines debhelper buildsystem class interface and implementation
+# Defines debhelper build system class interface and implementation
 # of common functionality.
 #
 # Copyright: © 2008-2009 Modestas Vainius
@@ -13,7 +13,7 @@ use File::Spec;
 use Debian::Debhelper::Dh_Lib;
 
 # Cache DEB_BUILD_GNU_TYPE value. Performance hit of multiple
-# invocations is noticable when listing buildsystems.
+# invocations is noticable when listing build systems.
 our $DEB_BUILD_GNU_TYPE = dpkg_architecture_value("DEB_BUILD_GNU_TYPE");
 
 # Build system name. Defaults to the last component of the class
@@ -26,7 +26,7 @@ sub NAME {
                return $1;
        }
        else {
-               error("ınvalid buildsystem class name: $class");
+               error("ınvalid build system class name: $class");
        }
 }
 
@@ -46,11 +46,8 @@ sub DEFAULT_BUILD_DIRECTORY {
 #                  directory) where the sources to be built live. If not
 #                  specified or empty, defaults to the current directory.
 # - builddir -     specifies build directory to use. Path is relative to the
-#                  source directory unless it starts with ./, then it is
-#                  assumed to be relative to the top directory. If undef or
-#                  empty, DEFAULT_BUILD_DIRECTORY relative to the source
-#                  directory will be used. If not specified, in source build
-#                  will be attempted.
+#                  current (top) directory. If undef or empty,
+#                  DEFAULT_BUILD_DIRECTORY directory will be used. 
 # Derived class can override the constructor to initialize common object
 # parameters. Do NOT use constructor to execute commands or otherwise
 # configure/setup build environment. There is absolutely no guarantee the
@@ -67,7 +64,7 @@ sub new {
                my $curdir = Cwd::getcwd();
                my $abspath = Cwd::abs_path($opts{sourcedir});
                if (! -d $abspath || $abspath !~ /^\Q$curdir\E/) {
-                       error("Invalid or non-existing path to the source directory: ".$opts{sourcedir});
+                       error("invalid or non-existing path to the source directory: ".$opts{sourcedir});
                }
                $this->{sourcedir} = File::Spec->abs2rel($abspath, $curdir);
        }
@@ -83,20 +80,7 @@ sub new {
 sub _set_builddir {
        my $this=shift;
        my $builddir=shift;
-       if ($builddir) {
-               if ($builddir =~ m!^\./(.*)!) {
-                       # Specified as relative to the current directory
-                       $this->{builddir} = $1;
-               }
-               else {
-                       # Specified as relative to the source directory
-                       $this->{builddir} = $this->get_sourcepath($builddir);
-               }
-       }
-       else {
-               # Relative to the source directory by default
-               $this->{builddir} = $this->get_sourcepath($this->DEFAULT_BUILD_DIRECTORY());
-       }
+       $this->{builddir} = ($builddir) ? $builddir : $this->DEFAULT_BUILD_DIRECTORY;
 
        # Canonicalize. If build directory ends up the same as source directory, drop it
        if (defined $this->{builddir}) {
@@ -107,16 +91,16 @@ sub _set_builddir {
        }
 }
 
-# This instance method is called to check if the build system is capable
+# This instance method is called to check if the build system is able
 # to auto build a source package. Additional argument $step describes
 # which operation the caller is going to perform (either configure,
 # build, test, install or clean). You must override this method for the
 # build system module to be ever picked up automatically. This method is
 # used in conjuction with @Dh_Buildsystems::BUILDSYSTEMS.
 #
-# This method is supposed to be called with source root directory being
-# working directory. Use $this->get_buildpath($path) method to get full
-# path to the files in the build directory.
+# This method is supposed to be called inside the source root directory.
+# Use $this->get_buildpath($path) method to get full path to the files
+# in the build directory.
 sub check_auto_buildable {
        my $this=shift;
        my ($step) = @_;
@@ -134,15 +118,20 @@ sub enforce_in_source_building {
 }
 
 # Derived class can call this method in its constructor to enforce
-# out of source building even if the user didn't request it.
+# out of source building even if the user didn't request it. However,
+# if 'builddir' named parameter is passed, accept its value as the
+# build directory even if it matches the source directory (meaning out
+# of source is only prefered to in source, not enforced).
 sub enforce_out_of_source_building {
-       my ($this, $builddir) = @_;
+       my $this=shift;
+       my %args=@_;
        if (!defined $this->get_builddir()) {
-               $this->_set_builddir($builddir);
-               # The build directory might have been dropped if it matched the
-               # source directory. Just set to default in this case.
-               if (!defined $this->get_builddir()) {
-                       $this->_set_builddir();
+               $this->_set_builddir($args{builddir});
+               if (!defined $this->get_builddir() && !$args{builddir}) {
+                       # If we are here, DEFAULT_BUILD_DIRECTORY matches
+                       # the source directory, building might fail.
+                       error("default build directory is the same as the source directory." .
+                             " Please specify a custom build directory");
                }
        }
 }
@@ -172,7 +161,7 @@ sub _canonpath {
 # converts and returns path of $path being relative the $base.
 sub _rel2rel {
        my ($this, $path, $base, $root)=@_;
-       $root = File::Spec->rootdir() if !defined $root;
+       $root = "/tmp" if !defined $root;
        
        return File::Spec->abs2rel(
            File::Spec->rel2abs($path, $root),
@@ -195,7 +184,8 @@ sub get_sourcepath {
 }
 
 # Get path to the build directory if it was specified
-# (relative to the current (top) directory). undef otherwise.
+# (relative to the current (top) directory). undef if the same
+# as the source directory.
 sub get_builddir {
        my $this=shift;
        return $this->{builddir};
@@ -267,13 +257,13 @@ sub _cd {
        }
 }
 
-# Changes working directory to the source directory (if needed)
+# Changes working directory to the source directory (if needed),
 # calls doit(@_) and changes working directory back to the top
 # directory.
 sub doit_in_sourcedir {
        my $this=shift;
        if ($this->get_sourcedir() ne '.') {
-               my $sourcedir = get_sourcedir();
+               my $sourcedir = $this->get_sourcedir();
                my $curdir = Cwd::getcwd();
                $this->_cd($sourcedir);
                doit(@_);
@@ -309,15 +299,18 @@ sub doit_in_builddir {
 # If build directory does not exist, nothing is done and 0 is returned.
 sub rmdir_builddir {
        my $this=shift;
+       my $only_empty=shift;
        if ($this->get_builddir()) {
                my $buildpath = $this->get_buildpath();
                if (-d $buildpath && ! $dh{NO_ACT}) {
-                       doit("rm", "-rf", $buildpath);
-                       # If build directory had 2 or more levels, delete empty
-                       # parent directories until the source directory level.
                        my @spdir = File::Spec->splitdir($this->get_build_rel2sourcedir());
                        my $peek;
-                       pop @spdir;
+                       if (!$only_empty) {
+                               doit("rm", "-rf", $buildpath);
+                               pop @spdir;
+                       }
+                       # If build directory had 2 or more levels, delete empty
+                       # parent directories until the source directory level.
                        while (($peek=pop(@spdir)) && $peek ne '.' && $peek ne '..') {
                                last if ! rmdir($this->get_sourcepath(File::Spec->catdir(@spdir, $peek)));
                        }
@@ -356,7 +349,7 @@ sub post_building_step {
 # In case of failure, the method may just error() out.
 #
 # These methods should be overriden by derived classes to
-# implement buildsystem specific steps needed to build the
+# implement build system specific steps needed to build the
 # source. Arbitary number of custom step arguments might be
 # passed. Default implementations do nothing.
 sub configure {
@@ -381,4 +374,4 @@ sub clean {
        my $this=shift;
 }
 
-1;
+1