]> git.sur5r.net Git - openldap/blob - build/mkdep
Initial revision
[openldap] / build / mkdep
1 #!/bin/sh -
2 #
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
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.
17 #
18 #       @(#)mkdep.sh    5.12 (Berkeley) 6/30/88
19 #
20 # We now use whatever path is already set by the invoker
21 #PATH=/bin:/usr/bin:/usr/ucb
22 #export PATH
23
24 set -e                          # exit immediately if any errors occur
25
26 MAKE=Makefile                   # default makefile name is "Makefile"
27 NOSLASH="no"                    # by default, / dependencies are included
28 CC=cc                           # default compiler is cc
29
30 while :
31         do case "$1" in
32                 # -f allows you to select a makefile name
33                 -f)
34                         MAKE=$2
35                         shift; shift ;;
36
37                 # -c allows you to select a compiler to use (default is cc)
38                 -c)
39                         CC=$2
40                         shift; shift ;;
41
42                 # the -p flag produces "program: program.c" style dependencies
43                 # so .o's don't get produced
44                 -p)
45                         SED='s;\.o;;'
46                         shift ;;
47
48                 # the -s flag removes dependencies to files that begin with /
49                 -s)
50                         NOSLASH=yes;
51                         shift ;;
52
53 #               -*)     shift ;;
54
55                 *)
56                         break ;;
57         esac
58 done
59
60 if [ $# = 0 ] ; then
61         echo 'usage: mkdep [-p] [-f makefile] [flags] file ...'
62         exit 1
63 fi
64
65 if [ ! -w $MAKE ]; then
66         echo "mkdep: no writeable file \"$MAKE\""
67         exit 1
68 fi
69
70 TMP=/tmp/mkdep$$
71
72 trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
73
74 cp $MAKE ${MAKE}.bak
75
76 sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
77
78 cat << _EOF_ >> $TMP
79 # DO NOT DELETE THIS LINE -- mkdep uses it.
80 # DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
81
82 _EOF_
83
84 # If your compiler doesn't have -M, add it.  If you can't, the next two
85 # lines will try and replace the "cc -M".  The real problem is that this
86 # hack can't deal with anything that requires a search path, and doesn't
87 # even try for anything using bracket (<>) syntax.
88 #
89 # egrep '^#include[     ]*".*"' /dev/null $* |
90 # sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
91
92 $CC -M $* |
93 sed "
94         s; \./; ;g
95         $SED" |
96 awk '
97 $1 ~ /:/ {
98         filenm=$1
99         dep=$2
100 }
101 $1 !~ /:/ {
102         dep=$1
103 }
104 /.*/ {
105         if ( noslash = "yes" && dep ~ /^\// ) next
106         if (filenm != prev) {
107                 if (rec != "")
108                         print rec;
109                 rec = filenm " " dep;
110                 prev = filenm;
111         }
112         else {
113                 if (length(rec dep) > 78) {
114                         print rec;
115                         rec = filenm " " dep;
116                 }
117                 else
118                         rec = rec " " dep
119         }
120     }
121 END {
122         print rec
123 }' noslash="$NOSLASH" >> $TMP
124
125 cat << _EOF_ >> $TMP
126
127 # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
128 _EOF_
129
130 # copy to preserve permissions
131 cp $TMP $MAKE
132 rm -f ${MAKE}.bak $TMP
133 exit 0