]> git.donarmstrong.com Git - lilypond.git/blob - bin/make-website.pl
release: 0.1.22
[lilypond.git] / bin / make-website.pl
1 #!@PERL@ -w 
2 # -*-Perl-*- 
3
4
5 # stupid script to generate WWW site.  The WWW site is my 
6 # test-suite for LilyPond, I usually don't distribute versions that
7 # fail to make the website
8
9 use FileHandle;
10 use Getopt::Long;
11
12 my $lily_version;
13 my $footstr;
14 my $mw_id = "<!make_website!>";
15 my $id_str = "make-website 0.4";
16 my $TAR="tar";
17 my $MAKE="make";
18
19 sub get_version
20 {
21     my ($vstr)=("");
22     open V, "$depth/VERSION";
23     while (<V>) {
24         s/#.*$//g;
25         next if (/^ *$/);
26         s/^/\$/;
27         s/= *(.*)$/=\"$1\";/;
28         $vstr .= $_;
29     }
30     eval ($vstr);
31     
32     $lily_version= "$TOPLEVEL_MAJOR_VERSION.$TOPLEVEL_MINOR_VERSION.$TOPLEVEL_PATCH_LEVEL$TOPLEVEL_MY_PATCH_LEVEL";
33     
34     # stupid checks.
35     $lily_version= $lily_version;
36     
37     close V;
38 }
39
40 sub set_html_footer
41 {
42     my $MAILADDRESS=$ENV{MAILADDRESS};
43     my @pw=(getpwuid($<));
44     my $username=$pw[6];
45
46     $footstr = 
47         "\n<hr>Please take me <a href=index.html>back to the index</a>\n
48 of LilyPond -- The GNU Project Music typesetter
49 <hr>
50 <font size=-1>
51 This page was built using <code>" . $id_str . "</code> from lilypond-"
52     . $lily_version . 
53         " by<p>
54 <address><br>$username <a href=mailto:" 
55     . $MAILADDRESS . ">&lt<!bla>" . $MAILADDRESS ."</a>&gt</address>
56 <p></font>";
57 }
58     
59
60 # do something, check return status
61 sub my_system
62 {
63     my (@cmds) = @_;
64     foreach $cmd (@cmds) {
65         my ($ignoreret)=0;
66         if ( $cmd  =~ /^-/ ) {
67             $ignoreret = 1;
68             $cmd = substr ($cmd, 1);
69         }
70         
71         my $ret =  ( system ($cmd));
72         if ($ret) {
73             if ($ignoreret) {
74                 print STDERR "ignoring failed command \`$cmd\' (status $ret)\n";
75             }else {
76                 print STDERR "\nmake_website: failed on command \`$cmd\' (status $ret)\n";
77                 exit 2;
78             }
79         }
80     }
81 }
82
83
84 local $base="lilypond/";
85
86 local @examples=("twinkle-pop", 
87                  "wtk1-fugue2",
88                  "standchen-16", 
89                  "standchen-20", 
90                  "wtk1-prelude1",
91                  "toccata-fuga-E", 
92                  "scsii-menuetto",
93                  "cadenza", 
94                  "gallina",
95                  "twinkle", 
96                  "collisions",
97                  "font",
98                  #"scales", 
99                  "rhythm", 
100                  "multi" );
101
102
103 sub gen_html
104 {
105     print "generating HTML\n";
106     my_system "$MAKE -kC .. html";
107 }
108
109 sub gen_examples
110 {
111     print "generating examples: \n";
112     my @todo=();
113     foreach $a (@examples) {
114         push @todo, "out/$a.ps.gz", "out/$a.gif", "out/$a.ly.txt";
115     }
116     
117     my_system ("$MAKE -C .. " . join(' ', @todo));
118 }
119
120 my @texstuff = ("mudela-man", "mudela-course");
121
122 sub gen_manuals
123 {
124     print "generating TeX doco list\n";
125     open HTMLLIST, ">tex_manuals.html";
126     print HTMLLIST "<HTML><TITLE>PostScript Manuals</TITLE>\n" ;
127     print HTMLLIST "<BODY><h1>LilyPond manuals (in PostScript)</h1>";
128     print HTMLLIST "<ul>\n";
129     my @todo=();
130     foreach $a (@texstuff) {
131         push @todo , "out/$a.ps.gz";
132         print HTMLLIST "<li><a href=$a.ps.gz>$a.ps.gz</a>";
133     }
134     print HTMLLIST "</ul>";
135     
136     print HTMLLIST "</BODY></HTML>";
137     close HTMLLIST;
138
139     my_system( "$MAKE -C .. " .  join(' ', @todo));
140 }
141
142 sub gen_list
143 {
144     print "generating HTML list\n";
145     open HTMLLIST, ">example_output.html";
146
147     print HTMLLIST "<html><body><TITLE>Rendered Examples</TITLE>\n
148 These example files are taken from the LilyPond distribution.
149 LilyPond currently only outputs TeX and MIDI. The pictures and
150 PostScript files were generated using TeX, Ghostscript and some
151 graphics tools.  The papersize used for these examples is A4.  The GIF
152 files have been scaled to eliminate aliasing."; 
153
154
155
156     foreach $a (@examples)
157     {
158         $name=$a; print HTMLLIST "<h1>example file: $name</h1>\n<XMP>\n";
159
160         open IF, "$depth/input/$a.ly";
161         input_record_separator IF "\n}";
162         
163         $desc = <IF>;
164         close IF;
165         
166         print HTMLLIST "$desc\n</XMP>";
167
168         $inputf="$a.ly.txt";
169         $giff="$a.gif";
170         $jpegf="$a.jpeg";
171         $pngf = "$a.png";
172         $psf="$a.ps.gz";
173         $midif="$a.midi";
174         
175         print HTMLLIST "<ul>";
176
177         print HTMLLIST "<li><a href=$inputf> The input file</a>"
178             if ( -f $inputf );
179         
180         print HTMLLIST "<li><a href=$giff>The output (picture)</a>"     
181             if ( -f $giff );
182
183         print HTMLLIST "<li><a href=$psf>The output (PS)</a>\n"
184             if ( -f $psf );
185                 
186         print HTMLLIST "<li><a href=$midif>The output (MIDI)</a>\n" 
187             if ( -f $midif );
188         print HTMLLIST "</ul>";
189     }
190     print HTMLLIST "</BODY></HTML>";
191     close HTMLLIST;
192 }
193
194 sub edit_html
195 {
196     print STDERR "adding footer\n";
197
198     OUTER:
199     foreach $a (<*.html>) {
200         open H, "$a";
201         my $sep="</BODY>";
202         input_record_separator H $sep;
203         my $file="";
204         
205         while (<H>) { 
206             if (/$mw_id/) {
207                 close H;
208                 next OUTER;
209             }
210             $file .= $_; 
211
212         }
213         close H;
214
215         my $subst =  $footstr;
216         $subst .= $back if (! $a =~ /index.html/ );
217         $file =~ s/$sep/$subst$sep/g ;
218         $file =~ s/\.gif/\.$image/g;
219         $file =~ s!<TITLE>(.*)</TITLE>!<TITLE>LilyPond WWW: $1</TITLE>!g;
220         open H, ">$a";
221         print H $mw_id;
222         
223         print H $file;
224         close H;
225     }
226 }
227
228 sub copy_txt_file
229 {
230     my ($f) = @_;
231     my $d = $f;
232     $d =~ s!^.*\/!!;
233     if (! $f =~ /.txt$/) {
234         $d = "$f.txt";
235     }
236     print, $d;
237 }
238     
239 sub top_of_NEWS
240 {
241     open NEWS, "NEWS.txt";
242     input_record_separator NEWS "****";
243     $desc = <NEWS>;
244     chop ($desc);
245     close NEWS;
246
247     return $desc;
248 }
249
250 sub edit_index
251 {
252     $ton = top_of_NEWS();
253     $ton = "\n<XMP>\n$ton\n</XMP>\n";
254     open INDEX, "index.html";
255     input_record_separator NEWS undef;
256     $index = <INDEX>;
257     close INDEX;
258     $index =~ s/top_of_NEWS/$ton/;
259     open INDEX, ">index.html";
260     print INDEX $index;
261     close INDEX;
262 }
263
264
265 sub copy_files
266 {  
267     print "copying files\n";
268     my_system "ln -s $depth/out ./docxx" if ( ! -x "docxx" ) ;
269     my_system "cp $depth/TODO ./TODO.txt",
270     "cp $depth/ANNOUNCE ./ANNOUNCE.txt",
271     "cp $depth/NEWS ./NEWS.txt",
272     "cp $depth/DEDICATION ./DEDICATION.txt";
273     my_system "make -C .. gifs";
274     
275 }
276
277 sub set_images
278 {
279     for $a (<*.gif>) {
280         if ($opt_png) {
281             my_system "gif2png -d $a";
282         }
283         if ($opt_jpeg) {
284             my $b=$a;
285             $b =~ s/.gif/.jpeg/;
286             my_system "cjpeg -o $b $a";
287         }
288     }
289 }
290
291 sub docxx_update
292 {
293     open BANNER, ">/tmp/lilybanner.html";
294     my $ban = $footstr;
295     $ban =~ s!index.html!../index.html!g;
296     print BANNER $ban;
297     close BANNER;
298     my_system "BANNEROPT=\"-B /tmp/lilybanner.html\" $depth/bin/out/make-docxx";
299 }
300
301 sub do_tar
302 {
303      print "tarring.\n";
304      $files = join (' ', < *.html *.$image *.ps.gz *.txt *.midi docxx/*>);
305      my_system
306          "-$TAR zvhcf website.tar.gz $files;",
307 #        "gzip -f9 website.tar;";
308 }
309
310 sub identify
311 {
312     print STDERR "This is " . $id_str . "\n";
313     
314 }
315 sub main
316 {
317     identify;
318     GetOptions("jpeg", "gif", "png", "noexamples");
319
320     local $image="gif" ;
321     $image = "png" if ($opt_png);
322     $image = "jpeg" if ($opt_jpeg);
323     
324     $depth = "../";
325     my $cwd;
326     chomp($cwd = `pwd`);
327     die "need to be in directory Documentation\n" if ( ! ($cwd =~ /Documentation$/));
328     get_version;
329     print "lily v. " . $lily_version . "\n";
330     set_html_footer;
331
332
333     $depth = "../../";
334
335     chdir ("out");
336     $ENV{"TEXINPUTS"} .= ":$depth/input/:";
337     $ENV{"LILYINCLUDE"} = "$depth/input/";
338
339
340     gen_html;
341     copy_files;
342
343     if (! $opt_noexamples) {
344         gen_examples;
345         gen_list;
346         gen_manuals;
347     }
348     set_images;
349
350     edit_html;
351     edit_index;
352     docxx_update;
353     do_tar;
354 }
355
356 main;