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