add Berkeley copyright notice
[unix-history] / usr / src / usr.bin / mkdep / mkdep.sh
CommitLineData
043ab8c8 1#!/bin/sh -
f48536ef 2#
043ab8c8
KB
3# Copyright (c) 1987 Regents of the University of California.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms are permitted
dc45ba8c
KB
7# provided that the above copyright notice and this paragraph are
8# duplicated in all such forms and that any documentation,
9# advertising materials, and other materials related to such
10# distribution and use acknowledge that the software was developed
11# by the University of California, Berkeley. The name of the
12# University may not be used to endorse or promote products derived
13# from this software without specific prior written permission.
14# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
043ab8c8 17#
97ed9a0c 18# @(#)mkdep.sh 5.14 (Berkeley) %G%
f48536ef 19#
c0644842
KB
20PATH=/bin:/usr/bin:/usr/ucb
21export PATH
8c3305b6 22
82629d33 23D=.depend # default dependency file is .depend
190489bd
KB
24
25while :
26 do case "$1" in
27 # -f allows you to select a makefile name
28 -f)
82629d33 29 D=$2
190489bd
KB
30 shift; shift ;;
31
32 # the -p flag produces "program: program.c" style dependencies
33 # so .o's don't get produced
34 -p)
742d9467 35 SED='s;\.o;;'
190489bd
KB
36 shift ;;
37 *)
38 break ;;
39 esac
40done
41
0ee442d6 42if [ $# = 0 ] ; then
82629d33 43 echo 'usage: mkdep [-p] [-f depend_file] [cc_flags] file ...'
0ee442d6
KB
44 exit 1
45fi
46
f48536ef
KB
47TMP=/tmp/mkdep$$
48
8c3305b6 49trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
f48536ef 50
e2b7b485
KB
51# If your compiler doesn't have -M, add it. If you can't, the next two
52# lines will try and replace the "cc -M". The real problem is that this
53# hack can't deal with anything that requires a search path, and doesn't
54# even try for anything using bracket (<>) syntax.
55#
56# egrep '^#include[ ]*".*"' /dev/null $* |
57# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
58
742d9467
KB
59cc -M $* |
60sed "
61 s; \./; ;g
62 $SED" |
63awk '{
64 if ($1 != prev) {
65 if (rec != "")
66 print rec;
67 rec = $0;
68 prev = $1;
69 }
70 else {
71 if (length(rec $2) > 78) {
72 print rec;
73 rec = $0;
74 }
75 else
76 rec = rec " " $2
77 }
78}
79END {
80 print rec
82629d33 81}' > $TMP
f48536ef 82
97ed9a0c 83mv $TMP $D
f48536ef 84exit 0