depcomp revision 880c7e28
1bdcaa8d0Smrg#! /bin/sh
2bdcaa8d0Smrg# depcomp - compile a program generating dependencies as side-effects
3bdcaa8d0Smrg
4880c7e28Smrgscriptversion=2011-12-04.11; # UTC
5bdcaa8d0Smrg
6880c7e28Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
7880c7e28Smrg# 2011 Free Software Foundation, Inc.
8bdcaa8d0Smrg
9bdcaa8d0Smrg# This program is free software; you can redistribute it and/or modify
10bdcaa8d0Smrg# it under the terms of the GNU General Public License as published by
11bdcaa8d0Smrg# the Free Software Foundation; either version 2, or (at your option)
12bdcaa8d0Smrg# any later version.
13bdcaa8d0Smrg
14bdcaa8d0Smrg# This program is distributed in the hope that it will be useful,
15bdcaa8d0Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16bdcaa8d0Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17bdcaa8d0Smrg# GNU General Public License for more details.
18bdcaa8d0Smrg
19bdcaa8d0Smrg# You should have received a copy of the GNU General Public License
2096ce994aSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21bdcaa8d0Smrg
22bdcaa8d0Smrg# As a special exception to the GNU General Public License, if you
23bdcaa8d0Smrg# distribute this file as part of a program that contains a
24bdcaa8d0Smrg# configuration script generated by Autoconf, you may include it under
25bdcaa8d0Smrg# the same distribution terms that you use for the rest of that program.
26bdcaa8d0Smrg
27bdcaa8d0Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
28bdcaa8d0Smrg
29bdcaa8d0Smrgcase $1 in
30bdcaa8d0Smrg  '')
31bdcaa8d0Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
32bdcaa8d0Smrg     exit 1;
33bdcaa8d0Smrg     ;;
34bdcaa8d0Smrg  -h | --h*)
35bdcaa8d0Smrg    cat <<\EOF
36bdcaa8d0SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
37bdcaa8d0Smrg
38bdcaa8d0SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
39bdcaa8d0Smrgas side-effects.
40bdcaa8d0Smrg
41bdcaa8d0SmrgEnvironment variables:
42bdcaa8d0Smrg  depmode     Dependency tracking mode.
43bdcaa8d0Smrg  source      Source file read by `PROGRAMS ARGS'.
44bdcaa8d0Smrg  object      Object file output by `PROGRAMS ARGS'.
45bdcaa8d0Smrg  DEPDIR      directory where to store dependencies.
46bdcaa8d0Smrg  depfile     Dependency file to output.
47880c7e28Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
48bdcaa8d0Smrg  libtool     Whether libtool is used (yes/no).
49bdcaa8d0Smrg
50bdcaa8d0SmrgReport bugs to <bug-automake@gnu.org>.
51bdcaa8d0SmrgEOF
52bdcaa8d0Smrg    exit $?
53bdcaa8d0Smrg    ;;
54bdcaa8d0Smrg  -v | --v*)
55bdcaa8d0Smrg    echo "depcomp $scriptversion"
56bdcaa8d0Smrg    exit $?
57bdcaa8d0Smrg    ;;
58bdcaa8d0Smrgesac
59bdcaa8d0Smrg
60bdcaa8d0Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
61bdcaa8d0Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
62bdcaa8d0Smrg  exit 1
63bdcaa8d0Smrgfi
64bdcaa8d0Smrg
65bdcaa8d0Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
66bdcaa8d0Smrgdepfile=${depfile-`echo "$object" |
67bdcaa8d0Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
68bdcaa8d0Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
69bdcaa8d0Smrg
70bdcaa8d0Smrgrm -f "$tmpdepfile"
71bdcaa8d0Smrg
72bdcaa8d0Smrg# Some modes work just like other modes, but use different flags.  We
73bdcaa8d0Smrg# parameterize here, but still list the modes in the big case below,
74bdcaa8d0Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
75bdcaa8d0Smrg# here, because this file can only contain one case statement.
76bdcaa8d0Smrgif test "$depmode" = hp; then
77bdcaa8d0Smrg  # HP compiler uses -M and no extra arg.
78bdcaa8d0Smrg  gccflag=-M
79bdcaa8d0Smrg  depmode=gcc
80bdcaa8d0Smrgfi
81bdcaa8d0Smrg
82bdcaa8d0Smrgif test "$depmode" = dashXmstdout; then
83bdcaa8d0Smrg   # This is just like dashmstdout with a different argument.
84bdcaa8d0Smrg   dashmflag=-xM
85bdcaa8d0Smrg   depmode=dashmstdout
86bdcaa8d0Smrgfi
87bdcaa8d0Smrg
8896ce994aSmrgcygpath_u="cygpath -u -f -"
8996ce994aSmrgif test "$depmode" = msvcmsys; then
9096ce994aSmrg   # This is just like msvisualcpp but w/o cygpath translation.
9196ce994aSmrg   # Just convert the backslash-escaped backslashes to single forward
9296ce994aSmrg   # slashes to satisfy depend.m4
93880c7e28Smrg   cygpath_u='sed s,\\\\,/,g'
9496ce994aSmrg   depmode=msvisualcpp
9596ce994aSmrgfi
9696ce994aSmrg
97880c7e28Smrgif test "$depmode" = msvc7msys; then
98880c7e28Smrg   # This is just like msvc7 but w/o cygpath translation.
99880c7e28Smrg   # Just convert the backslash-escaped backslashes to single forward
100880c7e28Smrg   # slashes to satisfy depend.m4
101880c7e28Smrg   cygpath_u='sed s,\\\\,/,g'
102880c7e28Smrg   depmode=msvc7
103880c7e28Smrgfi
104880c7e28Smrg
105bdcaa8d0Smrgcase "$depmode" in
106bdcaa8d0Smrggcc3)
107bdcaa8d0Smrg## gcc 3 implements dependency tracking that does exactly what
108bdcaa8d0Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
109bdcaa8d0Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
11072313efbSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
11172313efbSmrg## the command line argument order; so add the flags where they
11272313efbSmrg## appear in depend2.am.  Note that the slowdown incurred here
11372313efbSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
11472313efbSmrg  for arg
11572313efbSmrg  do
11672313efbSmrg    case $arg in
11772313efbSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
11872313efbSmrg    *)  set fnord "$@" "$arg" ;;
11972313efbSmrg    esac
12072313efbSmrg    shift # fnord
12172313efbSmrg    shift # $arg
12272313efbSmrg  done
12372313efbSmrg  "$@"
124bdcaa8d0Smrg  stat=$?
125bdcaa8d0Smrg  if test $stat -eq 0; then :
126bdcaa8d0Smrg  else
127bdcaa8d0Smrg    rm -f "$tmpdepfile"
128bdcaa8d0Smrg    exit $stat
129bdcaa8d0Smrg  fi
130bdcaa8d0Smrg  mv "$tmpdepfile" "$depfile"
131bdcaa8d0Smrg  ;;
132bdcaa8d0Smrg
133bdcaa8d0Smrggcc)
134bdcaa8d0Smrg## There are various ways to get dependency output from gcc.  Here's
135bdcaa8d0Smrg## why we pick this rather obscure method:
136bdcaa8d0Smrg## - Don't want to use -MD because we'd like the dependencies to end
137bdcaa8d0Smrg##   up in a subdir.  Having to rename by hand is ugly.
138bdcaa8d0Smrg##   (We might end up doing this anyway to support other compilers.)
139bdcaa8d0Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
140bdcaa8d0Smrg##   -MM, not -M (despite what the docs say).
141bdcaa8d0Smrg## - Using -M directly means running the compiler twice (even worse
142bdcaa8d0Smrg##   than renaming).
143bdcaa8d0Smrg  if test -z "$gccflag"; then
144bdcaa8d0Smrg    gccflag=-MD,
145bdcaa8d0Smrg  fi
146bdcaa8d0Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
147bdcaa8d0Smrg  stat=$?
148bdcaa8d0Smrg  if test $stat -eq 0; then :
149bdcaa8d0Smrg  else
150bdcaa8d0Smrg    rm -f "$tmpdepfile"
151bdcaa8d0Smrg    exit $stat
152bdcaa8d0Smrg  fi
153bdcaa8d0Smrg  rm -f "$depfile"
154bdcaa8d0Smrg  echo "$object : \\" > "$depfile"
155bdcaa8d0Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
156bdcaa8d0Smrg## The second -e expression handles DOS-style file names with drive letters.
157bdcaa8d0Smrg  sed -e 's/^[^:]*: / /' \
158bdcaa8d0Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
159bdcaa8d0Smrg## This next piece of magic avoids the `deleted header file' problem.
160bdcaa8d0Smrg## The problem is that when a header file which appears in a .P file
161bdcaa8d0Smrg## is deleted, the dependency causes make to die (because there is
162bdcaa8d0Smrg## typically no way to rebuild the header).  We avoid this by adding
163bdcaa8d0Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
164bdcaa8d0Smrg## this for us directly.
165bdcaa8d0Smrg  tr ' ' '
166bdcaa8d0Smrg' < "$tmpdepfile" |
167bdcaa8d0Smrg## Some versions of gcc put a space before the `:'.  On the theory
168bdcaa8d0Smrg## that the space means something, we add a space to the output as
169880c7e28Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
170880c7e28Smrg## to the object.  Take care to not repeat it in the output.
171bdcaa8d0Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
172bdcaa8d0Smrg## correctly.  Breaking it into two sed invocations is a workaround.
173880c7e28Smrg    sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
174880c7e28Smrg      | sed -e 's/$/ :/' >> "$depfile"
175bdcaa8d0Smrg  rm -f "$tmpdepfile"
176bdcaa8d0Smrg  ;;
177bdcaa8d0Smrg
178bdcaa8d0Smrghp)
179bdcaa8d0Smrg  # This case exists only to let depend.m4 do its work.  It works by
180bdcaa8d0Smrg  # looking at the text of this script.  This case will never be run,
181bdcaa8d0Smrg  # since it is checked for above.
182bdcaa8d0Smrg  exit 1
183bdcaa8d0Smrg  ;;
184bdcaa8d0Smrg
185bdcaa8d0Smrgsgi)
186bdcaa8d0Smrg  if test "$libtool" = yes; then
187bdcaa8d0Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
188bdcaa8d0Smrg  else
189bdcaa8d0Smrg    "$@" -MDupdate "$tmpdepfile"
190bdcaa8d0Smrg  fi
191bdcaa8d0Smrg  stat=$?
192bdcaa8d0Smrg  if test $stat -eq 0; then :
193bdcaa8d0Smrg  else
194bdcaa8d0Smrg    rm -f "$tmpdepfile"
195bdcaa8d0Smrg    exit $stat
196bdcaa8d0Smrg  fi
197bdcaa8d0Smrg  rm -f "$depfile"
198bdcaa8d0Smrg
199bdcaa8d0Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
200bdcaa8d0Smrg    echo "$object : \\" > "$depfile"
201bdcaa8d0Smrg
202bdcaa8d0Smrg    # Clip off the initial element (the dependent).  Don't try to be
203bdcaa8d0Smrg    # clever and replace this with sed code, as IRIX sed won't handle
204bdcaa8d0Smrg    # lines with more than a fixed number of characters (4096 in
205bdcaa8d0Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
206bdcaa8d0Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
207bdcaa8d0Smrg    # dependency line.
208bdcaa8d0Smrg    tr ' ' '
209bdcaa8d0Smrg' < "$tmpdepfile" \
210bdcaa8d0Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
211bdcaa8d0Smrg    tr '
21296ce994aSmrg' ' ' >> "$depfile"
21396ce994aSmrg    echo >> "$depfile"
214bdcaa8d0Smrg
215bdcaa8d0Smrg    # The second pass generates a dummy entry for each header file.
216bdcaa8d0Smrg    tr ' ' '
217bdcaa8d0Smrg' < "$tmpdepfile" \
218bdcaa8d0Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
21996ce994aSmrg   >> "$depfile"
220bdcaa8d0Smrg  else
221bdcaa8d0Smrg    # The sourcefile does not contain any dependencies, so just
222bdcaa8d0Smrg    # store a dummy comment line, to avoid errors with the Makefile
223bdcaa8d0Smrg    # "include basename.Plo" scheme.
224bdcaa8d0Smrg    echo "#dummy" > "$depfile"
225bdcaa8d0Smrg  fi
226bdcaa8d0Smrg  rm -f "$tmpdepfile"
227bdcaa8d0Smrg  ;;
228bdcaa8d0Smrg
229bdcaa8d0Smrgaix)
230bdcaa8d0Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
231bdcaa8d0Smrg  # in a .u file.  In older versions, this file always lives in the
232bdcaa8d0Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
233bdcaa8d0Smrg  # start of each line; $object doesn't have directory information.
234bdcaa8d0Smrg  # Version 6 uses the directory in both cases.
23572313efbSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
23672313efbSmrg  test "x$dir" = "x$object" && dir=
23772313efbSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
238bdcaa8d0Smrg  if test "$libtool" = yes; then
23972313efbSmrg    tmpdepfile1=$dir$base.u
24072313efbSmrg    tmpdepfile2=$base.u
24172313efbSmrg    tmpdepfile3=$dir.libs/$base.u
242bdcaa8d0Smrg    "$@" -Wc,-M
243bdcaa8d0Smrg  else
24472313efbSmrg    tmpdepfile1=$dir$base.u
24572313efbSmrg    tmpdepfile2=$dir$base.u
24672313efbSmrg    tmpdepfile3=$dir$base.u
247bdcaa8d0Smrg    "$@" -M
248bdcaa8d0Smrg  fi
249bdcaa8d0Smrg  stat=$?
250bdcaa8d0Smrg
251bdcaa8d0Smrg  if test $stat -eq 0; then :
252bdcaa8d0Smrg  else
25372313efbSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
254bdcaa8d0Smrg    exit $stat
255bdcaa8d0Smrg  fi
256bdcaa8d0Smrg
25772313efbSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
25872313efbSmrg  do
25972313efbSmrg    test -f "$tmpdepfile" && break
26072313efbSmrg  done
261bdcaa8d0Smrg  if test -f "$tmpdepfile"; then
262bdcaa8d0Smrg    # Each line is of the form `foo.o: dependent.h'.
263bdcaa8d0Smrg    # Do two passes, one to just change these to
264bdcaa8d0Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
26572313efbSmrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
26672313efbSmrg    # That's a tab and a space in the [].
26772313efbSmrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
268bdcaa8d0Smrg  else
269bdcaa8d0Smrg    # The sourcefile does not contain any dependencies, so just
270bdcaa8d0Smrg    # store a dummy comment line, to avoid errors with the Makefile
271bdcaa8d0Smrg    # "include basename.Plo" scheme.
272bdcaa8d0Smrg    echo "#dummy" > "$depfile"
273bdcaa8d0Smrg  fi
274bdcaa8d0Smrg  rm -f "$tmpdepfile"
275bdcaa8d0Smrg  ;;
276bdcaa8d0Smrg
277bdcaa8d0Smrgicc)
278bdcaa8d0Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
279bdcaa8d0Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
280bdcaa8d0Smrg  # ICC 7.0 will fill foo.d with something like
281bdcaa8d0Smrg  #    foo.o: sub/foo.c
282bdcaa8d0Smrg  #    foo.o: sub/foo.h
283bdcaa8d0Smrg  # which is wrong.  We want:
284bdcaa8d0Smrg  #    sub/foo.o: sub/foo.c
285bdcaa8d0Smrg  #    sub/foo.o: sub/foo.h
286bdcaa8d0Smrg  #    sub/foo.c:
287bdcaa8d0Smrg  #    sub/foo.h:
288bdcaa8d0Smrg  # ICC 7.1 will output
289bdcaa8d0Smrg  #    foo.o: sub/foo.c sub/foo.h
290bdcaa8d0Smrg  # and will wrap long lines using \ :
291bdcaa8d0Smrg  #    foo.o: sub/foo.c ... \
292bdcaa8d0Smrg  #     sub/foo.h ... \
293bdcaa8d0Smrg  #     ...
294bdcaa8d0Smrg
295bdcaa8d0Smrg  "$@" -MD -MF "$tmpdepfile"
296bdcaa8d0Smrg  stat=$?
297bdcaa8d0Smrg  if test $stat -eq 0; then :
298bdcaa8d0Smrg  else
299bdcaa8d0Smrg    rm -f "$tmpdepfile"
300bdcaa8d0Smrg    exit $stat
301bdcaa8d0Smrg  fi
302bdcaa8d0Smrg  rm -f "$depfile"
303bdcaa8d0Smrg  # Each line is of the form `foo.o: dependent.h',
304bdcaa8d0Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
305bdcaa8d0Smrg  # Do two passes, one to just change these to
306bdcaa8d0Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
307bdcaa8d0Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
308bdcaa8d0Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
309bdcaa8d0Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
310bdcaa8d0Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
311bdcaa8d0Smrg    sed -e 's/$/ :/' >> "$depfile"
312bdcaa8d0Smrg  rm -f "$tmpdepfile"
313bdcaa8d0Smrg  ;;
314bdcaa8d0Smrg
31572313efbSmrghp2)
31672313efbSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
31772313efbSmrg  # compilers, which have integrated preprocessors.  The correct option
31872313efbSmrg  # to use with these is +Maked; it writes dependencies to a file named
31972313efbSmrg  # 'foo.d', which lands next to the object file, wherever that
32072313efbSmrg  # happens to be.
32172313efbSmrg  # Much of this is similar to the tru64 case; see comments there.
32272313efbSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
32372313efbSmrg  test "x$dir" = "x$object" && dir=
32472313efbSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
32572313efbSmrg  if test "$libtool" = yes; then
32672313efbSmrg    tmpdepfile1=$dir$base.d
32772313efbSmrg    tmpdepfile2=$dir.libs/$base.d
32872313efbSmrg    "$@" -Wc,+Maked
32972313efbSmrg  else
33072313efbSmrg    tmpdepfile1=$dir$base.d
33172313efbSmrg    tmpdepfile2=$dir$base.d
33272313efbSmrg    "$@" +Maked
33372313efbSmrg  fi
33472313efbSmrg  stat=$?
33572313efbSmrg  if test $stat -eq 0; then :
33672313efbSmrg  else
33772313efbSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
33872313efbSmrg     exit $stat
33972313efbSmrg  fi
34072313efbSmrg
34172313efbSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
34272313efbSmrg  do
34372313efbSmrg    test -f "$tmpdepfile" && break
34472313efbSmrg  done
34572313efbSmrg  if test -f "$tmpdepfile"; then
34672313efbSmrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
34772313efbSmrg    # Add `dependent.h:' lines.
34896ce994aSmrg    sed -ne '2,${
34996ce994aSmrg	       s/^ *//
35096ce994aSmrg	       s/ \\*$//
35196ce994aSmrg	       s/$/:/
35296ce994aSmrg	       p
35396ce994aSmrg	     }' "$tmpdepfile" >> "$depfile"
35472313efbSmrg  else
35572313efbSmrg    echo "#dummy" > "$depfile"
35672313efbSmrg  fi
35772313efbSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
35872313efbSmrg  ;;
35972313efbSmrg
360bdcaa8d0Smrgtru64)
361bdcaa8d0Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
362bdcaa8d0Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
363bdcaa8d0Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
364bdcaa8d0Smrg   # dependencies in `foo.d' instead, so we check for that too.
365bdcaa8d0Smrg   # Subdirectories are respected.
366bdcaa8d0Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
367bdcaa8d0Smrg   test "x$dir" = "x$object" && dir=
368bdcaa8d0Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
369bdcaa8d0Smrg
370bdcaa8d0Smrg   if test "$libtool" = yes; then
371bdcaa8d0Smrg      # With Tru64 cc, shared objects can also be used to make a
37272313efbSmrg      # static library.  This mechanism is used in libtool 1.4 series to
373bdcaa8d0Smrg      # handle both shared and static libraries in a single compilation.
374bdcaa8d0Smrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
375bdcaa8d0Smrg      #
376bdcaa8d0Smrg      # With libtool 1.5 this exception was removed, and libtool now
377bdcaa8d0Smrg      # generates 2 separate objects for the 2 libraries.  These two
37872313efbSmrg      # compilations output dependencies in $dir.libs/$base.o.d and
379bdcaa8d0Smrg      # in $dir$base.o.d.  We have to check for both files, because
380bdcaa8d0Smrg      # one of the two compilations can be disabled.  We should prefer
381bdcaa8d0Smrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
382bdcaa8d0Smrg      # automatically cleaned when .libs/ is deleted, while ignoring
383bdcaa8d0Smrg      # the former would cause a distcleancheck panic.
384bdcaa8d0Smrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
385bdcaa8d0Smrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
386bdcaa8d0Smrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
387bdcaa8d0Smrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
388bdcaa8d0Smrg      "$@" -Wc,-MD
389bdcaa8d0Smrg   else
390bdcaa8d0Smrg      tmpdepfile1=$dir$base.o.d
391bdcaa8d0Smrg      tmpdepfile2=$dir$base.d
392bdcaa8d0Smrg      tmpdepfile3=$dir$base.d
393bdcaa8d0Smrg      tmpdepfile4=$dir$base.d
394bdcaa8d0Smrg      "$@" -MD
395bdcaa8d0Smrg   fi
396bdcaa8d0Smrg
397bdcaa8d0Smrg   stat=$?
398bdcaa8d0Smrg   if test $stat -eq 0; then :
399bdcaa8d0Smrg   else
400bdcaa8d0Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
401bdcaa8d0Smrg      exit $stat
402bdcaa8d0Smrg   fi
403bdcaa8d0Smrg
404bdcaa8d0Smrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
405bdcaa8d0Smrg   do
406bdcaa8d0Smrg     test -f "$tmpdepfile" && break
407bdcaa8d0Smrg   done
408bdcaa8d0Smrg   if test -f "$tmpdepfile"; then
409bdcaa8d0Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
410bdcaa8d0Smrg      # That's a tab and a space in the [].
411bdcaa8d0Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
412bdcaa8d0Smrg   else
413bdcaa8d0Smrg      echo "#dummy" > "$depfile"
414bdcaa8d0Smrg   fi
415bdcaa8d0Smrg   rm -f "$tmpdepfile"
416bdcaa8d0Smrg   ;;
417bdcaa8d0Smrg
418880c7e28Smrgmsvc7)
419880c7e28Smrg  if test "$libtool" = yes; then
420880c7e28Smrg    showIncludes=-Wc,-showIncludes
421880c7e28Smrg  else
422880c7e28Smrg    showIncludes=-showIncludes
423880c7e28Smrg  fi
424880c7e28Smrg  "$@" $showIncludes > "$tmpdepfile"
425880c7e28Smrg  stat=$?
426880c7e28Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
427880c7e28Smrg  if test "$stat" = 0; then :
428880c7e28Smrg  else
429880c7e28Smrg    rm -f "$tmpdepfile"
430880c7e28Smrg    exit $stat
431880c7e28Smrg  fi
432880c7e28Smrg  rm -f "$depfile"
433880c7e28Smrg  echo "$object : \\" > "$depfile"
434880c7e28Smrg  # The first sed program below extracts the file names and escapes
435880c7e28Smrg  # backslashes for cygpath.  The second sed program outputs the file
436880c7e28Smrg  # name when reading, but also accumulates all include files in the
437880c7e28Smrg  # hold buffer in order to output them again at the end.  This only
438880c7e28Smrg  # works with sed implementations that can handle large buffers.
439880c7e28Smrg  sed < "$tmpdepfile" -n '
440880c7e28Smrg/^Note: including file:  *\(.*\)/ {
441880c7e28Smrg  s//\1/
442880c7e28Smrg  s/\\/\\\\/g
443880c7e28Smrg  p
444880c7e28Smrg}' | $cygpath_u | sort -u | sed -n '
445880c7e28Smrgs/ /\\ /g
446880c7e28Smrgs/\(.*\)/	\1 \\/p
447880c7e28Smrgs/.\(.*\) \\/\1:/
448880c7e28SmrgH
449880c7e28Smrg$ {
450880c7e28Smrg  s/.*/	/
451880c7e28Smrg  G
452880c7e28Smrg  p
453880c7e28Smrg}' >> "$depfile"
454880c7e28Smrg  rm -f "$tmpdepfile"
455880c7e28Smrg  ;;
456880c7e28Smrg
457880c7e28Smrgmsvc7msys)
458880c7e28Smrg  # This case exists only to let depend.m4 do its work.  It works by
459880c7e28Smrg  # looking at the text of this script.  This case will never be run,
460880c7e28Smrg  # since it is checked for above.
461880c7e28Smrg  exit 1
462880c7e28Smrg  ;;
463880c7e28Smrg
464bdcaa8d0Smrg#nosideeffect)
465bdcaa8d0Smrg  # This comment above is used by automake to tell side-effect
466bdcaa8d0Smrg  # dependency tracking mechanisms from slower ones.
467bdcaa8d0Smrg
468bdcaa8d0Smrgdashmstdout)
469bdcaa8d0Smrg  # Important note: in order to support this mode, a compiler *must*
470bdcaa8d0Smrg  # always write the preprocessed file to stdout, regardless of -o.
471bdcaa8d0Smrg  "$@" || exit $?
472bdcaa8d0Smrg
473bdcaa8d0Smrg  # Remove the call to Libtool.
474bdcaa8d0Smrg  if test "$libtool" = yes; then
47596ce994aSmrg    while test "X$1" != 'X--mode=compile'; do
476bdcaa8d0Smrg      shift
477bdcaa8d0Smrg    done
478bdcaa8d0Smrg    shift
479bdcaa8d0Smrg  fi
480bdcaa8d0Smrg
481bdcaa8d0Smrg  # Remove `-o $object'.
482bdcaa8d0Smrg  IFS=" "
483bdcaa8d0Smrg  for arg
484bdcaa8d0Smrg  do
485bdcaa8d0Smrg    case $arg in
486bdcaa8d0Smrg    -o)
487bdcaa8d0Smrg      shift
488bdcaa8d0Smrg      ;;
489bdcaa8d0Smrg    $object)
490bdcaa8d0Smrg      shift
491bdcaa8d0Smrg      ;;
492bdcaa8d0Smrg    *)
493bdcaa8d0Smrg      set fnord "$@" "$arg"
494bdcaa8d0Smrg      shift # fnord
495bdcaa8d0Smrg      shift # $arg
496bdcaa8d0Smrg      ;;
497bdcaa8d0Smrg    esac
498bdcaa8d0Smrg  done
499bdcaa8d0Smrg
500bdcaa8d0Smrg  test -z "$dashmflag" && dashmflag=-M
501bdcaa8d0Smrg  # Require at least two characters before searching for `:'
502bdcaa8d0Smrg  # in the target name.  This is to cope with DOS-style filenames:
503bdcaa8d0Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
504bdcaa8d0Smrg  "$@" $dashmflag |
505bdcaa8d0Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
506bdcaa8d0Smrg  rm -f "$depfile"
507bdcaa8d0Smrg  cat < "$tmpdepfile" > "$depfile"
508bdcaa8d0Smrg  tr ' ' '
509bdcaa8d0Smrg' < "$tmpdepfile" | \
510bdcaa8d0Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
511bdcaa8d0Smrg## correctly.  Breaking it into two sed invocations is a workaround.
512bdcaa8d0Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
513bdcaa8d0Smrg  rm -f "$tmpdepfile"
514bdcaa8d0Smrg  ;;
515bdcaa8d0Smrg
516bdcaa8d0SmrgdashXmstdout)
517bdcaa8d0Smrg  # This case only exists to satisfy depend.m4.  It is never actually
518bdcaa8d0Smrg  # run, as this mode is specially recognized in the preamble.
519bdcaa8d0Smrg  exit 1
520bdcaa8d0Smrg  ;;
521bdcaa8d0Smrg
522bdcaa8d0Smrgmakedepend)
523bdcaa8d0Smrg  "$@" || exit $?
524bdcaa8d0Smrg  # Remove any Libtool call
525bdcaa8d0Smrg  if test "$libtool" = yes; then
52696ce994aSmrg    while test "X$1" != 'X--mode=compile'; do
527bdcaa8d0Smrg      shift
528bdcaa8d0Smrg    done
529bdcaa8d0Smrg    shift
530bdcaa8d0Smrg  fi
531bdcaa8d0Smrg  # X makedepend
532bdcaa8d0Smrg  shift
53396ce994aSmrg  cleared=no eat=no
53496ce994aSmrg  for arg
53596ce994aSmrg  do
536bdcaa8d0Smrg    case $cleared in
537bdcaa8d0Smrg    no)
538bdcaa8d0Smrg      set ""; shift
539bdcaa8d0Smrg      cleared=yes ;;
540bdcaa8d0Smrg    esac
54196ce994aSmrg    if test $eat = yes; then
54296ce994aSmrg      eat=no
54396ce994aSmrg      continue
54496ce994aSmrg    fi
545bdcaa8d0Smrg    case "$arg" in
546bdcaa8d0Smrg    -D*|-I*)
547bdcaa8d0Smrg      set fnord "$@" "$arg"; shift ;;
548bdcaa8d0Smrg    # Strip any option that makedepend may not understand.  Remove
549bdcaa8d0Smrg    # the object too, otherwise makedepend will parse it as a source file.
55096ce994aSmrg    -arch)
55196ce994aSmrg      eat=yes ;;
552bdcaa8d0Smrg    -*|$object)
553bdcaa8d0Smrg      ;;
554bdcaa8d0Smrg    *)
555bdcaa8d0Smrg      set fnord "$@" "$arg"; shift ;;
556bdcaa8d0Smrg    esac
557bdcaa8d0Smrg  done
55896ce994aSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
559bdcaa8d0Smrg  touch "$tmpdepfile"
560bdcaa8d0Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
561bdcaa8d0Smrg  rm -f "$depfile"
562880c7e28Smrg  # makedepend may prepend the VPATH from the source file name to the object.
563880c7e28Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
564880c7e28Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
565bdcaa8d0Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
566bdcaa8d0Smrg' | \
567bdcaa8d0Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
568bdcaa8d0Smrg## correctly.  Breaking it into two sed invocations is a workaround.
569bdcaa8d0Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
570bdcaa8d0Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
571bdcaa8d0Smrg  ;;
572bdcaa8d0Smrg
573bdcaa8d0Smrgcpp)
574bdcaa8d0Smrg  # Important note: in order to support this mode, a compiler *must*
575bdcaa8d0Smrg  # always write the preprocessed file to stdout.
576bdcaa8d0Smrg  "$@" || exit $?
577bdcaa8d0Smrg
578bdcaa8d0Smrg  # Remove the call to Libtool.
579bdcaa8d0Smrg  if test "$libtool" = yes; then
58096ce994aSmrg    while test "X$1" != 'X--mode=compile'; do
581bdcaa8d0Smrg      shift
582bdcaa8d0Smrg    done
583bdcaa8d0Smrg    shift
584bdcaa8d0Smrg  fi
585bdcaa8d0Smrg
586bdcaa8d0Smrg  # Remove `-o $object'.
587bdcaa8d0Smrg  IFS=" "
588bdcaa8d0Smrg  for arg
589bdcaa8d0Smrg  do
590bdcaa8d0Smrg    case $arg in
591bdcaa8d0Smrg    -o)
592bdcaa8d0Smrg      shift
593bdcaa8d0Smrg      ;;
594bdcaa8d0Smrg    $object)
595bdcaa8d0Smrg      shift
596bdcaa8d0Smrg      ;;
597bdcaa8d0Smrg    *)
598bdcaa8d0Smrg      set fnord "$@" "$arg"
599bdcaa8d0Smrg      shift # fnord
600bdcaa8d0Smrg      shift # $arg
601bdcaa8d0Smrg      ;;
602bdcaa8d0Smrg    esac
603bdcaa8d0Smrg  done
604bdcaa8d0Smrg
605bdcaa8d0Smrg  "$@" -E |
606bdcaa8d0Smrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
607bdcaa8d0Smrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
608bdcaa8d0Smrg    sed '$ s: \\$::' > "$tmpdepfile"
609bdcaa8d0Smrg  rm -f "$depfile"
610bdcaa8d0Smrg  echo "$object : \\" > "$depfile"
611bdcaa8d0Smrg  cat < "$tmpdepfile" >> "$depfile"
612bdcaa8d0Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
613bdcaa8d0Smrg  rm -f "$tmpdepfile"
614bdcaa8d0Smrg  ;;
615bdcaa8d0Smrg
616bdcaa8d0Smrgmsvisualcpp)
617bdcaa8d0Smrg  # Important note: in order to support this mode, a compiler *must*
61896ce994aSmrg  # always write the preprocessed file to stdout.
619bdcaa8d0Smrg  "$@" || exit $?
62096ce994aSmrg
62196ce994aSmrg  # Remove the call to Libtool.
62296ce994aSmrg  if test "$libtool" = yes; then
62396ce994aSmrg    while test "X$1" != 'X--mode=compile'; do
62496ce994aSmrg      shift
62596ce994aSmrg    done
62696ce994aSmrg    shift
62796ce994aSmrg  fi
62896ce994aSmrg
629bdcaa8d0Smrg  IFS=" "
630bdcaa8d0Smrg  for arg
631bdcaa8d0Smrg  do
632bdcaa8d0Smrg    case "$arg" in
63396ce994aSmrg    -o)
63496ce994aSmrg      shift
63596ce994aSmrg      ;;
63696ce994aSmrg    $object)
63796ce994aSmrg      shift
63896ce994aSmrg      ;;
639bdcaa8d0Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
640bdcaa8d0Smrg	set fnord "$@"
641bdcaa8d0Smrg	shift
642bdcaa8d0Smrg	shift
643bdcaa8d0Smrg	;;
644bdcaa8d0Smrg    *)
645bdcaa8d0Smrg	set fnord "$@" "$arg"
646bdcaa8d0Smrg	shift
647bdcaa8d0Smrg	shift
648bdcaa8d0Smrg	;;
649bdcaa8d0Smrg    esac
650bdcaa8d0Smrg  done
65196ce994aSmrg  "$@" -E 2>/dev/null |
65296ce994aSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
653bdcaa8d0Smrg  rm -f "$depfile"
654bdcaa8d0Smrg  echo "$object : \\" > "$depfile"
65596ce994aSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
656bdcaa8d0Smrg  echo "	" >> "$depfile"
65796ce994aSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
658bdcaa8d0Smrg  rm -f "$tmpdepfile"
659bdcaa8d0Smrg  ;;
660bdcaa8d0Smrg
66196ce994aSmrgmsvcmsys)
66296ce994aSmrg  # This case exists only to let depend.m4 do its work.  It works by
66396ce994aSmrg  # looking at the text of this script.  This case will never be run,
66496ce994aSmrg  # since it is checked for above.
66596ce994aSmrg  exit 1
66696ce994aSmrg  ;;
66796ce994aSmrg
668bdcaa8d0Smrgnone)
669bdcaa8d0Smrg  exec "$@"
670bdcaa8d0Smrg  ;;
671bdcaa8d0Smrg
672bdcaa8d0Smrg*)
673bdcaa8d0Smrg  echo "Unknown depmode $depmode" 1>&2
674bdcaa8d0Smrg  exit 1
675bdcaa8d0Smrg  ;;
676bdcaa8d0Smrgesac
677bdcaa8d0Smrg
678bdcaa8d0Smrgexit 0
679bdcaa8d0Smrg
680bdcaa8d0Smrg# Local Variables:
681bdcaa8d0Smrg# mode: shell-script
682bdcaa8d0Smrg# sh-indentation: 2
683bdcaa8d0Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
684bdcaa8d0Smrg# time-stamp-start: "scriptversion="
685bdcaa8d0Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
68696ce994aSmrg# time-stamp-time-zone: "UTC"
68796ce994aSmrg# time-stamp-end: "; # UTC"
688bdcaa8d0Smrg# End:
689