1219820Sjeff#! /bin/sh
2219820Sjeff# depcomp - compile a program generating dependencies as side-effects
3219820Sjeff
4219820Sjeffscriptversion=2005-07-09.11
5219820Sjeff
6219820Sjeff# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
7219820Sjeff
8219820Sjeff# This program is free software; you can redistribute it and/or modify
9219820Sjeff# it under the terms of the GNU General Public License as published by
10219820Sjeff# the Free Software Foundation; either version 2, or (at your option)
11219820Sjeff# any later version.
12219820Sjeff
13219820Sjeff# This program is distributed in the hope that it will be useful,
14219820Sjeff# but WITHOUT ANY WARRANTY; without even the implied warranty of
15219820Sjeff# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16219820Sjeff# GNU General Public License for more details.
17219820Sjeff
18219820Sjeff# You should have received a copy of the GNU General Public License
19219820Sjeff# along with this program; if not, write to the Free Software
20219820Sjeff# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21219820Sjeff# 02110-1301, USA.
22219820Sjeff
23219820Sjeff# As a special exception to the GNU General Public License, if you
24219820Sjeff# distribute this file as part of a program that contains a
25219820Sjeff# configuration script generated by Autoconf, you may include it under
26219820Sjeff# the same distribution terms that you use for the rest of that program.
27219820Sjeff
28219820Sjeff# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
29219820Sjeff
30219820Sjeffcase $1 in
31219820Sjeff  '')
32219820Sjeff     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
33219820Sjeff     exit 1;
34219820Sjeff     ;;
35219820Sjeff  -h | --h*)
36219820Sjeff    cat <<\EOF
37219820SjeffUsage: depcomp [--help] [--version] PROGRAM [ARGS]
38219820Sjeff
39219820SjeffRun PROGRAMS ARGS to compile a file, generating dependencies
40219820Sjeffas side-effects.
41219820Sjeff
42219820SjeffEnvironment variables:
43219820Sjeff  depmode     Dependency tracking mode.
44219820Sjeff  source      Source file read by `PROGRAMS ARGS'.
45219820Sjeff  object      Object file output by `PROGRAMS ARGS'.
46219820Sjeff  DEPDIR      directory where to store dependencies.
47219820Sjeff  depfile     Dependency file to output.
48219820Sjeff  tmpdepfile  Temporary file to use when outputing dependencies.
49219820Sjeff  libtool     Whether libtool is used (yes/no).
50219820Sjeff
51219820SjeffReport bugs to <bug-automake@gnu.org>.
52219820SjeffEOF
53219820Sjeff    exit $?
54219820Sjeff    ;;
55219820Sjeff  -v | --v*)
56219820Sjeff    echo "depcomp $scriptversion"
57219820Sjeff    exit $?
58219820Sjeff    ;;
59219820Sjeffesac
60219820Sjeff
61219820Sjeffif test -z "$depmode" || test -z "$source" || test -z "$object"; then
62219820Sjeff  echo "depcomp: Variables source, object and depmode must be set" 1>&2
63219820Sjeff  exit 1
64219820Sjefffi
65219820Sjeff
66219820Sjeff# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
67219820Sjeffdepfile=${depfile-`echo "$object" |
68219820Sjeff  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
69219820Sjefftmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
70219820Sjeff
71219820Sjeffrm -f "$tmpdepfile"
72219820Sjeff
73219820Sjeff# Some modes work just like other modes, but use different flags.  We
74219820Sjeff# parameterize here, but still list the modes in the big case below,
75219820Sjeff# to make depend.m4 easier to write.  Note that we *cannot* use a case
76219820Sjeff# here, because this file can only contain one case statement.
77219820Sjeffif test "$depmode" = hp; then
78219820Sjeff  # HP compiler uses -M and no extra arg.
79219820Sjeff  gccflag=-M
80219820Sjeff  depmode=gcc
81219820Sjefffi
82219820Sjeff
83219820Sjeffif test "$depmode" = dashXmstdout; then
84219820Sjeff   # This is just like dashmstdout with a different argument.
85219820Sjeff   dashmflag=-xM
86219820Sjeff   depmode=dashmstdout
87219820Sjefffi
88219820Sjeff
89219820Sjeffcase "$depmode" in
90219820Sjeffgcc3)
91219820Sjeff## gcc 3 implements dependency tracking that does exactly what
92219820Sjeff## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
93219820Sjeff## it if -MD -MP comes after the -MF stuff.  Hmm.
94219820Sjeff  "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
95219820Sjeff  stat=$?
96219820Sjeff  if test $stat -eq 0; then :
97219820Sjeff  else
98219820Sjeff    rm -f "$tmpdepfile"
99219820Sjeff    exit $stat
100219820Sjeff  fi
101219820Sjeff  mv "$tmpdepfile" "$depfile"
102219820Sjeff  ;;
103219820Sjeff
104219820Sjeffgcc)
105219820Sjeff## There are various ways to get dependency output from gcc.  Here's
106219820Sjeff## why we pick this rather obscure method:
107219820Sjeff## - Don't want to use -MD because we'd like the dependencies to end
108219820Sjeff##   up in a subdir.  Having to rename by hand is ugly.
109219820Sjeff##   (We might end up doing this anyway to support other compilers.)
110219820Sjeff## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
111219820Sjeff##   -MM, not -M (despite what the docs say).
112219820Sjeff## - Using -M directly means running the compiler twice (even worse
113219820Sjeff##   than renaming).
114219820Sjeff  if test -z "$gccflag"; then
115219820Sjeff    gccflag=-MD,
116219820Sjeff  fi
117219820Sjeff  "$@" -Wp,"$gccflag$tmpdepfile"
118219820Sjeff  stat=$?
119219820Sjeff  if test $stat -eq 0; then :
120219820Sjeff  else
121219820Sjeff    rm -f "$tmpdepfile"
122219820Sjeff    exit $stat
123219820Sjeff  fi
124219820Sjeff  rm -f "$depfile"
125219820Sjeff  echo "$object : \\" > "$depfile"
126219820Sjeff  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
127219820Sjeff## The second -e expression handles DOS-style file names with drive letters.
128219820Sjeff  sed -e 's/^[^:]*: / /' \
129219820Sjeff      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
130219820Sjeff## This next piece of magic avoids the `deleted header file' problem.
131219820Sjeff## The problem is that when a header file which appears in a .P file
132219820Sjeff## is deleted, the dependency causes make to die (because there is
133219820Sjeff## typically no way to rebuild the header).  We avoid this by adding
134219820Sjeff## dummy dependencies for each header file.  Too bad gcc doesn't do
135219820Sjeff## this for us directly.
136219820Sjeff  tr ' ' '
137219820Sjeff' < "$tmpdepfile" |
138219820Sjeff## Some versions of gcc put a space before the `:'.  On the theory
139219820Sjeff## that the space means something, we add a space to the output as
140219820Sjeff## well.
141219820Sjeff## Some versions of the HPUX 10.20 sed can't process this invocation
142219820Sjeff## correctly.  Breaking it into two sed invocations is a workaround.
143219820Sjeff    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
144219820Sjeff  rm -f "$tmpdepfile"
145219820Sjeff  ;;
146219820Sjeff
147219820Sjeffhp)
148219820Sjeff  # This case exists only to let depend.m4 do its work.  It works by
149219820Sjeff  # looking at the text of this script.  This case will never be run,
150219820Sjeff  # since it is checked for above.
151219820Sjeff  exit 1
152219820Sjeff  ;;
153219820Sjeff
154219820Sjeffsgi)
155219820Sjeff  if test "$libtool" = yes; then
156219820Sjeff    "$@" "-Wp,-MDupdate,$tmpdepfile"
157219820Sjeff  else
158219820Sjeff    "$@" -MDupdate "$tmpdepfile"
159219820Sjeff  fi
160219820Sjeff  stat=$?
161219820Sjeff  if test $stat -eq 0; then :
162219820Sjeff  else
163219820Sjeff    rm -f "$tmpdepfile"
164219820Sjeff    exit $stat
165219820Sjeff  fi
166219820Sjeff  rm -f "$depfile"
167219820Sjeff
168219820Sjeff  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
169219820Sjeff    echo "$object : \\" > "$depfile"
170219820Sjeff
171219820Sjeff    # Clip off the initial element (the dependent).  Don't try to be
172219820Sjeff    # clever and replace this with sed code, as IRIX sed won't handle
173219820Sjeff    # lines with more than a fixed number of characters (4096 in
174219820Sjeff    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
175219820Sjeff    # the IRIX cc adds comments like `#:fec' to the end of the
176219820Sjeff    # dependency line.
177219820Sjeff    tr ' ' '
178219820Sjeff' < "$tmpdepfile" \
179219820Sjeff    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
180219820Sjeff    tr '
181219820Sjeff' ' ' >> $depfile
182219820Sjeff    echo >> $depfile
183219820Sjeff
184219820Sjeff    # The second pass generates a dummy entry for each header file.
185219820Sjeff    tr ' ' '
186219820Sjeff' < "$tmpdepfile" \
187219820Sjeff   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
188219820Sjeff   >> $depfile
189219820Sjeff  else
190219820Sjeff    # The sourcefile does not contain any dependencies, so just
191219820Sjeff    # store a dummy comment line, to avoid errors with the Makefile
192219820Sjeff    # "include basename.Plo" scheme.
193219820Sjeff    echo "#dummy" > "$depfile"
194219820Sjeff  fi
195219820Sjeff  rm -f "$tmpdepfile"
196219820Sjeff  ;;
197219820Sjeff
198219820Sjeffaix)
199219820Sjeff  # The C for AIX Compiler uses -M and outputs the dependencies
200219820Sjeff  # in a .u file.  In older versions, this file always lives in the
201219820Sjeff  # current directory.  Also, the AIX compiler puts `$object:' at the
202219820Sjeff  # start of each line; $object doesn't have directory information.
203219820Sjeff  # Version 6 uses the directory in both cases.
204219820Sjeff  stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
205219820Sjeff  tmpdepfile="$stripped.u"
206219820Sjeff  if test "$libtool" = yes; then
207219820Sjeff    "$@" -Wc,-M
208219820Sjeff  else
209219820Sjeff    "$@" -M
210219820Sjeff  fi
211219820Sjeff  stat=$?
212219820Sjeff
213219820Sjeff  if test -f "$tmpdepfile"; then :
214219820Sjeff  else
215219820Sjeff    stripped=`echo "$stripped" | sed 's,^.*/,,'`
216219820Sjeff    tmpdepfile="$stripped.u"
217219820Sjeff  fi
218219820Sjeff
219219820Sjeff  if test $stat -eq 0; then :
220219820Sjeff  else
221219820Sjeff    rm -f "$tmpdepfile"
222219820Sjeff    exit $stat
223219820Sjeff  fi
224219820Sjeff
225219820Sjeff  if test -f "$tmpdepfile"; then
226219820Sjeff    outname="$stripped.o"
227219820Sjeff    # Each line is of the form `foo.o: dependent.h'.
228219820Sjeff    # Do two passes, one to just change these to
229219820Sjeff    # `$object: dependent.h' and one to simply `dependent.h:'.
230219820Sjeff    sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
231219820Sjeff    sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
232219820Sjeff  else
233219820Sjeff    # The sourcefile does not contain any dependencies, so just
234219820Sjeff    # store a dummy comment line, to avoid errors with the Makefile
235219820Sjeff    # "include basename.Plo" scheme.
236219820Sjeff    echo "#dummy" > "$depfile"
237219820Sjeff  fi
238219820Sjeff  rm -f "$tmpdepfile"
239219820Sjeff  ;;
240219820Sjeff
241219820Sjefficc)
242219820Sjeff  # Intel's C compiler understands `-MD -MF file'.  However on
243219820Sjeff  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
244219820Sjeff  # ICC 7.0 will fill foo.d with something like
245219820Sjeff  #    foo.o: sub/foo.c
246219820Sjeff  #    foo.o: sub/foo.h
247219820Sjeff  # which is wrong.  We want:
248219820Sjeff  #    sub/foo.o: sub/foo.c
249219820Sjeff  #    sub/foo.o: sub/foo.h
250219820Sjeff  #    sub/foo.c:
251219820Sjeff  #    sub/foo.h:
252219820Sjeff  # ICC 7.1 will output
253219820Sjeff  #    foo.o: sub/foo.c sub/foo.h
254219820Sjeff  # and will wrap long lines using \ :
255219820Sjeff  #    foo.o: sub/foo.c ... \
256219820Sjeff  #     sub/foo.h ... \
257219820Sjeff  #     ...
258219820Sjeff
259219820Sjeff  "$@" -MD -MF "$tmpdepfile"
260219820Sjeff  stat=$?
261219820Sjeff  if test $stat -eq 0; then :
262219820Sjeff  else
263219820Sjeff    rm -f "$tmpdepfile"
264219820Sjeff    exit $stat
265219820Sjeff  fi
266219820Sjeff  rm -f "$depfile"
267219820Sjeff  # Each line is of the form `foo.o: dependent.h',
268219820Sjeff  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
269219820Sjeff  # Do two passes, one to just change these to
270219820Sjeff  # `$object: dependent.h' and one to simply `dependent.h:'.
271219820Sjeff  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
272219820Sjeff  # Some versions of the HPUX 10.20 sed can't process this invocation
273219820Sjeff  # correctly.  Breaking it into two sed invocations is a workaround.
274219820Sjeff  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
275219820Sjeff    sed -e 's/$/ :/' >> "$depfile"
276219820Sjeff  rm -f "$tmpdepfile"
277219820Sjeff  ;;
278219820Sjeff
279219820Sjefftru64)
280219820Sjeff   # The Tru64 compiler uses -MD to generate dependencies as a side
281219820Sjeff   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
282219820Sjeff   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
283219820Sjeff   # dependencies in `foo.d' instead, so we check for that too.
284219820Sjeff   # Subdirectories are respected.
285219820Sjeff   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
286219820Sjeff   test "x$dir" = "x$object" && dir=
287219820Sjeff   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
288219820Sjeff
289219820Sjeff   if test "$libtool" = yes; then
290219820Sjeff      # With Tru64 cc, shared objects can also be used to make a
291219820Sjeff      # static library.  This mecanism is used in libtool 1.4 series to
292219820Sjeff      # handle both shared and static libraries in a single compilation.
293219820Sjeff      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
294219820Sjeff      #
295219820Sjeff      # With libtool 1.5 this exception was removed, and libtool now
296219820Sjeff      # generates 2 separate objects for the 2 libraries.  These two
297219820Sjeff      # compilations output dependencies in in $dir.libs/$base.o.d and
298219820Sjeff      # in $dir$base.o.d.  We have to check for both files, because
299219820Sjeff      # one of the two compilations can be disabled.  We should prefer
300219820Sjeff      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
301219820Sjeff      # automatically cleaned when .libs/ is deleted, while ignoring
302219820Sjeff      # the former would cause a distcleancheck panic.
303219820Sjeff      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
304219820Sjeff      tmpdepfile2=$dir$base.o.d          # libtool 1.5
305219820Sjeff      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
306219820Sjeff      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
307219820Sjeff      "$@" -Wc,-MD
308219820Sjeff   else
309219820Sjeff      tmpdepfile1=$dir$base.o.d
310219820Sjeff      tmpdepfile2=$dir$base.d
311219820Sjeff      tmpdepfile3=$dir$base.d
312219820Sjeff      tmpdepfile4=$dir$base.d
313219820Sjeff      "$@" -MD
314219820Sjeff   fi
315219820Sjeff
316219820Sjeff   stat=$?
317219820Sjeff   if test $stat -eq 0; then :
318219820Sjeff   else
319219820Sjeff      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
320219820Sjeff      exit $stat
321219820Sjeff   fi
322219820Sjeff
323219820Sjeff   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
324219820Sjeff   do
325219820Sjeff     test -f "$tmpdepfile" && break
326219820Sjeff   done
327219820Sjeff   if test -f "$tmpdepfile"; then
328219820Sjeff      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
329219820Sjeff      # That's a tab and a space in the [].
330219820Sjeff      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
331219820Sjeff   else
332219820Sjeff      echo "#dummy" > "$depfile"
333219820Sjeff   fi
334219820Sjeff   rm -f "$tmpdepfile"
335219820Sjeff   ;;
336219820Sjeff
337219820Sjeff#nosideeffect)
338219820Sjeff  # This comment above is used by automake to tell side-effect
339219820Sjeff  # dependency tracking mechanisms from slower ones.
340219820Sjeff
341219820Sjeffdashmstdout)
342219820Sjeff  # Important note: in order to support this mode, a compiler *must*
343219820Sjeff  # always write the preprocessed file to stdout, regardless of -o.
344219820Sjeff  "$@" || exit $?
345219820Sjeff
346219820Sjeff  # Remove the call to Libtool.
347219820Sjeff  if test "$libtool" = yes; then
348219820Sjeff    while test $1 != '--mode=compile'; do
349219820Sjeff      shift
350219820Sjeff    done
351219820Sjeff    shift
352219820Sjeff  fi
353219820Sjeff
354219820Sjeff  # Remove `-o $object'.
355219820Sjeff  IFS=" "
356219820Sjeff  for arg
357219820Sjeff  do
358219820Sjeff    case $arg in
359219820Sjeff    -o)
360219820Sjeff      shift
361219820Sjeff      ;;
362219820Sjeff    $object)
363219820Sjeff      shift
364219820Sjeff      ;;
365219820Sjeff    *)
366219820Sjeff      set fnord "$@" "$arg"
367219820Sjeff      shift # fnord
368219820Sjeff      shift # $arg
369219820Sjeff      ;;
370219820Sjeff    esac
371219820Sjeff  done
372219820Sjeff
373219820Sjeff  test -z "$dashmflag" && dashmflag=-M
374219820Sjeff  # Require at least two characters before searching for `:'
375219820Sjeff  # in the target name.  This is to cope with DOS-style filenames:
376219820Sjeff  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
377219820Sjeff  "$@" $dashmflag |
378219820Sjeff    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
379219820Sjeff  rm -f "$depfile"
380219820Sjeff  cat < "$tmpdepfile" > "$depfile"
381219820Sjeff  tr ' ' '
382219820Sjeff' < "$tmpdepfile" | \
383219820Sjeff## Some versions of the HPUX 10.20 sed can't process this invocation
384219820Sjeff## correctly.  Breaking it into two sed invocations is a workaround.
385219820Sjeff    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
386219820Sjeff  rm -f "$tmpdepfile"
387219820Sjeff  ;;
388219820Sjeff
389219820SjeffdashXmstdout)
390219820Sjeff  # This case only exists to satisfy depend.m4.  It is never actually
391219820Sjeff  # run, as this mode is specially recognized in the preamble.
392219820Sjeff  exit 1
393219820Sjeff  ;;
394219820Sjeff
395219820Sjeffmakedepend)
396219820Sjeff  "$@" || exit $?
397219820Sjeff  # Remove any Libtool call
398219820Sjeff  if test "$libtool" = yes; then
399219820Sjeff    while test $1 != '--mode=compile'; do
400219820Sjeff      shift
401219820Sjeff    done
402219820Sjeff    shift
403219820Sjeff  fi
404219820Sjeff  # X makedepend
405219820Sjeff  shift
406219820Sjeff  cleared=no
407219820Sjeff  for arg in "$@"; do
408219820Sjeff    case $cleared in
409219820Sjeff    no)
410219820Sjeff      set ""; shift
411219820Sjeff      cleared=yes ;;
412219820Sjeff    esac
413219820Sjeff    case "$arg" in
414219820Sjeff    -D*|-I*)
415219820Sjeff      set fnord "$@" "$arg"; shift ;;
416219820Sjeff    # Strip any option that makedepend may not understand.  Remove
417219820Sjeff    # the object too, otherwise makedepend will parse it as a source file.
418219820Sjeff    -*|$object)
419219820Sjeff      ;;
420219820Sjeff    *)
421219820Sjeff      set fnord "$@" "$arg"; shift ;;
422219820Sjeff    esac
423219820Sjeff  done
424219820Sjeff  obj_suffix="`echo $object | sed 's/^.*\././'`"
425219820Sjeff  touch "$tmpdepfile"
426219820Sjeff  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
427219820Sjeff  rm -f "$depfile"
428219820Sjeff  cat < "$tmpdepfile" > "$depfile"
429219820Sjeff  sed '1,2d' "$tmpdepfile" | tr ' ' '
430219820Sjeff' | \
431219820Sjeff## Some versions of the HPUX 10.20 sed can't process this invocation
432219820Sjeff## correctly.  Breaking it into two sed invocations is a workaround.
433219820Sjeff    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
434219820Sjeff  rm -f "$tmpdepfile" "$tmpdepfile".bak
435219820Sjeff  ;;
436219820Sjeff
437219820Sjeffcpp)
438219820Sjeff  # Important note: in order to support this mode, a compiler *must*
439219820Sjeff  # always write the preprocessed file to stdout.
440219820Sjeff  "$@" || exit $?
441219820Sjeff
442219820Sjeff  # Remove the call to Libtool.
443219820Sjeff  if test "$libtool" = yes; then
444219820Sjeff    while test $1 != '--mode=compile'; do
445219820Sjeff      shift
446219820Sjeff    done
447219820Sjeff    shift
448219820Sjeff  fi
449219820Sjeff
450219820Sjeff  # Remove `-o $object'.
451219820Sjeff  IFS=" "
452219820Sjeff  for arg
453219820Sjeff  do
454219820Sjeff    case $arg in
455219820Sjeff    -o)
456219820Sjeff      shift
457219820Sjeff      ;;
458219820Sjeff    $object)
459219820Sjeff      shift
460219820Sjeff      ;;
461219820Sjeff    *)
462219820Sjeff      set fnord "$@" "$arg"
463219820Sjeff      shift # fnord
464219820Sjeff      shift # $arg
465219820Sjeff      ;;
466219820Sjeff    esac
467219820Sjeff  done
468219820Sjeff
469219820Sjeff  "$@" -E |
470219820Sjeff    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
471219820Sjeff       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
472219820Sjeff    sed '$ s: \\$::' > "$tmpdepfile"
473219820Sjeff  rm -f "$depfile"
474219820Sjeff  echo "$object : \\" > "$depfile"
475219820Sjeff  cat < "$tmpdepfile" >> "$depfile"
476219820Sjeff  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
477219820Sjeff  rm -f "$tmpdepfile"
478219820Sjeff  ;;
479219820Sjeff
480219820Sjeffmsvisualcpp)
481219820Sjeff  # Important note: in order to support this mode, a compiler *must*
482219820Sjeff  # always write the preprocessed file to stdout, regardless of -o,
483219820Sjeff  # because we must use -o when running libtool.
484219820Sjeff  "$@" || exit $?
485219820Sjeff  IFS=" "
486219820Sjeff  for arg
487219820Sjeff  do
488219820Sjeff    case "$arg" in
489219820Sjeff    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
490219820Sjeff	set fnord "$@"
491219820Sjeff	shift
492219820Sjeff	shift
493219820Sjeff	;;
494219820Sjeff    *)
495219820Sjeff	set fnord "$@" "$arg"
496219820Sjeff	shift
497219820Sjeff	shift
498219820Sjeff	;;
499219820Sjeff    esac
500219820Sjeff  done
501219820Sjeff  "$@" -E |
502219820Sjeff  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
503219820Sjeff  rm -f "$depfile"
504219820Sjeff  echo "$object : \\" > "$depfile"
505219820Sjeff  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
506219820Sjeff  echo "	" >> "$depfile"
507219820Sjeff  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
508219820Sjeff  rm -f "$tmpdepfile"
509219820Sjeff  ;;
510219820Sjeff
511219820Sjeffnone)
512219820Sjeff  exec "$@"
513219820Sjeff  ;;
514219820Sjeff
515219820Sjeff*)
516219820Sjeff  echo "Unknown depmode $depmode" 1>&2
517219820Sjeff  exit 1
518219820Sjeff  ;;
519219820Sjeffesac
520219820Sjeff
521219820Sjeffexit 0
522219820Sjeff
523219820Sjeff# Local Variables:
524219820Sjeff# mode: shell-script
525219820Sjeff# sh-indentation: 2
526219820Sjeff# eval: (add-hook 'write-file-hooks 'time-stamp)
527219820Sjeff# time-stamp-start: "scriptversion="
528219820Sjeff# time-stamp-format: "%:y-%02m-%02d.%02H"
529219820Sjeff# time-stamp-end: "$"
530219820Sjeff# End:
531