/[MITgcm]/MITgcm/tools/xmakedepend
ViewVC logotype

Contents of /MITgcm/tools/xmakedepend

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download)
Thu Apr 4 21:50:09 2013 UTC (6 years, 11 months ago) by jmc
Branch: MAIN
Changes since 1.8: +2 -1 lines
add 1 line (easy to go go back to previous version) to switch on
 "-traditional -P" option for CPP command (==> no more warnings for
unbalanced single or double quote)

1 #! /usr/bin/env sh
2 #
3 # $Header: /u/gcmpack/MITgcm/tools/xmakedepend,v 1.8 2010/03/16 00:59:38 jmc Exp $
4 # $Name: $
5 #
6 # $TOG: mdepend.cpp /main/13 1997/06/20 21:12:18 kaleb $
7 #
8 # Do the equivalent of the 'makedepend' program, but do it right.
9 #
10 # Usage:
11 #
12 # makedepend [cpp-flags] [-w width] [-s magic-string] [-f makefile]
13 # [-o object-suffix]
14 #
15 # Notes:
16 #
17 # The C compiler used can be overridden with the environment
18 # variable "CC".
19 #
20 # The "-v" switch of the "makedepend" program is not supported.
21 #
22 #
23 # This script should
24 # work on both USG and BSD systems. However, when System V.4 comes out,
25 # USG users will probably have to change "silent" to "-s" instead of
26 # "-" (at least, that is what the documentation implies).
27 #
28 # $XFree86: xc/config/util/mdepend.cpp,v 3.2 1997/06/29 07:54:20 dawes Exp $
29 #
30
31 CPPARGS="-Dlinux -D__i386__ -D_POSIX_C_SOURCE=199309L -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_GNU_SOURCE "
32 CPPARGS="-traditional -P $CPPARGS"
33
34 CC="cpp $CPPARGS"
35 if test -x /lib/cpp ; then
36 CC="/lib/cpp $CPPARGS"
37 fi
38
39 silent='-'
40
41 TMP=./mdep$$
42 CPPCMD=${TMP}a
43 DEPENDLINES=${TMP}b
44 TMPMAKEFILE=${TMP}c
45 MAGICLINE=${TMP}d
46 ARGS=${TMP}e
47
48 trap "rm -f ${TMP}*; exit 1" 1 2 15
49 trap "rm -f ${TMP}*; exit 0" 1 2 13
50
51 echo " \c" > $CPPCMD
52 if [ `wc -c < $CPPCMD` -eq 1 ]
53 then
54 c="\c"
55 n=
56 else
57 c=
58 n="-n"
59 fi
60
61 echo $n "$c" >$ARGS
62
63 files=
64 makefile=
65 magic_string='# DO NOT DELETE'
66 objsuffix='.o'
67 width=78
68 endmarker=""
69 verbose=n
70 append=n
71
72 while [ $# != 0 ]
73 do
74 if [ "$endmarker"x != x ] && [ "$endmarker" = "$1" ]; then
75 endmarker=""
76 else
77 case "$1" in
78 -D*|-I*)
79 echo $n " '$1'$c" >> $ARGS
80 ;;
81
82 -g|-O) # ignore so we can just pass $(CFLAGS) in
83 ;;
84
85 *)
86 if [ "$endmarker"x = x ]; then
87 case "$1" in
88 -w)
89 width="$2"
90 shift
91 ;;
92 -s)
93 magic_string="$2"
94 shift
95 ;;
96 -f*)
97 if [ "$1" = "-f-" ]; then
98 makefile="-"
99 else
100 makefile="$2"
101 shift
102 fi
103 ;;
104 -o)
105 objsuffix="$2"
106 shift
107 ;;
108
109 --*)
110 echo "$1" | sed 's/^\-\-//' >${TMP}end
111 endmarker="`cat ${TMP}end`"
112 rm -f ${TMP}end
113 if [ "$endmarker"x = x ]; then
114 endmarker="--"
115 fi
116 ;;
117 -v)
118 verbose="y"
119 ;;
120
121 -a)
122 append="y"
123 ;;
124
125 -cc)
126 CC="$2"
127 shift
128 ;;
129
130 -cpp)
131 CC="$2 $CPPARGS"
132 shift
133 ;;
134
135 -*)
136 echo "Unknown option '$1' ignored" 1>&2
137 ;;
138 *)
139 files="$files $1"
140 ;;
141 esac
142 fi
143 ;;
144 esac
145 fi
146 shift
147 done
148 echo ' $*' >> $ARGS
149
150 echo "#!/bin/sh" > $CPPCMD
151 echo "exec $CC `cat $ARGS`" >> $CPPCMD
152 chmod +x $CPPCMD
153 rm $ARGS
154
155 case "$makefile" in
156 '')
157 if [ -r makefile ]
158 then
159 makefile=makefile
160 elif [ -r Makefile ]
161 then
162 makefile=Makefile
163 else
164 echo 'no makefile or Makefile found' 1>&2
165 exit 1
166 fi
167 ;;
168 -)
169 makefile=$TMPMAKEFILE
170 ;;
171 esac
172
173 if [ "$verbose"x = "y"x ]; then
174 cat $CPPCMD
175 fi
176
177 echo '' > $DEPENDLINES
178 for i in $files
179 do
180 $CPPCMD $i | sed -n "/^#/s;^;$i ;p"
181
182 done | sed -e 's|/[^/.][^/]*/\.\.||g' -e 's|/\.[^.][^/]*/\.\.||g' -e 's|"||g' -e 's| \./| |' | awk '!/<.*>/{
183 if ($1 != $4 && $2 != "#ident" && $2 != "#pragma")
184
185 {
186 ofile = substr ($1, 1, length ($1) - 2) "'"$objsuffix"'"
187 print ofile, $4
188 }
189 }' | sort -u | awk '
190
191
192 {
193 newrec = rec " " $2
194 if ($1 != old1)
195 {
196 old1 = $1
197 if (rec != "")
198 print rec
199 rec = $1 ": " $2
200 }
201 else if (length (newrec) > '"$width"')
202 {
203 print rec
204 rec = $1 ": " $2
205 }
206 else
207 rec = newrec
208 }
209 END {
210
211 if (rec != "")
212 print rec
213 }' | egrep -v '^[^:]*:[ ]*$' >> $DEPENDLINES
214
215
216 trap "" 1 2 13 15 # Now we are committed
217 case "$makefile" in
218 $TMPMAKEFILE)
219 ;;
220 *)
221 rm -f $makefile.bak
222 cp $makefile $makefile.bak
223 echo "Appending dependencies to $makefile"
224 ;;
225 esac
226
227 #
228 # If not -a, append the magic string and a blank line so that
229 # /^$magic_string/+1,\$d can be used to delete everything from after
230 # the magic string to the end of the file. Then, append a blank
231 # line again and then the dependencies.
232 #
233 if [ "$append" = "n" ]
234 then
235 cat >> $makefile << END_OF_APPEND
236
237 $magic_string
238
239 END_OF_APPEND
240 ed $silent $makefile << END_OF_ED_SCRIPT
241 /^$magic_string/+1,\$d
242 w
243 q
244 END_OF_ED_SCRIPT
245 echo '' >>$makefile
246 fi
247
248 cat $DEPENDLINES >>$makefile
249
250 case "$makefile" in
251 $TMPMAKEFILE)
252 cat $TMPMAKEFILE
253 ;;
254 esac
255
256 rm -f ${TMP}*
257 exit 0

  ViewVC Help
Powered by ViewVC 1.1.22