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