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.org code.
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.
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.
37 # ***** END LICENSE BLOCK *****
39 # acoutput-fast.pl - Quickly create makefiles that are in a common format.
41 # Most of the makefiles in mozilla only refer to two configure variables:
44 # However, configure does not know any better and it runs sed on each file
45 # with over 150 replacement rules (slow as molasses).
47 # This script takes a list of makefiles as input. For example,
49 # echo $MAKEFILES | acoutput-fast.pl
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
55 # CONFIG_FILES="unhandled_files..."; export CONFIG_FILES
57 # This command can be used to have config.status create the unhandled
60 # eval "echo $MAKEFILES | acoutput-fast.pl"
61 # AC_OUTPUT($MAKEFILES)
63 # Send comments, improvements, bugs to Steve Lamm (slamm@netscape.com).
68 return '.' if not $dir =~ m
%/%;
69 $dir =~ s
%/[^/][^/]*$%%;
73 # Create one directory. Assumes it doesn't already exist.
74 # Will create parent(s) if needed.
75 sub create_directory
{
77 my $parent = dirname
($dir);
78 create_directory
($parent) if not -d
$parent;
82 # Create all the directories at once.
83 # This can be much faster than calling mkdir() for each one.
84 sub create_directories
{
88 foreach $ac_file (@makefiles) {
89 push @dirs, dirname
($ac_file);
91 # Call mkdir with the directories sorted by subdir count (how many /'s)
93 foreach $dir (@dirs) {
95 print STDERR
"Creating directory $dir\n";
96 create_directory
($dir);
102 while($arg = shift) {
103 if ($arg =~ /^--srcdir=/) {
104 $ac_given_srcdir = (split /=/, $arg)[1];
106 if ($arg =~ /^--cygwin-srcdir/) {
107 $ac_cygwin_srcdir = (split /=/, $arg)[1];
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 '';
117 if (!$ac_cygwin_srcdir) {
118 $ac_cygwin_srcdir = $ac_given_srcdir;
121 # Read list of makefiles from the stdin or,
122 # from files listed on the command-line.
125 push @makefiles, split while (<STDIN
>);
127 # Create all the directories at once.
128 # This can be much faster than calling mkdir() for each one.
129 create_directories
(@makefiles);
131 # Output the makefiles.
134 foreach $ac_file (@makefiles) {
135 if (not $ac_file =~ /Makefile$/ or $ac_file =~ /:/) {
136 push @unhandled, $ac_file;
139 $ac_file_in = "$ac_given_srcdir/$ac_file.in";
140 $ac_dir = dirname
($ac_file);
141 if ($ac_dir eq '.') {
145 $ac_dir_suffix = "/$ac_dir";
146 $ac_dir_suffix =~ s
%^/\./%/%;
147 $ac_dots = $ac_dir_suffix;
148 $ac_dots =~ s
%/[^/]*%../%g;
150 if ($ac_given_srcdir eq '.') {
152 if ($ac_dots eq '') {
155 $top_srcdir = $ac_dots;
156 $top_srcdir =~ s
%/$%%;
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";
162 $srcdir = "$ac_dots$ac_cygwin_srcdir$ac_dir_suffix";
163 $top_srcdir = "$ac_dots$ac_cygwin_srcdir";
167 next if -M _
< -M
$ac_file_in;
168 print STDERR
"updating $ac_file\n";
170 print STDERR
"creating $ac_file\n";
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);
179 #if (/\@[_a-zA-Z]*\@.*\@[_a-zA-Z]*\@/) {
180 # warn "Two defines on a line:$ac_file:$.:$_";
181 # push @unhandled, $ac_file;
185 s/\@srcdir\@/$srcdir/g;
186 s/\@top_srcdir\@/$top_srcdir/g;
188 if (/\@[_a-zA-Z]*\@/) {
189 warn "Unknown variable:$ac_file:$.:$_";
190 push @unhandled, $ac_file;
199 # Print the shell command to be evaluated by configure.
201 print "CONFIG_FILES=\"".join(' ', @unhandled)."\"; export CONFIG_FILES\n";