fix exit change; major whitespace cleanup
[unix-history] / usr / src / usr.bin / mkdep / mkdep.old.compiler
CommitLineData
e808c60b
KB
1#!/bin/sh -
2#
0293662b 3# Copyright (c) 1991 The Regents of the University of California.
e808c60b
KB
4# All rights reserved.
5#
0293662b 6# %sccs.include.redist.sh%
e808c60b 7#
0293662b 8# @(#)mkdep.old.compiler 5.4 (Berkeley) %G%
e808c60b
KB
9#
10
11# This is a version of mkdep that works pretty well
12# with compilers that don't have -M.
a42cedc5 13MAKE=Makefile # default makefile name is "Makefile"
e808c60b
KB
14
15PATH=/bin:/usr/bin:/usr/ucb:/lib:/usr/lib
16
17INCL=
4db60ccd 18
e808c60b
KB
19while :
20 do case "$1" in
21 # -f allows you to select a makefile name
22 -f)
a42cedc5 23 MAKE=$2
e808c60b 24 shift; shift ;;
4db60ccd 25
e808c60b
KB
26 # the -p flag produces "program: program.c" style dependencies
27 # so .o's don't get produced
28 -p)
29 SED='s;\.o;;'
30 shift ;;
31 *)
32 break ;;
33 esac
34done
35
36if [ $# = 0 ] ; then
a42cedc5
MK
37 echo 'usage: mkdep [-p] [-f makefile] [flags] file ...'
38 exit 1
39fi
40
41if [ ! -w $MAKE ]; then
42 echo "mkdep: no writeable file \"$MAKE\""
e808c60b
KB
43 exit 1
44fi
45
46TMP=/tmp/mkdep$$
a42cedc5 47
e808c60b
KB
48trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
49
a42cedc5
MK
50cp $MAKE ${MAKE}.bak
51sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
52
53cat << _EOF_ >> $TMP
54# DO NOT DELETE THIS LINE -- mkdep uses it.
55# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
56
57_EOF_
58
59
e808c60b
KB
60for i do
61 case "$i" in
a42cedc5 62 -c|-M|-O)
e808c60b
KB
63 ;;
64 -I*)
65 INCL="$INCL $i";;
a42cedc5 66 -D*|-U*)
e808c60b
KB
67 FLAGS="$FLAGS $i";;
68 *)
69 # assume source file
70 # put '$dep' in front of dependencies
71 dep=`echo "$i" | sed -e 's,/,\\\\/,g' -e 's/\.c$/.o/'`
72
73 # Find includes, remove leading numerics, remove ./,
74 # remove double quotes, and remove trailing numerics.
75 # Sort that, discarding duplicates, and add '$dep'.
76 cpp $INCL $FLAGS "$i" | sed -e '
77 /^#/!d
78 s/# [0-9]* //
79 s,"./,",
80 s/"\(.*\)"/\1/
81 s/ [ 0-9]*$//' |
82 sort -u | sed -e "s/^/$dep: /";;
83 esac
84done |
85sed "
86 s; \./; ;g
87 /\.c:$/d
88 $SED" |
89awk '{
90 if ($1 != prev) {
91 if (rec != "")
92 print rec;
93 rec = $0;
94 prev = $1;
95 }
96 else {
97 if (length(rec $2) > 78) {
98 print rec;
99 rec = $0;
100 }
101 else
102 rec = rec " " $2
103 }
104}
105END {
106 print rec
a42cedc5 107}' >> $TMP
e808c60b 108
a42cedc5
MK
109cat << _EOF_ >> $TMP
110
111# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
112_EOF_
113
114# copy to preserve permissions
115cp $TMP $MAKE
116rm -f $TMP
e808c60b 117exit 0