#!/usr/local/bin/perl

# First extract the include lines from each file.

if (@ARGV == 0) 
{
        die "usage: depender FILES\n";
}

opendir(DIR,'.') || die "Can't open directory.";
@all_files = readdir(DIR);
closedir(DIR);

foreach $file (@ARGV) 
{
    open(FILE, $file) || warn "Can't open $file: $!\n";
    while (<FILE>) 
    {
	if (/^#include\s+["<]([^">]*)[">]/) 
 	{
	    $included = $1;
	    $includes{$file} .= $included . ' ';
#	    foreach $file_recur (@all_files) 
#	    {
#		if ($file == $file_recur) print $file_recur,"\n";
#	    }
	}
    }
#   print $file, " ", $includes{$file}, "\n";
}

# Now print them out in sorted order.

foreach $target (sort keys(%includes)) {
	@temp = split(/\./,$target);
	print "$temp[0]\.o: \t\t @includes{$target}\n";
#   $dependencies = $includes{$target};
#   foreach $dependency (split(/ /, $dependencies)) {
#	print "$target: $dependency\n";
#   }
}