head	1.2;
access;
symbols
	RELENG_2_2_8_RELEASE:1.1.1.1
	RELENG_2_2_7_RELEASE:1.1.1.1
	RELENG_2_2_6_RELEASE:1.1.1.1
	RELENG_2_2_5_RELEASE:1.1.1.1
	RELENG_2_2_2_RELEASE:1.1.1.1
	RELENG_2_2_1_RELEASE:1.1.1.1
	RELENG_2_2_0_RELEASE:1.1.1.1
	RELENG_2_1_7_RELEASE:1.1.1.1
	RELENG_2_1_6_1_RELEASE:1.1.1.1
	RELENG_2_1_6_RELEASE:1.1.1.1
	RELENG_2_2:1.1.1.1.0.8
	RELENG_2_2_BP:1.1.1.1
	RELENG_2_1_5_RELEASE:1.1.1.1
	RELENG_2_1_0_RELEASE:1.1.1.1
	RELENG_2_1_0:1.1.1.1.0.6
	RELENG_2_1_0_BP:1.1.1.1
	RELENG_2_0_5_RELEASE:1.1.1.1
	RELENG_2_0_5:1.1.1.1.0.4
	RELENG_2_0_5_BP:1.1.1.1
	RELENG_2_0_5_ALPHA:1.1.1.1
	RELEASE_2_0:1.1.1.1
	BETA_2_0:1.1.1.1
	ALPHA_2_0:1.1.1.1.0.2
	perl_4_036_bmake:1.1.1.1
	lwall:1.1.1;
locks; strict;
comment	@# @;


1.2
date	98.09.09.06.49.04;	author markm;	state dead;
branches;
next	1.1;

1.1
date	94.09.10.06.27.46;	author gclarkii;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	94.09.10.06.27.47;	author gclarkii;	state Exp;
branches;
next	;


desc
@@


1.2
log
@Old Perl is leaving us. Goodbye, faithful friend.
@
text
@#!../perl

$M = '-M';
$M = '-m' if -d '/usr/uts' && -f '/etc/master';

do 'getopt.pl';
do Getopt('f');

if ($opt_f) {
    $makefile = $opt_f;
}
elsif (-f 'makefile') {
    $makefile = 'makefile';
}
elsif (-f 'Makefile') {
    $makefile = 'Makefile';
}
else {
    die "No makefile\n";
}

$MF = 'mf00';

while(($key,$val) = each(ENV)) {
    $mac{$key} = $val;
}

do scan($makefile);

$co = $action{'.c.o'};
$co = ' ' unless $co;

$missing = "Missing dependencies:\n";
foreach $key (sort keys(o)) {
    if ($oc{$key}) {
	$src = $oc{$key};
	$action = $action{$key};
    }
    else {
	$action = '';
    }
    if (!$action) {
	if ($co && ($c = $key) =~ s/\.o$/.c/ && -f $c) {
	    $src = $c;
	    $action = $co;
	}
	else {
	    print "No source found for $key $c\n";
	    next;
	}
    }
    $I = '';
    $D = '';
    $I .= $1 while $action =~ s/(-I\S+\s*)//;
    $D .= $1 . ' ' while $action =~ s/(-D\w+)//;
    if ($opt_v) {
	$cmd = "Checking $key: cc $M $D $I $src";
	$cmd =~ s/\s\s+/ /g;
	print stderr $cmd,"\n";
    }
    open(CPP,"cc $M $D $I $src|") || die "Can't run C preprocessor: $!";
    while (<CPP>) {
	($name,$dep) = split;
	$dep =~ s|^\./||;
	(print $missing,"$key: $dep\n"),($missing='')
	    unless ($dep{"$key: $dep"} += 2) > 2;
    }
}

$extra = "\nExtraneous dependencies:\n";
foreach $key (sort keys(dep)) {
    if ($key =~ /\.o: .*\.h$/ && $dep{$key} == 1) {
	print $extra,$key,"\n";
	$extra = '';
    }
}

sub scan {
    local($makefile) = @@_;
    local($MF) = $MF;
    print stderr "Analyzing $makefile.\n" if $opt_v;
    $MF++;
    open($MF,$makefile) || die "Can't open $makefile: $!";
    while (<$MF>) {
	chop;
	chop($_ = $_ . <$MF>) while s/\\$//;
	next if /^#/;
	next if /^$/;
	s/\$\((\w+):([^=)]*)=([^)]*)\)/do subst("$1","$2","$3")/eg;
	s/\$\((\w+)\)/$mac{$1}/eg;
	$mac{$1} = $2, next if /^(\w+)\s*=\s*(.*)/;
	if (/^include\s+(.*)/) {
	    do scan($1);
	    print stderr "Continuing $makefile.\n" if $opt_v;
	    next;
	}
	if (/^([^:]+):\s*(.*)/) {
	    $left = $1;
	    $right = $2;
	    if ($right =~ /^([^;]*);(.*)/) {
		$right = $1;
		$action = $2;
	    }
	    else {
		$action = '';
	    }
	    while (<$MF>) {
		last unless /^\t/;
		chop;
		chop($_ = $_ . <$MF>) while s/\\$//;
		next if /^#/;
		last if /^$/;
		s/\$\((\w+):([^=)]*)=([^)]*)\)/do subst("$1","$2","$3")/eg;
		s/\$\((\w+)\)/$mac{$1}/eg;
		$action .= $_;
	    }
	    foreach $targ (split(' ',$left)) {
		$targ =~ s|^\./||;
		foreach $src (split(' ',$right)) {
		    $src =~ s|^\./||;
		    $deplist{$targ} .= ' ' . $src;
		    $dep{"$targ: $src"} = 1;
		    $o{$src} = 1 if $src =~ /\.o$/;
		    $oc{$targ} = $src if $targ =~ /\.o$/ && $src =~ /\.[yc]$/;
		}
		$action{$targ} .= $action;
	    }
	    redo if $_;
	}
    }
    close($MF);
}

sub subst {
    local($foo,$from,$to) = @@_;
    $foo = $mac{$foo};
    $from =~ s/\./[.]/;
    y/a/a/;
    $foo =~ s/\b$from\b/$to/g;
    $foo;
}
@


1.1
log
@Initial revision
@
text
@@


1.1.1.1
log
@Initial import of Perl 4.046 bmaked

@
text
@@
