]> git.donarmstrong.com Git - lilypond.git/blob - bin/make_website
release: 0.0.66
[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
10 sub get_version
11 {
12     my ($vstr)=("");
13     open V, "$depth/.version";
14     while (<V>) {
15         s/#.*$//g;
16         next if (/^ *$/);
17         s/^/\$/;
18         s/= *(.*)$/=\"$1\";/;
19         $vstr .= $_;
20     }
21     eval ($vstr);
22     
23     $lily_version= "$TOPLEVEL_MAJOR_VERSION.$TOPLEVEL_MINOR_VERSION.$TOPLEVEL_PATCH_LEVEL$TOPLEVEL_MY_PATCH_LEVEL";
24     
25     # stupid checks.
26     $lily_version= "$TOPLEVEL_MAJOR_VERSION.$TOPLEVEL_MINOR_VERSION.$TOPLEVEL_PATCH_LEVEL$TOPLEVEL_MY_PATCH_LEVEL";
27
28
29     close V;
30 }
31
32 sub set_html_footer
33 {
34     my $MAILADRESS=$ENV{MAILADRESS};
35     my @pw=(getpwuid($<));
36     my $username=$pw[6];
37
38     $footstr = 
39         "\n<hr>Please take me <a href=index.html>back to the index</a>\n<hr>
40 <font size=-1>
41 This page was generated by <code>make_website</code> from lilypond-$lily_version by
42 <p>
43 <address><br>$username <a href=mailto:$MAILADRESS>&lt<!bla>$MAILADRESS</a>&gt</address>
44 <p>" . `date` . "
45 <p></font>";
46 }
47     
48
49 # do something, check return status
50 sub my_system
51 {
52     my (@cmds) = @_;
53     foreach $cmd (@cmds) {
54         my ($ignoreret)=0;
55         if ( $cmd  =~ /^-/ ) {
56             $ignoreret = 1;
57             $cmd = substr ($cmd, 1);
58         }
59         
60         my $ret =  ( system ($cmd));
61         if (!$ignoreret && $ret) {
62             print STDERR "\nmake_website: failed on command \`$cmd\' (status $ret)\n";
63             exit 2;
64         }
65     }
66 }
67
68
69 local $base="lilypond/";
70 local @examples=("wohltemperirt" ,"standchen", "scsii-menuetto", "rhythm", "collisions");
71
72
73 sub gen_html
74 {
75     print "generating HTML\n";
76     my_system "make -kC .. html";
77 }
78
79 sub ps_to_gif 
80 {
81     my ($a)=@_;
82  
83     if (! -f "$a.ps" ) {
84         my_system("gunzip -c $a.ps.gz > $a.ps");
85     }
86     my_system "gs -q -sDEVICE=ppmraw -sOutputFile=- -r200 -dNOPAUSE  $a.ps -c quit |pnmscale 0.5| ppmtogif > $a.gif";
87 }
88
89
90 sub ps_to_jpeg
91
92     my ($a)=@_;
93     my $in = "$a.ps";
94     
95     my_system "gs -q -sDEVICE=ppmraw -sOutputFile=- -r200 -dNOPAUSE  $in -c quit |pnmscale 0.5| cjpeg -grayscale > $a.jpeg";
96 }
97
98 sub gen_examples
99 {
100     print "generating examples: \n";
101     foreach $a (@examples) {
102         $texfile="lelie";
103         $tex = "tex $texfile";
104         if ($a eq "standchen" || $a eq "scsii-menuetto" ) {
105             $tex = "latex $a";
106             $texfile = "$a";
107         }
108         
109         if ( ! -f "$a.ly.txt" ) {
110             my_system "ln $depth/input/$a.ly ./$a.ly.txt";
111         }
112         if (! -f "$a.dvi" ) {
113             my_system "lilypond $a;",
114             "$tex", "-mv $texfile.dvi $a.dvi";
115         }  
116         if ( ! -f "$a.ps.gz" && ! -f "$a.ps" ) {
117             my_system "dvips -o $a.ps $a.dvi";
118         }
119
120         my_system "mv lelie.midi $a.midi; " if ( -f "lelie.midi" );
121
122         # generate the pixmap at twice the size, then rescale (for antialiasing)
123         if ( ! -f "$a.gif" ) {
124             ps_to_gif($a);
125         }
126         if ( ! -f "$a.ps.gz" ) {
127             my_system "gzip -f $a.ps";
128         }   
129     }
130 }
131
132
133 sub gen_list
134 {
135     print "generating HTML list\n";
136     open HTMLLIST, ">example_output.html";
137     print HTMLLIST "<html><body><title>LilyPond examples</title>\n";
138     foreach $a (@examples) {
139         $name=$a;
140         print HTMLLIST "<h1>example file: $name</h1>\n<XMP>\n";
141
142         open IF, "$depth/input/$a.ly";
143         input_record_separator IF "%}";
144         
145         $desc = <IF>;
146         close IF;
147         
148         print HTMLLIST "$desc\n</XMP>";
149
150         $inputf="$a.ly.txt";
151         $giff="$a.gif";
152         $jpegf="$a.jpeg";
153         $pngf = "$a.png";
154         $psf="$a.ps.gz";
155         $midif="$a.midi";
156         
157         print HTMLLIST "<ul>";
158
159         print HTMLLIST "<li><a href=$inputf> The input file</a>"
160             if ( -f $inputf );
161         
162         print HTMLLIST "<li><a href=$giff>The output (picture)</a>"     
163             if ( -f $giff );
164
165         print HTMLLIST "<li><a href=$psf>The output (PS)</a>\n"
166             if ( -f $psf );
167                 
168         print HTMLLIST "<li><a href=$midif>The output (MIDI)</a>\n" 
169             if ( -f $midif );
170         print HTMLLIST "</ul>";
171     }
172     print HTMLLIST "</BODY></HTML>";
173     close HTMLLIST;
174 }
175
176 sub edit_html
177 {
178     print STDERR "adding footer\n";
179
180     OUTER:
181     foreach $a (<*.html>) {
182         open H, "$a";
183         my $sep="</BODY>";
184         input_record_separator H $sep;
185         my $file="";
186         
187         while (<H>) { 
188             if (/$mw_id/) {
189                 close H;
190                 next OUTER;
191             }
192             $file .= $_; 
193
194         }
195         close H;
196
197         my $subst =  $footstr;
198         $subst .= $back if (! $a =~ /index.html/ );
199         $file =~ s/$sep/$subst$sep/g ;
200         $file =~ s/\.gif/\.$image/g;
201         open H, ">$a";
202         print H $mw_id;
203         print H $file;
204         close H;
205     }
206 }
207
208 sub copy_files
209 {  
210     print "copying files\n";
211     print `ln -s $depth/out ./docxx` if ( ! -x "docxx" ) ;
212     my_system "cp $depth/TODO ./TODO.txt",
213     "cp $depth/NEWS ./NEWS.txt",
214     "cp ../lelie*gif .";
215 }
216
217 sub set_images
218 {
219     for $a (<*.gif>) {
220         if ($opt_png) {
221             my_system "gif2png -d $a";
222         }
223         if ($opt_jpeg) {
224             my $b=$a;
225             $b =~ s/.gif/.jpeg/;
226             my_system "cjpeg -o $b $a";
227         }
228     }
229 }
230
231 sub docxx_update
232 {
233     my_system "make -C $depth doc++";
234 }
235
236 sub do_tar
237 {
238      print "tarring.\n";
239      my_system
240          " tar vhcf website.tar *.html *.$image *.ps.gz *.txt *.midi docxx/*;",
241          "gzip -f9 website.tar;";
242 }
243 sub identify
244 {
245     print STDERR "make_website 0.1\n";
246     
247 }
248 sub main
249 {
250     identify;
251     GetOptions("jpeg", "gif", "png");
252
253     local $image="gif" ;
254     $image = "png" if ($opt_png);
255     $image = "jpeg" if ($opt_jpeg);
256     
257     $depth = "../";
258     my $cwd;
259     chomp($cwd = `pwd`);
260     die "need to be in directory Documentation\n" if ( ! ($cwd =~ /Documentation$/));
261     get_version;
262     set_html_footer;
263
264
265     $depth = "../../";
266
267     chdir ("out");
268     $ENV{"TEXINPUTS"} .= ":$depth/input/:";
269     $ENV{"LILYINCLUDE"} = "$depth/input/";
270
271
272     gen_html;
273     gen_examples;
274     copy_files;
275     set_images;
276     gen_list;
277     edit_html;
278
279     docxx_update;
280     do_tar;
281 }
282
283 main;