summaryrefslogtreecommitdiff
path: root/Debian
diff options
context:
space:
mode:
authorJoey Hess <joeyh@debian.org>2013-11-10 15:23:29 -0400
committerJoey Hess <joeyh@debian.org>2013-11-10 15:23:29 -0400
commit868ba759bb6eec429139205e01f59f494cdaf98b (patch)
tree36d25c13f7c002867e6b5cb0acd70398d79c00e3 /Debian
debhelper (9.20131110) unstable; urgency=low
* dh_installinit: Revert changes that added versioned dependency on sysv-rc to support upstart, which later grew to a versioned dependency on sysv-rc | file-rc, and which seems to want to continue growing to list other init systems, which there currently seem to be far too many of, for far too little benefit. The sysv-rc dependency is already met in stable. The file-rc dependency is not, so if someone cares about that, they need to find a properly designed solution, which this was not. Closes: #729248 # imported from the archive
Diffstat (limited to 'Debian')
-rw-r--r--Debian/Debhelper/Buildsystem.pm415
-rw-r--r--Debian/Debhelper/Buildsystem/ant.pm37
-rw-r--r--Debian/Debhelper/Buildsystem/autoconf.pm75
-rw-r--r--Debian/Debhelper/Buildsystem/cmake.pm77
-rw-r--r--Debian/Debhelper/Buildsystem/makefile.pm152
-rw-r--r--Debian/Debhelper/Buildsystem/perl_build.pm77
-rw-r--r--Debian/Debhelper/Buildsystem/perl_makemaker.pm80
-rw-r--r--Debian/Debhelper/Buildsystem/python_distutils.pm210
-rw-r--r--Debian/Debhelper/Buildsystem/qmake.pm83
-rw-r--r--Debian/Debhelper/Buildsystem/qmake_qt4.pm18
-rw-r--r--Debian/Debhelper/Dh_Buildsystems.pm228
-rw-r--r--Debian/Debhelper/Dh_Getopt.pm288
-rw-r--r--Debian/Debhelper/Dh_Lib.pm983
-rw-r--r--Debian/Debhelper/Sequence/python_support.pm15
14 files changed, 2738 insertions, 0 deletions
diff --git a/Debian/Debhelper/Buildsystem.pm b/Debian/Debhelper/Buildsystem.pm
new file mode 100644
index 00000000..8fde2159
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem.pm
@@ -0,0 +1,415 @@
+# 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;
+
+# 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-" . dpkg_architecture_value("DEB_HOST_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.
+# - parallel - max number of parallel processes to be spawned for building
+# sources (-1 = unlimited; 1 = no parallel)
+# 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,
+ parallel => undef,
+ cwd => Cwd::getcwd() }, $class);
+
+ if (exists $opts{sourcedir}) {
+ # Get relative sourcedir abs_path (without symlinks)
+ my $abspath = Cwd::abs_path($opts{sourcedir});
+ if (! -d $abspath || $abspath !~ /^\Q$this->{cwd}\E/) {
+ error("invalid or non-existing path to the source directory: ".$opts{sourcedir});
+ }
+ $this->{sourcedir} = File::Spec->abs2rel($abspath, $this->{cwd});
+ }
+ if (exists $opts{builddir}) {
+ $this->_set_builddir($opts{builddir});
+ }
+ if (defined $opts{parallel}) {
+ $this->{parallel} = $opts{parallel};
+ }
+ 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->DEFAULT_BUILD_DIRECTORY;
+
+ if (defined $builddir) {
+ $builddir = $this->canonpath($builddir); # Canonicalize
+
+ # Sanitize $builddir
+ if ($builddir =~ m#^\.\./#) {
+ # We can't handle those as relative. Make them absolute
+ $builddir = File::Spec->catdir($this->{cwd}, $builddir);
+ }
+ elsif ($builddir =~ /\Q$this->{cwd}\E/) {
+ $builddir = File::Spec->abs2rel($builddir, $this->{cwd});
+ }
+
+ # If build directory ends up the same as source directory, drop it
+ if ($builddir eq $this->get_sourcedir()) {
+ $builddir = undef;
+ }
+ }
+ $this->{builddir} = $builddir;
+ return $builddir;
+}
+
+# This instance method is called to check if the build system is able
+# to build a source package. It will be called during the build
+# system auto-selection process, inside the root directory of the debian
+# source package. The current build step is passed as an argument.
+# Return 0 if the source is not buildable, or a positive integer
+# otherwise.
+#
+# Generally, it is enough to look for invariant unique build system
+# files shipped with clean source to determine if the source might
+# be buildable or not. However, if the build system is derived from
+# another other auto-buildable build system, this method
+# may also check if the source has already been built with this build
+# system partitially by looking for temporary files or other common
+# results the build system produces during the build process. The
+# latter checks must be unique to the current build system and must
+# be very unlikely to be true for either its parent or other build
+# systems. If it is determined that the source has already built
+# partitially with this build system, the value returned must be
+# greater than the one of the SUPER call.
+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 *prefer*
+# out of source building. Unless build directory has already been
+# specified building will proceed in the DEFAULT_BUILD_DIRECTORY or
+# the one specified in the 'builddir' named parameter (which may
+# match the source directory). Typically you should pass @_ from
+# the constructor to this call.
+sub prefer_out_of_source_building {
+ my $this=shift;
+ my %args=@_;
+ if (!defined $this->get_builddir()) {
+ if (!$this->_set_builddir($args{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;
+ foreach 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 $root, converts and
+# returns path of $path being relative to the $base. If either $path or
+# $base is absolute, returns another $path (converted to) absolute.
+sub _rel2rel {
+ my ($this, $path, $base, $root)=@_;
+ $root = $this->{cwd} unless defined $root;
+
+ if (File::Spec->file_name_is_absolute($path)) {
+ return $path;
+ }
+ elsif (File::Spec->file_name_is_absolute($base)) {
+ return File::Spec->rel2abs($path, $root);
+ }
+ else {
+ 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;
+}
+
+sub get_parallel {
+ my $this=shift;
+ return $this->{parallel};
+}
+
+# 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)=@_;
+ verbose_print("cd $dir");
+ if (! $dh{NO_ACT}) {
+ 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();
+ $this->_cd($sourcedir);
+ doit(@_);
+ $this->_cd($this->_rel2rel($this->{cwd}, $sourcedir));
+ }
+ 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();
+ $this->_cd($buildpath);
+ doit(@_);
+ $this->_cd($this->_rel2rel($this->{cwd}, $buildpath));
+ }
+ 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) {
+ my @dir = File::Spec->splitdir($this->get_build_rel2sourcedir());
+ my $peek;
+ if (not $only_empty) {
+ doit("rm", "-rf", $buildpath);
+ pop @dir;
+ }
+ # If build directory is relative and had 2 or more levels, delete
+ # empty parent directories until the source or top directory level.
+ if (not File::Spec->file_name_is_absolute($buildpath)) {
+ while (($peek=pop @dir) && $peek ne '.' && $peek ne '..') {
+ my $dir = $this->get_sourcepath(File::Spec->catdir(@dir, $peek));
+ doit("rmdir", "--ignore-fail-on-non-empty", $dir);
+ last if -d $dir;
+ }
+ }
+ }
+ 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/ant.pm b/Debian/Debhelper/Buildsystem/ant.pm
new file mode 100644
index 00000000..52def4f6
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/ant.pm
@@ -0,0 +1,37 @@
+# A debhelper build system class for handling Ant based projects.
+#
+# Copyright: © 2009 Joey Hess
+# License: GPL-2+
+
+package Debian::Debhelper::Buildsystem::ant;
+
+use strict;
+use base 'Debian::Debhelper::Buildsystem';
+
+sub DESCRIPTION {
+ "Ant (build.xml)"
+}
+
+sub check_auto_buildable {
+ my $this=shift;
+ return (-e $this->get_sourcepath("build.xml")) ? 1 : 0;
+}
+
+sub new {
+ my $class=shift;
+ my $this=$class->SUPER::new(@_);
+ $this->enforce_in_source_building();
+ return $this;
+}
+
+sub build {
+ my $this=shift;
+ $this->doit_in_sourcedir("ant", @_);
+}
+
+sub clean {
+ my $this=shift;
+ $this->doit_in_sourcedir("ant", "clean", @_);
+}
+
+1
diff --git a/Debian/Debhelper/Buildsystem/autoconf.pm b/Debian/Debhelper/Buildsystem/autoconf.pm
new file mode 100644
index 00000000..20b9fd44
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/autoconf.pm
@@ -0,0 +1,75 @@
+# 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 compat);
+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 (compat with 7.0.x code path)
+ if ($step eq "configure") {
+ return 1 if -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";
+ my $multiarch=dpkg_architecture_value("DEB_HOST_MULTIARCH");
+ if (! compat(8)) {
+ if (defined $multiarch) {
+ push @opts, "--libdir=\${prefix}/lib/$multiarch";
+ push @opts, "--libexecdir=\${prefix}/lib/$multiarch";
+ }
+ else {
+ push @opts, "--libexecdir=\${prefix}/lib";
+ }
+ }
+ else {
+ 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();
+ eval {
+ $this->doit_in_builddir($this->get_source_rel2builddir("configure"), @opts, @_);
+ };
+ if ($@) {
+ if (-e $this->get_buildpath("config.log")) {
+ $this->doit_in_builddir("tail -v -n +0 config.log");
+ }
+ die $@;
+ }
+}
+
+1
diff --git a/Debian/Debhelper/Buildsystem/cmake.pm b/Debian/Debhelper/Buildsystem/cmake.pm
new file mode 100644
index 00000000..d47821ca
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/cmake.pm
@@ -0,0 +1,77 @@
+# 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 Debian::Debhelper::Dh_Lib qw(compat);
+use base 'Debian::Debhelper::Buildsystem::makefile';
+
+sub DESCRIPTION {
+ "CMake (CMakeLists.txt)"
+}
+
+sub check_auto_buildable {
+ my $this=shift;
+ my ($step)=@_;
+ if (-e $this->get_sourcepath("CMakeLists.txt")) {
+ my $ret = ($step eq "configure" && 1) ||
+ $this->SUPER::check_auto_buildable(@_);
+ # Existence of CMakeCache.txt indicates cmake has already
+ # been used by a prior build step, so should be used
+ # instead of the parent makefile class.
+ $ret++ if ($ret && -e $this->get_buildpath("CMakeCache.txt"));
+ return $ret;
+ }
+ return 0;
+}
+
+sub new {
+ my $class=shift;
+ my $this=$class->SUPER::new(@_);
+ $this->prefer_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_VERBOSE_MAKEFILE=ON";
+ push @flags, "-DCMAKE_BUILD_TYPE=RelWithDebInfo";
+
+ # CMake doesn't respect CPPFLAGS, see #653916.
+ if ($ENV{CPPFLAGS} && ! compat(8)) {
+ $ENV{CFLAGS} .= ' ' . $ENV{CPPFLAGS};
+ $ENV{CXXFLAGS} .= ' ' . $ENV{CPPFLAGS};
+ }
+
+ $this->mkdir_builddir();
+ eval {
+ $this->doit_in_builddir("cmake", $this->get_source_rel2builddir(), @flags, @_);
+ };
+ if ($@) {
+ if (-e $this->get_buildpath("CMakeCache.txt")) {
+ $this->doit_in_builddir("tail -v -n +0 CMakeCache.txt");
+ }
+ die $@;
+ }
+}
+
+sub test {
+ my $this=shift;
+
+ # Unlike make, CTest does not have "unlimited parallel" setting (-j implies
+ # -j1). So in order to simulate unlimited parallel, allow to fork a huge
+ # number of threads instead.
+ my $parallel = ($this->get_parallel() > 0) ? $this->get_parallel() : 999;
+ $ENV{CTEST_OUTPUT_ON_FAILURE} = 1;
+ return $this->SUPER::test(@_, "ARGS+=-j$parallel");
+}
+
+1
diff --git a/Debian/Debhelper/Buildsystem/makefile.pm b/Debian/Debhelper/Buildsystem/makefile.pm
new file mode 100644
index 00000000..2c68a836
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/makefile.pm
@@ -0,0 +1,152 @@
+# 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 clean_jobserver_makeflags);
+use base 'Debian::Debhelper::Buildsystem';
+
+# make makes things difficult by not providing a simple way to test
+# whether a Makefile target exists. Using -n and checking for a nonzero
+# exit status is not good enough, because even with -n, make will
+# run commands needed to eg, generate include files -- and those commands
+# could fail even though the target exists -- and we should let the target
+# run and propagate any failure.
+#
+# Using -n and checking for at least one line of output is better.
+# That will indicate make either wants to run one command, or
+# has output a "nothing to be done" message if the target exists but is a
+# noop.
+#
+# However, that heuristic is also not good enough, because a Makefile
+# could run code that outputs something, even though the -n is asking
+# it not to run anything. (Again, done for includes.) To detect this false
+# positive, there is unfortunately only one approach left: To
+# look for the error message printed by make when a target does not exist.
+#
+# This could break if make's output changes. It would only break a minority
+# of packages where this latter test is needed. The best way to avoid that
+# problem would be to fix make to have this simple and highly useful
+# missing feature.
+#
+# A final option would be to use -p and parse the output data base.
+# It's more practical for dh to use that method, since it operates on
+# only special debian/rules files, and not arbitrary Makefiles which
+# can be arbitrarily complicated, use implicit targets, and so on.
+sub exists_make_target {
+ my $this=shift;
+ my $target=shift;
+
+ my @opts=("-s", "-n", "--no-print-directory");
+ my $buildpath = $this->get_buildpath();
+ unshift @opts, "-C", $buildpath if $buildpath ne ".";
+
+ my $pid = open(MAKE, "-|");
+ defined($pid) || die "can't fork: $!";
+ if (! $pid) {
+ open(STDERR, ">&STDOUT");
+ $ENV{LC_ALL}='C';
+ exec($this->{makecmd}, @opts, $target, @_);
+ exit(1);
+ }
+
+ local $/=undef;
+ my $output=<MAKE>;
+ chomp $output;
+ close MAKE;
+
+ return defined $output
+ && length $output
+ && $output !~ /\*\*\* No rule to make target (`|')\Q$target\E'/;
+}
+
+sub do_make {
+ my $this=shift;
+
+ # Avoid possible warnings about unavailable jobserver,
+ # and force make to start a new jobserver.
+ clean_jobserver_makeflags();
+
+ # Note that this will override any -j settings in MAKEFLAGS.
+ unshift @_, "-j" . ($this->get_parallel() > 0 ? $this->get_parallel() : "");
+
+ $this->doit_in_builddir($this->{makecmd}, @_);
+}
+
+sub make_first_existing_target {
+ my $this=shift;
+ my $targets=shift;
+
+ foreach my $target (@$targets) {
+ if ($this->exists_make_target($target, @_)) {
+ $this->do_make($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) = @_;
+
+ if (-e $this->get_buildpath("Makefile") ||
+ -e $this->get_buildpath("makefile") ||
+ -e $this->get_buildpath("GNUmakefile"))
+ {
+ # This is always called in the source directory, but generally
+ # Makefiles are created (or live) in the build directory.
+ return 1;
+ } elsif ($step eq "clean" && defined $this->get_builddir() &&
+ $this->check_auto_buildable("configure"))
+ {
+ # Assume that the package can be cleaned (i.e. the build directory can
+ # be removed) as long as it is built out-of-source tree and can be
+ # configured. This is useful for derivative buildsystems which
+ # generate Makefiles.
+ return 1;
+ }
+ return 0;
+}
+
+sub build {
+ my $this=shift;
+ $this->do_make(@_);
+}
+
+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",
+ "AM_UPDATE_INFO_DIR=no", @_);
+}
+
+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..bfe1c08e
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/perl_build.pm
@@ -0,0 +1,77 @@
+# 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 Debian::Debhelper::Dh_Lib qw(compat);
+use base 'Debian::Debhelper::Buildsystem';
+use Config;
+
+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 ? 1 : 0;
+}
+
+sub do_perl {
+ my $this=shift;
+ $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;
+ my @flags;
+ $ENV{PERL_MM_USE_DEFAULT}=1;
+ if ($ENV{CFLAGS} && ! compat(8)) {
+ push @flags, "--config", "optimize=$ENV{CFLAGS} $ENV{CPPFLAGS}";
+ }
+ if ($ENV{LDFLAGS} && ! compat(8)) {
+ push @flags, "--config", "ld=$Config{ld} $ENV{CFLAGS} $ENV{LDFLAGS}";
+ }
+ $this->do_perl("Build.PL", "--installdirs", "vendor", @flags, @_);
+}
+
+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;
+ if (-e $this->get_sourcepath("Build")) {
+ $this->do_perl("Build", "distclean", "--allow_mb_mismatch", 1, @_);
+ }
+}
+
+1
diff --git a/Debian/Debhelper/Buildsystem/perl_makemaker.pm b/Debian/Debhelper/Buildsystem/perl_makemaker.pm
new file mode 100644
index 00000000..60cda3d0
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/perl_makemaker.pm
@@ -0,0 +1,80 @@
+# 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 Debian::Debhelper::Dh_Lib qw(compat);
+use base 'Debian::Debhelper::Buildsystem::makefile';
+use Config;
+
+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 "configure") {
+ return 1;
+ }
+ else {
+ 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;
+ my @flags;
+ # 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";
+
+ if ($ENV{CFLAGS} && ! compat(8)) {
+ push @flags, "OPTIMIZE=$ENV{CFLAGS} $ENV{CPPFLAGS}";
+ }
+ if ($ENV{LDFLAGS} && ! compat(8)) {
+ push @flags, "LD=$Config{ld} $ENV{CFLAGS} $ENV{LDFLAGS}";
+ }
+
+ $this->doit_in_sourcedir("perl", "Makefile.PL", "INSTALLDIRS=vendor",
+ # if perl_build is not tested first, need to pass packlist
+ # option to handle fallthrough case
+ (compat(7) ? "create_packlist=0" : ()),
+ @flags, @_);
+}
+
+sub install {
+ my $this=shift;
+ my $destdir=shift;
+
+ # Special case for Makefile.PL that uses
+ # Module::Build::Compat. PREFIX should not be passed
+ # for those; it already installs into /usr by default.
+ my $makefile=$this->get_sourcepath("Makefile");
+ if (system(qq{grep -q "generated automatically by MakeMaker" $makefile}) != 0) {
+ $this->SUPER::install($destdir, @_);
+ }
+ else {
+ $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..c3d58cc0
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/python_distutils.pm
@@ -0,0 +1,210 @@
+# 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 preferred.
+ $this->prefer_out_of_source_building(@_);
+ return $this;
+}
+
+sub check_auto_buildable {
+ my $this=shift;
+ return -e $this->get_sourcepath("setup.py") ? 1 : 0;
+}
+
+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);
+
+ if ($this->get_buildpath() ne $this->DEFAULT_BUILD_DIRECTORY()) {
+ # --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.
+ # See http://bugs.python.org/issue818201
+ # http://bugs.python.org/issue1011113
+ 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());
+ }
+
+ $this->SUPER::pre_building_step($step);
+}
+
+sub dbg_build_needed {
+ my $this=shift;
+ my $act=shift;
+
+ # Return a list of python-dbg package which are listed
+ # in the build-dependencies. This is kinda ugly, but building
+ # dbg extensions without checking if they're supposed to be
+ # built may result in various FTBFS if the package is not
+ # built in a clean chroot.
+
+ my @dbg;
+ open (CONTROL, 'debian/control') ||
+ error("cannot read debian/control: $!\n");
+ foreach my $builddeps (join('', <CONTROL>) =~
+ /^Build-Depends[^:]*:.*\n(?:^[^\w\n].*\n)*/gmi) {
+ while ($builddeps =~ /(python[^, ]*-dbg)/g) {
+ push @dbg, $1;
+ }
+ }
+
+ close CONTROL;
+ return @dbg;
+
+}
+
+sub setup_py {
+ my $this=shift;
+ my $act=shift;
+
+ # We need to to run setup.py with the default python last
+ # as distutils/setuptools modifies the shebang lines of scripts.
+ # This ensures that #!/usr/bin/python is installed last and
+ # not pythonX.Y
+ # Take into account that the default Python must not be in
+ # the requested Python versions.
+ # Then, run setup.py with each available python, to build
+ # extensions for each.
+
+ my $python_default = `pyversions -d`;
+ if ($? == -1) {
+ error("failed to run pyversions")
+ }
+ my $ecode = $? >> 8;
+ if ($ecode != 0) {
+ error("pyversions -d failed [$ecode]")
+ }
+ $python_default =~ s/^\s+//;
+ $python_default =~ s/\s+$//;
+ my @python_requested = split ' ', `pyversions -r`;
+ if ($? == -1) {
+ error("failed to run pyversions")
+ }
+ $ecode = $? >> 8;
+ if ($ecode != 0) {
+ error("pyversions -r failed [$ecode]")
+ }
+ if (grep /^\Q$python_default\E/, @python_requested) {
+ @python_requested = (
+ grep(!/^\Q$python_default\E/, @python_requested),
+ "python",
+ );
+ }
+
+ my @python_dbg;
+ my @dbg_build_needed = $this->dbg_build_needed();
+ foreach my $python (map { $_."-dbg" } @python_requested) {
+ if (grep /^(python-all-dbg|\Q$python\E)/, @dbg_build_needed) {
+ push @python_dbg, $python;
+ }
+ elsif (($python eq "python-dbg")
+ and (grep /^\Q$python_default\E/, @dbg_build_needed)) {
+ push @python_dbg, $python_default."-dbg";
+ }
+ }
+
+ foreach my $python (@python_dbg, @python_requested) {
+ if (-x "/usr/bin/".$python) {
+ # To allow backports of debhelper we don't pass
+ # --install-layout=deb to 'setup.py install` for
+ # those Python versions where the option is
+ # ignored by distutils/setuptools.
+ if ( $act eq "install" and not
+ ( ($python =~ /^python(?:-dbg)?$/
+ and $python_default =~ /^python2\.[2345]$/)
+ or $python =~ /^python2\.[2345](?:-dbg)?$/ )) {
+ $this->doit_in_sourcedir($python, "setup.py",
+ $act, @_, "--install-layout=deb");
+ }
+ else {
+ $this->doit_in_sourcedir($python, "setup.py",
+ $act, @_);
+ }
+ }
+ }
+}
+
+sub build {
+ my $this=shift;
+ $this->setup_py("build",
+ "--force",
+ @_);
+}
+
+sub install {
+ my $this=shift;
+ my $destdir=shift;
+ $this->setup_py("install",
+ "--force",
+ "--root=$destdir",
+ "--no-compile",
+ "-O0",
+ @_);
+}
+
+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/Buildsystem/qmake.pm b/Debian/Debhelper/Buildsystem/qmake.pm
new file mode 100644
index 00000000..91e817f8
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/qmake.pm
@@ -0,0 +1,83 @@
+# A debhelper build system class for Qt projects
+# (based on the makefile class).
+#
+# Copyright: © 2010 Kelvin Modderman
+# License: GPL-2+
+
+package Debian::Debhelper::Buildsystem::qmake;
+
+use strict;
+use warnings;
+use Debian::Debhelper::Dh_Lib qw(error);
+use base 'Debian::Debhelper::Buildsystem::makefile';
+
+our $qmake="qmake";
+
+sub DESCRIPTION {
+ "qmake (*.pro)";
+}
+
+sub check_auto_buildable {
+ my $this=shift;
+ my @projects=glob($this->get_sourcepath('*.pro'));
+ my $ret=0;
+
+ if (@projects > 0) {
+ $ret=1;
+ # Existence of a Makefile generated by qmake indicates qmake
+ # class has already been used by a prior build step, so should
+ # be used instead of the parent makefile class.
+ my $mf=$this->get_buildpath("Makefile");
+ if (-e $mf) {
+ $ret = $this->SUPER::check_auto_buildable(@_);
+ open(my $fh, '<', $mf)
+ or error("unable to open Makefile: $mf");
+ while(<$fh>) {
+ if (m/^# Generated by qmake/i) {
+ $ret++;
+ last;
+ }
+ }
+ close($fh);
+ }
+ }
+
+ return $ret;
+}
+
+sub configure {
+ my $this=shift;
+ my @options;
+ my @flags;
+
+ push @options, '-makefile';
+ push @options, '-nocache';
+
+ if ($ENV{CFLAGS}) {
+ push @flags, "QMAKE_CFLAGS_RELEASE=$ENV{CFLAGS} $ENV{CPPFLAGS}";
+ push @flags, "QMAKE_CFLAGS_DEBUG=$ENV{CFLAGS} $ENV{CPPFLAGS}";
+ }
+ if ($ENV{CXXFLAGS}) {
+ push @flags, "QMAKE_CXXFLAGS_RELEASE=$ENV{CXXFLAGS} $ENV{CPPFLAGS}";
+ push @flags, "QMAKE_CXXFLAGS_DEBUG=$ENV{CXXFLAGS} $ENV{CPPFLAGS}";
+ }
+ if ($ENV{LDFLAGS}) {
+ push @flags, "QMAKE_LFLAGS_RELEASE=$ENV{LDFLAGS}";
+ push @flags, "QMAKE_LFLAGS_DEBUG=$ENV{LDFLAGS}";
+ }
+ push @flags, "QMAKE_STRIP=:";
+ push @flags, "PREFIX=/usr";
+
+ $this->doit_in_builddir($qmake, @options, @flags, @_);
+}
+
+sub install {
+ my $this=shift;
+ my $destdir=shift;
+
+ # qmake generated Makefiles use INSTALL_ROOT in install target
+ # where one would expect DESTDIR to be used.
+ $this->SUPER::install($destdir, "INSTALL_ROOT=$destdir", @_);
+}
+
+1
diff --git a/Debian/Debhelper/Buildsystem/qmake_qt4.pm b/Debian/Debhelper/Buildsystem/qmake_qt4.pm
new file mode 100644
index 00000000..d5bac585
--- /dev/null
+++ b/Debian/Debhelper/Buildsystem/qmake_qt4.pm
@@ -0,0 +1,18 @@
+package Debian::Debhelper::Buildsystem::qmake_qt4;
+
+use strict;
+use warnings;
+use Debian::Debhelper::Dh_Lib qw(error);
+use base 'Debian::Debhelper::Buildsystem::qmake';
+
+sub DESCRIPTION {
+ "qmake for QT 4 (*.pro)";
+}
+
+sub configure {
+ my $this=shift;
+ $Debian::Debhelper::Buildsystem::qmake::qmake="qmake-qt4";
+ $this->SUPER::configure(@_);
+}
+
+1
diff --git a/Debian/Debhelper/Dh_Buildsystems.pm b/Debian/Debhelper/Dh_Buildsystems.pm
new file mode 100644
index 00000000..0a51a4d2
--- /dev/null
+++ b/Debian/Debhelper/Dh_Buildsystems.pm
@@ -0,0 +1,228 @@
+# 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);
+
+use constant BUILD_STEPS => qw(configure build test install clean);
+
+# Historical order must be kept for backwards compatibility. New
+# build systems MUST be added to the END of the list.
+our @BUILDSYSTEMS = (
+ "autoconf",
+ (! compat(7) ? "perl_build" : ()),
+ "perl_makemaker",
+ "makefile",
+ "python_distutils",
+ (compat(7) ? "perl_build" : ()),
+ "cmake",
+ "ant",
+ "qmake",
+ "qmake_qt4",
+);
+
+my $opt_buildsys;
+my $opt_sourcedir;
+my $opt_builddir;
+my $opt_list;
+my $opt_parallel;
+
+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;
+ }
+ if (!exists $bsopts{parallel}) {
+ $bsopts{parallel} = $opt_parallel;
+ }
+ return $module->new(%bsopts);
+}
+
+# Autoselect a build system from the list of instances
+sub autoselect_buildsystem {
+ my $step=shift;
+ my $selected;
+ my $selected_level = 0;
+
+ foreach my $inst (@_) {
+ # Only derived (i.e. more specific) build system can be
+ # considered beyond the currently selected one.
+ next if defined $selected && !$inst->isa(ref $selected);
+
+ # If the build system says it is auto-buildable at the current
+ # step and it can provide more specific information about its
+ # status than its parent (if any), auto-select it.
+ my $level = $inst->check_auto_buildable($step);
+ if ($level > $selected_level) {
+ $selected = $inst;
+ $selected_level = $level;
+ }
+ }
+ return $selected;
+}
+
+# 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
+ my @buildsystems;
+ foreach $system (@BUILDSYSTEMS) {
+ push @buildsystems, create_buildsystem_instance($system, @_);
+ }
+ return autoselect_buildsystem($step, @buildsystems);
+ }
+}
+
+sub load_all_buildsystems {
+ my $incs=shift || \@INC;
+ my (%buildsystems, @buildsystems);
+
+ foreach my $inc (@$incs) {
+ my $path = File::Spec->catdir($inc, "Debian/Debhelper/Buildsystem");
+ if (-d $path) {
+ foreach 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, @_);
+ }
+ }
+ }
+
+ # Standard debhelper build systems first
+ foreach 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
+ foreach my $name (keys %buildsystems) {
+ my $inst = $buildsystems{$name};
+ $inst->{thirdparty} = 1;
+ push @buildsystems, $inst;
+ }
+
+ return @buildsystems;
+}
+
+sub buildsystems_init {
+ my %args=@_;
+
+ my $max_parallel=1;
+
+ # 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,
+
+ "parallel" => sub { $max_parallel = -1 },
+ "max-parallel=i" => \$max_parallel,
+ );
+ $args{options}{$_} = $options{$_} foreach keys(%options);
+ Debian::Debhelper::Dh_Lib::init(%args);
+ Debian::Debhelper::Dh_Lib::set_buildflags();
+ set_parallel($max_parallel);
+}
+
+sub set_parallel {
+ my $max=shift;
+
+ # Get number of processes from parallel=n option, limiting it
+ # with $max if needed
+ $opt_parallel=get_buildoption("parallel") || 1;
+
+ if ($max > 0 && $opt_parallel > $max) {
+ $opt_parallel = $max;
+ }
+}
+
+sub buildsystems_list {
+ my $step=shift;
+
+ my @buildsystems = load_all_buildsystems();
+ my $auto = autoselect_buildsystem($step, grep { ! $_->{thirdparty} } @buildsystems);
+ my $specified;
+
+ # List build systems (including auto and specified status)
+ foreach my $inst (@buildsystems) {
+ if (! defined $specified && defined $opt_buildsys && $opt_buildsys eq $inst->NAME()) {
+ $specified = $inst;
+ }
+ printf("%-20s %s", $inst->NAME(), $inst->DESCRIPTION());
+ print " [3rd party]" if $inst->{thirdparty};
+ print "\n";
+ }
+ print "\n";
+ print "Auto-selected: ", $auto->NAME(), "\n" if defined $auto;
+ print "Specified: ", $specified->NAME(), "\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$/, BUILD_STEPS) == 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
new file mode 100644
index 00000000..e4f3e471
--- /dev/null
+++ b/Debian/Debhelper/Dh_Getopt.pm
@@ -0,0 +1,288 @@
+#!/usr/bin/perl -w
+#
+# Debhelper option processing library.
+#
+# Joey Hess GPL copyright 1998-2002
+
+package Debian::Debhelper::Dh_Getopt;
+use strict;
+
+use Debian::Debhelper::Dh_Lib;
+use Getopt::Long;
+
+my %exclude_package;
+
+sub showhelp {
+ my $prog=basename($0);
+ print "Usage: $prog [options]\n\n";
+ print " $prog is a part of debhelper. See debhelper(7)\n";
+ print " and $prog(1) for complete usage instructions.\n";
+ exit(1);
+}
+
+# Passed an option name and an option value, adds packages to the list
+# of packages. We need this so the list will be built up in the right
+# order.
+sub AddPackage { my($option,$value)=@_;
+ if ($option eq 'i' or $option eq 'indep') {
+ push @{$dh{DOPACKAGES}}, getpackages('indep');
+ $dh{DOINDEP}=1;
+ }
+ elsif ($option eq 'a' or $option eq 'arch' or
+ $option eq 's' or $option eq 'same-arch') {
+ push @{$dh{DOPACKAGES}}, getpackages('arch');
+ $dh{DOARCH}=1;
+ }
+ elsif ($option eq 'p' or $option eq 'package') {
+ push @{$dh{DOPACKAGES}}, $value;
+ }
+ else {
+ error("bad option $option - should never happen!\n");
+ }
+}
+
+# Adds packages to the list of debug packages.
+sub AddDebugPackage { my($option,$value)=@_;
+ push @{$dh{DEBUGPACKAGES}}, $value;
+}
+
+# Add a package to a list of packages that should not be acted on.
+sub ExcludePackage { my($option,$value)=@_;
+ $exclude_package{$value}=1;
+}
+
+# Add another item to the exclude list.
+sub AddExclude { my($option,$value)=@_;
+ push @{$dh{EXCLUDE}},$value;
+}
+
+# Add a file to the ignore list.
+sub AddIgnore { my($option,$file)=@_;
+ $dh{IGNORE}->{$file}=1;
+}
+
+# This collects non-options values.
+sub NonOption {
+ push @{$dh{ARGV}}, @_;
+}
+
+sub getoptions {
+ my $array=shift;
+ my %params=@_;
+
+ if (! exists $params{bundling} || $params{bundling}) {
+ Getopt::Long::config("bundling");
+ }
+
+ my @test;
+ my %options=(
+ "v" => \$dh{VERBOSE},
+ "verbose" => \$dh{VERBOSE},
+
+ "no-act" => \$dh{NO_ACT},
+
+ "i" => \&AddPackage,
+ "indep" => \&AddPackage,
+
+ "a" => \&AddPackage,
+ "arch" => \&AddPackage,
+
+ "p=s" => \&AddPackage,
+ "package=s" => \&AddPackage,
+
+ "N=s" => \&ExcludePackage,
+ "no-package=s" => \&ExcludePackage,
+
+ "remaining-packages" => \$dh{EXCLUDE_LOGGED},
+
+ "dbg-package=s" => \&AddDebugPackage,
+
+ "s" => \&AddPackage,
+ "same-arch" => \&AddPackage,
+
+ "n" => \$dh{NOSCRIPTS},
+ "noscripts" => \$dh{NOSCRIPTS},
+ "o" => \$dh{ONLYSCRIPTS},
+ "onlyscripts" => \$dh{ONLYSCRIPTS},
+
+ "X=s" => \&AddExclude,
+ "exclude=s" => \&AddExclude,
+
+ "d" => \$dh{D_FLAG},
+
+ "k" => \$dh{K_FLAG},
+ "keep" => \$dh{K_FLAG},
+
+ "P=s" => \$dh{TMPDIR},
+ "tmpdir=s" => \$dh{TMPDIR},
+
+ "u=s", => \$dh{U_PARAMS},
+
+ "V:s", => \$dh{V_FLAG},
+
+ "A" => \$dh{PARAMS_ALL},
+ "all" => \$dh{PARAMS_ALL},
+
+ "priority=s" => \$dh{PRIORITY},
+
+ "h|help" => \&showhelp,
+
+ "mainpackage=s" => \$dh{MAINPACKAGE},
+
+ "name=s" => \$dh{NAME},
+
+ "error-handler=s" => \$dh{ERROR_HANDLER},
+
+ "ignore=s" => \&AddIgnore,
+
+ "O=s" => sub { push @test, $_[1] },
+
+ (ref $params{options} ? %{$params{options}} : ()) ,
+
+ "<>" => \&NonOption,
+ );
+
+ if ($params{test}) {
+ foreach my $key (keys %options) {
+ $options{$key}=sub {};
+ }
+ }
+
+ my $oldwarn;
+ if ($params{test} || $params{ignore_unknown_options}) {
+ $oldwarn=$SIG{__WARN__};
+ $SIG{__WARN__}=sub {};
+ }
+ my $ret=Getopt::Long::GetOptionsFromArray($array, %options);
+ if ($oldwarn) {
+ $SIG{__WARN__}=$oldwarn;
+ }
+
+ foreach my $opt (@test) {
+ # Try to parse an option, and skip it
+ # if it is not known.
+ if (getoptions([$opt], %params,
+ ignore_unknown_options => 0,
+ test => 1)) {
+ getoptions([$opt], %params);
+ }
+ }
+
+ return 1 if $params{ignore_unknown_options};
+ return $ret;
+}
+
+sub split_options_string {
+ my $str=shift;
+ $str=~s/^\s+//;
+ return split(/\s+/,$str);
+}
+
+# Parse options and set %dh values.
+sub parseopts {
+ my %params=@_;
+
+ 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}) {
+ @ARGV_extra=split(/\x1e/, $ENV{DH_INTERNAL_OPTIONS});
+ getoptions(\@ARGV_extra, %params);
+
+ # Avoid forcing acting on packages specified in
+ # DH_INTERNAL_OPTIONS. This way, -p can be specified
+ # at the command line to act on a specific package, but when
+ # nothing is specified, the excludes will cause the set of
+ # packages DH_INTERNAL_OPTIONS specifies to be acted on.
+ if (defined $dh{DOPACKAGES}) {
+ foreach my $package (getpackages()) {
+ if (! grep { $_ eq $package } @{$dh{DOPACKAGES}}) {
+ $exclude_package{$package}=1;
+ }
+ }
+ }
+ delete $dh{DOPACKAGES};
+ delete $dh{DOINDEP};
+ delete $dh{DOARCH};
+ }
+
+ # DH_OPTIONS can contain additional options to be parsed like @ARGV
+ if (defined $ENV{DH_OPTIONS}) {
+ @ARGV_extra=split_options_string($ENV{DH_OPTIONS});
+ my $ret=getoptions(\@ARGV_extra, %params);
+ if (!$ret) {
+ warning("warning: ignored unknown options in DH_OPTIONS");
+ }
+ }
+
+ my $ret=getoptions(\@ARGV, %params);
+ if (!$ret) {
+ if (! compat(7)) {
+ error("unknown option; aborting");
+ }
+ }
+
+ # Check to see if -V was specified. If so, but no parameters were
+ # passed, the variable will be defined but empty.
+ if (defined($dh{V_FLAG})) {
+ $dh{V_FLAG_SET}=1;
+ }
+
+ # If we have not been given any packages to act on, assume they
+ # want us to act on them all. Note we have to do this before excluding
+ # packages out, below.
+ if (! defined $dh{DOPACKAGES} || ! @{$dh{DOPACKAGES}}) {
+ if ($dh{DOINDEP} || $dh{DOARCH}) {
+ # User specified that all arch (in)dep package be
+ # built, and there are none of that type.
+ if (! $dh{BLOCK_NOOP_WARNINGS}) {
+ warning("You asked that all arch in(dep) packages be built, but there are none of that type.");
+ }
+ exit(0);
+ }
+ push @{$dh{DOPACKAGES}},getpackages("both");
+ }
+
+ # Remove excluded packages from the list of packages to act on.
+ # Also unique the list, in case some options were specified that
+ # added a package to it twice.
+ my @package_list;
+ my $package;
+ my %packages_seen;
+ foreach $package (@{$dh{DOPACKAGES}}) {
+ if (defined($dh{EXCLUDE_LOGGED}) &&
+ grep { $_ eq basename($0) } load_log($package)) {
+ $exclude_package{$package}=1;
+ }
+ if (! $exclude_package{$package}) {
+ if (! exists $packages_seen{$package}) {
+ $packages_seen{$package}=1;
+ push @package_list, $package;
+ }
+ }
+ }
+ @{$dh{DOPACKAGES}}=@package_list;
+
+ if (! defined $dh{DOPACKAGES} || ! @{$dh{DOPACKAGES}}) {
+ if (! $dh{BLOCK_NOOP_WARNINGS}) {
+ warning("No packages to build.");
+ }
+ exit(0);
+ }
+
+ if (defined $dh{U_PARAMS}) {
+ # Split the U_PARAMS up into an array.
+ my $u=$dh{U_PARAMS};
+ undef $dh{U_PARAMS};
+ push @{$dh{U_PARAMS}}, split(/\s+/,$u);
+ }
+
+ # Anything left in @ARGV is options that appeared after a --
+ # These options are added to the U_PARAMS array, while the
+ # non-option values we collected replace them in @ARGV;
+ push @{$dh{U_PARAMS}}, @ARGV, @ARGV_extra;
+ @ARGV=@{$dh{ARGV}} if exists $dh{ARGV};
+}
+
+1
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
new file mode 100644
index 00000000..2acfad9b
--- /dev/null
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -0,0 +1,983 @@
+#!/usr/bin/perl -w
+#
+# Library functions for debhelper programs, perl version.
+#
+# Joey Hess, GPL copyright 1997-2008.
+
+package Debian::Debhelper::Dh_Lib;
+use strict;
+
+use Exporter;
+use vars qw(@ISA @EXPORT %dh);
+@ISA=qw(Exporter);
+@EXPORT=qw(&init &doit &complex_doit &verbose_print &error &warning &tmpdir
+ &pkgfile &pkgext &pkgfilename &isnative &autoscript &filearray
+ &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 &commit_override_log
+ &dpkg_architecture_value &sourcepackage
+ &is_make_jobserver_unavailable &clean_jobserver_makeflags
+ &cross_command &set_buildflags &get_buildoption);
+
+my $max_compat=10;
+
+# The Makefile changes this if debhelper is installed in a PREFIX.
+my $prefix="/usr";
+
+sub init {
+ my %params=@_;
+
+ # Check to see if an option line starts with a dash,
+ # or DH_OPTIONS is set.
+ # If so, we need to pass this off to the resource intensive
+ # 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) {
+ eval "use Debian::Debhelper::Dh_Getopt";
+ error($@) if $@;
+ Debian::Debhelper::Dh_Getopt::parseopts(%params);
+ }
+
+ # Another way to set excludes.
+ if (exists $ENV{DH_ALWAYS_EXCLUDE} && length $ENV{DH_ALWAYS_EXCLUDE}) {
+ push @{$dh{EXCLUDE}}, split(":", $ENV{DH_ALWAYS_EXCLUDE});
+ }
+
+ # Generate EXCLUDE_FIND.
+ if ($dh{EXCLUDE}) {
+ $dh{EXCLUDE_FIND}='';
+ foreach (@{$dh{EXCLUDE}}) {
+ my $x=$_;
+ $x=escape_shell($x);
+ $x=~s/\./\\\\./g;
+ $dh{EXCLUDE_FIND}.="-regex .\\*$x.\\* -or ";
+ }
+ $dh{EXCLUDE_FIND}=~s/ -or $//;
+ }
+
+ # Check to see if DH_VERBOSE environment variable was set, if so,
+ # make sure verbose is on.
+ if (defined $ENV{DH_VERBOSE} && $ENV{DH_VERBOSE} ne "") {
+ $dh{VERBOSE}=1;
+ }
+
+ # Check to see if DH_NO_ACT environment variable was set, if so,
+ # make sure no act mode is on.
+ if (defined $ENV{DH_NO_ACT} && $ENV{DH_NO_ACT} ne "") {
+ $dh{NO_ACT}=1;
+ }
+
+ # Get the name of the main binary package (first one listed in
+ # debian/control). Only if the main package was not set on the
+ # command line.
+ if (! exists $dh{MAINPACKAGE} || ! defined $dh{MAINPACKAGE}) {
+ my @allpackages=getpackages();
+ $dh{MAINPACKAGE}=$allpackages[0];
+ }
+
+ # Check if packages to build have been specified, if not, fall back to
+ # the default, building all relevant packages.
+ if (! defined $dh{DOPACKAGES} || ! @{$dh{DOPACKAGES}}) {
+ push @{$dh{DOPACKAGES}}, getpackages('both');
+ }
+
+ # Check to see if -P was specified. If so, we can only act on a single
+ # package.
+ if ($dh{TMPDIR} && $#{$dh{DOPACKAGES}} > 0) {
+ error("-P was specified, but multiple packages would be acted on (".join(",",@{$dh{DOPACKAGES}}).").");
+ }
+
+ # Figure out which package is the first one we were instructed to build.
+ # This package gets special treatement: files and directories specified on
+ # the command line may affect it.
+ $dh{FIRSTPACKAGE}=${$dh{DOPACKAGES}}[0];
+
+ # If no error handling function was specified, just propagate
+ # errors out.
+ if (! exists $dh{ERROR_HANDLER} || ! defined $dh{ERROR_HANDLER}) {
+ $dh{ERROR_HANDLER}='exit \$?';
+ }
+}
+
+# Run at exit. Add the command to the log files for the packages it acted
+# on, if it's exiting successfully.
+my $write_log=1;
+sub END {
+ if ($? == 0 && $write_log) {
+ write_log(basename($0), @{$dh{DOPACKAGES}});
+ }
+}
+
+sub logfile {
+ my $package=shift;
+ my $ext=pkgext($package);
+ return "debian/${ext}debhelper.log"
+}
+
+sub add_override {
+ my $line=shift;
+ $line="override_$ENV{DH_INTERNAL_OVERRIDE} $line"
+ if defined $ENV{DH_INTERNAL_OVERRIDE};
+ return $line;
+}
+
+sub remove_override {
+ my $line=shift;
+ $line=~s/^\Qoverride_$ENV{DH_INTERNAL_OVERRIDE}\E\s+//
+ if defined $ENV{DH_INTERNAL_OVERRIDE};
+ return $line;
+}
+
+sub load_log {
+ my ($package, $db)=@_;
+
+ my @log;
+ open(LOG, "<", logfile($package)) || return;
+ while (<LOG>) {
+ chomp;
+ my $command=remove_override($_);
+ push @log, $command;
+ $db->{$package}{$command}=1 if defined $db;
+ }
+ close LOG;
+ return @log;
+}
+
+sub write_log {
+ my $cmd=shift;
+ my @packages=@_;
+
+ return if $dh{NO_ACT};
+
+ foreach my $package (@packages) {
+ my $log=logfile($package);
+ open(LOG, ">>", $log) || error("failed to write to ${log}: $!");
+ print LOG add_override($cmd)."\n";
+ close LOG;
+ }
+}
+
+sub commit_override_log {
+ my @packages=@_;
+
+ return if $dh{NO_ACT};
+
+ foreach my $package (@packages) {
+ my @log=map { remove_override($_) } load_log($package);
+ my $log=logfile($package);
+ open(LOG, ">", $log) || error("failed to write to ${log}: $!");
+ print LOG $_."\n" foreach @log;
+ close LOG;
+ }
+}
+
+sub inhibit_log {
+ $write_log=0;
+}
+
+# Pass it an array containing the arguments of a shell command like would
+# be run by exec(). It turns that into a line like you might enter at the
+# shell, escaping metacharacters and quoting arguments that contain spaces.
+sub escape_shell {
+ my @args=@_;
+ my $line="";
+ my @ret;
+ foreach my $word (@args) {
+ if ($word=~/\s/) {
+ # Escape only a few things since it will be quoted.
+ # Note we use double quotes because you cannot
+ # escape ' in single quotes, while " can be escaped
+ # in double.
+ # This does make -V"foo bar" turn into "-Vfoo bar",
+ # but that will be parsed identically by the shell
+ # anyway..
+ $word=~s/([\n`\$"\\])/\\$1/g;
+ push @ret, "\"$word\"";
+ }
+ else {
+ # This list is from _Unix in a Nutshell_. (except '#')
+ $word=~s/([\s!"\$()*+#;<>?@\[\]\\`|~])/\\$1/g;
+ push @ret,$word;
+ }
+ }
+ return join(' ', @ret);
+}
+
+# Run a command, and display the command to stdout if verbose mode is on.
+# All commands that modifiy files in $TMP should be ran via this
+# function.
+#
+# Note that this cannot handle complex commands, especially anything
+# involving redirection. Use complex_doit instead.
+sub doit {
+ verbose_print(escape_shell(@_));
+
+ if (! $dh{NO_ACT}) {
+ system(@_) == 0 || _error_exitcode(join(" ", @_));
+ }
+}
+
+# Run a command and display the command to stdout if verbose mode is on.
+# Use doit() if you can, instead of this function, because this function
+# forks a shell. However, this function can handle more complicated stuff
+# like redirection.
+sub complex_doit {
+ verbose_print(join(" ",@_));
+
+ if (! $dh{NO_ACT}) {
+ # The join makes system get a scalar so it forks off a shell.
+ system(join(" ", @_)) == 0 || _error_exitcode(join(" ", @_))
+ }
+}
+
+sub _error_exitcode {
+ my $command=shift;
+ if ($? == -1) {
+ error("$command failed to to execute: $!");
+ }
+ elsif ($? & 127) {
+ error("$command died with signal ".($? & 127));
+ }
+ else {
+ error("$command returned exit code ".($? >> 8));
+ }
+}
+
+# Run a command that may have a huge number of arguments, like xargs does.
+# Pass in a reference to an array containing the arguments, and then other
+# parameters that are the command and any parameters that should be passed to
+# it each time.
+sub xargs {
+ my $args=shift;
+
+ # The kernel can accept command lines up to 20k worth of characters.
+ my $command_max=20000; # LINUX SPECIFIC!!
+ # (And obsolete; it's bigger now.)
+ # I could use POSIX::ARG_MAX, but that would be slow.
+
+ # Figure out length of static portion of command.
+ my $static_length=0;
+ foreach (@_) {
+ $static_length+=length($_)+1;
+ }
+
+ my @collect=();
+ my $length=$static_length;
+ foreach (@$args) {
+ if (length($_) + 1 + $static_length > $command_max) {
+ error("This command is greater than the maximum command size allowed by the kernel, and cannot be split up further. What on earth are you doing? \"@_ $_\"");
+ }
+ $length+=length($_) + 1;
+ if ($length < $command_max) {
+ push @collect, $_;
+ }
+ else {
+ doit(@_,@collect) if $#collect > -1;
+ @collect=($_);
+ $length=$static_length + length($_) + 1;
+ }
+ }
+ doit(@_,@collect) if $#collect > -1;
+}
+
+# Print something if the verbose flag is on.
+sub verbose_print {
+ my $message=shift;
+
+ if ($dh{VERBOSE}) {
+ print "\t$message\n";
+ }
+}
+
+# Output an error message and die (can be caught).
+sub error {
+ my $message=shift;
+
+ die basename($0).": $message\n";
+}
+
+# Output a warning.
+sub warning {
+ my $message=shift;
+
+ print STDERR basename($0).": $message\n";
+}
+
+# Returns the basename of the argument passed to it.
+sub basename {
+ my $fn=shift;
+
+ $fn=~s/\/$//g; # ignore trailing slashes
+ $fn=~s:^.*/(.*?)$:$1:;
+ return $fn;
+}
+
+# Returns the directory name of the argument passed to it.
+sub dirname {
+ my $fn=shift;
+
+ $fn=~s/\/$//g; # ignore trailing slashes
+ $fn=~s:^(.*)/.*?$:$1:;
+ return $fn;
+}
+
+# Pass in a number, will return true iff the current compatibility level
+# is less than or equal to that number.
+{
+ my $warned_compat=0;
+ my $c;
+
+ sub compat {
+ my $num=shift;
+ my $nowarn=shift;
+
+ if (! defined $c) {
+ $c=1;
+ if (-e 'debian/compat') {
+ open (COMPAT_IN, "debian/compat") || error "debian/compat: $!";
+ my $l=<COMPAT_IN>;
+ close COMPAT_IN;
+ if (! defined $l || ! length $l) {
+ warning("debian/compat is empty, assuming level $c")
+ unless defined $ENV{DH_COMPAT};
+ }
+ else {
+ chomp $l;
+ $c=$l;
+ }
+ }
+ else {
+ warning("No compatibility level specified in debian/compat");
+ warning("This package will soon FTBFS; time to fix it!");
+ }
+
+ if (defined $ENV{DH_COMPAT}) {
+ $c=$ENV{DH_COMPAT};
+ }
+ }
+
+ if ($c <= 4 && ! $warned_compat && ! $nowarn) {
+ warning("Compatibility levels before 5 are deprecated (level $c in use)");
+ $warned_compat=1;
+ }
+
+ if ($c > $max_compat) {
+ error("Sorry, but $max_compat is the highest compatibility level supported by this debhelper.");
+ }
+
+ return ($c <= $num);
+ }
+}
+
+# Pass it a name of a binary package, it returns the name of the tmp dir to
+# use, for that package.
+sub tmpdir {
+ my $package=shift;
+
+ if ($dh{TMPDIR}) {
+ return $dh{TMPDIR};
+ }
+ elsif (compat(1) && $package eq $dh{MAINPACKAGE}) {
+ # This is for back-compatibility with the debian/tmp tradition.
+ return "debian/tmp";
+ }
+ else {
+ return "debian/$package";
+ }
+}
+
+# Pass this the name of a binary package, and the name of the file wanted
+# for the package, and it will return the actual existing filename to use.
+#
+# It tries several filenames:
+# * debian/package.filename.buildarch
+# * debian/package.filename.buildos
+# * debian/package.filename
+# * debian/filename (if the package is the main package)
+# If --name was specified then the files
+# must have the name after the package name:
+# * debian/package.name.filename.buildarch
+# * debian/package.name.filename.buildos
+# * debian/package.name.filename
+# * debian/name.filename (if the package is the main package)
+sub pkgfile {
+ my $package=shift;
+ my $filename=shift;
+
+ if (defined $dh{NAME}) {
+ $filename="$dh{NAME}.$filename";
+ }
+
+ # First, check for files ending in buildarch and buildos.
+ my $match;
+ foreach my $file (glob("debian/$package.$filename.*")) {
+ next if ! -f $file;
+ next if $dh{IGNORE} && exists $dh{IGNORE}->{$file};
+ if ($file eq "debian/$package.$filename.".buildarch()) {
+ $match=$file;
+ # buildarch files are used in preference to buildos files.
+ last;
+ }
+ elsif ($file eq "debian/$package.$filename.".buildos()) {
+ $match=$file;
+ }
+ }
+ return $match if defined $match;
+
+ my @try=("debian/$package.$filename");
+ if ($package eq $dh{MAINPACKAGE}) {
+ push @try, "debian/$filename";
+ }
+
+ foreach my $file (@try) {
+ if (-f $file &&
+ (! $dh{IGNORE} || ! exists $dh{IGNORE}->{$file})) {
+ return $file;
+ }
+
+ }
+
+ return "";
+
+}
+
+# Pass it a name of a binary package, it returns the name to prefix to files
+# in debian/ for this package.
+sub pkgext {
+ my $package=shift;
+
+ if (compat(1) and $package eq $dh{MAINPACKAGE}) {
+ return "";
+ }
+ return "$package.";
+}
+
+# Pass it the name of a binary package, it returns the name to install
+# files by in eg, etc. Normally this is the same, but --name can override
+# it.
+sub pkgfilename {
+ my $package=shift;
+
+ if (defined $dh{NAME}) {
+ return $dh{NAME};
+ }
+ return $package;
+}
+
+# Returns 1 if the package is a native debian package, null otherwise.
+# As a side effect, sets $dh{VERSION} to the version of this package.
+{
+ # Caches return code so it only needs to run dpkg-parsechangelog once.
+ my %isnative_cache;
+
+ sub isnative {
+ my $package=shift;
+
+ return $isnative_cache{$package} if defined $isnative_cache{$package};
+
+ # Make sure we look at the correct changelog.
+ my $isnative_changelog=pkgfile($package,"changelog");
+ if (! $isnative_changelog) {
+ $isnative_changelog="debian/changelog";
+ }
+ # Get the package version.
+ my $version=`dpkg-parsechangelog -l$isnative_changelog`;
+ ($dh{VERSION})=$version=~m/Version:\s*(.*)/m;
+ # Did the changelog parse fail?
+ if (! defined $dh{VERSION}) {
+ error("changelog parse failure");
+ }
+
+ # Is this a native Debian package?
+ if ($dh{VERSION}=~m/.*-/) {
+ return $isnative_cache{$package}=0;
+ }
+ else {
+ return $isnative_cache{$package}=1;
+ }
+ }
+}
+
+# Automatically add a shell script snippet to a debian script.
+# Only works if the script has #DEBHELPER# in it.
+#
+# Parameters:
+# 1: package
+# 2: script to add to
+# 3: filename of snippet
+# 4: either text: shell-quoted sed to run on the snippet. Ie, 's/#PACKAGE#/$PACKAGE/'
+# or a sub to run on each line of the snippet. Ie sub { s/#PACKAGE#/$PACKAGE/ }
+sub autoscript {
+ my $package=shift;
+ my $script=shift;
+ my $filename=shift;
+ my $sed=shift || "";
+
+ # This is the file we will modify.
+ my $outfile="debian/".pkgext($package)."$script.debhelper";
+
+ # Figure out what shell script snippet to use.
+ my $infile;
+ if (defined($ENV{DH_AUTOSCRIPTDIR}) &&
+ -e "$ENV{DH_AUTOSCRIPTDIR}/$filename") {
+ $infile="$ENV{DH_AUTOSCRIPTDIR}/$filename";
+ }
+ else {
+ if (-e "$prefix/share/debhelper/autoscripts/$filename") {
+ $infile="$prefix/share/debhelper/autoscripts/$filename";
+ }
+ else {
+ error("$prefix/share/debhelper/autoscripts/$filename does not exist");
+ }
+ }
+
+ if (-e $outfile && ($script eq 'postrm' || $script eq 'prerm')
+ && !compat(5)) {
+ # Add fragments to top so they run in reverse order when removing.
+ complex_doit("echo \"# Automatically added by ".basename($0)."\"> $outfile.new");
+ autoscript_sed($sed, $infile, "$outfile.new");
+ complex_doit("echo '# End automatically added section' >> $outfile.new");
+ complex_doit("cat $outfile >> $outfile.new");
+ complex_doit("mv $outfile.new $outfile");
+ }
+ else {
+ complex_doit("echo \"# Automatically added by ".basename($0)."\">> $outfile");
+ autoscript_sed($sed, $infile, $outfile);
+ complex_doit("echo '# End automatically added section' >> $outfile");
+ }
+}
+
+sub autoscript_sed {
+ my $sed = shift;
+ my $infile = shift;
+ my $outfile = shift;
+ if (ref($sed) eq 'CODE') {
+ open(IN, $infile) or die "$infile: $!";
+ open(OUT, ">>$outfile") or die "$outfile: $!";
+ while (<IN>) { $sed->(); print OUT }
+ close(OUT) or die "$outfile: $!";
+ close(IN) or die "$infile: $!";
+ }
+ else {
+ complex_doit("sed \"$sed\" $infile >> $outfile");
+ }
+}
+
+# Removes a whole substvar line.
+sub delsubstvar {
+ my $package=shift;
+ my $substvar=shift;
+
+ my $ext=pkgext($package);
+ my $substvarfile="debian/${ext}substvars";
+
+ if (-e $substvarfile) {
+ complex_doit("grep -s -v '^${substvar}=' $substvarfile > $substvarfile.new || true");
+ doit("mv", "$substvarfile.new","$substvarfile");
+ }
+}
+
+# Adds a dependency on some package to the specified
+# substvar in a package's substvar's file.
+sub addsubstvar {
+ my $package=shift;
+ my $substvar=shift;
+ my $deppackage=shift;
+ my $verinfo=shift;
+ my $remove=shift;
+
+ my $ext=pkgext($package);
+ my $substvarfile="debian/${ext}substvars";
+ my $str=$deppackage;
+ $str.=" ($verinfo)" if defined $verinfo && length $verinfo;
+
+ # Figure out what the line will look like, based on what's there
+ # now, and what we're to add or remove.
+ my $line="";
+ if (-e $substvarfile) {
+ my %items;
+ open(SUBSTVARS_IN, "$substvarfile") || error "read $substvarfile: $!";
+ while (<SUBSTVARS_IN>) {
+ chomp;
+ if (/^\Q$substvar\E=(.*)/) {
+ %items = map { $_ => 1} split(", ", $1);
+
+ last;
+ }
+ }
+ close SUBSTVARS_IN;
+ if (! $remove) {
+ $items{$str}=1;
+ }
+ else {
+ delete $items{$str};
+ }
+ $line=join(", ", sort keys %items);
+ }
+ elsif (! $remove) {
+ $line=$str;
+ }
+
+ if (length $line) {
+ complex_doit("(grep -s -v ${substvar} $substvarfile; echo ".escape_shell("${substvar}=$line").") > $substvarfile.new");
+ doit("mv", "$substvarfile.new", $substvarfile);
+ }
+ else {
+ delsubstvar($package,$substvar);
+ }
+}
+
+# Reads in the specified file, one line at a time. splits on words,
+# and returns an array of arrays of the contents.
+# If a value is passed in as the second parameter, then glob
+# expansion is done in the directory specified by the parameter ("." is
+# frequently a good choice).
+sub filedoublearray {
+ my $file=shift;
+ my $globdir=shift;
+
+ # executable config files are a v9 thing.
+ my $x=! compat(8) && -x $file;
+ if ($x) {
+ require Cwd;
+ my $cmd=Cwd::abs_path($file);
+ open (DH_FARRAY_IN, "$cmd |") || error("cannot run $file: $!");
+ }
+ else {
+ open (DH_FARRAY_IN, $file) || error("cannot read $file: $!");
+ }
+
+ my @ret;
+ while (<DH_FARRAY_IN>) {
+ chomp;
+ # Only ignore comments and empty lines in v5 mode.
+ if (! compat(4) && ! $x) {
+ next if /^#/ || /^$/;
+ }
+ my @line;
+ # Only do glob expansion in v3 mode.
+ #
+ # The tricky bit is that the glob expansion is done
+ # as if we were in the specified directory, so the
+ # filenames that come out are relative to it.
+ if (defined $globdir && ! compat(2) && ! $x) {
+ foreach (map { glob "$globdir/$_" } split) {
+ s#^$globdir/##;
+ push @line, $_;
+ }
+ }
+ else {
+ @line = split;
+ }
+ push @ret, [@line];
+ }
+
+ close DH_FARRAY_IN || error("problem reading $file: $!");
+
+ return @ret;
+}
+
+# Reads in the specified file, one word at a time, and returns an array of
+# the result. Can do globbing as does filedoublearray.
+sub filearray {
+ return map { @$_ } filedoublearray(@_);
+}
+
+# Passed a filename, returns true if -X says that file should be excluded.
+sub excludefile {
+ my $filename = shift;
+ foreach my $f (@{$dh{EXCLUDE}}) {
+ return 1 if $filename =~ /\Q$f\E/;
+ }
+ return 0;
+}
+
+{
+ my %dpkg_arch_output;
+ sub dpkg_architecture_value {
+ my $var = shift;
+ if (! exists($dpkg_arch_output{$var})) {
+ local $_;
+ open(PIPE, '-|', 'dpkg-architecture')
+ or error("dpkg-architecture failed");
+ while (<PIPE>) {
+ chomp;
+ my ($k, $v) = split(/=/, $_, 2);
+ $dpkg_arch_output{$k} = $v;
+ }
+ close(PIPE);
+ }
+ return $dpkg_arch_output{$var};
+ }
+}
+
+# Returns the build architecture.
+sub buildarch {
+ dpkg_architecture_value('DEB_HOST_ARCH');
+}
+
+# Returns the build OS.
+sub buildos {
+ dpkg_architecture_value("DEB_HOST_ARCH_OS");
+}
+
+# Passed an arch and a list of arches to match against, returns true if matched
+{
+ my %knownsame;
+
+ sub samearch {
+ my $arch=shift;
+ my @archlist=split(/\s+/,shift);
+
+ foreach my $a (@archlist) {
+ # Avoid expensive dpkg-architecture call to compare
+ # with a simple architecture name. "linux-any" and
+ # other architecture wildcards are (currently)
+ # always hypenated.
+ if ($a !~ /-/) {
+ return 1 if $arch eq $a;
+ }
+ elsif (exists $knownsame{$arch}{$a}) {
+ return 1 if $knownsame{$arch}{$a};
+ }
+ elsif (system("dpkg-architecture", "-a$arch", "-i$a") == 0) {
+ return $knownsame{$arch}{$a}=1;
+ }
+ else {
+ $knownsame{$arch}{$a}=0;
+ }
+ }
+
+ 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.
+# Pass "arch" or "indep" to specify arch-dependant (that will be built
+# for the system's arch) or independant. If nothing is specified,
+# returns all packages. Also, "both" returns the union of "arch" and "indep"
+# packages.
+# As a side effect, populates %package_arches and %package_types with the
+# types of all packages (not only those returned).
+my (%package_types, %package_arches);
+sub getpackages {
+ my $type=shift;
+
+ %package_types=();
+ %package_arches=();
+
+ $type="" if ! defined $type;
+
+ my $package="";
+ my $arch="";
+ my $package_type;
+ my @list=();
+ my %seen;
+ open (CONTROL, 'debian/control') ||
+ error("cannot read debian/control: $!\n");
+ while (<CONTROL>) {
+ chomp;
+ s/\s+$//;
+ if (/^Package:\s*(.*)/) {
+ $package=$1;
+ # Detect duplicate package names in the same control file.
+ if (! $seen{$package}) {
+ $seen{$package}=1;
+ }
+ else {
+ error("debian/control has a duplicate entry for $package");
+ }
+ $package_type="deb";
+ }
+ if (/^Architecture:\s*(.*)/) {
+ $arch=$1;
+ }
+ if (/^(?:X[BC]*-)?Package-Type:\s*(.*)/) {
+ $package_type=$1;
+ }
+
+ if (!$_ or eof) { # end of stanza.
+ if ($package) {
+ $package_types{$package}=$package_type;
+ $package_arches{$package}=$arch;
+ }
+
+ if ($package &&
+ ((($type eq 'indep' || $type eq 'both') && $arch eq 'all') ||
+ (($type eq 'arch' || $type eq 'both') && ($arch eq 'any' ||
+ ($arch ne 'all' &&
+ samearch(buildarch(), $arch)))) ||
+ ! $type)) {
+ push @list, $package;
+ $package="";
+ $arch="";
+ }
+ }
+ }
+ close CONTROL;
+
+ return @list;
+}
+
+# Returns the arch a package will build for.
+sub package_arch {
+ my $package=shift;
+
+ if (! exists $package_arches{$package}) {
+ warning "package $package is not in control info";
+ return buildarch();
+ }
+ return $package_arches{$package} eq 'all' ? "all" : buildarch();
+}
+
+# Return true if a given package is really a udeb.
+sub is_udeb {
+ my $package=shift;
+
+ if (! exists $package_types{$package}) {
+ warning "package $package is not in control info";
+ return 0;
+ }
+ return $package_types{$package} eq 'udeb';
+}
+
+# Generates the filename that is used for a udeb package.
+sub udeb_filename {
+ my $package=shift;
+
+ my $filearch=package_arch($package);
+ isnative($package); # side effect
+ my $version=$dh{VERSION};
+ $version=~s/^[0-9]+://; # strip any epoch
+ return "${package}_${version}_$filearch.udeb";
+}
+
+# Handles #DEBHELPER# substitution in a script; also can generate a new
+# script from scratch if none exists but there is a .debhelper file for it.
+sub debhelper_script_subst {
+ my $package=shift;
+ my $script=shift;
+
+ my $tmp=tmpdir($package);
+ my $ext=pkgext($package);
+ my $file=pkgfile($package,$script);
+
+ if ($file ne '') {
+ if (-f "debian/$ext$script.debhelper") {
+ # Add this into the script, where it has #DEBHELPER#
+ complex_doit("perl -pe 's~#DEBHELPER#~qx{cat debian/$ext$script.debhelper}~eg' < $file > $tmp/DEBIAN/$script");
+ }
+ else {
+ # Just get rid of any #DEBHELPER# in the script.
+ complex_doit("sed s/#DEBHELPER#// < $file > $tmp/DEBIAN/$script");
+ }
+ doit("chown","0:0","$tmp/DEBIAN/$script");
+ doit("chmod",755,"$tmp/DEBIAN/$script");
+ }
+ elsif ( -f "debian/$ext$script.debhelper" ) {
+ complex_doit("printf '#!/bin/sh\nset -e\n' > $tmp/DEBIAN/$script");
+ complex_doit("cat debian/$ext$script.debhelper >> $tmp/DEBIAN/$script");
+ doit("chown","0:0","$tmp/DEBIAN/$script");
+ doit("chmod",755,"$tmp/DEBIAN/$script");
+ }
+}
+
+# Checks if make's jobserver is enabled via MAKEFLAGS, but
+# the FD used to communicate with it is actually not available.
+sub is_make_jobserver_unavailable {
+ if (exists $ENV{MAKEFLAGS} &&
+ $ENV{MAKEFLAGS} =~ /(?:^|\s)--jobserver-fds=(\d+)/) {
+ if (!open(my $in, "<&$1")) {
+ return 1; # unavailable
+ }
+ else {
+ close $in;
+ return 0; # available
+ }
+ }
+
+ return; # no jobserver specified
+}
+
+# Cleans out jobserver options from MAKEFLAGS.
+sub clean_jobserver_makeflags {
+ if (exists $ENV{MAKEFLAGS}) {
+ if ($ENV{MAKEFLAGS} =~ /(?:^|\s)--jobserver-fds=(\d+)/) {
+ $ENV{MAKEFLAGS} =~ s/(?:^|\s)--jobserver-fds=\S+//g;
+ $ENV{MAKEFLAGS} =~ s/(?:^|\s)-j\b//g;
+ }
+ delete $ENV{MAKEFLAGS} if $ENV{MAKEFLAGS} =~ /^\s*$/;
+ }
+}
+
+# If cross-compiling, returns appropriate cross version of command.
+sub cross_command {
+ my $command=shift;
+ if (dpkg_architecture_value("DEB_BUILD_GNU_TYPE")
+ ne dpkg_architecture_value("DEB_HOST_GNU_TYPE")) {
+ return dpkg_architecture_value("DEB_HOST_GNU_TYPE")."-$command";
+ }
+ else {
+ return $command;
+ }
+}
+
+# Sets environment variables from dpkg-buildflags. Avoids changing
+# any existing environment variables.
+sub set_buildflags {
+ return if $ENV{DH_INTERNAL_BUILDFLAGS} || compat(8);
+ $ENV{DH_INTERNAL_BUILDFLAGS}=1;
+
+ eval "use Dpkg::BuildFlags";
+ if ($@) {
+ warning "unable to load build flags: $@";
+ return;
+ }
+
+ my $buildflags = Dpkg::BuildFlags->new();
+ $buildflags->load_config();
+ foreach my $flag ($buildflags->list()) {
+ next unless $flag =~ /^[A-Z]/; # Skip flags starting with lowercase
+ if (! exists $ENV{$flag}) {
+ $ENV{$flag} = $buildflags->get($flag);
+ }
+ }
+}
+
+# Gets a DEB_BUILD_OPTIONS option, if set.
+sub get_buildoption {
+ my $wanted=shift;
+
+ return undef unless exists $ENV{DEB_BUILD_OPTIONS};
+
+ foreach my $opt (split(/\s+/, $ENV{DEB_BUILD_OPTIONS})) {
+ # currently parallel= is the only one with a parameter
+ if ($opt =~ /^parallel=(-?\d+)$/ && $wanted eq 'parallel') {
+ return $1;
+ }
+ elsif ($opt eq $wanted) {
+ return 1;
+ }
+ }
+}
+
+1
diff --git a/Debian/Debhelper/Sequence/python_support.pm b/Debian/Debhelper/Sequence/python_support.pm
new file mode 100644
index 00000000..c93d2126
--- /dev/null
+++ b/Debian/Debhelper/Sequence/python_support.pm
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+# debhelper sequence file for python-support
+
+use warnings;
+use strict;
+use Debian::Debhelper::Dh_Lib;
+
+# Test if dh_pysupport is available before inserting it.
+# (This would not be needed if this file was contained in the python-support
+# package.)
+if (-x "/usr/bin/dh_pysupport") {
+ insert_before("dh_installinit", "dh_pysupport");
+}
+
+1