#!/bin/sh

FNAME=${1:-Makefile.am}
MKDEP="### DO NOT REMOVE THIS LINE, IT IS USED BY MAKEDEPEND ###"
cp $FNAME $FNAME.bak
(sed -e "/$MKDEP/,\$d" < $FNAME.bak
echo $MKDEP
for k in *.ali; do
  i=`echo $k | sed -e 's/\.ali$//'`
  withlist=
  for j in `sed -n -e '/^D /p' $k | awk '{print $2}'`; do
    if [ -f $j ]; then
      withlist="$withlist $j"
    fi
  done
  if [ "x$withlist" != x ]; then
    echo "${i}.o:$withlist"
  fi
done
) > $FNAME
