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