annotate kdiff3/admin/config.pl @ 60:4732f709a8cb

*** empty log message ***
author joachim99
date Sun, 07 Mar 2004 10:08:07 +0000
parents 415083d043f3
children efe33e938730
rev   line source
joachim99@2 1 #!/usr/bin/perl
joachim99@2 2 # a script for use by autoconf to make the Makefiles
joachim99@2 3 # from the Makefile.in's
joachim99@2 4 #
joachim99@2 5 # the original autoconf mechanism first splits all substitutions into groups
joachim99@2 6 # of ca. 90, and than invokes sed for _every_ Makefile.in and every group
joachim99@2 7 # (so around 2-3 times per Makefile.in). So this takes forever, as sed
joachim99@2 8 # has to recompile the regexps every time.
joachim99@2 9 #
joachim99@2 10 # this script does better. It changes all Makefile.ins in one process.
joachim99@2 11 # in kdelibs the time for building Makefile went down from 2:59 min to 13 sec!
joachim99@2 12 #
joachim99@2 13 # written by Michael Matz <matz@kde.org>
joachim99@2 14 # adapted by Dirk Mueller <mueller@kde.org>
joachim99@14 15
joachim99@14 16 # This file is free software; you can redistribute it and/or
joachim99@14 17 # modify it under the terms of the GNU Library General Public
joachim99@14 18 # License as published by the Free Software Foundation; either
joachim99@14 19 # version 2 of the License, or (at your option) any later version.
joachim99@14 20
joachim99@14 21 # This library is distributed in the hope that it will be useful,
joachim99@14 22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
joachim99@14 23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
joachim99@14 24 # Library General Public License for more details.
joachim99@14 25
joachim99@14 26 # You should have received a copy of the GNU Library General Public License
joachim99@14 27 # along with this library; see the file COPYING.LIB. If not, write to
joachim99@14 28 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
joachim99@14 29 # Boston, MA 02111-1307, USA.
joachim99@2 30
joachim99@2 31 my $ac_subs=$ARGV[0];
joachim99@2 32 my $ac_sacfiles = $ARGV[1];
joachim99@2 33 my $ac_given_srcdir=$ARGV[2];
joachim99@2 34 my $ac_given_INSTALL=$ARGV[3];
joachim99@2 35
joachim99@2 36 #print "ac_subs=$ac_subs\n";
joachim99@2 37 #print "ac_sacfiles=$ac_sacfiles\n";
joachim99@2 38 #print "ac_given_srcdir=$ac_given_srcdir\n";
joachim99@2 39 #print "ac_given_INSTALL=$ac_given_INSTALL\n";
joachim99@2 40
joachim99@2 41 my ($srcdir, $top_srcdir);
joachim99@2 42 my $INSTALL;
joachim99@2 43 my $bad_perl = ($] < 5.005);
joachim99@2 44
joachim99@2 45 open(CF, "< $ac_subs") || die "can't open $ac_subs: $!";
joachim99@2 46 my @subs = <CF>;
joachim99@2 47 close(CF);
joachim99@2 48 chomp @subs;
joachim99@2 49 @comp_match=();
joachim99@2 50 @comp_subs=();
joachim99@2 51
joachim99@2 52 if ($bad_perl) {
joachim99@2 53 print "Using perl older than version 5.005\n";
joachim99@2 54 foreach my $pat (@subs) {
joachim99@14 55 if ( ($pat =~ m/s%([^%]*)%([^%]*)%g/ )
joachim99@14 56 || ($pat =~ m/s%([^%]*)%([^%]*)%;t/ )
joachim99@14 57 || ($pat =~ m/s,([^,]*),(.*),;t/)
joachim99@14 58 || ($pat =~ m%s/([^/]*)/([^/]*)/g% )
joachim99@14 59 || ($pat =~ m%s/([^/]*)/([^/]*)/;t% )
joachim99@2 60 ) {
joachim99@2 61 # form : s%bla%blubb%g
joachim99@2 62 # or s%bla%blubb%;t t (autoconf > 2.13 and < 2.52 ?)
joachim99@2 63 # or s,bla,blubb,;t t (autoconf 2.52)
joachim99@2 64 my $srch = $1;
joachim99@2 65 my $repl = $2;
joachim99@2 66 $repl =~ s/\\(.)/$1/g;
joachim99@2 67 push @comp_subs, make_closure($srch, $repl);
joachim99@2 68
joachim99@2 69 } elsif ( ($pat =~ /%([^%]*)%d/ )
joachim99@2 70 || ($pat =~ m%/([^/]*)/d% )
joachim99@2 71 ) {
joachim99@2 72 push @comp_subs, make_closure($1, "");
joachim99@2 73 } else {
joachim99@2 74 die "Uhh. Malformed pattern in $ac_subs ($pat)"
joachim99@2 75 unless ( $pat =~ /^\s*$/ ); # ignore white lines
joachim99@2 76 }
joachim99@2 77 }
joachim99@2 78 } else {
joachim99@2 79 foreach my $pat (@subs) {
joachim99@2 80 if ( ($pat =~ /s%([^%]*)%([^%]*)%g/ ) ||
joachim99@2 81 ($pat =~ /s%([^%]*)%([^%]*)%;t/ ) ||
joachim99@2 82 ($pat =~ /s,([^,]*),(.*),;t/) ) {
joachim99@2 83 # form : s%bla%blubb%g
joachim99@2 84 # or s%bla%blubb%;t t (autoconf > 2.13 and < 2.52 ?)
joachim99@2 85 # or s,bla,blubb,;t t (autoconf 2.52)
joachim99@2 86 my $srch = $1;
joachim99@2 87 my $repl = $2;
joachim99@2 88 push @comp_match, eval "qr/\Q$srch\E/"; # compile match pattern
joachim99@2 89 $repl =~ s/\\(.)/$1/g;
joachim99@2 90 push @comp_subs, $repl;
joachim99@2 91 } elsif ( ($pat =~ /%([^%]*)%d/ )
joachim99@2 92 || ($pat =~ m%/([^/]*)/d% )
joachim99@2 93 ) {
joachim99@2 94 push @comp_match, eval "qr/\Q$1\E/";
joachim99@2 95 push @comp_subs, "";
joachim99@2 96 } else {
joachim99@2 97 die "Uhh. Malformed pattern in $ac_cs_root.subs ($pat)"
joachim99@2 98 unless ( $pat =~ /^\s*$/ ); # ignore white lines
joachim99@2 99 }
joachim99@2 100 }
joachim99@2 101 }
joachim99@2 102 undef @subs;
joachim99@2 103
joachim99@2 104 # read the list of files to be patched, form:
joachim99@2 105 # ./Makefile arts/Makefile arts/examples/Makefile arts/flow/Makefile
joachim99@2 106
joachim99@2 107 open(CF, "< $ac_sacfiles") || die "can't open $ac_sacfiles: $!";
joachim99@2 108 my @ac_files = <CF>;
joachim99@2 109 close(CF);
joachim99@2 110 chomp @ac_files;
joachim99@2 111
joachim99@2 112
joachim99@2 113 my $ac_file;
joachim99@2 114 foreach $ac_file (@ac_files) {
joachim99@2 115 next if $ac_file =~ /\.\./;
joachim99@2 116 next if $ac_file =~ /^\s*$/;
joachim99@2 117 my $ac_file_in;
joachim99@2 118 my ($ac_dir, $ac_dots, $ac_dir_suffix);
joachim99@2 119
joachim99@2 120 if ($ac_file =~ /.*:.*/ ) {
joachim99@2 121 ($ac_file_in = $ac_file) =~ s%[^:]*:%%;
joachim99@2 122 $ac_file =~ s%:.*%%;
joachim99@2 123 } else {
joachim99@2 124 $ac_file_in = $ac_file.".in";
joachim99@2 125 }
joachim99@2 126
joachim99@2 127 # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories.
joachim99@2 128
joachim99@2 129 # Remove last slash and all that follows it. Not all systems have dirname.
joachim99@2 130 ($ac_dir = $ac_file) =~ s%/[^/][^/]*$%%;
joachim99@2 131 if ( ($ac_dir ne $ac_file) && ($ac_dir ne ".")) {
joachim99@2 132 # The file is in a subdirectory.
joachim99@2 133 if (! -d "$ac_dir") { mkdir "$ac_dir", 0777; }
joachim99@2 134 ($ac_dir_suffix = $ac_dir) =~ s%^./%%;
joachim99@2 135 $ac_dir_suffix="/".$ac_dir_suffix;
joachim99@2 136 # A "../" for each directory in $ac_dir_suffix.
joachim99@2 137 ($ac_dots = $ac_dir_suffix) =~ s%/[^/]*%../%g;
joachim99@2 138 } else {
joachim99@2 139 $ac_dir_suffix="";
joachim99@2 140 $ac_dots="";
joachim99@2 141 }
joachim99@2 142
joachim99@2 143 if ($ac_given_srcdir eq ".") {
joachim99@2 144 $srcdir=".";
joachim99@2 145 if ($ac_dots) {
joachim99@2 146 ( $top_srcdir = $ac_dots) =~ s%/$%%;
joachim99@2 147 } else { $top_srcdir="."; }
joachim99@2 148 } elsif ($ac_given_srcdir =~ m%^/%) {
joachim99@2 149 $srcdir=$ac_given_srcdir.$ac_dir_suffix;
joachim99@2 150 $top_srcdir = $ac_given_srcdir;
joachim99@2 151 } else {
joachim99@2 152 $srcdir = $ac_dots.$ac_given_srcdir.$ac_dir_suffix;
joachim99@2 153 $top_srcdir = $ac_dots.$ac_given_srcdir;
joachim99@2 154 }
joachim99@2 155
joachim99@2 156 if ($ac_given_INSTALL) {
joachim99@2 157 if ($ac_given_INSTALL =~ m%^/% ) {
joachim99@2 158 $INSTALL = $ac_given_INSTALL;
joachim99@2 159 } else {
joachim99@2 160 $INSTALL = $ac_dots.$ac_given_INSTALL;
joachim99@2 161 }
joachim99@2 162 }
joachim99@2 163
joachim99@2 164 print "fast creating $ac_file\n";
joachim99@2 165 unlink $ac_file;
joachim99@2 166 my $ac_comsub="";
joachim99@2 167 my $fname=$ac_file_in;
joachim99@2 168 $fname =~ s%.*/%%;
joachim99@2 169 my $configure_input="Generated automatically from $fname by config.pl.";
joachim99@2 170 if ($ac_file =~ /.*[Mm]akefile.*/) {
joachim99@2 171 $ac_comsub="# ".$configure_input."\n"; # for the first line in $ac_file
joachim99@2 172 }
joachim99@2 173
joachim99@2 174 my $ac_file_inputs;
joachim99@2 175 ($ac_file_inputs = $ac_file_in) =~ s%^%$ac_given_srcdir/%;
joachim99@2 176 $ac_file_inputs =~ s%:% $ac_given_srcdir/%g;
joachim99@2 177
joachim99@2 178 patch_file($ac_file, $ac_file_inputs, $ac_comsub);
joachim99@2 179 }
joachim99@2 180
joachim99@2 181 sub patch_file {
joachim99@14 182 my ($outf, $infiles, $identline) = @_;
joachim99@2 183 my $filedata;
joachim99@2 184 my @infiles=split(' ', $infiles);
joachim99@2 185 my $i=0;
joachim99@2 186
joachim99@2 187 foreach my $name (@infiles) {
joachim99@2 188 if (open(CF, "< $name")) {
joachim99@2 189 while (<CF>) {
joachim99@2 190 $filedata .= $_;
joachim99@2 191 }
joachim99@2 192 close(CF);
joachim99@2 193 } else {
joachim99@2 194 print STDERR "can't open $name: $!"."\n";
joachim99@2 195 }
joachim99@2 196 }
joachim99@14 197 if ($identline) {
joachim99@14 198 # Put the ident in the second line. For shitty automake 1.6x.
joachim99@14 199 $filedata =~ s%\n%\n$identline%;
joachim99@14 200 }
joachim99@2 201
joachim99@2 202 $filedata =~ s%\@configure_input\@%$configure_input%g;
joachim99@2 203 $filedata =~ s%\@srcdir\@%$srcdir%g;
joachim99@2 204 $filedata =~ s%\@top_srcdir\@%$top_srcdir%g;
joachim99@2 205 $filedata =~ s%\@INSTALL\@%$INSTALL%g;
joachim99@2 206
joachim99@2 207 if ($bad_perl) {
joachim99@2 208 while ($i <= $#comp_subs) {
joachim99@2 209 my $ref = $comp_subs[$i];
joachim99@2 210 &$ref(\$filedata);
joachim99@2 211 $i++;
joachim99@2 212 }
joachim99@2 213 } else {
joachim99@2 214 while ($i <= $#comp_match) {
joachim99@2 215 $filedata =~ s/$comp_match[$i]/$comp_subs[$i]/g;
joachim99@2 216 $i++;
joachim99@2 217 }
joachim99@2 218 }
joachim99@2 219 open(CF, "> $outf") || die "can't create $outf: $!";
joachim99@2 220 print CF $filedata;
joachim99@2 221 close(CF);
joachim99@2 222 }
joachim99@2 223
joachim99@2 224 sub make_closure {
joachim99@2 225 my ($pat, $sub) = @_;
joachim99@2 226 $pat =~ s/\@/\\@/g; # @bla@ -> \@bla\@
joachim99@2 227 $pat =~ s/\$/\\\$/g; # $bla -> \$bla
joachim99@2 228 $sub =~ s/\@/\\@/g;
joachim99@2 229 $sub =~ s/\$/\\\$/g;
joachim99@2 230 my $ret = eval "return sub { my \$ref=shift; \$\$ref =~ s%$pat%$sub%g; }";
joachim99@2 231 if ($@) {
joachim99@2 232 print "can't create CODE: $@\n";
joachim99@2 233 }
joachim99@2 234 return $ret;
joachim99@2 235 }