xref: /original-bsd/usr.bin/mkdep/mkdep.gcc.sh (revision a088de5a)
1#!/bin/sh -
2#
3# Copyright (c) 1991 The Regents of the University of California.
4# All rights reserved.
5#
6# %sccs.include.redist.sh%
7#
8#	@(#)mkdep.gcc.sh	5.3 (Berkeley) 05/06/91
9#
10
11PATH=/bin:/usr/bin:/usr/ucb
12export PATH
13
14D=.depend			# default dependency file is .depend
15append=0
16
17while :
18	do case "$1" in
19		# -a appends to the depend file
20		-a)
21			append=1
22			shift ;;
23
24		# -f allows you to select a makefile name
25		-f)
26			D=$2
27			shift; shift ;;
28
29		# the -p flag produces "program: program.c" style dependencies
30		# so .o's don't get produced
31		-p)
32			SED='s;\.o;;'
33			shift ;;
34		*)
35			break ;;
36	esac
37done
38
39if [ $# = 0 ] ; then
40	echo 'usage: mkdep [-p] [-f depend_file] [cc_flags] file ...'
41	exit 1
42fi
43
44TMP=/tmp/mkdep$$
45
46trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
47
48cpp -M $* > $TMP
49
50if [ $? != 0 ]; then
51	echo 'mkdep: compile failed.'
52	rm -f $TMP
53	exit 1
54fi
55
56if [ $append = 1 ]; then
57	cat $TMP >> $D
58	rm -f $TMP
59else
60	mv $TMP $D
61fi
62exit 0
63