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 # Historical order must be kept for backwards compatibility. New
17 # buildsystems MUST be added to the END of the list.
31 sub create_buildsystem_instance {
34 my $module = "Debian::Debhelper::Buildsystem::$system";
38 error("unable to load buildsystem class '$system': $@");
41 if (!exists $bsopts{builddir} && defined $opt_builddir) {
42 $bsopts{builddir} = ($opt_builddir eq "") ? undef : $opt_builddir;
44 return $module->new(%bsopts);
47 sub load_buildsystem {
48 my ($action, $system)=@_;
49 if (defined $system) {
50 my $inst = create_buildsystem_instance($system);
51 verbose_print("Selected buildsystem (specified): ".$inst->NAME());
55 # Try to determine build system automatically
56 for $system (@BUILDSYSTEMS) {
57 my $inst = create_buildsystem_instance($system, build_action=>$action);
58 if ($inst->is_buildable()) {
59 verbose_print("Selected buildsystem (auto): ". $inst->NAME());
67 sub buildsystems_init {
70 # TODO: Not documented in the manual pages yet.
71 # Initialize options from environment variables
72 if (exists $ENV{DH_AUTO_BUILDDIRECTORY}) {
73 $opt_builddir = $ENV{DH_AUTO_BUILDDIRECTORY};
75 if (exists $ENV{DH_AUTO_BUILDSYSTEM}) {
76 $opt_buildsys = $ENV{DH_AUTO_BUILDSYSTEM};
79 # Available command line options
81 "b:s" => \$opt_builddir,
82 "builddirectory:s" => \$opt_builddir,
84 "m=s" => \$opt_buildsys,
85 "buildsystem=s" => \$opt_buildsys,
88 "--list" => \$opt_list,
90 map { $args{options}{$_} = $options{$_} } keys(%options);
91 Debian::Debhelper::Dh_Lib::init(%args);
97 if (!defined $action) {
98 $action = basename($0);
99 $action =~ s/^dh_auto_//;
102 if (grep(/^\Q$action\E$/, qw{configure build test install clean}) == 0) {
103 error("unrecognized build action: " . $action);
107 # List buildsystems (including auto and specified status)
110 print "STATUS (* auto, + specified) NAME - DESCRIPTION", "\n";
111 for my $system (@BUILDSYSTEMS) {
112 my $inst = create_buildsystem_instance($system, build_action => undef);
113 my $is_specified = defined $opt_buildsys && $opt_buildsys eq $inst->NAME();
117 $specified_found = 1;
119 elsif (!$auto_found && $inst->check_auto_buildable($action)) {
126 printf("%s %s - %s.\n", $status, $inst->NAME(), $inst->DESCRIPTION());
128 # List a 3rd party buildsystem too.
129 if (!$specified_found && defined $opt_buildsys) {
130 my $inst = create_buildsystem_instance($opt_buildsys, build_action => undef);
131 printf("+ %s - %s.\n", $inst->NAME(), $inst->DESCRIPTION());
136 my $buildsystem = load_buildsystem($action, $opt_buildsys);
137 if (defined $buildsystem) {
138 $buildsystem->pre_action($action);
139 $buildsystem->$action(@_, @{$dh{U_PARAMS}});
140 $buildsystem->post_action($action);