]> git.sur5r.net Git - openldap/blob - build/mkdep
Update mkdep with CC_MKDEP_FLAGS from devel.
[openldap] / build / mkdep
1 #!/bin/sh -
2 # Copyright 1998,1999 The OpenLDAP Foundation
3 # COPYING RESTRICTIONS APPLY.  See COPYRIGHT File in top level directory
4 # of this package for details.
5 #
6 # Portions
7 # Copyright (c) 1987 Regents of the University of California.
8 # All rights reserved.
9 #
10 # Redistribution and use in source and binary forms are permitted
11 # provided that the above copyright notice and this paragraph are
12 # duplicated in all such forms and that any documentation,
13 # advertising materials, and other materials related to such
14 # distribution and use acknowledge that the software was developed
15 # by the University of California, Berkeley.  The name of the
16 # University may not be used to endorse or promote products derived
17 # from this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 #
22 #       @(#)mkdep.sh    5.12 (Berkeley) 6/30/88
23 #
24 # We now use whatever path is already set by the invoker
25 #PATH=/bin:/usr/bin:/usr/ucb
26 #export PATH
27
28 set -e                          # exit immediately if any errors occur
29
30 MAKE=Makefile                   # default makefile name is "Makefile"
31 NOSLASH="no"                    # by default, / dependencies are included
32 CC=${CC-cc}                             # default compiler is cc
33 : ${CC_MKDEP_FLAGS="-M"}        # cc -M usually produces dependencies
34 SRCDIR=""
35 SED=cat
36
37 while :
38         do case "$1" in
39                 # the -s flag removes dependencies to files that begin with /
40                 -s)
41                         NOSLASH=yes;
42                         shift ;;
43
44                 # -f allows you to select a makefile name
45                 -f)
46                         MAKE=$2
47                         shift; shift ;;
48
49                 # -d allows you to select a VPATH directory
50                 -d)
51                         SRCDIR=$2
52                         shift; shift ;;
53
54                 # -c allows you to select a compiler to use (default is cc)
55                 -c)
56                         CC=$2
57                         shift; shift ;;
58
59                 # the -p flag produces "program: program.c" style dependencies
60                 # so .o's don't get produced
61                 -p)
62                         SED='sed -e s;\.o;;'
63                         shift ;;
64
65
66                 # the -l flag produces libtool compatible dependencies
67                 -l)
68                         SED='sed -e s;\.o:;.lo:;'
69                         shift ;;
70
71 #               -*)     shift ;;
72
73                 *)
74                         break ;;
75         esac
76 done
77
78 if [ $# = 0 ] ; then
79         echo 'usage: mkdep [-p] [-s] [-c cc] [-f makefile] [-d srcdir] [flags] file ...'
80         exit 1
81 fi
82
83 if [ ! -w $MAKE ]; then
84         echo "mkdep: no writeable file \"$MAKE\""
85         exit 1
86 fi
87
88 TMP=/tmp/mkdep$$
89
90 trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
91
92 cp $MAKE ${MAKE}.bak
93
94 sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
95
96 cat << _EOF_ >> $TMP
97 # DO NOT DELETE THIS LINE -- mkdep uses it.
98 # DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
99
100 _EOF_
101
102 # If your compiler doesn't have -M, add it.  If you can't, the next two
103 # lines will try and replace the "cc -M".  The real problem is that this
104 # hack can't deal with anything that requires a search path, and doesn't
105 # even try for anything using bracket (<>) syntax.
106 #
107 # egrep '^#include[     ]*".*"' /dev/null $* |
108 # sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
109
110 if test "x$SRCDIR" = "x" ; then
111         files=$*
112 else
113         files=
114         for i in $* ; do
115                 if test -f $i ; then
116                         files="$files $i"
117                 elif test -f $SRCDIR/$i ; then
118                         files="$files $SRCDIR/$i"
119                 else
120                         files="$files $i"
121                 fi
122         done
123         CC="$CC -I$SRCDIR"
124 fi
125
126 cat << _EOF_ >> $TMP
127
128 #
129 # files: $*
130 # command: $CC $CC_MKDEP_FLAGS $files
131 #
132
133 _EOF_
134
135 $CC $CC_MKDEP_FLAGS $files | \
136         sed -e 's; \./; ;g' | \
137         $SED | \
138 awk '
139 $1 ~ /:/ {
140         filenm=$1;
141         dep=substr($0, length(filenm)+1);
142 }
143 $1 !~ /:/ {
144         dep=$0;
145 }
146 /.*/ {
147         split(dep, depends, " ");
148         for(d in depends) {
149                 dfile = depends[d];
150                 if (( noslash == "yes") && (dfile ~ /^\// )) next
151                 if ( length(dfile) < 2 ) continue
152                 rec = filenm " " dfile;
153                 print rec;
154         }
155     }
156 ' noslash="$NOSLASH" >> $TMP
157
158
159 cat << _EOF_ >> $TMP
160
161 # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
162 _EOF_
163
164 # copy to preserve permissions
165 cp $TMP $MAKE
166 rm -f ${MAKE}.bak $TMP
167 exit 0