]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/cvs/depcomp
This commit was generated by cvs2svn to compensate for changes in r95978,
[FreeBSD/FreeBSD.git] / contrib / cvs / depcomp
1 #! /bin/sh
2
3 # depcomp - compile a program generating dependencies as side-effects
4 # Copyright 1999, 2000 Free Software Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 # 02111-1307, USA.
20
21 # Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
22
23 if test -z "$depmode" || test -z "$source" || test -z "$object"; then
24   echo "depcomp: Variables source, object and depmode must be set" 1>&2
25   exit 1
26 fi
27 # `libtool' can also be set to `yes' or `no'.
28
29 depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`}
30 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
31
32 rm -f "$tmpdepfile"
33
34 # Some modes work just like other modes, but use different flags.  We
35 # parameterize here, but still list the modes in the big case below,
36 # to make depend.m4 easier to write.  Note that we *cannot* use a case
37 # here, because this file can only contain one case statement.
38 if test "$depmode" = hp; then
39   # HP compiler uses -M and no extra arg.
40   gccflag=-M
41   depmode=gcc
42 fi
43
44 if test "$depmode" = dashXmstdout; then
45    # This is just like dashmstdout with a different argument.
46    dashmflag=-xM
47    depmode=dashmstdout
48 fi
49
50 case "$depmode" in
51 gcc3)
52 ## gcc 3 implements dependency tracking that does exactly what
53 ## we want.  Yay!
54   "$@" -MT "$object" -MF "$tmpdepfile" -MD -MP
55   stat=$?
56   if test $stat -eq 0; then :
57   else
58     rm -f "$tmpdepfile"
59     exit $stat
60   fi
61   mv "$tmpdepfile" "$depfile"
62   ;;
63
64 gcc)
65 ## There are various ways to get dependency output from gcc.  Here's
66 ## why we pick this rather obscure method:
67 ## - Don't want to use -MD because we'd like the dependencies to end
68 ##   up in a subdir.  Having to rename by hand is ugly.
69 ##   (We might end up doing this anyway to support other compilers.)
70 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
71 ##   -MM, not -M (despite what the docs say).
72 ## - Using -M directly means running the compiler twice (even worse
73 ##   than renaming).
74   if test -z "$gccflag"; then
75     gccflag=-MD,
76   fi
77   "$@" -Wp,"$gccflag$tmpdepfile"
78   stat=$?
79   if test $stat -eq 0; then :
80   else
81     rm -f "$tmpdepfile"
82     exit $stat
83   fi
84   rm -f "$depfile"
85   echo "$object : \\" > "$depfile"
86   alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
87 ## The second -e expression handles DOS-style file names with drive letters.
88   sed -e 's/^[^:]*: / /' \
89       -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
90 ## This next piece of magic avoids the `deleted header file' problem.
91 ## The problem is that when a header file which appears in a .P file
92 ## is deleted, the dependency causes make to die (because there is
93 ## typically no way to rebuild the header).  We avoid this by adding
94 ## dummy dependencies for each header file.  Too bad gcc doesn't do
95 ## this for us directly.
96   tr ' ' '
97 ' < "$tmpdepfile" |
98 ## Some versions of gcc put a space before the `:'.  On the theory
99 ## that the space means something, we add a space to the output as
100 ## well.
101 ## Some versions of the HPUX 10.20 sed can't process this invocation
102 ## correctly.  Breaking it into two sed invocations is a workaround.
103     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
104   rm -f "$tmpdepfile"
105   ;;
106
107 hp)
108   # This case exists only to let depend.m4 do its work.  It works by
109   # looking at the text of this script.  This case will never be run,
110   # since it is checked for above.
111   exit 1
112   ;;
113
114 sgi)
115   if test "$libtool" = yes; then
116     "$@" "-Wp,-MDupdate,$tmpdepfile"
117   else
118     "$@" -MDupdate "$tmpdepfile"
119   fi
120   stat=$?
121   if test $stat -eq 0; then :
122   else
123     rm -f "$tmpdepfile"
124     exit $stat
125   fi
126
127   if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
128     rm -f "$depfile"
129     cp "$tmpdepfile" "$depfile"
130 ## This next piece of magic avoids the `deleted header file' problem.
131 ## The problem is that when a header file which appears in a .P file
132 ## is deleted, the dependency causes make to die (because there is
133 ## typically no way to rebuild the header).  We avoid this by adding
134 ## dummy dependencies for each header file.
135     tr ' ' '
136 ' < "$tmpdepfile" | \
137       sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' -e '/^#/d' | sed -e 's/$/ :/' >> "$depfile"
138   else
139     # The sourcefile does not contain any dependencies, so just
140     # store a dummy comment line, to avoid errors with the Makefile
141     # "include basename.Plo" scheme.
142     echo "#dummy" > "$depfile"
143   fi
144   rm -f "$tmpdepfile"
145   ;;
146
147 aix)
148   # The C for AIX Compiler uses -M and outputs the dependencies
149   # in a .u file.
150   tmpdepfile=`echo "$object" | sed 's/\(.*\)\..*$/\1.u/'`
151   if test "$libtool" = yes; then
152     "$@" -Wc,-M
153   else
154     "$@" -M
155   fi
156
157   stat=$?
158   if test $stat -eq 0; then :
159   else
160     rm -f "$tmpdepfile"
161     exit $stat
162   fi
163
164   if test -f "$tmpdepfile"; then
165     rm -f "$depfile"
166     cp "$tmpdepfile" "$depfile"
167 ## This next piece of magic avoids the `deleted header file' problem.
168 ## The problem is that when a header file which appears in a .P file
169 ## is deleted, the dependency causes make to die (because there is
170 ## typically no way to rebuild the header).  We avoid this by adding
171 ## dummy dependencies for each header file.
172     tr ' ' '
173 ' < "$tmpdepfile" | \
174       sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
175   else
176     # The sourcefile does not contain any dependencies, so just
177     # store a dummy comment line, to avoid errors with the Makefile
178     # "include basename.Plo" scheme.
179     echo "#dummy" > "$depfile"
180   fi
181   rm -f "$tmpdepfile"
182   ;;
183
184 #nosideeffect)
185   # This comment above is used by automake to tell side-effect
186   # dependency tracking mechanisms from slower ones.
187
188 dashmstdout)
189   # Important note: in order to support this mode, a compiler *must*
190   # always write the proprocessed file to stdout, regardless of -o,
191   # because we must use -o when running libtool.
192   test -z "$dashmflag" && dashmflag=-M
193   ( IFS=" "
194     case " $* " in
195     *" --mode=compile "*) # this is libtool, let us make it quiet
196       for arg
197       do # cycle over the arguments
198         case "$arg" in
199         "--mode=compile")
200           # insert --quiet before "--mode=compile"
201           set fnord "$@" --quiet
202           shift # fnord
203           ;;
204         esac
205         set fnord "$@" "$arg"
206         shift # fnord
207         shift # "$arg"
208       done
209       ;;
210     esac
211     "$@" $dashmflag | sed 's:^[^:]*\:[  ]*:'"$object"'\: :' > "$tmpdepfile"
212   ) &
213   proc=$!
214   "$@"
215   stat=$?
216   wait "$proc"
217   if test "$stat" != 0; then exit $stat; fi
218   rm -f "$depfile"
219   cat < "$tmpdepfile" > "$depfile"
220   tr ' ' '
221 ' < "$tmpdepfile" | \
222 ## Some versions of the HPUX 10.20 sed can't process this invocation
223 ## correctly.  Breaking it into two sed invocations is a workaround.
224     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
225   rm -f "$tmpdepfile"
226   ;;
227
228 dashXmstdout)
229   # This case only exists to satisfy depend.m4.  It is never actually
230   # run, as this mode is specially recognized in the preamble.
231   exit 1
232   ;;
233
234 makedepend)
235   # X makedepend
236   (
237     shift
238     cleared=no
239     for arg in "$@"; do
240       case $cleared in no)
241         set ""; shift
242         cleared=yes
243       esac
244       case "$arg" in
245         -D*|-I*)
246           set fnord "$@" "$arg"; shift;;
247         -*)
248           ;;
249         *)
250           set fnord "$@" "$arg"; shift;;
251       esac
252     done
253     obj_suffix="`echo $object | sed 's/^.*\././'`"
254     touch "$tmpdepfile"
255     ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
256   ) &
257   proc=$!
258   "$@"
259   stat=$?
260   wait "$proc"
261   if test "$stat" != 0; then exit $stat; fi
262   rm -f "$depfile"
263   cat < "$tmpdepfile" > "$depfile"
264   tail +3 "$tmpdepfile" | tr ' ' '
265 ' | \
266 ## Some versions of the HPUX 10.20 sed can't process this invocation
267 ## correctly.  Breaking it into two sed invocations is a workaround.
268     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
269   rm -f "$tmpdepfile" "$tmpdepfile".bak
270   ;;
271
272 cpp)
273   # Important note: in order to support this mode, a compiler *must*
274   # always write the proprocessed file to stdout, regardless of -o,
275   # because we must use -o when running libtool.
276   ( IFS=" "
277     case " $* " in
278     *" --mode=compile "*)
279       for arg
280       do # cycle over the arguments
281         case $arg in
282         "--mode=compile")
283           # insert --quiet before "--mode=compile"
284           set fnord "$@" --quiet
285           shift # fnord
286           ;;
287         esac
288         set fnord "$@" "$arg"
289         shift # fnord
290         shift # "$arg"
291       done
292       ;;
293     esac
294     "$@" -E |
295     sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
296     sed '$ s: \\$::' > "$tmpdepfile"
297   ) &
298   proc=$!
299   "$@"
300   stat=$?
301   wait "$proc"
302   if test "$stat" != 0; then exit $stat; fi
303   rm -f "$depfile"
304   echo "$object : \\" > "$depfile"
305   cat < "$tmpdepfile" >> "$depfile"
306   sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
307   rm -f "$tmpdepfile"
308   ;;
309
310 msvisualcpp)
311   # Important note: in order to support this mode, a compiler *must*
312   # always write the proprocessed file to stdout, regardless of -o,
313   # because we must use -o when running libtool.
314   ( IFS=" "
315     case " $* " in
316     *" --mode=compile "*)
317       for arg
318       do # cycle over the arguments
319         case $arg in
320         "--mode=compile")
321           # insert --quiet before "--mode=compile"
322           set fnord "$@" --quiet
323           shift # fnord
324           ;;
325         esac
326         set fnord "$@" "$arg"
327         shift # fnord
328         shift # "$arg"
329       done
330       ;;
331     esac
332     "$@" -E |
333     sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
334   ) &
335   proc=$!
336   "$@"
337   stat=$?
338   wait "$proc"
339   if test "$stat" != 0; then exit $stat; fi
340   rm -f "$depfile"
341   echo "$object : \\" > "$depfile"
342   . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::    \1 \\:p' >> "$depfile"
343   echo "        " >> "$depfile"
344   . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
345   rm -f "$tmpdepfile"
346   ;;
347
348 none)
349   exec "$@"
350   ;;
351
352 *)
353   echo "Unknown depmode $depmode" 1>&2
354   exit 1
355   ;;
356 esac
357
358 exit 0