depcomp revision 9b41ff1a
1fdb3d228Smrg#! /bin/sh
2fdb3d228Smrg# depcomp - compile a program generating dependencies as side-effects
39b41ff1aSmrg
49b41ff1aSmrgscriptversion=2009-04-28.21; # UTC
59b41ff1aSmrg
69b41ff1aSmrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
79b41ff1aSmrg# Software Foundation, Inc.
8fdb3d228Smrg
9fdb3d228Smrg# This program is free software; you can redistribute it and/or modify
10fdb3d228Smrg# it under the terms of the GNU General Public License as published by
11fdb3d228Smrg# the Free Software Foundation; either version 2, or (at your option)
12fdb3d228Smrg# any later version.
13fdb3d228Smrg
14fdb3d228Smrg# This program is distributed in the hope that it will be useful,
15fdb3d228Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16fdb3d228Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17fdb3d228Smrg# GNU General Public License for more details.
18fdb3d228Smrg
19fdb3d228Smrg# You should have received a copy of the GNU General Public License
209b41ff1aSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21fdb3d228Smrg
22fdb3d228Smrg# As a special exception to the GNU General Public License, if you
23fdb3d228Smrg# distribute this file as part of a program that contains a
24fdb3d228Smrg# configuration script generated by Autoconf, you may include it under
25fdb3d228Smrg# the same distribution terms that you use for the rest of that program.
26fdb3d228Smrg
27fdb3d228Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
28fdb3d228Smrg
299b41ff1aSmrgcase $1 in
309b41ff1aSmrg  '')
319b41ff1aSmrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
329b41ff1aSmrg     exit 1;
339b41ff1aSmrg     ;;
349b41ff1aSmrg  -h | --h*)
359b41ff1aSmrg    cat <<\EOF
369b41ff1aSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
379b41ff1aSmrg
389b41ff1aSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
399b41ff1aSmrgas side-effects.
409b41ff1aSmrg
419b41ff1aSmrgEnvironment variables:
429b41ff1aSmrg  depmode     Dependency tracking mode.
439b41ff1aSmrg  source      Source file read by `PROGRAMS ARGS'.
449b41ff1aSmrg  object      Object file output by `PROGRAMS ARGS'.
459b41ff1aSmrg  DEPDIR      directory where to store dependencies.
469b41ff1aSmrg  depfile     Dependency file to output.
479b41ff1aSmrg  tmpdepfile  Temporary file to use when outputing dependencies.
489b41ff1aSmrg  libtool     Whether libtool is used (yes/no).
499b41ff1aSmrg
509b41ff1aSmrgReport bugs to <bug-automake@gnu.org>.
519b41ff1aSmrgEOF
529b41ff1aSmrg    exit $?
539b41ff1aSmrg    ;;
549b41ff1aSmrg  -v | --v*)
559b41ff1aSmrg    echo "depcomp $scriptversion"
569b41ff1aSmrg    exit $?
579b41ff1aSmrg    ;;
589b41ff1aSmrgesac
599b41ff1aSmrg
60fdb3d228Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
61fdb3d228Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
62fdb3d228Smrg  exit 1
63fdb3d228Smrgfi
64fdb3d228Smrg
659b41ff1aSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
669b41ff1aSmrgdepfile=${depfile-`echo "$object" |
679b41ff1aSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
68fdb3d228Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
69fdb3d228Smrg
70fdb3d228Smrgrm -f "$tmpdepfile"
71fdb3d228Smrg
72fdb3d228Smrg# Some modes work just like other modes, but use different flags.  We
73fdb3d228Smrg# parameterize here, but still list the modes in the big case below,
74fdb3d228Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
75fdb3d228Smrg# here, because this file can only contain one case statement.
76fdb3d228Smrgif test "$depmode" = hp; then
77fdb3d228Smrg  # HP compiler uses -M and no extra arg.
78fdb3d228Smrg  gccflag=-M
79fdb3d228Smrg  depmode=gcc
80fdb3d228Smrgfi
81fdb3d228Smrg
82fdb3d228Smrgif test "$depmode" = dashXmstdout; then
83fdb3d228Smrg   # This is just like dashmstdout with a different argument.
84fdb3d228Smrg   dashmflag=-xM
85fdb3d228Smrg   depmode=dashmstdout
86fdb3d228Smrgfi
87fdb3d228Smrg
889b41ff1aSmrgcygpath_u="cygpath -u -f -"
899b41ff1aSmrgif test "$depmode" = msvcmsys; then
909b41ff1aSmrg   # This is just like msvisualcpp but w/o cygpath translation.
919b41ff1aSmrg   # Just convert the backslash-escaped backslashes to single forward
929b41ff1aSmrg   # slashes to satisfy depend.m4
939b41ff1aSmrg   cygpath_u="sed s,\\\\\\\\,/,g"
949b41ff1aSmrg   depmode=msvisualcpp
959b41ff1aSmrgfi
969b41ff1aSmrg
97fdb3d228Smrgcase "$depmode" in
98fdb3d228Smrggcc3)
99fdb3d228Smrg## gcc 3 implements dependency tracking that does exactly what
100fdb3d228Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
101fdb3d228Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1029b41ff1aSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1039b41ff1aSmrg## the command line argument order; so add the flags where they
1049b41ff1aSmrg## appear in depend2.am.  Note that the slowdown incurred here
1059b41ff1aSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1069b41ff1aSmrg  for arg
1079b41ff1aSmrg  do
1089b41ff1aSmrg    case $arg in
1099b41ff1aSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1109b41ff1aSmrg    *)  set fnord "$@" "$arg" ;;
1119b41ff1aSmrg    esac
1129b41ff1aSmrg    shift # fnord
1139b41ff1aSmrg    shift # $arg
1149b41ff1aSmrg  done
1159b41ff1aSmrg  "$@"
116fdb3d228Smrg  stat=$?
117fdb3d228Smrg  if test $stat -eq 0; then :
118fdb3d228Smrg  else
119fdb3d228Smrg    rm -f "$tmpdepfile"
120fdb3d228Smrg    exit $stat
121fdb3d228Smrg  fi
122fdb3d228Smrg  mv "$tmpdepfile" "$depfile"
123fdb3d228Smrg  ;;
124fdb3d228Smrg
125fdb3d228Smrggcc)
126fdb3d228Smrg## There are various ways to get dependency output from gcc.  Here's
127fdb3d228Smrg## why we pick this rather obscure method:
128fdb3d228Smrg## - Don't want to use -MD because we'd like the dependencies to end
129fdb3d228Smrg##   up in a subdir.  Having to rename by hand is ugly.
130fdb3d228Smrg##   (We might end up doing this anyway to support other compilers.)
131fdb3d228Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
132fdb3d228Smrg##   -MM, not -M (despite what the docs say).
133fdb3d228Smrg## - Using -M directly means running the compiler twice (even worse
134fdb3d228Smrg##   than renaming).
135fdb3d228Smrg  if test -z "$gccflag"; then
136fdb3d228Smrg    gccflag=-MD,
137fdb3d228Smrg  fi
138fdb3d228Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
139fdb3d228Smrg  stat=$?
140fdb3d228Smrg  if test $stat -eq 0; then :
141fdb3d228Smrg  else
142fdb3d228Smrg    rm -f "$tmpdepfile"
143fdb3d228Smrg    exit $stat
144fdb3d228Smrg  fi
145fdb3d228Smrg  rm -f "$depfile"
146fdb3d228Smrg  echo "$object : \\" > "$depfile"
147fdb3d228Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
148fdb3d228Smrg## The second -e expression handles DOS-style file names with drive letters.
149fdb3d228Smrg  sed -e 's/^[^:]*: / /' \
150fdb3d228Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
151fdb3d228Smrg## This next piece of magic avoids the `deleted header file' problem.
152fdb3d228Smrg## The problem is that when a header file which appears in a .P file
153fdb3d228Smrg## is deleted, the dependency causes make to die (because there is
154fdb3d228Smrg## typically no way to rebuild the header).  We avoid this by adding
155fdb3d228Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
156fdb3d228Smrg## this for us directly.
157fdb3d228Smrg  tr ' ' '
158fdb3d228Smrg' < "$tmpdepfile" |
159fdb3d228Smrg## Some versions of gcc put a space before the `:'.  On the theory
160fdb3d228Smrg## that the space means something, we add a space to the output as
161fdb3d228Smrg## well.
162fdb3d228Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
163fdb3d228Smrg## correctly.  Breaking it into two sed invocations is a workaround.
164fdb3d228Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
165fdb3d228Smrg  rm -f "$tmpdepfile"
166fdb3d228Smrg  ;;
167fdb3d228Smrg
168fdb3d228Smrghp)
169fdb3d228Smrg  # This case exists only to let depend.m4 do its work.  It works by
170fdb3d228Smrg  # looking at the text of this script.  This case will never be run,
171fdb3d228Smrg  # since it is checked for above.
172fdb3d228Smrg  exit 1
173fdb3d228Smrg  ;;
174fdb3d228Smrg
175fdb3d228Smrgsgi)
176fdb3d228Smrg  if test "$libtool" = yes; then
177fdb3d228Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
178fdb3d228Smrg  else
179fdb3d228Smrg    "$@" -MDupdate "$tmpdepfile"
180fdb3d228Smrg  fi
181fdb3d228Smrg  stat=$?
182fdb3d228Smrg  if test $stat -eq 0; then :
183fdb3d228Smrg  else
184fdb3d228Smrg    rm -f "$tmpdepfile"
185fdb3d228Smrg    exit $stat
186fdb3d228Smrg  fi
187fdb3d228Smrg  rm -f "$depfile"
188fdb3d228Smrg
189fdb3d228Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
190fdb3d228Smrg    echo "$object : \\" > "$depfile"
191fdb3d228Smrg
192fdb3d228Smrg    # Clip off the initial element (the dependent).  Don't try to be
193fdb3d228Smrg    # clever and replace this with sed code, as IRIX sed won't handle
194fdb3d228Smrg    # lines with more than a fixed number of characters (4096 in
195fdb3d228Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
196fdb3d228Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
197fdb3d228Smrg    # dependency line.
198fdb3d228Smrg    tr ' ' '
199fdb3d228Smrg' < "$tmpdepfile" \
200fdb3d228Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
201fdb3d228Smrg    tr '
2029b41ff1aSmrg' ' ' >> "$depfile"
2039b41ff1aSmrg    echo >> "$depfile"
204fdb3d228Smrg
205fdb3d228Smrg    # The second pass generates a dummy entry for each header file.
206fdb3d228Smrg    tr ' ' '
207fdb3d228Smrg' < "$tmpdepfile" \
208fdb3d228Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2099b41ff1aSmrg   >> "$depfile"
210fdb3d228Smrg  else
211fdb3d228Smrg    # The sourcefile does not contain any dependencies, so just
212fdb3d228Smrg    # store a dummy comment line, to avoid errors with the Makefile
213fdb3d228Smrg    # "include basename.Plo" scheme.
214fdb3d228Smrg    echo "#dummy" > "$depfile"
215fdb3d228Smrg  fi
216fdb3d228Smrg  rm -f "$tmpdepfile"
217fdb3d228Smrg  ;;
218fdb3d228Smrg
219fdb3d228Smrgaix)
220fdb3d228Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
221fdb3d228Smrg  # in a .u file.  In older versions, this file always lives in the
222fdb3d228Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
223fdb3d228Smrg  # start of each line; $object doesn't have directory information.
224fdb3d228Smrg  # Version 6 uses the directory in both cases.
2259b41ff1aSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
2269b41ff1aSmrg  test "x$dir" = "x$object" && dir=
2279b41ff1aSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
228fdb3d228Smrg  if test "$libtool" = yes; then
2299b41ff1aSmrg    tmpdepfile1=$dir$base.u
2309b41ff1aSmrg    tmpdepfile2=$base.u
2319b41ff1aSmrg    tmpdepfile3=$dir.libs/$base.u
232fdb3d228Smrg    "$@" -Wc,-M
233fdb3d228Smrg  else
2349b41ff1aSmrg    tmpdepfile1=$dir$base.u
2359b41ff1aSmrg    tmpdepfile2=$dir$base.u
2369b41ff1aSmrg    tmpdepfile3=$dir$base.u
237fdb3d228Smrg    "$@" -M
238fdb3d228Smrg  fi
239fdb3d228Smrg  stat=$?
240fdb3d228Smrg
241fdb3d228Smrg  if test $stat -eq 0; then :
242fdb3d228Smrg  else
2439b41ff1aSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
244fdb3d228Smrg    exit $stat
245fdb3d228Smrg  fi
246fdb3d228Smrg
2479b41ff1aSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
2489b41ff1aSmrg  do
2499b41ff1aSmrg    test -f "$tmpdepfile" && break
2509b41ff1aSmrg  done
251fdb3d228Smrg  if test -f "$tmpdepfile"; then
252fdb3d228Smrg    # Each line is of the form `foo.o: dependent.h'.
253fdb3d228Smrg    # Do two passes, one to just change these to
254fdb3d228Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
2559b41ff1aSmrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
2569b41ff1aSmrg    # That's a tab and a space in the [].
2579b41ff1aSmrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
258fdb3d228Smrg  else
259fdb3d228Smrg    # The sourcefile does not contain any dependencies, so just
260fdb3d228Smrg    # store a dummy comment line, to avoid errors with the Makefile
261fdb3d228Smrg    # "include basename.Plo" scheme.
262fdb3d228Smrg    echo "#dummy" > "$depfile"
263fdb3d228Smrg  fi
264fdb3d228Smrg  rm -f "$tmpdepfile"
265fdb3d228Smrg  ;;
266fdb3d228Smrg
267fdb3d228Smrgicc)
268fdb3d228Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
269fdb3d228Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
270fdb3d228Smrg  # ICC 7.0 will fill foo.d with something like
271fdb3d228Smrg  #    foo.o: sub/foo.c
272fdb3d228Smrg  #    foo.o: sub/foo.h
273fdb3d228Smrg  # which is wrong.  We want:
274fdb3d228Smrg  #    sub/foo.o: sub/foo.c
275fdb3d228Smrg  #    sub/foo.o: sub/foo.h
276fdb3d228Smrg  #    sub/foo.c:
277fdb3d228Smrg  #    sub/foo.h:
278fdb3d228Smrg  # ICC 7.1 will output
279fdb3d228Smrg  #    foo.o: sub/foo.c sub/foo.h
280fdb3d228Smrg  # and will wrap long lines using \ :
281fdb3d228Smrg  #    foo.o: sub/foo.c ... \
282fdb3d228Smrg  #     sub/foo.h ... \
283fdb3d228Smrg  #     ...
284fdb3d228Smrg
285fdb3d228Smrg  "$@" -MD -MF "$tmpdepfile"
286fdb3d228Smrg  stat=$?
287fdb3d228Smrg  if test $stat -eq 0; then :
288fdb3d228Smrg  else
289fdb3d228Smrg    rm -f "$tmpdepfile"
290fdb3d228Smrg    exit $stat
291fdb3d228Smrg  fi
292fdb3d228Smrg  rm -f "$depfile"
293fdb3d228Smrg  # Each line is of the form `foo.o: dependent.h',
294fdb3d228Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
295fdb3d228Smrg  # Do two passes, one to just change these to
296fdb3d228Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
297fdb3d228Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
298fdb3d228Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
299fdb3d228Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
300fdb3d228Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
301fdb3d228Smrg    sed -e 's/$/ :/' >> "$depfile"
302fdb3d228Smrg  rm -f "$tmpdepfile"
303fdb3d228Smrg  ;;
304fdb3d228Smrg
3059b41ff1aSmrghp2)
3069b41ff1aSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
3079b41ff1aSmrg  # compilers, which have integrated preprocessors.  The correct option
3089b41ff1aSmrg  # to use with these is +Maked; it writes dependencies to a file named
3099b41ff1aSmrg  # 'foo.d', which lands next to the object file, wherever that
3109b41ff1aSmrg  # happens to be.
3119b41ff1aSmrg  # Much of this is similar to the tru64 case; see comments there.
3129b41ff1aSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
3139b41ff1aSmrg  test "x$dir" = "x$object" && dir=
3149b41ff1aSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
3159b41ff1aSmrg  if test "$libtool" = yes; then
3169b41ff1aSmrg    tmpdepfile1=$dir$base.d
3179b41ff1aSmrg    tmpdepfile2=$dir.libs/$base.d
3189b41ff1aSmrg    "$@" -Wc,+Maked
3199b41ff1aSmrg  else
3209b41ff1aSmrg    tmpdepfile1=$dir$base.d
3219b41ff1aSmrg    tmpdepfile2=$dir$base.d
3229b41ff1aSmrg    "$@" +Maked
3239b41ff1aSmrg  fi
3249b41ff1aSmrg  stat=$?
3259b41ff1aSmrg  if test $stat -eq 0; then :
3269b41ff1aSmrg  else
3279b41ff1aSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
3289b41ff1aSmrg     exit $stat
3299b41ff1aSmrg  fi
3309b41ff1aSmrg
3319b41ff1aSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
3329b41ff1aSmrg  do
3339b41ff1aSmrg    test -f "$tmpdepfile" && break
3349b41ff1aSmrg  done
3359b41ff1aSmrg  if test -f "$tmpdepfile"; then
3369b41ff1aSmrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
3379b41ff1aSmrg    # Add `dependent.h:' lines.
3389b41ff1aSmrg    sed -ne '2,${
3399b41ff1aSmrg	       s/^ *//
3409b41ff1aSmrg	       s/ \\*$//
3419b41ff1aSmrg	       s/$/:/
3429b41ff1aSmrg	       p
3439b41ff1aSmrg	     }' "$tmpdepfile" >> "$depfile"
3449b41ff1aSmrg  else
3459b41ff1aSmrg    echo "#dummy" > "$depfile"
3469b41ff1aSmrg  fi
3479b41ff1aSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
3489b41ff1aSmrg  ;;
3499b41ff1aSmrg
350fdb3d228Smrgtru64)
351fdb3d228Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
352fdb3d228Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
353fdb3d228Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
354fdb3d228Smrg   # dependencies in `foo.d' instead, so we check for that too.
355fdb3d228Smrg   # Subdirectories are respected.
356fdb3d228Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
357fdb3d228Smrg   test "x$dir" = "x$object" && dir=
358fdb3d228Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
359fdb3d228Smrg
360fdb3d228Smrg   if test "$libtool" = yes; then
3619b41ff1aSmrg      # With Tru64 cc, shared objects can also be used to make a
3629b41ff1aSmrg      # static library.  This mechanism is used in libtool 1.4 series to
3639b41ff1aSmrg      # handle both shared and static libraries in a single compilation.
3649b41ff1aSmrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
3659b41ff1aSmrg      #
3669b41ff1aSmrg      # With libtool 1.5 this exception was removed, and libtool now
3679b41ff1aSmrg      # generates 2 separate objects for the 2 libraries.  These two
3689b41ff1aSmrg      # compilations output dependencies in $dir.libs/$base.o.d and
3699b41ff1aSmrg      # in $dir$base.o.d.  We have to check for both files, because
3709b41ff1aSmrg      # one of the two compilations can be disabled.  We should prefer
3719b41ff1aSmrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
3729b41ff1aSmrg      # automatically cleaned when .libs/ is deleted, while ignoring
3739b41ff1aSmrg      # the former would cause a distcleancheck panic.
3749b41ff1aSmrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
3759b41ff1aSmrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
3769b41ff1aSmrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
3779b41ff1aSmrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
378fdb3d228Smrg      "$@" -Wc,-MD
379fdb3d228Smrg   else
3809b41ff1aSmrg      tmpdepfile1=$dir$base.o.d
3819b41ff1aSmrg      tmpdepfile2=$dir$base.d
3829b41ff1aSmrg      tmpdepfile3=$dir$base.d
3839b41ff1aSmrg      tmpdepfile4=$dir$base.d
384fdb3d228Smrg      "$@" -MD
385fdb3d228Smrg   fi
386fdb3d228Smrg
387fdb3d228Smrg   stat=$?
388fdb3d228Smrg   if test $stat -eq 0; then :
389fdb3d228Smrg   else
3909b41ff1aSmrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
391fdb3d228Smrg      exit $stat
392fdb3d228Smrg   fi
393fdb3d228Smrg
3949b41ff1aSmrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
3959b41ff1aSmrg   do
3969b41ff1aSmrg     test -f "$tmpdepfile" && break
3979b41ff1aSmrg   done
398fdb3d228Smrg   if test -f "$tmpdepfile"; then
399fdb3d228Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
400fdb3d228Smrg      # That's a tab and a space in the [].
401fdb3d228Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
402fdb3d228Smrg   else
403fdb3d228Smrg      echo "#dummy" > "$depfile"
404fdb3d228Smrg   fi
405fdb3d228Smrg   rm -f "$tmpdepfile"
406fdb3d228Smrg   ;;
407fdb3d228Smrg
408fdb3d228Smrg#nosideeffect)
409fdb3d228Smrg  # This comment above is used by automake to tell side-effect
410fdb3d228Smrg  # dependency tracking mechanisms from slower ones.
411fdb3d228Smrg
412fdb3d228Smrgdashmstdout)
413fdb3d228Smrg  # Important note: in order to support this mode, a compiler *must*
414fdb3d228Smrg  # always write the preprocessed file to stdout, regardless of -o.
415fdb3d228Smrg  "$@" || exit $?
416fdb3d228Smrg
417fdb3d228Smrg  # Remove the call to Libtool.
418fdb3d228Smrg  if test "$libtool" = yes; then
4199b41ff1aSmrg    while test "X$1" != 'X--mode=compile'; do
420fdb3d228Smrg      shift
421fdb3d228Smrg    done
422fdb3d228Smrg    shift
423fdb3d228Smrg  fi
424fdb3d228Smrg
425fdb3d228Smrg  # Remove `-o $object'.
426fdb3d228Smrg  IFS=" "
427fdb3d228Smrg  for arg
428fdb3d228Smrg  do
429fdb3d228Smrg    case $arg in
430fdb3d228Smrg    -o)
431fdb3d228Smrg      shift
432fdb3d228Smrg      ;;
433fdb3d228Smrg    $object)
434fdb3d228Smrg      shift
435fdb3d228Smrg      ;;
436fdb3d228Smrg    *)
437fdb3d228Smrg      set fnord "$@" "$arg"
438fdb3d228Smrg      shift # fnord
439fdb3d228Smrg      shift # $arg
440fdb3d228Smrg      ;;
441fdb3d228Smrg    esac
442fdb3d228Smrg  done
443fdb3d228Smrg
444fdb3d228Smrg  test -z "$dashmflag" && dashmflag=-M
445fdb3d228Smrg  # Require at least two characters before searching for `:'
446fdb3d228Smrg  # in the target name.  This is to cope with DOS-style filenames:
447fdb3d228Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
448fdb3d228Smrg  "$@" $dashmflag |
449fdb3d228Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
450fdb3d228Smrg  rm -f "$depfile"
451fdb3d228Smrg  cat < "$tmpdepfile" > "$depfile"
452fdb3d228Smrg  tr ' ' '
453fdb3d228Smrg' < "$tmpdepfile" | \
454fdb3d228Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
455fdb3d228Smrg## correctly.  Breaking it into two sed invocations is a workaround.
456fdb3d228Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
457fdb3d228Smrg  rm -f "$tmpdepfile"
458fdb3d228Smrg  ;;
459fdb3d228Smrg
460fdb3d228SmrgdashXmstdout)
461fdb3d228Smrg  # This case only exists to satisfy depend.m4.  It is never actually
462fdb3d228Smrg  # run, as this mode is specially recognized in the preamble.
463fdb3d228Smrg  exit 1
464fdb3d228Smrg  ;;
465fdb3d228Smrg
466fdb3d228Smrgmakedepend)
467fdb3d228Smrg  "$@" || exit $?
468fdb3d228Smrg  # Remove any Libtool call
469fdb3d228Smrg  if test "$libtool" = yes; then
4709b41ff1aSmrg    while test "X$1" != 'X--mode=compile'; do
471fdb3d228Smrg      shift
472fdb3d228Smrg    done
473fdb3d228Smrg    shift
474fdb3d228Smrg  fi
475fdb3d228Smrg  # X makedepend
476fdb3d228Smrg  shift
4779b41ff1aSmrg  cleared=no eat=no
4789b41ff1aSmrg  for arg
4799b41ff1aSmrg  do
480fdb3d228Smrg    case $cleared in
481fdb3d228Smrg    no)
482fdb3d228Smrg      set ""; shift
483fdb3d228Smrg      cleared=yes ;;
484fdb3d228Smrg    esac
4859b41ff1aSmrg    if test $eat = yes; then
4869b41ff1aSmrg      eat=no
4879b41ff1aSmrg      continue
4889b41ff1aSmrg    fi
489fdb3d228Smrg    case "$arg" in
490fdb3d228Smrg    -D*|-I*)
491fdb3d228Smrg      set fnord "$@" "$arg"; shift ;;
492fdb3d228Smrg    # Strip any option that makedepend may not understand.  Remove
493fdb3d228Smrg    # the object too, otherwise makedepend will parse it as a source file.
4949b41ff1aSmrg    -arch)
4959b41ff1aSmrg      eat=yes ;;
496fdb3d228Smrg    -*|$object)
497fdb3d228Smrg      ;;
498fdb3d228Smrg    *)
499fdb3d228Smrg      set fnord "$@" "$arg"; shift ;;
500fdb3d228Smrg    esac
501fdb3d228Smrg  done
5029b41ff1aSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
503fdb3d228Smrg  touch "$tmpdepfile"
504fdb3d228Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
505fdb3d228Smrg  rm -f "$depfile"
506fdb3d228Smrg  cat < "$tmpdepfile" > "$depfile"
507fdb3d228Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
508fdb3d228Smrg' | \
509fdb3d228Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
510fdb3d228Smrg## correctly.  Breaking it into two sed invocations is a workaround.
511fdb3d228Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
512fdb3d228Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
513fdb3d228Smrg  ;;
514fdb3d228Smrg
515fdb3d228Smrgcpp)
516fdb3d228Smrg  # Important note: in order to support this mode, a compiler *must*
517fdb3d228Smrg  # always write the preprocessed file to stdout.
518fdb3d228Smrg  "$@" || exit $?
519fdb3d228Smrg
520fdb3d228Smrg  # Remove the call to Libtool.
521fdb3d228Smrg  if test "$libtool" = yes; then
5229b41ff1aSmrg    while test "X$1" != 'X--mode=compile'; do
523fdb3d228Smrg      shift
524fdb3d228Smrg    done
525fdb3d228Smrg    shift
526fdb3d228Smrg  fi
527fdb3d228Smrg
528fdb3d228Smrg  # Remove `-o $object'.
529fdb3d228Smrg  IFS=" "
530fdb3d228Smrg  for arg
531fdb3d228Smrg  do
532fdb3d228Smrg    case $arg in
533fdb3d228Smrg    -o)
534fdb3d228Smrg      shift
535fdb3d228Smrg      ;;
536fdb3d228Smrg    $object)
537fdb3d228Smrg      shift
538fdb3d228Smrg      ;;
539fdb3d228Smrg    *)
540fdb3d228Smrg      set fnord "$@" "$arg"
541fdb3d228Smrg      shift # fnord
542fdb3d228Smrg      shift # $arg
543fdb3d228Smrg      ;;
544fdb3d228Smrg    esac
545fdb3d228Smrg  done
546fdb3d228Smrg
547fdb3d228Smrg  "$@" -E |
5489b41ff1aSmrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
5499b41ff1aSmrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
550fdb3d228Smrg    sed '$ s: \\$::' > "$tmpdepfile"
551fdb3d228Smrg  rm -f "$depfile"
552fdb3d228Smrg  echo "$object : \\" > "$depfile"
553fdb3d228Smrg  cat < "$tmpdepfile" >> "$depfile"
554fdb3d228Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
555fdb3d228Smrg  rm -f "$tmpdepfile"
556fdb3d228Smrg  ;;
557fdb3d228Smrg
558fdb3d228Smrgmsvisualcpp)
559fdb3d228Smrg  # Important note: in order to support this mode, a compiler *must*
5609b41ff1aSmrg  # always write the preprocessed file to stdout.
561fdb3d228Smrg  "$@" || exit $?
5629b41ff1aSmrg
5639b41ff1aSmrg  # Remove the call to Libtool.
5649b41ff1aSmrg  if test "$libtool" = yes; then
5659b41ff1aSmrg    while test "X$1" != 'X--mode=compile'; do
5669b41ff1aSmrg      shift
5679b41ff1aSmrg    done
5689b41ff1aSmrg    shift
5699b41ff1aSmrg  fi
5709b41ff1aSmrg
571fdb3d228Smrg  IFS=" "
572fdb3d228Smrg  for arg
573fdb3d228Smrg  do
574fdb3d228Smrg    case "$arg" in
5759b41ff1aSmrg    -o)
5769b41ff1aSmrg      shift
5779b41ff1aSmrg      ;;
5789b41ff1aSmrg    $object)
5799b41ff1aSmrg      shift
5809b41ff1aSmrg      ;;
581fdb3d228Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
582fdb3d228Smrg	set fnord "$@"
583fdb3d228Smrg	shift
584fdb3d228Smrg	shift
585fdb3d228Smrg	;;
586fdb3d228Smrg    *)
587fdb3d228Smrg	set fnord "$@" "$arg"
588fdb3d228Smrg	shift
589fdb3d228Smrg	shift
590fdb3d228Smrg	;;
591fdb3d228Smrg    esac
592fdb3d228Smrg  done
5939b41ff1aSmrg  "$@" -E 2>/dev/null |
5949b41ff1aSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
595fdb3d228Smrg  rm -f "$depfile"
596fdb3d228Smrg  echo "$object : \\" > "$depfile"
5979b41ff1aSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
598fdb3d228Smrg  echo "	" >> "$depfile"
5999b41ff1aSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
600fdb3d228Smrg  rm -f "$tmpdepfile"
601fdb3d228Smrg  ;;
602fdb3d228Smrg
6039b41ff1aSmrgmsvcmsys)
6049b41ff1aSmrg  # This case exists only to let depend.m4 do its work.  It works by
6059b41ff1aSmrg  # looking at the text of this script.  This case will never be run,
6069b41ff1aSmrg  # since it is checked for above.
6079b41ff1aSmrg  exit 1
6089b41ff1aSmrg  ;;
6099b41ff1aSmrg
610fdb3d228Smrgnone)
611fdb3d228Smrg  exec "$@"
612fdb3d228Smrg  ;;
613fdb3d228Smrg
614fdb3d228Smrg*)
615fdb3d228Smrg  echo "Unknown depmode $depmode" 1>&2
616fdb3d228Smrg  exit 1
617fdb3d228Smrg  ;;
618fdb3d228Smrgesac
619fdb3d228Smrg
620fdb3d228Smrgexit 0
6219b41ff1aSmrg
6229b41ff1aSmrg# Local Variables:
6239b41ff1aSmrg# mode: shell-script
6249b41ff1aSmrg# sh-indentation: 2
6259b41ff1aSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
6269b41ff1aSmrg# time-stamp-start: "scriptversion="
6279b41ff1aSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
6289b41ff1aSmrg# time-stamp-time-zone: "UTC"
6299b41ff1aSmrg# time-stamp-end: "; # UTC"
6309b41ff1aSmrg# End:
631