fix exit change; major whitespace cleanup
[unix-history] / usr / src / usr.bin / mkdep / mkdep.gcc.sh
CommitLineData
2a4665f5
KB
1#!/bin/sh -
2#
0293662b 3# Copyright (c) 1991 The Regents of the University of California.
2a4665f5
KB
4# All rights reserved.
5#
0293662b 6# %sccs.include.redist.sh%
2a4665f5 7#
7377c44c 8# @(#)mkdep.gcc.sh 5.4 (Berkeley) %G%
2a4665f5 9#
0293662b 10
2a4665f5
KB
11PATH=/bin:/usr/bin:/usr/ucb
12export PATH
13
14D=.depend # default dependency file is .depend
15append=0
7377c44c 16SED=
2a4665f5
KB
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)
7377c44c 33 SED=p
2a4665f5 34 shift ;;
2a4665f5
KB
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
7377c44c
KB
49if [ "$SED"x = x ]; then
50 cpp -M $* > $TMP
51else
52 cpp -M $* | sed 's;\.o :; :;' > $TMP
53fi
2a4665f5
KB
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