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