]> git.sur5r.net Git - openldap/blob - build/mkdep
Merge in Normalized DN bug fixes and optimizations from devel.
[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 SRCDIR=""
30 SED=cat
31
32 while :
33         do case "$1" in
34                 # the -s flag removes dependencies to files that begin with /
35                 -s)
36                         NOSLASH=yes;
37                         shift ;;
38
39                 # -f allows you to select a makefile name
40                 -f)
41                         MAKE=$2
42                         shift; shift ;;
43
44                 # -d allows you to select a VPATH directory
45                 -d)
46                         SRCDIR=$2
47                         shift; shift ;;
48
49                 # -c allows you to select a compiler to use (default is cc)
50                 -c)
51                         CC=$2
52                         shift; shift ;;
53
54                 # the -p flag produces "program: program.c" style dependencies
55                 # so .o's don't get produced
56                 -p)
57                         SED='sed -e s;\.o;;'
58                         shift ;;
59
60
61                 # the -l flag produces libtool compatible dependencies
62                 -l)
63                         SED='sed -e s;\.o:;.lo:;'
64                         shift ;;
65
66 #               -*)     shift ;;
67
68                 *)
69                         break ;;
70         esac
71 done
72
73 if [ $# = 0 ] ; then
74         echo 'usage: mkdep [-p] [-s] [-c cc] [-f makefile] [-d srcdir] [flags] file ...'
75         exit 1
76 fi
77
78 if [ ! -w $MAKE ]; then
79         echo "mkdep: no writeable file \"$MAKE\""
80         exit 1
81 fi
82
83 TMP=/tmp/mkdep$$
84
85 trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
86
87 cp $MAKE ${MAKE}.bak
88
89 sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
90
91 cat << _EOF_ >> $TMP
92 # DO NOT DELETE THIS LINE -- mkdep uses it.
93 # DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
94
95 _EOF_
96
97 # If your compiler doesn't have -M, add it.  If you can't, the next two
98 # lines will try and replace the "cc -M".  The real problem is that this
99 # hack can't deal with anything that requires a search path, and doesn't
100 # even try for anything using bracket (<>) syntax.
101 #
102 # egrep '^#include[     ]*".*"' /dev/null $* |
103 # sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
104
105 if test "x$SRCDIR" = "x" ; then
106         files=$*
107 else
108         files=
109         for i in $* ; do
110                 if test -f $i ; then
111                         files="$files $i"
112                 elif test -f $SRCDIR/$i ; then
113                         files="$files $SRCDIR/$i"
114                 else
115                         files="$files $i"
116                 fi
117         done
118         CC="$CC -I$SRCDIR"
119 fi
120
121 cat << _EOF_ >> $TMP
122
123 #
124 # files: $*
125 # command: $CC -M $files
126 #
127
128 _EOF_
129
130 $CC -M $files | \
131         sed -e 's; \./; ;g' | \
132         $SED | \
133 awk '
134 $1 ~ /:/ {
135         filenm=$1
136         dep=$2
137 }
138 $1 !~ /:/ {
139         dep=$1
140 }
141 /.*/ {
142         if (( noslash == "yes") && (dep ~ /^\// )) next
143         if ( length(dep) < 2 ) next
144         rec = filenm " " dep;
145         print rec;
146     }
147 ' noslash="$NOSLASH" >> $TMP
148
149
150 cat << _EOF_ >> $TMP
151
152 # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
153 _EOF_
154
155 # copy to preserve permissions
156 cp $TMP $MAKE
157 rm -f ${MAKE}.bak $TMP
158 exit 0