]> git.donarmstrong.com Git - lilypond.git/blob - bin/make-website.pl
patch::: 0.1.38.jcn2: heen en weer
[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                  "font20",
99                  #"scales", 
100                  "rhythm", 
101                  "multi" );
102
103
104 sub gen_html
105 {
106     print "generating HTML\n";
107     my_system "$MAKE -kC .. html";
108 }
109
110 sub gen_examples
111 {
112     print "generating examples: \n";
113     my @todo=();
114     foreach $a (@examples) {
115         push @todo, "out/$a.ps.gz", "out/$a.gif", "out/$a.ly.txt";
116     }
117     
118     my_system ("$MAKE -C .. " . join(' ', @todo));
119 }
120
121 my @texstuff = ("mudela-man", "mudela-course");
122
123 sub gen_manuals
124 {
125     print "generating TeX doco list\n";
126     open HTMLLIST, ">tex_manuals.html";
127     print HTMLLIST "<HTML><TITLE>PostScript Manuals</TITLE>\n" ;
128     print HTMLLIST "<BODY><h1>LilyPond manuals (in PostScript)</h1>";
129     print HTMLLIST "<ul>\n";
130     my @todo=();
131     foreach $a (@texstuff) {
132         push @todo , "out/$a.ps.gz";
133         print HTMLLIST "<li><a href=$a.ps.gz>$a.ps.gz</a>";
134     }
135     print HTMLLIST "</ul>";
136     
137     print HTMLLIST "</BODY></HTML>";
138     close HTMLLIST;
139
140     my_system( "$MAKE -C .. " .  join(' ', @todo));
141 }
142
143 sub gen_list
144 {
145     print "generating HTML list\n";
146     open HTMLLIST, ">example_output.html";
147
148     print HTMLLIST "<html><body><TITLE>Rendered Examples</TITLE>\n
149 These example files are taken from the LilyPond distribution.
150 LilyPond currently only outputs TeX and MIDI. The pictures and
151 PostScript files were generated using TeX, Ghostscript and some
152 graphics tools.  The papersize used for these examples is A4.  The GIF
153 files have been scaled to eliminate aliasing."; 
154
155
156
157     foreach $a (@examples)
158     {
159         $name=$a; print HTMLLIST "<h1>example file: $name</h1>\n<XMP>\n";
160
161         open IF, "$depth/input/$a.ly";
162         input_record_separator IF "\n}";
163         
164         $desc = <IF>;
165         close IF;
166         
167         print HTMLLIST "$desc\n</XMP>";
168
169         $inputf="$a.ly.txt";
170         $giff="$a.gif";
171         $jpegf="$a.jpeg";
172         $pngf = "$a.png";
173         $psf="$a.ps.gz";
174         $midif="$a.midi";
175         
176         print HTMLLIST "<ul>";
177
178         print HTMLLIST "<li><a href=$inputf> The input file</a>"
179             if ( -f $inputf );
180         
181         print HTMLLIST "<li><a href=$giff>The output (picture)</a>"     
182             if ( -f $giff );
183
184         print HTMLLIST "<li><a href=$psf>The output (PS)</a>\n"
185             if ( -f $psf );
186                 
187         print HTMLLIST "<li><a href=$midif>The output (MIDI)</a>\n" 
188             if ( -f $midif );
189         print HTMLLIST "</ul>";
190     }
191     print HTMLLIST "</BODY></HTML>";
192     close HTMLLIST;
193 }
194
195 sub edit_html
196 {
197     print STDERR "adding footer\n";
198
199     OUTER:
200     foreach $a (<*.html>) {
201         open H, "$a";
202         my $sep="</BODY>";
203         input_record_separator H $sep;
204         my $file="";
205         
206         while (<H>) { 
207             if (/$mw_id/) {
208                 close H;
209                 next OUTER;
210             }
211             $file .= $_; 
212
213         }
214         close H;
215
216         my $subst =  $footstr;
217         $subst .= $back if (! $a =~ /index.html/ );
218         $file =~ s/$sep/$subst$sep/g ;
219         $file =~ s/\.gif/\.$image/g;
220         $file =~ s!<TITLE>(.*)</TITLE>!<TITLE>LilyPond WWW: $1</TITLE>!g;
221         open H, ">$a";
222         print H $mw_id;
223         
224         print H $file;
225         close H;
226     }
227 }
228
229 sub copy_txt_file
230 {
231     my ($f) = @_;
232     my $d = $f;
233     $d =~ s!^.*\/!!;
234     if (! $f =~ /.txt$/) {
235         $d = "$f.txt";
236     }
237     print, $d;
238 }
239     
240 sub top_of_NEWS
241 {
242     open NEWS, "NEWS.txt";
243     input_record_separator NEWS "****";
244     $desc = <NEWS>;
245     chop ($desc);
246     close NEWS;
247
248     return $desc;
249 }
250
251 sub edit_index
252 {
253     $ton = top_of_NEWS();
254     $ton = "\n<XMP>\n$ton\n</XMP>\n";
255     open INDEX, "index.html";
256     input_record_separator NEWS undef;
257     $index = <INDEX>;
258     close INDEX;
259     $index =~ s/top_of_NEWS/$ton/;
260     open INDEX, ">index.html";
261     print INDEX $index;
262     close INDEX;
263 }
264
265
266 sub copy_files
267 {  
268     print "copying files\n";
269     my_system "ln -s $depth/out ./docxx" if ( ! -x "docxx" ) ;
270     my_system "cp $depth/TODO ./TODO.txt",
271     "cp $depth/ANNOUNCE ./ANNOUNCE.txt",
272     "cp $depth/NEWS ./NEWS.txt",
273     "cp $depth/DEDICATION ./DEDICATION.txt";
274     my_system "make -C .. gifs";
275     
276 }
277
278 sub set_images
279 {
280     for $a (<*.gif>) {
281         if ($opt_png) {
282             my_system "gif2png -d $a";
283         }
284         if ($opt_jpeg) {
285             my $b=$a;
286             $b =~ s/.gif/.jpeg/;
287             my_system "cjpeg -o $b $a";
288         }
289     }
290 }
291
292 sub docxx_update
293 {
294     open BANNER, ">/tmp/lilybanner.html";
295     my $ban = $footstr;
296     $ban =~ s!index.html!../index.html!g;
297     print BANNER $ban;
298     close BANNER;
299     my_system("BANNEROPT=\"-B /tmp/lilybanner.html\" $depth/bin/out/make-docxx");
300     unlink "/tmp/lilybanner.html";
301 }
302
303 sub do_tar
304 {
305      print "tarring.\n";
306      $files = join (' ', < *.html *.$image *.ps.gz *.txt *.midi docxx/*>);
307      my_system
308          "-$TAR zvhcf website.tar.gz $files;",
309 #        "gzip -f9 website.tar;";
310 }
311
312 sub identify
313 {
314     print STDERR "This is " . $id_str . "\n";
315     
316 }
317 sub clean_tmp
318 {
319     @a = </tmp/gs*>;
320     unlink @a;
321 }
322     
323 sub main
324 {
325     identify;
326     GetOptions("jpeg", "gif", "png", "noexamples");
327
328     local $image="gif" ;
329     $image = "png" if ($opt_png);
330     $image = "jpeg" if ($opt_jpeg);
331     
332     $depth = "../";
333     my $cwd;
334     chomp($cwd = `pwd`);
335     die "need to be in directory Documentation\n" if ( ! ($cwd =~ /Documentation$/));
336     get_version;
337     print "lily v. " . $lily_version . "\n";
338     set_html_footer;
339
340
341     $depth = "../../";
342
343     chdir ("out");
344     $ENV{"TEXINPUTS"} .= ":$depth/input/:";
345     $ENV{"LILYINCLUDE"} = "$depth/input/";
346     $ENV{"LILYTOP"} = $depth;
347
348     gen_html;
349     copy_files;
350
351     if (! $opt_noexamples) {
352         gen_examples;
353         gen_list;
354         gen_manuals;
355     }
356     set_images;
357
358     edit_html;
359     edit_index;
360     docxx_update;
361     do_tar;
362     clean_tmp;
363 }
364
365 main;