3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
16 # The Original Code is Mozilla Communicator client code, released
19 # The Initial Developer of the Original Code is
20 # Netscape Communications Corporation.
21 # Portions created by the Initial Developer are Copyright (C) 1998-1999
22 # the Initial Developer. All Rights Reserved.
25 # Jonathan Granrose (granrose@netscape.com)
26 # Jean-Jacques Enser (jj@netscape.com)
28 # Alternatively, the contents of this file may be used under the terms of
29 # either of the GNU General Public License Version 2 or later (the "GPL"),
30 # or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 # in which case the provisions of the GPL or the LGPL are applicable instead
32 # of those above. If you wish to allow use of your version of this file only
33 # under the terms of either the GPL or the LGPL, and not to allow others to
34 # use your version of this file under the terms of the MPL, indicate your
35 # decision by deleting the provisions above and replace them with the notice
36 # and other provisions required by the GPL or the LGPL. If you do not delete
37 # the provisions above, a recipient may use your version of this file under
38 # the terms of any one of the MPL, the GPL or the LGPL.
40 # ***** END LICENSE BLOCK *****
44 # traverse directories created by pkgcp.pl and merge multiple .xpt files into
45 # a single .xpt file to improve startup performance.
50 # initialize variables
51 $srcdir = ""; # root directory being copied from
52 $destdir = ""; # root directory being copied to
53 $finaldir = ""; # where to put the final linked XPT
54 $verbose = 0; # shorthand for --debug 1
55 $debug = 0; # controls amount of debug output
56 $help = 0; # flag: if set, print usage
57 $xptlink = ""; # path to the xpt_link binary
59 # get command line options
60 $return = GetOptions
( "source|s=s", \
$srcdir,
61 "destination|d=s", \
$destdir,
62 "final|f=s", \
$finaldir,
65 "verbose|v", \
$verbose,
66 "xptlink|x=s", \
$xptlink,
67 "<>", \
&do_badargument
70 if ($finaldir ne "") {
77 # remove extra slashes from $destdir
81 if ($verbose && !($debug)) {
83 } elsif ($debug != 0) {
84 $debug = abs ($debug);
85 ($debug >= 2) && print "debug level: $debug\n";
91 die "Error: couldn't parse command line options. See \'$0 --help' for options.\nExiting...\n";
96 $xptdirs = (); # directories in the destination directory
98 ($debug >= 1) && print "\nLinking .xpt files...\n";
99 ($debug >= 2) && print "do_xptlink():\n";
101 # get list of directories on which to run xptlink
102 opendir (DESTDIR
, "$destdir") ||
103 die "Error: could not open directory $destdir. Exiting...\n";
104 @xptdirs = sort ( grep (!/^\./, readdir (DESTDIR
) ) );
105 ($debug >= 4) && print "xptdirs: @xptdirs\n";
108 foreach my $component (@xptdirs) {
109 ($debug >= 1) && print "[$component]\n";
111 print ("Checking for '$destdir/$component/$bindir"."components'\n") if $debug >= 3;
113 if (-d
"$destdir/$component/$bindir"."components") {
114 warn "File '$destdir/$component/$bindir"."components/$component.xpt' already exists."
115 if -f
"$destdir/$component/$bindir"."components/$component.xpt";
117 # create list of .xpt files in cwd
120 ($debug >= 4) && print "opendir: $destdir/$component/$bindir"."components\n";
121 opendir (COMPDIR
, "$destdir/$component/$bindir"."components") ||
122 die "Error: cannot open $destdir/$component/$bindir"."components. Exiting...\n";
123 ($debug >= 3) && print "Creating list of .xpt files...\n";
124 my @files = sort ( grep (!/^\./, readdir (COMPDIR
)));
125 foreach my $file (@files) {
126 ($debug >= 6) && print "$file\n";
127 if ( $file =~ /\.xpt$/ ) {
128 push @xptfiles, "$destdir/$component/$bindir"."components/$file";
129 ($debug >= 8) && print "xptfiles:\t@xptfiles\n";
134 # merge .xpt files into one if we found any in the dir
135 if ( scalar(@xptfiles) ) {
136 my ($merged, $fmerged);
137 if ($finaldir ne "") {
138 $merged = "$finaldir/$component.xpt";
141 $fmerged = "$destdir/$component/$bindir"."components/$component.xpt";
142 $merged = $fmerged.".new";
147 if ($^O
eq "cygwin") {
148 @realxptfiles = map {my $file = `cygpath -t mixed $_`;
151 $realmerged = `cygpath -t mixed $merged`;
155 @realxptfiles = @xptfiles;
156 $realmerged = $merged;
159 my $cmdline = "$xptlink $realmerged @realxptfiles";
160 ($debug >= 4) && print "$cmdline\n";
161 system($cmdline) == 0 || die ("'$cmdline' failed");
163 if ($finaldir eq "") {
164 # remove old .xpt files in the component directory.
165 ($debug >= 2) && print "Deleting individual xpt files.\n";
166 for my $file (@xptfiles) {
167 ($debug >= 4) && print "\t$file";
169 die "Couldn't unlink file $file.\n";
170 ($debug >= 4) && print "\t\tdeleted\n\n";
173 ($debug >= 2) && print "Renaming $merged as $fmerged\n";
174 rename ($merged, $fmerged) ||
175 die "Rename of '$merged' to '$fmerged' failed.\n";
180 ($debug >= 1) && print "Linking .xpt files completed.\n";
186 # Check that arguments to script are valid.
192 ($debug >= 2) && print "check_arguments():\n";
194 # if --help print usage
200 # make sure required variables are set:
201 # check source directory
202 if ( $srcdir eq "" ) {
203 print "Error: source directory (--source) not specified.\n";
205 } elsif ((! -d
$srcdir) || (! -r
$srcdir)) {
206 print "Error: source directory \"$srcdir\" is not a directory or is unreadable.\n";
211 if ( $destdir eq "" ) {
212 print "Error: destination directory (--destdir) not specified.\n";
214 } elsif ((! -d
$destdir) || (! -w
$destdir)) {
215 print "Error: destination directory \"$destdir\" is not a directory or is not writeable.\n";
220 print "See \'$0 --help\' for more information.\n";
221 print "Exiting...\n";
225 if ($xptlink eq "") {
226 $xptlink = "$srcdir/bin/xpt_link";
232 # This is called by GetOptions when there are extra command line arguments
233 # it doesn't understand.
237 warn "Warning: unknown command line option specified: @_.\n";
242 # display usage information
246 ($debug >= 2) && print "print_usage():\n";
251 Traverse component directory specified and merge multiple existing
252 .xpt files into single new .xpt files for improved startup time.
256 -s, --source <directory>
257 Specifies the directory from which the component files were
258 copied. Typically, this will be the same directory used by
262 -d, --destination <directory>
263 Specifies the directory in which the component directories are
264 located. Typically, this will be the same directory used by
269 Specifies which type of system this is. Used for setting path
270 delimiters correctly.
274 Prints this information.
278 Controls verbosity of debugging output, 10 being most verbose.
279 1 : same as --verbose.
280 2 : includes function calls.
281 3 : includes source and destination for each copy.
285 Print component names and files copied/deleted.
291 $0 --os unix -source /builds/mozilla/dist --destination /h/lithium/install --os unix --verbose
293 Note: options can be specified by either a leading '--' or '-'.