diff options
Diffstat (limited to '')
-rw-r--r-- | lib/Debian/Debhelper/Buildsystem.pm | 605 | ||||
-rw-r--r-- | lib/Debian/Debhelper/Buildsystem/ant.pm | 52 | ||||
-rw-r--r-- | lib/Debian/Debhelper/Buildsystem/autoconf.pm | 98 | ||||
-rw-r--r-- | lib/Debian/Debhelper/Buildsystem/cmake.pm | 202 | ||||
-rw-r--r-- | lib/Debian/Debhelper/Buildsystem/makefile.pm | 204 | ||||
-rw-r--r-- | lib/Debian/Debhelper/Buildsystem/meson.pm | 158 | ||||
-rw-r--r-- | lib/Debian/Debhelper/Buildsystem/ninja.pm | 90 | ||||
-rw-r--r-- | lib/Debian/Debhelper/Buildsystem/perl_build.pm | 97 | ||||
-rw-r--r-- | lib/Debian/Debhelper/Buildsystem/perl_makemaker.pm | 104 | ||||
-rw-r--r-- | lib/Debian/Debhelper/Buildsystem/python_distutils.pm | 214 | ||||
-rw-r--r-- | lib/Debian/Debhelper/Buildsystem/qmake.pm | 103 | ||||
-rw-r--r-- | lib/Debian/Debhelper/Buildsystem/qmake_qt4.pm | 15 |
12 files changed, 1942 insertions, 0 deletions
diff --git a/lib/Debian/Debhelper/Buildsystem.pm b/lib/Debian/Debhelper/Buildsystem.pm new file mode 100644 index 0000000..795f3d3 --- /dev/null +++ b/lib/Debian/Debhelper/Buildsystem.pm @@ -0,0 +1,605 @@ +# 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) = @_; + my $class = ref($this); + my $target_name; + if ($class) { + # Do not assume that the target buildsystem has been provided. + # NAME could be called during an error in the constructor. + if ($this->IS_GENERATOR_BUILD_SYSTEM and $this->get_targetbuildsystem) { + $target_name = $this->get_targetbuildsystem->NAME; + } + } else { + $class = $this; + } + if ($class =~ m/^.+::([^:]+)$/) { + my $name = $1; + return "${name}+${target_name}" if defined($target_name); + return $name; + } + else { + error("Invalid 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 overridden in the derived +# class if really needed. +sub DEFAULT_BUILD_DIRECTORY { + "obj-" . dpkg_architecture_value("DEB_HOST_GNU_TYPE"); +} + +# Return 1 if the build system generator +sub IS_GENERATOR_BUILD_SYSTEM { + return 0; +} + +# Generator build-systems only +# The name of the supported target systems. The first one is +# assumed to be the default if DEFAULT_TARGET_BUILD_SYSTEM is +# not overridden. +sub SUPPORTED_TARGET_BUILD_SYSTEMS { + error("class lacking SUPPORTED_TARGET_BUILD_SYSTEMS"); +} + +# Generator build-systems only +# Name of default target build system if target is unspecified +# (e.g. --buildsystem=cmake instead of cmake+makefile). +sub DEFAULT_TARGET_BUILD_SYSTEM { + my ($this) = @_; + my @targets = $this->SUPPORTED_TARGET_BUILD_SYSTEMS; + # Assume they are listed in order. + return $targets[0]; +} + +# For regular build systems, the same as DESCRIPTION +# For generator based build systems, the DESCRIPTION of the generator build +# system + the target build system. Do not override this method unless you +# know what you are doing. +sub FULL_DESCRIPTION { + my ($this) = @_; + my $description = $this->DESCRIPTION; + return $description if not exists($this->{'targetbuildsystem'}); + my $target_build_system = $this->{'targetbuildsystem'}; + return $description if not defined($target_build_system); + my $target_desc = $target_build_system->FULL_DESCRIPTION; + return "${description} combined with ${target_desc}"; +} + +# 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) +# - targetbuildsystem - The target build system for generator based build +# systems. Only set for generator build systems. +# 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); + + # Setup the target buildsystem early, so e.g. _set_builddir also + # applies to the target build system. Useful if the generator + # and target does not agree on (e.g.) the default build dir. + my $target_bs_name; + if (exists $opts{targetbuildsystem}) { + $target_bs_name = $opts{targetbuildsystem}; + } + + $target_bs_name //= $this->DEFAULT_TARGET_BUILD_SYSTEM if $this->IS_GENERATOR_BUILD_SYSTEM; + + if (defined($target_bs_name)) { + my %target_opts = %opts; + # Let the target know it is used as a target build system. + # E.g. the makefile has special cases based on whether it is + # the main or a target build system. + delete($target_opts{'targetbuildsystem'}); + $target_opts{'_is_targetbuildsystem'} = 1; + my $target_system =_create_buildsystem_instance($target_bs_name, 1, %target_opts); + $this->set_targetbuildsystem($target_system); + } + + $this->{'_is_targetbuildsystem'} = $opts{'_is_targetbuildsystem'} + if exists($opts{'_is_targetbuildsystem'}); + + 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; + # Use get as guard because this method is (also) called from the + # constructor before the target build system is setup. + if ($this->get_targetbuildsystem) { + $this->get_targetbuildsystem->{builddir} = $builddir; + }; + return $builddir; +} + +sub set_targetbuildsystem { + my ($this, $target_system) = @_; + my $ok = 0; + my $target_bs_name = $target_system->NAME; + if (not $this->IS_GENERATOR_BUILD_SYSTEM) { + my $name = $this->NAME; + error("Cannot set a target build system: Buildsystem ${name} is not a generator build system"); + } + for my $supported_bs_name ($this->SUPPORTED_TARGET_BUILD_SYSTEMS) { + if ($supported_bs_name eq $target_bs_name) { + $ok = 1; + last; + } + } + if (not $ok) { + my $name = $this->NAME; + error("Buildsystem ${name} does not support ${target_bs_name} as target build system."); + } + $this->{'targetbuildsystem'} = $target_system +} + +sub _is_targetbuildsystem { + my ($this) = @_; + return 0 if not exists($this->{'_is_targetbuildsystem'}); + return $this->{'_is_targetbuildsystem'}; +} + +# Returns the target build system if it is provided +sub get_targetbuildsystem { + my $this = shift; + return if not exists($this->{'targetbuildsystem'}); + return $this->{'targetbuildsystem'}; +} + +# 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 partially 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 +# partially 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; + } + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->get_targetbuildsystem->enforce_in_source_building(@_); + # Only warn in one build system. + delete($this->{warn_insource}); + } +} + +# 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"); + } + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->get_targetbuildsystem->prefer_out_of_source_building(@_); + } + } +} + +# 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}; +} + +# This parallel support for the given step +sub disable_parallel { + my ($this) = @_; + $this->{parallel} = 1; + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->get_targetbuildsystem->disable_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()) { + mkdirs($this->get_builddir()); + } +} + +sub check_auto_buildable_clean_oos_buildir { + my $this = shift; + my ($step) = @_; + # This only applies to clean + return 0 if $step ne 'clean'; + my $builddir = $this->get_builddir; + # If there is no builddir, then this rule does not apply. + return 0 if not defined($builddir) or not -d $builddir; + return 1; +} + +sub _generic_doit_in_dir { + my ($this, $dir, $sub, @args) = @_; + my %args; + if (ref($args[0])) { + %args = %{shift(@args)}; + } + $args{chdir} = $dir; + return $sub->(\%args, @args); +} + +# Changes working directory to the source directory (if needed), +# calls print_and_doit(@_) and changes working directory back to the +# top directory. +sub doit_in_sourcedir { + my ($this, @args) = @_; + $this->_generic_doit_in_dir($this->get_sourcedir, \&print_and_doit, @args); + return 1; +} + +# Changes working directory to the source directory (if needed), +# calls print_and_doit(@_) and changes working directory back to the +# top directory. Errors are ignored. +sub doit_in_sourcedir_noerror { + my ($this, @args) = @_; + return $this->_generic_doit_in_dir($this->get_sourcedir, \&print_and_doit_noerror, @args); +} + +# Changes working directory to the build directory (if needed), +# calls print_and_doit(@_) and changes working directory back to the +# top directory. +sub doit_in_builddir { + my ($this, @args) = @_; + $this->_generic_doit_in_dir($this->get_buildpath, \&print_and_doit, @args); + return 1; +} + +# Changes working directory to the build directory (if needed), +# calls print_and_doit(@_) and changes working directory back to the +# top directory. Errors are ignored. +sub doit_in_builddir_noerror { + my ($this, @args) = @_; + return $this->_generic_doit_in_dir($this->get_buildpath, \&print_and_doit_noerror, @args); +} + +# 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}; + } + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->get_targetbuildsystem->pre_building_step(@_); + } +} + +# 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)=@_; + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->get_targetbuildsystem->post_building_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 overridden by derived classes to +# implement build system specific steps needed to build the +# source. Arbitrary number of custom step arguments might be +# passed. Default implementations do nothing. +# +# Note: For generator build systems, the default is to +# delegate the step to the target build system for all +# steps except configure. +sub configure { + my $this=shift; +} + +sub build { + my $this=shift; + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->get_targetbuildsystem->build(@_); + } +} + +sub test { + my $this=shift; + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->get_targetbuildsystem->test(@_); + } +} + +# destdir parameter specifies where to install files. +sub install { + my $this=shift; + my ($destdir) = @_; + + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->get_targetbuildsystem->install(@_); + } +} + +sub clean { + my $this=shift; + + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->get_targetbuildsystem->clean(@_); + } +} + + +sub _create_buildsystem_instance { + my ($full_name, $required, %bsopts) = @_; + my @parts = split(m{[+]}, $full_name, 2); + my $name = $parts[0]; + my $module = "Debian::Debhelper::Buildsystem::$name"; + if (@parts > 1) { + if (exists($bsopts{'targetbuildsystem'})) { + error("Conflicting target buildsystem for ${name} (load as ${full_name}, but target configured in bsopts)"); + } + $bsopts{'targetbuildsystem'} = $parts[1]; + } + + eval "use $module"; + if ($@) { + return if not $required; + error("unable to load build system class '$name': $@"); + } + return $module->new(%bsopts); +} + +1 diff --git a/lib/Debian/Debhelper/Buildsystem/ant.pm b/lib/Debian/Debhelper/Buildsystem/ant.pm new file mode 100644 index 0000000..49aaf1e --- /dev/null +++ b/lib/Debian/Debhelper/Buildsystem/ant.pm @@ -0,0 +1,52 @@ +# 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 warnings; +use parent qw(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; + my $d_ant_prop = $this->get_sourcepath('debian/ant.properties'); + my @args; + if ( -f $d_ant_prop ) { + push(@args, '-propertyfile', $d_ant_prop); + } + + # Set the username to improve the reproducibility + push(@args, "-Duser.name", "debian"); + + $this->doit_in_sourcedir("ant", @args, @_); +} + +sub clean { + my $this=shift; + my $d_ant_prop = $this->get_sourcepath('debian/ant.properties'); + my @args; + if ( -f $d_ant_prop ) { + push(@args, '-propertyfile', $d_ant_prop); + } + $this->doit_in_sourcedir("ant", @args, "clean", @_); +} + +1 diff --git a/lib/Debian/Debhelper/Buildsystem/autoconf.pm b/lib/Debian/Debhelper/Buildsystem/autoconf.pm new file mode 100644 index 0000000..8752ea1 --- /dev/null +++ b/lib/Debian/Debhelper/Buildsystem/autoconf.pm @@ -0,0 +1,98 @@ +# 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 warnings; +use Debian::Debhelper::Dh_Lib qw(%dh dpkg_architecture_value get_buildoption sourcepackage compat); +use parent qw(Debian::Debhelper::Buildsystem::makefile); + +sub DESCRIPTION { + "GNU Autoconf (configure)" +} + +sub check_auto_buildable { + my $this=shift; + my ($step)=@_; + + return 0 unless -f $this->get_sourcepath("configure") && + -x _; + + # Handle configure explicitly; inherit the rest + return 1 if $step eq "configure"; + return $this->SUPER::check_auto_buildable(@_); +} + +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"; + # We pass --disable/enable-* options that might be unknown, so we + # should not emit warnings. + push @opts, "--disable-option-checking"; + if ($dh{QUIET}) { + push @opts, "--enable-silent-rules"; + } else { + push @opts, "--disable-silent-rules"; + } + 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") if compat(11); + } + else { + push(@opts, "--libexecdir=\${prefix}/lib") if compat(11); + } + } + else { + push @opts, "--libexecdir=\${prefix}/lib/" . sourcepackage(); + } + push @opts, "--runstatedir=/run" if not compat(10); + 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 $@; + } +} + +sub test { + my $this=shift; + + my $parallel = $this->get_parallel(); + my @autotest; + push @autotest, "-j$parallel"; + push @autotest, "--verbose" if not get_buildoption("terse"); + $this->make_first_existing_target(['test', 'check'], + "TESTSUITEFLAGS=@autotest", + "VERBOSE=1", @_); +} + +1 diff --git a/lib/Debian/Debhelper/Buildsystem/cmake.pm b/lib/Debian/Debhelper/Buildsystem/cmake.pm new file mode 100644 index 0000000..c4a2ad9 --- /dev/null +++ b/lib/Debian/Debhelper/Buildsystem/cmake.pm @@ -0,0 +1,202 @@ +# 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 warnings; +use Debian::Debhelper::Dh_Lib qw(%dh compat dpkg_architecture_value error is_cross_compiling get_buildoption print_and_doit); +use parent qw(Debian::Debhelper::Buildsystem); + +my @STANDARD_CMAKE_FLAGS = qw( + -DCMAKE_INSTALL_PREFIX=/usr + -DCMAKE_BUILD_TYPE=None + -DCMAKE_INSTALL_SYSCONFDIR=/etc + -DCMAKE_INSTALL_LOCALSTATEDIR=/var + -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON + -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF + -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON + -DFETCHCONTENT_FULLY_DISCONNECTED=ON +); + +my %DEB_HOST2CMAKE_SYSTEM = ( + 'linux' => 'Linux', + 'kfreebsd' => 'kFreeBSD', + 'hurd' => 'GNU', +); + +my %GNU_CPU2SYSTEM_PROCESSOR = ( + 'arm' => 'armv7l', + 'mips64el' => 'mips64', + 'powerpc64le' => 'ppc64le', +); + +my %TARGET_BUILD_SYSTEM2CMAKE_GENERATOR = ( + 'makefile' => 'Unix Makefiles', + 'ninja' => 'Ninja', +); + +sub DESCRIPTION { + "CMake (CMakeLists.txt)" +} + +sub IS_GENERATOR_BUILD_SYSTEM { + return 1; +} + +sub SUPPORTED_TARGET_BUILD_SYSTEMS { + return qw(makefile ninja); +} + +sub check_auto_buildable { + my $this=shift; + my ($step)=@_; + if (-e $this->get_sourcepath("CMakeLists.txt")) { + my $ret = ($step eq "configure" && 1) || + $this->get_targetbuildsystem->check_auto_buildable(@_); + if ($this->check_auto_buildable_clean_oos_buildir(@_)) { + # 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. + $ret++ if not $ret; + } + # 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; + # Standard set of cmake flags + my @flags = @STANDARD_CMAKE_FLAGS; + my $backend = $this->get_targetbuildsystem->NAME; + + push(@flags, '-DCMAKE_INSTALL_RUNSTATEDIR=/run') if not compat(10); + # Speed up installation phase a bit. + push(@flags, "-DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=ON") if not compat(12); + # Reproducibility #962474 / #1004939 + push(@flags, '-DCMAKE_BUILD_RPATH_USE_ORIGIN=ON') if not compat(13); + if (exists($TARGET_BUILD_SYSTEM2CMAKE_GENERATOR{$backend})) { + my $generator = $TARGET_BUILD_SYSTEM2CMAKE_GENERATOR{$backend}; + push(@flags, "-G${generator}"); + } + if (not $dh{QUIET}) { + push(@flags, "-DCMAKE_VERBOSE_MAKEFILE=ON"); + } + + if ($ENV{CC}) { + push @flags, "-DCMAKE_C_COMPILER=" . $ENV{CC}; + } + if ($ENV{CXX}) { + push @flags, "-DCMAKE_CXX_COMPILER=" . $ENV{CXX}; + } + if (is_cross_compiling()) { + my $deb_host = dpkg_architecture_value("DEB_HOST_ARCH_OS"); + if (my $cmake_system = $DEB_HOST2CMAKE_SYSTEM{$deb_host}) { + push(@flags, "-DCMAKE_SYSTEM_NAME=${cmake_system}"); + } else { + error("Cannot cross-compile - CMAKE_SYSTEM_NAME not known for ${deb_host}"); + } + my $gnu_cpu = dpkg_architecture_value("DEB_HOST_GNU_CPU"); + if (exists($GNU_CPU2SYSTEM_PROCESSOR{$gnu_cpu})) { + push @flags, "-DCMAKE_SYSTEM_PROCESSOR=" . $GNU_CPU2SYSTEM_PROCESSOR{$gnu_cpu}; + } else { + push @flags, "-DCMAKE_SYSTEM_PROCESSOR=${gnu_cpu}"; + } + if (not $ENV{CC}) { + push @flags, "-DCMAKE_C_COMPILER=" . dpkg_architecture_value("DEB_HOST_GNU_TYPE") . "-gcc"; + } + if (not $ENV{CXX}) { + push @flags, "-DCMAKE_CXX_COMPILER=" . dpkg_architecture_value("DEB_HOST_GNU_TYPE") . "-g++"; + } + push(@flags, "-DPKG_CONFIG_EXECUTABLE=/usr/bin/" . dpkg_architecture_value("DEB_HOST_GNU_TYPE") . "-pkg-config"); + push(@flags, "-DPKGCONFIG_EXECUTABLE=/usr/bin/" . dpkg_architecture_value("DEB_HOST_GNU_TYPE") . "-pkg-config"); + push(@flags, "-DQMAKE_EXECUTABLE=/usr/bin/" . dpkg_architecture_value("DEB_HOST_GNU_TYPE") . "-qmake"); + } + push(@flags, "-DCMAKE_INSTALL_LIBDIR=lib/" . dpkg_architecture_value("DEB_HOST_MULTIARCH")); + + # 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", @flags, @_, $this->get_source_rel2builddir()); + }; + if (my $err = $@) { + if (-e $this->get_buildpath("CMakeCache.txt")) { + $this->doit_in_builddir('tail', '-v', '-n', '+0', 'CMakeCache.txt'); + } + if (-e $this->get_buildpath('CMakeFiles/CMakeOutput.log')) { + $this->doit_in_builddir('tail', '-v', '-n', '+0', 'CMakeFiles/CMakeOutput.log'); + } + if (-e $this->get_buildpath('CMakeFiles/CMakeError.log')) { + $this->doit_in_builddir('tail', '-v', '-n', '+0', 'CMakeFiles/CMakeError.log'); + } + die $err; + } +} + +sub build { + my $this=shift; + my $target = $this->get_targetbuildsystem; + if ($target->NAME eq 'makefile') { + # Add VERBOSE=1 for #973029 when not asked to be quiet/terse. + push(@_, "VERBOSE=1") if not $dh{QUIET}; + } + return $this->SUPER::build(@_); +} + +sub test { + my $this=shift; + my $target = $this->get_targetbuildsystem; + $ENV{CTEST_OUTPUT_ON_FAILURE} = 1; + if ($target->NAME eq 'makefile') { + # 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; + unshift(@_, "ARGS+=-j$parallel"); + unshift(@_, "ARGS+=--verbose") if not get_buildoption("terse"); + } + return $this->SUPER::test(@_); +} + +sub install { + my $this = shift; + my $target = $this->get_targetbuildsystem; + + if (compat(13)) { + $target->install(@_); + } else { + # In compat 14 `cmake --install` is preferred to `make install`, + # see https://bugs.debian.org/1020732 + my $destdir = shift; + my %options = ( + update_env => { + 'LC_ALL' => 'C.UTF-8', + 'DESTDIR' => $destdir, + } + ); + print_and_doit(\%options, 'cmake', '--install', $this->get_buildpath, @_); + } + return 1; +} + +1 diff --git a/lib/Debian/Debhelper/Buildsystem/makefile.pm b/lib/Debian/Debhelper/Buildsystem/makefile.pm new file mode 100644 index 0000000..856a6dd --- /dev/null +++ b/lib/Debian/Debhelper/Buildsystem/makefile.pm @@ -0,0 +1,204 @@ +# 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 warnings; +use Debian::Debhelper::Dh_Lib qw(dpkg_architecture_value escape_shell clean_jobserver_makeflags is_cross_compiling compat + should_use_root gain_root_cmd error); +use parent qw(Debian::Debhelper::Buildsystem); + +my %DEB_DEFAULT_TOOLS = ( + 'CC' => 'gcc', + 'CXX' => 'g++', + 'PKG_CONFIG' => 'pkg-config', +); + +# 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) || error("fork failed: $!"); + 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. + my $parallel = $this->get_parallel(); + if ($parallel == 0 or $parallel > 1) { + # We have to use the empty string for "unlimited" + $parallel = '' if $parallel == 0; + unshift(@_, "-j${parallel}"); + } else { + unshift(@_, '-j1'); + } + + my @root_cmd; + if (exists($this->{_run_make_as_root}) and $this->{_run_make_as_root}) { + @root_cmd = gain_root_cmd(); + } + $this->doit_in_builddir(@root_cmd, $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 ($this->check_auto_buildable_clean_oos_buildir(@_) + and $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 _should_inject_cross_build_tools { + my ($this) = @_; + return ref($this) eq 'Debian::Debhelper::Buildsystem::makefile'; +} + + +sub build { + my $this=shift; + if (not $this->_is_targetbuildsystem + and is_cross_compiling() + and $this->_should_inject_cross_build_tools) { + # Only inject build tools variables during cross-compile when + # makefile is the explicit *main* build system. + for my $var (sort(keys(%DEB_DEFAULT_TOOLS))) { + my $tool = $DEB_DEFAULT_TOOLS{$var}; + if ($ENV{$var}) { + unshift @_, $var . "=" . $ENV{$var}; + } else { + unshift @_, $var . "=" . dpkg_architecture_value("DEB_HOST_GNU_TYPE") . "-" . $tool; + } + } + } + if (ref($this) eq 'Debian::Debhelper::Buildsystem::makefile' and not compat(10)) { + unshift @_, "INSTALL=install --strip-program=true"; + } + $this->do_make(@_); +} + +sub test { + my $this=shift; + $this->make_first_existing_target(['test', 'check'], @_); +} + +sub install { + my $this=shift; + my $destdir=shift; + if (ref($this) eq 'Debian::Debhelper::Buildsystem::makefile' and not compat(10)) { + unshift @_, "INSTALL=install --strip-program=true"; + } + if ( -f $this->get_buildpath('libtool')) { + $this->disable_parallel(); + } + + if (should_use_root('debhelper/upstream-make-install') and $< != 0) { + $this->{_run_make_as_root} = 1; + } + + $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/lib/Debian/Debhelper/Buildsystem/meson.pm b/lib/Debian/Debhelper/Buildsystem/meson.pm new file mode 100644 index 0000000..3cd447d --- /dev/null +++ b/lib/Debian/Debhelper/Buildsystem/meson.pm @@ -0,0 +1,158 @@ +# A debhelper build system class for handling Meson based projects. +# +# Copyright: © 2017 Michael Biebl +# License: GPL-2+ + +package Debian::Debhelper::Buildsystem::meson; + +use strict; +use warnings; +use Debian::Debhelper::Dh_Lib qw(compat dpkg_architecture_value is_cross_compiling doit warning error generated_file); +use parent qw(Debian::Debhelper::Buildsystem); + +sub DESCRIPTION { + "Meson (meson.build)" +} + +sub IS_GENERATOR_BUILD_SYSTEM { + return 1; +} + +sub SUPPORTED_TARGET_BUILD_SYSTEMS { + return qw(ninja); +} + + +sub check_auto_buildable { + my $this=shift; + my ($step)=@_; + + return 0 unless -e $this->get_sourcepath("meson.build"); + + # Handle configure explicitly; inherit the rest + return 1 if $step eq "configure"; + my $ret = $this->get_targetbuildsystem->check_auto_buildable(@_); + if ($ret == 0 and $this->check_auto_buildable_clean_oos_buildir(@_)) { + # 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. + $ret++; + } + return $ret; +} + +sub new { + my $class=shift; + my $this=$class->SUPER::new(@_); + $this->prefer_out_of_source_building(@_); + return $this; +} + +sub configure { + my $this=shift; + + # Standard set of options for meson. + my @opts = ( + '--wrap-mode=nodownload', + ); + push @opts, "--buildtype=plain"; + push @opts, "--prefix=/usr"; + push @opts, "--sysconfdir=/etc"; + push @opts, "--localstatedir=/var"; + my $multiarch=dpkg_architecture_value("DEB_HOST_MULTIARCH"); + push @opts, "--libdir=lib/$multiarch"; + push(@opts, "--libexecdir=lib/$multiarch") if compat(11); + + if (is_cross_compiling()) { + # http://mesonbuild.com/Cross-compilation.html + my $cross_file = $ENV{'DH_MESON_CROSS_FILE'}; + if (not $cross_file) { + my $debcrossgen = '/usr/share/meson/debcrossgen'; + if (not -x $debcrossgen) { + warning("Missing debcrossgen (${debcrossgen}) cannot generate a meson cross file and non was provided"); + error("Cannot cross-compile: Please use meson (>= 0.42.1) or provide a cross file via DH_MESON_CROSS_FILE"); + } + my $filename = generated_file('_source', 'meson-cross-file.conf'); + my %options = ( + stdout => '/dev/null', + update_env => { LC_ALL => 'C.UTF-8'}, + ); + doit(\%options, $debcrossgen, "-o${filename}"); + $cross_file = $filename; + } + if ($cross_file !~ m{^/}) { + # Make the file name absolute as meson will be called from the build dir. + require Cwd; + $cross_file =~ s{^\./}{}; + $cross_file = Cwd::getcwd() . "/${cross_file}"; + } + push(@opts, '--cross-file', $cross_file); + } + + $this->mkdir_builddir(); + eval { + my %options = ( + update_env => { LC_ALL => 'C.UTF-8'}, + ); + $this->doit_in_builddir(\%options, "meson", "setup", $this->get_source_rel2builddir(), @opts, @_); + }; + if ($@) { + if (-e $this->get_buildpath("meson-logs/meson-log.txt")) { + $this->doit_in_builddir('tail', '-v', '-n', '+0', 'meson-logs/meson-log.txt'); + } + die $@; + } +} + +sub test { + my $this = shift; + my $target = $this->get_targetbuildsystem; + + eval { + if (compat(12) or $target->NAME ne 'ninja') { + $target->test(@_); + } else { + # In compat 13 with meson+ninja, we prefer using "meson test" + # over "ninja test" + my %options = ( + update_env => { + 'LC_ALL' => 'C.UTF-8', + } + ); + if ($this->get_parallel() > 0) { + $options{update_env}{MESON_TESTTHREADS} = $this->get_parallel(); + } + $this->doit_in_builddir(\%options, 'meson', 'test', @_); + } + }; + if (my $err = $@) { + if (-e $this->get_buildpath("meson-logs/testlog.txt")) { + $this->doit_in_builddir('tail', '-v', '-n', '+0', 'meson-logs/testlog.txt'); + } + die $err; + } + return 1; +} + +sub install { + my ($this, $destdir, @args) = @_; + my $target = $this->get_targetbuildsystem; + + if (compat(13) or $target->NAME ne 'ninja') { + $target->install($destdir, @args); + } else { + # In compat 14 with meson+ninja, we prefer using "meson install" + # over "ninja install" + my %options = ( + update_env => { + 'LC_ALL' => 'C.UTF-8', + } + ); + $this->doit_in_builddir(\%options, 'meson', 'install', '--destdir', $destdir, @args); + } + return 1; +} + + + +1 diff --git a/lib/Debian/Debhelper/Buildsystem/ninja.pm b/lib/Debian/Debhelper/Buildsystem/ninja.pm new file mode 100644 index 0000000..c08ff16 --- /dev/null +++ b/lib/Debian/Debhelper/Buildsystem/ninja.pm @@ -0,0 +1,90 @@ +# A debhelper build system class for handling ninja based projects. +# +# Copyright: © 2017 Michael Biebl +# License: GPL-2+ + +package Debian::Debhelper::Buildsystem::ninja; + +use strict; +use warnings; +use Debian::Debhelper::Dh_Lib qw(%dh dpkg_architecture_value); +use parent qw(Debian::Debhelper::Buildsystem); + +sub DESCRIPTION { + "Ninja (build.ninja)" +} + +sub new { + my $class=shift; + my $this=$class->SUPER::new(@_); + $this->{buildcmd} = "ninja"; + return $this; +} + +sub check_auto_buildable { + my $this=shift; + my ($step) = @_; + + if (-e $this->get_buildpath("build.ninja")) + { + # This is always called in the source directory, but generally + # Ninja files are created (or live) in the build directory. + return 1; + } + return 0; +} + +sub build { + my $this=shift; + my %options = ( + update_env => { + 'LC_ALL' => 'C.UTF-8', + } + ); + if (!$dh{QUIET}) { + unshift @_, "-v"; + } + if ($this->get_parallel() > 0) { + unshift @_, "-j" . $this->get_parallel(); + } + $this->doit_in_builddir(\%options, $this->{buildcmd}, @_); +} + +sub test { + my $this=shift; + my %options = ( + update_env => { + 'LC_ALL' => 'C.UTF-8', + } + ); + if ($this->get_parallel() > 0) { + $options{update_env}{MESON_TESTTHREADS} = $this->get_parallel(); + } + $this->doit_in_builddir(\%options, $this->{buildcmd}, "test", @_); +} + +sub install { + my $this=shift; + my $destdir=shift; + my %options = ( + update_env => { + 'LC_ALL' => 'C.UTF-8', + 'DESTDIR' => $destdir, + } + ); + $this->doit_in_builddir(\%options, $this->{buildcmd}, "install", @_); +} + +sub clean { + my $this=shift; + if (!$this->rmdir_builddir()) { + my %options = ( + update_env => { + 'LC_ALL' => 'C.UTF-8', + } + ); + $this->doit_in_builddir(\%options, $this->{buildcmd}, "clean", @_); + } +} + +1 diff --git a/lib/Debian/Debhelper/Buildsystem/perl_build.pm b/lib/Debian/Debhelper/Buildsystem/perl_build.pm new file mode 100644 index 0000000..8752905 --- /dev/null +++ b/lib/Debian/Debhelper/Buildsystem/perl_build.pm @@ -0,0 +1,97 @@ +# 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 warnings; +use Debian::Debhelper::Dh_Lib qw(compat is_cross_compiling perl_cross_incdir warning); +use parent qw(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; + my %options; + if (is_cross_compiling()) { + my $cross_incdir = perl_cross_incdir(); + if (defined $cross_incdir) { + my $perl5lib = $cross_incdir; + $perl5lib .= $Config{path_sep} . $ENV{PERL5LIB} + if defined $ENV{PERL5LIB}; + $options{update_env} = { PERL5LIB => $perl5lib }; + } else { + warning("cross Config.pm does not exist (missing build dependency on perl-xs-dev?)"); + } + } + $this->doit_in_sourcedir(\%options, $^X, @_); +} + +sub new { + my $class=shift; + my $this= $class->SUPER::new(@_); + $this->enforce_in_source_building(); + return $this; +} + +sub configure { + my $this=shift; + my (@flags, @perl_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)) { + my $ld = $Config{ld}; + if (is_cross_compiling()) { + my $incdir = perl_cross_incdir(); + $ld = qx/perl -I$incdir -MConfig -e 'print \$Config{ld}'/ + if defined $incdir; + } + push @flags, "--config", "ld=$ld $ENV{CFLAGS} $ENV{LDFLAGS}"; + } + push(@perl_flags, '-I.') if compat(10); + $this->do_perl(@perl_flags, "Build.PL", "--installdirs", "vendor", @flags, @_); +} + +sub build { + my $this=shift; + $this->do_perl("Build", @_); +} + +sub test { + my $this=shift; + $this->do_perl("Build", "test", "--verbose", 1, @_); +} + +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", "realclean", "--allow_mb_mismatch", 1, @_); + } +} + +1 diff --git a/lib/Debian/Debhelper/Buildsystem/perl_makemaker.pm b/lib/Debian/Debhelper/Buildsystem/perl_makemaker.pm new file mode 100644 index 0000000..881f1ec --- /dev/null +++ b/lib/Debian/Debhelper/Buildsystem/perl_makemaker.pm @@ -0,0 +1,104 @@ +# 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 warnings; +use Debian::Debhelper::Dh_Lib qw(compat is_cross_compiling perl_cross_incdir warning); +use parent qw(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, @perl_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}"; + } + my $cross_flag; + if (is_cross_compiling()) { + my $incdir = perl_cross_incdir(); + if (defined $incdir) { + $cross_flag = "-I$incdir"; + } else { + warning("cross Config.pm does not exist (missing build dependency on perl-xs-dev?)"); + } + } + if ($ENV{LDFLAGS} && ! compat(8)) { + my $ld = $Config{ld}; + $ld = qx/perl $cross_flag -MConfig -e 'print \$Config{ld}'/ + if is_cross_compiling() and defined $cross_flag; + push @flags, "LD=$ld $ENV{CFLAGS} $ENV{LDFLAGS}"; + } + + push(@perl_flags, '-I.') if compat(10); + + push @perl_flags, $cross_flag + if is_cross_compiling() and defined $cross_flag; + + $this->doit_in_sourcedir($^X, @perl_flags, "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 test { + my $this=shift; + # Make tests verbose + $this->SUPER::test("TEST_VERBOSE=1", @_); +} + +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/lib/Debian/Debhelper/Buildsystem/python_distutils.pm b/lib/Debian/Debhelper/Buildsystem/python_distutils.pm new file mode 100644 index 0000000..e5fe7ed --- /dev/null +++ b/lib/Debian/Debhelper/Buildsystem/python_distutils.pm @@ -0,0 +1,214 @@ +# 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 warnings; +use Cwd (); +use Debian::Debhelper::Dh_Lib qw(error deprecated_functionality); +use parent qw(Debian::Debhelper::Buildsystem); + +sub DESCRIPTION { + "Python Distutils (setup.py) [DEPRECATED]" +} + +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; + + deprecated_functionality('Please use the third-party "pybuild" build system instead of python-distutils', + 12); + + 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 (my $fd, '<', 'debian/control') || + error("cannot read debian/control: $!\n"); + foreach my $builddeps (join('', <$fd>) =~ + /^Build-Depends[^:]*:.*\n(?:^[^\w\n].*\n)*/gmi) { + while ($builddeps =~ /(python[^, ]*-dbg)/g) { + push @dbg, $1; + } + } + + close($fd); + return @dbg; + +} + +sub setup_py { + my $this=shift; + my $act=shift; + + # We need 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/lib/Debian/Debhelper/Buildsystem/qmake.pm b/lib/Debian/Debhelper/Buildsystem/qmake.pm new file mode 100644 index 0000000..18b896d --- /dev/null +++ b/lib/Debian/Debhelper/Buildsystem/qmake.pm @@ -0,0 +1,103 @@ +# 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(dpkg_architecture_value error is_cross_compiling); +use parent qw(Debian::Debhelper::Buildsystem::makefile); + +my %OS_MKSPEC_MAPPING = ( + 'linux' => 'linux-g++', + 'kfreebsd' => 'gnukfreebsd-g++', + 'hurd' => 'hurd-g++', +); + +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'; + if (is_cross_compiling()) { + my $host_os = dpkg_architecture_value("DEB_HOST_ARCH_OS"); + + if (defined(my $spec = $OS_MKSPEC_MAPPING{$host_os})) { + push(@options, "-spec", $spec); + } else { + error("Cannot cross-compile: Missing entry for HOST OS ${host_os} for qmake's -spec option"); + } + } + + 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->mkdir_builddir(); + $this->doit_in_builddir($this->_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", @_); +} + +sub _qmake { + if (is_cross_compiling()) { + return dpkg_architecture_value("DEB_HOST_GNU_TYPE") . "-qmake"; + } + return 'qmake'; +} + +1 diff --git a/lib/Debian/Debhelper/Buildsystem/qmake_qt4.pm b/lib/Debian/Debhelper/Buildsystem/qmake_qt4.pm new file mode 100644 index 0000000..60d9084 --- /dev/null +++ b/lib/Debian/Debhelper/Buildsystem/qmake_qt4.pm @@ -0,0 +1,15 @@ +package Debian::Debhelper::Buildsystem::qmake_qt4; + +use strict; +use warnings; +use parent qw(Debian::Debhelper::Buildsystem::qmake); + +sub DESCRIPTION { + "qmake for QT 4 (*.pro)"; +} + +sub _qmake { + return 'qmake-qt4'; +} + +1 |