summaryrefslogtreecommitdiff
path: root/Debian
diff options
context:
space:
mode:
Diffstat (limited to 'Debian')
-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
9 files changed, 804 insertions, 5 deletions
diff --git a/Debian/Debhelper/Buildsystem.pm b/Debian/Debhelper/Buildsystem.pm
new file mode 100644
index 0000000..5bebfe2
--- /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 0000000..fcdc256
--- /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 0000000..8bdbabb
--- /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 0000000..244ef30
--- /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 0000000..ce69f4c
--- /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 0000000..a7bb5cc
--- /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",
+ @_);
+}
+
+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 0000000..01a8c14
--- /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 0000000..afb03dd
--- /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 f09c808..28a90f7 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;
@@ -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