]> git.donarmstrong.com Git - lilypond.git/blob - bin/make_website
89fafd7c246acbc0a248866d6825795ba53cd4b5
[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", 
75                  "scsii-menuetto", "collisions", "cadenza", "scales", "book");
76
77 # rhythm, scales, 
78
79
80 sub gen_html
81 {
82     print "generating HTML\n";
83     my_system "make -kC .. html";
84 }
85
86 sub ps_to_gif 
87 {
88     my ($a)=@_;
89  
90     if (! -f "$a.ps" ) {
91         my_system("gunzip -c $a.ps.gz > $a.ps");
92     }
93     my_system "gs -q -sDEVICE=ppmraw -sOutputFile=- -r200 -dNOPAUSE  $a.ps -c quit |pnmscale 0.5| ppmtogif > $a.gif";
94 }
95
96
97 sub ps_to_jpeg
98
99     my ($a)=@_;
100     my $in = "$a.ps";
101     
102     my_system "gs -q -sDEVICE=ppmraw -sOutputFile=- -r200 -dNOPAUSE  $in -c quit |pnmscale 0.5| cjpeg -grayscale > $a.jpeg";
103 }
104
105 sub gen_examples
106 {
107     print "generating examples: \n";
108     foreach $a (@examples) {
109         $texfile="lelie";
110         $tex = "tex $texfile";
111         if ($a eq "standchen" || $a eq "scsii-menuetto" || $a eq "book" ) {
112             $tex = "latex $a";
113             $texfile = "$a";
114         }
115         
116         if ( ! -f "$a.ly.txt" ) {
117             my_system "ln $depth/input/$a.ly ./$a.ly.txt";
118         }
119         if (! -f "$a.dvi" ) {
120             my_system "lilypond $a;",
121             "$tex", "-mv $texfile.dvi $a.dvi";
122         }  
123         if ( ! -f "$a.ps.gz" && ! -f "$a.ps" ) {
124             my_system "dvips -o $a.ps $a.dvi";
125         }
126
127         my_system "mv lelie.midi $a.midi; " if ( -f "lelie.midi" );
128
129         # generate the pixmap at twice the size, then rescale (for antialiasing)
130         if ( ! -f "$a.gif" ) {
131             ps_to_gif($a);
132         }
133         if ( ! -f "$a.ps.gz" ) {
134             my_system "gzip -f $a.ps";
135         }   
136     }
137 }
138
139
140 sub gen_list
141 {
142     print "generating HTML list\n";
143     open HTMLLIST, ">example_output.html";
144     print HTMLLIST "<html><body><title>LilyPond examples</title>\n
145 These example files are taken from the LilyPond distribution.\n
146 LilyPond currently only outputs TeX and MIDI. The pictures and\n
147  PostScript files were generated using TeX, Ghostscript and some graphics tools. \n
148 The GIF files have been scaled to eliminate aliasing.";
149     foreach $a (@examples) {
150         $name=$a;
151         print HTMLLIST "<h1>example file: $name</h1>\n<XMP>\n";
152
153         open IF, "$depth/input/$a.ly";
154         input_record_separator IF "%}";
155         
156         $desc = <IF>;
157         close IF;
158         
159         print HTMLLIST "$desc\n</XMP>";
160
161         $inputf="$a.ly.txt";
162         $giff="$a.gif";
163         $jpegf="$a.jpeg";
164         $pngf = "$a.png";
165         $psf="$a.ps.gz";
166         $midif="$a.midi";
167         
168         print HTMLLIST "<ul>";
169
170         print HTMLLIST "<li><a href=$inputf> The input file</a>"
171             if ( -f $inputf );
172         
173         print HTMLLIST "<li><a href=$giff>The output (picture)</a>"     
174             if ( -f $giff );
175
176         print HTMLLIST "<li><a href=$psf>The output (PS)</a>\n"
177             if ( -f $psf );
178                 
179         print HTMLLIST "<li><a href=$midif>The output (MIDI)</a>\n" 
180             if ( -f $midif );
181         print HTMLLIST "</ul>";
182     }
183     print HTMLLIST "</BODY></HTML>";
184     close HTMLLIST;
185 }
186
187 sub edit_html
188 {
189     print STDERR "adding footer\n";
190
191     OUTER:
192     foreach $a (<*.html>) {
193         open H, "$a";
194         my $sep="</BODY>";
195         input_record_separator H $sep;
196         my $file="";
197         
198         while (<H>) { 
199             if (/$mw_id/) {
200                 close H;
201                 next OUTER;
202             }
203             $file .= $_; 
204
205         }
206         close H;
207
208         my $subst =  $footstr;
209         $subst .= $back if (! $a =~ /index.html/ );
210         $file =~ s/$sep/$subst$sep/g ;
211         $file =~ s/\.gif/\.$image/g;
212         open H, ">$a";
213         print H $mw_id;
214         print H $file;
215         close H;
216     }
217 }
218
219 sub copy_files
220 {  
221     print "copying files\n";
222     print `ln -s $depth/out ./docxx` if ( ! -x "docxx" ) ;
223     my_system "cp $depth/TODO ./TODO.txt",
224     "cp $depth/NEWS ./NEWS.txt",
225     "cp ../lelie*gif .";
226 }
227
228 sub set_images
229 {
230     for $a (<*.gif>) {
231         if ($opt_png) {
232             my_system "gif2png -d $a";
233         }
234         if ($opt_jpeg) {
235             my $b=$a;
236             $b =~ s/.gif/.jpeg/;
237             my_system "cjpeg -o $b $a";
238         }
239     }
240 }
241
242 sub docxx_update
243 {
244     my_system "make -C $depth doc++";
245 }
246
247 sub do_tar
248 {
249      print "tarring.\n";
250      $files = join (' ', < *.html *.$image *.ps.gz *.txt *.midi docxx/*>);
251      my_system
252          "-tar vhcf website.tar $files;",
253          "gzip -f9 website.tar;";
254 }
255 sub identify
256 {
257     print STDERR "make_website 0.1\n";
258     
259 }
260 sub main
261 {
262     identify;
263     GetOptions("jpeg", "gif", "png", "noexamples");
264
265     local $image="gif" ;
266     $image = "png" if ($opt_png);
267     $image = "jpeg" if ($opt_jpeg);
268     
269     $depth = "../";
270     my $cwd;
271     chomp($cwd = `pwd`);
272     die "need to be in directory Documentation\n" if ( ! ($cwd =~ /Documentation$/));
273     get_version;
274     set_html_footer;
275
276
277     $depth = "../../";
278
279     chdir ("out");
280     $ENV{"TEXINPUTS"} .= ":$depth/input/:";
281     $ENV{"LILYINCLUDE"} = "$depth/input/";
282
283
284     gen_html;
285     copy_files;
286     if (! $opt_noexamples) {
287         gen_examples;
288         gen_list;
289     }
290     set_images;
291
292     edit_html;
293     docxx_update;
294     do_tar;
295 }
296
297 main;