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