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