#!/usr/local/bin/perl
#
# spdepend - extract depencencies from a spice deck
# Parse .include lines and emit a list of the files a given file depends on
#
# Output file from a spice run is assumed to have the extension ".lis",
# unless otherwise specified with the -e option.
#
# if the file foo.sp contains the line
#  .include "bar.md"
# then the output of spdepend will be
#  foo.lis: bar.md
#
# Alternate usage:  "spdepend -e.hlis" produces this output:
#  foo.hlis: bar.md
#
# $Log: spdepend,v $
# Revision 1.1  1994/11/23 18:31:07  tell
# Initial revision
#
#

if($#ARGV == 1 && $ARGV[0] =~ m/^-e/) {
	$ext = $ARGV[0];
	$ext =~ s/^-e//;
	shift(@ARGV);
} else {
	$ext = '.lis';
}

if($#ARGV != 0) { 
	print STDERR "usage: spdepend <file>\n";
	exit 1;
}
$infile = $ARGV[0];

open(INFILE, $infile) || die "$infile: $!\n";

while($_ = <INFILE>) {
	if($_ =~ /^.include\s*(\S*)/) {
		$incfile = $1;
		$incfile =~ s/'//g;
		$incfile =~ s/"//g;
		push(@depends, $incfile);
	}	
}

$base = $infile;
$base =~ s/.sp$//;

print "$base$ext: ", join(' ', @depends), "\n";


