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

Annotation of /MITgcm/tools/xmakedepend

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


Revision 1.8 - (hide annotations) (download)
Tue Mar 16 00:59:38 2010 UTC (11 years, 1 month ago) by jmc
Branch: MAIN
CVS Tags: checkpoint62v, checkpoint62u, checkpoint62t, checkpoint62s, checkpoint62r, checkpoint62q, checkpoint62p, checkpoint62g, checkpoint62f, checkpoint62e, checkpoint62d, checkpoint62k, checkpoint62j, checkpoint62i, checkpoint62h, checkpoint62o, checkpoint62n, checkpoint62m, checkpoint62l, checkpoint62w, checkpoint62z, checkpoint62y, checkpoint62x, checkpoint63g, checkpoint64, checkpoint63, checkpoint63p, checkpoint63q, checkpoint63r, checkpoint63s, checkpoint63l, checkpoint63m, checkpoint63n, checkpoint63o, checkpoint63h, checkpoint63i, checkpoint63j, checkpoint63k, checkpoint63d, checkpoint63e, checkpoint63f, checkpoint63a, checkpoint63b, checkpoint63c, checkpoint64a, checkpoint64c, checkpoint64b, checkpoint64e, checkpoint64d, checkpoint64f
Changes since 1.7: +4 -7 lines
add cvs Header & Name ; remove debugging "cat $CPPCMD".

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

  ViewVC Help
Powered by ViewVC 1.1.22