#!/bin/sh
###########################################################################
# LPRng - An Extended Print Spooler System
#
# Copyright 1988-1995 Patrick Powell, San Diego State University
#     papowell@sdsu.edu
# See LICENSE for conditions of use.
#
###########################################################################
# MODULE: UTILS/makeinc
# PURPOSE: find dependencies for files
#   NOTE: uses GCC to expand the files
#   Usage: cd source_directory;  makeinc *.o
#  Note: you have to modify the -I. -I./include line
#     if you change structure
# makeinc,v 3.1 1996/12/28 21:40:52 papowell Exp
########################################################################## 
for i in $* ; do
	# echo $i
	I=`echo $i | sed 's/\.o/.c/'`
	II=`ls ./*/$I 2>/dev/null`
	if [ ! -n "$II" ]; then II=`ls ./$I 2>/dev/null`; fi;
	# echo $II

	gcc -E \
	-I. -I./include -I.. \
	$II >/tmp/s
	awk '
/^# [0-9]/ {
if( $3 ~ /usr/ ) next;
l = substr( $3, 2); l = substr( l, 1, length(l)-1);
if( l ~ /\.c$/ ) next;
print l; }

{ next; }' </tmp/s >/tmp/t
	sort /tmp/t |uniq | sed -e 's,.*/,,' >/tmp/w
	echo -n $i ":"
	awk 'BEGIN { printf "\t" }
		{printf "%s ", $0}
	END { print }' < /tmp/w
done
