xref: /csrg-svn/usr.bin/mkdep/mkdep.ultrix (revision 62117)
144234Sbostic#!/bin/sh -
244234Sbostic#
3*62117Sbostic# Copyright (c) 1991, 1993
4*62117Sbostic#	The Regents of the University of California.  All rights reserved.
544234Sbostic#
647966Sbostic# %sccs.include.redist.sh%
744234Sbostic#
8*62117Sbostic#	@(#)mkdep.ultrix	8.1 (Berkeley) 06/06/93
944234Sbostic#
1047966Sbostic
1144234SbosticPATH=/bin:/usr/bin:/usr/ucb
1244234Sbosticexport PATH
1344234Sbostic
1444234SbosticMAKE=Makefile			# default makefile name is "Makefile"
1544234Sbostic
1644234Sbosticwhile :
1744234Sbostic	do case "$1" in
1844234Sbostic		# -f allows you to select a makefile name
1944234Sbostic		-f)
2044234Sbostic			MAKE=$2
2144234Sbostic			shift; shift ;;
2244234Sbostic
2344234Sbostic		# the -p flag produces "program: program.c" style dependencies
2444234Sbostic		# so .o's don't get produced
2544234Sbostic		-p)
2644234Sbostic			SED='s;\.o;;'
2744234Sbostic			shift ;;
2844234Sbostic		*)
2944234Sbostic			break ;;
3044234Sbostic	esac
3144234Sbosticdone
3244234Sbostic
3344234Sbosticif [ $# = 0 ] ; then
3444234Sbostic	echo 'usage: mkdep [-p] [-f makefile] [flags] file ...'
3544234Sbostic	exit 1
3644234Sbosticfi
3744234Sbostic
3844234Sbosticif [ ! -w $MAKE ]; then
3944234Sbostic	echo "mkdep: no writeable file \"$MAKE\""
4044234Sbostic	exit 1
4144234Sbosticfi
4244234Sbostic
4344234SbosticTMP=/tmp/mkdep$$
4444234Sbostic
4544234Sbostictrap 'rm -f $TMP ; exit 1' 1 2 3 13 15
4644234Sbostic
4744234Sbosticcp $MAKE ${MAKE}.bak
4844234Sbostic
4944234Sbosticsed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
5044234Sbostic
5144234Sbosticcat << _EOF_ >> $TMP
5244234Sbostic# DO NOT DELETE THIS LINE -- mkdep uses it.
5344234Sbostic# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
5444234Sbostic
5544234Sbostic_EOF_
5644234Sbostic
5744234Sbostic# If your compiler doesn't have -M, add it.  If you can't, the next two
5844234Sbostic# lines will try and replace the "cc -M".  The real problem is that this
5944234Sbostic# hack can't deal with anything that requires a search path, and doesn't
6044234Sbostic# even try for anything using bracket (<>) syntax.
6144234Sbostic#
6244234Sbostic# egrep '^#include[ 	]*".*"' /dev/null $* |
6344234Sbostic# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
6444234Sbostic
6544234Sbostic# Ultrix has already used -M for something else.
6644234Sbosticcc -Em $* |
6744234Sbosticsed "
6844234Sbostic	s; \./; ;g
6944234Sbostic	$SED" |
7044234Sbosticawk '{
7144234Sbostic	if ($1 != prev) {
7244234Sbostic		if (rec != "")
7344234Sbostic			print rec;
7444234Sbostic		rec = $0;
7544234Sbostic		prev = $1;
7644234Sbostic	}
7744234Sbostic	else {
7844234Sbostic		if (length(rec $2) > 78) {
7944234Sbostic			print rec;
8044234Sbostic			rec = $0;
8144234Sbostic		}
8244234Sbostic		else
8344234Sbostic			rec = rec " " $2
8444234Sbostic	}
8544234Sbostic}
8644234SbosticEND {
8744234Sbostic	print rec
8844234Sbostic}' >> $TMP
8944234Sbostic
9044234Sbosticcat << _EOF_ >> $TMP
9144234Sbostic
9244234Sbostic# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
9344234Sbostic_EOF_
9444234Sbostic
9544234Sbostic# copy to preserve permissions
9644234Sbosticcp $TMP $MAKE
9744234Sbosticrm -f ${MAKE}.bak $TMP
9844234Sbosticexit 0
99