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
# the first part was done by looking at the config.status files generated
21
my $ac_sacfiles = $ARGV[1];
22
my $ac_given_srcdir=$ARGV[2];
23
my $ac_given_INSTALL=$ARGV[3];
25
#print "ac_subs=$ac_subs\n";
26
#print "ac_sacfiles=$ac_sacfiles\n";
27
#print "ac_given_srcdir=$ac_given_srcdir\n";
28
#print "ac_given_INSTALL=$ac_given_INSTALL\n";
30
my ($srcdir, $top_srcdir);
32
my $bad_perl = ($] < 5.005);
34
open(CF, "< $ac_subs") || die "can't open $ac_subs: $!";
42
print "Using perl older than version 5.005\n";
43
foreach my $pat (@subs) {
44
if ( ($pat =~ /s%([^%]*)%([^%]*)%g/ )
45
|| ($pat =~ m%/([^/]*)/([^/]*)/g% )
46
|| ($pat =~ /s%([^%]*)%([^%]*)%;t/ )
47
|| ($pat =~ m%/([^/]*)/([^/]*)/;t% )
48
|| ($pat =~ /s,([^,]*),(.*),;t/)
50
# form : s%bla%blubb%g
51
# or s%bla%blubb%;t t (autoconf > 2.13 and < 2.52 ?)
52
# or s,bla,blubb,;t t (autoconf 2.52)
55
$repl =~ s/\\(.)/$1/g;
56
push @comp_subs, make_closure($srch, $repl);
58
} elsif ( ($pat =~ /%([^%]*)%d/ )
59
|| ($pat =~ m%/([^/]*)/d% )
61
push @comp_subs, make_closure($1, "");
63
die "Uhh. Malformed pattern in $ac_subs ($pat)"
64
unless ( $pat =~ /^\s*$/ ); # ignore white lines
68
foreach my $pat (@subs) {
69
if ( ($pat =~ /s%([^%]*)%([^%]*)%g/ ) ||
70
($pat =~ /s%([^%]*)%([^%]*)%;t/ ) ||
71
($pat =~ /s,([^,]*),(.*),;t/) ) {
72
# form : s%bla%blubb%g
73
# or s%bla%blubb%;t t (autoconf > 2.13 and < 2.52 ?)
74
# or s,bla,blubb,;t t (autoconf 2.52)
77
push @comp_match, eval "qr/\Q$srch\E/"; # compile match pattern
78
$repl =~ s/\\(.)/$1/g;
79
push @comp_subs, $repl;
80
} elsif ( ($pat =~ /%([^%]*)%d/ )
81
|| ($pat =~ m%/([^/]*)/d% )
83
push @comp_match, eval "qr/\Q$1\E/";
86
die "Uhh. Malformed pattern in $ac_cs_root.subs ($pat)"
87
unless ( $pat =~ /^\s*$/ ); # ignore white lines
93
# read the list of files to be patched, form:
94
# ./Makefile arts/Makefile arts/examples/Makefile arts/flow/Makefile
96
open(CF, "< $ac_sacfiles") || die "can't open $ac_sacfiles: $!";
103
foreach $ac_file (@ac_files) {
104
next if $ac_file =~ /\.\./;
105
next if $ac_file =~ /^\s*$/;
107
my ($ac_dir, $ac_dots, $ac_dir_suffix);
109
if ($ac_file =~ /.*:.*/ ) {
110
($ac_file_in = $ac_file) =~ s%[^:]*:%%;
113
$ac_file_in = $ac_file.".in";
116
# Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories.
118
# Remove last slash and all that follows it. Not all systems have dirname.
119
($ac_dir = $ac_file) =~ s%/[^/][^/]*$%%;
120
if ( ($ac_dir ne $ac_file) && ($ac_dir ne ".")) {
121
# The file is in a subdirectory.
122
if (! -d "$ac_dir") { mkdir "$ac_dir", 0777; }
123
($ac_dir_suffix = $ac_dir) =~ s%^./%%;
124
$ac_dir_suffix="/".$ac_dir_suffix;
125
# A "../" for each directory in $ac_dir_suffix.
126
($ac_dots = $ac_dir_suffix) =~ s%/[^/]*%../%g;
132
if ($ac_given_srcdir eq ".") {
135
( $top_srcdir = $ac_dots) =~ s%/$%%;
136
} else { $top_srcdir="."; }
137
} elsif ($ac_given_srcdir =~ m%^/%) {
138
$srcdir=$ac_given_srcdir.$ac_dir_suffix;
139
$top_srcdir = $ac_given_srcdir;
141
$srcdir = $ac_dots.$ac_given_srcdir.$ac_dir_suffix;
142
$top_srcdir = $ac_dots.$ac_given_srcdir;
145
if ($ac_given_INSTALL) {
146
if ($ac_given_INSTALL =~ m%^/% ) {
147
$INSTALL = $ac_given_INSTALL;
149
$INSTALL = $ac_dots.$ac_given_INSTALL;
153
print "fast creating $ac_file\n";
156
my $fname=$ac_file_in;
158
my $configure_input="Generated automatically from $fname by config.pl.";
159
if ($ac_file =~ /.*[Mm]akefile.*/) {
160
$ac_comsub="# ".$configure_input."\n"; # for the first line in $ac_file
164
($ac_file_inputs = $ac_file_in) =~ s%^%$ac_given_srcdir/%;
165
$ac_file_inputs =~ s%:% $ac_given_srcdir/%g;
167
patch_file($ac_file, $ac_file_inputs, $ac_comsub);
171
my ($outf, $infiles, $firstline) = @_;
173
my @infiles=split(' ', $infiles);
177
$filedata = $firstline;
179
foreach my $name (@infiles) {
180
if (open(CF, "< $name")) {
186
print STDERR "can't open $name: $!"."\n";
190
$filedata =~ s%\@configure_input\@%$configure_input%g;
191
$filedata =~ s%\@srcdir\@%$srcdir%g;
192
$filedata =~ s%\@top_srcdir\@%$top_srcdir%g;
193
$filedata =~ s%\@INSTALL\@%$INSTALL%g;
196
while ($i <= $#comp_subs) {
197
my $ref = $comp_subs[$i];
202
while ($i <= $#comp_match) {
203
$filedata =~ s/$comp_match[$i]/$comp_subs[$i]/g;
207
open(CF, "> $outf") || die "can't create $outf: $!";
213
my ($pat, $sub) = @_;
214
$pat =~ s/\@/\\@/g; # @bla@ -> \@bla\@
215
$pat =~ s/\$/\\\$/g; # $bla -> \$bla
218
my $ret = eval "return sub { my \$ref=shift; \$\$ref =~ s%$pat%$sub%g; }";
220
print "can't create CODE: $@\n";