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