]> git.donarmstrong.com Git - lilypond.git/blob - bin/make_website
ce8c6bb7936407ecbfd0538dd462eaa2b95a30f3
[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>Please take me <a href=index.html>back to the index</a>\n<hr>
38 <font size=-1>
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>";
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
61 local $base="lilypond/";
62 local @examples=("wohltemperirt" ,"standchen", "scsii-menuetto", "rhythm", "collisions");
63
64
65 sub gen_html
66 {
67     print "generating HTML\n";
68     my_system "make -kC .. html";
69 }
70
71 sub gen_examples
72 {
73     print "generating examples: \n";
74     foreach $a (@examples) {
75         $texfile="lelie";
76         $tex = "tex $texfile";
77         if ($a eq "standchen" || $a eq "scsii-menuetto" ) {
78             $tex = "latex $a";
79             $texfile = "$a";
80         }
81         
82         if ( ! -f "$a.ly.txt" ) {
83             my_system "ln $depth/input/$a.ly ./$a.ly.txt";
84         }
85         if ( ! -f "$a.ps.gz" ) {
86             my_system "lilypond $a;",
87             "$tex",
88             "dvips -o $a.ps $texfile;";
89
90         }
91
92         my_system "mv lelie.midi $a.midi; "     if ( -f "lelie.midi" );
93
94         # generate the pixmap at twice the size, then rescale (for antialiasing)
95         if ( ! -f "$a.gif" ) {
96             my_system "gs -q -sDEVICE=ppmraw -sOutputFile=- -r200 -dNOPAUSE  $a.ps -c quit |pnmscale 0.5| ppmtogif > $a.gif",
97              "gzip $a.ps";
98         }   
99     }
100 }
101
102
103 sub gen_list
104 {
105     print "generating HTML list\n";
106     open HTMLLIST, ">example_output.html";
107     print HTMLLIST "<html><body><title>LilyPond examples</title>\n";
108     foreach $a (@examples) {
109         $name=$a;
110         print HTMLLIST "<h1>example file: $name</h1>\n<XMP>\n";
111
112         open IF, "$depth/input/$a.ly";
113         input_record_separator IF "%}";
114         
115         $desc = <IF>;
116         close IF;
117         
118         print HTMLLIST "$desc\n</XMP>";
119
120         $inputf="$a.ly.txt";
121         $giff="$a.gif";
122         $psf="$a.ps.gz";
123         $midif="$a.midi";
124         
125         print HTMLLIST "<ul>
126 <li><a href=$inputf> The input file</a>
127 <li><a href=$giff>The output (gif)</a>
128 <li><a href=$psf>The output (PS)</a>\n";
129         
130         print HTMLLIST "<li><a href=$midif>The output (MIDI)</a>\n"
131             if ( -f $midif );
132         print HTMLLIST "</ul>";
133     }
134     print HTMLLIST "</BODY></HTML>";
135         close HTMLLIST;
136 }
137
138 sub edit_html
139 {
140     print STDERR "adding footer\n";
141
142     OUTER:
143     foreach $a (<*.html>) {
144         open H, "$a";
145         my $sep="</BODY>";
146         input_record_separator H $sep;
147         my $file="";
148         
149         while (<H>) { 
150             if (/$mw_id/) {
151                 close H;
152                 next OUTER;
153             }
154             $file .= $_; 
155
156         }
157         close H;
158
159         my $subst =  $footstr;
160         $subst .= $back if (! $a =~ /index.html/ );
161         $file =~ s/$sep/$subst$sep/g ;
162         
163         open H, ">$a";
164         print H $mw_id;
165         print H $file;
166         close H;
167     }
168 }
169 sub copy_files
170 {  
171     print "copying files\n";
172     print `ln -s $depth/out ./docxx` if ( ! -x "docxx" ) ;
173     my_system "cp $depth/TODO ./TODO.txt",
174     "cp $depth/NEWS ./NEWS.txt",
175     "cp ../lelie*gif .";
176 }
177
178 sub docxx_update
179 {
180     my_system "make -C $depth doc++";
181 }
182
183 sub do_tar
184 {
185      print "tarring.\n";
186      my_system
187          " tar vhcf website.tar *.html *.gif *.ps.gz *.txt *.midi docxx/*;",
188          "gzip -f9 website.tar;";
189 }
190
191 sub main
192 {
193     $depth = "../";
194     my $cwd;
195     chomp($cwd = `pwd`);
196     die "need to be in directory Documentation\n" if ( ! ($cwd =~ /Documentation$/));
197     get_version;
198     set_html_footer;
199
200
201     $depth = "../../";
202
203     chdir ("out");
204     $ENV{"TEXINPUTS"} .= ":$depth/input/:";
205     $ENV{"LILYINCLUDE"} = "$depth/input/";
206
207
208     gen_html;
209     gen_examples;
210     gen_list;
211     copy_files;
212     edit_html;
213     docxx_update;
214     do_tar;
215 }
216 main;