: use /bin/sh
# $Id: makedepend.SH,v 4.4 1991/09/09 20:23:31 sob Exp sob $
#
# $Log: makedepend.SH,v $
# Revision 4.4  1991/09/09  20:23:31  sob
# release 4.4
#
# 
# This software is Copyright 1991 by Stan Barber. 
#
# Permission is hereby granted to copy, reproduce, redistribute or otherwise
# use this software as long as: there is no monetary profit gained
# specifically from the use or reproduction of this software, it is not
# sold, rented, traded or otherwise marketed, and this copyright notice is
# included prominently in any copy made. 
#
# The author make no claims as to the fitness or correctness of this software
# for any use whatsoever, and it is provided as is. Any use of this software
# is at the user's own risk. 
export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)

/bin/cat /dev/null >.deptmp
echo "(Note: this is going to take a while.)"
/bin/rm -f X*.c
for file in *.c; do
    filebase=`basename $file .c`
    echo "Finding dependencies for $filebase.o."
    /usr/bin/sed -n <$file >X$file \
	-e "/^${filebase}_init(/q" \
	-e '/^#/{' \
	-e 's|/\*.*$||' \
	-e p \
	-e '}'
    /lib/cpp -I/usr/local/include X$file | /usr/bin/sed  \
	-e '/^# *line/s/line//' 	-e '/^# *[0-9]/!d' \
	-e 's/^.*"\(.*\)".*$/'$filebase'.o: \1/' \
	-e 's|: \./|: |' \
	-e 's|: X|: |' | \
	/usr/bin/uniq | /usr/bin/sort | /usr/bin/uniq >> .deptmp
done

for file in *.SH; do
    echo `basename $file .SH`: $file config.sh \; /bin/sh $file >> .deptmp
done

/usr/bin/sed <Makefile >Makefile.new -e '1,/^# AUTOMATICALLY/!d'

if test -s .deptmp; then
    echo "Updating Makefile..."
    echo "# If this runs make out of memory, delete /usr/include lines." >>Makefile.new
    /usr/bin/sed -e 's/\$/$$/g' .deptmp >>Makefile.new
else
    echo "You don't seem to have a proper C preprocessor.  Using grep instead."
    /usr/bin/egrep '^#include ' *.c *.h >.deptmp
    echo "Updating Makefile..."
    <.deptmp /usr/bin/sed -n 's|c:#include "\(.*\)".*$$|o: \1|p' >> Makefile.new
    <.deptmp /usr/bin/sed -n 's|c:#include <\(.*\)>.*$$|o: /usr/include/\1|p' >> Makefile.new
    <.deptmp /usr/bin/sed -n 's|h:#include "\(.*\)".*$$|h: \1|p' >> Makefile.new
    <.deptmp /usr/bin/sed -n 's|h:#include <\(.*\)>.*$$|h: /usr/include/\1|p' >> Makefile.new
fi
/bin/mv Makefile Makefile.old
/bin/mv Makefile.new Makefile
echo "# WARNING: Put nothing here or make depend will gobble it up!" >> Makefile
rm .deptmp X*.c

