diff options
27 files changed, 3081 insertions, 248 deletions
diff --git a/Debian/Debhelper/Buildsystem.pm b/Debian/Debhelper/Buildsystem.pm new file mode 100644 index 00000000..3ee37a5f --- /dev/null +++ b/Debian/Debhelper/Buildsystem.pm @@ -0,0 +1,377 @@ +# Defines debhelper build system class interface and implementation +# of common functionality. +# +# Copyright: © 2008-2009 Modestas Vainius +# License: GPL-2+ + +package Debian::Debhelper::Buildsystem; + +use strict; +use warnings; +use Cwd (); +use File::Spec; +use Debian::Debhelper::Dh_Lib; + +# Cache DEB_BUILD_GNU_TYPE value. Performance hit of multiple +# invocations is noticable when listing build systems. +our $DEB_BUILD_GNU_TYPE = dpkg_architecture_value("DEB_BUILD_GNU_TYPE"); + +# Build system name. Defaults to the last component of the class +# name. Do not override this method unless you know what you are +# doing. +sub NAME { + my $this=shift; + my $class = ref($this) || $this; + if ($class =~ m/^.+::([^:]+)$/) { + return $1; + } + else { + error("ınvalid build system class name: $class"); + } +} + +# Description of the build system to be shown to the users. +sub DESCRIPTION { + error("class lacking a DESCRIPTION"); +} + +# Default build directory. Can be overriden in the derived +# class if really needed. +sub DEFAULT_BUILD_DIRECTORY { + "obj-" . $DEB_BUILD_GNU_TYPE; +} + +# Constructs a new build system object. Named parameters: +# - sourcedir- specifies source directory (relative to the current (top) +# directory) where the sources to be built live. If not +# specified or empty, defaults to the current directory. +# - builddir - specifies build directory to use. Path is relative to the +# current (top) directory. If undef or empty, +# DEFAULT_BUILD_DIRECTORY directory will be used. +# Derived class can override the constructor to initialize common object +# parameters. Do NOT use constructor to execute commands or otherwise +# configure/setup build environment. There is absolutely no guarantee the +# constructed object will be used to build something. Use pre_building_step(), +# $build_step() or post_building_step() methods for this. +sub new { + my ($class, %opts)=@_; + + my $this = bless({ sourcedir => '.', + builddir => undef, }, $class); + + if (exists $opts{sourcedir}) { + # Get relative sourcedir abs_path (without symlinks) + my $curdir = Cwd::getcwd(); + my $abspath = Cwd::abs_path($opts{sourcedir}); + if (! -d $abspath || $abspath !~ /^\Q$curdir\E/) { + error("invalid or non-existing path to the source directory: ".$opts{sourcedir}); + } + $this->{sourcedir} = File::Spec->abs2rel($abspath, $curdir); + } + if (exists $opts{builddir}) { + $this->_set_builddir($opts{builddir}); + } + return $this; +} + +# Private method to set a build directory. If undef, use default. +# Do $this->{builddir} = undef or pass $this->get_sourcedir() to +# unset the build directory. +sub _set_builddir { + my $this=shift; + my $builddir=shift; + $this->{builddir} = ($builddir) ? $builddir : $this->DEFAULT_BUILD_DIRECTORY; + + # Canonicalize. If build directory ends up the same as source directory, drop it + if (defined $this->{builddir}) { + $this->{builddir} = $this->_canonpath($this->{builddir}); + if ($this->{builddir} eq $this->get_sourcedir()) { + $this->{builddir} = undef; + } + } +} + +# This instance method is called to check if the build system is capable +# to auto build a source package. Additional argument $step describes +# which operation the caller is going to perform (either configure, +# build, test, install or clean). You must override this method for the +# build system module to be ever picked up automatically. This method is +# used in conjuction with @Dh_Buildsystems::BUILDSYSTEMS. +# +# This method is supposed to be called with source root directory being +# working directory. Use $this->get_buildpath($path) method to get full +# path to the files in the build directory. +sub check_auto_buildable { + my $this=shift; + my ($step) = @_; + return 0; +} + +# Derived class can call this method in its constructor +# to enforce in source building even if the user requested otherwise. +sub enforce_in_source_building { + my $this=shift; + if ($this->get_builddir()) { + $this->{warn_insource} = 1; + $this->{builddir} = undef; + } +} + +# Derived class can call this method in its constructor to enforce +# out of source building even if the user didn't request it. However, +# if 'builddir' named parameter is passed, accept its value as the +# build directory even if it matches the source directory (meaning out +# of source is only prefered to in source, not enforced). +sub enforce_out_of_source_building { + my $this=shift; + my %args=@_; + if (!defined $this->get_builddir()) { + $this->_set_builddir($args{builddir}); + if (!defined $this->get_builddir() && !$args{builddir}) { + # If we are here, DEFAULT_BUILD_DIRECTORY matches + # the source directory, building might fail. + error("default build directory is the same as the source directory." . + " Please specify a custom build directory"); + } + } +} + +# Enhanced version of File::Spec::canonpath. It collapses .. +# too so it may return invalid path if symlinks are involved. +# On the other hand, it does not need for the path to exist. +sub _canonpath { + my ($this, $path)=@_; + my @canon; + my $back=0; + for my $comp (split(m%/+%, $path)) { + if ($comp eq '.') { + next; + } + elsif ($comp eq '..') { + if (@canon > 0) { pop @canon; } else { $back++; } + } + else { + push @canon, $comp; + } + } + return (@canon + $back > 0) ? join('/', ('..')x$back, @canon) : '.'; +} + +# Given both $path and $base are relative to the same directory, +# converts and returns path of $path being relative the $base. +sub _rel2rel { + my ($this, $path, $base, $root)=@_; + $root = "/tmp" if !defined $root; + + return File::Spec->abs2rel( + File::Spec->rel2abs($path, $root), + File::Spec->rel2abs($base, $root) + ); +} + +# Get path to the source directory +# (relative to the current (top) directory) +sub get_sourcedir { + my $this=shift; + return $this->{sourcedir}; +} + +# Convert path relative to the source directory to the path relative +# to the current (top) directory. +sub get_sourcepath { + my ($this, $path)=@_; + return File::Spec->catfile($this->get_sourcedir(), $path); +} + +# Get path to the build directory if it was specified +# (relative to the current (top) directory). undef if the same +# as the source directory. +sub get_builddir { + my $this=shift; + return $this->{builddir}; +} + +# Convert path that is relative to the build directory to the path +# that is relative to the current (top) directory. +# If $path is not specified, always returns build directory path +# relative to the current (top) directory regardless if builddir was +# specified or not. +sub get_buildpath { + my ($this, $path)=@_; + my $builddir = $this->get_builddir() || $this->get_sourcedir(); + if (defined $path) { + return File::Spec->catfile($builddir, $path); + } + return $builddir; +} + +# When given a relative path to the source directory, converts it +# to the path that is relative to the build directory. If $path is +# not given, returns a path to the source directory that is relative +# to the build directory. +sub get_source_rel2builddir { + my $this=shift; + my $path=shift; + + my $dir = '.'; + if ($this->get_builddir()) { + $dir = $this->_rel2rel($this->get_sourcedir(), $this->get_builddir()); + } + if (defined $path) { + return File::Spec->catfile($dir, $path); + } + return $dir; +} + +# When given a relative path to the build directory, converts it +# to the path that is relative to the source directory. If $path is +# not given, returns a path to the build directory that is relative +# to the source directory. +sub get_build_rel2sourcedir { + my $this=shift; + my $path=shift; + + my $dir = '.'; + if ($this->get_builddir()) { + $dir = $this->_rel2rel($this->get_builddir(), $this->get_sourcedir()); + } + if (defined $path) { + return File::Spec->catfile($dir, $path); + } + return $dir; +} + +# Creates a build directory. +sub mkdir_builddir { + my $this=shift; + if ($this->get_builddir()) { + doit("mkdir", "-p", $this->get_builddir()); + } +} + +sub _cd { + my ($this, $dir)=@_; + if (! $dh{NO_ACT}) { + verbose_print("cd $dir"); + chdir $dir or error("error: unable to chdir to $dir"); + } +} + +# Changes working directory to the source directory (if needed) +# calls doit(@_) and changes working directory back to the top +# directory. +sub doit_in_sourcedir { + my $this=shift; + if ($this->get_sourcedir() ne '.') { + my $sourcedir = $this->get_sourcedir(); + my $curdir = Cwd::getcwd(); + $this->_cd($sourcedir); + doit(@_); + $this->_cd($this->_rel2rel($curdir, $sourcedir, $curdir)); + } + else { + doit(@_); + } + return 1; +} + +# Changes working directory to the build directory (if needed), +# calls doit(@_) and changes working directory back to the top +# directory. +sub doit_in_builddir { + my $this=shift; + if ($this->get_buildpath() ne '.') { + my $buildpath = $this->get_buildpath(); + my $curdir = Cwd::getcwd(); + $this->_cd($buildpath); + doit(@_); + $this->_cd($this->_rel2rel($curdir, $buildpath, $curdir)); + } + else { + doit(@_); + } + return 1; +} + +# In case of out of source tree building, whole build directory +# gets wiped (if it exists) and 1 is returned. If build directory +# had 2 or more levels, empty parent directories are also deleted. +# If build directory does not exist, nothing is done and 0 is returned. +sub rmdir_builddir { + my $this=shift; + my $only_empty=shift; + if ($this->get_builddir()) { + my $buildpath = $this->get_buildpath(); + if (-d $buildpath && ! $dh{NO_ACT}) { + my @spdir = File::Spec->splitdir($this->get_build_rel2sourcedir()); + my $peek; + if (!$only_empty) { + doit("rm", "-rf", $buildpath); + pop @spdir; + } + # If build directory had 2 or more levels, delete empty + # parent directories until the source directory level. + while (($peek=pop(@spdir)) && $peek ne '.' && $peek ne '..') { + last if ! rmdir($this->get_sourcepath(File::Spec->catdir(@spdir, $peek))); + } + } + return 1; + } + return 0; +} + +# Instance method that is called before performing any step (see below). +# Action name is passed as an argument. Derived classes overriding this +# method should also call SUPER implementation of it. +sub pre_building_step { + my $this=shift; + my ($step)=@_; + + # Warn if in source building was enforced but build directory was + # specified. See enforce_in_source_building(). + if ($this->{warn_insource}) { + warning("warning: " . $this->NAME() . + " does not support building out of source tree. In source building enforced."); + delete $this->{warn_insource}; + } +} + +# Instance method that is called after performing any step (see below). +# Action name is passed as an argument. Derived classes overriding this +# method should also call SUPER implementation of it. +sub post_building_step { + my $this=shift; + my ($step)=@_; +} + +# The instance methods below provide support for configuring, +# building, testing, install and cleaning source packages. +# In case of failure, the method may just error() out. +# +# These methods should be overriden by derived classes to +# implement build system specific steps needed to build the +# source. Arbitary number of custom step arguments might be +# passed. Default implementations do nothing. +sub configure { + my $this=shift; +} + +sub build { + my $this=shift; +} + +sub test { + my $this=shift; +} + +# destdir parameter specifies where to install files. +sub install { + my $this=shift; + my $destdir=shift; +} + +sub clean { + my $this=shift; +} + +1; diff --git a/Debian/Debhelper/Buildsystem/autoconf.pm b/Debian/Debhelper/Buildsystem/autoconf.pm new file mode 100644 index 00000000..9121a1d7 --- /dev/null +++ b/Debian/Debhelper/Buildsystem/autoconf.pm @@ -0,0 +1,187 @@ +# 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; + +=head1 NAME + +B<autoconf> - GNU Autoconf (configure) + +=head1 SYNOPSIS + +B<dh_auto_*> [B<--buildsystem>=I<autoconf>] ... + +=head1 DESCRIPTION + +GNU Autoconf is a popular cross-platform build system. Autoconf F<configure> +script prepares the source for building and generates necessary F<Makefile>s +and other temporary files in the build directory. Then a standard set of +make targets needs to be executed in the build directory to complete source +build process. GNU Autoconf build system can be typically identified by +presence of the F<configure> script in the source directory. + +=head1 DH_AUTO NOTES + +Both in source (default) and out of source tree building modes are supported. +However, please note that some original source packages might not be compatible +with out of source tree building mode of Autoconf and hence build process may +fail later even if the I<configure> step succeeds. + +=head1 BUILD PROCESS + +=cut + +use strict; +use Debian::Debhelper::Dh_Lib qw(dpkg_architecture_value sourcepackage); +use base 'Debian::Debhelper::Buildsystem::makefile'; + +sub DESCRIPTION { + "GNU Autoconf (configure)" +} + +sub check_auto_buildable { + my $this=shift; + my ($step)=@_; + + # Handle configure; the rest - next class + if ($step eq "configure") { + return -x $this->get_sourcepath("configure"); + } + return 0; +} + +=head2 Configure step + +=over 4 + +=item I<Behaviour> + +Execute F<configure> from the source directory with working directory set to +the build directory. A set of standard arguments are passed to the F<configure> +script: + + --build=`dpkg_architecture -qDEB_BUILD_GNU_TYPE` + --prefix=/usr + --includedir=${prefix}/include + --mandir=${prefix}/share/man + --infodir=${prefix}/share/info + --sysconfdir=/etc + --localstatedir=/var + --libexecdir=${prefix}/lib/$name_of_debian_source_package + --disable-maintainer-mode + --disable-dependency-tracking + --host=`dpkg_architecture -qDEB_HOST_GNU_TYPE` (if different from --build) + +=item I<Auto-selection> + +If executable file F<configure> exists in the source directory. + +=back + +=cut +sub configure { + my $this=shift; + + # Standard set of options for configure. + my @opts; + push @opts, "--build=" . dpkg_architecture_value("DEB_BUILD_GNU_TYPE"); + push @opts, "--prefix=/usr"; + push @opts, "--includedir=\${prefix}/include"; + push @opts, "--mandir=\${prefix}/share/man"; + push @opts, "--infodir=\${prefix}/share/info"; + push @opts, "--sysconfdir=/etc"; + push @opts, "--localstatedir=/var"; + push @opts, "--libexecdir=\${prefix}/lib/" . sourcepackage(); + push @opts, "--disable-maintainer-mode"; + push @opts, "--disable-dependency-tracking"; + # Provide --host only if different from --build, as recommended in + # autotools-dev README.Debian: When provided (even if equal) + # autoconf 2.52+ switches to cross-compiling mode. + if (dpkg_architecture_value("DEB_BUILD_GNU_TYPE") + ne dpkg_architecture_value("DEB_HOST_GNU_TYPE")) { + push @opts, "--host=" . dpkg_architecture_value("DEB_HOST_GNU_TYPE"); + } + + $this->mkdir_builddir(); + $this->doit_in_builddir($this->get_source_rel2builddir("configure"), @opts, @_); +} + +=head2 Build step + +=over 4 + +=item I<Behaviour> + +Execute C<make> in the build directory. See I<makefile> build system +documentation for more information. + +=item I<Auto-selection> + +It is normal for the I<makefile> build system to be auto-selected at this step. + +=back + +=head2 Test step + +=over 4 + +=item I<Behaviour> + +Execute either C<make test> or C<make check> in the build directory. See +I<makefile> build system documentation for more information. + +=item I<Auto-selection> + +It is normal for the I<makefile> build system to be auto-selected at this step. + +=back + +=head2 Install step + +=over 4 + +=item I<Behaviour> + +Execute C<make install DESTDIR=$destdir> in the build directory with $destdir +set to the appropriate temporary installation directory. See I<makefile> build +system documentation for more information. + +=item I<Auto-selection> + +It is normal for the I<makefile> build system to be auto-selected at this step. + +=back + +=head2 Clean step + +=over 4 + +=item I<Behaviour> + +Remove the build directory if building out of source tree or execute C<make +distclean> if building in source. See I<makefile> build system documentation +for more information. + +=item I<Auto-selection> + +It is normal for the I<makefile> build system to be auto-selected at this step. + +=back + +=head1 SEE ALSO + +L<dh_auto_makefile(7)> + +L<dh_auto(7)> + +=head1 AUTHORS + + Joey Hess <joeyh@debian.org> + Modestas Vainius <modestas@vainius.eu> + +=cut + +1; diff --git a/Debian/Debhelper/Buildsystem/cmake.pm b/Debian/Debhelper/Buildsystem/cmake.pm new file mode 100644 index 00000000..0275bfb8 --- /dev/null +++ b/Debian/Debhelper/Buildsystem/cmake.pm @@ -0,0 +1,170 @@ +# 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; + +=head1 NAME + +B<cmake> - CMake (CMakeLists.txt) + +=head1 SYNOPSIS + +B<dh_auto_*> [B<--buildsystem>=I<cmake>] ... + +=head1 DESCRIPTION + +CMake is a family of tools designed to build, test and package software. CMake +generates F<Makefile>s and other temporary files in the build directory from +the directives present in the F<CMakeLists.txt> and a couple of other build +system source files. Then a standard set of make targets needs to be executed +in the build directory to complete source building process. CMake is available +in the cmake package that is essential throughout the whole build process. + +=head1 DH_AUTO NOTES + +Out of source tree building is done by default if this debhelper build system +is selected. This is due to the fact that there is no way to properly clean up +build directory from temporary files unless it is removed completely. +Therefore I<clean> step cannot be fully implemented if building is done in +source. However, the user may still enable in source building by explicitly +specifying a build directory path that is equal to the source directory path. + +=head1 BUILD PROCESS + +=cut + +use strict; +use base 'Debian::Debhelper::Buildsystem::makefile'; + +sub DESCRIPTION { + "CMake (CMakeLists.txt)" +} + +sub check_auto_buildable { + my $this=shift; + my ($step)=@_; + my $ret = -e $this->get_sourcepath("CMakeLists.txt"); + $ret &&= $this->SUPER::check_auto_buildable(@_) if $step ne "configure"; + return $ret; +} + +sub new { + my $class=shift; + my $this=$class->SUPER::new(@_); + # Prefer out of source tree building. + $this->enforce_out_of_source_building(@_); + return $this; +} + +=head2 Configure step + +=over 4 + +=item I<Behaviour> + +Execute C<cmake> in the build directory passing a path to the source directory +and defining the following flags: + + -DCMAKE_INSTALL_PREFIX=/usr + -DCMAKE_SKIP_RPATH=ON + -DCMAKE_VERBOSE_MAKEFILE=ON + +=item I<Auto-selection> + +If F<CMakeLists.txt> file exists but neither F<configure>, F<Makefile.PL>, +F<setup.py> or F<Build.PL> exist in the source directory. + +=back + +=cut +sub configure { + my $this=shift; + my @flags; + + # Standard set of cmake flags + push @flags, "-DCMAKE_INSTALL_PREFIX=/usr"; + push @flags, "-DCMAKE_SKIP_RPATH=ON"; + push @flags, "-DCMAKE_VERBOSE_MAKEFILE=ON"; + + $this->mkdir_builddir(); + $this->doit_in_builddir("cmake", $this->get_source_rel2builddir(), @flags); +} + +=head2 Build step + +=over 4 + +=item I<Behaviour> + +Execute C<make> in the build directory. See I<makefile> build system documentation +for more information. + +=item I<Auto-selection> + +It is normal for the I<makefile> build system to be auto-selected at this step. + +=back + +=head2 Test step + +=over 4 + +=item I<Behaviour> + +Execute C<make test> in the build directory. See I<makefile> build system +documentation for more information. + +=item I<Auto-selection> + +It is normal for the I<makefile> build system to be auto-selected at this step. + +=back + +=head2 Install step + +=over 4 + +=item I<Behaviour> + +Execute C<make install DESTDIR=$destdir> in the build directory with $destdir +set to the appropriate temporary installation directory. See I<makefile> build +system documentation for more information. + +=item I<Auto-selection> + +It is normal for the I<makefile> build system to be auto-selected at this step. + +=back + +=head2 Clean step + +=over 4 + +=item I<Behaviour> + +Remove the build directory if building out of source tree (complete clean up) +or execute C<make clean> if building in source (incomplete clean up). See +I<makefile> build system documentation for more information. + +=item I<Auto-selection> + +It is normal for the I<makefile> build system to be auto-selected at this step. + +=back + +=head1 SEE ALSO + +L<dh_auto_makefile(7)> + +L<dh_auto(7)> + +=head1 AUTHORS + + Modestas Vainius <modestas@vainius.eu> + +=cut + +1; diff --git a/Debian/Debhelper/Buildsystem/makefile.pm b/Debian/Debhelper/Buildsystem/makefile.pm new file mode 100644 index 00000000..32ad5178 --- /dev/null +++ b/Debian/Debhelper/Buildsystem/makefile.pm @@ -0,0 +1,226 @@ +# 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; + +=head1 NAME + +B<makefile> - make (Makefile) + +=head1 SYNOPSIS + +B<dh_auto_*> [B<--buildsystem>=I<makefile>] ... + +=head1 DESCRIPTION + +Makefile based projects use C<make> to control build process. C<make> utility +is the most popular tool on *NIX for building & installing packages from +source. It is also a basis for most other popular build systems. For example, +GNU Autoconf (autoconf) or CMake (cmake) generate F<Makefile>s during I<configure> +step and leave the rest of build process for C<make> to handle. + +=head1 DH_AUTO NOTES + +Since C<make> itself does not strictly define standard target names, a couple +of the most popular targets are tried for each building step. Whichever first +of them is discovered to exist, it is run. If neither of the tried targets +exist in the actual, the building step is assumed to have completed +successfully. However, if executed C<make> target fails, the respective dh_auto +program will fail too. + +If MAKE environment variable is set, its value is executed rather than default +C<make> command. + +Both in source (default) and out of source tree building modes are supported. +Either F<Makefile>, F<makefile> or F<GNUmakefile> file should be present in the +build directory for this debhelper build system to work. + +=head1 BUILD PROCESS + +=head2 Configure step + +=over 4 + +=item I<Behaviour> + +Do nothing (auto-selection continues). + +=item I<Auto-selection> + +It will never be auto-selected at this step. + +=back + +=cut + +use strict; +use Debian::Debhelper::Dh_Lib qw(escape_shell); +use base 'Debian::Debhelper::Buildsystem'; + +sub get_makecmd_C { + my $this=shift; + my $buildpath = $this->get_buildpath(); + if ($buildpath ne '.') { + return $this->{makecmd} . " -C " . escape_shell($buildpath); + } + return $this->{makecmd}; +} + +sub exists_make_target { + my ($this, $target) = @_; + my $makecmd=$this->get_makecmd_C(); + + # Use make -n to check to see if the target would do + # anything. There's no good way to test if a target exists. + my $ret=`$makecmd -s -n --no-print-directory $target 2>/dev/null`; + chomp $ret; + return length($ret); +} + +sub make_first_existing_target { + my $this=shift; + my $targets=shift; + + foreach my $target (@$targets) { + if ($this->exists_make_target($target)) { + $this->doit_in_builddir($this->{makecmd}, $target, @_); + return $target; + } + } + return undef; +} + +sub DESCRIPTION { + "simple Makefile" +} + +sub new { + my $class=shift; + my $this=$class->SUPER::new(@_); + $this->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make"; + return $this; +} + +sub check_auto_buildable { + my $this=shift; + my ($step) = @_; + + # Handles build, test, install, clean; configure - next class + if (grep /^\Q$step\E$/, qw{build test install clean}) { + # This is always called in the source directory, but generally + # Makefiles are created (or live) in the the build directory. + return -e $this->get_buildpath("Makefile") || + -e $this->get_buildpath("makefile") || + -e $this->get_buildpath("GNUmakefile"); + } + return 0; +} + +=head2 Build step + +=over 4 + +=item I<Behaviour> + +Execute C<make> (without arguments) with working directory changed to the build +directory. + +=item I<Auto-selection> + +If either F<Makefile>, F<makefile> or F<GNUmakefile> exists in the build +directory, but F<Makefile.PL> does not exist in the source directory. + +=back + +=cut +sub build { + my $this=shift; + $this->doit_in_builddir($this->{makecmd}, @_); +} + +=head2 Test step + +=over 4 + +=item I<Behaviour> + +Try to C<make> either I<test> or I<check> target (the first existing one) with +working directory changed to the build directory. + +=item I<Auto-selection> + +If either F<Makefile>, F<makefile> or F<GNUmakefile> exists in the build +directory, but F<Makefile.PL> does not exist in the source directory. + +=back + +=cut +sub test { + my $this=shift; + $this->make_first_existing_target(['test', 'check'], @_); +} + +=head2 Install step + +=over 4 + +=item I<Behaviour> + +Try to run C<make install DESTDIR=$destdir> with working directory changed to +the build directory. $desdir is the path to the appropriate temporary +installation directory under debian/ (see L<dh_auto_install(1)>). + +=item I<Auto-selection> + +If either F<Makefile>, F<makefile> or F<GNUmakefile> exists in the build +directory, but F<Makefile.PL> does not exist in the source directory. + +=back + +=cut +sub install { + my $this=shift; + my $destdir=shift; + $this->make_first_existing_target(['install'], "DESTDIR=$destdir", @_); +} + +=head2 Clean step + +=over 4 + +=item I<Behaviour> + +When building in source, try to C<make> either I<distclean>, I<realclean> or +I<clean> target (the first existing one) in the source directory. When building +out of source tree, recursively remove the whole build directory. + +=item I<Auto-selection> + +If either F<Makefile>, F<makefile> or F<GNUmakefile> exists in the build +directory, but F<Makefile.PL> does not exist in the source directory. + +=back + +=cut +sub clean { + my $this=shift; + if (!$this->rmdir_builddir()) { + $this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_); + } +} + +=head1 SEE ALSO + +L<dh_auto(7)> + +=head1 AUTHORS + + Joey Hess <joeyh@debian.org> + Modestas Vainius <modestas@vainius.eu> + +=cut + +1; diff --git a/Debian/Debhelper/Buildsystem/perl_build.pm b/Debian/Debhelper/Buildsystem/perl_build.pm new file mode 100644 index 00000000..26210152 --- /dev/null +++ b/Debian/Debhelper/Buildsystem/perl_build.pm @@ -0,0 +1,190 @@ +# 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; + +=head1 NAME + +B<perl_build> - Perl Module::Build (Build.PL) + +=head1 SYNOPSIS + +B<dh_auto_*> [B<--buildsystem>=I<perl_build>] ... + +=head1 DESCRIPTION + +Module::Build is a system for building, testing, and installing Perl modules. +It does not require a C<make> on your system - most of the Module::Build code is +pure-perl and written in a very cross-platform way. Its only prerequisites are +modules that are included with perl 5.6.0. Typically, Module::Build build system +can be identified by presence of the F<Build.PL> script in the source +directory. + +=head1 DH_AUTO NOTES + +Out of source tree building is not supported. C<MODULEBUILDRC=/dev/null> +environment variable is exported in each building step. + +=head1 BUILD PROCESS + +=cut + +use strict; +use base 'Debian::Debhelper::Buildsystem'; + +sub DESCRIPTION { + "Perl Module::Build (Build.PL)" +} + +sub check_auto_buildable { + my ($this, $step) = @_; + + # Handles everything + my $ret = -e $this->get_sourcepath("Build.PL"); + if ($step ne "configure") { + $ret &&= -e $this->get_sourcepath("Build"); + } + return $ret; +} + +sub do_perl { + my $this=shift; + $ENV{MODULEBUILDRC} = "/dev/null"; + $this->doit_in_sourcedir("perl", @_); +} + +sub new { + my $class=shift; + my $this= $class->SUPER::new(@_); + $this->enforce_in_source_building(); + return $this; +} + +=head2 Configure step + +=over 4 + +=item I<Behaviour> + +Execute C<perl Build.PL> passing C<installdirs=vendor> parameter by default. +Environment variable C<PERL_MM_USE_DEFAULT> is set before running the script. + +=item I<Auto-selection> + +If F<configure>, F<Makefile.PL>, F<setup.py> do not exist, but F<Build.PL> +exists in the source directory. + +=back + +=cut +sub configure { + my $this=shift; + $ENV{PERL_MM_USE_DEFAULT}=1; + $this->do_perl("Build.PL", "installdirs=vendor", @_); +} + +=head2 Build step + +=over 4 + +=item I<Behaviour> + +Execute C<perl Build>. + +=item I<Auto-selection> + +If F<Makefile>, F<makefile>, F<GNUmakefile> (build directory) and F<setup.py> +(source directory) do not exist, but F<Build.PL> and F<Build> files exist in +the source directory. + +=back + +=cut +sub build { + my $this=shift; + $this->do_perl("Build", @_); +} + +=head2 Test step + +=over 4 + +=item I<Behaviour> + +Execute C<perl Build test>. + +=item I<Auto-selection> + +If F<Makefile>, F<makefile>, F<GNUmakefile> (build directory) and F<setup.py> +(source directory) do not exist, but F<Build.PL> and F<Build> files exist in +the source directory. + +=back + +=cut +sub test { + my $this=shift; + $this->do_perl("Build", "test", @_); +} + +=head2 Install step + +=over 4 + +=item I<Behaviour> + +Execute C<perl Build install destdir=$destdir create_packlist=0>. $destdir is +the path to the temporary installation directory (see L<dh_auto_install(1)>). + +=item I<Auto-selection> + +If F<Makefile>, F<makefile>, F<GNUmakefile> (build directory) and F<setup.py> +(source directory) do not exist, but F<Build.PL> and F<Build> files exist in +the source directory. + +=back + +=cut +sub install { + my $this=shift; + my $destdir=shift; + $this->do_perl("Build", "install", "destdir=$destdir", "create_packlist=0", @_); +} + +=head2 Clean step + +=over 4 + +=item I<Behaviour> + +Execute C<perl Build --allow_mb_mismatch 1 distclean>. + +=item I<Auto-selection> + +If F<Makefile>, F<makefile>, F<GNUmakefile> (build directory) and F<setup.py> +(source directory) do not exist, but F<Build.PL> and F<Build> files exist in +the source directory. + +=back + +=cut +sub clean { + my $this=shift; + $this->do_perl("Build", "--allow_mb_mismatch", 1, "distclean", @_); +} + +=head1 SEE ALSO + +L<dh_auto(7)> + +=head1 AUTHORS + + Joey Hess <joeyh@debian.org> + Modestas Vainius <modestas@vainius.eu> + +=cut + +1; diff --git a/Debian/Debhelper/Buildsystem/perl_makemaker.pm b/Debian/Debhelper/Buildsystem/perl_makemaker.pm new file mode 100644 index 00000000..102e23f5 --- /dev/null +++ b/Debian/Debhelper/Buildsystem/perl_makemaker.pm @@ -0,0 +1,182 @@ +# 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; + +=head1 NAME + +B<perl_makemaker> - Perl ExtUtils::MakeMaker (Makefile.PL) + +=head1 SYNOPSIS + +B<dh_auto_*> [B<--buildsystem>=I<perl_makemaker>] ... + +=head1 DESCRIPTION + +Perl ExtUtils::MakeMaker utility is designed to write a Makefile for an +extension module from a Makefile.PL (at configure step). The rest of build +process is handled by C<make>. Typically, ExtUtils::MakeMaker build system can +be identified by presence of the F<Makefile.PL> script in the source directory. + +=head1 DH_AUTO NOTES + +Out of source tree building is not supported. + +=head1 BUILD PROCESS + +=cut + +use strict; +use base 'Debian::Debhelper::Buildsystem::makefile'; + +sub DESCRIPTION { + "Perl ExtUtils::MakeMaker (Makefile.PL)" +} + +sub check_auto_buildable { + my $this=shift; + my ($step)=@_; + + # Handles everything if Makefile.PL exists. Otherwise - next class. + if (-e $this->get_sourcepath("Makefile.PL")) { + if ($step eq "install" || $step eq "configure") { + return 1; + } + else { + # This is backwards compatible (with << 7.3) until build, test and + # clean steps are not reimplemented in the backwards compatibility + # breaking way. However, this is absolutely necessary for + # enforce_in_source_building() to work in corner cases in build, + # test and clean steps as the next class (makefile) does not + # enforce it. + return $this->SUPER::check_auto_buildable(@_); + } + } + return 0; +} + +sub new { + my $class=shift; + my $this=$class->SUPER::new(@_); + $this->enforce_in_source_building(); + return $this; +} + +=head2 Configure step + +=over + +=item I<Behaviour> + +Execute C<Makefile.PL> script passing C<INSTALLDIRS=vendor> and +C<create_packlist=0> parameters. Environment variables C<PERL_MM_USE_DEFAULT=1> +and C<PERL_AUTOINSTALL=--skipdeps> are exported before running the script. + +=item I<Auto-selection> + +If F<Makefile.PL> file exists but F<configure> does not exist in the source +directory. + +=back + +=cut +sub configure { + my $this=shift; + # If set to a true value then MakeMaker's prompt function will + # # always return the default without waiting for user input. + $ENV{PERL_MM_USE_DEFAULT}=1; + # This prevents Module::Install from interactive behavior. + $ENV{PERL_AUTOINSTALL}="--skipdeps"; + + $this->doit_in_sourcedir("perl", "Makefile.PL", "INSTALLDIRS=vendor", + "create_packlist=0", + @_); +} + +=head2 Build step + +=over 4 + +=item I<Behaviour> + +Execute C<make> in the build directory. See I<makefile> build system +documentation for more information. + +=item I<Auto-selection> + +Both F<Makefile.PL> and F<Makefile> exist in the source directory. + +=back + +=head2 Test step + +=over 4 + +=item I<Behaviour> + +Execute C<make test> in the source directory. See I<makefile> build system +documentation for more information. + +=item I<Auto-selection> + +Both F<Makefile.PL> and F<Makefile> exist in the source directory. + +=back + +=cut + +=head2 Install step + +=over 4 + +=item I<Behaviour> + +Execute C<make install DESTDIR=$destdir PREFIX=/usr> in the source directory +with $destdir set to the appropriate temporary installation directory. See +I<makefile> build system documentation for more information. + +=item I<Auto-selection> + +Both F<Makefile.PL> and F<Makefile> exist in the source directory. + +=back + +=cut +sub install { + my $this=shift; + my $destdir=shift; + $this->SUPER::install($destdir, "PREFIX=/usr", @_); +} + +=head2 Clean step + +=over 4 + +=item I<Behaviour> + +Execute C<make distclean> in the source directory. See I<makefile> build system +documentation for more information. + +=item I<Auto-selection> + +Both F<Makefile.PL> and F<Makefile> exist in the source directory. + +=back + +=head1 SEE ALSO + +L<dh_auto_makefile(7)> + +L<dh_auto(7)> + +=head1 AUTHORS + + Joey Hess <joeyh@debian.org> + Modestas Vainius <modestas@vainius.eu> + +=cut + +1; diff --git a/Debian/Debhelper/Buildsystem/python_distutils.pm b/Debian/Debhelper/Buildsystem/python_distutils.pm new file mode 100644 index 00000000..8266fa0b --- /dev/null +++ b/Debian/Debhelper/Buildsystem/python_distutils.pm @@ -0,0 +1,238 @@ +# 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; + +=head1 NAME + +B<python_distutils> - Python Distutils (setup.py) + +=head1 SYNOPSIS + +B<dh_auto_*> [B<--buildsystem>=I<python_distutils>] ... + +=head1 DESCRIPTION + +Python Distribution Utilities (Distutils for short) is a standard Python build +system. It is used to package most of the Python modules in the source +distribution form. Typically, only two steps (build and install) are needed to +finish installation of the Distutils based Python module. This build system can +be typically identified by presence of the F<setup.py> in the source directory. + +=head1 DH_AUTO NOTES + +Out of source tree building is done by default but in source building is also +supported. PLEASE NOTE that B<default build directory> is B<$srcdir/build> +where $srcdir is a path to the source directory. + +Due to design flaws of Distutils, it is not possible to set a B<custom> build +directory via command line arguments to F<setup.py>. Therefore, the same effect +is achieved by writing appropriate F<.pydistutils.cfg> file to the build +directory and pointing $HOME environment variable to the build directory. + +=head1 BUILD PROCESS + +=cut + +use strict; +use Cwd (); +use Debian::Debhelper::Dh_Lib qw(error); +use base 'Debian::Debhelper::Buildsystem'; + +sub DESCRIPTION { + "Python Distutils (setup.py)" +} + +sub DEFAULT_BUILD_DIRECTORY { + my $this=shift; + return $this->_canonpath($this->get_sourcepath("build")); +} + +sub new { + my $class=shift; + my $this=$class->SUPER::new(@_); + # Out of source tree building is prefered. + $this->enforce_out_of_source_building(@_); + return $this; +} + +sub check_auto_buildable { + my $this=shift; + return -e $this->get_sourcepath("setup.py"); +} + +sub not_our_cfg { + my $this=shift; + my $ret; + if (open(my $cfg, $this->get_buildpath(".pydistutils.cfg"))) { + $ret = not "# Created by dh_auto\n" eq <$cfg>; + close DISTUTILSCFG; + } + return $ret; +} + +sub create_cfg { + my $this=shift; + if (open(my $cfg, ">", $this->get_buildpath(".pydistutils.cfg"))) { + print $cfg "# Created by dh_auto", "\n"; + print $cfg "[build]\nbuild-base=", $this->get_build_rel2sourcedir(), "\n"; + close $cfg; + return 1; + } + return 0; +} + +sub pre_building_step { + my $this=shift; + my $step=shift; + + return unless grep /$step/, qw(build install clean); + + # --build-base can only be passed to the build command. However, + # it is always read from the config file (really weird design). + # Therefore create such a cfg config file. + if ($this->get_buildpath() ne $this->DEFAULT_BUILD_DIRECTORY()) { + not $this->not_our_cfg() or + error("cannot set custom build directory: .pydistutils.cfg is in use"); + $this->mkdir_builddir(); + $this->create_cfg() or + error("cannot set custom build directory: unwritable .pydistutils.cfg"); + # Distutils reads $HOME/.pydistutils.cfg + $ENV{HOME} = Cwd::abs_path($this->get_buildpath()); + } +} + +sub setup_py { + my $this=shift; + my $act=shift; + $this->doit_in_sourcedir("python", "setup.py", $act, @_); +} + +=head2 Configure step + +=over 4 + +=item I<Behaviour> + +Do nothing but stop auto-selection process. + +=item I<Auto-selection> + +If neither F<configure>, F<Makefile.PL> exist, but F<setup.py> exists in the +source directory. + +=back + +=cut + +=head2 Build step + +=over 4 + +=item I<Behaviour> + +Execute C<python setup.py build>. + +=item I<Auto-selection> + +If F<Makefile>, F<makefile> F<GNUmakefile> do not exist in the build directory +and F<setup.py> file exists in the source directory. + +=back + +=cut +sub build { + my $this=shift; + $this->setup_py("build", @_); +} + +=head2 Test step + +=over 4 + +=item I<Behaviour> + +Do nothing but stop auto-selection process. + +=item I<Auto-selection> + +F<Makefile>, F<makefile>, F<GNUmakefile> do not exist in the build directory and +F<setup.py> file exists in the source directory. + +=back + +=cut + +=head2 Install step + +=over 4 + +=item I<Behaviour> + +Execute C<python setup.py install> passing temporary installation directory via +C<--root> parameter. C<--no-compile> and C<-O0> parameters are also passed by +default. See L<dh_auto_install(1)> for more information. + +=item I<Auto-selection> + +F<Makefile>, F<makefile>, F<GNUmakefile> do not exist in the build directory and +F<setup.py> file exists in the source directory. + +=back + +=cut +sub install { + my $this=shift; + my $destdir=shift; + $this->setup_py("install", "--root=$destdir", "--no-compile", "-O0", @_); +} + +=head2 Clean step + +=over 4 + +=item I<Behaviour> + +Execute C<python setup.py clean -a>. Additional parameters (if specified) are +passed to the latter command. F<.pydistutils.cfg> is also removed if it was +created (together with the build directory if it is ends up empty). Finally, +recursively find and delete all *.pyc files from the source directory. + +=item I<Auto-selection> + +F<Makefile>, F<makefile>, F<GNUmakefile> do not exist in the build directory and +F<setup.py> file exists in the source directory. + +=back + +=cut +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', '{}', ';'); +} + +=head1 SEE ALSO + +L<dh_auto(7)> + +=head1 AUTHORS + + Joey Hess <joeyh@debian.org> + Modestas Vainius <modestas@vainius.eu> + +=cut + +1; diff --git a/Debian/Debhelper/Dh_Buildsystems.pm b/Debian/Debhelper/Dh_Buildsystems.pm new file mode 100644 index 00000000..df810208 --- /dev/null +++ b/Debian/Debhelper/Dh_Buildsystems.pm @@ -0,0 +1,231 @@ +# A module for loading and managing debhelper build system class. +# This module is intended to be used by all dh_auto_* programs. +# +# Copyright: © 2009 Modestas Vainius +# License: GPL-2+ + +package Debian::Debhelper::Dh_Buildsystems; + +use strict; +use warnings; +use Debian::Debhelper::Dh_Lib; +use File::Spec; + +use base 'Exporter'; +our @EXPORT=qw(&buildsystems_init &buildsystems_do &load_buildsystem &load_all_buildsystems); + +# Historical order must be kept for backwards compatibility. New +# build systems MUST be added to the END of the list. +our @BUILDSYSTEMS = ( + "autoconf", + "perl_makemaker", + "makefile", + "python_distutils", + "perl_build", + "cmake", +); + +my $opt_buildsys; +my $opt_sourcedir; +my $opt_builddir; +my $opt_list; +my $opt_help_buildsys; + +sub create_buildsystem_instance { + my $system=shift; + my %bsopts=@_; + my $module = "Debian::Debhelper::Buildsystem::$system"; + + eval "use $module"; + if ($@) { + error("unable to load build system class '$system': $@"); + } + + if (!exists $bsopts{builddir} && defined $opt_builddir) { + $bsopts{builddir} = ($opt_builddir eq "") ? undef : $opt_builddir; + } + if (!exists $bsopts{sourcedir} && defined $opt_sourcedir) { + $bsopts{sourcedir} = ($opt_sourcedir eq "") ? undef : $opt_sourcedir; + } + return $module->new(%bsopts); +} + +# Similar to create_build system_instance(), but it attempts to autoselect +# a build system if none was specified. In case autoselection fails, undef +# is returned. +sub load_buildsystem { + my $system=shift; + my $step=shift; + if (defined $system) { + my $inst = create_buildsystem_instance($system, @_); + return $inst; + } + else { + # Try to determine build system automatically + for $system (@BUILDSYSTEMS) { + my $inst = create_buildsystem_instance($system, @_); + if ($inst->check_auto_buildable($step)) { + return $inst; + } + } + } + return; +} + +sub load_all_buildsystems { + my $incs=shift || \@INC; + my (%buildsystems, @buildsystems); + + for my $inc (@$incs) { + my $path = File::Spec->catdir($inc, "Debian/Debhelper/Buildsystem"); + if (-d $path) { + for my $module_path (glob "$path/*.pm") { + my $name = basename($module_path); + $name =~ s/\.pm$//; + next if exists $buildsystems{$name}; + $buildsystems{$name} = create_buildsystem_instance($name, @_); + } + } + } + + # Push debhelper built-in build systems first + for my $name (@BUILDSYSTEMS) { + error("debhelper built-in build system '$name' could not be found/loaded") + if not exists $buildsystems{$name}; + push @buildsystems, $buildsystems{$name}; + delete $buildsystems{$name}; + } + + # The rest are 3rd party build systems + for my $name (keys %buildsystems) { + my $inst = $buildsystems{$name}; + $inst->{thirdparty} = 1; + push @buildsystems, $inst; + } + + return @buildsystems; +} + +sub buildsystems_init { + my %args=@_; + + # Available command line options + my %options = ( + "D=s" => \$opt_sourcedir, + "sourcedirectory=s" => \$opt_sourcedir, + + "B:s" => \$opt_builddir, + "builddirectory:s" => \$opt_builddir, + + "S=s" => \$opt_buildsys, + "buildsystem=s" => \$opt_buildsys, + + "l" => \$opt_list, + "list" => \$opt_list, + + "help-buildsystem" => \$opt_help_buildsys, + ); + $args{options}{$_} = $options{$_} foreach keys(%options); + Debian::Debhelper::Dh_Lib::init(%args); +} + +sub buildsystems_list { + my $step=shift; + + # List build systems (including auto and specified status) + my ($auto, $specified); + my @buildsystems = load_all_buildsystems(); + for my $inst (@buildsystems) { + my $is_specified = defined $opt_buildsys && $opt_buildsys eq $inst->NAME(); + if (! defined $specified && defined $opt_buildsys && $opt_buildsys eq $inst->NAME()) { + $specified = $inst->NAME(); + } + elsif (! defined $auto && ! $inst->{thirdparty} && $inst->check_auto_buildable($step)) { + $auto = $inst->NAME(); + } + printf("%s - %s", $inst->NAME(), $inst->DESCRIPTION()); + print " [3rd party]" if $inst->{thirdparty}; + print "\n"; + } + print "\n"; + print "Auto-selected: $auto\n" if defined $auto; + print "Specified: $specified\n" if defined $specified; + print "No system auto-selected or specified\n" + if ! defined $auto && ! defined $specified; +} + +sub help_buildsystem { + my $step=shift; + + # Print build system help page to standard output + + my $inst = load_buildsystem($opt_buildsys, $step); + if ($inst) { + my $pmfile = ref $inst; + $pmfile =~ s#::#/#g; + $pmfile = $INC{"$pmfile.pm"}; + + # Display help with perldoc if it is installed and output is + # a tty + my $perldoc; + if (-t STDOUT) { + eval "use Pod::Perldoc"; + $perldoc = "Pod::Perldoc" if (!$@); + } + if ($perldoc) { + $perldoc = new Pod::Perldoc(); + $perldoc->{args} = [ '-oman', + '-w', 'section=7" "--name=dh_auto_'.lc($inst->NAME()), + '-w', 'center=Dh_auto build system documentation', + '-w', 'release=', + '-F', $pmfile ]; + $perldoc->process(); + } + else { + # No perldoc on the system. Use Pod::Usage to emit simple text + eval "use Pod::Usage"; + pod2usage( -message => "Help page for the ".$inst->NAME()." build system\n" . + '<' . '-'x74 . '>', + -input => $pmfile, -exitval => 'NOEXIT', + -verbose => 2, -noperldoc => 1 ); + print '<', '-'x74, '>', "\n"; + } + return 0; + } + else { + print STDERR "No system auto-selected or specified. Try using --buildsystem option\n"; + return 1; + } +} + +sub buildsystems_do { + my $step=shift; + + if (!defined $step) { + $step = basename($0); + $step =~ s/^dh_auto_//; + } + + if (grep(/^\Q$step\E$/, qw{configure build test install clean}) == 0) { + error("unrecognized build step: " . $step); + } + + if ($opt_list) { + buildsystems_list($step); + exit 0; + } + + if ($opt_help_buildsys) { + exit help_buildsystem($step); + } + + my $buildsystem = load_buildsystem($opt_buildsys, $step); + if (defined $buildsystem) { + $buildsystem->pre_building_step($step); + $buildsystem->$step(@_, @{$dh{U_PARAMS}}); + $buildsystem->post_building_step($step); + } + return 0; +} + +1; diff --git a/Debian/Debhelper/Dh_Getopt.pm b/Debian/Debhelper/Dh_Getopt.pm index 864b168e..9ca9d167 100644 --- a/Debian/Debhelper/Dh_Getopt.pm +++ b/Debian/Debhelper/Dh_Getopt.pm @@ -143,6 +143,12 @@ sub getoptions { ) } +sub split_options_string { + my $str=shift; + $str=~s/^\s+//; + return split(/\s+/,$str); +} + # Parse options and set %dh values. sub parseopts { my $options=shift; @@ -152,10 +158,7 @@ sub parseopts { # DH_INTERNAL_OPTIONS is used to pass additional options from # dh through an override target to a command. if (defined $ENV{DH_INTERNAL_OPTIONS}) { - $ENV{DH_INTERNAL_OPTIONS}=~s/^\s+//; - $ENV{DH_INTERNAL_OPTIONS}=~s/\s+$//; - @ARGV_extra=split(/\s+/,$ENV{DH_INTERNAL_OPTIONS}); - + @ARGV_extra=split_options_string($ENV{DH_INTERNAL_OPTIONS}); # Unknown options will be silently ignored. my $oldwarn=$SIG{__WARN__}; $SIG{__WARN__}=sub {}; @@ -184,9 +187,7 @@ sub parseopts { # to be parsed like @ARGV, but with unknown options # skipped. if (defined $ENV{DH_OPTIONS}) { - $ENV{DH_OPTIONS}=~s/^\s+//; - $ENV{DH_OPTIONS}=~s/\s+$//; - @ARGV_extra=split(/\s+/,$ENV{DH_OPTIONS}); + @ARGV_extra=split_options_string($ENV{DH_OPTIONS}); my $ret=getoptions(\@ARGV_extra, $options); if (!$ret) { warning("warning: ignored unknown options in DH_OPTIONS"); diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm index f09c8087..28a90f7b 100644 --- a/Debian/Debhelper/Dh_Lib.pm +++ b/Debian/Debhelper/Dh_Lib.pm @@ -15,7 +15,8 @@ use vars qw(@ISA @EXPORT %dh); &filedoublearray &getpackages &basename &dirname &xargs %dh &compat &addsubstvar &delsubstvar &excludefile &package_arch &is_udeb &udeb_filename &debhelper_script_subst &escape_shell - &inhibit_log &load_log &write_log); + &inhibit_log &load_log &write_log &dpkg_architecture_value + &sourcepackage); my $max_compat=7; @@ -605,15 +606,21 @@ sub excludefile { return 0; } +sub dpkg_architecture_value { + my $var = shift; + my $value=`dpkg-architecture -q$var 2>/dev/null` || error("dpkg-architecture failed"); + chomp $value; + return $value; +} + # Returns the build architecture. (Memoized) { my $arch; sub buildarch { - return $arch if defined $arch; - - $arch=`dpkg-architecture -qDEB_HOST_ARCH 2>/dev/null` || error("dpkg-architecture failed"); - chomp $arch; + if (!defined $arch) { + $arch=dpkg_architecture_value('DEB_HOST_ARCH'); + } return $arch; } } @@ -643,6 +650,23 @@ sub samearch { return 0; } +# Returns source package name +sub sourcepackage { + open (CONTROL, 'debian/control') || + error("cannot read debian/control: $!\n"); + while (<CONTROL>) { + chomp; + s/\s+$//; + if (/^Source:\s*(.*)/) { + close CONTROL; + return $1; + } + } + + close CONTROL; + error("could not find Source: line in control file."); +} + # Returns a list of packages in the control file. # Must pass "arch" or "indep" or "same" to specify arch-dependant or # -independant or same arch packages. If nothing is specified, returns all @@ -27,15 +27,28 @@ PERLLIBDIR=$(shell perl -MConfig -e 'print $$Config{vendorlib}')/Debian/Debhelpe POD2MAN=pod2man -c Debhelper -r "$(VERSION)" +DH_AUTO_POD=man/dh_auto_pod + # l10n to be built is determined from .po files LANGS=$(notdir $(basename $(wildcard man/po4a/po/*.po))) build: version - find . -maxdepth 1 -type f -perm +100 -name "dh*" \ + find . -maxdepth 1 -type f -perm +100 -name "dh*" -a ! -name "dh_auto*" \ -exec $(POD2MAN) {} {}.1 \; cat debhelper.pod | \ $(MAKEMANLIST) `find . -maxdepth 1 -type f -perm +100 -name "dh_*" | sort` | \ $(POD2MAN) --name="debhelper" --section=7 > debhelper.7 + # Generate dh_auto program PODs and manual pages + ./run find . -maxdepth 1 -type f -perm +100 -name "dh_auto_*" \ + -exec $(DH_AUTO_POD) {} -oman/{}.pod \; + cd man; for pod in dh_auto_*.pod; do $(POD2MAN) --section=1 $$pod "../$${pod%.pod}.1"; done + # Generate dh_auto POD and manual page + ./run $(DH_AUTO_POD) -oman/dh_auto.pod + $(POD2MAN) --section=7 man/dh_auto.pod dh_auto.7 + # Generate dh_auto build system manual pages + find Debian/Debhelper/Buildsystem -maxdepth 1 -type f -name "*.pm" \ + -exec sh -c 'n=`basename {}`;n=$${n%.pm}; $(POD2MAN) --section=7 --name dh_auto_$$n {} dh_auto_$$n.7' \; + # Translations po4a -L UTF-8 man/po4a/po4a.cfg set -e; \ for lang in $(LANGS); do \ @@ -54,7 +67,7 @@ version: Debian/Debhelper/Dh_Version.pm clean: - rm -f *.1 *.7 Debian/Debhelper/Dh_Version.pm + rm -f *.1 *.7 man/dh_auto*.pod Debian/Debhelper/Dh_Version.pm po4a --rm-translations --rm-backups man/po4a/po4a.cfg for lang in $(LANGS); do \ if [ -e man/$$lang ]; then rmdir man/$$lang; fi; \ @@ -63,13 +76,15 @@ clean: install: install -d $(DESTDIR)/usr/bin \ $(DESTDIR)/usr/share/debhelper/autoscripts \ - $(DESTDIR)$(PERLLIBDIR)/Sequence - install $(shell find -maxdepth 1 -mindepth 1 -name dh\* |grep -v \.1\$$) $(DESTDIR)/usr/bin + $(DESTDIR)$(PERLLIBDIR)/Sequence \ + $(DESTDIR)$(PERLLIBDIR)/Buildsystem + install $(shell find -maxdepth 1 -mindepth 1 -name dh\* -executable |grep -v \.1\$$) $(DESTDIR)/usr/bin install -m 0644 autoscripts/* $(DESTDIR)/usr/share/debhelper/autoscripts install -m 0644 Debian/Debhelper/*.pm $(DESTDIR)$(PERLLIBDIR) install -m 0644 Debian/Debhelper/Sequence/*.pm $(DESTDIR)$(PERLLIBDIR)/Sequence + install -m 0644 Debian/Debhelper/Buildsystem/*.pm $(DESTDIR)$(PERLLIBDIR)/Buildsystem test: version - ./run perl -MTest::Harness -e 'runtests grep { ! /CVS/ && ! /\.svn/ } @ARGV' t/* + ./run perl -MTest::Harness -e 'runtests grep { ! /CVS/ && ! /\.svn/ && -f && -x } @ARGV' t/* t/buildsystems/* # clean up log etc ./run dh_clean diff --git a/debian/changelog b/debian/changelog index 0e3b9428..615f95bb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,23 @@ +debhelper (7.3.0) UNRELEASED; urgency=low + + * Modular object oriented dh_auto_* buildsystem support, + contributed by Modestas Vainius + - dh_auto_* --sourcedirectory can now be used to specify a source + directory if sources and/or the whole buildsystem lives in other + but the top level directory. Closes: #530597 + - dh_auto_* --builddirectory can now be used to specify a build + directory to use for out of source building, for build systems + that support it. Closes: #480577 + - dh_auto_* --buildsystem can now be used to override the autodetected + build system, or force use of a third-party class. + - dh_auto_* --list can be used to list available and selected build + systems. + - Adds support for cmake. + - Historical dh_auto_* behavior should be preserved despite these + large changes.. + + -- Joey Hess <joeyh@debian.org> Mon, 20 Apr 2009 16:26:08 -0400 + debhelper (7.2.17) unstable; urgency=low * Allow command-specific options to be passed to commands diff --git a/debian/copyright b/debian/copyright index 46e44921..ffb117c9 100644 --- a/debian/copyright +++ b/debian/copyright @@ -54,3 +54,7 @@ License: GPL-2+ Files: dh_bugfiles Copyright: Modestas Vainius <modestas@vainius.eu> License: GPL-2+ + +Files: Debian/Debhelper/Buildsystem*, Debian/Debhelper/Dh_Buildsystems.pm +Copyright: © 2008-2009 Modestas Vainius +License: GPL-2+ diff --git a/dh_auto.pod b/dh_auto.pod new file mode 100644 index 00000000..6eb244fb --- /dev/null +++ b/dh_auto.pod @@ -0,0 +1,228 @@ +=head1 NAME + +dh_auto - debhelper based package source building suite + +=head1 SYNOPTIS + +B<dh_auto_*> [B<--buildsystem=>I<buildsystem>] [B<--sourcedirectory=>I<srcdir>] [B<--builddirectory>[=I<builddir>]] + +B<dh_auto_*> B<--list> [B<-S>I<buildsystem>] [B<-D>I<srcdir>] [B<-B>[I<builddir>]] + +B<dh_auto_*> B<--help-buildsystem> [B<-S>I<buildsystem>] [B<-D>I<srcdir>] [B<-B>[I<builddir>]] + +=head1 DESCRIPTION + +dh_auto is a family of debhelper programs that are responsible for managing +build process of the package sources. dh_auto takes a burden of identifying and +configuring package build system with a standard set of options that a typical +Debian package needs. However, it is also flexible enough to allow +customization of the build process in various ways. Due to good defaults, it +should be able to handle 90% of packages even without any additional arguments +passed to the dh_auto programs. Therefore, dh_auto is one of the main driving +forces behind the L<dh(1)> command sequencer. Similarly, dh_auto programs can +be easily (either fully or partially) integrated into traditional Debian +packaging. + +One of the key dh_auto features is that it wraps around all common source build +systems and exposes their common features via well-defined command line +interface of the dh_auto programs. dh_auto is designed that each type of source +build system is handled by its corresponding I<debhelper build system> which +translates dh_auto options into the source build system specific details. +Therefore, dh_auto is capable to handle e.g. out of source tree building +transparently. + +The build process is split into 5 I<building steps>: configure, build, test, +install and clean. Each step is managed by the respective dh_auto_$step +program. Each program accepts a set of shared dh_auto options, step specific +options (if any) and arbitrary number of extra arguments which are additionally +passed to the underlying build system command being executed. Whatever is +executed under the hood depends on the selected debhelper build system, +building step (i.e. dh_auto program) and dh_auto options in effect. + +=head1 DH_AUTO PROGRAMS + +=over 2 + +#DH_AUTO LIST# + +=back + +=head1 FEATURES + +=over 2 + +=item I<Build system auto-selection> + +dh_auto examines package source and/or build directories at each building step +looking for typical indications of the source build systems it supports. If the +build system is recognized, its corresponding building step commands are +executed. If more than one debhelper build system indicates to match the source +build system, only the first one is selected. If the build system isn't +recognized, dh_auto program silently succeeds. dh_auto programs may fail only +if wrong debhelper build system gets selected and/or source build system +commands fail or cannot be executed. + +The auto-selection process implies that a different but compatible debhelper +build system may be auto-selected at each building step. For example, GNU +Autoconf is just a configure layer on top of the simple Makefile build system. + +=item I<Manual build system selection> + +In addition to the build system auto-selection, dh_auto offers a way for a user +to specify which debhelper build system to assume for the package. In such a +case, auto-selection is skipped entirely and no prior checks are made before +executing commands of the specified build system. Obviously, if a wrong build +system was specified and/or source build system commands failed or could not be +executed, the dh_auto program would fail too. + +Manual build system selection could be useful if package sources came with more +than one build system, auto-selection fails/gives wrong results due its +limitations or you want to use a third party debhelper build system (provided +by an external package (see below)). + +=item I<Source tree switching> + +Typically, the top directory of the package sources is where the debianization +directory (debian/) lives. However, sometimes the whole original source tree +might be somewhere in the subdirectory or a single Debian source package might +actually contain multiple original source packages with their contents being in +the separate subdirectories. dh_auto handles such cases by letting the user to +specify a path to the source directory. All dh_auto programs regardless of the +build system selected support source directory switching. + +=item I<Out of source tree building> + +Throughout the build process of the most packages, lots of temporary files are +generated by their source build systems. Since they are of no use when binary +packages are built, it is a task of L<dh_auto_clean(1)> to clean them up. If +temporary files are generated in the same directories where source files are, +it is referred as "in source building" in this documentation. However, some +build systems support the concept of "out of source tree" building when all +temporary files are generated in the arbitrary build directory avoiding +extensive pollution of the source tree. dh_auto allows to specify a path to the +build directory and then it will do out of source tree building in it if the +source build system supports this feature. + +In source building is a default mode and it is supported by most debhelper +build systems. However, some source build systems do not support in source +building or highly recommend out of source tree building. In this case, dh_auto +follows the recommendation and might default to the out of source tree building +even if the build directory was not explicitly specified. However, if the build +system does not support out of source tree building, it is an error to specify +the build directory. + +=item I<Third party debhelper build systems> + +It is very easy to write a third party debhelper build system class and ship it +in the external package. The only limitation is that support for it can only be +enabled manually (via "Manual build system selection"). Their auto-selection is +not allowed in order to keep the process stable under various system +configurations (i.e. when different sets of third party debhelper build systems +are installed). However, the user can always discover all default and third +party debhelper build systems supported on the system by passing the L<--list> +option to any dh_auto program. + +=back + +Read section L</"DH_AUTO SHARED OPTIONS"> for more details how to enable the +features listed above. + +=head1 SUPPORTED BUILD SYSTEMS + +dh_auto provides support for the most popular build systems out of the box +(listed below). See section L</"DEBHELPER BUILD SYSTEM DETAILS"> for more +information how each build system is auto-selected and what commands are +executed to complete each building step. To get information about a third party +debhelper build system installed on your system, use I<--help-buildsystem> +option. + +#SUPPORTED BUILD SYSTEMS# + +=head1 #SUPPORTED BUILD SYSTEMS INTRO FOR DH_AUTO PROGRAMS + +Below you will find a list of the debhelper build systems that are shipped with +debhelper itself along with their details concerning this building step. They +are listed in the order of auto-selection preference. Consult +L<dh_auto_$buildsystem(7)> or L</"DEBHELPER BUILD SYSTEM DETAILS"> section of +L<dh_auto(7)>, or use L<--help--buildsystem> option for a more complete +reference about each build system. + +=head1 DH_AUTO SHARED OPTIONS + +=over 4 + +=item B<--buildsystem=>I<buildsystem>, B<-S>I<buildsystem> + +Select the specified debhelper I<buildsystem> instead of trying to auto-select +one which might be applicable for the package. I<buildsystem> specific commands +will be executed to complete a building step without any prior checks. This +option is also the only way to select a third party debhelper build system. + +=item B<--sourcedirectory>=I<directory>, B<-D>I<directory> + +Assume that the original package source tree is at the specified I<directory> +rather than the top level directory of the Debian source package tree (C<.>). +I<directory> path is assumed to be relative to the top level directory (where +debian/ is) and must exist. + +=item B<--builddirectory>=[I<directory>], B<-B>[I<directory>] + +Enable out of source building and use the specified I<directory> as the build +directory. If specified, I<directory> must be relative to the top level +directory of the Debian source package tree and generally does not need to +exist before the build process is started. If I<directory> parameter is +omitted, default build directory will be used. It is S<C<obj-`dpkg_architecture +-qDEB_BUILD_GNU_TYPE`>> by default but any debhelper build system can choose +another value (see documentation of the debhelper build systems). + +If this option is not specified, building will be done in source by default +unless the selected build system enforces/prefers out of source tree building. +In such a case, the default build directory will be used even if +L<--builddirectory> is not specified. If the selected build system just prefers +out of source tree building but still allows in source building, the latter can +be re-enabled by passing a build directory path that is equal to the source +directory path. + +=item B<--list>, B<-l> + +List all debhelper build systems available on this system and exit. The list +includes both default (listed first in the auto-selection order) and third +party build systems (clearly marked as such). The list is concluded with the +information about which build system would be auto-selected to complete the +building step or which one is manually specified with the I<--buildsystem> +option. + +=item B<--help-buildsystem> + +Print detailed help about a build system which would be auto-selected or which +is manually specified with the L<--buildsystem> option. Exit immediately +afterwards. + +=back + +=head1 DEBHELPER BUILD SYSTEM DETAILS + +This section provides more information about debhelper build systems supported +by default. They are listed in the order of auto-selection preference. The +first build system that matches auto-selection criteria is always selected and +the following ones are not even considered. Auto-selection conditions might +differ at each building step even for the same debhelper build system. + +#BUILD SYSTEM DETAILS# + +=head1 SEE ALSO + +L<debhelper(7)> + +=over 2 + +=item B<Default debhelper build systems> + +#BUILD SYSTEM MAN LIST# + +=back + +=head1 AUTHORS + + Joey Hess <joeyh@debian.org> + Modestas Vainius <modestas@vainius.eu> diff --git a/dh_auto_build b/dh_auto_build index 75ce51cf..d16694cf 100755 --- a/dh_auto_build +++ b/dh_auto_build @@ -2,27 +2,30 @@ =head1 NAME -dh_auto_build - automatically builds a package +dh_auto_build - build package sources =cut use strict; -use Debian::Debhelper::Dh_Lib; +use Debian::Debhelper::Dh_Buildsystems; =head1 SYNOPSIS -B<dh_auto_build> [S<I<debhelper options>>] [S<B<--> I<params>>] +B<dh_auto_build> [S<I<debhelper options>>] [S<I<dh_auto options>>] [S<B<--> I<params>>] =head1 DESCRIPTION -dh_auto_build is a debhelper program that tries to automatically -build a package. If a Makefile is found, this is done by running make (or -MAKE, if the environment variable is set). -If there's a setup.py, or Build.PL, it is run to build the package. +dh_auto_build is a debhelper program that is responsible for the I<build> step +of the L<dh_auto(7)> building process. Typically, this is the point when +package sources are compiled into binaries or otherwise transformed into ready +to use format. Files produced throughout this step are put to the build +directory. -This is intended to work for about 90% of packages. If it doesn't work, -you're encouraged to skip using dh_auto_build at all, and just run the -build process manually. +You can pass additional parameters via I<params>. However, if dh_auto_build +does not meet your needs or does not work, it is safe to skip/override it +entirely and build the package with custom commands. + +#DH_AUTO SHARED OPTIONS# =head1 OPTIONS @@ -35,29 +38,28 @@ or override any standard parameters that dh_auto_build passes. =back -=cut +=head1 SUPPORTED BUILD SYSTEMS -init(); +#SUPPORTED BUILD SYSTEMS INTRO# +#SUPPORTED BUILD SYSTEMS LIST# -if (-e "Makefile" || -e "makefile" || -e "GNUmakefile") { - doit(exists $ENV{MAKE} ? $ENV{MAKE} : "make", @{$dh{U_PARAMS}}); -} -elsif (-e "setup.py") { - doit("python", "setup.py", "build", @{$dh{U_PARAMS}}); -} -elsif (-e "Build.PL" && -e "Build") { - $ENV{MODULEBUILDRC} = "/dev/null"; - doit("perl", "Build", @{$dh{U_PARAMS}}); -} +=cut + +buildsystems_init(); +buildsystems_do(); =head1 SEE ALSO +L<dh_auto(7)> + L<debhelper(7)> -This program is a part of debhelper. +This program is a part of debhelper and its dh_auto package source building +suite. =head1 AUTHOR -Joey Hess <joeyh@debian.org> + Joey Hess <joeyh@debian.org> + Modestas Vainius <modestas@vainius.eu> =cut diff --git a/dh_auto_clean b/dh_auto_clean index 610155ae..625675b8 100755 --- a/dh_auto_clean +++ b/dh_auto_clean @@ -2,28 +2,30 @@ =head1 NAME -dh_auto_clean - automatically cleans up after a build +dh_auto_clean - clean temporary files after building package sources =cut use strict; -use Debian::Debhelper::Dh_Lib; +use Debian::Debhelper::Dh_Buildsystems; =head1 SYNOPSIS -B<dh_auto_clean> [S<I<debhelper options>>] [S<B<--> I<params>>] +B<dh_auto_clean> [S<I<debhelper options>>] [S<I<dh_auto options>>] [S<B<--> I<params>>] =head1 DESCRIPTION -dh_auto_clean is a debhelper program that tries to automatically clean up -after a package build. If there's a Makefile and it contains a "distclean", -"realclean", or "clean" target, then this is done by running make (or MAKE, -if the environment variable is set). If there is a setup.py or Build.PL, it -is run to clean the package. +dh_auto_clean is a debhelper program that is responsible for the I<clean> step +of the L<dh_auto(7)> building process. It tries to automatically clean up after +a package build by removing all temporary files from the build directory or +even the build directory itself as appropriate. dh_auto_clean will fail only if +the source build system clean routine fails. However, if the latter does not +exist or there is nothing to clean it will exit with zero status doing nothing. -This is intended to work for about 90% of packages. If it doesn't work, or -tries to use the wrong clean target, you're encouraged to skip using -dh_auto_clean at all, and just run make clean manually. +If dh_auto_clean does not meet your needs or does not work, it is safe to +skip/override it entirely and just run clean up manually. + +#DH_AUTO SHARED OPTIONS# =head1 OPTIONS @@ -36,42 +38,27 @@ or override the any standard parameters that dh_auto_clean passes. =back +=head1 SUPPORTED BUILD SYSTEMS + +#SUPPORTED BUILD SYSTEMS INTRO# +#SUPPORTED BUILD SYSTEMS LIST# + =cut -init(); - -if (-e "Makefile" || -e "makefile" || -e "GNUmakefile") { - $ENV{MAKE}="make" unless exists $ENV{MAKE}; - foreach my $target (qw{distclean realclean clean}) { - # Use make -n to check to see if the target would do - # anything. There's no good way to test if a target exists. - my $ret=`$ENV{MAKE} -s -n $target 2>/dev/null`; - chomp $ret; - if (length $ret) { - doit($ENV{MAKE}, $target, @{$dh{U_PARAMS}}); - last; - } - } -} -elsif (-e "setup.py") { - doit("python", "setup.py", "clean", "-a", @{$dh{U_PARAMS}}); - # The setup.py might import files, leading to python creating pyc - # files. - doit('find', '.', '-name', '*.pyc', '-exec', 'rm', '{}', ';'); -} -elsif (-e "Build.PL" && -e "Build") { - $ENV{MODULEBUILDRC} = "/dev/null"; - doit("perl", "Build", "--allow_mb_mismatch", 1, "distclean", @{$dh{U_PARAMS}}); -} +buildsystems_init(); +buildsystems_do(); =head1 SEE ALSO +L<dh_auto(7)> + L<debhelper(7)> -This program is a part of debhelper. +This program is a part of debhelper and its dh_auto package source building suite. -=head1 AUTHOR +=head1 AUTHORS -Joey Hess <joeyh@debian.org> + Joey Hess <joeyh@debian.org> + Modestas Vainius <modestas@vainius.eu> =cut diff --git a/dh_auto_configure b/dh_auto_configure index 5f48056f..3f326cef 100755 --- a/dh_auto_configure +++ b/dh_auto_configure @@ -2,28 +2,34 @@ =head1 NAME -dh_auto_configure - automatically configure a package prior to building +dh_auto_configure - configure and prepare package sources for building =cut use strict; -use Debian::Debhelper::Dh_Lib; +use Debian::Debhelper::Dh_Buildsystems; =head1 SYNOPSIS -B<dh_auto_configure> [S<I<debhelper options>>] [S<B<--> I<params>>] +B<dh_auto_configure> [S<I<debhelper options>>] [S<I<dh_auto options>>] [S<B<--> I<params>>] =head1 DESCRIPTION -dh_auto_configure is a debhelper program that tries to automatically -configure a package prior to building. It looks for and runs a ./configure -script, Makefile.PL, or Build.PL. A standard set of parameters is -determined and passed to the program that is run. If no program to run is -found, dh_auto_configure will exit without doing anything. +dh_auto_configure is a debhelper program that is responsible for the +I<configure> step of the L<dh_auto(7)> building process. Since I<configure> is +the first step, typically it is the point when build configuration options +are set, system settings are detected and various build system specific +temporary files are pre-generated in the build directory. Some simpler build +systems do not need this step. In such a case, dh_auto_configure silently +succeeds without doing anything. -This is intended to work for about 90% of packages. If it doesn't work, -you're encouraged to skip using dh_auto_configure at all, and just run -./configure or its equivalent manually. +dh_auto_configure usually pre-configures the source build system with a set of +standard options which most Debian packages need to set anyway. Custom options +can be passed as I<params>. If dh_auto_configure does not meet your needs or +does not work, it is safe to skip/override it entirely and just run a configure +script or its equivalent manually. + +#DH_AUTO SHARED OPTIONS# =head1 OPTIONS @@ -31,7 +37,7 @@ you're encouraged to skip using dh_auto_configure at all, and just run =item B<--> I<params> -Pass "params" to the program that is run, after the standard +Pass I<params> to the command that is run, after the standard parameters that dh_auto_configure passes. This can be used to supplement or override those parameters. For example: @@ -39,78 +45,28 @@ or override those parameters. For example: =back +=head1 SUPPORTED BUILD SYSTEMS + +#SUPPORTED BUILD SYSTEMS INTRO# +#SUPPORTED BUILD SYSTEMS LIST# + =cut -init(); - -sub dpkg_architecture_value { - my $var=shift; - my $value=`dpkg-architecture -q$var 2>/dev/null` || error("dpkg-architecture failed"); - chomp $value; - return $value; -} - -sub sourcepackage { - open (CONTROL, 'debian/control') || - error("cannot read debian/control: $!\n"); - while (<CONTROL>) { - chomp; - s/\s+$//; - if (/^Source:\s*(.*)/) { - close CONTROL; - return $1; - } - } - - close CONTROL; - error("could not find Source: line in control file."); -} - -if (-x "configure") { - # Standard set of options for configure. - my @opts; - push @opts, "--build=".dpkg_architecture_value("DEB_BUILD_GNU_TYPE"); - push @opts, "--prefix=/usr"; - push @opts, "--includedir=\${prefix}/include"; - push @opts, "--mandir=\${prefix}/share/man"; - push @opts, "--infodir=\${prefix}/share/info"; - push @opts, "--sysconfdir=/etc"; - push @opts, "--localstatedir=/var"; - push @opts, "--libexecdir=\${prefix}/lib/".sourcepackage(); - push @opts, "--disable-maintainer-mode"; - push @opts, "--disable-dependency-tracking"; - # Provide --host only if different from --build, as recommended in - # autotools-dev README.Debian: When provided (even if equal) autotools - # 2.52+ switches to cross-compiling mode. - if (dpkg_architecture_value("DEB_BUILD_GNU_TYPE") ne dpkg_architecture_value("DEB_HOST_GNU_TYPE")) { - push @opts, "--host=".dpkg_architecture_value("DEB_HOST_GNU_TYPE"); - } - doit("./configure", @opts, @{$dh{U_PARAMS}}); -} -elsif (-e "Makefile.PL") { - # If set to a true value then MakeMaker's prompt function will - # always return the default without waiting for user input. - $ENV{PERL_MM_USE_DEFAULT}=1; - # This prevents Module::Install from interactive behavior. - $ENV{PERL_AUTOINSTALL}="--skipdeps"; - - doit("perl", "Makefile.PL", "INSTALLDIRS=vendor", - "create_packlist=0", @{$dh{U_PARAMS}}); -} -elsif (-e "Build.PL") { - $ENV{PERL_MM_USE_DEFAULT}=1; # Module::Build can also use this. - $ENV{MODULEBUILDRC} = "/dev/null"; - doit("perl", "Build.PL", "installdirs=vendor", @{$dh{U_PARAMS}}); -} +buildsystems_init(); +buildsystems_do(); =head1 SEE ALSO +L<dh_auto(7)> + L<debhelper(7)> -This program is a part of debhelper. +This program is a part of debhelper and its dh_auto package source building +suite. -=head1 AUTHOR +=head1 AUTHORS -Joey Hess <joeyh@debian.org> + Joey Hess <joeyh@debian.org> + Modestas Vainius <modestas@vainius.eu> =cut diff --git a/dh_auto_install b/dh_auto_install index 264725ca..5c772245 100755 --- a/dh_auto_install +++ b/dh_auto_install @@ -2,24 +2,26 @@ =head1 NAME -dh_auto_install - automatically runs make install or similar +dh_auto_install - install built files into the temporary directory under debian/ =cut use strict; use Debian::Debhelper::Dh_Lib; +use Debian::Debhelper::Dh_Buildsystems; use Cwd; =head1 SYNOPSIS -B<dh_auto_install> [S<I<debhelper options>>] [S<B<--> I<params>>] +B<dh_auto_install> [S<I<debhelper options>>] [S<I<dh_auto options>>] [S<B<--> I<params>>] =head1 DESCRIPTION -dh_auto_install is a debhelper program that tries to automatically install -built files. If there's a Makefile and it contains a "install" target, -then this is done by running make (or MAKE, if the environment variable is -set). If there is a setup.py or Build.PL, it is used. +dh_auto_install is a debhelper program that is responsible for the I<install> +step of the L<dh_auto(7)> building process. dh_auto_install tries to run +original package installation routine to install built files into the proper +places of the file system hierarchy recreated under the (temporary) directory +in debian/. The files are installed into debian/<package>/ if there is only one binary package. In the multiple binary package case, the files are instead @@ -27,13 +29,10 @@ installed into debian/tmp/, and should be moved from there to the appropriate package build directory using L<dh_install(1)> or L<dh_movefiles(1)>. -DESTDIR is used to tell make where to install the files. -If the Makefile was generated by MakeMaker from a Makefile.PL, it will -automatically set PREFIX=/usr too, since such Makefiles need that. +If dh_auto_install does not meet your needs or does not work, it is safe to +skip/override it entirely and just run C<make install> or the like manually. -This is intended to work for about 90% of packages. If it doesn't work, or -tries to use the wrong install target, you're encouraged to skip using -dh_auto_install at all, and just run make install manually. +#DH_AUTO SHARED OPTIONS# =head1 OPTIONS @@ -46,9 +45,14 @@ or override the any standard parameters that dh_auto_install passes. =back +=head1 SUPPORTED BUILD SYSTEMS + +#SUPPORTED BUILD SYSTEMS INTRO# +#SUPPORTED BUILD SYSTEMS LIST# + =cut -init(); +buildsystems_init(); my $destdir; my @allpackages=getpackages(); @@ -60,49 +64,20 @@ else { } $destdir=cwd()."/".$destdir; -if (-e "Makefile" || -e "makefile" || -e "GNUmakefile") { - $ENV{MAKE}="make" unless exists $ENV{MAKE}; - my @params="DESTDIR=$destdir"; - - # Special case for MakeMaker generated Makefiles. - if (-e "Makefile" && - system('grep -q "generated automatically by MakeMaker" Makefile') == 0) { - push @params, "PREFIX=/usr"; - } - - foreach my $target (qw{install}) { - # Use make -n to check to see if the target would do - # anything. There's no good way to test if a target exists. - my $ret=`$ENV{MAKE} -s -n $target 2>/dev/null`; - chomp $ret; - if (length $ret) { - doit($ENV{MAKE}, $target, - @params, - @{$dh{U_PARAMS}}); - last; - } - } -} -elsif (-e "setup.py") { - doit("python", "setup.py", "install", - "--root=$destdir", - "--no-compile", "-O0", - @{$dh{U_PARAMS}}); -} -elsif (-e "Build.PL" && -e "Build") { - $ENV{MODULEBUILDRC} = "/dev/null"; - doit("perl", "Build", "install", "destdir=$destdir", - "create_packlist=0", @{$dh{U_PARAMS}}); -} +buildsystems_do("install", $destdir); =head1 SEE ALSO +L<dh_auto(7)> + L<debhelper(7)> -This program is a part of debhelper. +This program is a part of debhelper and its dh_auto package source building +suite. -=head1 AUTHOR +=head1 AUTHORS -Joey Hess <joeyh@debian.org> + Joey Hess <joeyh@debian.org> + Modestas Vainius <modestas@vainius.eu> =cut diff --git a/dh_auto_test b/dh_auto_test index ea2d7fdc..062563fd 100755 --- a/dh_auto_test +++ b/dh_auto_test @@ -2,29 +2,35 @@ =head1 NAME -dh_auto_test - automatically runs a package's test suites +dh_auto_test - run package test suites after building =cut use strict; -use Debian::Debhelper::Dh_Lib; +use Debian::Debhelper::Dh_Buildsystems; =head1 SYNOPSIS -B<dh_auto_test> [S<I<debhelper options>>] [S<B<--> I<params>>] +B<dh_auto_test> [S<I<debhelper options>>] [S<I<dh_auto options>>] [S<B<--> I<params>>] =head1 DESCRIPTION -dh_auto_test is a debhelper program that tries to automatically run a -package's test suite. If there's a Makefile and it contains a "test" -or "check" target, then this is done by running make (or MAKE, if the -environment variable is set). If the test suite fails, the command will -exit nonzero. If there's no test suite, it will exit zero without doing -anything. +dh_auto_test is a debhelper program that is responsible for the I<test> step of +the L<dh_auto(7)> building process. Typically, this is the point when package +test suite is run to check if the sources were built successfully and/or +binaries provide expected functionality. dh_auto_test will fail if test suite +fails. However, if there's no test suite, it will exit with zero status +without doing anything. -This is intended to work for about 90% of packages with a test suite. If it -doesn't work, you're encouraged to skip using dh_auto_test at all, and -just run the test suite manually. +If dh_auto_test does not meet your needs or does not work, it is safe to +skip/override it entirely and just run the test suite manually. + +=head1 NOTES + +If the DEB_BUILD_OPTIONS environment variable contains "nocheck", no tests will +be performed. + +#DH_AUTO SHARED OPTIONS# =head1 OPTIONS @@ -37,45 +43,32 @@ or override the any standard parameters that dh_auto_test passes. =back -=head1 NOTES +=head1 SUPPORTED BUILD SYSTEMS -If the DEB_BUILD_OPTIONS environment variable contains "nocheck", no -tests will be performed. +#SUPPORTED BUILD SYSTEMS INTRO# +#SUPPORTED BUILD SYSTEMS LIST# =cut -init(); - if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS} =~ /nocheck/) { exit 0; } -if (-e "Makefile" || -e "makefile" || -e "GNUmakefile") { - $ENV{MAKE}="make" unless exists $ENV{MAKE}; - foreach my $target (qw{test check}) { - # Use make -n to check to see if the target would do - # anything. There's no good way to test if a target exists. - my $ret=`$ENV{MAKE} -s -n $target 2>/dev/null`; - chomp $ret; - if (length $ret) { - doit($ENV{MAKE}, $target, @{$dh{U_PARAMS}}); - last; - } - } -} -elsif (-e "Build.PL" && -e "Build") { - $ENV{MODULEBUILDRC} = "/dev/null"; - doit(qw/perl Build test/, @{$dh{U_PARAMS}}); -} +buildsystems_init(); +buildsystems_do(); =head1 SEE ALSO +L<dh_auto(7)> + L<debhelper(7)> -This program is a part of debhelper. +This program is a part of debhelper and its dh_auto package source building +suite. -=head1 AUTHOR +=head1 AUTHORS -Joey Hess <joeyh@debian.org> + Joey Hess <joeyh@debian.org> + Modestas Vainius <modestas@vainius.eu> =cut diff --git a/doc/PROGRAMMING b/doc/PROGRAMMING index 9963181e..bd79628c 100644 --- a/doc/PROGRAMMING +++ b/doc/PROGRAMMING @@ -250,13 +250,13 @@ write_log($cmd, $package ...) Writes the log files for the specified package(s), adding the cmd to the end. -Sequence Addons +Sequence Addons: --------------- The dh(1) command has a --with <addon> parameter that ca be used to load -a sequence addon named Debian::Debhelper::Sequence::<addon>. -These addons can add/remove commands to the dh command sequences, by calling -some functions from Dh_Lib: +a sequence addon module named Debian::Debhelper::Sequence::<addon>. +These modules can add/remove commands to the dh command sequences, by +calling some functions from Dh_Lib: insert_before($existing_command, $new_command) Insert $new_command in sequences before $existing_command @@ -267,4 +267,19 @@ insert_after($existing_command, $new_command) remove_command($existing_command) Remove $existing_command from the list of commands to run. +Buildsystem Classes: +------------------- + +The dh_auto_* commands are frontends that use debhelper buildsystem +classes. These classes have names like Debian::Debhelper::Buildsystem::foo, +and are derived from Debian::Debhelper::Buildsystem, or other, related +classes. + +A buildsystem class needs to inherit or define these methods: DESCRIPTION, +check_auto_buildable, build, test, install, clean. See the comments +inside Debian::Debhelper::Buildsystem for details. + +Note that third-party buildsystems will not automatically be used by default, +but can be forced to be used via the --buildsystem parameter. + -- Joey Hess <joeyh@debian.org> diff --git a/man/dh_auto_pod b/man/dh_auto_pod new file mode 100755 index 00000000..01817b23 --- /dev/null +++ b/man/dh_auto_pod @@ -0,0 +1,288 @@ +#!/usr/bin/perl -w + +package CommandStrip; +use base Pod::Parser; + +sub command { + my $parser=shift; + if (!exists $parser->{_stripped_}) { + $parser->{_stripped_} = 1; + return; + } + return $parser->SUPER::command(@_); +} + +package main; + +use strict; +use warnings; +use Debian::Debhelper::Dh_Lib; +use Debian::Debhelper::Dh_Buildsystems; +use Pod::Select; +use IO::String; +use File::Spec; +use Pod::InputObjects; + +my @buildsystem_pods; +my $DH_AUTO_POD = "dh_auto.pod"; + +# Preloads build system PODs +sub get_buildsystem_pods { + my $parser = new Pod::Select(); + if (!@buildsystem_pods) { + my @buildsystems = load_all_buildsystems([ "." ]); + for my $system (@buildsystems) { + my $podfile = File::Spec->catfile("Debian/Debhelper/Buildsystem", $system->NAME() . ".pm"); + my $iostr = new IO::String(); + + open(my $fh, $podfile) or error("Unable to read $podfile"); + $system->{pod_fh} = $fh; + + # Extract build system name from POD + $parser->select('NAME'); + strip_first_command($parser, $fh, $iostr); + + # Remove empty lines and join new lines + $system->{pod_name} = join(" ", grep ! /^\s*$/, split(/\n/, ${$iostr->string_ref()})); + + push @buildsystem_pods, $system; + } + } + return @buildsystem_pods; +} + +# Strips the first command (i.e. line starting with =), prints +# everything else +sub strip_first_command { + my ($parser, $input_fh, $output_fh)=@_; + + my $iostr = new IO::String(); + seek(\*$input_fh, 0, 0); + $parser->parse_from_filehandle($input_fh, $iostr); + $iostr->pos(0); + CommandStrip->new()->parse_from_filehandle($iostr, $output_fh); + $iostr->close(); +} + +# Prints everything +sub print_everything { + my ($parser, $input_fh, $output_fh)=@_; + seek(\*$input_fh, 0, 0); + $parser->parse_from_filehandle($input_fh, $output_fh); +} + +# Prints POD paragraph +# Common parameters -name, -text. Results into =${-name} ${-text} +sub print_pod_parag { + my %args=@_; + my $output_fh = $args{output} || \*STDOUT; + print $output_fh Pod::Paragraph->new(@_)->raw_text(), "\n\n"; +} + +#sub unique_authors { +# my ($authors, $parser, $fh)=@_; +# my $iostr = new IO::String(); + +# $parser->select('AUTHOR[^\s]*'); +# seek(\*$fh, 0, 0); +# strip_first_command($parser, $fh, $iostr); +# $iostr->pos(0); +# while (my $author = <$iostr>) { +# $author =~ s/\s+/ /g; +# $author =~ s/^\s+//; +# $author =~ s/\s+$//; +# $authors->{$author} = scalar(keys %$authors) +# if !exists $authors->{$author}; +# } +# $iostr->close(); +#} + +############# Generation of dh_auto_step POD ############# + +sub get_dh_auto_shared_options_for_step { + my $step=shift; + my $parser = new Pod::Select(); + my $iostr = new IO::String(); + + $parser->select('DH_AUTO SHARED OPTIONS'); + print_everything($parser, \*DH_AUTO, $iostr); + return ${$iostr->string_ref()}; +} + +sub get_supported_buildsystems_intro_for_step { + my $step=shift; + my $parser = new Pod::Select(); + my $iostr = new IO::String(); + + # A common "SUPPORTED BUILD SYSTEMS" dh_auto POD + $parser->select('#SUPPORTED BUILD SYSTEMS INTRO FOR DH_AUTO PROGRAMS'); + strip_first_command($parser, \*DH_AUTO, $iostr); + return ${$iostr->string_ref()}; +} + +sub get_supported_buildsystems_list_for_step { + my $step=shift; + my $parser = new Pod::Select(); + my $iostr = new IO::String(); + + # Append build system list from build system PODs + for my $bs (get_buildsystem_pods()) { + my $bs_fh = $bs->{pod_fh}; + + # =head2 Build system name + print_pod_parag(output => $iostr, -name => 'head2', -text => $bs->{pod_name}); + + # Now print DH_AUTO NOTES + $parser->select('DH_AUTO NOTES'); + strip_first_command($parser, $bs_fh, $iostr); + + # And step specific help follows + $parser->select('BUILD PROCESS/' . ucfirst($step) . " step"); + strip_first_command($parser, $bs_fh, $iostr); + } + return ${$iostr->string_ref()}; +} + +sub generate_step_pod { + my $step=shift; + $step = $1 if ($step =~ /dh_auto_(.*)$/); + + my $dh_auto_step = "dh_auto_$step"; + my $dh_auto_shared_options = get_dh_auto_shared_options_for_step($step); + my $supported_bs_intro = get_supported_buildsystems_intro_for_step($step); + my $supported_bs_list = get_supported_buildsystems_list_for_step($step); + open(DH_AUTO_STEP, "podselect $dh_auto_step |") + or error("Unable to read $dh_auto_step"); + while (<DH_AUTO_STEP>) { + s/#DH_AUTO SHARED OPTIONS#/$dh_auto_shared_options/; + s/#SUPPORTED BUILD SYSTEMS INTRO#/$supported_bs_intro/; + s/#SUPPORTED BUILD SYSTEMS LIST#/$supported_bs_list/; + print $_; + } + close DH_AUTO_STEP; +} + +############# Generation of dh_auto POD ############# + +sub get_dh_auto_program_list_for_dh_auto { + my @steps=@_; + my $parser = new Pod::Select(); + my $collect = ""; + + $parser->select('NAME'); + foreach my $step (@steps) { + my $iostr = new IO::String(); + open (my $fh, "dh_auto_$step") or die "$_: $!"; + strip_first_command($parser, $fh, $iostr); + close $fh; + if (${$iostr->string_ref()} =~ /^(.*?) - (.*)/) { + $collect .= "=item $1(1)\n\n$2\n\n"; + } + } + return $collect; +} + +sub get_supported_buildsystems_for_dh_auto { + my $parser = new Pod::Select(); + my $iostr = new IO::String(); + + # Build system list from build system PODs (NAME + DESCRIPTION) + for my $bs (sort { $a->NAME() cmp $b->NAME() } get_buildsystem_pods()) { + my $bs_fh = $bs->{pod_fh}; + + # =head2 Build system name + print_pod_parag(output => $iostr, -name => 'head2', -text => $bs->{pod_name}); + + $parser->select('DESCRIPTION'); + strip_first_command($parser, $bs_fh, $iostr); + } + return ${$iostr->string_ref()}; +} + +sub get_buildsystem_details_for_dh_auto { + my @steps=@_; + my $parser = new Pod::Select(); + my $iostr = new IO::String(); + + # Build system details from build system PODs + for my $bs (get_buildsystem_pods()) { + my $bs_fh = $bs->{pod_fh}; + + print_pod_parag(output => $iostr, -name => 'head2', -text => $bs->NAME()); + + # Now print DH_AUTO NOTES + $parser->select('DH_AUTO NOTES'); + strip_first_command($parser, $bs_fh, $iostr); + + # And step specific documentation + for my $step (@steps) { + $parser->select('BUILD PROCESS/' . ucfirst($step) . " step"); + print_pod_parag(output => $iostr, -name => 'head3', -text => 'B<' . ucfirst($step) . " step>"); + strip_first_command($parser, $bs_fh, $iostr); + } + } + return ${$iostr->string_ref()}; +} + +sub get_dh_auto_program_man_list_for_dh_auto { + return join("\n\n", map { "L<dh_auto_$_(1)>" } @_); +} + +sub get_buildsystem_man_list_for_dh_auto { + return join("\n\n", map { "L<dh_auto_" . $_->NAME() . "(7)>" } get_buildsystem_pods()); +} + +sub generate_dh_auto_pod { + my @steps=@_; + my $parser = new Pod::Select(); + my $iostr = new IO::String(); + + my $dh_auto_list = get_dh_auto_program_list_for_dh_auto(@steps); + my $supported_bs = get_supported_buildsystems_for_dh_auto(@steps); + my $bs_details = get_buildsystem_details_for_dh_auto(@steps); + my $dh_auto_man_list = get_dh_auto_program_man_list_for_dh_auto(@steps); + my $bs_man_list = get_buildsystem_man_list_for_dh_auto(); + + # Filter out all sections starting with # + $parser->select('[^#].*'); + print_everything($parser, \*DH_AUTO, $iostr); + + seek(\*$iostr, 0, 0); + while (<$iostr>) { + s/#DH_AUTO LIST#/$dh_auto_list/; + s/#SUPPORTED BUILD SYSTEMS#/$supported_bs/; + s/#BUILD SYSTEM DETAILS#/$bs_details/; + s/#DH_AUTO MAN LIST#/$dh_auto_man_list/; + s/#BUILD SYSTEM MAN LIST#/$bs_man_list/; + print $_; + } + $iostr->close(); +} + +############# Entry point ############# + +my @args; +my $outfile; +foreach (@ARGV) { + if (/^-o(.*)/) { + $outfile = $1; + } + else { + push @args, $_; + } +} + +if ($outfile) { + open(OUTFILE, ">", $outfile) or die "Unable to open output file $outfile"; + open(STDOUT, ">&OUTFILE") or die "Unable to redirect standard output"; +} + +open(DH_AUTO, $DH_AUTO_POD) or error("Unable to read $DH_AUTO_POD"); +if (@args > 0) { + generate_step_pod(@args); +} +else { + generate_dh_auto_pod(qw(configure build test install clean)); +} +close DH_AUTO; +close OUTFILE if $outfile; diff --git a/t/buildsystems/autoconf/configure b/t/buildsystems/autoconf/configure new file mode 100755 index 00000000..adea14e6 --- /dev/null +++ b/t/buildsystems/autoconf/configure @@ -0,0 +1,74 @@ +#!/usr/bin/perl + +# Emulate autoconf behaviour and do some checks + +use strict; +use warnings; + +my @OPTIONS=qw( + ^--build=.*$ + ^--prefix=/usr$ + ^--includedir=\$\{prefix\}/include$ + ^--mandir=\$\{prefix\}/share/man$ + ^--infodir=\$\{prefix\}/share/info$ + ^--sysconfdir=/etc$ + ^--localstatedir=/var$ + ^--libexecdir=\$\{prefix\}/lib/.*$ + ^--disable-maintainer-mode$ + ^--disable-dependency-tracking$ +); + +# Verify if all command line arguments were passed +my @options = map { { regex => qr/$_/, + str => $_, + found => 0 } } @OPTIONS; +my @extra_args; +ARGV_LOOP: foreach my $arg (@ARGV) { + foreach my $opt (@options) { + if ($arg =~ $opt->{regex}) { + $opt->{found} = 1; + next ARGV_LOOP; + } + } + # Extra / unrecognized argument + push @extra_args, $arg; +} + +my @notfound = grep { ! $_->{found} and $_ } @options; +if (@notfound) { + print STDERR "Error: the following default options were NOT passed\n"; + print STDERR " ", $_->{str}, "\n" foreach (@notfound); + exit 1; +} + +# Create a simple Makefile +open(MAKEFILE, ">", "Makefile"); +print MAKEFILE <<EOF; +CONFIGURE := $0 +all: stamp_configure \$(CONFIGURE) + \@echo Package built > stamp_build + +# Tests if dh_auto_test executes 'check' target if 'test' does not exist +check: \$(CONFIGURE) stamp_build + \@echo Tested > stamp_test + +install: stamp_build + \@echo DESTDIR=\$(DESTDIR) > stamp_install + +# Tests whether dh_auto_clean executes distclean but does not touch +# this target +clean: + echo "This should not have been executed" >&2 && exit 1 + +distclean: + \@rm -f stamp_* Makefile + +.PHONY: all check install clean distclean +EOF +close MAKEFILE; + +open(STAMP, ">", "stamp_configure"); +print STAMP $_, "\n" foreach (@extra_args); +close STAMP; + +exit 0; diff --git a/t/buildsystems/buildsystem_tests b/t/buildsystems/buildsystem_tests new file mode 100755 index 00000000..82d8c100 --- /dev/null +++ b/t/buildsystems/buildsystem_tests @@ -0,0 +1,434 @@ +#!/usr/bin/perl + +use Test::More tests => 227; + +use strict; +use warnings; +use IPC::Open2; +use Cwd (); +use File::Temp qw(tempfile tempdir); +use File::Basename (); + +# Let the tests to be run from anywhere but currect directory +# is expected to be the one where this test lives in. +chdir File::Basename::dirname($0) or die "Unable to chdir to ".File::Basename::dirname($0); + +use_ok( 'Debian::Debhelper::Dh_Lib' ); +use_ok( 'Debian::Debhelper::Buildsystem' ); +use_ok( 'Debian::Debhelper::Dh_Buildsystems' ); + +my $TOPDIR = "../.."; +my @STEPS = qw(configure build test install clean); +my @BUILDSYSTEMS = qw(autoconf perl_makemaker makefile python_distutils perl_build cmake); +my $BS_CLASS = 'Debian::Debhelper::Buildsystem'; + +my ($bs, @bs, %bs); +my ($tmp, @tmp, %tmp); +my ($tmpdir, $builddir, $default_builddir); + +### Common subs #### +sub touch { + my $file=shift; + my $chmod=shift; + open FILE, ">", $file and close FILE or die "Unable to touch $file"; + chmod $chmod, $file if defined $chmod; +} + +sub cleandir { + my $dir=shift; + system ("find", $dir, "-type", "f", "-delete"); +} +sub readlines { + my $h=shift; + my @lines = <$h>; + close $h; + chop @lines; + return \@lines; +} + +sub process_stdout { + my ($cmdline, $stdin) = @_; + my ($reader, $writer); + + open2($reader, $writer, $cmdline) or die "Unable to exec $cmdline"; + print $writer $stdin if $stdin; + close $writer; + return readlines($reader); +} + +### Test Buildsystem class API methods +is( $BS_CLASS->_canonpath("path/to/the/./nowhere/../../somewhere"), + "path/to/somewhere", "_canonpath no1" ); +is( $BS_CLASS->_canonpath("path/to/../forward/../../somewhere"), + "somewhere","_canonpath no2" ); +is( $BS_CLASS->_canonpath("path/to/../../../somewhere"), + "../somewhere","_canonpath no3" ); +is( $BS_CLASS->_canonpath("./"), ".", "_canonpath no4" ); +is( $BS_CLASS->_rel2rel("path/my/file", "path/my"), + "file", "_rel2rel no1" ); +is( $BS_CLASS->_rel2rel("path/dir/file", "path/my"), + "../dir/file", "_rel2rel no2" ); +is( $BS_CLASS->_rel2rel("file", "/root/path/my", "/root"), + "../../file", "_rel2rel no3" ); +is( $BS_CLASS->_rel2rel(".", "."), ".", "_rel2rel no4" ); +is( $BS_CLASS->_rel2rel("path", "path/"), ".", "_rel2rel no5" ); + +### Test Buildsystem class path API methods under different configurations +sub test_buildsystem_paths_api { + my ($bs, $config, $expected)=@_; + + my $api_is = sub { + my ($got, $name)=@_; + is( $got, $expected->{$name}, "paths API ($config): $name") + }; + + &$api_is( $bs->get_sourcedir(), 'get_sourcedir()' ); + &$api_is( $bs->get_sourcepath("a/b"), 'get_sourcepath(a/b)' ); + &$api_is( $bs->get_builddir(), 'get_builddir()' ); + &$api_is( $bs->get_buildpath(), 'get_buildpath()' ); + &$api_is( $bs->get_buildpath("a/b"), 'get_buildpath(a/b)' ); + &$api_is( $bs->get_source_rel2builddir(), 'get_source_rel2builddir()' ); + &$api_is( $bs->get_source_rel2builddir("a/b"), 'get_source_rel2builddir(a/b)' ); + &$api_is( $bs->get_build_rel2sourcedir(), 'get_build_rel2sourcedir()' ); + &$api_is( $bs->get_build_rel2sourcedir("a/b"), 'get_build_rel2sourcedir(a/b)' ); +} + +# Defaults +$bs = $BS_CLASS->new(); +$default_builddir = $bs->DEFAULT_BUILD_DIRECTORY(); +%tmp = ( + "get_sourcedir()" => ".", + "get_sourcepath(a/b)" => "./a/b", + "get_builddir()" => undef, + "get_buildpath()" => ".", + "get_buildpath(a/b)" => "./a/b", + "get_source_rel2builddir()" => ".", + "get_source_rel2builddir(a/b)" => "./a/b", + "get_build_rel2sourcedir()" => ".", + "get_build_rel2sourcedir(a/b)" => "./a/b", +); +test_buildsystem_paths_api($bs, "no builddir, no sourcedir", \%tmp); + +# builddir=bld/dir +$bs = $BS_CLASS->new(builddir => "bld/dir"); +%tmp = ( + "get_sourcedir()" => ".", + "get_sourcepath(a/b)" => "./a/b", + "get_builddir()" => "bld/dir", + "get_buildpath()" => "bld/dir", + "get_buildpath(a/b)" => "bld/dir/a/b", + "get_source_rel2builddir()" => "../..", + "get_source_rel2builddir(a/b)" => "../../a/b", + "get_build_rel2sourcedir()" => "bld/dir", + "get_build_rel2sourcedir(a/b)" => "bld/dir/a/b", +); +test_buildsystem_paths_api($bs, "builddir=bld/dir, no sourcedir", \%tmp); + +# Default builddir, sourcedir=autoconf +$bs = $BS_CLASS->new(builddir => undef, sourcedir => "autoconf"); +%tmp = ( + "get_sourcedir()" => "autoconf", + "get_sourcepath(a/b)" => "autoconf/a/b", + "get_builddir()" => "$default_builddir", + "get_buildpath()" => "$default_builddir", + "get_buildpath(a/b)" => "$default_builddir/a/b", + "get_source_rel2builddir()" => "../autoconf", + "get_source_rel2builddir(a/b)" => "../autoconf/a/b", + "get_build_rel2sourcedir()" => "../$default_builddir", + "get_build_rel2sourcedir(a/b)" => "../$default_builddir/a/b", +); +test_buildsystem_paths_api($bs, "default builddir, sourcedir=autoconf", \%tmp); + +# Enforce out of source tree building +# sourcedir=builddir=autoconf hence default builddir is implied +$bs = $BS_CLASS->new(builddir => "autoconf", sourcedir => "autoconf/"); +$bs->enforce_out_of_source_building(); +test_buildsystem_paths_api($bs, "hard out of source enforced, sourcedir=builddir", \%tmp); + +# sourcedir=autoconf (builddir should be dropped) +$bs = $BS_CLASS->new(builddir => "autoconf", sourcedir => "autoconf"); +%tmp = ( + "get_sourcedir()" => "autoconf", + "get_sourcepath(a/b)" => "autoconf/a/b", + "get_builddir()" => undef, + "get_buildpath()" => "autoconf", + "get_buildpath(a/b)" => "autoconf/a/b", + "get_source_rel2builddir()" => ".", + "get_source_rel2builddir(a/b)" => "./a/b", + "get_build_rel2sourcedir()" => ".", + "get_build_rel2sourcedir(a/b)" => "./a/b", +); +test_buildsystem_paths_api($bs, "no builddir, sourcedir=autoconf", \%tmp); + +# Prefer out of source tree building when +# sourcedir=builddir=autoconf hence builddir should be dropped. +$bs->enforce_out_of_source_building(builddir => "autoconf"); +test_buildsystem_paths_api($bs, "out of source prefered, sourcedir=builddir", \%tmp); + +# builddir=bld/dir, sourcedir=autoconf. Should be the same as sourcedir=autoconf. +$bs = $BS_CLASS->new(builddir => "bld/dir", sourcedir => "autoconf"); +$bs->enforce_in_source_building(); +test_buildsystem_paths_api($bs, "in source enforced, sourcedir=autoconf", \%tmp); + +# builddir=../bld/dir (relative to the curdir) +$bs = $BS_CLASS->new(builddir => "bld/dir/", sourcedir => "autoconf"); +%tmp = ( + "get_sourcedir()" => "autoconf", + "get_sourcepath(a/b)" => "autoconf/a/b", + "get_builddir()" => "bld/dir", + "get_buildpath()" => "bld/dir", + "get_buildpath(a/b)" => "bld/dir/a/b", + "get_source_rel2builddir()" => "../../autoconf", + "get_source_rel2builddir(a/b)" => "../../autoconf/a/b", + "get_build_rel2sourcedir()" => "../bld/dir", + "get_build_rel2sourcedir(a/b)" => "../bld/dir/a/b", +); +test_buildsystem_paths_api($bs, "builddir=../bld/dir, sourcedir=autoconf", \%tmp); + +### Test if all buildsystems can be loaded +@bs = load_all_buildsystems([ $INC[0] ]); +@tmp = map { $_->NAME() } @bs; +is_deeply( \@tmp, \@BUILDSYSTEMS, "load_all_buildsystems() loads all built-in buildsystems" ); + +### Test check_auto_buildable() of each buildsystem +sub test_check_auto_buildable { + my $bs=shift; + my $config=shift; + my $expected=shift; + my @steps=@_ || @STEPS; + + if (! ref $expected) { + my %all_steps; + $all_steps{$_} = $expected foreach (@steps); + $expected = \%all_steps; + } + for my $step (@steps) { + my $e = 0; + if (exists $expected->{$step}) { + $e = $expected->{$step}; + } elsif (exists $expected->{default}) { + $e = $expected->{default}; + } + if ($e) { + ok( $bs->check_auto_buildable($step), + $bs->NAME() . "($config): check_auto_buildable($step)" ); + } + else { + ok( ! $bs->check_auto_buildable($step), + $bs->NAME() . "($config): ! check_auto_buildable($step)" ); + } + } +} + +$tmpdir = tempdir("tmp.XXXXXX"); +$builddir = "$tmpdir/builddir"; +mkdir $builddir; +%tmp = ( + builddir => "$tmpdir/builddir", + sourcedir => $tmpdir +); + +$bs{autoconf} = load_buildsystem("autoconf", undef, %tmp); +$bs{cmake} = load_buildsystem("cmake", undef, %tmp); +$bs{perl_mm} = load_buildsystem("perl_makemaker", undef, %tmp); +$bs = load_buildsystem("makefile", undef, %tmp); + +test_check_auto_buildable($bs{autoconf}, "no configure", 0); +test_check_auto_buildable($bs{cmake}, "no CMakeLists.txt", 0); +test_check_auto_buildable($bs{perl_mm}, "no Makefile.PL", 0); +test_check_auto_buildable($bs, "no Makefile", 0); + +touch "$tmpdir/configure", 0755; +test_check_auto_buildable($bs{autoconf}, "configure", { configure => 1 }); + +touch "$tmpdir/CMakeLists.txt"; +test_check_auto_buildable($bs{cmake}, "CMakeLists.txt", { configure => 1 }); + +touch "$tmpdir/Makefile.PL"; +test_check_auto_buildable($bs{perl_mm}, "Makefile.PL", + { configure => 1, install => 1 }); + +# With Makefile +touch "$builddir/Makefile"; +test_check_auto_buildable($bs, "Makefile", { configure => 0, default => 1 }); +test_check_auto_buildable($bs{autoconf}, "configure+Makefile", { configure => 1 }); +test_check_auto_buildable($bs{cmake}, "CMakeLists.txt+Makefile", 1); + +# Makefile.PL forces in-source +#(see note in check_auto_buildable() why always 1 here) +unlink "$builddir/Makefile"; +touch "$tmpdir/Makefile"; +test_check_auto_buildable($bs{perl_mm}, "Makefile.PL+Makefile", 1); + +# Perl Build.PL - handles always +$bs = load_buildsystem("perl_build", undef, %tmp); +test_check_auto_buildable($bs, "no Build.PL", 0); +touch "$tmpdir/Build.PL"; +test_check_auto_buildable($bs, "Build.PL", { configure => 1 }); +touch "$tmpdir/Build"; # forced in source +test_check_auto_buildable($bs, "Build.PL+Build", 1); + +# Python Distutils +$bs = load_buildsystem("python_distutils", undef, %tmp); +test_check_auto_buildable($bs, "no setup.py", 0); +touch "$tmpdir/setup.py"; +test_check_auto_buildable($bs, "setup.py", 1); + +cleandir($tmpdir); + +### Now test if it can autoselect a proper buildsystem for a typical package +sub test_autoselection { + my $system=shift; + my $expected=shift; + for my $step (@STEPS) { + my $bs = load_buildsystem(undef, $step, @_); + my $e = $expected; + $e = $expected->{$step} if ref $expected; + if (defined $bs) { + is( $bs->NAME(), $e, "autoselection($system): $step=".((defined $e)?$e:'undef') ); + } + else { + is ( undef, $e, "autoselection($system): $step=".((defined $e)?$e:'undef') ); + } + } +} + +# Autoconf +touch "$tmpdir/configure", 0755; +touch "$builddir/Makefile"; +test_autoselection("autoconf", + { configure => "autoconf", build => "makefile", + test => "makefile", install => "makefile", clean => "makefile" }, %tmp); +cleandir $tmpdir; + +# Perl Makemaker (build, test, clean fail with builddir set [not supported]) +touch "$tmpdir/Makefile.PL"; +touch "$tmpdir/Makefile"; +test_autoselection("perl_makemaker", "perl_makemaker", %tmp); +cleandir $tmpdir; + +# Makefile +touch "$builddir/Makefile"; +test_autoselection("makefile", { build => "makefile", test => "makefile", + install => "makefile", clean => "makefile" }, %tmp); +cleandir $tmpdir; + +# Python Distutils +touch "$tmpdir/setup.py"; +test_autoselection("python_distutils", "python_distutils", %tmp); +cleandir $tmpdir; + +# Perl Build +touch "$tmpdir/Build.PL"; +touch "$tmpdir/Build"; +test_autoselection("perl_build", "perl_build", %tmp); +cleandir $tmpdir; + +# CMake +touch "$tmpdir/CMakeLists.txt"; +touch "$builddir/Makefile"; +test_autoselection("cmake", + { configure => "cmake", build => "makefile", + test => "makefile", install => "makefile", clean => "makefile" }, %tmp); +cleandir $tmpdir; + +### Test buildsystems_init() and commandline/env argument handling +sub get_load_bs_source { + my ($system, $step)=@_; + $step = (defined $step) ? "'$step'" : 'undef'; + $system = (defined $system) ? "'$system'" : 'undef'; + +return <<EOF; +use strict; +use warnings; +use Debian::Debhelper::Dh_Buildsystems; + +buildsystems_init(); +my \$bs = load_buildsystem($system, $step); +if (defined \$bs) { + print 'NAME=', \$bs->NAME(), "\\n"; + print \$_, "=", (defined \$bs->{\$_}) ? \$bs->{\$_} : 'undef', "\\n" + foreach (sort keys \%\$bs); +} +EOF +} + +is_deeply( process_stdout("$^X -- - --builddirectory='autoconf/bld dir' --sourcedirectory autoconf", + get_load_bs_source(undef, "configure")), + [ 'NAME=autoconf', 'builddir=autoconf/bld dir', 'makecmd=make', 'sourcedir=autoconf' ], + "autoconf autoselection and sourcedir/builddir" ); + +is_deeply( process_stdout("$^X -- - -Sautoconf -D autoconf", get_load_bs_source("autoconf", "build")), + [ 'NAME=autoconf', 'builddir=undef', 'makecmd=make', 'sourcedir=autoconf' ], + "forced autoconf and sourcedir" ); + +is_deeply( process_stdout("$^X -- - -B -Sautoconf", get_load_bs_source("autoconf", "build")), + [ 'NAME=autoconf', "builddir=$default_builddir", 'makecmd=make', 'sourcedir=.' ], + "forced autoconf and default build directory" ); + +# Build the autoconf test package +sub dh_auto_do_autoconf { + my $sourcedir=shift; + my $builddir=shift; + my %args=@_; + + my (@lines, @extra_args); + my $buildpath = $sourcedir; + my @dh_auto_args = ("-D", $sourcedir); + my $dh_auto_str = "-D $sourcedir"; + if ($builddir) { + push @dh_auto_args, "-B", $builddir; + $dh_auto_str .= " -B $builddir"; + $buildpath = $builddir; + } + + my $do_dh_auto = sub { + my $step=shift; + my @extra_args; + my $extra_str = ""; + if (exists $args{"${step}_args"}) { + push @extra_args, @{$args{"${step}_args"}}; + $extra_str .= " $_" foreach (@extra_args); + } + is ( system("$TOPDIR/dh_auto_$step", @dh_auto_args, "--", @extra_args), 0, + "dh_auto_$step $dh_auto_str$extra_str" ); + return @extra_args; + }; + + @extra_args = &$do_dh_auto('configure'); + ok ( -f "$buildpath/Makefile", "$buildpath/Makefile exists" ); + @lines=(); + if (ok( open(FILE, "$buildpath/stamp_configure"), "$buildpath/stamp_configure exists") ) { + @lines = @{readlines(\*FILE)}; + } + is_deeply( \@lines, \@extra_args, "$buildpath/stamp_configure contains extra args" ); + + &$do_dh_auto('build'); + ok ( -f "$buildpath/stamp_build", "$buildpath/stamp_build exists" ); + &$do_dh_auto('test'); + ok ( -f "$buildpath/stamp_test", "$buildpath/stamp_test exists" ); + &$do_dh_auto('install'); + @lines=(); + if ( ok(open(FILE, "$buildpath/stamp_install"), "$buildpath/stamp_install exists") ) { + @lines = @{readlines(\*FILE)}; + } + is_deeply( \@lines, [ "DESTDIR=".Cwd::getcwd()."/debian/testpackage" ], + "$buildpath/stamp_install contains DESTDIR" ); + &$do_dh_auto('clean'); + if ($builddir) { + ok ( ! -e "$buildpath", "builddir $buildpath was removed" ); + } + else { + ok ( ! -e "$buildpath/Makefile" && ! -e "$buildpath/stamp_configure", "Makefile and stamps gone" ); + } + ok ( -x "$sourcedir/configure", "configure script renamins after clean" ); +} + +dh_auto_do_autoconf('autoconf'); +dh_auto_do_autoconf('autoconf', 'bld/dir', configure_args => [ "--extra-autoconf-configure-arg" ]); +ok ( ! -e 'autoconf/bld', "autoconf/bld got deleted too" ); + +END { + system("rm", "-rf", $tmpdir); + system("$TOPDIR/dh_clean"); +} diff --git a/t/buildsystems/debian/changelog b/t/buildsystems/debian/changelog new file mode 100644 index 00000000..f902d892 --- /dev/null +++ b/t/buildsystems/debian/changelog @@ -0,0 +1,5 @@ +testpackage (1.0-1) unstable; urgency=low + + * Initial release. (Closes: #XXXXXX) + + -- Test <testing@nowhere> Tue, 09 Jun 2009 15:35:32 +0300 diff --git a/t/buildsystems/debian/compat b/t/buildsystems/debian/compat new file mode 100644 index 00000000..7f8f011e --- /dev/null +++ b/t/buildsystems/debian/compat @@ -0,0 +1 @@ +7 diff --git a/t/buildsystems/debian/control b/t/buildsystems/debian/control new file mode 100644 index 00000000..7edd806e --- /dev/null +++ b/t/buildsystems/debian/control @@ -0,0 +1,10 @@ +Source: testsrcpackage +Section: devel +Priority: optional +Maintainer: Test <testing@nowhere> +Standards-Version: 3.8.1 + +Package: testpackage +Architecture: all +Description: short description + Long description @@ -2,7 +2,7 @@ use Test; my @progs=grep { -x $_ } glob("dh_*"), "dh"; -my @libs=glob("Debian/Debhelper/*.pm"); +my @libs=(glob("Debian/Debhelper/*.pm"), glob("Debian/Debhelper/*/*.pm")); plan(tests => (@progs + @libs)); |