Support debugger drivers that use a regular expression to search for the prompt.
[kdbg.git] / admin / config.pl
blob011cd25b2e1f8165addc50050e3237f2425ee5f8
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@ifh.de>
15 # the first part was done by looking at the config.status files generated
16 # by configure.
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);
27 my $INSTALL;
28 my $bad_perl = ($] < 5.005);
30 open(CF, "< $ac_cs_root.subs") || die "can't open $ac_cs_root.subs: $!";
31 my @subs = <CF>;
32 close(CF);
33 chomp @subs;
34 @comp_match=();
35 @comp_subs=();
37 if ($bad_perl) {
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% )
44 ) {
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% )
50 ) {
51 push @comp_subs, make_closure($1, "");
52 } else {
53 die "Uhh. Malformed pattern in $ac_cs_root.subs ($pat)"
54 unless ( $pat =~ /^\s*$/ ); # ignore white lines
57 } else {
58 foreach my $pat (@subs) {
59 if ( ($pat =~ /s%([^%]*)%([^%]*)%g/ )
60 || ($pat =~ m%/([^/]*)/([^/]*)/g% )
61 || ($pat =~ /s%([^%]*)%([^%]*)%;t/ )
62 || ($pat =~ m%/([^/]*)/([^/]*)/;t% )
63 ) {
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
67 push @comp_subs, $2;
68 } elsif ( ($pat =~ /%([^%]*)%d/ )
69 || ($pat =~ m%/([^/]*)/d% )
70 ) {
71 push @comp_match, eval "qr/\Q$1\E/";
72 push @comp_subs, "";
73 } else {
74 die "Uhh. Malformed pattern in $ac_cs_root.subs ($pat)"
75 unless ( $pat =~ /^\s*$/ ); # ignore white lines
79 undef @subs;
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: $!";
85 my @ac_files = <CF>;
86 close(CF);
87 chomp @ac_files;
89 my $ac_file;
90 foreach $ac_file (@ac_files) {
91 next if $ac_file =~ /\.\./;
92 next if $ac_file =~ /^\s*$/;
93 my $ac_file_in;
94 my ($ac_dir, $ac_dots, $ac_dir_suffix);
96 if ($ac_file =~ /.*:.*/ ) {
97 ($ac_file_in = $ac_file) =~ s%[^:]*:%%;
98 $ac_file =~ s%:.*%%;
99 } else {
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;
114 } else {
115 $ac_dir_suffix="";
116 $ac_dots="";
119 if ($ac_given_srcdir eq ".") {
120 $srcdir=".";
121 if ($ac_dots) {
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;
127 } else {
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;
135 } else {
136 $INSTALL = $ac_dots.$ac_given_INSTALL;
140 print "fast creating $ac_file\n";
141 unlink $ac_file;
142 my $ac_comsub="";
143 my $fname=$ac_file_in;
144 $fname =~ s%.*/%%;
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
150 my $ac_file_inputs;
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);
157 sub patch_file {
158 my ($outf, $infiles, $firstline) = @_;
159 my $filedata;
160 my @infiles=split(' ', $infiles);
161 my $i=0;
163 if ($firstline) {
164 $filedata = $firstline;
166 foreach my $name (@infiles) {
167 if (open(CF, "< $name")) {
168 while (<CF>) {
169 $filedata .= $_;
171 close(CF);
172 } else {
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;
182 if ($bad_perl) {
183 while ($i <= $#comp_subs) {
184 my $ref = $comp_subs[$i];
185 &$ref(\$filedata);
186 $i++;
188 } else {
189 while ($i <= $#comp_match) {
190 $filedata =~ s/$comp_match[$i]/$comp_subs[$i]/g;
191 $i++;
194 open(CF, "> $outf") || die "can't create $outf: $!";
195 print CF $filedata;
196 close(CF);
199 sub make_closure {
200 my ($pat, $sub) = @_;
201 $pat =~ s/\@/\\@/g; # @bla@ -> \@bla\@
202 $pat =~ s/\$/\\\$/g; # $bla -> \$bla
203 $sub =~ s/\@/\\@/g;
204 $sub =~ s/\$/\\\$/g;
205 my $ret = eval "return sub { my \$ref=shift; \$\$ref =~ s%$pat%$sub%g; }";
206 if ($@) {
207 print "can't create CODE: $@\n";
209 return $ret;