xref: /original-bsd/usr.bin/mkdep/mkdep.gcc.sh (revision ec35a16d)
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.gcc.sh	8.1 (Berkeley) 06/06/93
9#
10
11PATH=/bin:/usr/bin:/usr/ucb
12export PATH
13
14D=.depend			# default dependency file is .depend
15append=0
16pflag=
17
18while :
19	do case "$1" in
20		# -a appends to the depend file
21		-a)
22			append=1
23			shift ;;
24
25		# -f allows you to select a makefile name
26		-f)
27			D=$2
28			shift; shift ;;
29
30		# the -p flag produces "program: program.c" style dependencies
31		# so .o's don't get produced
32		-p)
33			pflag=p
34			shift ;;
35		*)
36			break ;;
37	esac
38done
39
40if [ $# = 0 ] ; then
41	echo 'usage: mkdep [-p] [-f depend_file] [cc_flags] file ...'
42	exit 1
43fi
44
45TMP=/tmp/mkdep$$
46
47trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
48
49if [ x$pflag = x ]; then
50	cpp -M $* | sed -e 's; \./; ;g' > $TMP
51else
52	cpp -M $* | sed -e 's;\.o :; :;' -e 's; \./; ;g' > $TMP
53fi
54
55if [ $? != 0 ]; then
56	echo 'mkdep: compile failed.'
57	rm -f $TMP
58	exit 1
59fi
60
61if [ $append = 1 ]; then
62	cat $TMP >> $D
63	rm -f $TMP
64else
65	mv $TMP $D
66fi
67exit 0
68