]> git.donarmstrong.com Git - lilypond.git/blob - bin/make_website
patch::: 0.0.73pre.jcn1: epsilon performance
[lilypond.git] / bin / make_website
1 #!/usr/bin/perl -w
2 # stupid script to generate WWW site.
3
4 use FileHandle;
5 use Getopt::Long;
6 my $lily_version;
7 my $footstr;
8 my $mw_id = "<!make_website!>";
9
10 sub get_version
11 {
12     my ($vstr)=("");
13     open V, "$depth/.version";
14     while (<V>) {
15         s/#.*$//g;
16         next if (/^ *$/);
17         s/^/\$/;
18         s/= *(.*)$/=\"$1\";/;
19         $vstr .= $_;
20     }
21     eval ($vstr);
22     
23     $lily_version= "$TOPLEVEL_MAJOR_VERSION.$TOPLEVEL_MINOR_VERSION.$TOPLEVEL_PATCH_LEVEL$TOPLEVEL_MY_PATCH_LEVEL";
24     
25     # stupid checks.
26     $lily_version= "$TOPLEVEL_MAJOR_VERSION.$TOPLEVEL_MINOR_VERSION.$TOPLEVEL_PATCH_LEVEL$TOPLEVEL_MY_PATCH_LEVEL";
27
28
29     close V;
30 }
31
32 sub set_html_footer
33 {
34     my $MAILADRESS=$ENV{MAILADRESS};
35     my @pw=(getpwuid($<));
36     my $username=$pw[6];
37
38     $footstr = 
39         "\n<hr>Please take me <a href=index.html>back to the index</a>\n<hr>
40 <font size=-1>
41 This page was generated by <code>make_website</code> from lilypond-$lily_version by
42 <p>
43 <address><br>$username <a href=mailto:$MAILADRESS>&lt<!bla>$MAILADRESS</a>&gt</address>
44 <p>" . `date` . "
45 <p></font>";
46 }
47     
48
49 # do something, check return status
50 sub my_system
51 {
52     my (@cmds) = @_;
53     foreach $cmd (@cmds) {
54         my ($ignoreret)=0;
55         if ( $cmd  =~ /^-/ ) {
56             $ignoreret = 1;
57             $cmd = substr ($cmd, 1);
58         }
59         
60         my $ret =  ( system ($cmd));
61         if ($ret) {
62             if ($ignoreret) {
63                 print STDERR "ignoring failed command \`$cmd\' (status $ret)\n";
64             }else {
65                 print STDERR "\nmake_website: failed on command \`$cmd\' (status $ret)\n";
66                 exit 2;
67             }
68         }
69     }
70 }
71
72
73 local $base="lilypond/";
74 local @examples=("multi", "wohltemperirt" ,"standchen", "toccata-fuga-E", "scsii-menuetto", "collisions");
75
76 # rhythm, scales, 
77
78
79 sub gen_html
80 {
81     print "generating HTML\n";
82     my_system "make -kC .. html";
83 }
84
85 sub ps_to_gif 
86 {
87     my ($a)=@_;
88  
89     if (! -f "$a.ps" ) {
90         my_system("gunzip -c $a.ps.gz > $a.ps");
91     }
92     my_system "gs -q -sDEVICE=ppmraw -sOutputFile=- -r200 -dNOPAUSE  $a.ps -c quit |pnmscale 0.5| ppmtogif > $a.gif";
93 }
94
95
96 sub ps_to_jpeg
97
98     my ($a)=@_;
99     my $in = "$a.ps";
100     
101     my_system "gs -q -sDEVICE=ppmraw -sOutputFile=- -r200 -dNOPAUSE  $in -c quit |pnmscale 0.5| cjpeg -grayscale > $a.jpeg";
102 }
103
104 sub gen_examples
105 {
106     print "generating examples: \n";
107     foreach $a (@examples) {
108         $texfile="lelie";
109         $tex = "tex $texfile";
110         if ($a eq "standchen" || $a eq "scsii-menuetto" ) {
111             $tex = "latex $a";
112             $texfile = "$a";
113         }
114         
115         if ( ! -f "$a.ly.txt" ) {
116             my_system "ln $depth/input/$a.ly ./$a.ly.txt";
117         }
118         if (! -f "$a.dvi" ) {
119             my_system "lilypond $a;",
120             "$tex", "-mv $texfile.dvi $a.dvi";
121         }  
122         if ( ! -f "$a.ps.gz" && ! -f "$a.ps" ) {
123             my_system "dvips -o $a.ps $a.dvi";
124         }
125
126         my_system "mv lelie.midi $a.midi; " if ( -f "lelie.midi" );
127
128         # generate the pixmap at twice the size, then rescale (for antialiasing)
129         if ( ! -f "$a.gif" ) {
130             ps_to_gif($a);
131         }
132         if ( ! -f "$a.ps.gz" ) {
133             my_system "gzip -f $a.ps";
134         }   
135     }
136 }
137
138
139 sub gen_list
140 {
141     print "generating HTML list\n";
142     open HTMLLIST, ">example_output.html";
143     print HTMLLIST "<html><body><title>LilyPond examples</title>\n
144 These example files are taken from the LilyPond distribution.\n
145 LilyPond currently only outputs TeX and MIDI. The pictures and\n
146  PostScript files were generated using TeX, Ghostscript and some graphics tools. \n
147 The GIF files have been scaled to eliminate aliasing.";
148     foreach $a (@examples) {
149         $name=$a;
150         print HTMLLIST "<h1>example file: $name</h1>\n<XMP>\n";
151
152         open IF, "$depth/input/$a.ly";
153         input_record_separator IF "%}";
154         
155         $desc = <IF>;
156         close IF;
157         
158         print HTMLLIST "$desc\n</XMP>";
159
160         $inputf="$a.ly.txt";
161         $giff="$a.gif";
162         $jpegf="$a.jpeg";
163         $pngf = "$a.png";
164         $psf="$a.ps.gz";
165         $midif="$a.midi";
166         
167         print HTMLLIST "<ul>";
168
169         print HTMLLIST "<li><a href=$inputf> The input file</a>"
170             if ( -f $inputf );
171         
172         print HTMLLIST "<li><a href=$giff>The output (picture)</a>"     
173             if ( -f $giff );
174
175         print HTMLLIST "<li><a href=$psf>The output (PS)</a>\n"
176             if ( -f $psf );
177                 
178         print HTMLLIST "<li><a href=$midif>The output (MIDI)</a>\n" 
179             if ( -f $midif );
180         print HTMLLIST "</ul>";
181     }
182     print HTMLLIST "</BODY></HTML>";
183     close HTMLLIST;
184 }
185
186 sub edit_html
187 {
188     print STDERR "adding footer\n";
189
190     OUTER:
191     foreach $a (<*.html>) {
192         open H, "$a";
193         my $sep="</BODY>";
194         input_record_separator H $sep;
195         my $file="";
196         
197         while (<H>) { 
198             if (/$mw_id/) {
199                 close H;
200                 next OUTER;
201             }
202             $file .= $_; 
203
204         }
205         close H;
206
207         my $subst =  $footstr;
208         $subst .= $back if (! $a =~ /index.html/ );
209         $file =~ s/$sep/$subst$sep/g ;
210         $file =~ s/\.gif/\.$image/g;
211         open H, ">$a";
212         print H $mw_id;
213         print H $file;
214         close H;
215     }
216 }
217
218 sub copy_files
219 {  
220     print "copying files\n";
221     print `ln -s $depth/out ./docxx` if ( ! -x "docxx" ) ;
222     my_system "cp $depth/TODO ./TODO.txt",
223     "cp $depth/NEWS ./NEWS.txt",
224     "cp ../lelie*gif .";
225 }
226
227 sub set_images
228 {
229     for $a (<*.gif>) {
230         if ($opt_png) {
231             my_system "gif2png -d $a";
232         }
233         if ($opt_jpeg) {
234             my $b=$a;
235             $b =~ s/.gif/.jpeg/;
236             my_system "cjpeg -o $b $a";
237         }
238     }
239 }
240
241 sub docxx_update
242 {
243     my_system "make -C $depth doc++";
244 }
245
246 sub do_tar
247 {
248      print "tarring.\n";
249      $files = join (' ', < *.html *.$image *.ps.gz *.txt *.midi docxx/*>);
250      my_system
251          "-tar vhcf website.tar $files;",
252          "gzip -f9 website.tar;";
253 }
254 sub identify
255 {
256     print STDERR "make_website 0.1\n";
257     
258 }
259 sub main
260 {
261     identify;
262     GetOptions("jpeg", "gif", "png", "noexamples");
263
264     local $image="gif" ;
265     $image = "png" if ($opt_png);
266     $image = "jpeg" if ($opt_jpeg);
267     
268     $depth = "../";
269     my $cwd;
270     chomp($cwd = `pwd`);
271     die "need to be in directory Documentation\n" if ( ! ($cwd =~ /Documentation$/));
272     get_version;
273     set_html_footer;
274
275
276     $depth = "../../";
277
278     chdir ("out");
279     $ENV{"TEXINPUTS"} .= ":$depth/input/:";
280     $ENV{"LILYINCLUDE"} = "$depth/input/";
281
282
283     gen_html;
284     copy_files;
285     if (! $opt_noexamples) {
286         gen_examples;
287         gen_list;
288     }
289     set_images;
290
291     edit_html;
292     docxx_update;
293     do_tar;
294 }
295
296 main;