xref: /original-bsd/usr.bin/mkdep/mkdep.ultrix (revision c3e32dec)
1#!/bin/sh -
2#
3# Copyright (c) 1991, 1993
4#	The Regents of the University of California.  All rights reserved.
5#
6# %sccs.include.redist.sh%
7#
8#	@(#)mkdep.ultrix	8.1 (Berkeley) 06/06/93
9#
10
11PATH=/bin:/usr/bin:/usr/ucb
12export PATH
13
14MAKE=Makefile			# default makefile name is "Makefile"
15
16while :
17	do case "$1" in
18		# -f allows you to select a makefile name
19		-f)
20			MAKE=$2
21			shift; shift ;;
22
23		# the -p flag produces "program: program.c" style dependencies
24		# so .o's don't get produced
25		-p)
26			SED='s;\.o;;'
27			shift ;;
28		*)
29			break ;;
30	esac
31done
32
33if [ $# = 0 ] ; then
34	echo 'usage: mkdep [-p] [-f makefile] [flags] file ...'
35	exit 1
36fi
37
38if [ ! -w $MAKE ]; then
39	echo "mkdep: no writeable file \"$MAKE\""
40	exit 1
41fi
42
43TMP=/tmp/mkdep$$
44
45trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
46
47cp $MAKE ${MAKE}.bak
48
49sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
50
51cat << _EOF_ >> $TMP
52# DO NOT DELETE THIS LINE -- mkdep uses it.
53# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
54
55_EOF_
56
57# If your compiler doesn't have -M, add it.  If you can't, the next two
58# lines will try and replace the "cc -M".  The real problem is that this
59# hack can't deal with anything that requires a search path, and doesn't
60# even try for anything using bracket (<>) syntax.
61#
62# egrep '^#include[ 	]*".*"' /dev/null $* |
63# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
64
65# Ultrix has already used -M for something else.
66cc -Em $* |
67sed "
68	s; \./; ;g
69	$SED" |
70awk '{
71	if ($1 != prev) {
72		if (rec != "")
73			print rec;
74		rec = $0;
75		prev = $1;
76	}
77	else {
78		if (length(rec $2) > 78) {
79			print rec;
80			rec = $0;
81		}
82		else
83			rec = rec " " $2
84	}
85}
86END {
87	print rec
88}' >> $TMP
89
90cat << _EOF_ >> $TMP
91
92# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
93_EOF_
94
95# copy to preserve permissions
96cp $TMP $MAKE
97rm -f ${MAKE}.bak $TMP
98exit 0
99