1 # A module for loading and managing debhelper buildsystem plugins.
2 # This module is intended to be used by all dh_auto_* helper commands.
4 # Copyright: © 2009 Modestas Vainius
7 package Debian::Debhelper::Dh_Buildsystems;
11 use Debian::Debhelper::Dh_Lib;
14 our @EXPORT=qw(&buildsystems_init &buildsystems_do &load_buildsystem);
16 # XXX JEH as noted, this has to match historical order for back-compat
17 # XXX MDX Current dh_auto_* look like:
18 # configure: autotools, perl_makemaker, perl_build
19 # build: makefile, python_distutils, perl_build
20 # test: makefile, perl_build
21 # install: makefile (with perl_makermaker) hack, python_distutils, perl_build
22 # clean: makefile, python_distutils, perl_build
23 # So historical @BUILDSYSTEMS order (as per autodetection, see
24 # is_auto_buildable() of the respective classes):
25 # autotools (+configure; the rest - next class)
26 # python_distutils (+build +install +clean; the rest - next class)
27 # perl_makemaker (+configure +install (special hack); the rest - next class)
28 # makefile (+build +test +install +clean; configure - next class)
29 # perl_build (handles everything)
30 # XXX JEH I think that makes sense..
32 # Historical order must be kept for backwards compatibility. New
33 # buildsystems MUST be added to the END of the list.
43 sub create_buildsystem_instance {
46 my $module = "Debian::Debhelper::Buildsystem::$system";
50 error("unable to load buildsystem class '$system': $@");
53 if (!exists $bsopts{builddir} && exists $dh{BUILDDIR}) {
54 $bsopts{builddir} = $dh{BUILDDIR};
56 return $module->new(%bsopts);
59 sub load_buildsystem {
60 my ($action, $system)=@_;
61 if (defined $system) {
62 my $inst = create_buildsystem_instance($system);
63 verbose_print("Selected buildsystem (specified): ".$inst->NAME());
67 # Try to determine build system automatically
68 for $system (@BUILDSYSTEMS) {
69 my $inst = create_buildsystem_instance($system, is_auto=>1);
70 if ($inst->is_auto_buildable($action)) {
71 verbose_print("Selected buildsystem (auto): ". $inst->NAME());
79 sub list_buildsystems {
80 for my $system (@BUILDSYSTEMS) {
81 my $inst = create_buildsystem_instance($system);
82 printf("%s - %s.\n", $inst->NAME(), $inst->DESCRIPTION());
86 sub buildsystems_init {
89 # TODO: Not documented in the manual pages yet.
90 # Initialize options from environment variables
91 # XXX JEH I think these should be my variables, they are only used
92 # inside this one file so putting them in the global %dh hash seems
94 if (exists $ENV{DH_AUTO_BUILDDIRECTORY}) {
95 $dh{BUILDDIR} = $ENV{DH_AUTO_BUILDDIRECTORY};
97 if (exists $ENV{DH_AUTO_BUILDSYSTEM}) {
98 $dh{BUILDSYS} = $ENV{DH_AUTO_BUILDSYSTEM};
101 # Available command line options
102 my $list_bs = sub { list_buildsystems(); exit 0 };
103 my $set_builddir = sub { $dh{BUILDDIR} = $_[1] };
105 "b:s" => $set_builddir,
106 "build-directory:s" => $set_builddir,
107 "builddirectory:s" => $set_builddir,
109 "m=s" => \$dh{BUILDSYS},
110 # XXX JEH Let's only keep one spelling of this.
111 "build-system=s" => \$dh{BUILDSYS},
112 "buildsystem=s" => \$dh{BUILDSYS},
115 "--list" => $list_bs,
117 map { $args{options}{$_} = $options{$_} } keys(%options);
118 Debian::Debhelper::Dh_Lib::init(%args);
121 sub buildsystems_do {
124 if (!defined $action) {
125 $action = basename($0);
126 $action =~ s/^dh_auto_//;
129 if (grep(/^\Q$action\E$/, qw{configure build test install clean}) == 0) {
130 error("unrecognized auto action: ".basename($0));
133 my $buildsystem = load_buildsystem($action, $dh{BUILDSYS});
134 if (defined $buildsystem) {
135 $buildsystem->pre_action($action);
136 $buildsystem->$action(@_, @{$dh{U_PARAMS}});
137 $buildsystem->post_action($action);