136038Sbostic#!/bin/sh -
236038Sbostic#
3*62117Sbostic# Copyright (c) 1991, 1993
4*62117Sbostic#	The Regents of the University of California.  All rights reserved.
536038Sbostic#
647966Sbostic# %sccs.include.redist.sh%
736038Sbostic#
8*62117Sbostic#	@(#)mkdep.old.compiler	8.1 (Berkeley) 06/06/93
936038Sbostic#
1036038Sbostic
1136038Sbostic# This is a version of mkdep that works pretty well
1236038Sbostic# with compilers that don't have -M.
1345035SkarelsMAKE=Makefile			# default makefile name is "Makefile"
1436038Sbostic
1536038SbosticPATH=/bin:/usr/bin:/usr/ucb:/lib:/usr/lib
1636038Sbostic
1736038SbosticINCL=
1836097Sbostic
1936038Sbosticwhile :
2036038Sbostic	do case "$1" in
2136038Sbostic		# -f allows you to select a makefile name
2236038Sbostic		-f)
2345035Skarels			MAKE=$2
2436038Sbostic			shift; shift ;;
2536097Sbostic
2636038Sbostic		# the -p flag produces "program: program.c" style dependencies
2736038Sbostic		# so .o's don't get produced
2836038Sbostic		-p)
2936038Sbostic			SED='s;\.o;;'
3036038Sbostic			shift ;;
3136038Sbostic		*)
3236038Sbostic			break ;;
3336038Sbostic	esac
3436038Sbosticdone
3536038Sbostic
3636038Sbosticif [ $# = 0 ] ; then
3745035Skarels	echo 'usage: mkdep [-p] [-f makefile] [flags] file ...'
3836038Sbostic	exit 1
3936038Sbosticfi
4036038Sbostic
4145035Skarelsif [ ! -w $MAKE ]; then
4245035Skarels	echo "mkdep: no writeable file \"$MAKE\""
4345035Skarels	exit 1
4445035Skarelsfi
4545035Skarels
4636038SbosticTMP=/tmp/mkdep$$
4745035Skarels
4836038Sbostictrap 'rm -f $TMP ; exit 1' 1 2 3 13 15
4936038Sbostic
5045035Skarelscp $MAKE ${MAKE}.bak
5145035Skarelssed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
5245035Skarels
5345035Skarelscat << _EOF_ >> $TMP
5445035Skarels# DO NOT DELETE THIS LINE -- mkdep uses it.
5545035Skarels# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
5645035Skarels
5745035Skarels_EOF_
5845035Skarels
5945035Skarels
6036038Sbosticfor i do
6136038Sbostic	case "$i" in
6245035Skarels	-c|-M|-O)
6336038Sbostic		;;
6436038Sbostic	-I*)
6536038Sbostic		INCL="$INCL $i";;
6645035Skarels	-D*|-U*)
6736038Sbostic		FLAGS="$FLAGS $i";;
6836038Sbostic	*)
6936038Sbostic		# assume source file
7036038Sbostic		# put '$dep' in front of dependencies
7136038Sbostic		dep=`echo "$i" | sed -e 's,/,\\\\/,g' -e 's/\.c$/.o/'`
7236038Sbostic
7336038Sbostic		# Find includes, remove leading numerics, remove ./,
7436038Sbostic		# remove double quotes, and remove trailing numerics.
7536038Sbostic		# Sort that, discarding duplicates, and add '$dep'.
7636038Sbostic		cpp $INCL $FLAGS "$i" | sed -e '
7736038Sbostic			/^#/!d
7836038Sbostic			s/# [0-9]* //
7936038Sbostic			s,"./,",
8036038Sbostic			s/"\(.*\)"/\1/
8136038Sbostic			s/ [ 0-9]*$//' |
8236038Sbostic		sort -u | sed -e "s/^/$dep: /";;
8336038Sbostic	esac
8436038Sbosticdone |
8536038Sbosticsed "
8636038Sbostic	s; \./; ;g
8736038Sbostic	/\.c:$/d
8836038Sbostic	$SED" |
8936038Sbosticawk '{
9036038Sbostic	if ($1 != prev) {
9136038Sbostic		if (rec != "")
9236038Sbostic			print rec;
9336038Sbostic		rec = $0;
9436038Sbostic		prev = $1;
9536038Sbostic	}
9636038Sbostic	else {
9736038Sbostic		if (length(rec $2) > 78) {
9836038Sbostic			print rec;
9936038Sbostic			rec = $0;
10036038Sbostic		}
10136038Sbostic		else
10236038Sbostic			rec = rec " " $2
10336038Sbostic	}
10436038Sbostic}
10536038SbosticEND {
10636038Sbostic	print rec
10745035Skarels}' >> $TMP
10836038Sbostic
10945035Skarelscat << _EOF_ >> $TMP
11045035Skarels
11145035Skarels# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
11245035Skarels_EOF_
11345035Skarels
11445035Skarels# copy to preserve permissions
11545035Skarelscp $TMP $MAKE
11645035Skarelsrm -f $TMP
11736038Sbosticexit 0
118