diff options
Diffstat (limited to 'Debian/Debhelper/Buildsystem')
-rw-r--r-- | Debian/Debhelper/Buildsystem/autoconf.pm | 55 | ||||
-rw-r--r-- | Debian/Debhelper/Buildsystem/cmake.pm | 45 | ||||
-rw-r--r-- | Debian/Debhelper/Buildsystem/makefile.pm | 95 | ||||
-rw-r--r-- | Debian/Debhelper/Buildsystem/perl_build.pm | 67 | ||||
-rw-r--r-- | Debian/Debhelper/Buildsystem/perl_makemaker.pm | 64 | ||||
-rw-r--r-- | Debian/Debhelper/Buildsystem/python_distutils.pm | 109 |
6 files changed, 435 insertions, 0 deletions
diff --git a/Debian/Debhelper/Buildsystem/autoconf.pm b/Debian/Debhelper/Buildsystem/autoconf.pm new file mode 100644 index 00000000..60fa9e85 --- /dev/null +++ b/Debian/Debhelper/Buildsystem/autoconf.pm @@ -0,0 +1,55 @@ +# A debhelper build system class for handling Autoconf based projects +# +# Copyright: © 2008 Joey Hess +# © 2008-2009 Modestas Vainius +# License: GPL-2+ + +package Debian::Debhelper::Buildsystem::autoconf; + +use strict; +use Debian::Debhelper::Dh_Lib qw(dpkg_architecture_value sourcepackage); +use base 'Debian::Debhelper::Buildsystem::makefile'; + +sub DESCRIPTION { + "GNU Autoconf (configure)" +} + +sub check_auto_buildable { + my $this=shift; + my ($step)=@_; + + # Handle configure; the rest - next class + if ($step eq "configure") { + return -x $this->get_sourcepath("configure"); + } + return 0; +} + +sub configure { + my $this=shift; + + # Standard set of options for configure. + my @opts; + push @opts, "--build=" . dpkg_architecture_value("DEB_BUILD_GNU_TYPE"); + push @opts, "--prefix=/usr"; + push @opts, "--includedir=\${prefix}/include"; + push @opts, "--mandir=\${prefix}/share/man"; + push @opts, "--infodir=\${prefix}/share/info"; + push @opts, "--sysconfdir=/etc"; + push @opts, "--localstatedir=/var"; + push @opts, "--libexecdir=\${prefix}/lib/" . sourcepackage(); + push @opts, "--disable-maintainer-mode"; + push @opts, "--disable-dependency-tracking"; + # Provide --host only if different from --build, as recommended in + # autotools-dev README.Debian: When provided (even if equal) + # autoconf 2.52+ switches to cross-compiling mode. + if (dpkg_architecture_value("DEB_BUILD_GNU_TYPE") + ne dpkg_architecture_value("DEB_HOST_GNU_TYPE")) { + push @opts, "--host=" . dpkg_architecture_value("DEB_HOST_GNU_TYPE"); + } + + $this->mkdir_builddir(); + $this->doit_in_builddir($this->get_source_rel2builddir("configure"), @opts, @_); +} + +1; diff --git a/Debian/Debhelper/Buildsystem/cmake.pm b/Debian/Debhelper/Buildsystem/cmake.pm new file mode 100644 index 00000000..56628740 --- /dev/null +++ b/Debian/Debhelper/Buildsystem/cmake.pm @@ -0,0 +1,45 @@ +# A debhelper build system class for handling CMake based projects. +# It prefers out of source tree building. +# +# Copyright: © 2008-2009 Modestas Vainius +# License: GPL-2+ + +package Debian::Debhelper::Buildsystem::cmake; + +use strict; +use base 'Debian::Debhelper::Buildsystem::makefile'; + +sub DESCRIPTION { + "CMake (CMakeLists.txt)" +} + +sub check_auto_buildable { + my $this=shift; + my ($step)=@_; + my $ret = -e $this->get_sourcepath("CMakeLists.txt"); + $ret &&= $this->SUPER::check_auto_buildable(@_) if $step ne "configure"; + return $ret; +} + +sub new { + my $class=shift; + my $this=$class->SUPER::new(@_); + # Prefer out of source tree building. + $this->enforce_out_of_source_building(@_); + return $this; +} + +sub configure { + my $this=shift; + my @flags; + + # Standard set of cmake flags + push @flags, "-DCMAKE_INSTALL_PREFIX=/usr"; + push @flags, "-DCMAKE_SKIP_RPATH=ON"; + push @flags, "-DCMAKE_VERBOSE_MAKEFILE=ON"; + + $this->mkdir_builddir(); + $this->doit_in_builddir("cmake", $this->get_source_rel2builddir(), @flags); +} + +1; diff --git a/Debian/Debhelper/Buildsystem/makefile.pm b/Debian/Debhelper/Buildsystem/makefile.pm new file mode 100644 index 00000000..d84d3349 --- /dev/null +++ b/Debian/Debhelper/Buildsystem/makefile.pm @@ -0,0 +1,95 @@ +# A debhelper build system class for handling simple Makefile based projects. +# +# Copyright: © 2008 Joey Hess +# © 2008-2009 Modestas Vainius +# License: GPL-2+ + +package Debian::Debhelper::Buildsystem::makefile; + +use strict; +use Debian::Debhelper::Dh_Lib qw(escape_shell); +use base 'Debian::Debhelper::Buildsystem'; + +sub get_makecmd_C { + my $this=shift; + my $buildpath = $this->get_buildpath(); + if ($buildpath ne '.') { + return $this->{makecmd} . " -C " . escape_shell($buildpath); + } + return $this->{makecmd}; +} + +sub exists_make_target { + my ($this, $target) = @_; + my $makecmd=$this->get_makecmd_C(); + + # Use make -n to check to see if the target would do + # anything. There's no good way to test if a target exists. + my $ret=`$makecmd -s -n --no-print-directory $target 2>/dev/null`; + chomp $ret; + return length($ret); +} + +sub make_first_existing_target { + my $this=shift; + my $targets=shift; + + foreach my $target (@$targets) { + if ($this->exists_make_target($target)) { + $this->doit_in_builddir($this->{makecmd}, $target, @_); + return $target; + } + } + return undef; +} + +sub DESCRIPTION { + "simple Makefile" +} + +sub new { + my $class=shift; + my $this=$class->SUPER::new(@_); + $this->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make"; + return $this; +} + +sub check_auto_buildable { + my $this=shift; + my ($step) = @_; + + # Handles build, test, install, clean; configure - next class + if (grep /^\Q$step\E$/, qw{build test install clean}) { + # This is always called in the source directory, but generally + # Makefiles are created (or live) in the the build directory. + return -e $this->get_buildpath("Makefile") || + -e $this->get_buildpath("makefile") || + -e $this->get_buildpath("GNUmakefile"); + } + return 0; +} + +sub build { + my $this=shift; + $this->doit_in_builddir($this->{makecmd}, @_); +} + +sub test { + my $this=shift; + $this->make_first_existing_target(['test', 'check'], @_); +} + +sub install { + my $this=shift; + my $destdir=shift; + $this->make_first_existing_target(['install'], "DESTDIR=$destdir", @_); +} + +sub clean { + my $this=shift; + if (!$this->rmdir_builddir()) { + $this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_); + } +} + +1; diff --git a/Debian/Debhelper/Buildsystem/perl_build.pm b/Debian/Debhelper/Buildsystem/perl_build.pm new file mode 100644 index 00000000..3567cb1a --- /dev/null +++ b/Debian/Debhelper/Buildsystem/perl_build.pm @@ -0,0 +1,67 @@ +# A build system class for handling Perl Build based projects. +# +# Copyright: © 2008-2009 Joey Hess +# © 2008-2009 Modestas Vainius +# License: GPL-2+ + +package Debian::Debhelper::Buildsystem::perl_build; + +use strict; +use base 'Debian::Debhelper::Buildsystem'; + +sub DESCRIPTION { + "Perl Module::Build (Build.PL)" +} + +sub check_auto_buildable { + my ($this, $step) = @_; + + # Handles everything + my $ret = -e $this->get_sourcepath("Build.PL"); + if ($step ne "configure") { + $ret &&= -e $this->get_sourcepath("Build"); + } + return $ret; +} + +sub do_perl { + my $this=shift; + $ENV{MODULEBUILDRC} = "/dev/null"; + $this->doit_in_sourcedir("perl", @_); +} + +sub new { + my $class=shift; + my $this= $class->SUPER::new(@_); + $this->enforce_in_source_building(); + return $this; +} + +sub configure { + my $this=shift; + $ENV{PERL_MM_USE_DEFAULT}=1; + $this->do_perl("Build.PL", "installdirs=vendor", @_); +} + +sub build { + my $this=shift; + $this->do_perl("Build", @_); +} + +sub test { + my $this=shift; + $this->do_perl("Build", "test", @_); +} + +sub install { + my $this=shift; + my $destdir=shift; + $this->do_perl("Build", "install", "destdir=$destdir", "create_packlist=0", @_); +} + +sub clean { + my $this=shift; + $this->do_perl("Build", "--allow_mb_mismatch", 1, "distclean", @_); +} + +1; diff --git a/Debian/Debhelper/Buildsystem/perl_makemaker.pm b/Debian/Debhelper/Buildsystem/perl_makemaker.pm new file mode 100644 index 00000000..07a827ac --- /dev/null +++ b/Debian/Debhelper/Buildsystem/perl_makemaker.pm @@ -0,0 +1,64 @@ +# A debhelper build system class for handling Perl MakeMaker based projects. +# +# Copyright: © 2008-2009 Joey Hess +# © 2008-2009 Modestas Vainius +# License: GPL-2+ + +package Debian::Debhelper::Buildsystem::perl_makemaker; + +use strict; +use base 'Debian::Debhelper::Buildsystem::makefile'; + +sub DESCRIPTION { + "Perl ExtUtils::MakeMaker (Makefile.PL)" +} + +sub check_auto_buildable { + my $this=shift; + my ($step)=@_; + + # Handles everything if Makefile.PL exists. Otherwise - next class. + if (-e $this->get_sourcepath("Makefile.PL")) { + if ($step eq "install" || $step eq "configure") { + return 1; + } + else { + # This is backwards compatible (with << 7.3) until build, test and + # clean steps are not reimplemented in the backwards compatibility + # breaking way. However, this is absolutely necessary for + # enforce_in_source_building() to work in corner cases in build, + # test and clean steps as the next class (makefile) does not + # enforce it. + return $this->SUPER::check_auto_buildable(@_); + } + } + return 0; +} + +sub new { + my $class=shift; + my $this=$class->SUPER::new(@_); + $this->enforce_in_source_building(); + return $this; +} + +sub configure { + my $this=shift; + # If set to a true value then MakeMaker's prompt function will + # # always return the default without waiting for user input. + $ENV{PERL_MM_USE_DEFAULT}=1; + # This prevents Module::Install from interactive behavior. + $ENV{PERL_AUTOINSTALL}="--skipdeps"; + + $this->doit_in_sourcedir("perl", "Makefile.PL", "INSTALLDIRS=vendor", + "create_packlist=0", + @_); +} + +sub install { + my $this=shift; + my $destdir=shift; + $this->SUPER::install($destdir, "PREFIX=/usr", @_); +} + +1; diff --git a/Debian/Debhelper/Buildsystem/python_distutils.pm b/Debian/Debhelper/Buildsystem/python_distutils.pm new file mode 100644 index 00000000..46f4c1c1 --- /dev/null +++ b/Debian/Debhelper/Buildsystem/python_distutils.pm @@ -0,0 +1,109 @@ +# A debhelper build system class for building Python Distutils based +# projects. It prefers out of source tree building. +# +# Copyright: © 2008 Joey Hess +# © 2008-2009 Modestas Vainius +# License: GPL-2+ + +package Debian::Debhelper::Buildsystem::python_distutils; + +use strict; +use Cwd (); +use Debian::Debhelper::Dh_Lib qw(error); +use base 'Debian::Debhelper::Buildsystem'; + +sub DESCRIPTION { + "Python Distutils (setup.py)" +} + +sub DEFAULT_BUILD_DIRECTORY { + my $this=shift; + return $this->_canonpath($this->get_sourcepath("build")); +} + +sub new { + my $class=shift; + my $this=$class->SUPER::new(@_); + # Out of source tree building is prefered. + $this->enforce_out_of_source_building(@_); + return $this; +} + +sub check_auto_buildable { + my $this=shift; + return -e $this->get_sourcepath("setup.py"); +} + +sub not_our_cfg { + my $this=shift; + my $ret; + if (open(my $cfg, $this->get_buildpath(".pydistutils.cfg"))) { + $ret = not "# Created by dh_auto\n" eq <$cfg>; + close $cfg; + } + return $ret; +} + +sub create_cfg { + my $this=shift; + if (open(my $cfg, ">", $this->get_buildpath(".pydistutils.cfg"))) { + print $cfg "# Created by dh_auto", "\n"; + print $cfg "[build]\nbuild-base=", $this->get_build_rel2sourcedir(), "\n"; + close $cfg; + return 1; + } + return 0; +} + +sub pre_building_step { + my $this=shift; + my $step=shift; + + return unless grep /$step/, qw(build install clean); + + # --build-base can only be passed to the build command. However, + # it is always read from the config file (really weird design). + # Therefore create such a cfg config file. + if ($this->get_buildpath() ne $this->DEFAULT_BUILD_DIRECTORY()) { + not $this->not_our_cfg() or + error("cannot set custom build directory: .pydistutils.cfg is in use"); + $this->mkdir_builddir(); + $this->create_cfg() or + error("cannot set custom build directory: unwritable .pydistutils.cfg"); + # Distutils reads $HOME/.pydistutils.cfg + $ENV{HOME} = Cwd::abs_path($this->get_buildpath()); + } +} + +sub setup_py { + my $this=shift; + my $act=shift; + $this->doit_in_sourcedir("python", "setup.py", $act, @_); +} + +sub build { + my $this=shift; + $this->setup_py("build", @_); +} + +sub install { + my $this=shift; + my $destdir=shift; + $this->setup_py("install", "--root=$destdir", "--no-compile", "-O0", @_); +} + +sub clean { + my $this=shift; + $this->setup_py("clean", "-a", @_); + + # Config file will remain if it was created by us + if (!$this->not_our_cfg()) { + unlink($this->get_buildpath(".pydistutils.cfg")); + $this->rmdir_builddir(1); # only if empty + } + # The setup.py might import files, leading to python creating pyc + # files. + $this->doit_in_sourcedir('find', '.', '-name', '*.pyc', '-exec', 'rm', '{}', ';'); +} + +1; |