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