8 if (!exists $parser->{_stripped_}) {
9 $parser->{_stripped_} = 1;
12 return $parser->SUPER::command(@_);
19 use Debian::Debhelper::Dh_Lib;
20 use Debian::Debhelper::Dh_Buildsystems;
24 use Pod::InputObjects;
27 my $DH_AUTO_POD = "dh_auto.pod";
29 # Preloads build system PODs
30 sub get_buildsystem_pods {
31 my $parser = new Pod::Select();
32 if (!@buildsystem_pods) {
33 my @buildsystems = load_all_buildsystems([ "." ]);
34 for my $system (@buildsystems) {
35 my $podfile = File::Spec->catfile("Debian/Debhelper/Buildsystem", $system->NAME() . ".pm");
36 my $iostr = new IO::String();
38 open(my $fh, $podfile) or error("Unable to read $podfile");
39 $system->{pod_fh} = $fh;
41 # Extract build system name from POD
42 $parser->select('NAME');
43 strip_first_command($parser, $fh, $iostr);
45 # Remove empty lines and join new lines
46 $system->{pod_name} = join(" ", grep ! /^\s*$/, split(/\n/, ${$iostr->string_ref()}));
48 push @buildsystem_pods, $system;
51 return @buildsystem_pods;
54 # Strips the first command (i.e. line starting with =), prints
56 sub strip_first_command {
57 my ($parser, $input_fh, $output_fh)=@_;
59 my $iostr = new IO::String();
60 seek(\*$input_fh, 0, 0);
61 $parser->parse_from_filehandle($input_fh, $iostr);
63 CommandStrip->new()->parse_from_filehandle($iostr, $output_fh);
68 sub print_everything {
69 my ($parser, $input_fh, $output_fh)=@_;
70 seek(\*$input_fh, 0, 0);
71 $parser->parse_from_filehandle($input_fh, $output_fh);
74 # Prints POD paragraph
75 # Common parameters -name, -text. Results into =${-name} ${-text}
78 my $output_fh = $args{output} || \*STDOUT;
79 print $output_fh Pod::Paragraph->new(@_)->raw_text(), "\n\n";
83 # my ($authors, $parser, $fh)=@_;
84 # my $iostr = new IO::String();
86 # $parser->select('AUTHOR[^\s]*');
88 # strip_first_command($parser, $fh, $iostr);
90 # while (my $author = <$iostr>) {
91 # $author =~ s/\s+/ /g;
92 # $author =~ s/^\s+//;
93 # $author =~ s/\s+$//;
94 # $authors->{$author} = scalar(keys %$authors)
95 # if !exists $authors->{$author};
100 ############# Generation of dh_auto_step POD #############
102 sub get_dh_auto_shared_options_for_step {
104 my $parser = new Pod::Select();
105 my $iostr = new IO::String();
107 $parser->select('DH_AUTO SHARED OPTIONS');
108 print_everything($parser, \*DH_AUTO, $iostr);
109 return ${$iostr->string_ref()};
112 sub get_supported_buildsystems_intro_for_step {
114 my $parser = new Pod::Select();
115 my $iostr = new IO::String();
117 # A common "SUPPORTED BUILD SYSTEMS" dh_auto POD
118 $parser->select('#SUPPORTED BUILD SYSTEMS INTRO FOR DH_AUTO PROGRAMS');
119 strip_first_command($parser, \*DH_AUTO, $iostr);
120 return ${$iostr->string_ref()};
123 sub get_supported_buildsystems_list_for_step {
125 my $parser = new Pod::Select();
126 my $iostr = new IO::String();
128 # Append build system list from build system PODs
129 for my $bs (get_buildsystem_pods()) {
130 my $bs_fh = $bs->{pod_fh};
132 # =head2 Build system name
133 print_pod_parag(output => $iostr, -name => 'head2', -text => $bs->{pod_name});
135 # Now print DH_AUTO NOTES
136 $parser->select('DH_AUTO NOTES');
137 strip_first_command($parser, $bs_fh, $iostr);
139 # And step specific help follows
140 $parser->select('BUILD PROCESS/' . ucfirst($step) . " step");
141 strip_first_command($parser, $bs_fh, $iostr);
143 return ${$iostr->string_ref()};
146 sub generate_step_pod {
148 $step = $1 if ($step =~ /dh_auto_(.*)$/);
150 my $dh_auto_step = "dh_auto_$step";
151 my $dh_auto_shared_options = get_dh_auto_shared_options_for_step($step);
152 my $supported_bs_intro = get_supported_buildsystems_intro_for_step($step);
153 my $supported_bs_list = get_supported_buildsystems_list_for_step($step);
154 open(DH_AUTO_STEP, "podselect $dh_auto_step |")
155 or error("Unable to read $dh_auto_step");
156 while (<DH_AUTO_STEP>) {
157 s/#DH_AUTO SHARED OPTIONS#/$dh_auto_shared_options/;
158 s/#SUPPORTED BUILD SYSTEMS INTRO#/$supported_bs_intro/;
159 s/#SUPPORTED BUILD SYSTEMS LIST#/$supported_bs_list/;
165 ############# Generation of dh_auto POD #############
167 sub get_dh_auto_program_list_for_dh_auto {
169 my $parser = new Pod::Select();
172 $parser->select('NAME');
173 foreach my $step (@steps) {
174 my $iostr = new IO::String();
175 open (my $fh, "dh_auto_$step") or die "$_: $!";
176 strip_first_command($parser, $fh, $iostr);
178 if (${$iostr->string_ref()} =~ /^(.*?) - (.*)/) {
179 $collect .= "=item $1(1)\n\n$2\n\n";
185 sub get_supported_buildsystems_for_dh_auto {
186 my $parser = new Pod::Select();
187 my $iostr = new IO::String();
189 # Build system list from build system PODs (NAME + DESCRIPTION)
190 for my $bs (sort { $a->NAME() cmp $b->NAME() } get_buildsystem_pods()) {
191 my $bs_fh = $bs->{pod_fh};
193 # =head2 Build system name
194 print_pod_parag(output => $iostr, -name => 'head2', -text => $bs->{pod_name});
196 $parser->select('DESCRIPTION');
197 strip_first_command($parser, $bs_fh, $iostr);
199 return ${$iostr->string_ref()};
202 sub get_buildsystem_details_for_dh_auto {
204 my $parser = new Pod::Select();
205 my $iostr = new IO::String();
207 # Build system details from build system PODs
208 for my $bs (get_buildsystem_pods()) {
209 my $bs_fh = $bs->{pod_fh};
211 print_pod_parag(output => $iostr, -name => 'head2', -text => $bs->NAME());
213 # Now print DH_AUTO NOTES
214 $parser->select('DH_AUTO NOTES');
215 strip_first_command($parser, $bs_fh, $iostr);
217 # And step specific documentation
218 for my $step (@steps) {
219 $parser->select('BUILD PROCESS/' . ucfirst($step) . " step");
220 print_pod_parag(output => $iostr, -name => 'head3', -text => 'B<' . ucfirst($step) . " step>");
221 strip_first_command($parser, $bs_fh, $iostr);
224 return ${$iostr->string_ref()};
227 sub get_dh_auto_program_man_list_for_dh_auto {
228 return join("\n\n", map { "L<dh_auto_$_(1)>" } @_);
231 sub get_buildsystem_man_list_for_dh_auto {
232 return join("\n\n", map { "L<dh_auto_" . $_->NAME() . "(7)>" } get_buildsystem_pods());
235 sub generate_dh_auto_pod {
237 my $parser = new Pod::Select();
238 my $iostr = new IO::String();
240 my $dh_auto_list = get_dh_auto_program_list_for_dh_auto(@steps);
241 my $supported_bs = get_supported_buildsystems_for_dh_auto(@steps);
242 my $bs_details = get_buildsystem_details_for_dh_auto(@steps);
243 my $dh_auto_man_list = get_dh_auto_program_man_list_for_dh_auto(@steps);
244 my $bs_man_list = get_buildsystem_man_list_for_dh_auto();
246 # Filter out all sections starting with #
247 $parser->select('[^#].*');
248 print_everything($parser, \*DH_AUTO, $iostr);
250 seek(\*$iostr, 0, 0);
252 s/#DH_AUTO LIST#/$dh_auto_list/;
253 s/#SUPPORTED BUILD SYSTEMS#/$supported_bs/;
254 s/#BUILD SYSTEM DETAILS#/$bs_details/;
255 s/#DH_AUTO MAN LIST#/$dh_auto_man_list/;
256 s/#BUILD SYSTEM MAN LIST#/$bs_man_list/;
262 ############# Entry point #############
276 open(OUTFILE, ">", $outfile) or die "Unable to open output file $outfile";
277 open(STDOUT, ">&OUTFILE") or die "Unable to redirect standard output";
280 open(DH_AUTO, $DH_AUTO_POD) or error("Unable to read $DH_AUTO_POD");
282 generate_step_pod(@args);
285 generate_dh_auto_pod(qw(configure build test install clean));
288 close OUTFILE if $outfile;