]> git.donarmstrong.com Git - lilypond.git/blob - bin/make-website.in
release: 0.1.13
[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
7 my $lily_version;
8 my $footstr;
9 my $mw_id = "<!make_website!>";
10 my $id_str = "make-website 0.4";
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", "wtk1-fugue2",
81                  #"standchen-16", 
82                  #"standchen-20", 
83                  "wtk1-prelude1",
84                  "toccata-fuga-E", 
85                  "scsii-menuetto",
86                  "cadenza", "scales", 
87                 #"rhythm", 
88                  "gallina");
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
135     print HTMLLIST "<html><body><TITLE>Rendered Examples</TITLE>\n
136 These example files are taken from the LilyPond distribution.
137 LilyPond currently only outputs TeX and MIDI. The pictures and
138 PostScript files were generated using TeX, Ghostscript and some
139 graphics tools.  The papersize used for these examples is A4.  The GIF
140 files have been scaled to eliminate aliasing."; 
141
142
143
144     foreach $a (@examples)
145     {
146         $name=$a; print HTMLLIST "<h1>example file: $name</h1>\n<XMP>\n";
147
148         open IF, "$depth/input/$a.ly";
149         input_record_separator IF "%}";
150         
151         $desc = <IF>;
152         close IF;
153         
154         print HTMLLIST "$desc\n</XMP>";
155
156         $inputf="$a.ly.txt";
157         $giff="$a.gif";
158         $jpegf="$a.jpeg";
159         $pngf = "$a.png";
160         $psf="$a.ps.gz";
161         $midif="$a.midi";
162         
163         print HTMLLIST "<ul>";
164
165         print HTMLLIST "<li><a href=$inputf> The input file</a>"
166             if ( -f $inputf );
167         
168         print HTMLLIST "<li><a href=$giff>The output (picture)</a>"     
169             if ( -f $giff );
170
171         print HTMLLIST "<li><a href=$psf>The output (PS)</a>\n"
172             if ( -f $psf );
173                 
174         print HTMLLIST "<li><a href=$midif>The output (MIDI)</a>\n" 
175             if ( -f $midif );
176         print HTMLLIST "</ul>";
177     }
178     print HTMLLIST "</BODY></HTML>";
179     close HTMLLIST;
180 }
181
182 sub edit_html
183 {
184     print STDERR "adding footer\n";
185
186     OUTER:
187     foreach $a (<*.html>) {
188         open H, "$a";
189         my $sep="</BODY>";
190         input_record_separator H $sep;
191         my $file="";
192         
193         while (<H>) { 
194             if (/$mw_id/) {
195                 close H;
196                 next OUTER;
197             }
198             $file .= $_; 
199
200         }
201         close H;
202
203         my $subst =  $footstr;
204         $subst .= $back if (! $a =~ /index.html/ );
205         $file =~ s/$sep/$subst$sep/g ;
206         $file =~ s/\.gif/\.$image/g;
207         $file =~ s!<TITLE>(.*)</TITLE>!<TITLE>LilyPond WWW: $1</TITLE>!g;
208         open H, ">$a";
209         print H $mw_id;
210         
211         print H $file;
212         close H;
213     }
214 }
215
216 sub copy_txt_file
217 {
218     my ($f) = @_;
219     my $d = $f;
220     $d =~ s!^.*\/!!;
221     if (! $f =~ /.txt$/) {
222         $d = "$f.txt";
223     }
224     print $f, $d;
225 }
226     
227 sub copy_files
228 {  
229     print "copying files\n";
230     my_system "ln -s $depth/out ./docxx" if ( ! -x "docxx" ) ;
231     my_system "cp $depth/TODO ./TODO.txt",
232     "cp $depth/ANNOUNCE ./ANNOUNCE.txt",
233     "cp $depth/NEWS ./NEWS.txt",
234     "cp $depth/DEDICATION ./DEDICATION.txt";
235     my_system "make -C .. gifs";
236     
237 }
238
239 sub set_images
240 {
241     for $a (<*.gif>) {
242         if ($opt_png) {
243             my_system "gif2png -d $a";
244         }
245         if ($opt_jpeg) {
246             my $b=$a;
247             $b =~ s/.gif/.jpeg/;
248             my_system "cjpeg -o $b $a";
249         }
250     }
251 }
252
253 sub docxx_update
254 {
255     open BANNER, ">/tmp/lilybanner.html";
256     my $ban = $footstr;
257     $ban =~ s!index.html!../index.html!g;
258     print BANNER $ban;
259     close BANNER;
260     my_system "$MAKE -C $depth docxx-opts=\"-p -S -k -B /tmp/lilybanner.html\" doc++";
261     # should add a cute header.
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 zvhcf website.tar.gz $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     print "lily v. " . $lily_version . "\n";
293     set_html_footer;
294
295
296     $depth = "../../";
297
298     chdir ("out");
299     $ENV{"TEXINPUTS"} .= ":$depth/input/:";
300     $ENV{"LILYINCLUDE"} = "$depth/input/";
301
302
303     gen_html;
304     copy_files;
305     if (! $opt_noexamples) {
306         gen_examples;
307         gen_list;
308         gen_manuals;
309     }
310     set_images;
311
312     edit_html;
313     docxx_update;
314     do_tar;
315 }
316
317 main;