~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to admin/config.pl

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
# a script for use by autoconf to make the Makefiles
 
3
# from the Makefile.in's
 
4
#
 
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.
 
9
#
 
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!
 
12
#
 
13
# written by Michael Matz <matz@kde.org>
 
14
# adapted by Dirk Mueller <mueller@kde.org>
 
15
#
 
16
# the first part was done by looking at the config.status files generated
 
17
# by configure.
 
18
 
19
 
 
20
my $ac_subs=$ARGV[0];
 
21
my $ac_sacfiles = $ARGV[1];
 
22
my $ac_given_srcdir=$ARGV[2];
 
23
my $ac_given_INSTALL=$ARGV[3];
 
24
 
 
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";
 
29
 
 
30
my ($srcdir, $top_srcdir);
 
31
my $INSTALL;
 
32
my $bad_perl = ($] < 5.005);
 
33
 
 
34
open(CF, "< $ac_subs") || die "can't open $ac_subs: $!";
 
35
my @subs = <CF>;
 
36
close(CF);
 
37
chomp @subs;
 
38
@comp_match=();
 
39
@comp_subs=();
 
40
 
 
41
if ($bad_perl) {
 
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/)
 
49
           ) {
 
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)
 
53
            my $srch = $1;
 
54
            my $repl = $2;
 
55
            $repl =~ s/\\(.)/$1/g;
 
56
            push @comp_subs, make_closure($srch, $repl);
 
57
 
 
58
        } elsif ( ($pat =~ /%([^%]*)%d/ )
 
59
           || ($pat =~ m%/([^/]*)/d% )
 
60
           ) {
 
61
            push @comp_subs, make_closure($1, "");
 
62
        } else {
 
63
            die "Uhh. Malformed pattern in $ac_subs ($pat)"
 
64
                unless ( $pat =~ /^\s*$/ );   # ignore white lines
 
65
        }
 
66
    }
 
67
} else {
 
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)
 
75
         my $srch = $1;
 
76
         my $repl = $2;
 
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% )
 
82
              ) {
 
83
        push @comp_match, eval "qr/\Q$1\E/";
 
84
        push @comp_subs, "";
 
85
      } else {
 
86
          die "Uhh. Malformed pattern in $ac_cs_root.subs ($pat)"
 
87
          unless ( $pat =~ /^\s*$/ );   # ignore white lines
 
88
      }
 
89
    }
 
90
}
 
91
undef @subs;
 
92
 
 
93
# read the list of files to be patched, form:
 
94
# ./Makefile arts/Makefile arts/examples/Makefile arts/flow/Makefile
 
95
 
 
96
open(CF, "< $ac_sacfiles") || die "can't open $ac_sacfiles: $!";
 
97
my @ac_files = <CF>;
 
98
close(CF);
 
99
chomp @ac_files;
 
100
 
 
101
 
 
102
my $ac_file;
 
103
foreach $ac_file (@ac_files) {
 
104
    next if $ac_file =~ /\.\./;
 
105
    next if $ac_file =~ /^\s*$/;
 
106
    my $ac_file_in;
 
107
    my ($ac_dir, $ac_dots, $ac_dir_suffix);
 
108
 
 
109
    if ($ac_file =~ /.*:.*/ ) {
 
110
        ($ac_file_in = $ac_file) =~ s%[^:]*:%%;
 
111
        $ac_file =~ s%:.*%%;
 
112
    } else {
 
113
        $ac_file_in = $ac_file.".in";
 
114
    }
 
115
 
 
116
# Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories.
 
117
 
 
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;
 
127
    } else {
 
128
        $ac_dir_suffix="";
 
129
        $ac_dots="";
 
130
    }
 
131
 
 
132
    if ($ac_given_srcdir eq ".") {
 
133
        $srcdir=".";
 
134
        if ($ac_dots) {
 
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;
 
140
    } else {
 
141
        $srcdir = $ac_dots.$ac_given_srcdir.$ac_dir_suffix;
 
142
        $top_srcdir = $ac_dots.$ac_given_srcdir;
 
143
    }
 
144
 
 
145
    if ($ac_given_INSTALL) {
 
146
        if ($ac_given_INSTALL =~ m%^/% ) {
 
147
            $INSTALL = $ac_given_INSTALL;
 
148
        } else {
 
149
            $INSTALL = $ac_dots.$ac_given_INSTALL;
 
150
        }
 
151
    }
 
152
 
 
153
    print "fast creating $ac_file\n";
 
154
    unlink $ac_file;
 
155
    my $ac_comsub="";
 
156
    my $fname=$ac_file_in;
 
157
    $fname =~ s%.*/%%;
 
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
 
161
    }
 
162
 
 
163
    my $ac_file_inputs;
 
164
    ($ac_file_inputs = $ac_file_in) =~ s%^%$ac_given_srcdir/%;
 
165
    $ac_file_inputs =~ s%:% $ac_given_srcdir/%g;
 
166
 
 
167
    patch_file($ac_file, $ac_file_inputs, $ac_comsub);
 
168
}
 
169
 
 
170
sub patch_file {
 
171
    my ($outf, $infiles, $firstline) = @_;
 
172
    my $filedata;
 
173
    my @infiles=split(' ', $infiles);
 
174
    my $i=0;
 
175
 
 
176
    if ($firstline) {
 
177
        $filedata = $firstline;
 
178
    }
 
179
    foreach my $name (@infiles) {
 
180
        if (open(CF, "< $name")) {
 
181
            while (<CF>) {
 
182
                $filedata .= $_;
 
183
            }
 
184
            close(CF);
 
185
        } else {
 
186
            print STDERR "can't open $name: $!"."\n";
 
187
        }
 
188
    }
 
189
 
 
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;
 
194
 
 
195
    if ($bad_perl) {
 
196
        while ($i <= $#comp_subs) {
 
197
            my $ref = $comp_subs[$i];
 
198
            &$ref(\$filedata);
 
199
            $i++;
 
200
        }
 
201
    } else {
 
202
        while ($i <= $#comp_match) {
 
203
            $filedata =~ s/$comp_match[$i]/$comp_subs[$i]/g;
 
204
            $i++;
 
205
        }
 
206
    }
 
207
    open(CF, "> $outf") || die "can't create $outf: $!";
 
208
    print CF $filedata;
 
209
    close(CF);
 
210
}
 
211
 
 
212
sub make_closure {
 
213
    my ($pat, $sub) = @_;
 
214
    $pat =~ s/\@/\\@/g;   # @bla@ -> \@bla\@
 
215
    $pat =~ s/\$/\\\$/g;  # $bla -> \$bla
 
216
    $sub =~ s/\@/\\@/g;
 
217
    $sub =~ s/\$/\\\$/g;
 
218
    my $ret = eval "return sub { my \$ref=shift; \$\$ref =~ s%$pat%$sub%g; }";
 
219
    if ($@) {
 
220
        print "can't create CODE: $@\n";
 
221
    }
 
222
    return $ret;
 
223
}