xref: /csrg-svn/usr.bin/mkdep/mkdep.append (revision 62117)
144233Sbostic#!/bin/sh -
244233Sbostic#
3*62117Sbostic# Copyright (c) 1991, 1993
4*62117Sbostic#	The Regents of the University of California.  All rights reserved.
544233Sbostic#
647966Sbostic# %sccs.include.redist.sh%
744233Sbostic#
8*62117Sbostic#	@(#)mkdep.append	8.1 (Berkeley) 06/06/93
944233Sbostic#
1047966Sbostic
1144233SbosticPATH=/bin:/usr/bin:/usr/ucb
1244233Sbosticexport PATH
1344233Sbostic
1444233SbosticMAKE=Makefile			# default makefile name is "Makefile"
1544233Sbostic
1644233Sbosticwhile :
1744233Sbostic	do case "$1" in
1844233Sbostic		# -f allows you to select a makefile name
1944233Sbostic		-f)
2044233Sbostic			MAKE=$2
2144233Sbostic			shift; shift ;;
2244233Sbostic
2344233Sbostic		# the -p flag produces "program: program.c" style dependencies
2444233Sbostic		# so .o's don't get produced
2544233Sbostic		-p)
2644233Sbostic			SED='s;\.o;;'
2744233Sbostic			shift ;;
2844233Sbostic		*)
2944233Sbostic			break ;;
3044233Sbostic	esac
3144233Sbosticdone
3244233Sbostic
3344233Sbosticif [ $# = 0 ] ; then
3444233Sbostic	echo 'usage: mkdep [-p] [-f makefile] [flags] file ...'
3544233Sbostic	exit 1
3644233Sbosticfi
3744233Sbostic
3844233Sbosticif [ ! -w $MAKE ]; then
3944233Sbostic	echo "mkdep: no writeable file \"$MAKE\""
4044233Sbostic	exit 1
4144233Sbosticfi
4244233Sbostic
4344233SbosticTMP=/tmp/mkdep$$
4444233Sbostic
4544233Sbostictrap 'rm -f $TMP ; exit 1' 1 2 3 13 15
4644233Sbostic
4744233Sbosticcp $MAKE ${MAKE}.bak
4844233Sbostic
4944233Sbosticsed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
5044233Sbostic
5144233Sbosticcat << _EOF_ >> $TMP
5244233Sbostic# DO NOT DELETE THIS LINE -- mkdep uses it.
5344233Sbostic# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
5444233Sbostic
5544233Sbostic_EOF_
5644233Sbostic
5744233Sbostic# If your compiler doesn't have -M, add it.  If you can't, the next two
5844233Sbostic# lines will try and replace the "cc -M".  The real problem is that this
5944233Sbostic# hack can't deal with anything that requires a search path, and doesn't
6044233Sbostic# even try for anything using bracket (<>) syntax.
6144233Sbostic#
6244233Sbostic# egrep '^#include[ 	]*".*"' /dev/null $* |
6344233Sbostic# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
6444233Sbostic
6544233Sbosticcc -M $* |
6644233Sbosticsed "
6744233Sbostic	s; \./; ;g
6844233Sbostic	$SED" |
6944233Sbosticawk '{
7044233Sbostic	if ($1 != prev) {
7144233Sbostic		if (rec != "")
7244233Sbostic			print rec;
7344233Sbostic		rec = $0;
7444233Sbostic		prev = $1;
7544233Sbostic	}
7644233Sbostic	else {
7744233Sbostic		if (length(rec $2) > 78) {
7844233Sbostic			print rec;
7944233Sbostic			rec = $0;
8044233Sbostic		}
8144233Sbostic		else
8244233Sbostic			rec = rec " " $2
8344233Sbostic	}
8444233Sbostic}
8544233SbosticEND {
8644233Sbostic	print rec
8744233Sbostic}' >> $TMP
8844233Sbostic
8944233Sbosticcat << _EOF_ >> $TMP
9044233Sbostic
9144233Sbostic# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
9244233Sbostic_EOF_
9344233Sbostic
9444233Sbostic# copy to preserve permissions
9544233Sbosticcp $TMP $MAKE
9644233Sbosticrm -f ${MAKE}.bak $TMP
9744233Sbosticexit 0
98