depcomp revision 42a55b46
1c582b7e3Smrg#! /bin/sh
2c582b7e3Smrg# depcomp - compile a program generating dependencies as side-effects
3c582b7e3Smrg
442a55b46Smrgscriptversion=2011-12-04.11; # UTC
5c582b7e3Smrg
642a55b46Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
742a55b46Smrg# 2011 Free Software Foundation, Inc.
8c582b7e3Smrg
9c582b7e3Smrg# This program is free software; you can redistribute it and/or modify
10c582b7e3Smrg# it under the terms of the GNU General Public License as published by
11c582b7e3Smrg# the Free Software Foundation; either version 2, or (at your option)
12c582b7e3Smrg# any later version.
13c582b7e3Smrg
14c582b7e3Smrg# This program is distributed in the hope that it will be useful,
15c582b7e3Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16c582b7e3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17c582b7e3Smrg# GNU General Public License for more details.
18c582b7e3Smrg
19c582b7e3Smrg# You should have received a copy of the GNU General Public License
2019019ffeSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21c582b7e3Smrg
22c582b7e3Smrg# As a special exception to the GNU General Public License, if you
23c582b7e3Smrg# distribute this file as part of a program that contains a
24c582b7e3Smrg# configuration script generated by Autoconf, you may include it under
25c582b7e3Smrg# the same distribution terms that you use for the rest of that program.
26c582b7e3Smrg
27c582b7e3Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
28c582b7e3Smrg
29c582b7e3Smrgcase $1 in
30c582b7e3Smrg  '')
31c582b7e3Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
32c582b7e3Smrg     exit 1;
33c582b7e3Smrg     ;;
34c582b7e3Smrg  -h | --h*)
35c582b7e3Smrg    cat <<\EOF
36c582b7e3SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
37c582b7e3Smrg
38c582b7e3SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
39c582b7e3Smrgas side-effects.
40c582b7e3Smrg
41c582b7e3SmrgEnvironment variables:
42c582b7e3Smrg  depmode     Dependency tracking mode.
43c582b7e3Smrg  source      Source file read by `PROGRAMS ARGS'.
44c582b7e3Smrg  object      Object file output by `PROGRAMS ARGS'.
45c582b7e3Smrg  DEPDIR      directory where to store dependencies.
46c582b7e3Smrg  depfile     Dependency file to output.
4742a55b46Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
48c582b7e3Smrg  libtool     Whether libtool is used (yes/no).
49c582b7e3Smrg
50c582b7e3SmrgReport bugs to <bug-automake@gnu.org>.
51c582b7e3SmrgEOF
52c582b7e3Smrg    exit $?
53c582b7e3Smrg    ;;
54c582b7e3Smrg  -v | --v*)
55c582b7e3Smrg    echo "depcomp $scriptversion"
56c582b7e3Smrg    exit $?
57c582b7e3Smrg    ;;
58c582b7e3Smrgesac
59c582b7e3Smrg
60c582b7e3Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
61c582b7e3Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
62c582b7e3Smrg  exit 1
63c582b7e3Smrgfi
64c582b7e3Smrg
65c582b7e3Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
66c582b7e3Smrgdepfile=${depfile-`echo "$object" |
67c582b7e3Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
68c582b7e3Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
69c582b7e3Smrg
70c582b7e3Smrgrm -f "$tmpdepfile"
71c582b7e3Smrg
72c582b7e3Smrg# Some modes work just like other modes, but use different flags.  We
73c582b7e3Smrg# parameterize here, but still list the modes in the big case below,
74c582b7e3Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
75c582b7e3Smrg# here, because this file can only contain one case statement.
76c582b7e3Smrgif test "$depmode" = hp; then
77c582b7e3Smrg  # HP compiler uses -M and no extra arg.
78c582b7e3Smrg  gccflag=-M
79c582b7e3Smrg  depmode=gcc
80c582b7e3Smrgfi
81c582b7e3Smrg
82c582b7e3Smrgif test "$depmode" = dashXmstdout; then
83c582b7e3Smrg   # This is just like dashmstdout with a different argument.
84c582b7e3Smrg   dashmflag=-xM
85c582b7e3Smrg   depmode=dashmstdout
86c582b7e3Smrgfi
87c582b7e3Smrg
8819019ffeSmrgcygpath_u="cygpath -u -f -"
8919019ffeSmrgif test "$depmode" = msvcmsys; then
9019019ffeSmrg   # This is just like msvisualcpp but w/o cygpath translation.
9119019ffeSmrg   # Just convert the backslash-escaped backslashes to single forward
9219019ffeSmrg   # slashes to satisfy depend.m4
9342a55b46Smrg   cygpath_u='sed s,\\\\,/,g'
9419019ffeSmrg   depmode=msvisualcpp
9519019ffeSmrgfi
9619019ffeSmrg
9742a55b46Smrgif test "$depmode" = msvc7msys; then
9842a55b46Smrg   # This is just like msvc7 but w/o cygpath translation.
9942a55b46Smrg   # Just convert the backslash-escaped backslashes to single forward
10042a55b46Smrg   # slashes to satisfy depend.m4
10142a55b46Smrg   cygpath_u='sed s,\\\\,/,g'
10242a55b46Smrg   depmode=msvc7
10342a55b46Smrgfi
10442a55b46Smrg
105c582b7e3Smrgcase "$depmode" in
106c582b7e3Smrggcc3)
107c582b7e3Smrg## gcc 3 implements dependency tracking that does exactly what
108c582b7e3Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
109c582b7e3Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
110c582b7e3Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
111c582b7e3Smrg## the command line argument order; so add the flags where they
112c582b7e3Smrg## appear in depend2.am.  Note that the slowdown incurred here
113c582b7e3Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
114c582b7e3Smrg  for arg
115c582b7e3Smrg  do
116c582b7e3Smrg    case $arg in
117c582b7e3Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
118c582b7e3Smrg    *)  set fnord "$@" "$arg" ;;
119c582b7e3Smrg    esac
120c582b7e3Smrg    shift # fnord
121c582b7e3Smrg    shift # $arg
122c582b7e3Smrg  done
123c582b7e3Smrg  "$@"
124c582b7e3Smrg  stat=$?
125c582b7e3Smrg  if test $stat -eq 0; then :
126c582b7e3Smrg  else
127c582b7e3Smrg    rm -f "$tmpdepfile"
128c582b7e3Smrg    exit $stat
129c582b7e3Smrg  fi
130c582b7e3Smrg  mv "$tmpdepfile" "$depfile"
131c582b7e3Smrg  ;;
132c582b7e3Smrg
133c582b7e3Smrggcc)
134c582b7e3Smrg## There are various ways to get dependency output from gcc.  Here's
135c582b7e3Smrg## why we pick this rather obscure method:
136c582b7e3Smrg## - Don't want to use -MD because we'd like the dependencies to end
137c582b7e3Smrg##   up in a subdir.  Having to rename by hand is ugly.
138c582b7e3Smrg##   (We might end up doing this anyway to support other compilers.)
139c582b7e3Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
140c582b7e3Smrg##   -MM, not -M (despite what the docs say).
141c582b7e3Smrg## - Using -M directly means running the compiler twice (even worse
142c582b7e3Smrg##   than renaming).
143c582b7e3Smrg  if test -z "$gccflag"; then
144c582b7e3Smrg    gccflag=-MD,
145c582b7e3Smrg  fi
146c582b7e3Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
147c582b7e3Smrg  stat=$?
148c582b7e3Smrg  if test $stat -eq 0; then :
149c582b7e3Smrg  else
150c582b7e3Smrg    rm -f "$tmpdepfile"
151c582b7e3Smrg    exit $stat
152c582b7e3Smrg  fi
153c582b7e3Smrg  rm -f "$depfile"
154c582b7e3Smrg  echo "$object : \\" > "$depfile"
155c582b7e3Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
156c582b7e3Smrg## The second -e expression handles DOS-style file names with drive letters.
157c582b7e3Smrg  sed -e 's/^[^:]*: / /' \
158c582b7e3Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
159c582b7e3Smrg## This next piece of magic avoids the `deleted header file' problem.
160c582b7e3Smrg## The problem is that when a header file which appears in a .P file
161c582b7e3Smrg## is deleted, the dependency causes make to die (because there is
162c582b7e3Smrg## typically no way to rebuild the header).  We avoid this by adding
163c582b7e3Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
164c582b7e3Smrg## this for us directly.
165c582b7e3Smrg  tr ' ' '
166c582b7e3Smrg' < "$tmpdepfile" |
167c582b7e3Smrg## Some versions of gcc put a space before the `:'.  On the theory
168c582b7e3Smrg## that the space means something, we add a space to the output as
16942a55b46Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
17042a55b46Smrg## to the object.  Take care to not repeat it in the output.
171c582b7e3Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
172c582b7e3Smrg## correctly.  Breaking it into two sed invocations is a workaround.
17342a55b46Smrg    sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
17442a55b46Smrg      | sed -e 's/$/ :/' >> "$depfile"
175c582b7e3Smrg  rm -f "$tmpdepfile"
176c582b7e3Smrg  ;;
177c582b7e3Smrg
178c582b7e3Smrghp)
179c582b7e3Smrg  # This case exists only to let depend.m4 do its work.  It works by
180c582b7e3Smrg  # looking at the text of this script.  This case will never be run,
181c582b7e3Smrg  # since it is checked for above.
182c582b7e3Smrg  exit 1
183c582b7e3Smrg  ;;
184c582b7e3Smrg
185c582b7e3Smrgsgi)
186c582b7e3Smrg  if test "$libtool" = yes; then
187c582b7e3Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
188c582b7e3Smrg  else
189c582b7e3Smrg    "$@" -MDupdate "$tmpdepfile"
190c582b7e3Smrg  fi
191c582b7e3Smrg  stat=$?
192c582b7e3Smrg  if test $stat -eq 0; then :
193c582b7e3Smrg  else
194c582b7e3Smrg    rm -f "$tmpdepfile"
195c582b7e3Smrg    exit $stat
196c582b7e3Smrg  fi
197c582b7e3Smrg  rm -f "$depfile"
198c582b7e3Smrg
199c582b7e3Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
200c582b7e3Smrg    echo "$object : \\" > "$depfile"
201c582b7e3Smrg
202c582b7e3Smrg    # Clip off the initial element (the dependent).  Don't try to be
203c582b7e3Smrg    # clever and replace this with sed code, as IRIX sed won't handle
204c582b7e3Smrg    # lines with more than a fixed number of characters (4096 in
205c582b7e3Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
206c582b7e3Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
207c582b7e3Smrg    # dependency line.
208c582b7e3Smrg    tr ' ' '
209c582b7e3Smrg' < "$tmpdepfile" \
210c582b7e3Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
211c582b7e3Smrg    tr '
21219019ffeSmrg' ' ' >> "$depfile"
21319019ffeSmrg    echo >> "$depfile"
214c582b7e3Smrg
215c582b7e3Smrg    # The second pass generates a dummy entry for each header file.
216c582b7e3Smrg    tr ' ' '
217c582b7e3Smrg' < "$tmpdepfile" \
218c582b7e3Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
21919019ffeSmrg   >> "$depfile"
220c582b7e3Smrg  else
221c582b7e3Smrg    # The sourcefile does not contain any dependencies, so just
222c582b7e3Smrg    # store a dummy comment line, to avoid errors with the Makefile
223c582b7e3Smrg    # "include basename.Plo" scheme.
224c582b7e3Smrg    echo "#dummy" > "$depfile"
225c582b7e3Smrg  fi
226c582b7e3Smrg  rm -f "$tmpdepfile"
227c582b7e3Smrg  ;;
228c582b7e3Smrg
229c582b7e3Smrgaix)
230c582b7e3Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
231c582b7e3Smrg  # in a .u file.  In older versions, this file always lives in the
232c582b7e3Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
233c582b7e3Smrg  # start of each line; $object doesn't have directory information.
234c582b7e3Smrg  # Version 6 uses the directory in both cases.
235c582b7e3Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
236c582b7e3Smrg  test "x$dir" = "x$object" && dir=
237c582b7e3Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
238c582b7e3Smrg  if test "$libtool" = yes; then
239c582b7e3Smrg    tmpdepfile1=$dir$base.u
240c582b7e3Smrg    tmpdepfile2=$base.u
241c582b7e3Smrg    tmpdepfile3=$dir.libs/$base.u
242c582b7e3Smrg    "$@" -Wc,-M
243c582b7e3Smrg  else
244c582b7e3Smrg    tmpdepfile1=$dir$base.u
245c582b7e3Smrg    tmpdepfile2=$dir$base.u
246c582b7e3Smrg    tmpdepfile3=$dir$base.u
247c582b7e3Smrg    "$@" -M
248c582b7e3Smrg  fi
249c582b7e3Smrg  stat=$?
250c582b7e3Smrg
251c582b7e3Smrg  if test $stat -eq 0; then :
252c582b7e3Smrg  else
253c582b7e3Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
254c582b7e3Smrg    exit $stat
255c582b7e3Smrg  fi
256c582b7e3Smrg
257c582b7e3Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
258c582b7e3Smrg  do
259c582b7e3Smrg    test -f "$tmpdepfile" && break
260c582b7e3Smrg  done
261c582b7e3Smrg  if test -f "$tmpdepfile"; then
262c582b7e3Smrg    # Each line is of the form `foo.o: dependent.h'.
263c582b7e3Smrg    # Do two passes, one to just change these to
264c582b7e3Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
265c582b7e3Smrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
266c582b7e3Smrg    # That's a tab and a space in the [].
267c582b7e3Smrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
268c582b7e3Smrg  else
269c582b7e3Smrg    # The sourcefile does not contain any dependencies, so just
270c582b7e3Smrg    # store a dummy comment line, to avoid errors with the Makefile
271c582b7e3Smrg    # "include basename.Plo" scheme.
272c582b7e3Smrg    echo "#dummy" > "$depfile"
273c582b7e3Smrg  fi
274c582b7e3Smrg  rm -f "$tmpdepfile"
275c582b7e3Smrg  ;;
276c582b7e3Smrg
277c582b7e3Smrgicc)
278c582b7e3Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
279c582b7e3Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
280c582b7e3Smrg  # ICC 7.0 will fill foo.d with something like
281c582b7e3Smrg  #    foo.o: sub/foo.c
282c582b7e3Smrg  #    foo.o: sub/foo.h
283c582b7e3Smrg  # which is wrong.  We want:
284c582b7e3Smrg  #    sub/foo.o: sub/foo.c
285c582b7e3Smrg  #    sub/foo.o: sub/foo.h
286c582b7e3Smrg  #    sub/foo.c:
287c582b7e3Smrg  #    sub/foo.h:
288c582b7e3Smrg  # ICC 7.1 will output
289c582b7e3Smrg  #    foo.o: sub/foo.c sub/foo.h
290c582b7e3Smrg  # and will wrap long lines using \ :
291c582b7e3Smrg  #    foo.o: sub/foo.c ... \
292c582b7e3Smrg  #     sub/foo.h ... \
293c582b7e3Smrg  #     ...
294c582b7e3Smrg
295c582b7e3Smrg  "$@" -MD -MF "$tmpdepfile"
296c582b7e3Smrg  stat=$?
297c582b7e3Smrg  if test $stat -eq 0; then :
298c582b7e3Smrg  else
299c582b7e3Smrg    rm -f "$tmpdepfile"
300c582b7e3Smrg    exit $stat
301c582b7e3Smrg  fi
302c582b7e3Smrg  rm -f "$depfile"
303c582b7e3Smrg  # Each line is of the form `foo.o: dependent.h',
304c582b7e3Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
305c582b7e3Smrg  # Do two passes, one to just change these to
306c582b7e3Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
307c582b7e3Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
308c582b7e3Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
309c582b7e3Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
310c582b7e3Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
311c582b7e3Smrg    sed -e 's/$/ :/' >> "$depfile"
312c582b7e3Smrg  rm -f "$tmpdepfile"
313c582b7e3Smrg  ;;
314c582b7e3Smrg
315c582b7e3Smrghp2)
316c582b7e3Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
317c582b7e3Smrg  # compilers, which have integrated preprocessors.  The correct option
318c582b7e3Smrg  # to use with these is +Maked; it writes dependencies to a file named
319c582b7e3Smrg  # 'foo.d', which lands next to the object file, wherever that
320c582b7e3Smrg  # happens to be.
321c582b7e3Smrg  # Much of this is similar to the tru64 case; see comments there.
322c582b7e3Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
323c582b7e3Smrg  test "x$dir" = "x$object" && dir=
324c582b7e3Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
325c582b7e3Smrg  if test "$libtool" = yes; then
326c582b7e3Smrg    tmpdepfile1=$dir$base.d
327c582b7e3Smrg    tmpdepfile2=$dir.libs/$base.d
328c582b7e3Smrg    "$@" -Wc,+Maked
329c582b7e3Smrg  else
330c582b7e3Smrg    tmpdepfile1=$dir$base.d
331c582b7e3Smrg    tmpdepfile2=$dir$base.d
332c582b7e3Smrg    "$@" +Maked
333c582b7e3Smrg  fi
334c582b7e3Smrg  stat=$?
335c582b7e3Smrg  if test $stat -eq 0; then :
336c582b7e3Smrg  else
337c582b7e3Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
338c582b7e3Smrg     exit $stat
339c582b7e3Smrg  fi
340c582b7e3Smrg
341c582b7e3Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
342c582b7e3Smrg  do
343c582b7e3Smrg    test -f "$tmpdepfile" && break
344c582b7e3Smrg  done
345c582b7e3Smrg  if test -f "$tmpdepfile"; then
346c582b7e3Smrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
347c582b7e3Smrg    # Add `dependent.h:' lines.
34819019ffeSmrg    sed -ne '2,${
34919019ffeSmrg	       s/^ *//
35019019ffeSmrg	       s/ \\*$//
35119019ffeSmrg	       s/$/:/
35219019ffeSmrg	       p
35319019ffeSmrg	     }' "$tmpdepfile" >> "$depfile"
354c582b7e3Smrg  else
355c582b7e3Smrg    echo "#dummy" > "$depfile"
356c582b7e3Smrg  fi
357c582b7e3Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
358c582b7e3Smrg  ;;
359c582b7e3Smrg
360c582b7e3Smrgtru64)
361c582b7e3Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
362c582b7e3Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
363c582b7e3Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
364c582b7e3Smrg   # dependencies in `foo.d' instead, so we check for that too.
365c582b7e3Smrg   # Subdirectories are respected.
366c582b7e3Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
367c582b7e3Smrg   test "x$dir" = "x$object" && dir=
368c582b7e3Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
369c582b7e3Smrg
370c582b7e3Smrg   if test "$libtool" = yes; then
371c582b7e3Smrg      # With Tru64 cc, shared objects can also be used to make a
372c582b7e3Smrg      # static library.  This mechanism is used in libtool 1.4 series to
373c582b7e3Smrg      # handle both shared and static libraries in a single compilation.
374c582b7e3Smrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
375c582b7e3Smrg      #
376c582b7e3Smrg      # With libtool 1.5 this exception was removed, and libtool now
377c582b7e3Smrg      # generates 2 separate objects for the 2 libraries.  These two
378c582b7e3Smrg      # compilations output dependencies in $dir.libs/$base.o.d and
379c582b7e3Smrg      # in $dir$base.o.d.  We have to check for both files, because
380c582b7e3Smrg      # one of the two compilations can be disabled.  We should prefer
381c582b7e3Smrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
382c582b7e3Smrg      # automatically cleaned when .libs/ is deleted, while ignoring
383c582b7e3Smrg      # the former would cause a distcleancheck panic.
384c582b7e3Smrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
385c582b7e3Smrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
386c582b7e3Smrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
387c582b7e3Smrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
388c582b7e3Smrg      "$@" -Wc,-MD
389c582b7e3Smrg   else
390c582b7e3Smrg      tmpdepfile1=$dir$base.o.d
391c582b7e3Smrg      tmpdepfile2=$dir$base.d
392c582b7e3Smrg      tmpdepfile3=$dir$base.d
393c582b7e3Smrg      tmpdepfile4=$dir$base.d
394c582b7e3Smrg      "$@" -MD
395c582b7e3Smrg   fi
396c582b7e3Smrg
397c582b7e3Smrg   stat=$?
398c582b7e3Smrg   if test $stat -eq 0; then :
399c582b7e3Smrg   else
400c582b7e3Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
401c582b7e3Smrg      exit $stat
402c582b7e3Smrg   fi
403c582b7e3Smrg
404c582b7e3Smrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
405c582b7e3Smrg   do
406c582b7e3Smrg     test -f "$tmpdepfile" && break
407c582b7e3Smrg   done
408c582b7e3Smrg   if test -f "$tmpdepfile"; then
409c582b7e3Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
410c582b7e3Smrg      # That's a tab and a space in the [].
411c582b7e3Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
412c582b7e3Smrg   else
413c582b7e3Smrg      echo "#dummy" > "$depfile"
414c582b7e3Smrg   fi
415c582b7e3Smrg   rm -f "$tmpdepfile"
416c582b7e3Smrg   ;;
417c582b7e3Smrg
41842a55b46Smrgmsvc7)
41942a55b46Smrg  if test "$libtool" = yes; then
42042a55b46Smrg    showIncludes=-Wc,-showIncludes
42142a55b46Smrg  else
42242a55b46Smrg    showIncludes=-showIncludes
42342a55b46Smrg  fi
42442a55b46Smrg  "$@" $showIncludes > "$tmpdepfile"
42542a55b46Smrg  stat=$?
42642a55b46Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
42742a55b46Smrg  if test "$stat" = 0; then :
42842a55b46Smrg  else
42942a55b46Smrg    rm -f "$tmpdepfile"
43042a55b46Smrg    exit $stat
43142a55b46Smrg  fi
43242a55b46Smrg  rm -f "$depfile"
43342a55b46Smrg  echo "$object : \\" > "$depfile"
43442a55b46Smrg  # The first sed program below extracts the file names and escapes
43542a55b46Smrg  # backslashes for cygpath.  The second sed program outputs the file
43642a55b46Smrg  # name when reading, but also accumulates all include files in the
43742a55b46Smrg  # hold buffer in order to output them again at the end.  This only
43842a55b46Smrg  # works with sed implementations that can handle large buffers.
43942a55b46Smrg  sed < "$tmpdepfile" -n '
44042a55b46Smrg/^Note: including file:  *\(.*\)/ {
44142a55b46Smrg  s//\1/
44242a55b46Smrg  s/\\/\\\\/g
44342a55b46Smrg  p
44442a55b46Smrg}' | $cygpath_u | sort -u | sed -n '
44542a55b46Smrgs/ /\\ /g
44642a55b46Smrgs/\(.*\)/	\1 \\/p
44742a55b46Smrgs/.\(.*\) \\/\1:/
44842a55b46SmrgH
44942a55b46Smrg$ {
45042a55b46Smrg  s/.*/	/
45142a55b46Smrg  G
45242a55b46Smrg  p
45342a55b46Smrg}' >> "$depfile"
45442a55b46Smrg  rm -f "$tmpdepfile"
45542a55b46Smrg  ;;
45642a55b46Smrg
45742a55b46Smrgmsvc7msys)
45842a55b46Smrg  # This case exists only to let depend.m4 do its work.  It works by
45942a55b46Smrg  # looking at the text of this script.  This case will never be run,
46042a55b46Smrg  # since it is checked for above.
46142a55b46Smrg  exit 1
46242a55b46Smrg  ;;
46342a55b46Smrg
464c582b7e3Smrg#nosideeffect)
465c582b7e3Smrg  # This comment above is used by automake to tell side-effect
466c582b7e3Smrg  # dependency tracking mechanisms from slower ones.
467c582b7e3Smrg
468c582b7e3Smrgdashmstdout)
469c582b7e3Smrg  # Important note: in order to support this mode, a compiler *must*
470c582b7e3Smrg  # always write the preprocessed file to stdout, regardless of -o.
471c582b7e3Smrg  "$@" || exit $?
472c582b7e3Smrg
473c582b7e3Smrg  # Remove the call to Libtool.
474c582b7e3Smrg  if test "$libtool" = yes; then
47519019ffeSmrg    while test "X$1" != 'X--mode=compile'; do
476c582b7e3Smrg      shift
477c582b7e3Smrg    done
478c582b7e3Smrg    shift
479c582b7e3Smrg  fi
480c582b7e3Smrg
481c582b7e3Smrg  # Remove `-o $object'.
482c582b7e3Smrg  IFS=" "
483c582b7e3Smrg  for arg
484c582b7e3Smrg  do
485c582b7e3Smrg    case $arg in
486c582b7e3Smrg    -o)
487c582b7e3Smrg      shift
488c582b7e3Smrg      ;;
489c582b7e3Smrg    $object)
490c582b7e3Smrg      shift
491c582b7e3Smrg      ;;
492c582b7e3Smrg    *)
493c582b7e3Smrg      set fnord "$@" "$arg"
494c582b7e3Smrg      shift # fnord
495c582b7e3Smrg      shift # $arg
496c582b7e3Smrg      ;;
497c582b7e3Smrg    esac
498c582b7e3Smrg  done
499c582b7e3Smrg
500c582b7e3Smrg  test -z "$dashmflag" && dashmflag=-M
501c582b7e3Smrg  # Require at least two characters before searching for `:'
502c582b7e3Smrg  # in the target name.  This is to cope with DOS-style filenames:
503c582b7e3Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
504c582b7e3Smrg  "$@" $dashmflag |
505c582b7e3Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
506c582b7e3Smrg  rm -f "$depfile"
507c582b7e3Smrg  cat < "$tmpdepfile" > "$depfile"
508c582b7e3Smrg  tr ' ' '
509c582b7e3Smrg' < "$tmpdepfile" | \
510c582b7e3Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
511c582b7e3Smrg## correctly.  Breaking it into two sed invocations is a workaround.
512c582b7e3Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
513c582b7e3Smrg  rm -f "$tmpdepfile"
514c582b7e3Smrg  ;;
515c582b7e3Smrg
516c582b7e3SmrgdashXmstdout)
517c582b7e3Smrg  # This case only exists to satisfy depend.m4.  It is never actually
518c582b7e3Smrg  # run, as this mode is specially recognized in the preamble.
519c582b7e3Smrg  exit 1
520c582b7e3Smrg  ;;
521c582b7e3Smrg
522c582b7e3Smrgmakedepend)
523c582b7e3Smrg  "$@" || exit $?
524c582b7e3Smrg  # Remove any Libtool call
525c582b7e3Smrg  if test "$libtool" = yes; then
52619019ffeSmrg    while test "X$1" != 'X--mode=compile'; do
527c582b7e3Smrg      shift
528c582b7e3Smrg    done
529c582b7e3Smrg    shift
530c582b7e3Smrg  fi
531c582b7e3Smrg  # X makedepend
532c582b7e3Smrg  shift
53319019ffeSmrg  cleared=no eat=no
53419019ffeSmrg  for arg
53519019ffeSmrg  do
536c582b7e3Smrg    case $cleared in
537c582b7e3Smrg    no)
538c582b7e3Smrg      set ""; shift
539c582b7e3Smrg      cleared=yes ;;
540c582b7e3Smrg    esac
54119019ffeSmrg    if test $eat = yes; then
54219019ffeSmrg      eat=no
54319019ffeSmrg      continue
54419019ffeSmrg    fi
545c582b7e3Smrg    case "$arg" in
546c582b7e3Smrg    -D*|-I*)
547c582b7e3Smrg      set fnord "$@" "$arg"; shift ;;
548c582b7e3Smrg    # Strip any option that makedepend may not understand.  Remove
549c582b7e3Smrg    # the object too, otherwise makedepend will parse it as a source file.
55019019ffeSmrg    -arch)
55119019ffeSmrg      eat=yes ;;
552c582b7e3Smrg    -*|$object)
553c582b7e3Smrg      ;;
554c582b7e3Smrg    *)
555c582b7e3Smrg      set fnord "$@" "$arg"; shift ;;
556c582b7e3Smrg    esac
557c582b7e3Smrg  done
55819019ffeSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
559c582b7e3Smrg  touch "$tmpdepfile"
560c582b7e3Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
561c582b7e3Smrg  rm -f "$depfile"
56242a55b46Smrg  # makedepend may prepend the VPATH from the source file name to the object.
56342a55b46Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
56442a55b46Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
565c582b7e3Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
566c582b7e3Smrg' | \
567c582b7e3Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
568c582b7e3Smrg## correctly.  Breaking it into two sed invocations is a workaround.
569c582b7e3Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
570c582b7e3Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
571c582b7e3Smrg  ;;
572c582b7e3Smrg
573c582b7e3Smrgcpp)
574c582b7e3Smrg  # Important note: in order to support this mode, a compiler *must*
575c582b7e3Smrg  # always write the preprocessed file to stdout.
576c582b7e3Smrg  "$@" || exit $?
577c582b7e3Smrg
578c582b7e3Smrg  # Remove the call to Libtool.
579c582b7e3Smrg  if test "$libtool" = yes; then
58019019ffeSmrg    while test "X$1" != 'X--mode=compile'; do
581c582b7e3Smrg      shift
582c582b7e3Smrg    done
583c582b7e3Smrg    shift
584c582b7e3Smrg  fi
585c582b7e3Smrg
586c582b7e3Smrg  # Remove `-o $object'.
587c582b7e3Smrg  IFS=" "
588c582b7e3Smrg  for arg
589c582b7e3Smrg  do
590c582b7e3Smrg    case $arg in
591c582b7e3Smrg    -o)
592c582b7e3Smrg      shift
593c582b7e3Smrg      ;;
594c582b7e3Smrg    $object)
595c582b7e3Smrg      shift
596c582b7e3Smrg      ;;
597c582b7e3Smrg    *)
598c582b7e3Smrg      set fnord "$@" "$arg"
599c582b7e3Smrg      shift # fnord
600c582b7e3Smrg      shift # $arg
601c582b7e3Smrg      ;;
602c582b7e3Smrg    esac
603c582b7e3Smrg  done
604c582b7e3Smrg
605c582b7e3Smrg  "$@" -E |
606c582b7e3Smrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
607c582b7e3Smrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
608c582b7e3Smrg    sed '$ s: \\$::' > "$tmpdepfile"
609c582b7e3Smrg  rm -f "$depfile"
610c582b7e3Smrg  echo "$object : \\" > "$depfile"
611c582b7e3Smrg  cat < "$tmpdepfile" >> "$depfile"
612c582b7e3Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
613c582b7e3Smrg  rm -f "$tmpdepfile"
614c582b7e3Smrg  ;;
615c582b7e3Smrg
616c582b7e3Smrgmsvisualcpp)
617c582b7e3Smrg  # Important note: in order to support this mode, a compiler *must*
61819019ffeSmrg  # always write the preprocessed file to stdout.
619c582b7e3Smrg  "$@" || exit $?
62019019ffeSmrg
62119019ffeSmrg  # Remove the call to Libtool.
62219019ffeSmrg  if test "$libtool" = yes; then
62319019ffeSmrg    while test "X$1" != 'X--mode=compile'; do
62419019ffeSmrg      shift
62519019ffeSmrg    done
62619019ffeSmrg    shift
62719019ffeSmrg  fi
62819019ffeSmrg
629c582b7e3Smrg  IFS=" "
630c582b7e3Smrg  for arg
631c582b7e3Smrg  do
632c582b7e3Smrg    case "$arg" in
63319019ffeSmrg    -o)
63419019ffeSmrg      shift
63519019ffeSmrg      ;;
63619019ffeSmrg    $object)
63719019ffeSmrg      shift
63819019ffeSmrg      ;;
639c582b7e3Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
640c582b7e3Smrg	set fnord "$@"
641c582b7e3Smrg	shift
642c582b7e3Smrg	shift
643c582b7e3Smrg	;;
644c582b7e3Smrg    *)
645c582b7e3Smrg	set fnord "$@" "$arg"
646c582b7e3Smrg	shift
647c582b7e3Smrg	shift
648c582b7e3Smrg	;;
649c582b7e3Smrg    esac
650c582b7e3Smrg  done
65119019ffeSmrg  "$@" -E 2>/dev/null |
65219019ffeSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
653c582b7e3Smrg  rm -f "$depfile"
654c582b7e3Smrg  echo "$object : \\" > "$depfile"
65519019ffeSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
656c582b7e3Smrg  echo "	" >> "$depfile"
65719019ffeSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
658c582b7e3Smrg  rm -f "$tmpdepfile"
659c582b7e3Smrg  ;;
660c582b7e3Smrg
66119019ffeSmrgmsvcmsys)
66219019ffeSmrg  # This case exists only to let depend.m4 do its work.  It works by
66319019ffeSmrg  # looking at the text of this script.  This case will never be run,
66419019ffeSmrg  # since it is checked for above.
66519019ffeSmrg  exit 1
66619019ffeSmrg  ;;
66719019ffeSmrg
668c582b7e3Smrgnone)
669c582b7e3Smrg  exec "$@"
670c582b7e3Smrg  ;;
671c582b7e3Smrg
672c582b7e3Smrg*)
673c582b7e3Smrg  echo "Unknown depmode $depmode" 1>&2
674c582b7e3Smrg  exit 1
675c582b7e3Smrg  ;;
676c582b7e3Smrgesac
677c582b7e3Smrg
678c582b7e3Smrgexit 0
679c582b7e3Smrg
680c582b7e3Smrg# Local Variables:
681c582b7e3Smrg# mode: shell-script
682c582b7e3Smrg# sh-indentation: 2
683c582b7e3Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
684c582b7e3Smrg# time-stamp-start: "scriptversion="
685c582b7e3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
68619019ffeSmrg# time-stamp-time-zone: "UTC"
68719019ffeSmrg# time-stamp-end: "; # UTC"
688c582b7e3Smrg# End:
689