

function action ()
{
  file=$1

  suffix=`echo ${file} | sed -e 's#.*[.]##'`

  eval cpp -M ${incl} ${file}

  eval cpp -M ${incl} ${file} | \
    sed -e 's#[.]o:#_'"${suffix}"'_dependencies = #' | \
    egrep -v '(/usr/include|/usr/lib)' | eval sed ${e}
}

use_includes=`cmt -quiet show macro use_includes | grep use_includes= | sed -e 's#use_includes=.##' -e 's#.$##'`
includes=`cmt -quiet show macro includes | grep includes= | sed -e 's#$[(]use_includes[)]#'"${use_includes}"'#' -e 's#includes=.##' -e 's#.$##' -e 's#$(ppcmd)##g' -e 's#["]##g'`

tmp1=/tmp/A$$
tmp2=/tmp/B$$
tmp3=/tmp/C$$

echo ${includes} >|${tmp1}
cmt filter ${tmp1} ${tmp2}

a=`cat ${tmp1} | sed -e 's#[ ][ ]*# #g' -e 's#^[ ]##'`
b=`cat ${tmp2} | sed -e 's#[ ][ ]*# #g' -e 's#^[ ]##'`

e=; i=1; for x in `echo ${a}`; do y=`echo $b | cut -d' ' -f${i}`; i=`expr ${i} + 1`; e="${e} -e 's#${y}#${x}#'"; done

incl=; for f in `echo $includes | sed -e 's#[(]#{#g' -e 's#[)]#}#'`; do incl="${incl} -I${f}"; done
echo e=$e

files=$*

for f in `echo ${files}`; do
  action ${f}
done


