/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/js/build/autoconf/make-makefile

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs · Perl · 315 lines · 197 code · 35 blank · 83 comment · 30 complexity · 735491a89e26a15cbed1f3196a9e634e MD5 · raw file

  1. #! /usr/bin/env perl
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. #
  5. # The contents of this file are subject to the Mozilla Public License Version
  6. # 1.1 (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. # http://www.mozilla.org/MPL/
  9. #
  10. # Software distributed under the License is distributed on an "AS IS" basis,
  11. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. # for the specific language governing rights and limitations under the
  13. # License.
  14. #
  15. # The Original Code is mozilla.org code.
  16. #
  17. # The Initial Developer of the Original Code is
  18. # Netscape Communications Corporation.
  19. # Portions created by the Initial Developer are Copyright (C) 1999
  20. # the Initial Developer. All Rights Reserved.
  21. #
  22. # Contributor(s):
  23. #
  24. # Alternatively, the contents of this file may be used under the terms of
  25. # either of the GNU General Public License Version 2 or later (the "GPL"),
  26. # or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. # in which case the provisions of the GPL or the LGPL are applicable instead
  28. # of those above. If you wish to allow use of your version of this file only
  29. # under the terms of either the GPL or the LGPL, and not to allow others to
  30. # use your version of this file under the terms of the MPL, indicate your
  31. # decision by deleting the provisions above and replace them with the notice
  32. # and other provisions required by the GPL or the LGPL. If you do not delete
  33. # the provisions above, a recipient may use your version of this file under
  34. # the terms of any one of the MPL, the GPL or the LGPL.
  35. #
  36. # ***** END LICENSE BLOCK *****
  37. # make-makefiles - Quickly create Makefiles for subdirectories.
  38. # Also, creates any needed subdirectories.
  39. #
  40. # usage: make-makefiles [ -t <topsrcdir> -p <print_topsrcdir> -d <depth> ] [ <subdir> | <subdir>/Makefile ] ...
  41. # Send comments, improvements, bugs to Steve Lamm (slamm@netscape.com).
  42. #$debug = 1;
  43. # Determine various tree path variables
  44. #
  45. ($topsrcdir, $ptopsrcdir, $depth, @makefiles) = parse_arguments(@ARGV);
  46. $object_fullpath = `pwd`;
  47. chdir $depth;
  48. $object_root = `pwd`;
  49. chomp $object_fullpath;
  50. chomp $object_root;
  51. # $source_subdir is the path from the object root to where
  52. # 'make-makefile' was called. For example, if make-makefile was
  53. # called from "mozilla/gfx/src", then $source_subdir would be
  54. # "gfx/src/".
  55. $source_subdir = "$object_fullpath/";
  56. my $quoted_object_root = quotemeta($object_root);
  57. $source_subdir =~ s|^$quoted_object_root/||;
  58. # Prefix makefiles with $source_subdir so that paths
  59. # will be relative to the top of the object tree.
  60. #
  61. for $makefile (@makefiles) {
  62. $makefile = "$source_subdir$makefile";
  63. }
  64. create_directories(@makefiles);
  65. # Find the path to the source directory based on how 'make-makefile'
  66. # was invoked. The path is either relative to the object directory
  67. # or an absolute path.
  68. $given_srcdir = find_srcdir($topsrcdir, $depth);
  69. $pgiven_srcdir = find_srcdir($ptopsrcdir, $depth);
  70. if ($debug) {
  71. warn "object_fullpath = $object_fullpath\n";
  72. warn "object_root = $object_root\n";
  73. warn "source_subdir = $source_subdir\n";
  74. warn "makefiles = @makefiles\n";
  75. warn "given_srcdir = $given_srcdir\n";
  76. }
  77. @unhandled = update_makefiles($given_srcdir, $pgiven_srcdir, @makefiles);
  78. run_config_status(@unhandled);
  79. # end of Main
  80. ############################################################
  81. sub dirname {
  82. return $_[0] =~ /(.*)\/.*/ ? "$1" : '.';
  83. }
  84. # find_depth: Pull the value of DEPTH out of a Makefile (or Makefile.in)
  85. sub find_depth {
  86. my $depth = '';
  87. open(MAKEFILE, "<$_[0]") || die "Unable to open $_[0]: $!\n";
  88. while (<MAKEFILE>) {
  89. next unless /^DEPTH\s*=\s*(\..*)/;
  90. $depth = $1;
  91. last;
  92. }
  93. close MAKEFILE;
  94. return $depth;
  95. }
  96. sub parse_arguments {
  97. my @args = @_;
  98. my $depth = '';
  99. my $topsrcdir = '';
  100. my $ptopsrcdir;
  101. my @makefiles = ();
  102. while (1) {
  103. if ($args[0] eq '-d') {
  104. $depth = $args[1];
  105. shift @args;
  106. shift @args;
  107. } elsif ($args[0] eq '-t') {
  108. $topsrcdir = $args[1];
  109. shift @args;
  110. shift @args;
  111. } elsif ($args[0] eq '-p') {
  112. $ptopsrcdir = $args[1];
  113. shift @args;
  114. shift @args;
  115. } else {
  116. last;
  117. }
  118. }
  119. if ($topsrcdir eq '') {
  120. $topsrcdir = $0; # Figure out topsrcdir based on program name.
  121. $topsrcdir =~ s|/?build/autoconf/.*$||;
  122. }
  123. if ($ptopsrcdir eq '') {
  124. $ptopsrcdir = $topsrcdir;
  125. }
  126. if ($depth eq '') {
  127. # Use $(DEPTH) in the Makefile or Makefile.in to determine the depth
  128. if (-e "Makefile.in") {
  129. $depth = find_depth("Makefile.in");
  130. } elsif (-e "Makefile") {
  131. $depth = find_depth("Makefile");
  132. } elsif (-e "../Makefile") {
  133. $depth = "../".find_depth("../Makefile");
  134. $depth =~ s/\/\.$//;
  135. } else {
  136. warn "Unable to determine depth (e.g. ../..) to root of objdir tree.\n";
  137. die "No Makefile(.in) present. Try running with '-d <depth>'\n";
  138. }
  139. }
  140. # Build the list of makefiles to generate
  141. #
  142. @makefiles = ();
  143. my $makefile;
  144. foreach $makefile (@args) {
  145. $makefile =~ s/\.in$//;
  146. $makefile =~ s/\/$//;
  147. $makefile =~ /Makefile$/ or $makefile .= "/Makefile";
  148. push @makefiles, "$makefile";
  149. }
  150. @makefiles = "Makefile" unless @args;
  151. return ($topsrcdir, $ptopsrcdir, $depth, @makefiles);
  152. }
  153. # Create all the directories at once.
  154. # This can be much faster than calling mkdir() for each one.
  155. sub create_directories {
  156. my @makefiles = @_;
  157. my @dirs = ();
  158. my $ac_file;
  159. foreach $ac_file (@makefiles) {
  160. push @dirs, dirname($ac_file);
  161. }
  162. # Call mkdir with the directories sorted by subdir count (how many /'s)
  163. system "mkdir -p ". join(' ', map("\"$_\"", @dirs)) if @dirs;
  164. }
  165. # Find the top of the source directory
  166. # (Assuming that the executable is in $top_srcdir/build/autoconf)
  167. sub find_srcdir {
  168. my ($ac_given_srcdir, $depth) = @_;
  169. if ($debug) {
  170. print "ac_given_srcdir = $ac_given_srcdir\n";
  171. print "depth = $depth\n";
  172. }
  173. if ($ac_given_srcdir =~ /^\./ and $depth ne '.') {
  174. my $quoted_depth = quotemeta($depth);
  175. $ac_given_srcdir =~ s|^$quoted_depth/?||;
  176. }
  177. if ($debug) {
  178. print "ac_given_srcdir = $ac_given_srcdir\n";
  179. }
  180. $ac_given_srcdir = '.' if $ac_given_srcdir eq '';
  181. return $ac_given_srcdir;
  182. }
  183. # Output the makefiles.
  184. #
  185. sub update_makefiles {
  186. my ($ac_given_srcdir, $pac_given_srcdir, @makefiles) = @_;
  187. my @unhandled=();
  188. my $ac_file;
  189. foreach $ac_file (@makefiles) {
  190. my $ac_file_in = "$ac_given_srcdir/${ac_file}.in";
  191. my $ac_dir = dirname($ac_file);
  192. my $ac_dots = '';
  193. my $ac_dir_suffix = '';
  194. my $srcdir = '.';
  195. my $top_srcdir = '.';
  196. # Determine $srcdir and $top_srcdir
  197. #
  198. if ($ac_dir ne '.') {
  199. $ac_dir_suffix = "/$ac_dir";
  200. $ac_dir_suffix =~ s%^/\./%/%;
  201. $ac_dots = $ac_dir_suffix;
  202. # Remove .. components from the provided dir suffix, and
  203. # also the forward path components they were reversing.
  204. my $backtracks = $ac_dots =~ s%\.\.(/|$)%%g;
  205. while ($backtracks--) {
  206. $ac_dots =~ s%/[^/]*%%;
  207. }
  208. $ac_dots =~ s%/[^/]*%../%g;
  209. }
  210. if ($ac_given_srcdir eq '.') {
  211. if ($ac_dots ne '') {
  212. $top_srcdir = $ac_dots;
  213. $top_srcdir =~ s%/$%%;
  214. }
  215. } elsif ($pac_given_srcdir =~ m%^/% or $pac_given_srcdir =~ m%^.:/%) {
  216. $srcdir = "$pac_given_srcdir$ac_dir_suffix";
  217. $top_srcdir = "$pac_given_srcdir";
  218. } else {
  219. if ($debug) {
  220. print "ac_dots = $ac_dots\n";
  221. print "ac_dir_suffix = $ac_dir_suffix\n";
  222. }
  223. $srcdir = "$ac_dots$ac_given_srcdir$ac_dir_suffix";
  224. $top_srcdir = "$ac_dots$ac_given_srcdir";
  225. }
  226. if ($debug) {
  227. print "ac_dir = $ac_dir\n";
  228. print "ac_file = $ac_file\n";
  229. print "ac_file_in = $ac_file_in\n";
  230. print "srcdir = $srcdir\n";
  231. print "top_srcdir = $top_srcdir\n";
  232. print "cwd = " . `pwd` . "\n";
  233. }
  234. # Copy the file and make substitutions.
  235. # @srcdir@ -> value of $srcdir
  236. # @top_srcdir@ -> value of $top_srcdir
  237. #
  238. if (-e $ac_file) {
  239. next if -M _ < -M $ac_file_in; # Next if Makefile is up-to-date.
  240. warn "updating $ac_file\n";
  241. } else {
  242. warn "creating $ac_file\n";
  243. }
  244. open INFILE, "<$ac_file_in" or do {
  245. warn "$0: Cannot read $ac_file_in: No such file or directory\n";
  246. next;
  247. };
  248. open OUTFILE, ">$ac_file" or do {
  249. warn "$0: Unable to create $ac_file\n";
  250. next;
  251. };
  252. while (<INFILE>) {
  253. #if (/\@[_a-zA-Z]*\@.*\@[_a-zA-Z]*\@/) {
  254. # #warn "Two defines on a line:$ac_file:$.:$_";
  255. # push @unhandled, $ac_file;
  256. # last;
  257. #}
  258. s/\@srcdir\@/$srcdir/g;
  259. s/\@top_srcdir\@/$top_srcdir/g;
  260. if (/\@[_a-zA-Z]*\@/) {
  261. #warn "Unknown variable:$ac_file:$.:$_";
  262. push @unhandled, $ac_file;
  263. last;
  264. }
  265. print OUTFILE;
  266. }
  267. close INFILE;
  268. close OUTFILE;
  269. }
  270. return @unhandled;
  271. }
  272. sub run_config_status {
  273. my @unhandled = @_;
  274. # Run config.status with any unhandled files.
  275. #
  276. if (@unhandled) {
  277. $ENV{CONFIG_FILES}= join ' ', @unhandled;
  278. system "./config.status";
  279. }
  280. }