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);
54 # Try to determine build system automatically
55 for $system (@BUILDSYSTEMS) {
56 my $inst = create_buildsystem_instance($system, build_action=>$action);
57 if ($inst->is_buildable()) {
65 sub buildsystems_init {
68 # TODO: Not documented in the manual pages yet.
69 # Initialize options from environment variables
70 if (exists $ENV{DH_AUTO_BUILDDIRECTORY}) {
71 $opt_builddir = $ENV{DH_AUTO_BUILDDIRECTORY};
73 if (exists $ENV{DH_AUTO_BUILDSYSTEM}) {
74 $opt_buildsys = $ENV{DH_AUTO_BUILDSYSTEM};
77 # Available command line options
79 "b:s" => \$opt_builddir,
80 "builddirectory:s" => \$opt_builddir,
82 "m=s" => \$opt_buildsys,
83 "buildsystem=s" => \$opt_buildsys,
86 "--list" => \$opt_list,
88 map { $args{options}{$_} = $options{$_} } keys(%options);
89 Debian::Debhelper::Dh_Lib::init(%args);
92 sub buildsystems_list {
95 # List buildsystems (including auto and specified status)
96 my ($auto, $specified);
97 for my $system (@BUILDSYSTEMS) {
98 my $inst = create_buildsystem_instance($system, build_action => undef);
99 my $is_specified = defined $opt_buildsys && $opt_buildsys eq $inst->NAME();
100 if (! defined $specified && defined $opt_buildsys && $opt_buildsys eq $inst->NAME()) {
101 $specified = $inst->NAME();
103 elsif (! defined $auto && $inst->check_auto_buildable($action)) {
104 $auto = $inst->NAME();
106 printf("%s - %s\n", $inst->NAME(), $inst->DESCRIPTION());
108 # List a specified 3rd party buildsystem too.
109 if (! defined $specified && defined $opt_buildsys) {
110 my $inst = create_buildsystem_instance($opt_buildsys, build_action => undef);
111 printf("%s - %s.\n", $inst->NAME(), $inst->DESCRIPTION());
112 $specified = $inst->NAME();
115 print "Auto-selected: $auto\n" if defined $auto;
116 print "Specified: $specified\n" if defined $specified;
117 print "No system auto-selected or specified\n"
118 if ! defined $auto && ! defined $specified;
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 build action: " . $action);
134 buildsystems_list($action);
138 my $buildsystem = load_buildsystem($action, $opt_buildsys);
139 if (defined $buildsystem) {
140 $buildsystem->pre_action($action);
141 $buildsystem->$action(@_, @{$dh{U_PARAMS}});
142 $buildsystem->post_action($action);