/[jscoverage]/trunk/js/build/autoconf/acoutput-fast.pl
ViewVC logotype

Contents of /trunk/js/build/autoconf/acoutput-fast.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 399 - (show annotations)
Tue Dec 9 03:37:47 2008 UTC (11 years, 11 months ago) by siliconforks
File MIME type: text/plain
File size: 6004 byte(s)
Use SpiderMonkey from Firefox 3.1b2.

1 #! /usr/bin/env perl
2 #
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 #
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/
10 #
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
14 # License.
15 #
16 # The Original Code is mozilla.org code.
17 #
18 # The Initial Developer of the Original Code is
19 # Netscape Communications Corporation.
20 # Portions created by the Initial Developer are Copyright (C) 1999
21 # the Initial Developer. All Rights Reserved.
22 #
23 # Contributor(s):
24 #
25 # Alternatively, the contents of this file may be used under the terms of
26 # either of the GNU General Public License Version 2 or later (the "GPL"),
27 # or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
36 #
37 # ***** END LICENSE BLOCK *****
38
39 # acoutput-fast.pl - Quickly create makefiles that are in a common format.
40 #
41 # Most of the makefiles in mozilla only refer to two configure variables:
42 # @srcdir@
43 # @top_srcdir@
44 # However, configure does not know any better and it runs sed on each file
45 # with over 150 replacement rules (slow as molasses).
46 #
47 # This script takes a list of makefiles as input. For example,
48 #
49 # echo $MAKEFILES | acoutput-fast.pl
50 #
51 # The script creates each Makefile that only references @srcdir@ and
52 # @top_srcdir@. For other files, it lists them in a shell command that is
53 # printed to stdout:
54 #
55 # CONFIG_FILES="unhandled_files..."; export CONFIG_FILES
56 #
57 # This command can be used to have config.status create the unhandled
58 # files. For example,
59 #
60 # eval "echo $MAKEFILES | acoutput-fast.pl"
61 # AC_OUTPUT($MAKEFILES)
62 #
63 # Send comments, improvements, bugs to Steve Lamm (slamm@netscape.com).
64
65 #use File::Basename;
66 sub dirname {
67 my $dir = $_[0];
68 return '.' if not $dir =~ m%/%;
69 $dir =~ s%/[^/][^/]*$%%;
70 return $dir;
71 }
72
73 # Create one directory. Assumes it doesn't already exist.
74 # Will create parent(s) if needed.
75 sub create_directory {
76 my $dir = $_[0];
77 my $parent = dirname($dir);
78 create_directory($parent) if not -d $parent;
79 mkdir "$dir",0777;
80 }
81
82 # Create all the directories at once.
83 # This can be much faster than calling mkdir() for each one.
84 sub create_directories {
85 my @makefiles = @_;
86 my @dirs = ();
87 my $ac_file;
88 foreach $ac_file (@makefiles) {
89 push @dirs, dirname($ac_file);
90 }
91 # Call mkdir with the directories sorted by subdir count (how many /'s)
92 if (@dirs) {
93 foreach $dir (@dirs) {
94 if (not -d $dir) {
95 print STDERR "Creating directory $dir\n";
96 create_directory($dir);
97 }
98 }
99 }
100 }
101
102 while($arg = shift) {
103 if ($arg =~ /^--srcdir=/) {
104 $ac_given_srcdir = (split /=/, $arg)[1];
105 }
106 if ($arg =~ /^--cygwin-srcdir/) {
107 $ac_cygwin_srcdir = (split /=/, $arg)[1];
108 }
109 }
110
111 if (!$ac_given_srcdir) {
112 $ac_given_srcdir = $0;
113 $ac_given_srcdir =~ s|/?build/autoconf/.*$||;
114 $ac_given_srcdir = '.' if $ac_given_srcdir eq '';
115 }
116
117 if (!$ac_cygwin_srcdir) {
118 $ac_cygwin_srcdir = $ac_given_srcdir;
119 }
120
121 # Read list of makefiles from the stdin or,
122 # from files listed on the command-line.
123 #
124 @makefiles=();
125 push @makefiles, split while (<STDIN>);
126
127 # Create all the directories at once.
128 # This can be much faster than calling mkdir() for each one.
129 create_directories(@makefiles);
130
131 # Output the makefiles.
132 #
133 @unhandled=();
134 foreach $ac_file (@makefiles) {
135 if (not $ac_file =~ /Makefile$/ or $ac_file =~ /:/) {
136 push @unhandled, $ac_file;
137 next;
138 }
139 $ac_file_in = "$ac_given_srcdir/$ac_file.in";
140 $ac_dir = dirname($ac_file);
141 if ($ac_dir eq '.') {
142 $ac_dir_suffix = '';
143 $ac_dots = '';
144 } else {
145 $ac_dir_suffix = "/$ac_dir";
146 $ac_dir_suffix =~ s%^/\./%/%;
147 $ac_dots = $ac_dir_suffix;
148 $ac_dots =~ s%/[^/]*%../%g;
149 }
150 if ($ac_given_srcdir eq '.') {
151 $srcdir = '.';
152 if ($ac_dots eq '') {
153 $top_srcdir = '.'
154 } else {
155 $top_srcdir = $ac_dots;
156 $top_srcdir =~ s%/$%%;
157 }
158 } elsif ($ac_cygwin_srcdir =~ m%^/% or $ac_cygwin_srcdir =~ m%^.:/%) {
159 $srcdir = "$ac_cygwin_srcdir$ac_dir_suffix";
160 $top_srcdir = "$ac_cygwin_srcdir";
161 } else {
162 $srcdir = "$ac_dots$ac_cygwin_srcdir$ac_dir_suffix";
163 $top_srcdir = "$ac_dots$ac_cygwin_srcdir";
164 }
165
166 if (-e $ac_file) {
167 next if -M _ < -M $ac_file_in;
168 print STDERR "updating $ac_file\n";
169 } else {
170 print STDERR "creating $ac_file\n";
171 }
172
173 open (INFILE, "<$ac_file_in")
174 or ( warn "can't read $ac_file_in: No such file or directory\n" and next);
175 open (OUTFILE, ">$ac_file")
176 or ( warn "Unable to create $ac_file\n" and next);
177
178 while (<INFILE>) {
179 #if (/\@[_a-zA-Z]*\@.*\@[_a-zA-Z]*\@/) {
180 # warn "Two defines on a line:$ac_file:$.:$_";
181 # push @unhandled, $ac_file;
182 # last;
183 #}
184
185 s/\@srcdir\@/$srcdir/g;
186 s/\@top_srcdir\@/$top_srcdir/g;
187
188 if (/\@[_a-zA-Z]*\@/) {
189 warn "Unknown variable:$ac_file:$.:$_";
190 push @unhandled, $ac_file;
191 last;
192 }
193 print OUTFILE;
194 }
195 close INFILE;
196 close OUTFILE;
197 }
198
199 # Print the shell command to be evaluated by configure.
200 #
201 print "CONFIG_FILES=\"".join(' ', @unhandled)."\"; export CONFIG_FILES\n";
202

  ViewVC Help
Powered by ViewVC 1.1.24