/[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.7 - (hide annotations) (download)
Mon Mar 15 22:06:20 2010 UTC (14 years ago) by jahn
Branch: MAIN
Changes since 1.6: +4 -1 lines
hack to make it work with recent cpp (hopefully...)

1 edhill 1.4 #! /usr/bin/env sh
2 heimbach 1.1 #
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 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 "
29 edhill 1.3
30 edhill 1.6 CC="cpp $CPPARGS"
31     if test -x /lib/cpp ; then
32     CC="/lib/cpp $CPPARGS"
33 edhill 1.3 fi
34 heimbach 1.1
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 adcroft 1.2 shift
124     ;;
125    
126     -cpp)
127     CC="$2 $CPPARGS"
128 heimbach 1.1 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 jahn 1.7 cat $CPPCMD
174    
175    
176 heimbach 1.1 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    
186     {
187     ofile = substr ($1, 1, length ($1) - 2) "'"$objsuffix"'"
188     print ofile, $4
189     }
190     }' | sort -u | awk '
191    
192    
193     {
194     newrec = rec " " $2
195     if ($1 != old1)
196     {
197     old1 = $1
198     if (rec != "")
199     print rec
200     rec = $1 ": " $2
201     }
202     else if (length (newrec) > '"$width"')
203     {
204     print rec
205     rec = $1 ": " $2
206     }
207     else
208     rec = newrec
209     }
210     END {
211    
212     if (rec != "")
213     print rec
214     }' | egrep -v '^[^:]*:[ ]*$' >> $DEPENDLINES
215    
216    
217     trap "" 1 2 13 15 # Now we are committed
218     case "$makefile" in
219     $TMPMAKEFILE)
220     ;;
221     *)
222     rm -f $makefile.bak
223     cp $makefile $makefile.bak
224     echo "Appending dependencies to $makefile"
225     ;;
226     esac
227    
228     #
229     # If not -a, append the magic string and a blank line so that
230     # /^$magic_string/+1,\$d can be used to delete everything from after
231     # the magic string to the end of the file. Then, append a blank
232     # line again and then the dependencies.
233     #
234     if [ "$append" = "n" ]
235     then
236     cat >> $makefile << END_OF_APPEND
237    
238     $magic_string
239    
240     END_OF_APPEND
241     ed $silent $makefile << END_OF_ED_SCRIPT
242     /^$magic_string/+1,\$d
243     w
244     q
245     END_OF_ED_SCRIPT
246     echo '' >>$makefile
247     fi
248    
249     cat $DEPENDLINES >>$makefile
250    
251     case "$makefile" in
252     $TMPMAKEFILE)
253     cat $TMPMAKEFILE
254     ;;
255    
256     esac
257    
258     rm -f ${TMP}*
259     exit 0

  ViewVC Help
Powered by ViewVC 1.1.22