Install gettext-0.18.1.1.tar.gz
[msysgit.git] / mingw / share / doc / gettext / examples / hello-c++-kde / admin / config.pl
blob1af1cf27bb98da2332bc2595feca8934dd86b8a1
1 #!/usr/bin/perl
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.
31 my $ac_subs=$ARGV[0];
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);
42 my $INSTALL;
43 my $bad_perl = ($] < 5.005);
45 open(CF, "< $ac_subs") || die "can't open $ac_subs: $!";
46 my @subs = <CF>;
47 close(CF);
48 chomp @subs;
49 @comp_match=();
50 @comp_subs=();
52 if ($bad_perl) {
53 print "Using perl older than version 5.005\n";
54 foreach my $pat (@subs) {
55 if ( ($pat =~ m/s%([^%]*)%([^%]*)%g/ )
56 || ($pat =~ m/s%([^%]*)%([^%]*)%;t/ )
57 || ($pat =~ m/s,([^,]*),(.*),;t/)
58 || ($pat =~ m%s/([^/]*)/([^/]*)/g% )
59 || ($pat =~ m%s/([^/]*)/([^/]*)/;t% )
60 ) {
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)
64 my $srch = $1;
65 my $repl = $2;
66 $repl =~ s/\\(.)/$1/g;
67 push @comp_subs, make_closure($srch, $repl);
69 } elsif ( ($pat =~ /%([^%]*)%d/ )
70 || ($pat =~ m%/([^/]*)/d% )
71 ) {
72 push @comp_subs, make_closure($1, "");
73 } else {
74 die "Uhh. Malformed pattern in $ac_subs ($pat)"
75 unless ( $pat =~ /^\s*$/ ); # ignore white lines
78 } else {
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)
86 my $srch = $1;
87 my $repl = $2;
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% )
93 ) {
94 push @comp_match, eval "qr/\Q$1\E/";
95 push @comp_subs, "";
96 } else {
97 die "Uhh. Malformed pattern in $ac_cs_root.subs ($pat)"
98 unless ( $pat =~ /^\s*$/ ); # ignore white lines
102 undef @subs;
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: $!";
108 my @ac_files = <CF>;
109 close(CF);
110 chomp @ac_files;
113 my $ac_file;
114 foreach $ac_file (@ac_files) {
115 next if $ac_file =~ /\.\./;
116 next if $ac_file =~ /^\s*$/;
117 my $ac_file_in;
118 my ($ac_dir, $ac_dots, $ac_dir_suffix);
120 if ($ac_file =~ /.*:.*/ ) {
121 ($ac_file_in = $ac_file) =~ s%[^:]*:%%;
122 $ac_file =~ s%:.*%%;
123 } else {
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;
138 } else {
139 $ac_dir_suffix="";
140 $ac_dots="";
143 if ($ac_given_srcdir eq ".") {
144 $srcdir=".";
145 if ($ac_dots) {
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;
151 } else {
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;
159 } else {
160 $INSTALL = $ac_dots.$ac_given_INSTALL;
164 print "fast creating $ac_file\n";
165 unlink $ac_file;
166 my $ac_comsub="";
167 my $fname=$ac_file_in;
168 $fname =~ s%.*/%%;
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
174 my $ac_file_inputs;
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);
181 sub patch_file {
182 my ($outf, $infiles, $identline) = @_;
183 my $filedata;
184 my @infiles=split(' ', $infiles);
185 my $i=0;
187 foreach my $name (@infiles) {
188 if (open(CF, "< $name")) {
189 while (<CF>) {
190 $filedata .= $_;
192 close(CF);
193 } else {
194 print STDERR "can't open $name: $!"."\n";
197 if ($identline) {
198 # Put the ident in the second line. For shitty automake 1.6x.
199 $filedata =~ s%\n%\n$identline%;
202 $filedata =~ s%\@configure_input\@%$configure_input%g;
203 $filedata =~ s%\@srcdir\@%$srcdir%g;
204 $filedata =~ s%\@top_srcdir\@%$top_srcdir%g;
205 $filedata =~ s%\@INSTALL\@%$INSTALL%g;
207 if ($bad_perl) {
208 while ($i <= $#comp_subs) {
209 my $ref = $comp_subs[$i];
210 &$ref(\$filedata);
211 $i++;
213 } else {
214 while ($i <= $#comp_match) {
215 $filedata =~ s/$comp_match[$i]/$comp_subs[$i]/g;
216 $i++;
219 open(CF, "> $outf") || die "can't create $outf: $!";
220 print CF $filedata;
221 close(CF);
224 sub make_closure {
225 my ($pat, $sub) = @_;
226 $pat =~ s/\@/\\@/g; # @bla@ -> \@bla\@
227 $pat =~ s/\$/\\\$/g; # $bla -> \$bla
228 $sub =~ s/\@/\\@/g;
229 $sub =~ s/\$/\\\$/g;
230 my $ret = eval "return sub { my \$ref=shift; \$\$ref =~ s%$pat%$sub%g; }";
231 if ($@) {
232 print "can't create CODE: $@\n";
234 return $ret;