head	1.2;
access;
symbols
	RELENG_4_11_0_RELEASE:1.1.1.1
	RELENG_4_11:1.1.1.1.0.20
	RELENG_4_11_BP:1.1.1.1
	RELENG_4_10_0_RELEASE:1.1.1.1
	RELENG_4_10:1.1.1.1.0.18
	RELENG_4_10_BP:1.1.1.1
	RELENG_4_9_0_RELEASE:1.1.1.1
	RELENG_4_9:1.1.1.1.0.16
	RELENG_4_9_BP:1.1.1.1
	RELENG_4_8_0_RELEASE:1.1.1.1
	RELENG_4_8:1.1.1.1.0.14
	RELENG_4_8_BP:1.1.1.1
	RELENG_4_7_0_RELEASE:1.1.1.1
	RELENG_4_7:1.1.1.1.0.12
	RELENG_4_7_BP:1.1.1.1
	RELENG_4_6_2_RELEASE:1.1.1.1
	RELENG_4_6_1_RELEASE:1.1.1.1
	RELENG_4_6_0_RELEASE:1.1.1.1
	RELENG_4_6:1.1.1.1.0.10
	RELENG_4_6_BP:1.1.1.1
	v5_006_01:1.1.1.1
	RELENG_4_5_0_RELEASE:1.1.1.1
	RELENG_4_5:1.1.1.1.0.8
	RELENG_4_5_BP:1.1.1.1
	RELENG_4_4_0_RELEASE:1.1.1.1
	RELENG_4_4:1.1.1.1.0.6
	RELENG_4_4_BP:1.1.1.1
	RELENG_4_3_0_RELEASE:1.1.1.1
	RELENG_4_3:1.1.1.1.0.4
	RELENG_4_3_BP:1.1.1.1
	RELENG_4_2_0_RELEASE:1.1.1.1
	RELENG_4_1_1_RELEASE:1.1.1.1
	PRE_SMPNG:1.1.1.1
	RELENG_4_1_0_RELEASE:1.1.1.1
	v5_006:1.1.1.1
	RELENG_4_0_0_RELEASE:1.1.1.1
	RELENG_4:1.1.1.1.0.2
	RELENG_4_BP:1.1.1.1
	v5_005_03:1.1.1.1
	LWALL:1.1.1;
locks; strict;
comment	@# @;


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

1.1
date	99.05.02.14.19.06;	author markm;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	99.05.02.14.19.06;	author markm;	state Exp;
branches;
next	;


desc
@@


1.2
log
@Perl is no longer in base. Long live the port!
@
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
@Maintenance releace 3 of perl5.005. Includes support for threads.
@
text
@@
