Perl -Sx "{0}" {"Parameters"}; Exit {Status}
#!perl
#
# EzDepend - Primitive tool to make dependency lists
#
# $Log: EzDepend,v $
# Revision 1.2  2002/01/10 17:35:53  aubonbeurre
# Update to GUSI 2.1.9
#
# Revision 1.1  1998/08/01 21:52:45  neeri
# Added scripts
#

ARG: while ($arg = shift @ARGV) {
	if ($arg eq "-i") {
		if ($arg = shift @ARGV) {
			$arg = ":$arg" unless $arg =~ /:/;
			$arg =~ s/:$//;
			push @Include, $arg;
		}
	} elsif ($arg eq "-f") {
		if ($arg = shift @ARGV) {
			open(OLD, "$arg") or die "Couldn't open file \"$arg\": $!";
			unlink "$arg.bak";
			rename $arg, "$arg.bak" or die "Couldn't create backup file: $!";
			open(STDOUT, ">$arg");
			while (<OLD>) {
				print, next if 1../^### Dependence/;
				next ARG;
			}
			print "\n### Dependences start here. Do not change anything below this line\n\n";
		}
	} else {
		push @File, $arg;
	}
}

@F = @File;

while ($F = shift @File) {
	next if $Done{$F}++;
	($R = $F) =~ s/.*://;
	open(F, "$F") or warn "Couldn't open \"$F\": $!", next;
	while (<F>) {
		next unless /#include\s+\"(.*)\"/;
		for $I (@Include) {
			next unless -f "$I:$1";
			push @File, "$I:$1";
			++${$Depend{$R}}{"$1"};
			last;
		}
	}
}

for $F (sort keys %Depend) {
	printf "%-20s :", $F;
	for $P (sort keys %{$Depend{$F}}) {
		print " $P";
	}
	print "\t; setfile -m . \$\@\n"
}
