132-13
[darwin-xtools.git] / dyld / unit-tests / bin / make-recursive.pl
bloba44135022ed41a585c88ef7b62ccf33b2ffa6daa
1 #!/usr/bin/perl
3 use strict;
4 use Data::Dumper;
5 use File::Find;
6 use Cwd qw(realpath);
8 my @args = @ARGV;
10 my $makefiles =
12 'makefile' => undef,
13 'Makefile' => undef,
16 my $find_opts =
18 'wanted' => \&find_callback,
21 my $keywords =
23 'root' => '',
24 'cwd' => '',
25 'cmd' => '',
26 'exit' => '',
27 'stdout' => [],
28 'stderr' => [],
31 my $keyword;
32 my $max_keyword_len = 0;
33 foreach $keyword (keys %$keywords)
34 { if($max_keyword_len < length($keyword)) { $max_keyword_len = length($keyword); } }
35 my $delim = ':';
36 $max_keyword_len += length($delim) + length(' ');
38 my $last_keyword = '';
40 sub print_line
42 my ($keyword, $val) = @_;
44 if(!exists($$keywords{$keyword}))
46 print STDERR "error: keyword $keyword not in \$keywords set\n";
47 exit(1);
50 my $keyword_len = 0;
52 if($keyword ne $last_keyword)
54 print("$keyword"); print($delim);
55 $keyword_len = length($keyword) + length($delim);
57 if($max_keyword_len > $keyword_len)
59 my $num_spaces = $max_keyword_len - $keyword_len;
60 print(' ' x $num_spaces);
62 print("$val");
63 if(0)
65 $last_keyword = $keyword;
69 my $root = '.';
70 $root = &realpath($root);
71 print_line("root", "$root\n");
73 find($find_opts, $root);
75 sub find_callback
77 if(exists($$makefiles{$_}))
79 my $makefile = $_;
80 my $reldir = $File::Find::dir;
81 $reldir =~ s|^$root/||;
83 &print_line("cwd", "\$root/$reldir\n");
84 my $cmd = [ "make" ];
86 my $arg; foreach $arg (@ARGV) { push @$cmd, $arg; } # better way to do this?
87 &print_line("cmd", "@$cmd\n");
89 open(SAVEOUT, ">&STDOUT") || die("$!");
90 open(SAVEERR, ">&STDERR") || die("$!");
91 open(STDOUT, ">/tmp/unit-tests-stdout") || die("$!");
92 open(STDERR, ">/tmp/unit-tests-stderr") || die("$!");
94 $ENV{UNIT_TEST_NAME} = $reldir;
95 my $exit = system(@$cmd);
97 close(STDOUT) || die("$!");
98 close(STDERR) || die("$!");
99 open(STDOUT, ">&SAVEOUT") || die("$!");
100 open(STDERR, ">&SAVEERR") || die("$!");
102 &print_line("exit", "$exit\n");
104 open(OUT, "</tmp/unit-tests-stdout") || die("$!");
105 while(<OUT>)
107 &print_line("stdout", "$_");
109 close(OUT) || die("$!");
110 unlink("/tmp/unit-tests-stdout");
112 open(ERR, "</tmp/unit-tests-stderr") || die("$!");
113 while(<ERR>)
115 &print_line("stderr", "$_");
117 close(ERR) || die("$!");
119 unlink("/tmp/unit-tests-stderr");