1d9c7fc6cSmrg#! /bin/sh
2d9c7fc6cSmrg# depcomp - compile a program generating dependencies as side-effects
3d9c7fc6cSmrg
405a1a286Smrgscriptversion=2009-04-28.21; # UTC
5d9c7fc6cSmrg
605a1a286Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
705a1a286Smrg# Software Foundation, Inc.
8d9c7fc6cSmrg
9d9c7fc6cSmrg# This program is free software; you can redistribute it and/or modify
10d9c7fc6cSmrg# it under the terms of the GNU General Public License as published by
11d9c7fc6cSmrg# the Free Software Foundation; either version 2, or (at your option)
12d9c7fc6cSmrg# any later version.
13d9c7fc6cSmrg
14d9c7fc6cSmrg# This program is distributed in the hope that it will be useful,
15d9c7fc6cSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16d9c7fc6cSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17d9c7fc6cSmrg# GNU General Public License for more details.
18d9c7fc6cSmrg
19d9c7fc6cSmrg# You should have received a copy of the GNU General Public License
2005a1a286Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21d9c7fc6cSmrg
22d9c7fc6cSmrg# As a special exception to the GNU General Public License, if you
23d9c7fc6cSmrg# distribute this file as part of a program that contains a
24d9c7fc6cSmrg# configuration script generated by Autoconf, you may include it under
25d9c7fc6cSmrg# the same distribution terms that you use for the rest of that program.
26d9c7fc6cSmrg
27d9c7fc6cSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
28d9c7fc6cSmrg
29d9c7fc6cSmrgcase $1 in
30d9c7fc6cSmrg  '')
31d9c7fc6cSmrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
32d9c7fc6cSmrg     exit 1;
33d9c7fc6cSmrg     ;;
34d9c7fc6cSmrg  -h | --h*)
35d9c7fc6cSmrg    cat <<\EOF
36d9c7fc6cSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
37d9c7fc6cSmrg
38d9c7fc6cSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
39d9c7fc6cSmrgas side-effects.
40d9c7fc6cSmrg
41d9c7fc6cSmrgEnvironment variables:
42d9c7fc6cSmrg  depmode     Dependency tracking mode.
43d9c7fc6cSmrg  source      Source file read by `PROGRAMS ARGS'.
44d9c7fc6cSmrg  object      Object file output by `PROGRAMS ARGS'.
45d9c7fc6cSmrg  DEPDIR      directory where to store dependencies.
46d9c7fc6cSmrg  depfile     Dependency file to output.
47d9c7fc6cSmrg  tmpdepfile  Temporary file to use when outputing dependencies.
48d9c7fc6cSmrg  libtool     Whether libtool is used (yes/no).
49d9c7fc6cSmrg
50d9c7fc6cSmrgReport bugs to <bug-automake@gnu.org>.
51d9c7fc6cSmrgEOF
52d9c7fc6cSmrg    exit $?
53d9c7fc6cSmrg    ;;
54d9c7fc6cSmrg  -v | --v*)
55d9c7fc6cSmrg    echo "depcomp $scriptversion"
56d9c7fc6cSmrg    exit $?
57d9c7fc6cSmrg    ;;
58d9c7fc6cSmrgesac
59d9c7fc6cSmrg
60d9c7fc6cSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
61d9c7fc6cSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
62d9c7fc6cSmrg  exit 1
63d9c7fc6cSmrgfi
64d9c7fc6cSmrg
65d9c7fc6cSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
66d9c7fc6cSmrgdepfile=${depfile-`echo "$object" |
67d9c7fc6cSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
68d9c7fc6cSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
69d9c7fc6cSmrg
70d9c7fc6cSmrgrm -f "$tmpdepfile"
71d9c7fc6cSmrg
72d9c7fc6cSmrg# Some modes work just like other modes, but use different flags.  We
73d9c7fc6cSmrg# parameterize here, but still list the modes in the big case below,
74d9c7fc6cSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
75d9c7fc6cSmrg# here, because this file can only contain one case statement.
76d9c7fc6cSmrgif test "$depmode" = hp; then
77d9c7fc6cSmrg  # HP compiler uses -M and no extra arg.
78d9c7fc6cSmrg  gccflag=-M
79d9c7fc6cSmrg  depmode=gcc
80d9c7fc6cSmrgfi
81d9c7fc6cSmrg
82d9c7fc6cSmrgif test "$depmode" = dashXmstdout; then
83d9c7fc6cSmrg   # This is just like dashmstdout with a different argument.
84d9c7fc6cSmrg   dashmflag=-xM
85d9c7fc6cSmrg   depmode=dashmstdout
86d9c7fc6cSmrgfi
87d9c7fc6cSmrg
8805a1a286Smrgcygpath_u="cygpath -u -f -"
8905a1a286Smrgif test "$depmode" = msvcmsys; then
9005a1a286Smrg   # This is just like msvisualcpp but w/o cygpath translation.
9105a1a286Smrg   # Just convert the backslash-escaped backslashes to single forward
9205a1a286Smrg   # slashes to satisfy depend.m4
9305a1a286Smrg   cygpath_u="sed s,\\\\\\\\,/,g"
9405a1a286Smrg   depmode=msvisualcpp
9505a1a286Smrgfi
9605a1a286Smrg
97d9c7fc6cSmrgcase "$depmode" in
98d9c7fc6cSmrggcc3)
99d9c7fc6cSmrg## gcc 3 implements dependency tracking that does exactly what
100d9c7fc6cSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
101d9c7fc6cSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
10205a1a286Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
10305a1a286Smrg## the command line argument order; so add the flags where they
10405a1a286Smrg## appear in depend2.am.  Note that the slowdown incurred here
10505a1a286Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
10605a1a286Smrg  for arg
10705a1a286Smrg  do
10805a1a286Smrg    case $arg in
10905a1a286Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
11005a1a286Smrg    *)  set fnord "$@" "$arg" ;;
11105a1a286Smrg    esac
11205a1a286Smrg    shift # fnord
11305a1a286Smrg    shift # $arg
11405a1a286Smrg  done
11505a1a286Smrg  "$@"
116d9c7fc6cSmrg  stat=$?
117d9c7fc6cSmrg  if test $stat -eq 0; then :
118d9c7fc6cSmrg  else
119d9c7fc6cSmrg    rm -f "$tmpdepfile"
120d9c7fc6cSmrg    exit $stat
121d9c7fc6cSmrg  fi
122d9c7fc6cSmrg  mv "$tmpdepfile" "$depfile"
123d9c7fc6cSmrg  ;;
124d9c7fc6cSmrg
125d9c7fc6cSmrggcc)
126d9c7fc6cSmrg## There are various ways to get dependency output from gcc.  Here's
127d9c7fc6cSmrg## why we pick this rather obscure method:
128d9c7fc6cSmrg## - Don't want to use -MD because we'd like the dependencies to end
129d9c7fc6cSmrg##   up in a subdir.  Having to rename by hand is ugly.
130d9c7fc6cSmrg##   (We might end up doing this anyway to support other compilers.)
131d9c7fc6cSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
132d9c7fc6cSmrg##   -MM, not -M (despite what the docs say).
133d9c7fc6cSmrg## - Using -M directly means running the compiler twice (even worse
134d9c7fc6cSmrg##   than renaming).
135d9c7fc6cSmrg  if test -z "$gccflag"; then
136d9c7fc6cSmrg    gccflag=-MD,
137d9c7fc6cSmrg  fi
138d9c7fc6cSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
139d9c7fc6cSmrg  stat=$?
140d9c7fc6cSmrg  if test $stat -eq 0; then :
141d9c7fc6cSmrg  else
142d9c7fc6cSmrg    rm -f "$tmpdepfile"
143d9c7fc6cSmrg    exit $stat
144d9c7fc6cSmrg  fi
145d9c7fc6cSmrg  rm -f "$depfile"
146d9c7fc6cSmrg  echo "$object : \\" > "$depfile"
147d9c7fc6cSmrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
148d9c7fc6cSmrg## The second -e expression handles DOS-style file names with drive letters.
149d9c7fc6cSmrg  sed -e 's/^[^:]*: / /' \
150d9c7fc6cSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
151d9c7fc6cSmrg## This next piece of magic avoids the `deleted header file' problem.
152d9c7fc6cSmrg## The problem is that when a header file which appears in a .P file
153d9c7fc6cSmrg## is deleted, the dependency causes make to die (because there is
154d9c7fc6cSmrg## typically no way to rebuild the header).  We avoid this by adding
155d9c7fc6cSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
156d9c7fc6cSmrg## this for us directly.
157d9c7fc6cSmrg  tr ' ' '
158d9c7fc6cSmrg' < "$tmpdepfile" |
159d9c7fc6cSmrg## Some versions of gcc put a space before the `:'.  On the theory
160d9c7fc6cSmrg## that the space means something, we add a space to the output as
161d9c7fc6cSmrg## well.
162d9c7fc6cSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
163d9c7fc6cSmrg## correctly.  Breaking it into two sed invocations is a workaround.
164d9c7fc6cSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
165d9c7fc6cSmrg  rm -f "$tmpdepfile"
166d9c7fc6cSmrg  ;;
167d9c7fc6cSmrg
168d9c7fc6cSmrghp)
169d9c7fc6cSmrg  # This case exists only to let depend.m4 do its work.  It works by
170d9c7fc6cSmrg  # looking at the text of this script.  This case will never be run,
171d9c7fc6cSmrg  # since it is checked for above.
172d9c7fc6cSmrg  exit 1
173d9c7fc6cSmrg  ;;
174d9c7fc6cSmrg
175d9c7fc6cSmrgsgi)
176d9c7fc6cSmrg  if test "$libtool" = yes; then
177d9c7fc6cSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
178d9c7fc6cSmrg  else
179d9c7fc6cSmrg    "$@" -MDupdate "$tmpdepfile"
180d9c7fc6cSmrg  fi
181d9c7fc6cSmrg  stat=$?
182d9c7fc6cSmrg  if test $stat -eq 0; then :
183d9c7fc6cSmrg  else
184d9c7fc6cSmrg    rm -f "$tmpdepfile"
185d9c7fc6cSmrg    exit $stat
186d9c7fc6cSmrg  fi
187d9c7fc6cSmrg  rm -f "$depfile"
188d9c7fc6cSmrg
189d9c7fc6cSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
190d9c7fc6cSmrg    echo "$object : \\" > "$depfile"
191d9c7fc6cSmrg
192d9c7fc6cSmrg    # Clip off the initial element (the dependent).  Don't try to be
193d9c7fc6cSmrg    # clever and replace this with sed code, as IRIX sed won't handle
194d9c7fc6cSmrg    # lines with more than a fixed number of characters (4096 in
195d9c7fc6cSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
196d9c7fc6cSmrg    # the IRIX cc adds comments like `#:fec' to the end of the
197d9c7fc6cSmrg    # dependency line.
198d9c7fc6cSmrg    tr ' ' '
199d9c7fc6cSmrg' < "$tmpdepfile" \
200d9c7fc6cSmrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
201d9c7fc6cSmrg    tr '
20205a1a286Smrg' ' ' >> "$depfile"
20305a1a286Smrg    echo >> "$depfile"
204d9c7fc6cSmrg
205d9c7fc6cSmrg    # The second pass generates a dummy entry for each header file.
206d9c7fc6cSmrg    tr ' ' '
207d9c7fc6cSmrg' < "$tmpdepfile" \
208d9c7fc6cSmrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
20905a1a286Smrg   >> "$depfile"
210d9c7fc6cSmrg  else
211d9c7fc6cSmrg    # The sourcefile does not contain any dependencies, so just
212d9c7fc6cSmrg    # store a dummy comment line, to avoid errors with the Makefile
213d9c7fc6cSmrg    # "include basename.Plo" scheme.
214d9c7fc6cSmrg    echo "#dummy" > "$depfile"
215d9c7fc6cSmrg  fi
216d9c7fc6cSmrg  rm -f "$tmpdepfile"
217d9c7fc6cSmrg  ;;
218d9c7fc6cSmrg
219d9c7fc6cSmrgaix)
220d9c7fc6cSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
221d9c7fc6cSmrg  # in a .u file.  In older versions, this file always lives in the
222d9c7fc6cSmrg  # current directory.  Also, the AIX compiler puts `$object:' at the
223d9c7fc6cSmrg  # start of each line; $object doesn't have directory information.
224d9c7fc6cSmrg  # Version 6 uses the directory in both cases.
22505a1a286Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
22605a1a286Smrg  test "x$dir" = "x$object" && dir=
22705a1a286Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
228d9c7fc6cSmrg  if test "$libtool" = yes; then
22905a1a286Smrg    tmpdepfile1=$dir$base.u
23005a1a286Smrg    tmpdepfile2=$base.u
23105a1a286Smrg    tmpdepfile3=$dir.libs/$base.u
232d9c7fc6cSmrg    "$@" -Wc,-M
233d9c7fc6cSmrg  else
23405a1a286Smrg    tmpdepfile1=$dir$base.u
23505a1a286Smrg    tmpdepfile2=$dir$base.u
23605a1a286Smrg    tmpdepfile3=$dir$base.u
237d9c7fc6cSmrg    "$@" -M
238d9c7fc6cSmrg  fi
239d9c7fc6cSmrg  stat=$?
240d9c7fc6cSmrg
241d9c7fc6cSmrg  if test $stat -eq 0; then :
242d9c7fc6cSmrg  else
24305a1a286Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
244d9c7fc6cSmrg    exit $stat
245d9c7fc6cSmrg  fi
246d9c7fc6cSmrg
24705a1a286Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
24805a1a286Smrg  do
24905a1a286Smrg    test -f "$tmpdepfile" && break
25005a1a286Smrg  done
251d9c7fc6cSmrg  if test -f "$tmpdepfile"; then
252d9c7fc6cSmrg    # Each line is of the form `foo.o: dependent.h'.
253d9c7fc6cSmrg    # Do two passes, one to just change these to
254d9c7fc6cSmrg    # `$object: dependent.h' and one to simply `dependent.h:'.
25505a1a286Smrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
25605a1a286Smrg    # That's a tab and a space in the [].
25705a1a286Smrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
258d9c7fc6cSmrg  else
259d9c7fc6cSmrg    # The sourcefile does not contain any dependencies, so just
260d9c7fc6cSmrg    # store a dummy comment line, to avoid errors with the Makefile
261d9c7fc6cSmrg    # "include basename.Plo" scheme.
262d9c7fc6cSmrg    echo "#dummy" > "$depfile"
263d9c7fc6cSmrg  fi
264d9c7fc6cSmrg  rm -f "$tmpdepfile"
265d9c7fc6cSmrg  ;;
266d9c7fc6cSmrg
267d9c7fc6cSmrgicc)
268d9c7fc6cSmrg  # Intel's C compiler understands `-MD -MF file'.  However on
269d9c7fc6cSmrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
270d9c7fc6cSmrg  # ICC 7.0 will fill foo.d with something like
271d9c7fc6cSmrg  #    foo.o: sub/foo.c
272d9c7fc6cSmrg  #    foo.o: sub/foo.h
273d9c7fc6cSmrg  # which is wrong.  We want:
274d9c7fc6cSmrg  #    sub/foo.o: sub/foo.c
275d9c7fc6cSmrg  #    sub/foo.o: sub/foo.h
276d9c7fc6cSmrg  #    sub/foo.c:
277d9c7fc6cSmrg  #    sub/foo.h:
278d9c7fc6cSmrg  # ICC 7.1 will output
279d9c7fc6cSmrg  #    foo.o: sub/foo.c sub/foo.h
280d9c7fc6cSmrg  # and will wrap long lines using \ :
281d9c7fc6cSmrg  #    foo.o: sub/foo.c ... \
282d9c7fc6cSmrg  #     sub/foo.h ... \
283d9c7fc6cSmrg  #     ...
284d9c7fc6cSmrg
285d9c7fc6cSmrg  "$@" -MD -MF "$tmpdepfile"
286d9c7fc6cSmrg  stat=$?
287d9c7fc6cSmrg  if test $stat -eq 0; then :
288d9c7fc6cSmrg  else
289d9c7fc6cSmrg    rm -f "$tmpdepfile"
290d9c7fc6cSmrg    exit $stat
291d9c7fc6cSmrg  fi
292d9c7fc6cSmrg  rm -f "$depfile"
293d9c7fc6cSmrg  # Each line is of the form `foo.o: dependent.h',
294d9c7fc6cSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
295d9c7fc6cSmrg  # Do two passes, one to just change these to
296d9c7fc6cSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
297d9c7fc6cSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
298d9c7fc6cSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
299d9c7fc6cSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
300d9c7fc6cSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
301d9c7fc6cSmrg    sed -e 's/$/ :/' >> "$depfile"
302d9c7fc6cSmrg  rm -f "$tmpdepfile"
303d9c7fc6cSmrg  ;;
304d9c7fc6cSmrg
30505a1a286Smrghp2)
30605a1a286Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
30705a1a286Smrg  # compilers, which have integrated preprocessors.  The correct option
30805a1a286Smrg  # to use with these is +Maked; it writes dependencies to a file named
30905a1a286Smrg  # 'foo.d', which lands next to the object file, wherever that
31005a1a286Smrg  # happens to be.
31105a1a286Smrg  # Much of this is similar to the tru64 case; see comments there.
31205a1a286Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
31305a1a286Smrg  test "x$dir" = "x$object" && dir=
31405a1a286Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
31505a1a286Smrg  if test "$libtool" = yes; then
31605a1a286Smrg    tmpdepfile1=$dir$base.d
31705a1a286Smrg    tmpdepfile2=$dir.libs/$base.d
31805a1a286Smrg    "$@" -Wc,+Maked
31905a1a286Smrg  else
32005a1a286Smrg    tmpdepfile1=$dir$base.d
32105a1a286Smrg    tmpdepfile2=$dir$base.d
32205a1a286Smrg    "$@" +Maked
32305a1a286Smrg  fi
32405a1a286Smrg  stat=$?
32505a1a286Smrg  if test $stat -eq 0; then :
32605a1a286Smrg  else
32705a1a286Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
32805a1a286Smrg     exit $stat
32905a1a286Smrg  fi
33005a1a286Smrg
33105a1a286Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
33205a1a286Smrg  do
33305a1a286Smrg    test -f "$tmpdepfile" && break
33405a1a286Smrg  done
33505a1a286Smrg  if test -f "$tmpdepfile"; then
33605a1a286Smrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
33705a1a286Smrg    # Add `dependent.h:' lines.
33805a1a286Smrg    sed -ne '2,${
33905a1a286Smrg	       s/^ *//
34005a1a286Smrg	       s/ \\*$//
34105a1a286Smrg	       s/$/:/
34205a1a286Smrg	       p
34305a1a286Smrg	     }' "$tmpdepfile" >> "$depfile"
34405a1a286Smrg  else
34505a1a286Smrg    echo "#dummy" > "$depfile"
34605a1a286Smrg  fi
34705a1a286Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
34805a1a286Smrg  ;;
34905a1a286Smrg
350d9c7fc6cSmrgtru64)
351d9c7fc6cSmrg   # The Tru64 compiler uses -MD to generate dependencies as a side
352d9c7fc6cSmrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
353d9c7fc6cSmrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
354d9c7fc6cSmrg   # dependencies in `foo.d' instead, so we check for that too.
355d9c7fc6cSmrg   # Subdirectories are respected.
356d9c7fc6cSmrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
357d9c7fc6cSmrg   test "x$dir" = "x$object" && dir=
358d9c7fc6cSmrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
359d9c7fc6cSmrg
360d9c7fc6cSmrg   if test "$libtool" = yes; then
361d9c7fc6cSmrg      # With Tru64 cc, shared objects can also be used to make a
36205a1a286Smrg      # static library.  This mechanism is used in libtool 1.4 series to
363d9c7fc6cSmrg      # handle both shared and static libraries in a single compilation.
364d9c7fc6cSmrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
365d9c7fc6cSmrg      #
366d9c7fc6cSmrg      # With libtool 1.5 this exception was removed, and libtool now
367d9c7fc6cSmrg      # generates 2 separate objects for the 2 libraries.  These two
36805a1a286Smrg      # compilations output dependencies in $dir.libs/$base.o.d and
369d9c7fc6cSmrg      # in $dir$base.o.d.  We have to check for both files, because
370d9c7fc6cSmrg      # one of the two compilations can be disabled.  We should prefer
371d9c7fc6cSmrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
372d9c7fc6cSmrg      # automatically cleaned when .libs/ is deleted, while ignoring
373d9c7fc6cSmrg      # the former would cause a distcleancheck panic.
374d9c7fc6cSmrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
375d9c7fc6cSmrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
376d9c7fc6cSmrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
377d9c7fc6cSmrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
378d9c7fc6cSmrg      "$@" -Wc,-MD
379d9c7fc6cSmrg   else
380d9c7fc6cSmrg      tmpdepfile1=$dir$base.o.d
381d9c7fc6cSmrg      tmpdepfile2=$dir$base.d
382d9c7fc6cSmrg      tmpdepfile3=$dir$base.d
383d9c7fc6cSmrg      tmpdepfile4=$dir$base.d
384d9c7fc6cSmrg      "$@" -MD
385d9c7fc6cSmrg   fi
386d9c7fc6cSmrg
387d9c7fc6cSmrg   stat=$?
388d9c7fc6cSmrg   if test $stat -eq 0; then :
389d9c7fc6cSmrg   else
390d9c7fc6cSmrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
391d9c7fc6cSmrg      exit $stat
392d9c7fc6cSmrg   fi
393d9c7fc6cSmrg
394d9c7fc6cSmrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
395d9c7fc6cSmrg   do
396d9c7fc6cSmrg     test -f "$tmpdepfile" && break
397d9c7fc6cSmrg   done
398d9c7fc6cSmrg   if test -f "$tmpdepfile"; then
399d9c7fc6cSmrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
400d9c7fc6cSmrg      # That's a tab and a space in the [].
401d9c7fc6cSmrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
402d9c7fc6cSmrg   else
403d9c7fc6cSmrg      echo "#dummy" > "$depfile"
404d9c7fc6cSmrg   fi
405d9c7fc6cSmrg   rm -f "$tmpdepfile"
406d9c7fc6cSmrg   ;;
407d9c7fc6cSmrg
408d9c7fc6cSmrg#nosideeffect)
409d9c7fc6cSmrg  # This comment above is used by automake to tell side-effect
410d9c7fc6cSmrg  # dependency tracking mechanisms from slower ones.
411d9c7fc6cSmrg
412d9c7fc6cSmrgdashmstdout)
413d9c7fc6cSmrg  # Important note: in order to support this mode, a compiler *must*
414d9c7fc6cSmrg  # always write the preprocessed file to stdout, regardless of -o.
415d9c7fc6cSmrg  "$@" || exit $?
416d9c7fc6cSmrg
417d9c7fc6cSmrg  # Remove the call to Libtool.
418d9c7fc6cSmrg  if test "$libtool" = yes; then
41905a1a286Smrg    while test "X$1" != 'X--mode=compile'; do
420d9c7fc6cSmrg      shift
421d9c7fc6cSmrg    done
422d9c7fc6cSmrg    shift
423d9c7fc6cSmrg  fi
424d9c7fc6cSmrg
425d9c7fc6cSmrg  # Remove `-o $object'.
426d9c7fc6cSmrg  IFS=" "
427d9c7fc6cSmrg  for arg
428d9c7fc6cSmrg  do
429d9c7fc6cSmrg    case $arg in
430d9c7fc6cSmrg    -o)
431d9c7fc6cSmrg      shift
432d9c7fc6cSmrg      ;;
433d9c7fc6cSmrg    $object)
434d9c7fc6cSmrg      shift
435d9c7fc6cSmrg      ;;
436d9c7fc6cSmrg    *)
437d9c7fc6cSmrg      set fnord "$@" "$arg"
438d9c7fc6cSmrg      shift # fnord
439d9c7fc6cSmrg      shift # $arg
440d9c7fc6cSmrg      ;;
441d9c7fc6cSmrg    esac
442d9c7fc6cSmrg  done
443d9c7fc6cSmrg
444d9c7fc6cSmrg  test -z "$dashmflag" && dashmflag=-M
445d9c7fc6cSmrg  # Require at least two characters before searching for `:'
446d9c7fc6cSmrg  # in the target name.  This is to cope with DOS-style filenames:
447d9c7fc6cSmrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
448d9c7fc6cSmrg  "$@" $dashmflag |
449d9c7fc6cSmrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
450d9c7fc6cSmrg  rm -f "$depfile"
451d9c7fc6cSmrg  cat < "$tmpdepfile" > "$depfile"
452d9c7fc6cSmrg  tr ' ' '
453d9c7fc6cSmrg' < "$tmpdepfile" | \
454d9c7fc6cSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
455d9c7fc6cSmrg## correctly.  Breaking it into two sed invocations is a workaround.
456d9c7fc6cSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
457d9c7fc6cSmrg  rm -f "$tmpdepfile"
458d9c7fc6cSmrg  ;;
459d9c7fc6cSmrg
460d9c7fc6cSmrgdashXmstdout)
461d9c7fc6cSmrg  # This case only exists to satisfy depend.m4.  It is never actually
462d9c7fc6cSmrg  # run, as this mode is specially recognized in the preamble.
463d9c7fc6cSmrg  exit 1
464d9c7fc6cSmrg  ;;
465d9c7fc6cSmrg
466d9c7fc6cSmrgmakedepend)
467d9c7fc6cSmrg  "$@" || exit $?
468d9c7fc6cSmrg  # Remove any Libtool call
469d9c7fc6cSmrg  if test "$libtool" = yes; then
47005a1a286Smrg    while test "X$1" != 'X--mode=compile'; do
471d9c7fc6cSmrg      shift
472d9c7fc6cSmrg    done
473d9c7fc6cSmrg    shift
474d9c7fc6cSmrg  fi
475d9c7fc6cSmrg  # X makedepend
476d9c7fc6cSmrg  shift
47705a1a286Smrg  cleared=no eat=no
47805a1a286Smrg  for arg
47905a1a286Smrg  do
480d9c7fc6cSmrg    case $cleared in
481d9c7fc6cSmrg    no)
482d9c7fc6cSmrg      set ""; shift
483d9c7fc6cSmrg      cleared=yes ;;
484d9c7fc6cSmrg    esac
48505a1a286Smrg    if test $eat = yes; then
48605a1a286Smrg      eat=no
48705a1a286Smrg      continue
48805a1a286Smrg    fi
489d9c7fc6cSmrg    case "$arg" in
490d9c7fc6cSmrg    -D*|-I*)
491d9c7fc6cSmrg      set fnord "$@" "$arg"; shift ;;
492d9c7fc6cSmrg    # Strip any option that makedepend may not understand.  Remove
493d9c7fc6cSmrg    # the object too, otherwise makedepend will parse it as a source file.
49405a1a286Smrg    -arch)
49505a1a286Smrg      eat=yes ;;
496d9c7fc6cSmrg    -*|$object)
497d9c7fc6cSmrg      ;;
498d9c7fc6cSmrg    *)
499d9c7fc6cSmrg      set fnord "$@" "$arg"; shift ;;
500d9c7fc6cSmrg    esac
501d9c7fc6cSmrg  done
50205a1a286Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
503d9c7fc6cSmrg  touch "$tmpdepfile"
504d9c7fc6cSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
505d9c7fc6cSmrg  rm -f "$depfile"
506d9c7fc6cSmrg  cat < "$tmpdepfile" > "$depfile"
507d9c7fc6cSmrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
508d9c7fc6cSmrg' | \
509d9c7fc6cSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
510d9c7fc6cSmrg## correctly.  Breaking it into two sed invocations is a workaround.
511d9c7fc6cSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
512d9c7fc6cSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
513d9c7fc6cSmrg  ;;
514d9c7fc6cSmrg
515d9c7fc6cSmrgcpp)
516d9c7fc6cSmrg  # Important note: in order to support this mode, a compiler *must*
517d9c7fc6cSmrg  # always write the preprocessed file to stdout.
518d9c7fc6cSmrg  "$@" || exit $?
519d9c7fc6cSmrg
520d9c7fc6cSmrg  # Remove the call to Libtool.
521d9c7fc6cSmrg  if test "$libtool" = yes; then
52205a1a286Smrg    while test "X$1" != 'X--mode=compile'; do
523d9c7fc6cSmrg      shift
524d9c7fc6cSmrg    done
525d9c7fc6cSmrg    shift
526d9c7fc6cSmrg  fi
527d9c7fc6cSmrg
528d9c7fc6cSmrg  # Remove `-o $object'.
529d9c7fc6cSmrg  IFS=" "
530d9c7fc6cSmrg  for arg
531d9c7fc6cSmrg  do
532d9c7fc6cSmrg    case $arg in
533d9c7fc6cSmrg    -o)
534d9c7fc6cSmrg      shift
535d9c7fc6cSmrg      ;;
536d9c7fc6cSmrg    $object)
537d9c7fc6cSmrg      shift
538d9c7fc6cSmrg      ;;
539d9c7fc6cSmrg    *)
540d9c7fc6cSmrg      set fnord "$@" "$arg"
541d9c7fc6cSmrg      shift # fnord
542d9c7fc6cSmrg      shift # $arg
543d9c7fc6cSmrg      ;;
544d9c7fc6cSmrg    esac
545d9c7fc6cSmrg  done
546d9c7fc6cSmrg
547d9c7fc6cSmrg  "$@" -E |
548d9c7fc6cSmrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
549d9c7fc6cSmrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
550d9c7fc6cSmrg    sed '$ s: \\$::' > "$tmpdepfile"
551d9c7fc6cSmrg  rm -f "$depfile"
552d9c7fc6cSmrg  echo "$object : \\" > "$depfile"
553d9c7fc6cSmrg  cat < "$tmpdepfile" >> "$depfile"
554d9c7fc6cSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
555d9c7fc6cSmrg  rm -f "$tmpdepfile"
556d9c7fc6cSmrg  ;;
557d9c7fc6cSmrg
558d9c7fc6cSmrgmsvisualcpp)
559d9c7fc6cSmrg  # Important note: in order to support this mode, a compiler *must*
56005a1a286Smrg  # always write the preprocessed file to stdout.
561d9c7fc6cSmrg  "$@" || exit $?
56205a1a286Smrg
56305a1a286Smrg  # Remove the call to Libtool.
56405a1a286Smrg  if test "$libtool" = yes; then
56505a1a286Smrg    while test "X$1" != 'X--mode=compile'; do
56605a1a286Smrg      shift
56705a1a286Smrg    done
56805a1a286Smrg    shift
56905a1a286Smrg  fi
57005a1a286Smrg
571d9c7fc6cSmrg  IFS=" "
572d9c7fc6cSmrg  for arg
573d9c7fc6cSmrg  do
574d9c7fc6cSmrg    case "$arg" in
57505a1a286Smrg    -o)
57605a1a286Smrg      shift
57705a1a286Smrg      ;;
57805a1a286Smrg    $object)
57905a1a286Smrg      shift
58005a1a286Smrg      ;;
581d9c7fc6cSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
582d9c7fc6cSmrg	set fnord "$@"
583d9c7fc6cSmrg	shift
584d9c7fc6cSmrg	shift
585d9c7fc6cSmrg	;;
586d9c7fc6cSmrg    *)
587d9c7fc6cSmrg	set fnord "$@" "$arg"
588d9c7fc6cSmrg	shift
589d9c7fc6cSmrg	shift
590d9c7fc6cSmrg	;;
591d9c7fc6cSmrg    esac
592d9c7fc6cSmrg  done
59305a1a286Smrg  "$@" -E 2>/dev/null |
59405a1a286Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
595d9c7fc6cSmrg  rm -f "$depfile"
596d9c7fc6cSmrg  echo "$object : \\" > "$depfile"
59705a1a286Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
598d9c7fc6cSmrg  echo "	" >> "$depfile"
59905a1a286Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
600d9c7fc6cSmrg  rm -f "$tmpdepfile"
601d9c7fc6cSmrg  ;;
602d9c7fc6cSmrg
60305a1a286Smrgmsvcmsys)
60405a1a286Smrg  # This case exists only to let depend.m4 do its work.  It works by
60505a1a286Smrg  # looking at the text of this script.  This case will never be run,
60605a1a286Smrg  # since it is checked for above.
60705a1a286Smrg  exit 1
60805a1a286Smrg  ;;
60905a1a286Smrg
610d9c7fc6cSmrgnone)
611d9c7fc6cSmrg  exec "$@"
612d9c7fc6cSmrg  ;;
613d9c7fc6cSmrg
614d9c7fc6cSmrg*)
615d9c7fc6cSmrg  echo "Unknown depmode $depmode" 1>&2
616d9c7fc6cSmrg  exit 1
617d9c7fc6cSmrg  ;;
618d9c7fc6cSmrgesac
619d9c7fc6cSmrg
620d9c7fc6cSmrgexit 0
621d9c7fc6cSmrg
622d9c7fc6cSmrg# Local Variables:
623d9c7fc6cSmrg# mode: shell-script
624d9c7fc6cSmrg# sh-indentation: 2
625d9c7fc6cSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
626d9c7fc6cSmrg# time-stamp-start: "scriptversion="
627d9c7fc6cSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
62805a1a286Smrg# time-stamp-time-zone: "UTC"
62905a1a286Smrg# time-stamp-end: "; # UTC"
630d9c7fc6cSmrg# End:
631