]> git.sur5r.net Git - openldap/blob - build/mkdep
fbaea123b4dce7f16c8f89183330e29ac0d2275d
[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-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
49                 # the -l flag produces libtool compatible dependencies
50                 -l)
51                         SED='s;\.o:;.lo:;'
52                         shift ;;
53
54                 # the -s flag removes dependencies to files that begin with /
55                 -s)
56                         NOSLASH=yes;
57                         shift ;;
58
59 #               -*)     shift ;;
60
61                 *)
62                         break ;;
63         esac
64 done
65
66 if [ $# = 0 ] ; then
67         echo 'usage: mkdep [-p] [-s] [-c cc] [-f makefile] [flags] file ...'
68         exit 1
69 fi
70
71 if [ ! -w $MAKE ]; then
72         echo "mkdep: no writeable file \"$MAKE\""
73         exit 1
74 fi
75
76 TMP=/tmp/mkdep$$
77
78 trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
79
80 cp $MAKE ${MAKE}.bak
81
82 sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
83
84 cat << _EOF_ >> $TMP
85 # DO NOT DELETE THIS LINE -- mkdep uses it.
86 # DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
87
88 _EOF_
89
90 # If your compiler doesn't have -M, add it.  If you can't, the next two
91 # lines will try and replace the "cc -M".  The real problem is that this
92 # hack can't deal with anything that requires a search path, and doesn't
93 # even try for anything using bracket (<>) syntax.
94 #
95 # egrep '^#include[     ]*".*"' /dev/null $* |
96 # sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
97
98 $CC -M $* |
99 sed "
100         s; \./; ;g
101         $SED" |
102 awk '
103 $1 ~ /:/ {
104         filenm=$1
105         dep=$2
106 }
107 $1 !~ /:/ {
108         dep=$1
109 }
110 /.*/ {
111         if ( noslash = "yes" && dep ~ /^\// ) next
112         if (filenm != prev) {
113                 if (rec != "")
114                         print rec;
115                 rec = filenm " " dep;
116                 prev = filenm;
117         }
118         else {
119                 if (length(rec dep) > 78) {
120                         print rec;
121                         rec = filenm " " dep;
122                 }
123                 else
124                         rec = rec " " dep
125         }
126     }
127 END {
128         print rec
129 }' noslash="$NOSLASH" >> $TMP
130
131 cat << _EOF_ >> $TMP
132
133 # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
134 _EOF_
135
136 # copy to preserve permissions
137 cp $TMP $MAKE
138 rm -f ${MAKE}.bak $TMP
139 exit 0