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 ($step, $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_step=>$step);
57 if ($inst->is_buildable()) {
65 sub buildsystems_init {
68 # Available command line options
70 "b:s" => \$opt_builddir,
71 "builddirectory:s" => \$opt_builddir,
73 "c=s" => \$opt_buildsys,
74 "buildsystem=s" => \$opt_buildsys,
77 "--list" => \$opt_list,
79 $args{options}{$_} = $options{$_} foreach keys(%options);
81 # Pass options from the DH_AUTO_OPTIONS environment variable
82 if (defined $ENV{DH_AUTO_OPTIONS}) {
83 $args{extra_args} = $ENV{DH_AUTO_OPTIONS};
85 Debian::Debhelper::Dh_Lib::init(%args);
88 sub buildsystems_list {
91 # List buildsystems (including auto and specified status)
92 my ($auto, $specified);
93 for my $system (@BUILDSYSTEMS) {
94 my $inst = create_buildsystem_instance($system, build_step => undef);
95 my $is_specified = defined $opt_buildsys && $opt_buildsys eq $inst->NAME();
96 if (! defined $specified && defined $opt_buildsys && $opt_buildsys eq $inst->NAME()) {
97 $specified = $inst->NAME();
99 elsif (! defined $auto && $inst->check_auto_buildable($step)) {
100 $auto = $inst->NAME();
102 printf("%s - %s\n", $inst->NAME(), $inst->DESCRIPTION());
104 # List a specified 3rd party buildsystem too.
105 if (! defined $specified && defined $opt_buildsys) {
106 my $inst = create_buildsystem_instance($opt_buildsys, build_step => undef);
107 printf("%s - %s.\n", $inst->NAME(), $inst->DESCRIPTION());
108 $specified = $inst->NAME();
111 print "Auto-selected: $auto\n" if defined $auto;
112 print "Specified: $specified\n" if defined $specified;
113 print "No system auto-selected or specified\n"
114 if ! defined $auto && ! defined $specified;
117 sub buildsystems_do {
120 if (!defined $step) {
121 $step = basename($0);
122 $step =~ s/^dh_auto_//;
125 if (grep(/^\Q$step\E$/, qw{configure build test install clean}) == 0) {
126 error("unrecognized build step: " . $step);
130 buildsystems_list($step);
134 my $buildsystem = load_buildsystem($step, $opt_buildsys);
135 if (defined $buildsystem) {
136 $buildsystem->pre_step($step);
137 $buildsystem->$step(@_, @{$dh{U_PARAMS}});
138 $buildsystem->post_step($step);