depcomp revision a1d141d5
1a1d141d5Smrg#! /bin/sh
2a1d141d5Smrg
3a1d141d5Smrg# depcomp - compile a program generating dependencies as side-effects
4a1d141d5Smrg# Copyright 1999, 2000, 2003 Free Software Foundation, Inc.
5a1d141d5Smrg
6a1d141d5Smrg# This program is free software; you can redistribute it and/or modify
7a1d141d5Smrg# it under the terms of the GNU General Public License as published by
8a1d141d5Smrg# the Free Software Foundation; either version 2, or (at your option)
9a1d141d5Smrg# any later version.
10a1d141d5Smrg
11a1d141d5Smrg# This program is distributed in the hope that it will be useful,
12a1d141d5Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
13a1d141d5Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14a1d141d5Smrg# GNU General Public License for more details.
15a1d141d5Smrg
16a1d141d5Smrg# You should have received a copy of the GNU General Public License
17a1d141d5Smrg# along with this program; if not, write to the Free Software
18a1d141d5Smrg# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19a1d141d5Smrg# 02111-1307, USA.
20a1d141d5Smrg
21a1d141d5Smrg# As a special exception to the GNU General Public License, if you
22a1d141d5Smrg# distribute this file as part of a program that contains a
23a1d141d5Smrg# configuration script generated by Autoconf, you may include it under
24a1d141d5Smrg# the same distribution terms that you use for the rest of that program.
25a1d141d5Smrg
26a1d141d5Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27a1d141d5Smrg
28a1d141d5Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
29a1d141d5Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
30a1d141d5Smrg  exit 1
31a1d141d5Smrgfi
32a1d141d5Smrg# `libtool' can also be set to `yes' or `no'.
33a1d141d5Smrg
34a1d141d5Smrgif test -z "$depfile"; then
35a1d141d5Smrg   base=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'`
36a1d141d5Smrg   dir=`echo "$object" | sed 's,/.*$,/,'`
37a1d141d5Smrg   if test "$dir" = "$object"; then
38a1d141d5Smrg      dir=
39a1d141d5Smrg   fi
40a1d141d5Smrg   # FIXME: should be _deps on DOS.
41a1d141d5Smrg   depfile="$dir.deps/$base"
42a1d141d5Smrgfi
43a1d141d5Smrg
44a1d141d5Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
45a1d141d5Smrg
46a1d141d5Smrgrm -f "$tmpdepfile"
47a1d141d5Smrg
48a1d141d5Smrg# Some modes work just like other modes, but use different flags.  We
49a1d141d5Smrg# parameterize here, but still list the modes in the big case below,
50a1d141d5Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
51a1d141d5Smrg# here, because this file can only contain one case statement.
52a1d141d5Smrgif test "$depmode" = hp; then
53a1d141d5Smrg  # HP compiler uses -M and no extra arg.
54a1d141d5Smrg  gccflag=-M
55a1d141d5Smrg  depmode=gcc
56a1d141d5Smrgfi
57a1d141d5Smrg
58a1d141d5Smrgif test "$depmode" = dashXmstdout; then
59a1d141d5Smrg   # This is just like dashmstdout with a different argument.
60a1d141d5Smrg   dashmflag=-xM
61a1d141d5Smrg   depmode=dashmstdout
62a1d141d5Smrgfi
63a1d141d5Smrg
64a1d141d5Smrgcase "$depmode" in
65a1d141d5Smrggcc3)
66a1d141d5Smrg## gcc 3 implements dependency tracking that does exactly what
67a1d141d5Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
68a1d141d5Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
69a1d141d5Smrg  "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
70a1d141d5Smrg  stat=$?
71a1d141d5Smrg  if test $stat -eq 0; then :
72a1d141d5Smrg  else
73a1d141d5Smrg    rm -f "$tmpdepfile"
74a1d141d5Smrg    exit $stat
75a1d141d5Smrg  fi
76a1d141d5Smrg  mv "$tmpdepfile" "$depfile"
77a1d141d5Smrg  ;;
78a1d141d5Smrg
79a1d141d5Smrggcc)
80a1d141d5Smrg## There are various ways to get dependency output from gcc.  Here's
81a1d141d5Smrg## why we pick this rather obscure method:
82a1d141d5Smrg## - Don't want to use -MD because we'd like the dependencies to end
83a1d141d5Smrg##   up in a subdir.  Having to rename by hand is ugly.
84a1d141d5Smrg##   (We might end up doing this anyway to support other compilers.)
85a1d141d5Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
86a1d141d5Smrg##   -MM, not -M (despite what the docs say).
87a1d141d5Smrg## - Using -M directly means running the compiler twice (even worse
88a1d141d5Smrg##   than renaming).
89a1d141d5Smrg  if test -z "$gccflag"; then
90a1d141d5Smrg    gccflag=-MD,
91a1d141d5Smrg  fi
92a1d141d5Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
93a1d141d5Smrg  stat=$?
94a1d141d5Smrg  if test $stat -eq 0; then :
95a1d141d5Smrg  else
96a1d141d5Smrg    rm -f "$tmpdepfile"
97a1d141d5Smrg    exit $stat
98a1d141d5Smrg  fi
99a1d141d5Smrg  rm -f "$depfile"
100a1d141d5Smrg  echo "$object : \\" > "$depfile"
101a1d141d5Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
102a1d141d5Smrg## The second -e expression handles DOS-style file names with drive letters.
103a1d141d5Smrg  sed -e 's/^[^:]*: / /' \
104a1d141d5Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
105a1d141d5Smrg## This next piece of magic avoids the `deleted header file' problem.
106a1d141d5Smrg## The problem is that when a header file which appears in a .P file
107a1d141d5Smrg## is deleted, the dependency causes make to die (because there is
108a1d141d5Smrg## typically no way to rebuild the header).  We avoid this by adding
109a1d141d5Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
110a1d141d5Smrg## this for us directly.
111a1d141d5Smrg  tr ' ' '
112a1d141d5Smrg' < "$tmpdepfile" |
113a1d141d5Smrg## Some versions of gcc put a space before the `:'.  On the theory
114a1d141d5Smrg## that the space means something, we add a space to the output as
115a1d141d5Smrg## well.
116a1d141d5Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
117a1d141d5Smrg## correctly.  Breaking it into two sed invocations is a workaround.
118a1d141d5Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
119a1d141d5Smrg  rm -f "$tmpdepfile"
120a1d141d5Smrg  ;;
121a1d141d5Smrg
122a1d141d5Smrghp)
123a1d141d5Smrg  # This case exists only to let depend.m4 do its work.  It works by
124a1d141d5Smrg  # looking at the text of this script.  This case will never be run,
125a1d141d5Smrg  # since it is checked for above.
126a1d141d5Smrg  exit 1
127a1d141d5Smrg  ;;
128a1d141d5Smrg
129a1d141d5Smrgsgi)
130a1d141d5Smrg  if test "$libtool" = yes; then
131a1d141d5Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
132a1d141d5Smrg  else
133a1d141d5Smrg    "$@" -MDupdate "$tmpdepfile"
134a1d141d5Smrg  fi
135a1d141d5Smrg  stat=$?
136a1d141d5Smrg  if test $stat -eq 0; then :
137a1d141d5Smrg  else
138a1d141d5Smrg    rm -f "$tmpdepfile"
139a1d141d5Smrg    exit $stat
140a1d141d5Smrg  fi
141a1d141d5Smrg  rm -f "$depfile"
142a1d141d5Smrg
143a1d141d5Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
144a1d141d5Smrg    echo "$object : \\" > "$depfile"
145a1d141d5Smrg
146a1d141d5Smrg    # Clip off the initial element (the dependent).  Don't try to be
147a1d141d5Smrg    # clever and replace this with sed code, as IRIX sed won't handle
148a1d141d5Smrg    # lines with more than a fixed number of characters (4096 in
149a1d141d5Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
150a1d141d5Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
151a1d141d5Smrg    # dependency line.
152a1d141d5Smrg    tr ' ' '
153a1d141d5Smrg' < "$tmpdepfile" \
154a1d141d5Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
155a1d141d5Smrg    tr '
156a1d141d5Smrg' ' ' >> $depfile
157a1d141d5Smrg    echo >> $depfile
158a1d141d5Smrg
159a1d141d5Smrg    # The second pass generates a dummy entry for each header file.
160a1d141d5Smrg    tr ' ' '
161a1d141d5Smrg' < "$tmpdepfile" \
162a1d141d5Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
163a1d141d5Smrg   >> $depfile
164a1d141d5Smrg  else
165a1d141d5Smrg    # The sourcefile does not contain any dependencies, so just
166a1d141d5Smrg    # store a dummy comment line, to avoid errors with the Makefile
167a1d141d5Smrg    # "include basename.Plo" scheme.
168a1d141d5Smrg    echo "#dummy" > "$depfile"
169a1d141d5Smrg  fi
170a1d141d5Smrg  rm -f "$tmpdepfile"
171a1d141d5Smrg  ;;
172a1d141d5Smrg
173a1d141d5Smrgaix)
174a1d141d5Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
175a1d141d5Smrg  # in a .u file.  In older versions, this file always lives in the
176a1d141d5Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
177a1d141d5Smrg  # start of each line; $object doesn't have directory information.
178a1d141d5Smrg  # Version 6 uses the directory in both cases.
179a1d141d5Smrg  stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
180a1d141d5Smrg  tmpdepfile="$stripped.u"
181a1d141d5Smrg  if test "$libtool" = yes; then
182a1d141d5Smrg    "$@" -Wc,-M
183a1d141d5Smrg  else
184a1d141d5Smrg    "$@" -M
185a1d141d5Smrg  fi
186a1d141d5Smrg  stat=$?
187a1d141d5Smrg
188a1d141d5Smrg  if test -f "$tmpdepfile"; then :
189a1d141d5Smrg  else
190a1d141d5Smrg    stripped=`echo "$stripped" | sed 's,^.*/,,'`
191a1d141d5Smrg    tmpdepfile="$stripped.u"
192a1d141d5Smrg  fi
193a1d141d5Smrg
194a1d141d5Smrg  if test $stat -eq 0; then :
195a1d141d5Smrg  else
196a1d141d5Smrg    rm -f "$tmpdepfile"
197a1d141d5Smrg    exit $stat
198a1d141d5Smrg  fi
199a1d141d5Smrg
200a1d141d5Smrg  if test -f "$tmpdepfile"; then
201a1d141d5Smrg    outname="$stripped.o"
202a1d141d5Smrg    # Each line is of the form `foo.o: dependent.h'.
203a1d141d5Smrg    # Do two passes, one to just change these to
204a1d141d5Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
205a1d141d5Smrg    sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
206a1d141d5Smrg    sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
207a1d141d5Smrg  else
208a1d141d5Smrg    # The sourcefile does not contain any dependencies, so just
209a1d141d5Smrg    # store a dummy comment line, to avoid errors with the Makefile
210a1d141d5Smrg    # "include basename.Plo" scheme.
211a1d141d5Smrg    echo "#dummy" > "$depfile"
212a1d141d5Smrg  fi
213a1d141d5Smrg  rm -f "$tmpdepfile"
214a1d141d5Smrg  ;;
215a1d141d5Smrg
216a1d141d5Smrgicc)
217a1d141d5Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
218a1d141d5Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
219a1d141d5Smrg  # ICC 7.0 will fill foo.d with something like
220a1d141d5Smrg  #    foo.o: sub/foo.c
221a1d141d5Smrg  #    foo.o: sub/foo.h
222a1d141d5Smrg  # which is wrong.  We want:
223a1d141d5Smrg  #    sub/foo.o: sub/foo.c
224a1d141d5Smrg  #    sub/foo.o: sub/foo.h
225a1d141d5Smrg  #    sub/foo.c:
226a1d141d5Smrg  #    sub/foo.h:
227a1d141d5Smrg  # ICC 7.1 will output
228a1d141d5Smrg  #    foo.o: sub/foo.c sub/foo.h
229a1d141d5Smrg  # and will wrap long lines using \ :
230a1d141d5Smrg  #    foo.o: sub/foo.c ... \
231a1d141d5Smrg  #     sub/foo.h ... \
232a1d141d5Smrg  #     ...
233a1d141d5Smrg
234a1d141d5Smrg  "$@" -MD -MF "$tmpdepfile"
235a1d141d5Smrg  stat=$?
236a1d141d5Smrg  if test $stat -eq 0; then :
237a1d141d5Smrg  else
238a1d141d5Smrg    rm -f "$tmpdepfile"
239a1d141d5Smrg    exit $stat
240a1d141d5Smrg  fi
241a1d141d5Smrg  rm -f "$depfile"
242a1d141d5Smrg  # Each line is of the form `foo.o: dependent.h',
243a1d141d5Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
244a1d141d5Smrg  # Do two passes, one to just change these to
245a1d141d5Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
246a1d141d5Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
247a1d141d5Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
248a1d141d5Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
249a1d141d5Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
250a1d141d5Smrg    sed -e 's/$/ :/' >> "$depfile"
251a1d141d5Smrg  rm -f "$tmpdepfile"
252a1d141d5Smrg  ;;
253a1d141d5Smrg
254a1d141d5Smrgtru64)
255a1d141d5Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
256a1d141d5Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
257a1d141d5Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
258a1d141d5Smrg   # dependencies in `foo.d' instead, so we check for that too.
259a1d141d5Smrg   # Subdirectories are respected.
260a1d141d5Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
261a1d141d5Smrg   test "x$dir" = "x$object" && dir=
262a1d141d5Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
263a1d141d5Smrg
264a1d141d5Smrg   if test "$libtool" = yes; then
265a1d141d5Smrg      tmpdepfile1="$dir.libs/$base.lo.d"
266a1d141d5Smrg      tmpdepfile2="$dir.libs/$base.d"
267a1d141d5Smrg      "$@" -Wc,-MD
268a1d141d5Smrg   else
269a1d141d5Smrg      tmpdepfile1="$dir$base.o.d"
270a1d141d5Smrg      tmpdepfile2="$dir$base.d"
271a1d141d5Smrg      "$@" -MD
272a1d141d5Smrg   fi
273a1d141d5Smrg
274a1d141d5Smrg   stat=$?
275a1d141d5Smrg   if test $stat -eq 0; then :
276a1d141d5Smrg   else
277a1d141d5Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2"
278a1d141d5Smrg      exit $stat
279a1d141d5Smrg   fi
280a1d141d5Smrg
281a1d141d5Smrg   if test -f "$tmpdepfile1"; then
282a1d141d5Smrg      tmpdepfile="$tmpdepfile1"
283a1d141d5Smrg   else
284a1d141d5Smrg      tmpdepfile="$tmpdepfile2"
285a1d141d5Smrg   fi
286a1d141d5Smrg   if test -f "$tmpdepfile"; then
287a1d141d5Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
288a1d141d5Smrg      # That's a tab and a space in the [].
289a1d141d5Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
290a1d141d5Smrg   else
291a1d141d5Smrg      echo "#dummy" > "$depfile"
292a1d141d5Smrg   fi
293a1d141d5Smrg   rm -f "$tmpdepfile"
294a1d141d5Smrg   ;;
295a1d141d5Smrg
296a1d141d5Smrg#nosideeffect)
297a1d141d5Smrg  # This comment above is used by automake to tell side-effect
298a1d141d5Smrg  # dependency tracking mechanisms from slower ones.
299a1d141d5Smrg
300a1d141d5Smrgdashmstdout)
301a1d141d5Smrg  # Important note: in order to support this mode, a compiler *must*
302a1d141d5Smrg  # always write the preprocessed file to stdout, regardless of -o.
303a1d141d5Smrg  "$@" || exit $?
304a1d141d5Smrg
305a1d141d5Smrg  # Remove the call to Libtool.
306a1d141d5Smrg  if test "$libtool" = yes; then
307a1d141d5Smrg    while test $1 != '--mode=compile'; do
308a1d141d5Smrg      shift
309a1d141d5Smrg    done
310a1d141d5Smrg    shift
311a1d141d5Smrg  fi
312a1d141d5Smrg
313a1d141d5Smrg  # Remove `-o $object'.
314a1d141d5Smrg  IFS=" "
315a1d141d5Smrg  for arg
316a1d141d5Smrg  do
317a1d141d5Smrg    case $arg in
318a1d141d5Smrg    -o)
319a1d141d5Smrg      shift
320a1d141d5Smrg      ;;
321a1d141d5Smrg    $object)
322a1d141d5Smrg      shift
323a1d141d5Smrg      ;;
324a1d141d5Smrg    *)
325a1d141d5Smrg      set fnord "$@" "$arg"
326a1d141d5Smrg      shift # fnord
327a1d141d5Smrg      shift # $arg
328a1d141d5Smrg      ;;
329a1d141d5Smrg    esac
330a1d141d5Smrg  done
331a1d141d5Smrg
332a1d141d5Smrg  test -z "$dashmflag" && dashmflag=-M
333a1d141d5Smrg  # Require at least two characters before searching for `:'
334a1d141d5Smrg  # in the target name.  This is to cope with DOS-style filenames:
335a1d141d5Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
336a1d141d5Smrg  "$@" $dashmflag |
337a1d141d5Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
338a1d141d5Smrg  rm -f "$depfile"
339a1d141d5Smrg  cat < "$tmpdepfile" > "$depfile"
340a1d141d5Smrg  tr ' ' '
341a1d141d5Smrg' < "$tmpdepfile" | \
342a1d141d5Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
343a1d141d5Smrg## correctly.  Breaking it into two sed invocations is a workaround.
344a1d141d5Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
345a1d141d5Smrg  rm -f "$tmpdepfile"
346a1d141d5Smrg  ;;
347a1d141d5Smrg
348a1d141d5SmrgdashXmstdout)
349a1d141d5Smrg  # This case only exists to satisfy depend.m4.  It is never actually
350a1d141d5Smrg  # run, as this mode is specially recognized in the preamble.
351a1d141d5Smrg  exit 1
352a1d141d5Smrg  ;;
353a1d141d5Smrg
354a1d141d5Smrgmakedepend)
355a1d141d5Smrg  "$@" || exit $?
356a1d141d5Smrg  # Remove any Libtool call
357a1d141d5Smrg  if test "$libtool" = yes; then
358a1d141d5Smrg    while test $1 != '--mode=compile'; do
359a1d141d5Smrg      shift
360a1d141d5Smrg    done
361a1d141d5Smrg    shift
362a1d141d5Smrg  fi
363a1d141d5Smrg  # X makedepend
364a1d141d5Smrg  shift
365a1d141d5Smrg  cleared=no
366a1d141d5Smrg  for arg in "$@"; do
367a1d141d5Smrg    case $cleared in
368a1d141d5Smrg    no)
369a1d141d5Smrg      set ""; shift
370a1d141d5Smrg      cleared=yes ;;
371a1d141d5Smrg    esac
372a1d141d5Smrg    case "$arg" in
373a1d141d5Smrg    -D*|-I*)
374a1d141d5Smrg      set fnord "$@" "$arg"; shift ;;
375a1d141d5Smrg    # Strip any option that makedepend may not understand.  Remove
376a1d141d5Smrg    # the object too, otherwise makedepend will parse it as a source file.
377a1d141d5Smrg    -*|$object)
378a1d141d5Smrg      ;;
379a1d141d5Smrg    *)
380a1d141d5Smrg      set fnord "$@" "$arg"; shift ;;
381a1d141d5Smrg    esac
382a1d141d5Smrg  done
383a1d141d5Smrg  obj_suffix="`echo $object | sed 's/^.*\././'`"
384a1d141d5Smrg  touch "$tmpdepfile"
385a1d141d5Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
386a1d141d5Smrg  rm -f "$depfile"
387a1d141d5Smrg  cat < "$tmpdepfile" > "$depfile"
388a1d141d5Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
389a1d141d5Smrg' | \
390a1d141d5Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
391a1d141d5Smrg## correctly.  Breaking it into two sed invocations is a workaround.
392a1d141d5Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
393a1d141d5Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
394a1d141d5Smrg  ;;
395a1d141d5Smrg
396a1d141d5Smrgcpp)
397a1d141d5Smrg  # Important note: in order to support this mode, a compiler *must*
398a1d141d5Smrg  # always write the preprocessed file to stdout.
399a1d141d5Smrg  "$@" || exit $?
400a1d141d5Smrg
401a1d141d5Smrg  # Remove the call to Libtool.
402a1d141d5Smrg  if test "$libtool" = yes; then
403a1d141d5Smrg    while test $1 != '--mode=compile'; do
404a1d141d5Smrg      shift
405a1d141d5Smrg    done
406a1d141d5Smrg    shift
407a1d141d5Smrg  fi
408a1d141d5Smrg
409a1d141d5Smrg  # Remove `-o $object'.
410a1d141d5Smrg  IFS=" "
411a1d141d5Smrg  for arg
412a1d141d5Smrg  do
413a1d141d5Smrg    case $arg in
414a1d141d5Smrg    -o)
415a1d141d5Smrg      shift
416a1d141d5Smrg      ;;
417a1d141d5Smrg    $object)
418a1d141d5Smrg      shift
419a1d141d5Smrg      ;;
420a1d141d5Smrg    *)
421a1d141d5Smrg      set fnord "$@" "$arg"
422a1d141d5Smrg      shift # fnord
423a1d141d5Smrg      shift # $arg
424a1d141d5Smrg      ;;
425a1d141d5Smrg    esac
426a1d141d5Smrg  done
427a1d141d5Smrg
428a1d141d5Smrg  "$@" -E |
429a1d141d5Smrg    sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
430a1d141d5Smrg    sed '$ s: \\$::' > "$tmpdepfile"
431a1d141d5Smrg  rm -f "$depfile"
432a1d141d5Smrg  echo "$object : \\" > "$depfile"
433a1d141d5Smrg  cat < "$tmpdepfile" >> "$depfile"
434a1d141d5Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
435a1d141d5Smrg  rm -f "$tmpdepfile"
436a1d141d5Smrg  ;;
437a1d141d5Smrg
438a1d141d5Smrgmsvisualcpp)
439a1d141d5Smrg  # Important note: in order to support this mode, a compiler *must*
440a1d141d5Smrg  # always write the preprocessed file to stdout, regardless of -o,
441a1d141d5Smrg  # because we must use -o when running libtool.
442a1d141d5Smrg  "$@" || exit $?
443a1d141d5Smrg  IFS=" "
444a1d141d5Smrg  for arg
445a1d141d5Smrg  do
446a1d141d5Smrg    case "$arg" in
447a1d141d5Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
448a1d141d5Smrg	set fnord "$@"
449a1d141d5Smrg	shift
450a1d141d5Smrg	shift
451a1d141d5Smrg	;;
452a1d141d5Smrg    *)
453a1d141d5Smrg	set fnord "$@" "$arg"
454a1d141d5Smrg	shift
455a1d141d5Smrg	shift
456a1d141d5Smrg	;;
457a1d141d5Smrg    esac
458a1d141d5Smrg  done
459a1d141d5Smrg  "$@" -E |
460a1d141d5Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
461a1d141d5Smrg  rm -f "$depfile"
462a1d141d5Smrg  echo "$object : \\" > "$depfile"
463a1d141d5Smrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
464a1d141d5Smrg  echo "	" >> "$depfile"
465a1d141d5Smrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
466a1d141d5Smrg  rm -f "$tmpdepfile"
467a1d141d5Smrg  ;;
468a1d141d5Smrg
469a1d141d5Smrgnone)
470a1d141d5Smrg  exec "$@"
471a1d141d5Smrg  ;;
472a1d141d5Smrg
473a1d141d5Smrg*)
474a1d141d5Smrg  echo "Unknown depmode $depmode" 1>&2
475a1d141d5Smrg  exit 1
476a1d141d5Smrg  ;;
477a1d141d5Smrgesac
478a1d141d5Smrg
479a1d141d5Smrgexit 0
480