/[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.2 - (show annotations) (download)
Fri Sep 26 15:31:49 2003 UTC (20 years, 6 months ago) by adcroft
Branch: MAIN
CVS Tags: checkpoint51k_post, checkpoint51o_pre, checkpoint51l_post, checkpoint52, checkpoint51f_post, checkpoint51t_post, checkpoint51n_post, checkpoint51s_post, checkpoint51j_post, checkpoint51n_pre, checkpoint51l_pre, checkpoint51q_post, checkpoint51h_pre, branchpoint-genmake2, checkpoint51r_post, checkpoint51i_post, checkpoint51i_pre, checkpoint51o_post, checkpoint51g_post, ecco_c52_e35, checkpoint51m_post, checkpoint51p_post, checkpoint51u_post
Branch point for: branch-genmake2, branch-nonh, tg2-branch, checkpoint51n_branch
Changes since 1.1: +8 -2 lines
 o Changed path to shell from /usr/bin/sh to /bin/sh
 o Changed default CC from "cpp" to "/lib/cpp"
 o Added new option: -cpp to specify the C pre-processor
   - this will allow use to pass non-standard cpp paths from genmake

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

  ViewVC Help
Powered by ViewVC 1.1.22