2
# a script for use by autoconf to make the Makefiles
3
# from the Makefile.in's
5
# the original autoconf mechanism first splits all substitutions into groups
6
# of ca. 90, and than invokes sed for _every_ Makefile.in and every group
7
# (so around 2-3 times per Makefile.in). So this takes forever, as sed
8
# has to recompile the regexps every time.
10
# this script does better. It changes all Makefile.ins in one process.
11
# in kdelibs the time for building Makefile went down from 2:59 min to 13 sec!
13
# written by Michael Matz <matz@kde.org>
14
# adapted by Dirk Mueller <mueller@kde.org>
16
# This file is free software; you can redistribute it and/or
17
# modify it under the terms of the GNU Library General Public
18
# License as published by the Free Software Foundation; either
19
# version 2 of the License, or (at your option) any later version.
21
# This library is distributed in the hope that it will be useful,
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24
# Library General Public License for more details.
26
# You should have received a copy of the GNU Library General Public License
27
# along with this library; see the file COPYING.LIB. If not, write to
28
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29
# Boston, MA 02111-1307, USA.
32
my $ac_sacfiles = $ARGV[1];
33
my $ac_given_srcdir=$ARGV[2];
34
my $ac_given_INSTALL=$ARGV[3];
36
#print "ac_subs=$ac_subs\n";
37
#print "ac_sacfiles=$ac_sacfiles\n";
38
#print "ac_given_srcdir=$ac_given_srcdir\n";
39
#print "ac_given_INSTALL=$ac_given_INSTALL\n";
41
my ($srcdir, $top_srcdir);
43
my $bad_perl = ($] < 5.005);
45
open(CF, "< $ac_subs") || die "can't open $ac_subs: $!";
53
print "Using perl older than version 5.005\n";
54
foreach my $pat (@subs) {
55
if ( ($pat =~ /s%([^%]*)%([^%]*)%g/ )
56
|| ($pat =~ m%/([^/]*)/([^/]*)/g% )
57
|| ($pat =~ /s%([^%]*)%([^%]*)%;t/ )
58
|| ($pat =~ m%/([^/]*)/([^/]*)/;t% )
59
|| ($pat =~ /s,([^,]*),(.*),;t/)
61
# form : s%bla%blubb%g
62
# or s%bla%blubb%;t t (autoconf > 2.13 and < 2.52 ?)
63
# or s,bla,blubb,;t t (autoconf 2.52)
66
$repl =~ s/\\(.)/$1/g;
67
push @comp_subs, make_closure($srch, $repl);
69
} elsif ( ($pat =~ /%([^%]*)%d/ )
70
|| ($pat =~ m%/([^/]*)/d% )
72
push @comp_subs, make_closure($1, "");
74
die "Uhh. Malformed pattern in $ac_subs ($pat)"
75
unless ( $pat =~ /^\s*$/ ); # ignore white lines
79
foreach my $pat (@subs) {
80
if ( ($pat =~ /s%([^%]*)%([^%]*)%g/ ) ||
81
($pat =~ /s%([^%]*)%([^%]*)%;t/ ) ||
82
($pat =~ /s,([^,]*),(.*),;t/) ) {
83
# form : s%bla%blubb%g
84
# or s%bla%blubb%;t t (autoconf > 2.13 and < 2.52 ?)
85
# or s,bla,blubb,;t t (autoconf 2.52)
88
push @comp_match, eval "qr/\Q$srch\E/"; # compile match pattern
89
$repl =~ s/\\(.)/$1/g;
90
push @comp_subs, $repl;
91
} elsif ( ($pat =~ /%([^%]*)%d/ )
92
|| ($pat =~ m%/([^/]*)/d% )
94
push @comp_match, eval "qr/\Q$1\E/";
97
die "Uhh. Malformed pattern in $ac_cs_root.subs ($pat)"
98
unless ( $pat =~ /^\s*$/ ); # ignore white lines
104
# read the list of files to be patched, form:
105
# ./Makefile arts/Makefile arts/examples/Makefile arts/flow/Makefile
107
open(CF, "< $ac_sacfiles") || die "can't open $ac_sacfiles: $!";
114
foreach $ac_file (@ac_files) {
115
next if $ac_file =~ /\.\./;
116
next if $ac_file =~ /^\s*$/;
118
my ($ac_dir, $ac_dots, $ac_dir_suffix);
120
if ($ac_file =~ /.*:.*/ ) {
121
($ac_file_in = $ac_file) =~ s%[^:]*:%%;
124
$ac_file_in = $ac_file.".in";
127
# Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories.
129
# Remove last slash and all that follows it. Not all systems have dirname.
130
($ac_dir = $ac_file) =~ s%/[^/][^/]*$%%;
131
if ( ($ac_dir ne $ac_file) && ($ac_dir ne ".")) {
132
# The file is in a subdirectory.
133
if (! -d "$ac_dir") { mkdir "$ac_dir", 0777; }
134
($ac_dir_suffix = $ac_dir) =~ s%^./%%;
135
$ac_dir_suffix="/".$ac_dir_suffix;
136
# A "../" for each directory in $ac_dir_suffix.
137
($ac_dots = $ac_dir_suffix) =~ s%/[^/]*%../%g;
143
if ($ac_given_srcdir eq ".") {
146
( $top_srcdir = $ac_dots) =~ s%/$%%;
147
} else { $top_srcdir="."; }
148
} elsif ($ac_given_srcdir =~ m%^/%) {
149
$srcdir=$ac_given_srcdir.$ac_dir_suffix;
150
$top_srcdir = $ac_given_srcdir;
152
$srcdir = $ac_dots.$ac_given_srcdir.$ac_dir_suffix;
153
$top_srcdir = $ac_dots.$ac_given_srcdir;
156
if ($ac_given_INSTALL) {
157
if ($ac_given_INSTALL =~ m%^/% ) {
158
$INSTALL = $ac_given_INSTALL;
160
$INSTALL = $ac_dots.$ac_given_INSTALL;
164
print "fast creating $ac_file\n";
167
my $fname=$ac_file_in;
169
my $configure_input="Generated automatically from $fname by config.pl.";
170
if ($ac_file =~ /.*[Mm]akefile.*/) {
171
$ac_comsub="# ".$configure_input."\n"; # for the first line in $ac_file
175
($ac_file_inputs = $ac_file_in) =~ s%^%$ac_given_srcdir/%;
176
$ac_file_inputs =~ s%:% $ac_given_srcdir/%g;
178
patch_file($ac_file, $ac_file_inputs, $ac_comsub);
182
my ($outf, $infiles, $firstline) = @_;
184
my @infiles=split(' ', $infiles);
188
$filedata = $firstline;
190
foreach my $name (@infiles) {
191
if (open(CF, "< $name")) {
197
print STDERR "can't open $name: $!"."\n";
201
$filedata =~ s%\@configure_input\@%$configure_input%g;
202
$filedata =~ s%\@srcdir\@%$srcdir%g;
203
$filedata =~ s%\@top_srcdir\@%$top_srcdir%g;
204
$filedata =~ s%\@INSTALL\@%$INSTALL%g;
207
while ($i <= $#comp_subs) {
208
my $ref = $comp_subs[$i];
213
while ($i <= $#comp_match) {
214
$filedata =~ s/$comp_match[$i]/$comp_subs[$i]/g;
218
open(CF, "> $outf") || die "can't create $outf: $!";
224
my ($pat, $sub) = @_;
225
$pat =~ s/\@/\\@/g; # @bla@ -> \@bla\@
226
$pat =~ s/\$/\\\$/g; # $bla -> \$bla
229
my $ret = eval "return sub { my \$ref=shift; \$\$ref =~ s%$pat%$sub%g; }";
231
print "can't create CODE: $@\n";