summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Debian/Debhelper/Buildsystem.pm384
-rw-r--r--Debian/Debhelper/Buildsystem/autoconf.pm55
-rw-r--r--Debian/Debhelper/Buildsystem/cmake.pm48
-rw-r--r--Debian/Debhelper/Buildsystem/makefile.pm95
-rw-r--r--Debian/Debhelper/Buildsystem/perl_build.pm67
-rw-r--r--Debian/Debhelper/Buildsystem/perl_makemaker.pm64
-rw-r--r--Debian/Debhelper/Buildsystem/python_distutils.pm51
-rw-r--r--Debian/Debhelper/Dh_Buildsystems.pm186
-rw-r--r--Debian/Debhelper/Dh_Getopt.pm48
-rw-r--r--Debian/Debhelper/Dh_Lib.pm38
-rw-r--r--Makefile6
-rw-r--r--debhelper.pod10
-rw-r--r--debian/changelog20
-rw-r--r--debian/copyright4
-rwxr-xr-xdh_auto_build16
-rwxr-xr-xdh_auto_clean29
-rwxr-xr-xdh_auto_configure67
-rwxr-xr-xdh_auto_install38
-rwxr-xr-xdh_auto_test23
-rw-r--r--doc/PROGRAMMING23
-rwxr-xr-xt/buildsystems/autoconf/configure74
-rwxr-xr-xt/buildsystems/buildsystem_tests430
-rw-r--r--t/buildsystems/debian/changelog5
-rw-r--r--t/buildsystems/debian/compat1
-rw-r--r--t/buildsystems/debian/control10
-rwxr-xr-xt/syntax2
26 files changed, 1609 insertions, 185 deletions
diff --git a/Debian/Debhelper/Buildsystem.pm b/Debian/Debhelper/Buildsystem.pm
new file mode 100644
index 00000000..ca43391f
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem.pm
@@ -0,0 +1,384 @@
+# Defines debhelper buildsystem class interface and implementation
+# of common functionality.
+#
+# Copyright: © 2008-2009 Modestas Vainius
+# License: GPL-2+
+
+package Debian::Debhelper::Buildsystem;
+
+use strict;
+use warnings;
+use Cwd ();
+use File::Spec;
+use Debian::Debhelper::Dh_Lib;
+
+# Cache DEB_BUILD_GNU_TYPE value. Performance hit of multiple
+# invocations is noticable when listing buildsystems.
+our $DEB_BUILD_GNU_TYPE = dpkg_architecture_value("DEB_BUILD_GNU_TYPE");
+
+# Build system name. Defaults to the last component of the class
+# name. Do not override this method unless you know what you are
+# doing.
+sub NAME {
+ my $this=shift;
+ my $class = ref($this) || $this;
+ if ($class =~ m/^.+::([^:]+)$/) {
+ return $1;
+ }
+ else {
+ error("ınvalid buildsystem class name: $class");
+ }
+}
+
+# Description of the build system to be shown to the users.
+sub DESCRIPTION {
+ error("class lacking a DESCRIPTION");
+}
+
+# Default build directory. Can be overriden in the derived
+# class if really needed.
+sub DEFAULT_BUILD_DIRECTORY {
+ "obj-" . $DEB_BUILD_GNU_TYPE;
+}
+
+# Constructs a new build system object. Named parameters:
+# - sourcedir- specifies source directory (relative to the current (top)
+# 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.
+# 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
+# constructed object will be used to build something. Use pre_building_step(),
+# $build_step() or post_building_step() methods for this.
+sub new {
+ my ($class, %opts)=@_;
+
+ my $this = bless({ sourcedir => '.',
+ builddir => undef, }, $class);
+
+ if (exists $opts{sourcedir}) {
+ # Get relative sourcedir abs_path (without symlinks)
+ 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});
+ }
+ $this->{sourcedir} = File::Spec->abs2rel($abspath, $curdir);
+ }
+ if (exists $opts{builddir}) {
+ $this->_set_builddir($opts{builddir});
+ }
+ return $this;
+}
+
+# Private method to set a build directory. If undef, use default.
+# Do $this->{builddir} = undef or pass $this->get_sourcedir() to
+# unset the build directory.
+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());
+ }
+
+ # Canonicalize. If build directory ends up the same as source directory, drop it
+ if (defined $this->{builddir}) {
+ $this->{builddir} = $this->_canonpath($this->{builddir});
+ if ($this->{builddir} eq $this->get_sourcedir()) {
+ $this->{builddir} = undef;
+ }
+ }
+}
+
+# This instance method is called to check if the build system is capable
+# 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.
+sub check_auto_buildable {
+ my $this=shift;
+ my ($step) = @_;
+ return 0;
+}
+
+# Derived class can call this method in its constructor
+# to enforce in source building even if the user requested otherwise.
+sub enforce_in_source_building {
+ my $this=shift;
+ if ($this->get_builddir()) {
+ $this->{warn_insource} = 1;
+ $this->{builddir} = undef;
+ }
+}
+
+# Derived class can call this method in its constructor to enforce
+# out of source building even if the user didn't request it.
+sub enforce_out_of_source_building {
+ my ($this, $builddir) = @_;
+ 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();
+ }
+ }
+}
+
+# Enhanced version of File::Spec::canonpath. It collapses ..
+# too so it may return invalid path if symlinks are involved.
+# On the other hand, it does not need for the path to exist.
+sub _canonpath {
+ my ($this, $path)=@_;
+ my @canon;
+ my $back=0;
+ for my $comp (split(m%/+%, $path)) {
+ if ($comp eq '.') {
+ next;
+ }
+ elsif ($comp eq '..') {
+ if (@canon > 0) { pop @canon; } else { $back++; }
+ }
+ else {
+ push @canon, $comp;
+ }
+ }
+ return (@canon + $back > 0) ? join('/', ('..')x$back, @canon) : '.';
+}
+
+# Given both $path and $base are relative to the same directory,
+# converts and returns path of $path being relative the $base.
+sub _rel2rel {
+ my ($this, $path, $base, $root)=@_;
+ $root = File::Spec->rootdir() if !defined $root;
+
+ return File::Spec->abs2rel(
+ File::Spec->rel2abs($path, $root),
+ File::Spec->rel2abs($base, $root)
+ );
+}
+
+# Get path to the source directory
+# (relative to the current (top) directory)
+sub get_sourcedir {
+ my $this=shift;
+ return $this->{sourcedir};
+}
+
+# Convert path relative to the source directory to the path relative
+# to the current (top) directory.
+sub get_sourcepath {
+ my ($this, $path)=@_;
+ return File::Spec->catfile($this->get_sourcedir(), $path);
+}
+
+# Get path to the build directory if it was specified
+# (relative to the current (top) directory). undef otherwise.
+sub get_builddir {
+ my $this=shift;
+ return $this->{builddir};
+}
+
+# Convert path that is relative to the build directory to the path
+# that is relative to the current (top) directory.
+# If $path is not specified, always returns build directory path
+# relative to the current (top) directory regardless if builddir was
+# specified or not.
+sub get_buildpath {
+ my ($this, $path)=@_;
+ my $builddir = $this->get_builddir() || $this->get_sourcedir();
+ if (defined $path) {
+ return File::Spec->catfile($builddir, $path);
+ }
+ return $builddir;
+}
+
+# When given a relative path to the source directory, converts it
+# to the path that is relative to the build directory. If $path is
+# not given, returns a path to the source directory that is relative
+# to the build directory.
+sub get_source_rel2builddir {
+ my $this=shift;
+ my $path=shift;
+
+ my $dir = '.';
+ if ($this->get_builddir()) {
+ $dir = $this->_rel2rel($this->get_sourcedir(), $this->get_builddir());
+ }
+ if (defined $path) {
+ return File::Spec->catfile($dir, $path);
+ }
+ return $dir;
+}
+
+# When given a relative path to the build directory, converts it
+# to the path that is relative to the source directory. If $path is
+# not given, returns a path to the build directory that is relative
+# to the source directory.
+sub get_build_rel2sourcedir {
+ my $this=shift;
+ my $path=shift;
+
+ my $dir = '.';
+ if ($this->get_builddir()) {
+ $dir = $this->_rel2rel($this->get_builddir(), $this->get_sourcedir());
+ }
+ if (defined $path) {
+ return File::Spec->catfile($dir, $path);
+ }
+ return $dir;
+}
+
+# Creates a build directory.
+sub mkdir_builddir {
+ my $this=shift;
+ if ($this->get_builddir()) {
+ doit("mkdir", "-p", $this->get_builddir());
+ }
+}
+
+sub _cd {
+ my ($this, $dir)=@_;
+ if (! $dh{NO_ACT}) {
+ verbose_print("cd $dir");
+ chdir $dir or error("error: unable to chdir to $dir");
+ }
+}
+
+# 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 $curdir = Cwd::getcwd();
+ $this->_cd($sourcedir);
+ doit(@_);
+ $this->_cd($this->_rel2rel($curdir, $sourcedir, $curdir));
+ }
+ else {
+ doit(@_);
+ }
+ return 1;
+}
+
+# Changes working directory to the build directory (if needed),
+# calls doit(@_) and changes working directory back to the top
+# directory.
+sub doit_in_builddir {
+ my $this=shift;
+ if ($this->get_buildpath() ne '.') {
+ my $buildpath = $this->get_buildpath();
+ my $curdir = Cwd::getcwd();
+ $this->_cd($buildpath);
+ doit(@_);
+ $this->_cd($this->_rel2rel($curdir, $buildpath, $curdir));
+ }
+ else {
+ doit(@_);
+ }
+ return 1;
+}
+
+# In case of out of source tree building, whole build directory
+# gets wiped (if it exists) and 1 is returned. If build directory
+# had 2 or more levels, empty parent directories are also deleted.
+# If build directory does not exist, nothing is done and 0 is returned.
+sub rmdir_builddir {
+ my $this=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;
+ while (($peek=pop(@spdir)) && $peek ne '.' && $peek ne '..') {
+ last if ! rmdir($this->get_sourcepath(File::Spec->catdir(@spdir, $peek)));
+ }
+ }
+ return 1;
+ }
+ return 0;
+}
+
+# Instance method that is called before performing any step (see below).
+# Action name is passed as an argument. Derived classes overriding this
+# method should also call SUPER implementation of it.
+sub pre_building_step {
+ my $this=shift;
+ my ($step)=@_;
+
+ # Warn if in source building was enforced but build directory was
+ # specified. See enforce_in_source_building().
+ if ($this->{warn_insource}) {
+ warning("warning: " . $this->NAME() .
+ " does not support building out of source tree. In source building enforced.");
+ delete $this->{warn_insource};
+ }
+}
+
+# Instance method that is called after performing any step (see below).
+# Action name is passed as an argument. Derived classes overriding this
+# method should also call SUPER implementation of it.
+sub post_building_step {
+ my $this=shift;
+ my ($step)=@_;
+}
+
+# The instance methods below provide support for configuring,
+# building, testing, install and cleaning source packages.
+# 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
+# source. Arbitary number of custom step arguments might be
+# passed. Default implementations do nothing.
+sub configure {
+ my $this=shift;
+}
+
+sub build {
+ my $this=shift;
+}
+
+sub test {
+ my $this=shift;
+}
+
+# destdir parameter specifies where to install files.
+sub install {
+ my $this=shift;
+ my $destdir=shift;
+}
+
+sub clean {
+ my $this=shift;
+}
+
+1;
diff --git a/Debian/Debhelper/Buildsystem/autoconf.pm b/Debian/Debhelper/Buildsystem/autoconf.pm
new file mode 100644
index 00000000..c92e2c1f
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/autoconf.pm
@@ -0,0 +1,55 @@
+# A buildsystem plugin for handling autoconf based projects
+#
+# Copyright: © 2008 Joey Hess
+# © 2008-2009 Modestas Vainius
+# License: GPL-2+
+
+package Debian::Debhelper::Buildsystem::autoconf;
+
+use strict;
+use Debian::Debhelper::Dh_Lib qw(dpkg_architecture_value sourcepackage);
+use base 'Debian::Debhelper::Buildsystem::makefile';
+
+sub DESCRIPTION {
+ "GNU Autoconf (configure)"
+}
+
+sub check_auto_buildable {
+ my $this=shift;
+ my ($step)=@_;
+
+ # Handle configure; the rest - next class
+ if ($step eq "configure") {
+ return -x $this->get_sourcepath("configure");
+ }
+ return 0;
+}
+
+sub configure {
+ my $this=shift;
+
+ # Standard set of options for configure.
+ my @opts;
+ push @opts, "--build=" . dpkg_architecture_value("DEB_BUILD_GNU_TYPE");
+ push @opts, "--prefix=/usr";
+ push @opts, "--includedir=\${prefix}/include";
+ push @opts, "--mandir=\${prefix}/share/man";
+ push @opts, "--infodir=\${prefix}/share/info";
+ push @opts, "--sysconfdir=/etc";
+ push @opts, "--localstatedir=/var";
+ push @opts, "--libexecdir=\${prefix}/lib/" . sourcepackage();
+ push @opts, "--disable-maintainer-mode";
+ push @opts, "--disable-dependency-tracking";
+ # Provide --host only if different from --build, as recommended in
+ # autotools-dev README.Debian: When provided (even if equal)
+ # autoconf 2.52+ switches to cross-compiling mode.
+ if (dpkg_architecture_value("DEB_BUILD_GNU_TYPE")
+ ne dpkg_architecture_value("DEB_HOST_GNU_TYPE")) {
+ push @opts, "--host=" . dpkg_architecture_value("DEB_HOST_GNU_TYPE");
+ }
+
+ $this->mkdir_builddir();
+ $this->doit_in_builddir($this->get_source_rel2builddir("configure"), @opts, @_);
+}
+
+1;
diff --git a/Debian/Debhelper/Buildsystem/cmake.pm b/Debian/Debhelper/Buildsystem/cmake.pm
new file mode 100644
index 00000000..a30fbb03
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/cmake.pm
@@ -0,0 +1,48 @@
+# A buildsystem plugin for handling CMake based projects.
+# It enforces out of source tree building.
+#
+# Copyright: © 2008-2009 Modestas Vainius
+# License: GPL-2+
+
+package Debian::Debhelper::Buildsystem::cmake;
+
+use strict;
+use base 'Debian::Debhelper::Buildsystem::makefile';
+
+sub DESCRIPTION {
+ "CMake (CMakeLists.txt)"
+}
+
+sub check_auto_buildable {
+ my $this=shift;
+ my ($step)=@_;
+ my $ret = -e $this->get_sourcepath("CMakeLists.txt");
+ $ret &&= $this->SUPER::check_auto_buildable(@_) if $step ne "configure";
+ return $ret;
+}
+
+sub new {
+ my $class=shift;
+ my $this=$class->SUPER::new(@_);
+ # Enforce out of source tree building.
+ $this->enforce_out_of_source_building();
+ return $this;
+}
+
+sub configure {
+ my $this=shift;
+ my @flags;
+
+ # Standard set of cmake flags
+ push @flags, "-DCMAKE_INSTALL_PREFIX=/usr";
+ push @flags, "-DCMAKE_C_FLAGS=$ENV{CFLAGS}" if (exists $ENV{CFLAGS});
+ push @flags, "-DCMAKE_CXX_FLAGS=$ENV{CXXFLAGS}" if (exists $ENV{CXXFLAGS});
+ push @flags, "-DCMAKE_LD_FLAGS=$ENV{LDFLAGS}" if (exists $ENV{LDFLAGS});
+ push @flags, "-DCMAKE_SKIP_RPATH=ON";
+ push @flags, "-DCMAKE_VERBOSE_MAKEFILE=ON";
+
+ $this->mkdir_builddir();
+ $this->doit_in_builddir("cmake", $this->get_source_rel2builddir(), @flags);
+}
+
+1;
diff --git a/Debian/Debhelper/Buildsystem/makefile.pm b/Debian/Debhelper/Buildsystem/makefile.pm
new file mode 100644
index 00000000..6a9e6877
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/makefile.pm
@@ -0,0 +1,95 @@
+# A buildsystem plugin 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);
+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 make_first_existing_target {
+ my $this=shift;
+ my $targets=shift;
+
+ foreach my $target (@$targets) {
+ if ($this->exists_make_target($target)) {
+ $this->doit_in_builddir($this->{makecmd}, $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->doit_in_builddir($this->{makecmd}, @_);
+}
+
+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;
diff --git a/Debian/Debhelper/Buildsystem/perl_build.pm b/Debian/Debhelper/Buildsystem/perl_build.pm
new file mode 100644
index 00000000..525b0e1c
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/perl_build.pm
@@ -0,0 +1,67 @@
+# A buildsystem plugin for handling Perl Build based projects.
+#
+# Copyright: © 2008-2009 Joey Hess
+# © 2008-2009 Modestas Vainius
+# License: GPL-2+
+
+package Debian::Debhelper::Buildsystem::perl_build;
+
+use strict;
+use base 'Debian::Debhelper::Buildsystem';
+
+sub DESCRIPTION {
+ "Perl Module::Build (Build.PL)"
+}
+
+sub check_auto_buildable {
+ my ($this, $step) = @_;
+
+ # Handles everything
+ my $ret = -e $this->get_sourcepath("Build.PL");
+ if ($step ne "configure") {
+ $ret &&= -e $this->get_sourcepath("Build");
+ }
+ return $ret;
+}
+
+sub do_perl {
+ my $this=shift;
+ $ENV{MODULEBUILDRC} = "/dev/null";
+ $this->doit_in_sourcedir("perl", @_);
+}
+
+sub new {
+ my $class=shift;
+ my $this= $class->SUPER::new(@_);
+ $this->enforce_in_source_building();
+ return $this;
+}
+
+sub configure {
+ my $this=shift;
+ $ENV{PERL_MM_USE_DEFAULT}=1;
+ $this->do_perl("Build.PL", "installdirs=vendor", @_);
+}
+
+sub build {
+ my $this=shift;
+ $this->do_perl("Build", @_);
+}
+
+sub test {
+ my $this=shift;
+ $this->do_perl("Build", "test", @_);
+}
+
+sub install {
+ my $this=shift;
+ my $destdir=shift;
+ $this->do_perl("Build", "install", "destdir=$destdir", "create_packlist=0", @_);
+}
+
+sub clean {
+ my $this=shift;
+ $this->do_perl("Build", "--allow_mb_mismatch", 1, "distclean", @_);
+}
+
+1;
diff --git a/Debian/Debhelper/Buildsystem/perl_makemaker.pm b/Debian/Debhelper/Buildsystem/perl_makemaker.pm
new file mode 100644
index 00000000..4281fa26
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/perl_makemaker.pm
@@ -0,0 +1,64 @@
+# A buildsystem plugin for handling Perl MakeMaker based projects.
+#
+# Copyright: © 2008-2009 Joey Hess
+# © 2008-2009 Modestas Vainius
+# License: GPL-2+
+
+package Debian::Debhelper::Buildsystem::perl_makemaker;
+
+use strict;
+use base 'Debian::Debhelper::Buildsystem::makefile';
+
+sub DESCRIPTION {
+ "Perl ExtUtils::MakeMaker (Makefile.PL)"
+}
+
+sub check_auto_buildable {
+ my $this=shift;
+ my ($step)=@_;
+
+ # Handles everything if Makefile.PL exists. Otherwise - next class.
+ if (-e $this->get_sourcepath("Makefile.PL")) {
+ if ($step eq "install" || $step eq "configure") {
+ return 1;
+ }
+ else {
+ # This is backwards compatible (with << 7.3) until build, test and
+ # clean steps are not reimplemented in the backwards compatibility
+ # breaking way. However, this is absolutely necessary for
+ # enforce_in_source_building() to work in corner cases in build,
+ # test and clean steps as the next class (makefile) does not
+ # enforce it.
+ return $this->SUPER::check_auto_buildable(@_);
+ }
+ }
+ return 0;
+}
+
+sub new {
+ my $class=shift;
+ my $this=$class->SUPER::new(@_);
+ $this->enforce_in_source_building();
+ return $this;
+}
+
+sub configure {
+ my $this=shift;
+ # If set to a true value then MakeMaker's prompt function will
+ # # always return the default without waiting for user input.
+ $ENV{PERL_MM_USE_DEFAULT}=1;
+ # This prevents Module::Install from interactive behavior.
+ $ENV{PERL_AUTOINSTALL}="--skipdeps";
+
+ $this->doit_in_sourcedir("perl", "Makefile.PL", "INSTALLDIRS=vendor",
+ "create_packlist=0",
+ @_);
+}
+
+sub install {
+ my $this=shift;
+ my $destdir=shift;
+ $this->SUPER::install($destdir, "PREFIX=/usr", @_);
+}
+
+1;
diff --git a/Debian/Debhelper/Buildsystem/python_distutils.pm b/Debian/Debhelper/Buildsystem/python_distutils.pm
new file mode 100644
index 00000000..bfb76eea
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/python_distutils.pm
@@ -0,0 +1,51 @@
+# A buildsystem plugin for building Python Distutils based
+# projects.
+#
+# Copyright: © 2008 Joey Hess
+# © 2008-2009 Modestas Vainius
+# License: GPL-2+
+
+package Debian::Debhelper::Buildsystem::python_distutils;
+
+use strict;
+use base 'Debian::Debhelper::Buildsystem';
+
+sub DESCRIPTION {
+ "Python distutils"
+}
+
+sub check_auto_buildable {
+ my $this=shift;
+ return -e $this->get_sourcepath("setup.py");
+}
+
+sub setup_py {
+ my $this=shift;
+ my $act=shift;
+
+ if ($this->get_builddir()) {
+ unshift @_, "--build-base=" . $this->get_build_rel2sourcedir();
+ }
+ $this->doit_in_sourcedir("python", "setup.py", $act, @_);
+}
+
+sub build {
+ my $this=shift;
+ $this->setup_py("build", @_);
+}
+
+sub install {
+ my $this=shift;
+ my $destdir=shift;
+ $this->setup_py("install", "--root=$destdir", "--no-compile", "-O0", @_);
+}
+
+sub clean {
+ my $this=shift;
+ $this->setup_py("clean", "-a", @_);
+ # The setup.py might import files, leading to python creating pyc
+ # files.
+ $this->doit_in_sourcedir('find', '.', '-name', '*.pyc', '-exec', 'rm', '{}', ';');
+}
+
+1;
diff --git a/Debian/Debhelper/Dh_Buildsystems.pm b/Debian/Debhelper/Dh_Buildsystems.pm
new file mode 100644
index 00000000..8e9920f1
--- /dev/null
+++ b/Debian/Debhelper/Dh_Buildsystems.pm
@@ -0,0 +1,186 @@
+# A module for loading and managing debhelper buildsystem plugins.
+# This module is intended to be used by all dh_auto_* helper commands.
+#
+# Copyright: © 2009 Modestas Vainius
+# License: GPL-2+
+
+package Debian::Debhelper::Dh_Buildsystems;
+
+use strict;
+use warnings;
+use Debian::Debhelper::Dh_Lib;
+use File::Spec;
+
+use base 'Exporter';
+our @EXPORT=qw(&buildsystems_init &buildsystems_do &load_buildsystem &load_all_buildsystems);
+
+# Historical order must be kept for backwards compatibility. New
+# buildsystems MUST be added to the END of the list.
+our @BUILDSYSTEMS = (
+ "autoconf",
+ "perl_makemaker",
+ "makefile",
+ "python_distutils",
+ "perl_build",
+ "cmake",
+);
+
+my $opt_buildsys;
+my $opt_sourcedir;
+my $opt_builddir;
+my $opt_list;
+
+sub create_buildsystem_instance {
+ my $system=shift;
+ my %bsopts=@_;
+ my $module = "Debian::Debhelper::Buildsystem::$system";
+
+ eval "use $module";
+ if ($@) {
+ error("unable to load buildsystem class '$system': $@");
+ }
+
+ if (!exists $bsopts{builddir} && defined $opt_builddir) {
+ $bsopts{builddir} = ($opt_builddir eq "") ? undef : $opt_builddir;
+ }
+ if (!exists $bsopts{sourcedir} && defined $opt_sourcedir) {
+ $bsopts{sourcedir} = ($opt_sourcedir eq "") ? undef : $opt_sourcedir;
+ }
+ return $module->new(%bsopts);
+}
+
+# Similar to create_buildsystem_instance(), but it attempts to autoselect
+# a buildsystem if none was specified. In case autoselection fails, undef
+# is returned.
+sub load_buildsystem {
+ my $system=shift;
+ my $step=shift;
+ if (defined $system) {
+ my $inst = create_buildsystem_instance($system, @_);
+ return $inst;
+ }
+ else {
+ # Try to determine build system automatically
+ for $system (@BUILDSYSTEMS) {
+ my $inst = create_buildsystem_instance($system, @_);
+ if ($inst->check_auto_buildable($step)) {
+ return $inst;
+ }
+ }
+ }
+ return;
+}
+
+sub load_all_buildsystems {
+ my $incs=shift || \@INC;
+ my (%buildsystems, @buildsystems);
+
+ for my $inc (@$incs) {
+ my $path = File::Spec->catdir($inc, "Debian/Debhelper/Buildsystem");
+ if (-d $path) {
+ for my $module_path (glob "$path/*.pm") {
+ my $name = basename($module_path);
+ $name =~ s/\.pm$//;
+ next if exists $buildsystems{$name};
+ $buildsystems{$name} = create_buildsystem_instance($name, @_);
+ }
+ }
+ }
+
+ # Push debhelper built-in buildsystems first
+ for my $name (@BUILDSYSTEMS) {
+ error("Debhelper built-in buildsystem '$name' could not be found/loaded")
+ if not exists $buildsystems{$name};
+ push @buildsystems, $buildsystems{$name};
+ delete $buildsystems{$name};
+ }
+
+ # The rest are 3rd party buildsystems
+ for my $name (keys %buildsystems) {
+ my $inst = $buildsystems{$name};
+ $inst->{thirdparty} = 1;
+ push @buildsystems, $inst;
+ }
+
+ return @buildsystems;
+}
+
+sub buildsystems_init {
+ my %args=@_;
+
+ # Available command line options
+ my %options = (
+ "d" => undef, # cancel default D_FLAG option spec
+ "d=s" => \$opt_sourcedir,
+ "sourcedirectory=s" => \$opt_sourcedir,
+
+ "b:s" => \$opt_builddir,
+ "builddirectory:s" => \$opt_builddir,
+
+ "c=s" => \$opt_buildsys,
+ "buildsystem=s" => \$opt_buildsys,
+
+ "l" => \$opt_list,
+ "--list" => \$opt_list,
+ );
+ $args{options}{$_} = $options{$_} foreach keys(%options);
+
+ # Pass options from the DH_AUTO_OPTIONS environment variable
+ if (defined $ENV{DH_AUTO_OPTIONS}) {
+ $args{extra_args} = $ENV{DH_AUTO_OPTIONS};
+ }
+ Debian::Debhelper::Dh_Lib::init(%args);
+}
+
+sub buildsystems_list {
+ my $step=shift;
+
+ # List buildsystems (including auto and specified status)
+ my ($auto, $specified);
+ my @buildsystems = load_all_buildsystems();
+ for my $inst (@buildsystems) {
+ my $is_specified = defined $opt_buildsys && $opt_buildsys eq $inst->NAME();
+ if (! defined $specified && defined $opt_buildsys && $opt_buildsys eq $inst->NAME()) {
+ $specified = $inst->NAME();
+ }
+ elsif (! defined $auto && ! $inst->{thirdparty} && $inst->check_auto_buildable($step)) {
+ $auto = $inst->NAME();
+ }
+ printf("%s - %s", $inst->NAME(), $inst->DESCRIPTION());
+ print " [3rd party]" if $inst->{thirdparty};
+ print "\n";
+ }
+ print "\n";
+ print "Auto-selected: $auto\n" if defined $auto;
+ print "Specified: $specified\n" if defined $specified;
+ print "No system auto-selected or specified\n"
+ if ! defined $auto && ! defined $specified;
+}
+
+sub buildsystems_do {
+ my $step=shift;
+
+ if (!defined $step) {
+ $step = basename($0);
+ $step =~ s/^dh_auto_//;
+ }
+
+ if (grep(/^\Q$step\E$/, qw{configure build test install clean}) == 0) {
+ error("unrecognized build step: " . $step);
+ }
+
+ if ($opt_list) {
+ buildsystems_list($step);
+ exit 0;
+ }
+
+ my $buildsystem = load_buildsystem($opt_buildsys, $step);
+ if (defined $buildsystem) {
+ $buildsystem->pre_building_step($step);
+ $buildsystem->$step(@_, @{$dh{U_PARAMS}});
+ $buildsystem->post_building_step($step);
+ }
+ return 0;
+}
+
+1;
diff --git a/Debian/Debhelper/Dh_Getopt.pm b/Debian/Debhelper/Dh_Getopt.pm
index 864b168e..2a5aa6c2 100644
--- a/Debian/Debhelper/Dh_Getopt.pm
+++ b/Debian/Debhelper/Dh_Getopt.pm
@@ -71,9 +71,9 @@ sub NonOption {
sub getoptions {
my $array=shift;
- my %options=%{shift()} if ref $_[0];
+ my $extraoptions=shift;
- Getopt::Long::GetOptionsFromArray($array,
+ my %options=(
"v" => \$dh{VERBOSE},
"verbose" => \$dh{VERBOSE},
@@ -137,25 +137,42 @@ sub getoptions {
"ignore=s" => \&AddIgnore,
- %options,
-
"<>" => \&NonOption,
- )
+ );
+
+ # Merge extra options and cancel default ones as needed (undef)
+ if (defined $extraoptions) {
+ for my $opt (keys %$extraoptions) {
+ if (defined $extraoptions->{$opt}) {
+ $options{$opt}=$extraoptions->{$opt};
+ }
+ else {
+ delete $options{$opt};
+ }
+ }
+ }
+
+ Getopt::Long::GetOptionsFromArray($array, %options);
+}
+
+sub split_options_string {
+ my $str=shift;
+
+ $str=~s/^\s+//;
+ return map { $_=~s/\\(\s)/$1/g; $_=~s/\s+$//g; $_ } split(/(?<!\\)\s+/,$str);
}
# Parse options and set %dh values.
sub parseopts {
my $options=shift;
+ my $extra_args=shift;
my @ARGV_extra;
# DH_INTERNAL_OPTIONS is used to pass additional options from
# dh through an override target to a command.
if (defined $ENV{DH_INTERNAL_OPTIONS}) {
- $ENV{DH_INTERNAL_OPTIONS}=~s/^\s+//;
- $ENV{DH_INTERNAL_OPTIONS}=~s/\s+$//;
- @ARGV_extra=split(/\s+/,$ENV{DH_INTERNAL_OPTIONS});
-
+ @ARGV_extra=split_options_string($ENV{DH_INTERNAL_OPTIONS});
# Unknown options will be silently ignored.
my $oldwarn=$SIG{__WARN__};
$SIG{__WARN__}=sub {};
@@ -184,15 +201,22 @@ sub parseopts {
# to be parsed like @ARGV, but with unknown options
# skipped.
if (defined $ENV{DH_OPTIONS}) {
- $ENV{DH_OPTIONS}=~s/^\s+//;
- $ENV{DH_OPTIONS}=~s/\s+$//;
- @ARGV_extra=split(/\s+/,$ENV{DH_OPTIONS});
+ @ARGV_extra=split_options_string($ENV{DH_OPTIONS});
my $ret=getoptions(\@ARGV_extra, $options);
if (!$ret) {
warning("warning: ignored unknown options in DH_OPTIONS");
}
}
+ if (defined $extra_args) {
+ my @extra_opts=split_options_string($extra_args);
+ my $ret=getoptions(\@extra_opts, $options);
+ if (!$ret) {
+ warning("warning: ignored unknown options");
+ }
+ push @ARGV_extra, @extra_opts;
+ }
+
my $ret=getoptions(\@ARGV, $options);
if (!$ret) {
warning("warning: unknown options will be a fatal error in a future debhelper release");
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index f09c8087..b3162d07 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -15,7 +15,8 @@ use vars qw(@ISA @EXPORT %dh);
&filedoublearray &getpackages &basename &dirname &xargs %dh
&compat &addsubstvar &delsubstvar &excludefile &package_arch
&is_udeb &udeb_filename &debhelper_script_subst &escape_shell
- &inhibit_log &load_log &write_log);
+ &inhibit_log &load_log &write_log &dpkg_architecture_value
+ &sourcepackage);
my $max_compat=7;
@@ -28,10 +29,10 @@ sub init {
# Getopt::Long, which I'd prefer to avoid loading at all if possible.
if ((defined $ENV{DH_OPTIONS} && length $ENV{DH_OPTIONS}) ||
(defined $ENV{DH_INTERNAL_OPTIONS} && length $ENV{DH_INTERNAL_OPTIONS}) ||
- grep /^-/, @ARGV) {
+ (defined $params{extra_args}) || grep /^-/, @ARGV) {
eval "use Debian::Debhelper::Dh_Getopt";
error($@) if $@;
- Debian::Debhelper::Dh_Getopt::parseopts($params{options});
+ Debian::Debhelper::Dh_Getopt::parseopts($params{options}, $params{extra_args});
}
# Another way to set excludes.
@@ -605,15 +606,21 @@ sub excludefile {
return 0;
}
+sub dpkg_architecture_value {
+ my $var = shift;
+ my $value=`dpkg-architecture -q$var 2>/dev/null` || error("dpkg-architecture failed");
+ chomp $value;
+ return $value;
+}
+
# Returns the build architecture. (Memoized)
{
my $arch;
sub buildarch {
- return $arch if defined $arch;
-
- $arch=`dpkg-architecture -qDEB_HOST_ARCH 2>/dev/null` || error("dpkg-architecture failed");
- chomp $arch;
+ if (!defined $arch) {
+ $arch=dpkg_architecture_value('DEB_HOST_ARCH');
+ }
return $arch;
}
}
@@ -643,6 +650,23 @@ sub samearch {
return 0;
}
+# Returns source package name
+sub sourcepackage {
+ open (CONTROL, 'debian/control') ||
+ error("cannot read debian/control: $!\n");
+ while (<CONTROL>) {
+ chomp;
+ s/\s+$//;
+ if (/^Source:\s*(.*)/) {
+ close CONTROL;
+ return $1;
+ }
+ }
+
+ close CONTROL;
+ error("could not find Source: line in control file.");
+}
+
# Returns a list of packages in the control file.
# Must pass "arch" or "indep" or "same" to specify arch-dependant or
# -independant or same arch packages. If nothing is specified, returns all
diff --git a/Makefile b/Makefile
index cde11399..f13b3fc9 100644
--- a/Makefile
+++ b/Makefile
@@ -63,13 +63,15 @@ clean:
install:
install -d $(DESTDIR)/usr/bin \
$(DESTDIR)/usr/share/debhelper/autoscripts \
- $(DESTDIR)$(PERLLIBDIR)/Sequence
+ $(DESTDIR)$(PERLLIBDIR)/Sequence \
+ $(DESTDIR)$(PERLLIBDIR)/Buildsystem
install $(shell find -maxdepth 1 -mindepth 1 -name dh\* |grep -v \.1\$$) $(DESTDIR)/usr/bin
install -m 0644 autoscripts/* $(DESTDIR)/usr/share/debhelper/autoscripts
install -m 0644 Debian/Debhelper/*.pm $(DESTDIR)$(PERLLIBDIR)
install -m 0644 Debian/Debhelper/Sequence/*.pm $(DESTDIR)$(PERLLIBDIR)/Sequence
+ install -m 0644 Debian/Debhelper/Buildsystem/*.pm $(DESTDIR)$(PERLLIBDIR)/Buildsystem
test: version
- ./run perl -MTest::Harness -e 'runtests grep { ! /CVS/ && ! /\.svn/ } @ARGV' t/*
+ ./run perl -MTest::Harness -e 'runtests grep { ! /CVS/ && ! /\.svn/ && -f && -x } @ARGV' t/* t/buildsystems/*
# clean up log etc
./run dh_clean
diff --git a/debhelper.pod b/debhelper.pod
index 388453c3..8c232d28 100644
--- a/debhelper.pod
+++ b/debhelper.pod
@@ -491,8 +491,14 @@ Anything in this variable will be prepended to the command line arguments
of all debhelper commands. Command-specific options will be ignored by
commands that do not support them.
-This is useful in some situations, for example, if you need to pass -p to
-all debhelper commands that will be run. One good way to set DH_OPTIONS is
+Arguments are separated by whitespaces unless a whitespace is escaped
+with a backslash character (\). Then the whitespace is treated literally.
+Likewise, the backslash character is treated literally unless it is followed
+by a single whitespace. If a backslash is followed by two or more spaces,
+it will be considered as the last symbol of the argument.
+
+DH_OPTIONS is useful in some situations, for example, if you need to pass -p
+to all debhelper commands that will be run. One good way to set DH_OPTIONS is
by using "Target-specific Variable Values" in your debian/rules file. See
the make documentation for details on doing this.
diff --git a/debian/changelog b/debian/changelog
index c735e9d2..3916f1ce 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,23 @@
+debhelper (7.3.0) UNRELEASED; urgency=low
+
+ * Modular object oriented dh_auto_* buildsystem support,
+ contributed by Modestas Vainius
+ - dh_auto_* --sourcedirectory can now be used to specify a source
+ directory if sources and/or the whole buildsystem lives in other
+ but the top level directory. Closes: #530597
+ - dh_auto_* --builddirectory can now be used to specify a build
+ directory to use for out of source building, for build systems
+ that support it. Closes: #480577
+ - dh_auto_* --buildsystem can now be used to override the autodetected
+ build system, or force use of a third-party class.
+ - dh_auto_* --list can be used to list available and selected build
+ systems.
+ - Adds support for cmake.
+ - Historical dh_auto_* behavior should be preserved despite these
+ large changes..
+
+ -- Joey Hess <joeyh@debian.org> Mon, 20 Apr 2009 16:26:08 -0400
+
debhelper (7.2.17) UNRELEASED; urgency=low
* Allow command-specific options to be passed to commands
diff --git a/debian/copyright b/debian/copyright
index 46e44921..ffb117c9 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -54,3 +54,7 @@ License: GPL-2+
Files: dh_bugfiles
Copyright: Modestas Vainius <modestas@vainius.eu>
License: GPL-2+
+
+Files: Debian/Debhelper/Buildsystem*, Debian/Debhelper/Dh_Buildsystems.pm
+Copyright: © 2008-2009 Modestas Vainius
+License: GPL-2+
diff --git a/dh_auto_build b/dh_auto_build
index 75ce51cf..56b9b5f0 100755
--- a/dh_auto_build
+++ b/dh_auto_build
@@ -7,7 +7,7 @@ dh_auto_build - automatically builds a package
=cut
use strict;
-use Debian::Debhelper::Dh_Lib;
+use Debian::Debhelper::Dh_Buildsystems;
=head1 SYNOPSIS
@@ -37,18 +37,8 @@ or override any standard parameters that dh_auto_build passes.
=cut
-init();
-
-if (-e "Makefile" || -e "makefile" || -e "GNUmakefile") {
- doit(exists $ENV{MAKE} ? $ENV{MAKE} : "make", @{$dh{U_PARAMS}});
-}
-elsif (-e "setup.py") {
- doit("python", "setup.py", "build", @{$dh{U_PARAMS}});
-}
-elsif (-e "Build.PL" && -e "Build") {
- $ENV{MODULEBUILDRC} = "/dev/null";
- doit("perl", "Build", @{$dh{U_PARAMS}});
-}
+buildsystems_init();
+buildsystems_do();
=head1 SEE ALSO
diff --git a/dh_auto_clean b/dh_auto_clean
index 610155ae..1b7d46cd 100755
--- a/dh_auto_clean
+++ b/dh_auto_clean
@@ -7,7 +7,7 @@ dh_auto_clean - automatically cleans up after a build
=cut
use strict;
-use Debian::Debhelper::Dh_Lib;
+use Debian::Debhelper::Dh_Buildsystems;
=head1 SYNOPSIS
@@ -38,31 +38,8 @@ or override the any standard parameters that dh_auto_clean passes.
=cut
-init();
-
-if (-e "Makefile" || -e "makefile" || -e "GNUmakefile") {
- $ENV{MAKE}="make" unless exists $ENV{MAKE};
- foreach my $target (qw{distclean realclean clean}) {
- # 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=`$ENV{MAKE} -s -n $target 2>/dev/null`;
- chomp $ret;
- if (length $ret) {
- doit($ENV{MAKE}, $target, @{$dh{U_PARAMS}});
- last;
- }
- }
-}
-elsif (-e "setup.py") {
- doit("python", "setup.py", "clean", "-a", @{$dh{U_PARAMS}});
- # The setup.py might import files, leading to python creating pyc
- # files.
- doit('find', '.', '-name', '*.pyc', '-exec', 'rm', '{}', ';');
-}
-elsif (-e "Build.PL" && -e "Build") {
- $ENV{MODULEBUILDRC} = "/dev/null";
- doit("perl", "Build", "--allow_mb_mismatch", 1, "distclean", @{$dh{U_PARAMS}});
-}
+buildsystems_init();
+buildsystems_do();
=head1 SEE ALSO
diff --git a/dh_auto_configure b/dh_auto_configure
index 5f48056f..34d6298a 100755
--- a/dh_auto_configure
+++ b/dh_auto_configure
@@ -7,7 +7,7 @@ dh_auto_configure - automatically configure a package prior to building
=cut
use strict;
-use Debian::Debhelper::Dh_Lib;
+use Debian::Debhelper::Dh_Buildsystems;
=head1 SYNOPSIS
@@ -17,7 +17,7 @@ B<dh_auto_configure> [S<I<debhelper options>>] [S<B<--> I<params>>]
dh_auto_configure is a debhelper program that tries to automatically
configure a package prior to building. It looks for and runs a ./configure
-script, Makefile.PL, or Build.PL. A standard set of parameters is
+script, Makefile.PL, Build.PL, or cmake. A standard set of parameters is
determined and passed to the program that is run. If no program to run is
found, dh_auto_configure will exit without doing anything.
@@ -41,67 +41,8 @@ or override those parameters. For example:
=cut
-init();
-
-sub dpkg_architecture_value {
- my $var=shift;
- my $value=`dpkg-architecture -q$var 2>/dev/null` || error("dpkg-architecture failed");
- chomp $value;
- return $value;
-}
-
-sub sourcepackage {
- open (CONTROL, 'debian/control') ||
- error("cannot read debian/control: $!\n");
- while (<CONTROL>) {
- chomp;
- s/\s+$//;
- if (/^Source:\s*(.*)/) {
- close CONTROL;
- return $1;
- }
- }
-
- close CONTROL;
- error("could not find Source: line in control file.");
-}
-
-if (-x "configure") {
- # Standard set of options for configure.
- my @opts;
- push @opts, "--build=".dpkg_architecture_value("DEB_BUILD_GNU_TYPE");
- push @opts, "--prefix=/usr";
- push @opts, "--includedir=\${prefix}/include";
- push @opts, "--mandir=\${prefix}/share/man";
- push @opts, "--infodir=\${prefix}/share/info";
- push @opts, "--sysconfdir=/etc";
- push @opts, "--localstatedir=/var";
- push @opts, "--libexecdir=\${prefix}/lib/".sourcepackage();
- push @opts, "--disable-maintainer-mode";
- push @opts, "--disable-dependency-tracking";
- # Provide --host only if different from --build, as recommended in
- # autotools-dev README.Debian: When provided (even if equal) autotools
- # 2.52+ switches to cross-compiling mode.
- if (dpkg_architecture_value("DEB_BUILD_GNU_TYPE") ne dpkg_architecture_value("DEB_HOST_GNU_TYPE")) {
- push @opts, "--host=".dpkg_architecture_value("DEB_HOST_GNU_TYPE");
- }
- doit("./configure", @opts, @{$dh{U_PARAMS}});
-}
-elsif (-e "Makefile.PL") {
- # If set to a true value then MakeMaker's prompt function will
- # always return the default without waiting for user input.
- $ENV{PERL_MM_USE_DEFAULT}=1;
- # This prevents Module::Install from interactive behavior.
- $ENV{PERL_AUTOINSTALL}="--skipdeps";
-
- doit("perl", "Makefile.PL", "INSTALLDIRS=vendor",
- "create_packlist=0", @{$dh{U_PARAMS}});
-}
-elsif (-e "Build.PL") {
- $ENV{PERL_MM_USE_DEFAULT}=1; # Module::Build can also use this.
- $ENV{MODULEBUILDRC} = "/dev/null";
- doit("perl", "Build.PL", "installdirs=vendor", @{$dh{U_PARAMS}});
-}
+buildsystems_init();
+buildsystems_do();
=head1 SEE ALSO
diff --git a/dh_auto_install b/dh_auto_install
index 264725ca..db2c6e90 100755
--- a/dh_auto_install
+++ b/dh_auto_install
@@ -8,6 +8,7 @@ dh_auto_install - automatically runs make install or similar
use strict;
use Debian::Debhelper::Dh_Lib;
+use Debian::Debhelper::Dh_Buildsystems;
use Cwd;
=head1 SYNOPSIS
@@ -48,7 +49,7 @@ or override the any standard parameters that dh_auto_install passes.
=cut
-init();
+buildsystems_init();
my $destdir;
my @allpackages=getpackages();
@@ -60,40 +61,7 @@ else {
}
$destdir=cwd()."/".$destdir;
-if (-e "Makefile" || -e "makefile" || -e "GNUmakefile") {
- $ENV{MAKE}="make" unless exists $ENV{MAKE};
- my @params="DESTDIR=$destdir";
-
- # Special case for MakeMaker generated Makefiles.
- if (-e "Makefile" &&
- system('grep -q "generated automatically by MakeMaker" Makefile') == 0) {
- push @params, "PREFIX=/usr";
- }
-
- foreach my $target (qw{install}) {
- # 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=`$ENV{MAKE} -s -n $target 2>/dev/null`;
- chomp $ret;
- if (length $ret) {
- doit($ENV{MAKE}, $target,
- @params,
- @{$dh{U_PARAMS}});
- last;
- }
- }
-}
-elsif (-e "setup.py") {
- doit("python", "setup.py", "install",
- "--root=$destdir",
- "--no-compile", "-O0",
- @{$dh{U_PARAMS}});
-}
-elsif (-e "Build.PL" && -e "Build") {
- $ENV{MODULEBUILDRC} = "/dev/null";
- doit("perl", "Build", "install", "destdir=$destdir",
- "create_packlist=0", @{$dh{U_PARAMS}});
-}
+buildsystems_do("install", $destdir);
=head1 SEE ALSO
diff --git a/dh_auto_test b/dh_auto_test
index ea2d7fdc..e68bf09a 100755
--- a/dh_auto_test
+++ b/dh_auto_test
@@ -7,7 +7,7 @@ dh_auto_test - automatically runs a package's test suites
=cut
use strict;
-use Debian::Debhelper::Dh_Lib;
+use Debian::Debhelper::Dh_Buildsystems;
=head1 SYNOPSIS
@@ -44,29 +44,12 @@ tests will be performed.
=cut
-init();
-
if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS} =~ /nocheck/) {
exit 0;
}
-if (-e "Makefile" || -e "makefile" || -e "GNUmakefile") {
- $ENV{MAKE}="make" unless exists $ENV{MAKE};
- foreach my $target (qw{test check}) {
- # 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=`$ENV{MAKE} -s -n $target 2>/dev/null`;
- chomp $ret;
- if (length $ret) {
- doit($ENV{MAKE}, $target, @{$dh{U_PARAMS}});
- last;
- }
- }
-}
-elsif (-e "Build.PL" && -e "Build") {
- $ENV{MODULEBUILDRC} = "/dev/null";
- doit(qw/perl Build test/, @{$dh{U_PARAMS}});
-}
+buildsystems_init();
+buildsystems_do();
=head1 SEE ALSO
diff --git a/doc/PROGRAMMING b/doc/PROGRAMMING
index 9963181e..bd79628c 100644
--- a/doc/PROGRAMMING
+++ b/doc/PROGRAMMING
@@ -250,13 +250,13 @@ write_log($cmd, $package ...)
Writes the log files for the specified package(s), adding
the cmd to the end.
-Sequence Addons
+Sequence Addons:
---------------
The dh(1) command has a --with <addon> parameter that ca be used to load
-a sequence addon named Debian::Debhelper::Sequence::<addon>.
-These addons can add/remove commands to the dh command sequences, by calling
-some functions from Dh_Lib:
+a sequence addon module named Debian::Debhelper::Sequence::<addon>.
+These modules can add/remove commands to the dh command sequences, by
+calling some functions from Dh_Lib:
insert_before($existing_command, $new_command)
Insert $new_command in sequences before $existing_command
@@ -267,4 +267,19 @@ insert_after($existing_command, $new_command)
remove_command($existing_command)
Remove $existing_command from the list of commands to run.
+Buildsystem Classes:
+-------------------
+
+The dh_auto_* commands are frontends that use debhelper buildsystem
+classes. These classes have names like Debian::Debhelper::Buildsystem::foo,
+and are derived from Debian::Debhelper::Buildsystem, or other, related
+classes.
+
+A buildsystem class needs to inherit or define these methods: DESCRIPTION,
+check_auto_buildable, build, test, install, clean. See the comments
+inside Debian::Debhelper::Buildsystem for details.
+
+Note that third-party buildsystems will not automatically be used by default,
+but can be forced to be used via the --buildsystem parameter.
+
-- Joey Hess <joeyh@debian.org>
diff --git a/t/buildsystems/autoconf/configure b/t/buildsystems/autoconf/configure
new file mode 100755
index 00000000..adea14e6
--- /dev/null
+++ b/t/buildsystems/autoconf/configure
@@ -0,0 +1,74 @@
+#!/usr/bin/perl
+
+# Emulate autoconf behaviour and do some checks
+
+use strict;
+use warnings;
+
+my @OPTIONS=qw(
+ ^--build=.*$
+ ^--prefix=/usr$
+ ^--includedir=\$\{prefix\}/include$
+ ^--mandir=\$\{prefix\}/share/man$
+ ^--infodir=\$\{prefix\}/share/info$
+ ^--sysconfdir=/etc$
+ ^--localstatedir=/var$
+ ^--libexecdir=\$\{prefix\}/lib/.*$
+ ^--disable-maintainer-mode$
+ ^--disable-dependency-tracking$
+);
+
+# Verify if all command line arguments were passed
+my @options = map { { regex => qr/$_/,
+ str => $_,
+ found => 0 } } @OPTIONS;
+my @extra_args;
+ARGV_LOOP: foreach my $arg (@ARGV) {
+ foreach my $opt (@options) {
+ if ($arg =~ $opt->{regex}) {
+ $opt->{found} = 1;
+ next ARGV_LOOP;
+ }
+ }
+ # Extra / unrecognized argument
+ push @extra_args, $arg;
+}
+
+my @notfound = grep { ! $_->{found} and $_ } @options;
+if (@notfound) {
+ print STDERR "Error: the following default options were NOT passed\n";
+ print STDERR " ", $_->{str}, "\n" foreach (@notfound);
+ exit 1;
+}
+
+# Create a simple Makefile
+open(MAKEFILE, ">", "Makefile");
+print MAKEFILE <<EOF;
+CONFIGURE := $0
+all: stamp_configure \$(CONFIGURE)
+ \@echo Package built > stamp_build
+
+# Tests if dh_auto_test executes 'check' target if 'test' does not exist
+check: \$(CONFIGURE) stamp_build
+ \@echo Tested > stamp_test
+
+install: stamp_build
+ \@echo DESTDIR=\$(DESTDIR) > stamp_install
+
+# Tests whether dh_auto_clean executes distclean but does not touch
+# this target
+clean:
+ echo "This should not have been executed" >&2 && exit 1
+
+distclean:
+ \@rm -f stamp_* Makefile
+
+.PHONY: all check install clean distclean
+EOF
+close MAKEFILE;
+
+open(STAMP, ">", "stamp_configure");
+print STAMP $_, "\n" foreach (@extra_args);
+close STAMP;
+
+exit 0;
diff --git a/t/buildsystems/buildsystem_tests b/t/buildsystems/buildsystem_tests
new file mode 100755
index 00000000..a2b451a9
--- /dev/null
+++ b/t/buildsystems/buildsystem_tests
@@ -0,0 +1,430 @@
+#!/usr/bin/perl
+
+use Test::More tests => 224;
+
+use strict;
+use warnings;
+use IPC::Open2;
+use Cwd ();
+use File::Temp qw(tempfile tempdir);
+use File::Basename ();
+
+# Let the tests to be run from anywhere but currect directory
+# is expected to be the one where this test lives in.
+chdir File::Basename::dirname($0) or die "Unable to chdir to ".File::Basename::dirname($0);
+
+use_ok( 'Debian::Debhelper::Dh_Lib' );
+use_ok( 'Debian::Debhelper::Buildsystem' );
+use_ok( 'Debian::Debhelper::Dh_Buildsystems' );
+
+my $TOPDIR = "../..";
+my @STEPS = qw(configure build test install clean);
+my @BUILDSYSTEMS = qw(autoconf perl_makemaker makefile python_distutils perl_build cmake);
+my $BS_CLASS = 'Debian::Debhelper::Buildsystem';
+
+my ($bs, @bs, %bs);
+my ($tmp, @tmp, %tmp);
+my ($tmpdir, $builddir, $default_builddir);
+
+### Common subs ####
+sub touch {
+ my $file=shift;
+ my $chmod=shift;
+ open FILE, ">", $file and close FILE or die "Unable to touch $file";
+ chmod $chmod, $file if defined $chmod;
+}
+
+sub cleandir {
+ my $dir=shift;
+ system ("find", $dir, "-type", "f", "-delete");
+}
+sub readlines {
+ my $h=shift;
+ my @lines = <$h>;
+ close $h;
+ chop @lines;
+ return \@lines;
+}
+
+sub process_stdout {
+ my ($cmdline, $stdin) = @_;
+ my ($reader, $writer);
+
+ open2($reader, $writer, $cmdline) or die "Unable to exec $cmdline";
+ print $writer $stdin if $stdin;
+ close $writer;
+ return readlines($reader);
+}
+
+### Test Buildsystem class API methods
+is( $BS_CLASS->_canonpath("path/to/the/./nowhere/../../somewhere"),
+ "path/to/somewhere", "_canonpath no1" );
+is( $BS_CLASS->_canonpath("path/to/../forward/../../somewhere"),
+ "somewhere","_canonpath no2" );
+is( $BS_CLASS->_canonpath("path/to/../../../somewhere"),
+ "../somewhere","_canonpath no3" );
+is( $BS_CLASS->_rel2rel("path/my/file", "path/my"),
+ "file", "_rel2rel no1" );
+is( $BS_CLASS->_rel2rel("path/dir/file", "path/my"),
+ "../dir/file", "_rel2rel no2" );
+is( $BS_CLASS->_rel2rel("file", "/root/path/my", "/root"),
+ "../../file", "_rel2rel no3" );
+
+### Test Buildsystem class path API methods under different configurations
+sub test_buildsystem_paths_api {
+ my ($bs, $config, $expected)=@_;
+
+ my $api_is = sub {
+ my ($got, $name)=@_;
+ is( $got, $expected->{$name}, "paths API ($config): $name")
+ };
+
+ &$api_is( $bs->get_sourcedir(), 'get_sourcedir()' );
+ &$api_is( $bs->get_sourcepath("a/b"), 'get_sourcepath(a/b)' );
+ &$api_is( $bs->get_builddir(), 'get_builddir()' );
+ &$api_is( $bs->get_buildpath(), 'get_buildpath()' );
+ &$api_is( $bs->get_buildpath("a/b"), 'get_buildpath(a/b)' );
+ &$api_is( $bs->get_source_rel2builddir(), 'get_source_rel2builddir()' );
+ &$api_is( $bs->get_source_rel2builddir("a/b"), 'get_source_rel2builddir(a/b)' );
+ &$api_is( $bs->get_build_rel2sourcedir(), 'get_build_rel2sourcedir()' );
+ &$api_is( $bs->get_build_rel2sourcedir("a/b"), 'get_build_rel2sourcedir(a/b)' );
+}
+
+# Defaults
+$bs = $BS_CLASS->new();
+$default_builddir = $bs->DEFAULT_BUILD_DIRECTORY();
+%tmp = (
+ "get_sourcedir()" => ".",
+ "get_sourcepath(a/b)" => "./a/b",
+ "get_builddir()" => undef,
+ "get_buildpath()" => ".",
+ "get_buildpath(a/b)" => "./a/b",
+ "get_source_rel2builddir()" => ".",
+ "get_source_rel2builddir(a/b)" => "./a/b",
+ "get_build_rel2sourcedir()" => ".",
+ "get_build_rel2sourcedir(a/b)" => "./a/b",
+);
+test_buildsystem_paths_api($bs, "no builddir, no sourcedir", \%tmp);
+
+# builddir=bld/dir
+$bs = $BS_CLASS->new(builddir => "bld/dir");
+%tmp = (
+ "get_sourcedir()" => ".",
+ "get_sourcepath(a/b)" => "./a/b",
+ "get_builddir()" => "bld/dir",
+ "get_buildpath()" => "bld/dir",
+ "get_buildpath(a/b)" => "bld/dir/a/b",
+ "get_source_rel2builddir()" => "../..",
+ "get_source_rel2builddir(a/b)" => "../../a/b",
+ "get_build_rel2sourcedir()" => "bld/dir",
+ "get_build_rel2sourcedir(a/b)" => "bld/dir/a/b",
+);
+test_buildsystem_paths_api($bs, "builddir=bld/dir, no sourcedir", \%tmp);
+
+# Default builddir, sourcedir=autoconf
+$bs = $BS_CLASS->new(builddir => undef, sourcedir => "autoconf");
+%tmp = (
+ "get_sourcedir()" => "autoconf",
+ "get_sourcepath(a/b)" => "autoconf/a/b",
+ "get_builddir()" => "autoconf/$default_builddir",
+ "get_buildpath()" => "autoconf/$default_builddir",
+ "get_buildpath(a/b)" => "autoconf/$default_builddir/a/b",
+ "get_source_rel2builddir()" => "..",
+ "get_source_rel2builddir(a/b)" => "../a/b",
+ "get_build_rel2sourcedir()" => "$default_builddir",
+ "get_build_rel2sourcedir(a/b)" => "$default_builddir/a/b",
+);
+test_buildsystem_paths_api($bs, "default builddir, sourcedir=autoconf", \%tmp);
+
+# Enforced out of source tree building
+# sourcedir=builddir=autoconf hence default builddir is implied
+$bs = $BS_CLASS->new(builddir => "./autoconf", sourcedir => "autoconf/");
+$bs->enforce_out_of_source_building();
+test_buildsystem_paths_api($bs, "out of source enforced, sourcedir=autoconf/", \%tmp);
+
+# sourcedir=autoconf (builddir should be dropped)
+$bs = $BS_CLASS->new(builddir => ".", sourcedir => "autoconf");
+%tmp = (
+ "get_sourcedir()" => "autoconf",
+ "get_sourcepath(a/b)" => "autoconf/a/b",
+ "get_builddir()" => undef,
+ "get_buildpath()" => "autoconf",
+ "get_buildpath(a/b)" => "autoconf/a/b",
+ "get_source_rel2builddir()" => ".",
+ "get_source_rel2builddir(a/b)" => "./a/b",
+ "get_build_rel2sourcedir()" => ".",
+ "get_build_rel2sourcedir(a/b)" => "./a/b",
+);
+test_buildsystem_paths_api($bs, "no builddir, sourcedir=autoconf", \%tmp);
+
+# builddir=bld/dir, sourcedir=autoconf. Should be the same as sourcedir=autoconf.
+$bs = $BS_CLASS->new(builddir => "bld/dir", sourcedir => "autoconf");
+$bs->enforce_in_source_building();
+test_buildsystem_paths_api($bs, "in source enforced, sourcedir=autoconf", \%tmp);
+
+# builddir=../bld/dir (relative to the sourcedir)
+$bs = $BS_CLASS->new(builddir => "../bld/dir/", sourcedir => "autoconf");
+%tmp = (
+ "get_sourcedir()" => "autoconf",
+ "get_sourcepath(a/b)" => "autoconf/a/b",
+ "get_builddir()" => "bld/dir",
+ "get_buildpath()" => "bld/dir",
+ "get_buildpath(a/b)" => "bld/dir/a/b",
+ "get_source_rel2builddir()" => "../../autoconf",
+ "get_source_rel2builddir(a/b)" => "../../autoconf/a/b",
+ "get_build_rel2sourcedir()" => "../bld/dir",
+ "get_build_rel2sourcedir(a/b)" => "../bld/dir/a/b",
+);
+test_buildsystem_paths_api($bs, "builddir=../bld/dir, sourcedir=autoconf", \%tmp);
+
+# Builddir relative to the pwd (same path as above).
+$bs = $BS_CLASS->new(builddir => "./bld/dir", sourcedir => "autoconf");
+test_buildsystem_paths_api($bs, "builddir=./bld/dir, sourcedir=autoconf", \%tmp);
+
+### Test if all buildsystems can be loaded
+@bs = load_all_buildsystems([ $INC[0] ]);
+@tmp = map { $_->NAME() } @bs;
+is_deeply( \@tmp, \@BUILDSYSTEMS, "load_all_buildsystems() loads all built-in buildsystems" );
+
+### Test check_auto_buildable() of each buildsystem
+sub test_check_auto_buildable {
+ my $bs=shift;
+ my $config=shift;
+ my $expected=shift;
+ my @steps=@_ || @STEPS;
+
+ if (! ref $expected) {
+ my %all_steps;
+ $all_steps{$_} = $expected foreach (@steps);
+ $expected = \%all_steps;
+ }
+ for my $step (@steps) {
+ my $e = 0;
+ if (exists $expected->{$step}) {
+ $e = $expected->{$step};
+ } elsif (exists $expected->{default}) {
+ $e = $expected->{default};
+ }
+ if ($e) {
+ ok( $bs->check_auto_buildable($step),
+ $bs->NAME() . "($config): check_auto_buildable($step)" );
+ }
+ else {
+ ok( ! $bs->check_auto_buildable($step),
+ $bs->NAME() . "($config): ! check_auto_buildable($step)" );
+ }
+ }
+}
+
+$tmpdir = tempdir("tmp.XXXXXX");
+$builddir = "$tmpdir/builddir";
+mkdir $builddir;
+%tmp = (
+ builddir => 'builddir',
+ sourcedir => $tmpdir
+);
+
+$bs{autoconf} = load_buildsystem("autoconf", undef, %tmp);
+$bs{cmake} = load_buildsystem("cmake", undef, %tmp);
+$bs{perl_mm} = load_buildsystem("perl_makemaker", undef, %tmp);
+$bs = load_buildsystem("makefile", undef, %tmp);
+
+test_check_auto_buildable($bs{autoconf}, "no configure", 0);
+test_check_auto_buildable($bs{cmake}, "no CMakeLists.txt", 0);
+test_check_auto_buildable($bs{perl_mm}, "no Makefile.PL", 0);
+test_check_auto_buildable($bs, "no Makefile", 0);
+
+touch "$tmpdir/configure", 0755;
+test_check_auto_buildable($bs{autoconf}, "configure", { configure => 1 });
+
+touch "$tmpdir/CMakeLists.txt";
+test_check_auto_buildable($bs{cmake}, "CMakeLists.txt", { configure => 1 });
+
+touch "$tmpdir/Makefile.PL";
+test_check_auto_buildable($bs{perl_mm}, "Makefile.PL",
+ { configure => 1, install => 1 });
+
+# With Makefile
+touch "$builddir/Makefile";
+test_check_auto_buildable($bs, "Makefile", { configure => 0, default => 1 });
+test_check_auto_buildable($bs{autoconf}, "configure+Makefile", { configure => 1 });
+test_check_auto_buildable($bs{cmake}, "CMakeLists.txt+Makefile", 1);
+
+# Makefile.PL forces in-source
+#(see note in check_auto_buildable() why always 1 here)
+unlink "$builddir/Makefile";
+touch "$tmpdir/Makefile";
+test_check_auto_buildable($bs{perl_mm}, "Makefile.PL+Makefile", 1);
+
+# Perl Build.PL - handles always
+$bs = load_buildsystem("perl_build", undef, %tmp);
+test_check_auto_buildable($bs, "no Build.PL", 0);
+touch "$tmpdir/Build.PL";
+test_check_auto_buildable($bs, "Build.PL", { configure => 1 });
+touch "$tmpdir/Build"; # forced in source
+test_check_auto_buildable($bs, "Build.PL+Build", 1);
+
+# Python Distutils
+$bs = load_buildsystem("python_distutils", undef, %tmp);
+test_check_auto_buildable($bs, "no setup.py", 0);
+touch "$tmpdir/setup.py";
+test_check_auto_buildable($bs, "setup.py", 1);
+
+cleandir($tmpdir);
+
+### Now test if it can autoselect a proper buildsystem for a typical package
+sub test_autoselection {
+ my $system=shift;
+ my $expected=shift;
+ for my $step (@STEPS) {
+ my $bs = load_buildsystem(undef, $step, @_);
+ my $e = $expected;
+ $e = $expected->{$step} if ref $expected;
+ if (defined $bs) {
+ is( $bs->NAME(), $e, "autoselection($system): $step=".((defined $e)?$e:'undef') );
+ }
+ else {
+ is ( undef, $e, "autoselection($system): $step=".((defined $e)?$e:'undef') );
+ }
+ }
+}
+
+# Autoconf
+touch "$tmpdir/configure", 0755;
+touch "$builddir/Makefile";
+test_autoselection("autoconf",
+ { configure => "autoconf", build => "makefile",
+ test => "makefile", install => "makefile", clean => "makefile" }, %tmp);
+cleandir $tmpdir;
+
+# Perl Makemaker (build, test, clean fail with builddir set [not supported])
+touch "$tmpdir/Makefile.PL";
+touch "$tmpdir/Makefile";
+test_autoselection("perl_makemaker", "perl_makemaker", %tmp);
+cleandir $tmpdir;
+
+# Makefile
+touch "$builddir/Makefile";
+test_autoselection("makefile", { build => "makefile", test => "makefile",
+ install => "makefile", clean => "makefile" }, %tmp);
+cleandir $tmpdir;
+
+# Python Distutils
+touch "$tmpdir/setup.py";
+test_autoselection("python_distutils", "python_distutils", %tmp);
+cleandir $tmpdir;
+
+# Perl Build
+touch "$tmpdir/Build.PL";
+touch "$tmpdir/Build";
+test_autoselection("perl_build", "perl_build", %tmp);
+cleandir $tmpdir;
+
+# CMake
+touch "$tmpdir/CMakeLists.txt";
+touch "$builddir/Makefile";
+test_autoselection("cmake",
+ { configure => "cmake", build => "makefile",
+ test => "makefile", install => "makefile", clean => "makefile" }, %tmp);
+cleandir $tmpdir;
+
+### Test buildsystems_init() and commandline/env argument handling
+sub get_load_bs_source {
+ my ($system, $step)=@_;
+ $step = (defined $step) ? "'$step'" : 'undef';
+ $system = (defined $system) ? "'$system'" : 'undef';
+
+return <<EOF;
+use strict;
+use warnings;
+use Debian::Debhelper::Dh_Buildsystems;
+
+buildsystems_init();
+my \$bs = load_buildsystem($system, $step);
+if (defined \$bs) {
+ print 'NAME=', \$bs->NAME(), "\\n";
+ print \$_, "=", (defined \$bs->{\$_}) ? \$bs->{\$_} : 'undef', "\\n"
+ foreach (sort keys \%\$bs);
+}
+EOF
+}
+
+is_deeply( process_stdout("DH_AUTO_OPTIONS='--builddirectory=bld\\ dir --sourcedirectory autoconf' $^X -- -",
+ get_load_bs_source(undef, "configure")),
+ [ 'NAME=autoconf', 'builddir=autoconf/bld dir', 'makecmd=make', 'sourcedir=autoconf' ],
+ "dh_auto_options w/space, autoconf autoselection and sourcedir/builddir" );
+
+is_deeply( process_stdout("$^X -- - -cautoconf -d autoconf", get_load_bs_source("autoconf", "build")),
+ [ 'NAME=autoconf', 'builddir=undef', 'makecmd=make', 'sourcedir=autoconf' ],
+ "forced autoconf and sourcedir" );
+
+is_deeply( process_stdout("$^X -- - -b -cautoconf", get_load_bs_source("autoconf", "build")),
+ [ 'NAME=autoconf', "builddir=$default_builddir", 'makecmd=make', 'sourcedir=.' ],
+ "forced autoconf and default build directory" );
+
+# Build the autoconf test package
+sub dh_auto_do_autoconf {
+ my $sourcedir=shift;
+ my $builddir=shift;
+ my %args=@_;
+
+ my (@lines, @extra_args);
+ my $buildpath = $sourcedir;
+ my @dh_auto_args = ("-d", $sourcedir);
+ my $dh_auto_str = "-d $sourcedir";
+ if ($builddir) {
+ push @dh_auto_args, "-b", $builddir;
+ $dh_auto_str .= " -b $builddir";
+ $buildpath .= "/$builddir";
+ }
+
+ my $do_dh_auto = sub {
+ my $step=shift;
+ my @extra_args;
+ my $extra_str = "";
+ if (exists $args{"${step}_args"}) {
+ push @extra_args, @{$args{"${step}_args"}};
+ $extra_str .= " $_" foreach (@extra_args);
+ }
+ is ( system("$TOPDIR/dh_auto_$step", @dh_auto_args, "--", @extra_args), 0,
+ "dh_auto_$step $dh_auto_str$extra_str" );
+ return @extra_args;
+ };
+
+ @extra_args = &$do_dh_auto('configure');
+ ok ( -f "$buildpath/Makefile", "$buildpath/Makefile exists" );
+ @lines=();
+ if (ok( open(FILE, "$buildpath/stamp_configure"), "$buildpath/stamp_configure exists") ) {
+ @lines = @{readlines(\*FILE)};
+ }
+ is_deeply( \@lines, \@extra_args, "$buildpath/stamp_configure contains extra args" );
+
+ &$do_dh_auto('build');
+ ok ( -f "$buildpath/stamp_build", "$buildpath/stamp_build exists" );
+ &$do_dh_auto('test');
+ ok ( -f "$buildpath/stamp_test", "$buildpath/stamp_test exists" );
+ &$do_dh_auto('install');
+ @lines=();
+ if ( ok(open(FILE, "$buildpath/stamp_install"), "$buildpath/stamp_install exists") ) {
+ @lines = @{readlines(\*FILE)};
+ }
+ is_deeply( \@lines, [ "DESTDIR=".Cwd::getcwd()."/debian/testpackage" ],
+ "$buildpath/stamp_install contains DESTDIR" );
+ &$do_dh_auto('clean');
+ if ($builddir) {
+ ok ( ! -e "$buildpath", "builddir $buildpath was removed" );
+ }
+ else {
+ ok ( ! -e "$buildpath/Makefile" && ! -e "$buildpath/stamp_configure", "Makefile and stamps gone" );
+ }
+ ok ( -x "$sourcedir/configure", "configure script renamins after clean" );
+}
+
+dh_auto_do_autoconf('autoconf');
+dh_auto_do_autoconf('autoconf', 'bld/dir', configure_args => [ "--extra-autoconf-configure-arg" ]);
+ok ( ! -e 'autoconf/bld', "autoconf/bld got deleted too" );
+
+END {
+ system("rm", "-rf", $tmpdir);
+ system("$TOPDIR/dh_clean");
+}
diff --git a/t/buildsystems/debian/changelog b/t/buildsystems/debian/changelog
new file mode 100644
index 00000000..f902d892
--- /dev/null
+++ b/t/buildsystems/debian/changelog
@@ -0,0 +1,5 @@
+testpackage (1.0-1) unstable; urgency=low
+
+ * Initial release. (Closes: #XXXXXX)
+
+ -- Test <testing@nowhere> Tue, 09 Jun 2009 15:35:32 +0300
diff --git a/t/buildsystems/debian/compat b/t/buildsystems/debian/compat
new file mode 100644
index 00000000..7f8f011e
--- /dev/null
+++ b/t/buildsystems/debian/compat
@@ -0,0 +1 @@
+7
diff --git a/t/buildsystems/debian/control b/t/buildsystems/debian/control
new file mode 100644
index 00000000..7edd806e
--- /dev/null
+++ b/t/buildsystems/debian/control
@@ -0,0 +1,10 @@
+Source: testsrcpackage
+Section: devel
+Priority: optional
+Maintainer: Test <testing@nowhere>
+Standards-Version: 3.8.1
+
+Package: testpackage
+Architecture: all
+Description: short description
+ Long description
diff --git a/t/syntax b/t/syntax
index f80fa97c..92455457 100755
--- a/t/syntax
+++ b/t/syntax
@@ -2,7 +2,7 @@
use Test;
my @progs=grep { -x $_ } glob("dh_*"), "dh";
-my @libs=glob("Debian/Debhelper/*.pm");
+my @libs=(glob("Debian/Debhelper/*.pm"), glob("Debian/Debhelper/*/*.pm"));
plan(tests => (@progs + @libs));