4 $M = '-m' if -d '/usr/uts' && -f '/etc/master';
12 elsif (-f 'makefile') {
13 $makefile = 'makefile';
15 elsif (-f 'Makefile') {
16 $makefile = 'Makefile';
24 while(($key,$val) = each(ENV)) {
30 $co = $action{'.c.o'};
33 $missing = "Missing dependencies:\n";
34 foreach $key (sort keys(o)) {
37 $action = $action{$key};
43 if ($co && ($c = $key) =~ s/\.o$/.c/ && -f $c) {
48 print "No source found for $key $c\n";
54 $I .= $1 while $action =~ s/(-I\S+\s*)//;
55 $D .= $1 . ' ' while $action =~ s/(-D\w+)//;
57 $cmd = "Checking $key: cc $M $D $I $src";
59 print stderr $cmd,"\n";
61 open(CPP,"cc $M $D $I $src|") || die "Can't run C preprocessor: $!";
65 (print $missing,"$key: $dep\n"),($missing='')
66 unless ($dep{"$key: $dep"} += 2) > 2;
70 $extra = "\nExtraneous dependencies:\n";
71 foreach $key (sort keys(dep)) {
72 if ($key =~ /\.o: .*\.h$/ && $dep{$key} == 1) {
73 print $extra,$key,"\n";
79 local($makefile) = @_;
81 print stderr "Analyzing $makefile.\n" if $opt_v;
83 open($MF,$makefile) || die "Can't open $makefile: $!";
86 chop($_ = $_ . <$MF>) while s/\\$//;
89 s/\$\((\w+):([^=)]*)=([^)]*)\)/do subst("$1","$2","$3")/eg;
90 s/\$\((\w+)\)/$mac{$1}/eg;
91 $mac{$1} = $2, next if /^(\w+)\s*=\s*(.*)/;
92 if (/^include\s+(.*)/) {
94 print stderr "Continuing $makefile.\n" if $opt_v;
97 if (/^([^:]+):\s*(.*)/) {
100 if ($right =~ /^([^;]*);(.*)/) {
110 chop($_ = $_ . <$MF>) while s/\\$//;
113 s/\$\((\w+):([^=)]*)=([^)]*)\)/do subst("$1","$2","$3")/eg;
114 s/\$\((\w+)\)/$mac{$1}/eg;
117 foreach $targ (split(' ',$left)) {
119 foreach $src (split(' ',$right)) {
121 $deplist{$targ} .= ' ' . $src;
122 $dep{"$targ: $src"} = 1;
123 $o{$src} = 1 if $src =~ /\.o$/;
124 $oc{$targ} = $src if $targ =~ /\.o$/ && $src =~ /\.[yc]$/;
126 $action{$targ} .= $action;
135 local($foo,$from,$to) = @_;
139 $foo =~ s/\b$from\b/$to/g;