#! /bin/sh
# cc-M - replacement for cc -M
# $Id: cc-M,v 1.3 2002/02/04 19:14:14 phil Exp $

# NOTE! only handles .c files (no .l or .y)

flags=
for file in $*
do
    case $file in
	-D*|-U*|-I*)
	    flags="$flags $file"
	    ;;
	-*)
	    ;;
	*)
	    echo "# # $file"
# on some systems (AIX/RT) system defines are done by cc passing -D flags!!
#	    /lib/cpp $flags < $file | grep '^# 1 "[^"]'
	    cc -E $flags $file | grep '^#'
	    
	    ;;
    esac
done | awk '
/# # /    {
		file = $3
		lf = length(file)
		ext = substr(file,lf,1)
		left = file
		print left "\t" file
		next
	 }
$0 ~ /^# 1 / && NF >= 3  { print left "\t" substr($3,2,length($3) - 2) }
$1 == "#line" && NF >= 3 { print left "\t" substr($3,2,length($3) - 2) }' | \
(IFS="	";
while read LEFT RIGHT; do
	O=`basename $LEFT .c`.o
	echo ${O}: $RIGHT
done)
