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