/[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.6 - (show annotations) (download)
Thu Mar 3 18:05:39 2005 UTC (19 years ago) by edhill
Branch: MAIN
CVS Tags: checkpoint57m_post, checkpoint57g_pre, checkpoint57s_post, checkpoint58b_post, checkpoint57g_post, checkpoint57y_post, checkpoint62c, checkpoint57r_post, checkpoint57i_post, checkpoint59, checkpoint58, checkpoint58f_post, checkpoint57n_post, checkpoint58d_post, checkpoint58a_post, checkpoint57z_post, checkpoint62a, checkpoint58y_post, checkpoint58t_post, checkpoint58m_post, checkpoint57l_post, checkpoint57t_post, checkpoint57v_post, checkpoint57f_post, checkpoint60, checkpoint61, checkpoint62, checkpoint57h_pre, checkpoint58w_post, checkpoint57h_post, checkpoint57y_pre, checkpoint58o_post, checkpoint58p_post, checkpoint58q_post, checkpoint58e_post, mitgcm_mapl_00, checkpoint58r_post, checkpoint58n_post, checkpoint59q, checkpoint59p, checkpoint59r, checkpoint59e, checkpoint59d, checkpoint59g, checkpoint59f, checkpoint59a, checkpoint59c, checkpoint59b, checkpoint59m, checkpoint59l, checkpoint59o, checkpoint59n, checkpoint59i, checkpoint59h, checkpoint59k, checkpoint57p_post, checkpint57u_post, checkpoint57q_post, checkpoint58k_post, checkpoint62b, checkpoint58v_post, checkpoint58l_post, checkpoint57h_done, checkpoint57j_post, checkpoint57f_pre, checkpoint61f, checkpoint58g_post, checkpoint58x_post, checkpoint61n, checkpoint59j, checkpoint58h_post, checkpoint58j_post, checkpoint57o_post, checkpoint61q, checkpoint57k_post, checkpoint57w_post, checkpoint61e, checkpoint58i_post, checkpoint57x_post, checkpoint58c_post, checkpoint58u_post, checkpoint58s_post, checkpoint61g, checkpoint61d, checkpoint61b, checkpoint61c, checkpoint61a, checkpoint61o, checkpoint61l, checkpoint61m, checkpoint61j, checkpoint61k, checkpoint61h, checkpoint61i, checkpoint61v, checkpoint61w, checkpoint61t, checkpoint61u, checkpoint61r, checkpoint61s, checkpoint61p, checkpoint61z, checkpoint61x, checkpoint61y
Changes since 1.5: +3 -7 lines
 o saner default

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

  ViewVC Help
Powered by ViewVC 1.1.22