source: trunk/MagicSoft/AMC/activemirrorcontrol/admin/config.pl@ 6390

Last change on this file since 6390 was 3403, checked in by merck, 21 years ago
initial check-in of AMC software
File size: 5.7 KB
Line 
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@ifh.de>
14#
15# the first part was done by looking at the config.status files generated
16# by configure.
17#
18my $ac_cs_root=$ARGV[0];
19my $ac_given_srcdir=$ARGV[1];
20my $ac_given_INSTALL=$ARGV[2];
21
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";
25
26my ($srcdir, $top_srcdir);
27my $INSTALL;
28my $bad_perl = ($] < 5.005);
29
30open(CF, "< $ac_cs_root.subs") || die "can't open $ac_cs_root.subs: $!";
31my @subs = <CF>;
32close(CF);
33chomp @subs;
34@comp_match=();
35@comp_subs=();
36
37if ($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
55 }
56 }
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
76 }
77 }
78}
79undef @subs;
80
81# read the list of files to be patched, form:
82# ./Makefile arts/Makefile arts/examples/Makefile arts/flow/Makefile
83
84open(CF, "< $ac_cs_root.sacfiles") || die "can't open $ac_cs_root.sacfiles: $!";
85my @ac_files = <CF>;
86close(CF);
87chomp @ac_files;
88
89my $ac_file;
90foreach $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);
95
96 if ($ac_file =~ /.*:.*/ ) {
97 ($ac_file_in = $ac_file) =~ s%[^:]*:%%;
98 $ac_file =~ s%:.*%%;
99 } else {
100 $ac_file_in = $ac_file.".in";
101 }
102
103# Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories.
104
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="";
117 }
118
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;
130 }
131
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;
137 }
138 }
139
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
148 }
149
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;
153
154 patch_file($ac_file, $ac_file_inputs, $ac_comsub);
155}
156
157sub patch_file {
158 my ($outf, $infiles, $firstline) = @_;
159 my $filedata;
160 my @infiles=split(' ', $infiles);
161 my $i=0;
162
163 if ($firstline) {
164 $filedata = $firstline;
165 }
166 foreach my $name (@infiles) {
167 if (open(CF, "< $name")) {
168 while (<CF>) {
169 $filedata .= $_;
170 }
171 close(CF);
172 } else {
173 print STDERR "can't open $name: $!"."\n";
174 }
175 }
176
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;
181
182 if ($bad_perl) {
183 while ($i <= $#comp_subs) {
184 my $ref = $comp_subs[$i];
185 &$ref(\$filedata);
186 $i++;
187 }
188 } else {
189 while ($i <= $#comp_match) {
190 $filedata =~ s/$comp_match[$i]/$comp_subs[$i]/g;
191 $i++;
192 }
193 }
194 open(CF, "> $outf") || die "can't create $outf: $!";
195 print CF $filedata;
196 close(CF);
197}
198
199sub 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";
208 }
209 return $ret;
210}
Note: See TracBrowser for help on using the repository browser.