fix -p and include SED in compile statement so user can set SED
[unix-history] / usr / src / usr.bin / mkdep / mkdep.append
CommitLineData
6ef22919
KB
1#!/bin/sh -
2#
0293662b 3# Copyright (c) 1991 The Regents of the University of California.
6ef22919
KB
4# All rights reserved.
5#
0293662b 6# %sccs.include.redist.sh%
6ef22919 7#
0293662b 8# @(#)mkdep.append 5.2 (Berkeley) %G%
6ef22919 9#
0293662b 10
6ef22919
KB
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
65cc -M $* |
66sed "
67 s; \./; ;g
68 $SED" |
69awk '{
70 if ($1 != prev) {
71 if (rec != "")
72 print rec;
73 rec = $0;
74 prev = $1;
75 }
76 else {
77 if (length(rec $2) > 78) {
78 print rec;
79 rec = $0;
80 }
81 else
82 rec = rec " " $2
83 }
84}
85END {
86 print rec
87}' >> $TMP
88
89cat << _EOF_ >> $TMP
90
91# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
92_EOF_
93
94# copy to preserve permissions
95cp $TMP $MAKE
96rm -f ${MAKE}.bak $TMP
97exit 0