summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Debian/Debhelper/Buildsystem.pm257
-rw-r--r--Debian/Debhelper/Buildsystem/autoconf.pm56
-rw-r--r--Debian/Debhelper/Buildsystem/cmake.pm49
-rw-r--r--Debian/Debhelper/Buildsystem/makefile.pm94
-rw-r--r--Debian/Debhelper/Buildsystem/perl_build.pm68
-rw-r--r--Debian/Debhelper/Buildsystem/perl_makemaker.pm53
-rw-r--r--Debian/Debhelper/Buildsystem/python_distutils.pm51
-rw-r--r--Debian/Debhelper/Dh_Buildsystems.pm147
-rw-r--r--Debian/Debhelper/Dh_Lib.pm34
-rw-r--r--debian/changelog17
-rw-r--r--debian/copyright4
-rwxr-xr-xdh_auto_build16
-rwxr-xr-xdh_auto_clean29
-rwxr-xr-xdh_auto_configure64
-rwxr-xr-xdh_auto_install38
-rwxr-xr-xdh_auto_test23
-rw-r--r--doc/PROGRAMMING23
17 files changed, 860 insertions, 163 deletions
diff --git a/Debian/Debhelper/Buildsystem.pm b/Debian/Debhelper/Buildsystem.pm
new file mode 100644
index 00000000..5bebfe2e
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem.pm
@@ -0,0 +1,257 @@
+# 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:
+# - builddir - specifies build directory to use. If not specified,
+# in-source build will be performed. If undef or empty,
+# DEFAULT_BUILD_DIRECTORY will be used.
+# - build_action - set this parameter to the name of the build action
+# if you want the object to determine its is_buidable
+# status automatically (with check_auto_buildable()).
+# Do not pass this parameter if is_buildable flag should
+# be forced to true or set this parameter to undef if
+# is_buildable flag should be false.
+# Derived class can override the constructor to initialize common object
+# parameters and execute commands to configure build environment if
+# is_buildable flag is set on the object.
+sub new {
+ my ($class, %opts)=@_;
+
+ my $this = bless({ builddir => undef, is_buildable => 1 }, $class);
+ if (exists $opts{builddir}) {
+ if ($opts{builddir}) {
+ $this->{builddir} = $opts{builddir};
+ }
+ else {
+ $this->{builddir} = $this->DEFAULT_BUILD_DIRECTORY();
+ }
+ }
+ if (exists $opts{build_action}) {
+ if (defined $opts{build_action}) {
+ $this->{is_buildable} = $this->check_auto_buildable($opts{build_action});
+ }
+ else {
+ $this->{is_buildable} = 0;
+ }
+ }
+ return $this;
+}
+
+# Test is_buildable flag of the object.
+sub is_buildable {
+ my $this=shift;
+ return $this->{is_buildable};
+}
+
+# This instance method is called to check if the build system is capable
+# to auto build a source package. Additional argument $action 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 ($action) = @_;
+ 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->{builddir}) {
+ # Do not emit warning unless the object is buildable.
+ if ($this->is_buildable()) {
+ warning("warning: " . $this->NAME() .
+ " does not support building outside-source. In-source build enforced.");
+ }
+ $this->{builddir} = undef;
+ }
+}
+
+# Derived class can call this method in its constructor to enforce
+# outside-source building even if the user didn't request it.
+sub enforce_outside_source_building {
+ my ($this, $builddir) = @_;
+ if (!defined $this->{builddir}) {
+ $this->{builddir} = ($builddir && $builddir ne ".") ? $builddir : $this->DEFAULT_BUILD_DIRECTORY();
+ }
+}
+
+# Get path to the specified build directory
+sub get_builddir {
+ my $this=shift;
+ return $this->{builddir};
+}
+
+# Construct absolute path to the file from the given path that is relative
+# to the build directory.
+sub get_buildpath {
+ my ($this, $path) = @_;
+ if ($this->get_builddir()) {
+ return File::Spec->catfile($this->get_builddir(), $path);
+ }
+ else {
+ return File::Spec->catfile('.', $path);
+ }
+}
+
+# When given a relative path in the source tree, converts it
+# to the path that is relative to the build directory.
+# If $path is not given, returns relative path to the root of the
+# source tree from the build directory.
+sub get_rel2builddir_path {
+ my $this=shift;
+ my $path=shift;
+
+ if (defined $path) {
+ $path = File::Spec->catfile(Cwd::getcwd(), $path);
+ }
+ else {
+ $path = Cwd::getcwd();
+ }
+ if ($this->get_builddir()) {
+ return File::Spec->abs2rel($path, Cwd::abs_path($this->get_builddir()));
+ }
+ return $path;
+}
+
+# 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 the build directory (if needed), calls doit(@_)
+# and changes working directory back to the source directory.
+sub doit_in_builddir {
+ my $this=shift;
+ if ($this->get_builddir()) {
+ my $builddir = $this->get_builddir();
+ my $sourcedir = $this->get_rel2builddir_path();
+ $this->_cd($builddir);
+ doit(@_);
+ $this->_cd($sourcedir);
+ }
+ else {
+ doit(@_);
+ }
+ return 1;
+}
+
+# In case of outside-source tree building, whole build directory
+# gets wiped (if it exists) and 1 is returned. Otherwise, nothing
+# is done and 0 is returned.
+sub clean_builddir {
+ my $this=shift;
+ if ($this->get_builddir()) {
+ if (-d $this->get_builddir()) {
+ doit("rm", "-rf", $this->get_builddir());
+ }
+ return 1;
+ }
+ return 0;
+}
+
+
+# Instance method that is called before performing any action (see below).
+# Action name is passed as an argument. Derived classes overriding this
+# method should also call SUPER implementation of it.
+sub pre_action {
+ my $this=shift;
+ my ($action)=@_;
+}
+
+# Instance method that is called after performing any action (see below).
+# Action name is passed as an argument. Derived classes overriding this
+# method should also call SUPER implementation of it.
+sub post_action {
+ my $this=shift;
+ my ($action)=@_;
+}
+
+# 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 actions needed to build the
+# source. Arbitary number of custom action 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..fcdc2567
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/autoconf.pm
@@ -0,0 +1,56 @@
+# 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 File::Spec;
+use Debian::Debhelper::Dh_Lib;
+use base 'Debian::Debhelper::Buildsystem::makefile';
+
+sub DESCRIPTION {
+ "GNU Autoconf (configure)"
+}
+
+sub check_auto_buildable {
+ my $this=shift;
+ my ($action)=@_;
+
+ # Handle configure; the rest - next class
+ if ($action eq "configure") {
+ return -x "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_rel2builddir_path("configure"), @opts, @_);
+}
+
+1;
diff --git a/Debian/Debhelper/Buildsystem/cmake.pm b/Debian/Debhelper/Buildsystem/cmake.pm
new file mode 100644
index 00000000..8bdbabbb
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/cmake.pm
@@ -0,0 +1,49 @@
+# A buildsystem plugin for handling CMake based projects.
+# It enforces outside-source building.
+#
+# Copyright: © 2008-2009 Modestas Vainius
+# License: GPL-2+
+
+package Debian::Debhelper::Buildsystem::cmake;
+
+use strict;
+use Debian::Debhelper::Dh_Lib;
+use base 'Debian::Debhelper::Buildsystem::makefile';
+
+sub DESCRIPTION {
+ "CMake (CMakeLists.txt)"
+}
+
+sub check_auto_buildable {
+ my $this=shift;
+ my ($action)=@_;
+ my $ret = -e "CMakeLists.txt";
+ $ret &&= $this->SUPER::check_auto_buildable(@_) if $action ne "configure";
+ return $ret;
+}
+
+sub new {
+ my $class=shift;
+ my $this=$class->SUPER::new(@_);
+ # Enforce outside-source tree builds.
+ $this->enforce_outside_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_rel2builddir_path(), @flags);
+}
+
+1;
diff --git a/Debian/Debhelper/Buildsystem/makefile.pm b/Debian/Debhelper/Buildsystem/makefile.pm
new file mode 100644
index 00000000..244ef30d
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/makefile.pm
@@ -0,0 +1,94 @@
+# 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;
+use base 'Debian::Debhelper::Buildsystem';
+
+sub get_makecmd_C {
+ my $this=shift;
+ if ($this->get_builddir()) {
+ return $this->{makecmd} . " -C " . $this->get_builddir();
+ }
+ 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 $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 ($action) = @_;
+
+ # Handles build, test, install, clean; configure - next class
+ if (grep /^\Q$action\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->clean_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..ce69f4ce
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/perl_build.pm
@@ -0,0 +1,68 @@
+# 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 Debian::Debhelper::Dh_Lib;
+use base 'Debian::Debhelper::Buildsystem';
+
+sub DESCRIPTION {
+ "Perl Module::Build (Build.PL)"
+}
+
+sub check_auto_buildable {
+ my ($this, $action) = @_;
+
+ # Handles everything
+ my $ret = -e "Build.PL";
+ if ($action ne "configure") {
+ $ret &&= -e "Build";
+ }
+ return $ret;
+}
+
+sub do_perl {
+ my $this=shift;
+ $ENV{MODULEBUILDRC} = "/dev/null";
+ doit("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..c62041fe
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/perl_makemaker.pm
@@ -0,0 +1,53 @@
+# 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 Debian::Debhelper::Dh_Lib;
+use base 'Debian::Debhelper::Buildsystem::makefile';
+
+sub DESCRIPTION {
+ "Perl ExtUtils::MakeMaker (Makefile.PL)"
+}
+
+sub check_auto_buildable {
+ my $this=shift;
+ my ($action)=@_;
+
+ # Handles configure, install; the rest - next class
+ if ($action eq "install" || $action eq "configure") {
+ return -e "Makefile.PL";
+ }
+ else {
+ 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;
+ doit("perl", "Makefile.PL", "INSTALLDIRS=vendor",
+ "create_packlist=0", "--skipdeps",
+ @_);
+}
+
+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..01a8c14e
--- /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 Debian::Debhelper::Dh_Lib;
+use base 'Debian::Debhelper::Buildsystem';
+
+sub DESCRIPTION {
+ "Python distutils"
+}
+
+sub check_auto_buildable {
+ return -e "setup.py";
+}
+
+sub setup_py {
+ my $this=shift;
+ my $act=shift;
+
+ if ($this->get_builddir()) {
+ unshift @_, "--build-base=" . $this->get_builddir();
+ }
+ doit("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.
+ doit('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..afb03dd7
--- /dev/null
+++ b/Debian/Debhelper/Dh_Buildsystems.pm
@@ -0,0 +1,147 @@
+# 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 base 'Exporter';
+our @EXPORT=qw(&buildsystems_init &buildsystems_do &load_buildsystem);
+
+# 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_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;
+ }
+ return $module->new(%bsopts);
+}
+
+sub load_buildsystem {
+ my ($action, $system)=@_;
+ 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, build_action=>$action);
+ if ($inst->is_buildable()) {
+ return $inst;
+ }
+ }
+ }
+ return;
+}
+
+sub buildsystems_init {
+ my %args=@_;
+
+ # TODO: Not documented in the manual pages yet.
+ # Initialize options from environment variables
+ if (exists $ENV{DH_AUTO_BUILDDIRECTORY}) {
+ $opt_builddir = $ENV{DH_AUTO_BUILDDIRECTORY};
+ }
+ if (exists $ENV{DH_AUTO_BUILDSYSTEM}) {
+ $opt_buildsys = $ENV{DH_AUTO_BUILDSYSTEM};
+ }
+
+ # Available command line options
+ my %options = (
+ "b:s" => \$opt_builddir,
+ "builddirectory:s" => \$opt_builddir,
+
+ "m=s" => \$opt_buildsys,
+ "buildsystem=s" => \$opt_buildsys,
+
+ "l" => \$opt_list,
+ "--list" => \$opt_list,
+ );
+ map { $args{options}{$_} = $options{$_} } keys(%options);
+ Debian::Debhelper::Dh_Lib::init(%args);
+}
+
+sub buildsystems_list {
+ my $action=shift;
+
+ # List buildsystems (including auto and specified status)
+ my ($auto, $specified);
+ for my $system (@BUILDSYSTEMS) {
+ my $inst = create_buildsystem_instance($system, build_action => undef);
+ 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->check_auto_buildable($action)) {
+ $auto = $inst->NAME();
+ }
+ printf("%s - %s\n", $inst->NAME(), $inst->DESCRIPTION());
+ }
+ # List a specified 3rd party buildsystem too.
+ if (! defined $specified && defined $opt_buildsys) {
+ my $inst = create_buildsystem_instance($opt_buildsys, build_action => undef);
+ printf("%s - %s.\n", $inst->NAME(), $inst->DESCRIPTION());
+ $specified = $inst->NAME();
+ }
+ 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 $action=shift;
+
+ if (!defined $action) {
+ $action = basename($0);
+ $action =~ s/^dh_auto_//;
+ }
+
+ if (grep(/^\Q$action\E$/, qw{configure build test install clean}) == 0) {
+ error("unrecognized build action: " . $action);
+ }
+
+ if ($opt_list) {
+ buildsystems_list($action);
+ exit 0;
+ }
+
+ my $buildsystem = load_buildsystem($action, $opt_buildsys);
+ if (defined $buildsystem) {
+ $buildsystem->pre_action($action);
+ $buildsystem->$action(@_, @{$dh{U_PARAMS}});
+ $buildsystem->post_action($action);
+ }
+ return 0;
+}
+
+1;
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 829eabfc..c80389d7 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;
@@ -601,15 +602,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;
}
}
@@ -626,6 +633,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/debian/changelog b/debian/changelog
index 1f5cff0b..3a9a9f3f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,20 @@
+debhelper (7.3.0) UNRELEASED; urgency=low
+
+ * Modular object oriented dh_auto_* buildsystem support,
+ contributed by Modestas Vainius
+ - 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.11) UNRELEASED; urgency=low
* dh: Support --with addon,addon,...
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 a320df95..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,64 +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;
- doit("perl", "Makefile.PL", "INSTALLDIRS=vendor",
- "create_packlist=0", "--skipdeps", @{$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>