1#!/usr/bin/perl -w 2 3############################################### 4# # 5## for documentation ## 6### execute: ### 7#### % perldoc docset_build #### 8### to get the built-in ### 9## docs rendered ## 10# # 11############################################### 12 13use strict; 14 15require 5.005_03; 16 17use DocSet::5005compat; 18use warnings; 19require Cwd; 20local $| = 1; 21 22use File::Spec::Functions; 23 24my $config_file = pop @ARGV; 25my $abs_root = pop @ARGV; 26 27# must start from the abs root 28chdir $abs_root; 29 30# make the config_file path as a true full path with no .. in it 31my $cwd = Cwd::cwd(); 32$abs_root = $cwd; 33$config_file = catfile $cwd, $config_file; 34 35die "cannot find the config file ", 36 usage() unless -e $config_file and -r _; 37 38use Getopt::Std; 39 40use DocSet::RunTime (); 41use DocSet::DocSet::HTML (); 42use DocSet::DocSet::PSPDF (); 43 44###################################### 45### Init Command Line Arguments 46###################################### 47 48# set defaults if no options given 49my $verbose = 0; # verbose? 50my $podify_items = 0; # podify pseudo-pod (s/^* /=item */) 51my $split_html = 0; # create the splitted html version 52my $make_tgz = 0; # create the rel and bin+src archives? 53my $generate_ps = 0; # generate PS file 54my $generate_pdf = 0; # generate PDF file 55my $rebuild_all = 0; # ignore the timestamp of ../src/.last_modified 56my $print_anchors = 0; # print the available anchors 57my $validate_links = 0; # validate %links_to_check against %valid_anchors 58my $makefile_mode = 0; # executed from Makefile (forces rebuild, no 59 # PS/PDF file, no tgz archive created!) 60my $slides_mode = 0; 61 62###################################### 63### Process Command Line Arguments 64###################################### 65 66my %opts; 67getopts('hvtpdfalmise', \%opts); 68 69usage() if $opts{h}; 70 71if (keys %opts) { # options given 72 $verbose = $opts{v} || 0; 73 $podify_items = $opts{i} || 0; 74 $split_html = $opts{s} || 0; 75 $make_tgz = $opts{t} || 0; 76 $generate_ps = $opts{p} || 0; 77 $generate_pdf = $opts{d} || 0; 78 $rebuild_all = $opts{f} || 0; # force 79 $print_anchors = $opts{a} || 0; 80 $validate_links = $opts{l} || 0; 81 $slides_mode = $opts{e} || 0; 82 $makefile_mode = $opts{m} || 0; 83} 84 85if ($makefile_mode) { 86 $verbose = 1; 87 $make_tgz = 0; 88 $generate_ps = 0; 89 $generate_pdf = 0; 90 $rebuild_all = 1; 91 $print_anchors = 0; 92 $validate_links = 0; 93} 94 95# in the slides mode we turn preprocessing automatically to be on 96if ($slides_mode) { 97 $podify_items = 1; 98} 99 100# we need a PS version in order to create a pdf 101$generate_ps = 1 if $generate_pdf; 102 103# verify the ability to create PS version 104$generate_ps = DocSet::RunTime::can_create_ps if $generate_ps; 105 106# verify the ability to create PDF version 107$generate_pdf = DocSet::RunTime::can_create_pdf if $generate_pdf; 108 109# we cannot create PDF if we cannot generate PS 110$generate_pdf = 0 unless $generate_ps; 111 112## if there is no toc_file we cannot produce correct internal links, 113## therefore we force this option. 114#my $toc_file = $config->get_param('toc_file'); 115#$rebuild_all = 1, 116# print "!!! No $toc_file was found, forcing a complete rebuild\n" 117# unless -e $toc_file or $rebuild_all; 118 119my %options = ( 120 verbose => $verbose, 121 podify_items => $podify_items, 122 split_html => $split_html, 123 make_tgz => $make_tgz, 124 generate_ps => $generate_ps, 125 generate_pdf => $generate_pdf, 126 rebuild_all => $rebuild_all, 127 print_anchors => $print_anchors, 128 validate_links => $validate_links, 129 makefile_mode => $makefile_mode, 130 slides_mode => $slides_mode, 131); 132 133# make the runtime options available to other packages 134DocSet::RunTime::set_opt(\%options); 135 136# absolutize the base url 137 138 139 140###################################### 141### Create the PS/PDF DocSet 142###################################### 143if (DocSet::RunTime::get_opts('generate_ps')) { 144 DocSet::RunTime::registers_reset(); 145 my $docset = DocSet::DocSet::PSPDF->new($config_file); 146 $docset->set_dir(abs_root => "."); 147 $docset->scan; 148 $docset->render; 149} 150 151# HTML DocSet is rendered last, since it may need to link to the 152# products of previously rendered DocSets, e.g. PDF files. 153 154###################################### 155### Create the HTML DocSet 156###################################### 157{ 158 # scan for available configs (books/chapters) 159 DocSet::RunTime::registers_reset(); 160 my $docset = DocSet::DocSet::HTML->new($config_file); 161 # must be a relative path to be able to move the generated code from 162 # location to location, without adjusting the links 163 $docset->set_dir(abs_root => "."); 164 $docset->scan; 165 $docset->render; 166} 167 168 169 # go back to where you have from 170#chdir $orig_dir; 171 172###################################### 173### Subs 174###################################### 175 176########## 177sub usage{ 178 179 print <<USAGE; 180 pod2hpp [options] config_file_location 181 182Options: 183 184 -h this help 185 -v verbose 186 -i podify pseudo-pod items (s/^* /=item */) 187 -p generate PS file 188 -d generate PDF file 189 -f force a complete rebuild 190 -l do hypertext links validation 191 -m executed from Makefile (forces rebuild, 192 no PS/PDF file, 193 no tgz archive!) 194 195USAGE 196 197# not implemented/ported yet 198# -t create tar.gz 199# -s create the splitted html version 200# -a print available hypertext anchors 201# -e slides mode (for presentations) 202 203 exit; 204 205} # end of sub usage 206 207 208 209__END__ 210 211=head1 NAME 212 213docset_build - a script that does documentation projects building in HTML, PS and PDF formats 214 215=head1 SYNOPSIS 216 217 pod2hpp [options] configuration_file_location 218 219=head1 DESCRIPTION 220 221See C<DocSet> 222 223=head1 AUTHOR 224 225Stas Bekman <stas@stason.org> 226 227=head1 COPYRIGHT 228 229This program is distributed under the Artistic License, like the Perl 230itself. 231 232=cut 233 234 235=cut 236