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@ifh.de>
15
# the first part was done by looking at the config.status files generated
18
my $ac_cs_root=$ARGV[0];
19
my $ac_given_srcdir=$ARGV[1];
20
my $ac_given_INSTALL=$ARGV[2];
22
# print "ac_cs_root=$ac_cs_root\n";
23
# print "ac_given_srcdir=$ac_given_srcdir\n";
24
# print "ac_given_INSTALL=$ac_given_INSTALL\n";
26
my ($srcdir, $top_srcdir);
28
my $bad_perl = ($] < 5.005);
30
open(CF, "< $ac_cs_root.subs") || die "can't open $ac_cs_root.subs: $!";
38
print "Using perl older than version 5.005\n";
39
foreach my $pat (@subs) {
40
if ( ($pat =~ /s%([^%]*)%([^%]*)%g/ )
41
|| ($pat =~ m%/([^/]*)/([^/]*)/g% )
42
|| ($pat =~ /s%([^%]*)%([^%]*)%;t/ )
43
|| ($pat =~ m%/([^/]*)/([^/]*)/;t% )
45
# form : s%bla%blubb%g
46
# or s%bla%blubb%;t t (newer autoconf)
47
push @comp_subs, make_closure($1, $2);
48
} elsif ( ($pat =~ /%([^%]*)%d/ )
49
|| ($pat =~ m%/([^/]*)/d% )
51
push @comp_subs, make_closure($1, "");
53
die "Uhh. Malformed pattern in $ac_cs_root.subs ($pat)"
54
unless ( $pat =~ /^\s*$/ ); # ignore white lines
58
foreach my $pat (@subs) {
59
if ( ($pat =~ /s%([^%]*)%([^%]*)%g/ )
60
|| ($pat =~ m%/([^/]*)/([^/]*)/g% )
61
|| ($pat =~ /s%([^%]*)%([^%]*)%;t/ )
62
|| ($pat =~ m%/([^/]*)/([^/]*)/;t% )
64
# form : s%bla%blubb%g
65
# or s%bla%blubb%;t t (newer autoconf)
66
push @comp_match, eval "qr/\Q$1\E/"; # compile match pattern
68
} elsif ( ($pat =~ /%([^%]*)%d/ )
69
|| ($pat =~ m%/([^/]*)/d% )
71
push @comp_match, eval "qr/\Q$1\E/";
74
die "Uhh. Malformed pattern in $ac_cs_root.subs ($pat)"
75
unless ( $pat =~ /^\s*$/ ); # ignore white lines
81
# read the list of files to be patched, form:
82
# ./Makefile arts/Makefile arts/examples/Makefile arts/flow/Makefile
84
open(CF, "< $ac_cs_root.sacfiles") || die "can't open $ac_cs_root.sacfiles: $!";
90
foreach $ac_file (@ac_files) {
91
next if $ac_file =~ /\.\./;
92
next if $ac_file =~ /^\s*$/;
94
my ($ac_dir, $ac_dots, $ac_dir_suffix);
96
if ($ac_file =~ /.*:.*/ ) {
97
($ac_file_in = $ac_file) =~ s%[^:]*:%%;
100
$ac_file_in = $ac_file.".in";
103
# Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories.
105
# Remove last slash and all that follows it. Not all systems have dirname.
106
($ac_dir = $ac_file) =~ s%/[^/][^/]*$%%;
107
if ( ($ac_dir ne $ac_file) && ($ac_dir ne ".")) {
108
# The file is in a subdirectory.
109
if (! -d "$ac_dir") { mkdir "$ac_dir", 0777; }
110
($ac_dir_suffix = $ac_dir) =~ s%^./%%;
111
$ac_dir_suffix="/".$ac_dir_suffix;
112
# A "../" for each directory in $ac_dir_suffix.
113
($ac_dots = $ac_dir_suffix) =~ s%/[^/]*%../%g;
119
if ($ac_given_srcdir eq ".") {
122
( $top_srcdir = $ac_dots) =~ s%/$%%;
123
} else { $top_srcdir="."; }
124
} elsif ($ac_given_srcdir =~ m%^/%) {
125
$srcdir=$ac_given_srcdir.$ac_dir_suffix;
126
$top_srcdir = $ac_given_srcdir;
128
$srcdir = $ac_dots.$ac_given_srcdir.$ac_dir_suffix;
129
$top_srcdir = $ac_dots.$ac_given_srcdir;
132
if ($ac_given_INSTALL) {
133
if ($ac_given_INSTALL =~ m%^/% ) {
134
$INSTALL = $ac_given_INSTALL;
136
$INSTALL = $ac_dots.$ac_given_INSTALL;
140
print "fast creating $ac_file\n";
143
my $fname=$ac_file_in;
145
my $configure_input="Generated automatically from $fname by config.pl.";
146
if ($ac_file =~ /.*[Mm]akefile.*/) {
147
$ac_comsub="# ".$configure_input."\n"; # for the first line in $ac_file
151
($ac_file_inputs = $ac_file_in) =~ s%^%$ac_given_srcdir/%;
152
$ac_file_inputs =~ s%:% $ac_given_srcdir/%g;
154
patch_file($ac_file, $ac_file_inputs, $ac_comsub);
158
my ($outf, $infiles, $firstline) = @_;
160
my @infiles=split(' ', $infiles);
164
$filedata = $firstline;
166
foreach my $name (@infiles) {
167
if (open(CF, "< $name")) {
173
print STDERR "can't open $name: $!"."\n";
177
$filedata =~ s%\@configure_input\@%$configure_input%g;
178
$filedata =~ s%\@srcdir\@%$srcdir%g;
179
$filedata =~ s%\@top_srcdir\@%$top_srcdir%g;
180
$filedata =~ s%\@INSTALL\@%$INSTALL%g;
183
while ($i <= $#comp_subs) {
184
my $ref = $comp_subs[$i];
189
while ($i <= $#comp_match) {
190
$filedata =~ s/$comp_match[$i]/$comp_subs[$i]/g;
194
open(CF, "> $outf") || die "can't create $outf: $!";
200
my ($pat, $sub) = @_;
201
$pat =~ s/\@/\\@/g; # @bla@ -> \@bla\@
202
$pat =~ s/\$/\\\$/g; # $bla -> \$bla
205
my $ret = eval "return sub { my \$ref=shift; \$\$ref =~ s%$pat%$sub%g; }";
207
print "can't create CODE: $@\n";