summaryrefslogtreecommitdiff
path: root/Debian/Debhelper
diff options
context:
space:
mode:
Diffstat (limited to 'Debian/Debhelper')
-rw-r--r--Debian/Debhelper/Buildsystem.pm377
-rw-r--r--Debian/Debhelper/Buildsystem/autoconf.pm55
-rw-r--r--Debian/Debhelper/Buildsystem/cmake.pm45
-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.pm114
-rw-r--r--Debian/Debhelper/Dh_Buildsystems.pm180
-rw-r--r--Debian/Debhelper/Dh_Getopt.pm15
-rw-r--r--Debian/Debhelper/Dh_Lib.pm34
10 files changed, 1034 insertions, 12 deletions
diff --git a/Debian/Debhelper/Buildsystem.pm b/Debian/Debhelper/Buildsystem.pm
new file mode 100644
index 00000000..3ee37a5f
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem.pm
@@ -0,0 +1,377 @@
+# Defines debhelper build system 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 build systems.
+our $DEB_BUILD_GNU_TYPE = dpkg_architecture_value("DEB_BUILD_GNU_TYPE");
+
+# Build system name. Defaults to the last component of the class
+# 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 build system 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
+# current (top) directory. If undef or empty,
+# DEFAULT_BUILD_DIRECTORY directory will be used.
+# Derived class can override the constructor to initialize common object
+# parameters. Do NOT use constructor to execute commands or otherwise
+# configure/setup build environment. There is absolutely no guarantee the
+# 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;
+ $this->{builddir} = ($builddir) ? $builddir : $this->DEFAULT_BUILD_DIRECTORY;
+
+ # Canonicalize. If build directory ends up the same as source directory, drop it
+ if (defined $this->{builddir}) {
+ $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. However,
+# if 'builddir' named parameter is passed, accept its value as the
+# build directory even if it matches the source directory (meaning out
+# of source is only prefered to in source, not enforced).
+sub enforce_out_of_source_building {
+ my $this=shift;
+ my %args=@_;
+ if (!defined $this->get_builddir()) {
+ $this->_set_builddir($args{builddir});
+ if (!defined $this->get_builddir() && !$args{builddir}) {
+ # If we are here, DEFAULT_BUILD_DIRECTORY matches
+ # the source directory, building might fail.
+ error("default build directory is the same as the source directory." .
+ " Please specify a custom build directory");
+ }
+ }
+}
+
+# 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 = "/tmp" 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 if the same
+# as the source directory.
+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 = $this->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;
+ my $only_empty=shift;
+ if ($this->get_builddir()) {
+ my $buildpath = $this->get_buildpath();
+ if (-d $buildpath && ! $dh{NO_ACT}) {
+ my @spdir = File::Spec->splitdir($this->get_build_rel2sourcedir());
+ my $peek;
+ if (!$only_empty) {
+ doit("rm", "-rf", $buildpath);
+ pop @spdir;
+ }
+ # If build directory had 2 or more levels, delete empty
+ # parent directories until the source directory level.
+ while (($peek=pop(@spdir)) && $peek ne '.' && $peek ne '..') {
+ last if ! rmdir($this->get_sourcepath(File::Spec->catdir(@spdir, $peek)));
+ }
+ }
+ 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 build system 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..60fa9e85
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/autoconf.pm
@@ -0,0 +1,55 @@
+# A debhelper build system class 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..56628740
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/cmake.pm
@@ -0,0 +1,45 @@
+# A debhelper build system class for handling CMake based projects.
+# It prefers 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(@_);
+ # Prefer 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_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..d84d3349
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/makefile.pm
@@ -0,0 +1,95 @@
+# A debhelper build system class 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..3567cb1a
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/perl_build.pm
@@ -0,0 +1,67 @@
+# A build system class 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..07a827ac
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/perl_makemaker.pm
@@ -0,0 +1,64 @@
+# A debhelper build system class 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..39a4466a
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/python_distutils.pm
@@ -0,0 +1,114 @@
+# A debhelper build system class for building Python Distutils based
+# projects. It prefers out of source tree building.
+#
+# Copyright: © 2008 Joey Hess
+# © 2008-2009 Modestas Vainius
+# License: GPL-2+
+
+package Debian::Debhelper::Buildsystem::python_distutils;
+
+use strict;
+use Cwd ();
+use Debian::Debhelper::Dh_Lib qw(error);
+use base 'Debian::Debhelper::Buildsystem';
+
+sub DESCRIPTION {
+ "Python Distutils (setup.py)"
+}
+
+sub DEFAULT_BUILD_DIRECTORY {
+ my $this=shift;
+ return $this->_canonpath($this->get_sourcepath("build"));
+}
+
+sub new {
+ my $class=shift;
+ my $this=$class->SUPER::new(@_);
+ # Out of source tree building is prefered.
+ $this->enforce_out_of_source_building(@_);
+ return $this;
+}
+
+sub check_auto_buildable {
+ my $this=shift;
+ return -e $this->get_sourcepath("setup.py");
+}
+
+sub not_our_cfg {
+ my $this=shift;
+ my $ret;
+ if (open(my $cfg, $this->get_buildpath(".pydistutils.cfg"))) {
+ $ret = not "# Created by dh_auto\n" eq <$cfg>;
+ close $cfg;
+ }
+ return $ret;
+}
+
+sub create_cfg {
+ my $this=shift;
+ if (open(my $cfg, ">", $this->get_buildpath(".pydistutils.cfg"))) {
+ print $cfg "# Created by dh_auto", "\n";
+ print $cfg "[build]\nbuild-base=", $this->get_build_rel2sourcedir(), "\n";
+ close $cfg;
+ return 1;
+ }
+ return 0;
+}
+
+sub pre_building_step {
+ my $this=shift;
+ my $step=shift;
+
+ return unless grep /$step/, qw(build install clean);
+
+ # --build-base can only be passed to the build command. However,
+ # it is always read from the config file (really weird design).
+ # Therefore create such a cfg config file.
+ if ($this->get_buildpath() ne $this->DEFAULT_BUILD_DIRECTORY()) {
+ not $this->not_our_cfg() or
+ error("cannot set custom build directory: .pydistutils.cfg is in use");
+ $this->mkdir_builddir();
+ $this->create_cfg() or
+ error("cannot set custom build directory: unwritable .pydistutils.cfg");
+ # Distutils reads $HOME/.pydistutils.cfg
+ $ENV{HOME} = Cwd::abs_path($this->get_buildpath());
+ }
+}
+
+sub setup_py {
+ my $this=shift;
+ my $act=shift;
+ $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",
+ "--install-layout=deb",
+ @_);
+}
+
+sub clean {
+ my $this=shift;
+ $this->setup_py("clean", "-a", @_);
+
+ # Config file will remain if it was created by us
+ if (!$this->not_our_cfg()) {
+ unlink($this->get_buildpath(".pydistutils.cfg"));
+ $this->rmdir_builddir(1); # only if empty
+ }
+ # 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..d37c593d
--- /dev/null
+++ b/Debian/Debhelper/Dh_Buildsystems.pm
@@ -0,0 +1,180 @@
+# A module for loading and managing debhelper build system classes.
+# This module is intended to be used by all dh_auto_* programs.
+#
+# 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
+# build systems 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 build system 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_build system_instance(), but it attempts to autoselect
+# a build system 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 standard debhelper build systems first
+ for my $name (@BUILDSYSTEMS) {
+ error("standard debhelper build system '$name' could not be found/loaded")
+ if not exists $buildsystems{$name};
+ push @buildsystems, $buildsystems{$name};
+ delete $buildsystems{$name};
+ }
+
+ # The rest are 3rd party build systems
+ 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=s" => \$opt_sourcedir,
+ "sourcedirectory=s" => \$opt_sourcedir,
+
+ "B:s" => \$opt_builddir,
+ "builddirectory:s" => \$opt_builddir,
+
+ "S=s" => \$opt_buildsys,
+ "buildsystem=s" => \$opt_buildsys,
+
+ "l" => \$opt_list,
+ "list" => \$opt_list,
+ );
+ $args{options}{$_} = $options{$_} foreach keys(%options);
+ Debian::Debhelper::Dh_Lib::init(%args);
+}
+
+sub buildsystems_list {
+ my $step=shift;
+
+ # List build systems (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..9ca9d167 100644
--- a/Debian/Debhelper/Dh_Getopt.pm
+++ b/Debian/Debhelper/Dh_Getopt.pm
@@ -143,6 +143,12 @@ sub getoptions {
)
}
+sub split_options_string {
+ my $str=shift;
+ $str=~s/^\s+//;
+ return split(/\s+/,$str);
+}
+
# Parse options and set %dh values.
sub parseopts {
my $options=shift;
@@ -152,10 +158,7 @@ sub parseopts {
# 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,9 +187,7 @@ 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");
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index f09c8087..28a90f7b 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