Shared admin folder
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

config.pl 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #!/usr/bin/env 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 tdelibs 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. # This file is free software; you can redistribute it and/or
  16. # modify it under the terms of the GNU Library General Public
  17. # License as published by the Free Software Foundation; either
  18. # version 2 of the License, or (at your option) any later version.
  19. # This library is distributed in the hope that it will be useful,
  20. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  22. # Library General Public License for more details.
  23. # You should have received a copy of the GNU Library General Public License
  24. # along with this library; see the file COPYING.LIB. If not, write to
  25. # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  26. # Boston, MA 02110-1301, USA.
  27. use strict;
  28. use File::Path;
  29. my $ac_subs=$ARGV[0];
  30. my $ac_sacfiles = $ARGV[1];
  31. my $ac_given_srcdir=$ARGV[2];
  32. my $ac_given_INSTALL=$ARGV[3];
  33. my @comp_match;
  34. my @comp_subs;
  35. #print "ac_subs=$ac_subs\n";
  36. #print "ac_sacfiles=$ac_sacfiles\n";
  37. #print "ac_given_srcdir=$ac_given_srcdir\n";
  38. #print "ac_given_INSTALL=$ac_given_INSTALL\n";
  39. my $configure_input;
  40. my ($srcdir, $top_srcdir);
  41. my $INSTALL;
  42. my $bad_perl = ($] < 5.005);
  43. my $created_file_count = 0;
  44. open(CF, "< $ac_subs") || die "can't open $ac_subs: $!";
  45. my @subs = <CF>;
  46. my $pat;
  47. close(CF);
  48. chomp @subs;
  49. @comp_match=();
  50. @comp_subs=();
  51. if ($bad_perl) {
  52. print "Using perl older than version 5.005\n";
  53. foreach $pat (@subs) {
  54. if ( ($pat =~ m/s%([^%]*)%([^%]*)%g/ )
  55. || ($pat =~ m/s%([^%]*)%([^%]*)%;t/ )
  56. || ($pat =~ m/s,([^,]*),(.*),;t/)
  57. || ($pat =~ m%s/([^/]*)/([^/]*)/g% )
  58. || ($pat =~ m%s/([^/]*)/([^/]*)/;t% )
  59. ) {
  60. # form : s%bla%blubb%g
  61. # or s%bla%blubb%;t t (autoconf > 2.13 and < 2.52 ?)
  62. # or s,bla,blubb,;t t (autoconf 2.52)
  63. my $srch = $1;
  64. my $repl = $2;
  65. $repl =~ s/\\(.)/$1/g;
  66. push @comp_subs, make_closure($srch, $repl);
  67. } elsif ( ($pat =~ /%([^%]*)%d/ )
  68. || ($pat =~ m%/([^/]*)/d% )
  69. ) {
  70. push @comp_subs, make_closure($1, "");
  71. } else {
  72. die "Uhh. Malformed pattern in $ac_subs ($pat)"
  73. unless ( $pat =~ /^\s*$/ ); # ignore white lines
  74. }
  75. }
  76. } else {
  77. foreach $pat (@subs) {
  78. if ( ($pat =~ /s%([^%]*)%([^%]*)%g/ ) ||
  79. ($pat =~ /s%([^%]*)%([^%]*)%;t/ ) ||
  80. ($pat =~ /s,([^,]*),(.*),;t/) ) {
  81. # form : s%bla%blubb%g
  82. # or s%bla%blubb%;t t (autoconf > 2.13 and < 2.52 ?)
  83. # or s,bla,blubb,;t t (autoconf 2.52)
  84. my $srch = $1;
  85. my $repl = $2;
  86. push @comp_match, eval "qr/\Q$srch\E/"; # compile match pattern
  87. $repl =~ s/\\(.)/$1/g;
  88. push @comp_subs, $repl;
  89. } elsif ( ($pat =~ /%([^%]*)%d/ )
  90. || ($pat =~ m%/([^/]*)/d% )
  91. ) {
  92. push @comp_match, eval "qr/\Q$1\E/";
  93. push @comp_subs, "";
  94. } else {
  95. die "Uhh. Malformed pattern in $ac_subs ($pat)"
  96. unless ( $pat =~ /^\s*$/ ); # ignore white lines
  97. }
  98. }
  99. }
  100. undef @subs;
  101. # read the list of files to be patched, form:
  102. # ./Makefile arts/Makefile arts/examples/Makefile arts/flow/Makefile
  103. open(CF, "< $ac_sacfiles") || die "can't open $ac_sacfiles: $!";
  104. my @ac_files = <CF>;
  105. close(CF);
  106. chomp @ac_files;
  107. my $ac_file;
  108. foreach $ac_file (@ac_files) {
  109. next if $ac_file =~ /\.\./;
  110. next if $ac_file =~ /^\s*$/;
  111. my $ac_file_in;
  112. my ($ac_dir, $ac_dots, $ac_dir_suffix);
  113. if ($ac_file =~ /.*:.*/ ) {
  114. ($ac_file_in = $ac_file) =~ s%[^:]*:%%;
  115. $ac_file =~ s%:.*%%;
  116. } else {
  117. $ac_file_in = $ac_file.".in";
  118. }
  119. # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories.
  120. # Remove last slash and all that follows it. Not all systems have dirname.
  121. ($ac_dir = $ac_file) =~ s%/[^/][^/]*$%%;
  122. if ( ($ac_dir ne $ac_file) && ($ac_dir ne ".")) {
  123. # The file is in a subdirectory.
  124. if (! -d "$ac_dir") { mkpath "$ac_dir", 0, 0777; }
  125. ($ac_dir_suffix = $ac_dir) =~ s%^./%%;
  126. $ac_dir_suffix="/".$ac_dir_suffix;
  127. # A "../" for each directory in $ac_dir_suffix.
  128. ($ac_dots = $ac_dir_suffix) =~ s%/[^/]*%../%g;
  129. } else {
  130. $ac_dir_suffix="";
  131. $ac_dots="";
  132. }
  133. if ($ac_given_srcdir eq ".") {
  134. $srcdir=".";
  135. if ($ac_dots) {
  136. ( $top_srcdir = $ac_dots) =~ s%/$%%;
  137. } else { $top_srcdir="."; }
  138. } elsif ($ac_given_srcdir =~ m%^/%) {
  139. $srcdir=$ac_given_srcdir.$ac_dir_suffix;
  140. $top_srcdir = $ac_given_srcdir;
  141. } else {
  142. $srcdir = $ac_dots.$ac_given_srcdir.$ac_dir_suffix;
  143. $top_srcdir = $ac_dots.$ac_given_srcdir;
  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. print "fast creating $ac_file\n";
  153. unlink $ac_file;
  154. my $ac_comsub="";
  155. my $fname=$ac_file_in;
  156. $fname =~ s%.*/%%;
  157. $configure_input="$ac_file. Generated from $fname by config.pl.";
  158. my $ac_file_inputs;
  159. ($ac_file_inputs = $ac_file_in) =~ s%^%$ac_given_srcdir/%;
  160. $ac_file_inputs =~ s%:% $ac_given_srcdir/%g;
  161. patch_file($ac_file, $ac_file_inputs);
  162. ++$created_file_count;
  163. }
  164. print "config.pl: fast created $created_file_count file(s).\n";
  165. sub patch_file {
  166. my ($outf, $infiles) = @_;
  167. my $filedata;
  168. my @infiles=split(' ', $infiles);
  169. my $i=0;
  170. my $name;
  171. foreach $name (@infiles) {
  172. if (open(CF, "< $name")) {
  173. while (<CF>) {
  174. $filedata .= $_;
  175. }
  176. close(CF);
  177. } else {
  178. print STDERR "can't open $name: $!"."\n";
  179. }
  180. }
  181. $filedata =~ s%\@configure_input\@%$configure_input%g;
  182. $filedata =~ s%\@srcdir\@%$srcdir%g;
  183. $filedata =~ s%\@top_srcdir\@%$top_srcdir%g;
  184. $filedata =~ s%\@INSTALL\@%$INSTALL%g;
  185. if ($bad_perl) {
  186. while ($i <= $#comp_subs) {
  187. my $ref = $comp_subs[$i];
  188. &$ref(\$filedata);
  189. $i++;
  190. }
  191. } else {
  192. while ($i <= $#comp_match) {
  193. $filedata =~ s/$comp_match[$i]/$comp_subs[$i]/g;
  194. $i++;
  195. }
  196. }
  197. open(CF, "> $outf") || die "can't create $outf: $!";
  198. print CF $filedata;
  199. close(CF);
  200. }
  201. sub make_closure {
  202. my ($pat, $sub) = @_;
  203. my $ret = eval "return sub { my \$ref=shift; \$\$ref =~ s%\Q$pat\E%\Q$sub\E%g; }";
  204. if ($@) {
  205. print "can't create CODE: $@\n";
  206. }
  207. return $ret;
  208. }