source: box/trunk/infrastructure/makeparcels.pl.in @ 3000

Revision 3000, 7.5 KB checked in by chris, 5 months ago (diff)

Don't regenerate zipped manpages unless needed.

  • Property svn:eol-style set to native
Line 
1#!@PERL@
2
3use strict;
4use lib 'infrastructure';
5use BoxPlatform;
6
7my @parcels;
8my %parcel_contents;
9
10sub starts_with ($$)
11{
12        my ($string,$expected) = @_;
13        return substr($string, 0, length $expected) eq $expected;
14}
15
16sub os_matches ($)
17{
18        my ($prefix_string) = @_;
19        my @prefixes = split m'\,', $prefix_string;
20        foreach my $prefix (@prefixes)
21        {
22                return 1 if starts_with($build_os,  $prefix);
23                return 1 if starts_with($target_os, $prefix);
24        }
25        return 0;
26}
27
28my $copy_command = "cp -p";
29
30if ($build_os eq 'CYGWIN')
31{
32        $copy_command = "cp -pu"; # faster
33}
34
35open PARCELS,"parcels.txt" or die "Can't open parcels file";
36{
37        my $cur_parcel = '';
38        while(<PARCELS>)
39        {
40                chomp; s/#.+\Z//; s/\s+\Z//; s/\s+/ /g;
41                next unless m/\S/;
42               
43                # omit bits on some platforms?
44                next if m/\AEND-OMIT/;
45                if(m/\AOMIT:(.+)/)
46                {
47                        if (os_matches($1))
48                        {
49                                while(<PARCELS>)
50                                {
51                                        last if m/\AEND-OMIT/; 
52                                }
53                        }
54                        next;
55                }
56
57                if (m'\AONLY:(.+)')
58                {
59                        if (not os_matches($1))
60                        {
61                                while (<PARCELS>)
62                                {
63                                        last if m'\AEND-ONLY';
64                                }
65                        }
66                        next;
67                }
68                next if (m'\AEND-ONLY');
69
70                if (m'\AEXCEPT:(.+)')
71                {
72                        if (os_matches($1))
73                        {
74                                while (<PARCELS>)
75                                {
76                                        last if m'\AEND-EXCEPT';
77                                }
78                        }
79                        next;
80                }
81                next if (m'\AEND-EXCEPT');
82               
83                # new parcel, or a new parcel definition?
84                if(m/\A\s+(.+)\Z/)
85                {
86                        push @{$parcel_contents{$cur_parcel}},$1
87                }
88                else
89                {
90                        $cur_parcel = $_;
91                        push @parcels,$_;
92                }
93        }
94}
95close PARCELS;
96
97# create parcels directory
98mkdir "parcels",0755;
99mkdir "parcels/scripts",0755;
100
101# write master makefile
102
103open MAKE,">Makefile" or die "Can't open master Makefile for writing";
104
105print MAKE <<__E;
106#
107# AUTOMATICALLY GENERATED FILE
108#    do not edit!
109#
110#
111
112MAKE = $make_command
113
114__E
115
116print MAKE "all:\t",join(' ',map {"build-".$_} @parcels),"\n\n";
117
118print MAKE <<__END_OF_FRAGMENT;
119test:   release/common/test
120
121release/common/test:
122        ./runtest.pl ALL release
123
124.PHONY: docs
125docs:
126        cd docs; \$(MAKE)
127
128__END_OF_FRAGMENT
129
130my $release_flag = BoxPlatform::make_flag('RELEASE');
131my @clean_deps;
132
133for my $parcel (@parcels)
134{
135        my $version = BoxPlatform::parcel_root($parcel);
136        my $target  = BoxPlatform::parcel_target($parcel);
137        my $dir     = BoxPlatform::parcel_dir($parcel);
138        my @parcel_deps;
139
140        # Need to use BSD install on Solaris
141        my $install_bin = $build_os eq 'SunOS' ? '/usr/ucb/install' : 'install';
142
143        unless ($target_windows)
144        {
145                open SCRIPT,">parcels/scripts/install-$parcel" or die
146                        "Can't open installer script for $parcel for writing";
147                print SCRIPT "#!/bin/sh\n\n";
148        }
149
150        for(@{$parcel_contents{$parcel}})
151        {
152                my @args = split /\s+/;
153
154                my ($type,$name,$dest) = @args;
155                my $optional = 0;
156                my $install  = 1;
157
158                if ($type eq 'optional')
159                {
160                        $optional = 1;
161                        shift @args;
162                        ($type,$name,$dest) = @args;
163                }
164
165                if ($type eq 'noinstall')
166                {
167                        $install = 0;
168                        shift @args;
169                        ($type,$name,$dest) = @args;
170                }
171
172                if($type eq 'bin')
173                {
174                        my $exeext = $platform_exe_ext;
175                        print MAKE <<EOF;
176$dir/$name$exeext: release/bin/$name/$name$exeext
177        mkdir -p $dir
178        $copy_command release/bin/$name/$name$exeext $dir
179
180.PHONY: release/bin/$name/$name$exeext
181release/bin/$name/$name$exeext:
182        (cd bin/$name; \$(MAKE) $release_flag)
183
184EOF
185                        push @parcel_deps, "$dir/$name$exeext";
186                }
187                elsif ($type eq 'script')
188                {
189                        my $fullpath = $name;
190                        my $filename = $name;
191                        # remove path from script name
192                        $filename =~ s{.*/}{};
193
194                        print MAKE <<EOF;
195$dir/$filename: $fullpath
196        mkdir -p $dir
197EOF
198
199                        if ($optional)
200                        {
201                                print MAKE "\ttest -r $fullpath " .
202                                        "&& $copy_command $fullpath $dir || true\n";
203                        }
204                        else
205                        {
206                                print MAKE "\t$copy_command $fullpath $dir\n";
207                        }
208
209                        print MAKE "\n";
210
211                        push @parcel_deps, "$dir/$filename";
212                }
213                elsif($type eq 'man')
214                {
215                        print MAKE <<EOF;
216$dir/${name}.gz: docs/man/${name}.gz
217        mkdir -p $dir
218        $copy_command docs/man/${name}.gz $dir
219
220EOF
221                        # Releases have the docs pre-made, but users
222                        # may want to rebuild them for some reason.
223                        my $docbook_source = "docs/docbook/${name}";
224                        $docbook_source =~ s/\.[58]$/.xml/;
225                        print MAKE <<EOF;
226docs/man/${name}.gz: $docbook_source docs/docbook/bb-man.xsl
227        cd docs; \$(MAKE) man/${name}.gz
228
229EOF
230                        push @parcel_deps, "$dir/${name}.gz";
231                }
232                elsif($type eq 'html')
233                {
234                        print MAKE <<EOF;
235$dir/docs/${name}.html: docs/htmlguide/man-html/${name}.html
236        mkdir -p $dir/docs
237        $copy_command docs/htmlguide/man-html/${name}.html $dir/docs
238
239EOF
240                        # Releases have the docs pre-made, but users
241                        # may want to rebuild them for some reason.
242                        my $docbook_source = "docs/docbook/${name}.xml";
243                        print MAKE <<EOF;
244docs/htmlguide/man-html/${name}.html: $docbook_source docs/docbook/bb-nochunk-book.xsl
245        cd docs; \$(MAKE) htmlguide/man-html/${name}.html
246
247EOF
248                        push @parcel_deps, "$dir/docs/${name}.html";
249                }
250                elsif ($type eq 'subdir')
251                {
252                        shift @args;
253                        my $subdir = shift @args;
254                        print MAKE <<EOF;
255.PHONY: $name-build $name-clean
256
257$name-build:
258        cd $subdir; \$(MAKE) @args
259
260$name-clean:
261        cd $name; \$(MAKE) clean
262EOF
263                        push @parcel_deps, "$name-build";
264                        push @clean_deps,  "$name-clean";
265                }
266        }
267
268        print MAKE <<EOF;
269build-$parcel:  $target
270
271$target: @parcel_deps
272        test -d $dir || mkdir $dir
273EOF
274       
275        for(@{$parcel_contents{$parcel}})
276        {
277                my @args = split /\s+/;
278
279                my ($type,$name,$dest) = @args;
280
281                my $optional = 0;
282                my $install  = 1;
283
284                if ($type eq 'optional')
285                {
286                        $optional = 1;
287                        shift @args;
288                        ($type,$name,$dest) = @args;
289                }
290
291                if ($type eq 'noinstall')
292                {
293                        $install = 0;
294                        shift @args;
295                        ($type,$name,$dest) = @args;
296                }
297
298                if ($type eq 'script')
299                {
300                        # remove path from script name
301                        $name =~ s{.*/}{};
302                }
303
304                if ($type eq 'html')
305                {
306                        $dest = "share/doc/@PACKAGE_TARNAME@";
307                        $name = "docs/$name.html";
308                }
309
310                if ($type eq 'man')
311                {
312                        $name =~ /([0-9])$/;
313                        $dest = "man/man$1";
314                        $name =~ s/$/\.gz/;
315                }
316
317                if ($install and not $target_windows and not $type eq "subdir")
318                {
319                        my $local_install_dir = $install_into_dir;
320                        if (defined $dest)
321                        {
322                                if ($dest =~ m,^/,)
323                                {
324                                        # Don't add $prefix if $dest is a literal path
325                                        $local_install_dir = $dest;
326                                }
327                                else
328                                {
329                                        $local_install_dir = "@prefix@/$dest";
330                                }
331                        }
332                        print SCRIPT "mkdir -p " .
333                                "\${DESTDIR}$local_install_dir/\n";
334                        print SCRIPT "$install_bin $name " .
335                                "\${DESTDIR}$local_install_dir\n";
336                }
337        }
338
339        unless ($target_windows)
340        {       
341                close SCRIPT;
342                chmod 0755,"parcels/scripts/install-$parcel";
343        }
344       
345        my $root = BoxPlatform::parcel_root($parcel);
346
347        unless ($target_windows)
348        {
349                print MAKE "\tcp parcels/scripts/install-$parcel $dir\n";
350        }
351
352        print MAKE "\t(cd parcels; tar cf - $root | gzip -9 - > $root.tgz )\n";
353       
354        print MAKE "\n";
355
356        unless ($target_windows)
357        {       
358                print MAKE "install-$parcel:\n";
359                print MAKE "\t(cd $dir; ./install-$parcel)\n\n";
360        }
361}
362
363print MAKE <<EOF;
364install:
365        cat local/install.msg
366
367clean: @clean_deps
368        cd docs; \$(MAKE) clean
369EOF
370
371if ($build_os eq 'CYGWIN')
372{
373        print MAKE "\tfind release debug       -type f | xargs -r rm\n";
374        print MAKE "\tfind . -name 'autogen_*' -type f | xargs -r rm\n";
375}
376else
377{
378        print MAKE "\tfind release debug       -type f -exec rm {} \\;\n";
379        print MAKE "\tfind . -name 'autogen_*' -type f -exec rm {} \\;\n";
380}
381
382for my $parcel (@parcels)
383{
384        # need to use -f to avoid error if they don't exist (already cleaned)
385        print MAKE "\trm -rf ", BoxPlatform::parcel_dir($parcel),    "\n";
386        print MAKE "\trm -f  ", BoxPlatform::parcel_target($parcel), "\n";
387}
388
389close MAKE;
390
391open INSTALLMSG,">local/install.msg" or die "Can't open install message file for writing";
392print INSTALLMSG <<__E;
393
394Parcels need to be installed separately, and as root. Type one of the following:
395
396__E
397
398for(@parcels)
399{
400        print INSTALLMSG "    $make_command install-".$_."\n";
401}
402print INSTALLMSG "\n";
403
404close INSTALLMSG;
405
Note: See TracBrowser for help on using the repository browser.