]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Dh_Buildsystems.pm
Merge commit 'remotes/modestas/buildsystems' into buildsystems
[debhelper.git] / Debian / Debhelper / Dh_Buildsystems.pm
index 8e9920f1f21b533e66c310e0f2ec14ce016dde2e..3b150bd11062bbf8b325ef3bf362c24a8c691815 100644 (file)
@@ -1,5 +1,5 @@
-# A module for loading and managing debhelper buildsystem plugins.
-# This module is intended to be used by all dh_auto_* helper commands.
+# A module for loading and managing debhelper build system class.
+# This module is intended to be used by all dh_auto_* programs.
 #
 # Copyright: © 2009 Modestas Vainius
 # License: GPL-2+
@@ -15,7 +15,7 @@ use base 'Exporter';
 our @EXPORT=qw(&buildsystems_init &buildsystems_do &load_buildsystem &load_all_buildsystems);
 
 # Historical order must be kept for backwards compatibility. New
-# buildsystems MUST be added to the END of the list.
+# build systems MUST be added to the END of the list.
 our @BUILDSYSTEMS = (
     "autoconf",
     "perl_makemaker",
@@ -29,6 +29,7 @@ my $opt_buildsys;
 my $opt_sourcedir;
 my $opt_builddir;
 my $opt_list;
+my $opt_help_buildsys;
 
 sub create_buildsystem_instance {
        my $system=shift;
@@ -37,7 +38,7 @@ sub create_buildsystem_instance {
 
        eval "use $module";
        if ($@) {
-               error("unable to load buildsystem class '$system': $@");
+               error("unable to load build system class '$system': $@");
        }
 
        if (!exists $bsopts{builddir} && defined $opt_builddir) {
@@ -49,8 +50,8 @@ sub create_buildsystem_instance {
        return $module->new(%bsopts);
 }
 
-# Similar to create_buildsystem_instance(), but it attempts to autoselect
-# a buildsystem if none was specified. In case autoselection fails, undef
+# Similar to create_build system_instance(), but it attempts to autoselect
+# a build system if none was specified. In case autoselection fails, undef
 # is returned.
 sub load_buildsystem {
        my $system=shift;
@@ -87,15 +88,15 @@ sub load_all_buildsystems {
                }
        }
 
-       # Push debhelper built-in buildsystems first
+       # Push standard debhelper build systems first
        for my $name (@BUILDSYSTEMS) {
-               error("Debhelper built-in buildsystem '$name' could not be found/loaded")
+               error("standard debhelper build system '$name' could not be found/loaded")
                    if not exists $buildsystems{$name};
                push @buildsystems, $buildsystems{$name};
                delete $buildsystems{$name};
        }
 
-       # The rest are 3rd party buildsystems
+       # The rest are 3rd party build systems
        for my $name (keys %buildsystems) {
                my $inst = $buildsystems{$name};
                $inst->{thirdparty} = 1;
@@ -110,32 +111,28 @@ sub buildsystems_init {
 
        # Available command line options
        my %options = (
-           "d" => undef, # cancel default D_FLAG option spec
-           "d=s" => \$opt_sourcedir,
+           "D=s" => \$opt_sourcedir,
            "sourcedirectory=s" => \$opt_sourcedir,
        
-           "b:s" => \$opt_builddir,
+           "B:s" => \$opt_builddir,
            "builddirectory:s" => \$opt_builddir,
 
-           "c=s" => \$opt_buildsys,
+           "S=s" => \$opt_buildsys,
            "buildsystem=s" => \$opt_buildsys,
 
            "l" => \$opt_list,
-           "--list" => \$opt_list,
+           "list" => \$opt_list,
+
+           "help-buildsystem" => \$opt_help_buildsys,
        );
        $args{options}{$_} = $options{$_} foreach keys(%options);
-
-       # Pass options from the DH_AUTO_OPTIONS environment variable
-       if (defined $ENV{DH_AUTO_OPTIONS}) {
-               $args{extra_args} = $ENV{DH_AUTO_OPTIONS};
-       }
        Debian::Debhelper::Dh_Lib::init(%args);
 }
 
 sub buildsystems_list {
        my $step=shift;
 
-       # List buildsystems (including auto and specified status)
+       # List build systems (including auto and specified status)
        my ($auto, $specified);
        my @buildsystems = load_all_buildsystems();
        for my $inst (@buildsystems) {
@@ -157,6 +154,50 @@ sub buildsystems_list {
                if ! defined $auto && ! defined $specified;
 }
 
+sub help_buildsystem {
+       my $step=shift;
+
+       # Print build system help page to standard output
+
+       my $inst = load_buildsystem($opt_buildsys, $step);
+       if ($inst) {
+               my $pmfile = ref $inst;
+               $pmfile =~ s#::#/#g;
+               $pmfile = $INC{"$pmfile.pm"};
+
+               # Display help with perldoc if it is installed and output is
+               # a tty
+               my $perldoc;
+               if (-t STDOUT) {
+                       eval "use Pod::Perldoc";
+                       $perldoc = "Pod::Perldoc" if (!$@);
+               }
+               if ($perldoc) {
+                       $perldoc = new Pod::Perldoc();
+                       $perldoc->{args} = [ '-oman',
+                                            '-w', 'section=7" "--name=dh_auto_'.lc($inst->NAME()),
+                                            '-w', 'center=Dh_auto build system documentation',
+                                            '-w', 'release=',
+                                            '-F', $pmfile ];
+                       $perldoc->process();
+               }
+               else {
+                       # No perldoc on the system. Use Pod::Usage to emit simple text
+                       eval "use Pod::Usage";
+                       pod2usage( -message => "Help page for the ".$inst->NAME()." build system\n" .
+                                              '<' . '-'x74 . '>',
+                                  -input => $pmfile, -exitval => 'NOEXIT',
+                                  -verbose => 2, -noperldoc => 1 );
+                       print '<', '-'x74, '>', "\n";
+               }
+               return 0;
+       }
+       else {
+               print STDERR "No system auto-selected or specified. Try using --buildsystem option\n";
+               return 1;
+       }
+}
+
 sub buildsystems_do {
        my $step=shift;
 
@@ -174,6 +215,10 @@ sub buildsystems_do {
                exit 0;
        }
 
+       if ($opt_help_buildsys) {
+               exit help_buildsystem($step);
+       }
+
        my $buildsystem = load_buildsystem($opt_buildsys, $step);
        if (defined $buildsystem) {
                $buildsystem->pre_building_step($step);