1b85037dbSmrg#! /bin/sh
2b85037dbSmrg# depcomp - compile a program generating dependencies as side-effects
3b85037dbSmrg
428515619Smrgscriptversion=2012-03-27.16; # UTC
5b85037dbSmrg
628515619Smrg# Copyright (C) 1999-2012 Free Software Foundation, Inc.
7b85037dbSmrg
8b85037dbSmrg# This program is free software; you can redistribute it and/or modify
9b85037dbSmrg# it under the terms of the GNU General Public License as published by
10b85037dbSmrg# the Free Software Foundation; either version 2, or (at your option)
11b85037dbSmrg# any later version.
12b85037dbSmrg
13b85037dbSmrg# This program is distributed in the hope that it will be useful,
14b85037dbSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15b85037dbSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16b85037dbSmrg# GNU General Public License for more details.
17b85037dbSmrg
18b85037dbSmrg# You should have received a copy of the GNU General Public License
19b85037dbSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20b85037dbSmrg
21b85037dbSmrg# As a special exception to the GNU General Public License, if you
22b85037dbSmrg# distribute this file as part of a program that contains a
23b85037dbSmrg# configuration script generated by Autoconf, you may include it under
24b85037dbSmrg# the same distribution terms that you use for the rest of that program.
25b85037dbSmrg
26b85037dbSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27b85037dbSmrg
28b85037dbSmrgcase $1 in
29b85037dbSmrg  '')
3028515619Smrg     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31b85037dbSmrg     exit 1;
32b85037dbSmrg     ;;
33b85037dbSmrg  -h | --h*)
34b85037dbSmrg    cat <<\EOF
35b85037dbSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36b85037dbSmrg
37b85037dbSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38b85037dbSmrgas side-effects.
39b85037dbSmrg
40b85037dbSmrgEnvironment variables:
41b85037dbSmrg  depmode     Dependency tracking mode.
4228515619Smrg  source      Source file read by 'PROGRAMS ARGS'.
4328515619Smrg  object      Object file output by 'PROGRAMS ARGS'.
44b85037dbSmrg  DEPDIR      directory where to store dependencies.
45b85037dbSmrg  depfile     Dependency file to output.
4628515619Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
47b85037dbSmrg  libtool     Whether libtool is used (yes/no).
48b85037dbSmrg
49b85037dbSmrgReport bugs to <bug-automake@gnu.org>.
50b85037dbSmrgEOF
51b85037dbSmrg    exit $?
52b85037dbSmrg    ;;
53b85037dbSmrg  -v | --v*)
54b85037dbSmrg    echo "depcomp $scriptversion"
55b85037dbSmrg    exit $?
56b85037dbSmrg    ;;
57b85037dbSmrgesac
58b85037dbSmrg
5928515619Smrg# A tabulation character.
6028515619Smrgtab='	'
6128515619Smrg# A newline character.
6228515619Smrgnl='
6328515619Smrg'
6428515619Smrg
65b85037dbSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
66b85037dbSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
67b85037dbSmrg  exit 1
68b85037dbSmrgfi
69b85037dbSmrg
70b85037dbSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
71b85037dbSmrgdepfile=${depfile-`echo "$object" |
72b85037dbSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
73b85037dbSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
74b85037dbSmrg
75b85037dbSmrgrm -f "$tmpdepfile"
76b85037dbSmrg
77b85037dbSmrg# Some modes work just like other modes, but use different flags.  We
78b85037dbSmrg# parameterize here, but still list the modes in the big case below,
79b85037dbSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
80b85037dbSmrg# here, because this file can only contain one case statement.
81b85037dbSmrgif test "$depmode" = hp; then
82b85037dbSmrg  # HP compiler uses -M and no extra arg.
83b85037dbSmrg  gccflag=-M
84b85037dbSmrg  depmode=gcc
85b85037dbSmrgfi
86b85037dbSmrg
87b85037dbSmrgif test "$depmode" = dashXmstdout; then
88b85037dbSmrg   # This is just like dashmstdout with a different argument.
89b85037dbSmrg   dashmflag=-xM
90b85037dbSmrg   depmode=dashmstdout
91b85037dbSmrgfi
92b85037dbSmrg
93b85037dbSmrgcygpath_u="cygpath -u -f -"
94b85037dbSmrgif test "$depmode" = msvcmsys; then
95b85037dbSmrg   # This is just like msvisualcpp but w/o cygpath translation.
96b85037dbSmrg   # Just convert the backslash-escaped backslashes to single forward
97b85037dbSmrg   # slashes to satisfy depend.m4
9828515619Smrg   cygpath_u='sed s,\\\\,/,g'
99b85037dbSmrg   depmode=msvisualcpp
100b85037dbSmrgfi
101b85037dbSmrg
10228515619Smrgif test "$depmode" = msvc7msys; then
10328515619Smrg   # This is just like msvc7 but w/o cygpath translation.
10428515619Smrg   # Just convert the backslash-escaped backslashes to single forward
10528515619Smrg   # slashes to satisfy depend.m4
10628515619Smrg   cygpath_u='sed s,\\\\,/,g'
10728515619Smrg   depmode=msvc7
10828515619Smrgfi
10928515619Smrg
11028515619Smrgif test "$depmode" = xlc; then
11128515619Smrg   # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency informations.
11228515619Smrg   gccflag=-qmakedep=gcc,-MF
11328515619Smrg   depmode=gcc
11428515619Smrgfi
11528515619Smrg
116b85037dbSmrgcase "$depmode" in
117b85037dbSmrggcc3)
118b85037dbSmrg## gcc 3 implements dependency tracking that does exactly what
119b85037dbSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
120b85037dbSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
121b85037dbSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
122b85037dbSmrg## the command line argument order; so add the flags where they
123b85037dbSmrg## appear in depend2.am.  Note that the slowdown incurred here
124b85037dbSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
125b85037dbSmrg  for arg
126b85037dbSmrg  do
127b85037dbSmrg    case $arg in
128b85037dbSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
129b85037dbSmrg    *)  set fnord "$@" "$arg" ;;
130b85037dbSmrg    esac
131b85037dbSmrg    shift # fnord
132b85037dbSmrg    shift # $arg
133b85037dbSmrg  done
134b85037dbSmrg  "$@"
135b85037dbSmrg  stat=$?
136b85037dbSmrg  if test $stat -eq 0; then :
137b85037dbSmrg  else
138b85037dbSmrg    rm -f "$tmpdepfile"
139b85037dbSmrg    exit $stat
140b85037dbSmrg  fi
141b85037dbSmrg  mv "$tmpdepfile" "$depfile"
142b85037dbSmrg  ;;
143b85037dbSmrg
144b85037dbSmrggcc)
145b85037dbSmrg## There are various ways to get dependency output from gcc.  Here's
146b85037dbSmrg## why we pick this rather obscure method:
147b85037dbSmrg## - Don't want to use -MD because we'd like the dependencies to end
148b85037dbSmrg##   up in a subdir.  Having to rename by hand is ugly.
149b85037dbSmrg##   (We might end up doing this anyway to support other compilers.)
150b85037dbSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
151b85037dbSmrg##   -MM, not -M (despite what the docs say).
152b85037dbSmrg## - Using -M directly means running the compiler twice (even worse
153b85037dbSmrg##   than renaming).
154b85037dbSmrg  if test -z "$gccflag"; then
155b85037dbSmrg    gccflag=-MD,
156b85037dbSmrg  fi
157b85037dbSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
158b85037dbSmrg  stat=$?
159b85037dbSmrg  if test $stat -eq 0; then :
160b85037dbSmrg  else
161b85037dbSmrg    rm -f "$tmpdepfile"
162b85037dbSmrg    exit $stat
163b85037dbSmrg  fi
164b85037dbSmrg  rm -f "$depfile"
165b85037dbSmrg  echo "$object : \\" > "$depfile"
166b85037dbSmrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
167b85037dbSmrg## The second -e expression handles DOS-style file names with drive letters.
168b85037dbSmrg  sed -e 's/^[^:]*: / /' \
169b85037dbSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
17028515619Smrg## This next piece of magic avoids the "deleted header file" problem.
171b85037dbSmrg## The problem is that when a header file which appears in a .P file
172b85037dbSmrg## is deleted, the dependency causes make to die (because there is
173b85037dbSmrg## typically no way to rebuild the header).  We avoid this by adding
174b85037dbSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
175b85037dbSmrg## this for us directly.
17628515619Smrg  tr ' ' "$nl" < "$tmpdepfile" |
17728515619Smrg## Some versions of gcc put a space before the ':'.  On the theory
178b85037dbSmrg## that the space means something, we add a space to the output as
17928515619Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
18028515619Smrg## to the object.  Take care to not repeat it in the output.
181b85037dbSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
182b85037dbSmrg## correctly.  Breaking it into two sed invocations is a workaround.
18328515619Smrg    sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
18428515619Smrg      | sed -e 's/$/ :/' >> "$depfile"
185b85037dbSmrg  rm -f "$tmpdepfile"
186b85037dbSmrg  ;;
187b85037dbSmrg
188b85037dbSmrghp)
189b85037dbSmrg  # This case exists only to let depend.m4 do its work.  It works by
190b85037dbSmrg  # looking at the text of this script.  This case will never be run,
191b85037dbSmrg  # since it is checked for above.
192b85037dbSmrg  exit 1
193b85037dbSmrg  ;;
194b85037dbSmrg
195b85037dbSmrgsgi)
196b85037dbSmrg  if test "$libtool" = yes; then
197b85037dbSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
198b85037dbSmrg  else
199b85037dbSmrg    "$@" -MDupdate "$tmpdepfile"
200b85037dbSmrg  fi
201b85037dbSmrg  stat=$?
202b85037dbSmrg  if test $stat -eq 0; then :
203b85037dbSmrg  else
204b85037dbSmrg    rm -f "$tmpdepfile"
205b85037dbSmrg    exit $stat
206b85037dbSmrg  fi
207b85037dbSmrg  rm -f "$depfile"
208b85037dbSmrg
209b85037dbSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
210b85037dbSmrg    echo "$object : \\" > "$depfile"
211b85037dbSmrg
212b85037dbSmrg    # Clip off the initial element (the dependent).  Don't try to be
213b85037dbSmrg    # clever and replace this with sed code, as IRIX sed won't handle
214b85037dbSmrg    # lines with more than a fixed number of characters (4096 in
215b85037dbSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
21628515619Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
217b85037dbSmrg    # dependency line.
21828515619Smrg    tr ' ' "$nl" < "$tmpdepfile" \
219b85037dbSmrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
22028515619Smrg    tr "$nl" ' ' >> "$depfile"
221b85037dbSmrg    echo >> "$depfile"
222b85037dbSmrg
223b85037dbSmrg    # The second pass generates a dummy entry for each header file.
22428515619Smrg    tr ' ' "$nl" < "$tmpdepfile" \
225b85037dbSmrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
226b85037dbSmrg   >> "$depfile"
227b85037dbSmrg  else
228b85037dbSmrg    # The sourcefile does not contain any dependencies, so just
229b85037dbSmrg    # store a dummy comment line, to avoid errors with the Makefile
230b85037dbSmrg    # "include basename.Plo" scheme.
231b85037dbSmrg    echo "#dummy" > "$depfile"
232b85037dbSmrg  fi
233b85037dbSmrg  rm -f "$tmpdepfile"
234b85037dbSmrg  ;;
235b85037dbSmrg
23628515619Smrgxlc)
23728515619Smrg  # This case exists only to let depend.m4 do its work.  It works by
23828515619Smrg  # looking at the text of this script.  This case will never be run,
23928515619Smrg  # since it is checked for above.
24028515619Smrg  exit 1
24128515619Smrg  ;;
24228515619Smrg
243b85037dbSmrgaix)
244b85037dbSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
245b85037dbSmrg  # in a .u file.  In older versions, this file always lives in the
24628515619Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
247b85037dbSmrg  # start of each line; $object doesn't have directory information.
248b85037dbSmrg  # Version 6 uses the directory in both cases.
249b85037dbSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
250b85037dbSmrg  test "x$dir" = "x$object" && dir=
251b85037dbSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
252b85037dbSmrg  if test "$libtool" = yes; then
253b85037dbSmrg    tmpdepfile1=$dir$base.u
254b85037dbSmrg    tmpdepfile2=$base.u
255b85037dbSmrg    tmpdepfile3=$dir.libs/$base.u
256b85037dbSmrg    "$@" -Wc,-M
257b85037dbSmrg  else
258b85037dbSmrg    tmpdepfile1=$dir$base.u
259b85037dbSmrg    tmpdepfile2=$dir$base.u
260b85037dbSmrg    tmpdepfile3=$dir$base.u
261b85037dbSmrg    "$@" -M
262b85037dbSmrg  fi
263b85037dbSmrg  stat=$?
264b85037dbSmrg
265b85037dbSmrg  if test $stat -eq 0; then :
266b85037dbSmrg  else
267b85037dbSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
268b85037dbSmrg    exit $stat
269b85037dbSmrg  fi
270b85037dbSmrg
271b85037dbSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
272b85037dbSmrg  do
273b85037dbSmrg    test -f "$tmpdepfile" && break
274b85037dbSmrg  done
275b85037dbSmrg  if test -f "$tmpdepfile"; then
27628515619Smrg    # Each line is of the form 'foo.o: dependent.h'.
277b85037dbSmrg    # Do two passes, one to just change these to
27828515619Smrg    # '$object: dependent.h' and one to simply 'dependent.h:'.
279b85037dbSmrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
28028515619Smrg    sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
281b85037dbSmrg  else
282b85037dbSmrg    # The sourcefile does not contain any dependencies, so just
283b85037dbSmrg    # store a dummy comment line, to avoid errors with the Makefile
284b85037dbSmrg    # "include basename.Plo" scheme.
285b85037dbSmrg    echo "#dummy" > "$depfile"
286b85037dbSmrg  fi
287b85037dbSmrg  rm -f "$tmpdepfile"
288b85037dbSmrg  ;;
289b85037dbSmrg
290b85037dbSmrgicc)
29128515619Smrg  # Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'.
29228515619Smrg  # However on
29328515619Smrg  #    $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c
294b85037dbSmrg  # ICC 7.0 will fill foo.d with something like
295b85037dbSmrg  #    foo.o: sub/foo.c
296b85037dbSmrg  #    foo.o: sub/foo.h
29728515619Smrg  # which is wrong.  We want
298b85037dbSmrg  #    sub/foo.o: sub/foo.c
299b85037dbSmrg  #    sub/foo.o: sub/foo.h
300b85037dbSmrg  #    sub/foo.c:
301b85037dbSmrg  #    sub/foo.h:
302b85037dbSmrg  # ICC 7.1 will output
303b85037dbSmrg  #    foo.o: sub/foo.c sub/foo.h
30428515619Smrg  # and will wrap long lines using '\':
305b85037dbSmrg  #    foo.o: sub/foo.c ... \
306b85037dbSmrg  #     sub/foo.h ... \
307b85037dbSmrg  #     ...
30828515619Smrg  # tcc 0.9.26 (FIXME still under development at the moment of writing)
30928515619Smrg  # will emit a similar output, but also prepend the continuation lines
31028515619Smrg  # with horizontal tabulation characters.
311b85037dbSmrg  "$@" -MD -MF "$tmpdepfile"
312b85037dbSmrg  stat=$?
313b85037dbSmrg  if test $stat -eq 0; then :
314b85037dbSmrg  else
315b85037dbSmrg    rm -f "$tmpdepfile"
316b85037dbSmrg    exit $stat
317b85037dbSmrg  fi
318b85037dbSmrg  rm -f "$depfile"
31928515619Smrg  # Each line is of the form 'foo.o: dependent.h',
32028515619Smrg  # or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'.
321b85037dbSmrg  # Do two passes, one to just change these to
32228515619Smrg  # '$object: dependent.h' and one to simply 'dependent.h:'.
32328515619Smrg  sed -e "s/^[ $tab][ $tab]*/  /" -e "s,^[^:]*:,$object :," \
32428515619Smrg    < "$tmpdepfile" > "$depfile"
32528515619Smrg  sed '
32628515619Smrg    s/[ '"$tab"'][ '"$tab"']*/ /g
32728515619Smrg    s/^ *//
32828515619Smrg    s/ *\\*$//
32928515619Smrg    s/^[^:]*: *//
33028515619Smrg    /^$/d
33128515619Smrg    /:$/d
33228515619Smrg    s/$/ :/
33328515619Smrg  ' < "$tmpdepfile" >> "$depfile"
334b85037dbSmrg  rm -f "$tmpdepfile"
335b85037dbSmrg  ;;
336b85037dbSmrg
337b85037dbSmrghp2)
338b85037dbSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
339b85037dbSmrg  # compilers, which have integrated preprocessors.  The correct option
340b85037dbSmrg  # to use with these is +Maked; it writes dependencies to a file named
341b85037dbSmrg  # 'foo.d', which lands next to the object file, wherever that
342b85037dbSmrg  # happens to be.
343b85037dbSmrg  # Much of this is similar to the tru64 case; see comments there.
344b85037dbSmrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
345b85037dbSmrg  test "x$dir" = "x$object" && dir=
346b85037dbSmrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
347b85037dbSmrg  if test "$libtool" = yes; then
348b85037dbSmrg    tmpdepfile1=$dir$base.d
349b85037dbSmrg    tmpdepfile2=$dir.libs/$base.d
350b85037dbSmrg    "$@" -Wc,+Maked
351b85037dbSmrg  else
352b85037dbSmrg    tmpdepfile1=$dir$base.d
353b85037dbSmrg    tmpdepfile2=$dir$base.d
354b85037dbSmrg    "$@" +Maked
355b85037dbSmrg  fi
356b85037dbSmrg  stat=$?
357b85037dbSmrg  if test $stat -eq 0; then :
358b85037dbSmrg  else
359b85037dbSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
360b85037dbSmrg     exit $stat
361b85037dbSmrg  fi
362b85037dbSmrg
363b85037dbSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
364b85037dbSmrg  do
365b85037dbSmrg    test -f "$tmpdepfile" && break
366b85037dbSmrg  done
367b85037dbSmrg  if test -f "$tmpdepfile"; then
368b85037dbSmrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
36928515619Smrg    # Add 'dependent.h:' lines.
370b85037dbSmrg    sed -ne '2,${
371b85037dbSmrg	       s/^ *//
372b85037dbSmrg	       s/ \\*$//
373b85037dbSmrg	       s/$/:/
374b85037dbSmrg	       p
375b85037dbSmrg	     }' "$tmpdepfile" >> "$depfile"
376b85037dbSmrg  else
377b85037dbSmrg    echo "#dummy" > "$depfile"
378b85037dbSmrg  fi
379b85037dbSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
380b85037dbSmrg  ;;
381b85037dbSmrg
382b85037dbSmrgtru64)
383b85037dbSmrg   # The Tru64 compiler uses -MD to generate dependencies as a side
38428515619Smrg   # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
385b85037dbSmrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
38628515619Smrg   # dependencies in 'foo.d' instead, so we check for that too.
387b85037dbSmrg   # Subdirectories are respected.
388b85037dbSmrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
389b85037dbSmrg   test "x$dir" = "x$object" && dir=
390b85037dbSmrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
391b85037dbSmrg
392b85037dbSmrg   if test "$libtool" = yes; then
393b85037dbSmrg      # With Tru64 cc, shared objects can also be used to make a
394b85037dbSmrg      # static library.  This mechanism is used in libtool 1.4 series to
395b85037dbSmrg      # handle both shared and static libraries in a single compilation.
396b85037dbSmrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
397b85037dbSmrg      #
398b85037dbSmrg      # With libtool 1.5 this exception was removed, and libtool now
399b85037dbSmrg      # generates 2 separate objects for the 2 libraries.  These two
400b85037dbSmrg      # compilations output dependencies in $dir.libs/$base.o.d and
401b85037dbSmrg      # in $dir$base.o.d.  We have to check for both files, because
402b85037dbSmrg      # one of the two compilations can be disabled.  We should prefer
403b85037dbSmrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
404b85037dbSmrg      # automatically cleaned when .libs/ is deleted, while ignoring
405b85037dbSmrg      # the former would cause a distcleancheck panic.
406b85037dbSmrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
407b85037dbSmrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
408b85037dbSmrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
409b85037dbSmrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
410b85037dbSmrg      "$@" -Wc,-MD
411b85037dbSmrg   else
412b85037dbSmrg      tmpdepfile1=$dir$base.o.d
413b85037dbSmrg      tmpdepfile2=$dir$base.d
414b85037dbSmrg      tmpdepfile3=$dir$base.d
415b85037dbSmrg      tmpdepfile4=$dir$base.d
416b85037dbSmrg      "$@" -MD
417b85037dbSmrg   fi
418b85037dbSmrg
419b85037dbSmrg   stat=$?
420b85037dbSmrg   if test $stat -eq 0; then :
421b85037dbSmrg   else
422b85037dbSmrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
423b85037dbSmrg      exit $stat
424b85037dbSmrg   fi
425b85037dbSmrg
426b85037dbSmrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
427b85037dbSmrg   do
428b85037dbSmrg     test -f "$tmpdepfile" && break
429b85037dbSmrg   done
430b85037dbSmrg   if test -f "$tmpdepfile"; then
431b85037dbSmrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
43228515619Smrg      sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
433b85037dbSmrg   else
434b85037dbSmrg      echo "#dummy" > "$depfile"
435b85037dbSmrg   fi
436b85037dbSmrg   rm -f "$tmpdepfile"
437b85037dbSmrg   ;;
438b85037dbSmrg
43928515619Smrgmsvc7)
44028515619Smrg  if test "$libtool" = yes; then
44128515619Smrg    showIncludes=-Wc,-showIncludes
44228515619Smrg  else
44328515619Smrg    showIncludes=-showIncludes
44428515619Smrg  fi
44528515619Smrg  "$@" $showIncludes > "$tmpdepfile"
44628515619Smrg  stat=$?
44728515619Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
44828515619Smrg  if test "$stat" = 0; then :
44928515619Smrg  else
45028515619Smrg    rm -f "$tmpdepfile"
45128515619Smrg    exit $stat
45228515619Smrg  fi
45328515619Smrg  rm -f "$depfile"
45428515619Smrg  echo "$object : \\" > "$depfile"
45528515619Smrg  # The first sed program below extracts the file names and escapes
45628515619Smrg  # backslashes for cygpath.  The second sed program outputs the file
45728515619Smrg  # name when reading, but also accumulates all include files in the
45828515619Smrg  # hold buffer in order to output them again at the end.  This only
45928515619Smrg  # works with sed implementations that can handle large buffers.
46028515619Smrg  sed < "$tmpdepfile" -n '
46128515619Smrg/^Note: including file:  *\(.*\)/ {
46228515619Smrg  s//\1/
46328515619Smrg  s/\\/\\\\/g
46428515619Smrg  p
46528515619Smrg}' | $cygpath_u | sort -u | sed -n '
46628515619Smrgs/ /\\ /g
46728515619Smrgs/\(.*\)/'"$tab"'\1 \\/p
46828515619Smrgs/.\(.*\) \\/\1:/
46928515619SmrgH
47028515619Smrg$ {
47128515619Smrg  s/.*/'"$tab"'/
47228515619Smrg  G
47328515619Smrg  p
47428515619Smrg}' >> "$depfile"
47528515619Smrg  rm -f "$tmpdepfile"
47628515619Smrg  ;;
47728515619Smrg
47828515619Smrgmsvc7msys)
47928515619Smrg  # This case exists only to let depend.m4 do its work.  It works by
48028515619Smrg  # looking at the text of this script.  This case will never be run,
48128515619Smrg  # since it is checked for above.
48228515619Smrg  exit 1
48328515619Smrg  ;;
48428515619Smrg
485b85037dbSmrg#nosideeffect)
486b85037dbSmrg  # This comment above is used by automake to tell side-effect
487b85037dbSmrg  # dependency tracking mechanisms from slower ones.
488b85037dbSmrg
489b85037dbSmrgdashmstdout)
490b85037dbSmrg  # Important note: in order to support this mode, a compiler *must*
491b85037dbSmrg  # always write the preprocessed file to stdout, regardless of -o.
492b85037dbSmrg  "$@" || exit $?
493b85037dbSmrg
494b85037dbSmrg  # Remove the call to Libtool.
495b85037dbSmrg  if test "$libtool" = yes; then
496b85037dbSmrg    while test "X$1" != 'X--mode=compile'; do
497b85037dbSmrg      shift
498b85037dbSmrg    done
499b85037dbSmrg    shift
500b85037dbSmrg  fi
501b85037dbSmrg
50228515619Smrg  # Remove '-o $object'.
503b85037dbSmrg  IFS=" "
504b85037dbSmrg  for arg
505b85037dbSmrg  do
506b85037dbSmrg    case $arg in
507b85037dbSmrg    -o)
508b85037dbSmrg      shift
509b85037dbSmrg      ;;
510b85037dbSmrg    $object)
511b85037dbSmrg      shift
512b85037dbSmrg      ;;
513b85037dbSmrg    *)
514b85037dbSmrg      set fnord "$@" "$arg"
515b85037dbSmrg      shift # fnord
516b85037dbSmrg      shift # $arg
517b85037dbSmrg      ;;
518b85037dbSmrg    esac
519b85037dbSmrg  done
520b85037dbSmrg
521b85037dbSmrg  test -z "$dashmflag" && dashmflag=-M
52228515619Smrg  # Require at least two characters before searching for ':'
523b85037dbSmrg  # in the target name.  This is to cope with DOS-style filenames:
52428515619Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
525b85037dbSmrg  "$@" $dashmflag |
52628515619Smrg    sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile"
527b85037dbSmrg  rm -f "$depfile"
528b85037dbSmrg  cat < "$tmpdepfile" > "$depfile"
52928515619Smrg  tr ' ' "$nl" < "$tmpdepfile" | \
530b85037dbSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
531b85037dbSmrg## correctly.  Breaking it into two sed invocations is a workaround.
532b85037dbSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
533b85037dbSmrg  rm -f "$tmpdepfile"
534b85037dbSmrg  ;;
535b85037dbSmrg
536b85037dbSmrgdashXmstdout)
537b85037dbSmrg  # This case only exists to satisfy depend.m4.  It is never actually
538b85037dbSmrg  # run, as this mode is specially recognized in the preamble.
539b85037dbSmrg  exit 1
540b85037dbSmrg  ;;
541b85037dbSmrg
542b85037dbSmrgmakedepend)
543b85037dbSmrg  "$@" || exit $?
544b85037dbSmrg  # Remove any Libtool call
545b85037dbSmrg  if test "$libtool" = yes; then
546b85037dbSmrg    while test "X$1" != 'X--mode=compile'; do
547b85037dbSmrg      shift
548b85037dbSmrg    done
549b85037dbSmrg    shift
550b85037dbSmrg  fi
551b85037dbSmrg  # X makedepend
552b85037dbSmrg  shift
553b85037dbSmrg  cleared=no eat=no
554b85037dbSmrg  for arg
555b85037dbSmrg  do
556b85037dbSmrg    case $cleared in
557b85037dbSmrg    no)
558b85037dbSmrg      set ""; shift
559b85037dbSmrg      cleared=yes ;;
560b85037dbSmrg    esac
561b85037dbSmrg    if test $eat = yes; then
562b85037dbSmrg      eat=no
563b85037dbSmrg      continue
564b85037dbSmrg    fi
565b85037dbSmrg    case "$arg" in
566b85037dbSmrg    -D*|-I*)
567b85037dbSmrg      set fnord "$@" "$arg"; shift ;;
568b85037dbSmrg    # Strip any option that makedepend may not understand.  Remove
569b85037dbSmrg    # the object too, otherwise makedepend will parse it as a source file.
570b85037dbSmrg    -arch)
571b85037dbSmrg      eat=yes ;;
572b85037dbSmrg    -*|$object)
573b85037dbSmrg      ;;
574b85037dbSmrg    *)
575b85037dbSmrg      set fnord "$@" "$arg"; shift ;;
576b85037dbSmrg    esac
577b85037dbSmrg  done
578b85037dbSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
579b85037dbSmrg  touch "$tmpdepfile"
580b85037dbSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
581b85037dbSmrg  rm -f "$depfile"
58228515619Smrg  # makedepend may prepend the VPATH from the source file name to the object.
58328515619Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
58428515619Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
58528515619Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' "$nl" | \
586b85037dbSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
587b85037dbSmrg## correctly.  Breaking it into two sed invocations is a workaround.
588b85037dbSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
589b85037dbSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
590b85037dbSmrg  ;;
591b85037dbSmrg
592b85037dbSmrgcpp)
593b85037dbSmrg  # Important note: in order to support this mode, a compiler *must*
594b85037dbSmrg  # always write the preprocessed file to stdout.
595b85037dbSmrg  "$@" || exit $?
596b85037dbSmrg
597b85037dbSmrg  # Remove the call to Libtool.
598b85037dbSmrg  if test "$libtool" = yes; then
599b85037dbSmrg    while test "X$1" != 'X--mode=compile'; do
600b85037dbSmrg      shift
601b85037dbSmrg    done
602b85037dbSmrg    shift
603b85037dbSmrg  fi
604b85037dbSmrg
60528515619Smrg  # Remove '-o $object'.
606b85037dbSmrg  IFS=" "
607b85037dbSmrg  for arg
608b85037dbSmrg  do
609b85037dbSmrg    case $arg in
610b85037dbSmrg    -o)
611b85037dbSmrg      shift
612b85037dbSmrg      ;;
613b85037dbSmrg    $object)
614b85037dbSmrg      shift
615b85037dbSmrg      ;;
616b85037dbSmrg    *)
617b85037dbSmrg      set fnord "$@" "$arg"
618b85037dbSmrg      shift # fnord
619b85037dbSmrg      shift # $arg
620b85037dbSmrg      ;;
621b85037dbSmrg    esac
622b85037dbSmrg  done
623b85037dbSmrg
624b85037dbSmrg  "$@" -E |
625b85037dbSmrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
626b85037dbSmrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
627b85037dbSmrg    sed '$ s: \\$::' > "$tmpdepfile"
628b85037dbSmrg  rm -f "$depfile"
629b85037dbSmrg  echo "$object : \\" > "$depfile"
630b85037dbSmrg  cat < "$tmpdepfile" >> "$depfile"
631b85037dbSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
632b85037dbSmrg  rm -f "$tmpdepfile"
633b85037dbSmrg  ;;
634b85037dbSmrg
635b85037dbSmrgmsvisualcpp)
636b85037dbSmrg  # Important note: in order to support this mode, a compiler *must*
637b85037dbSmrg  # always write the preprocessed file to stdout.
638b85037dbSmrg  "$@" || exit $?
639b85037dbSmrg
640b85037dbSmrg  # Remove the call to Libtool.
641b85037dbSmrg  if test "$libtool" = yes; then
642b85037dbSmrg    while test "X$1" != 'X--mode=compile'; do
643b85037dbSmrg      shift
644b85037dbSmrg    done
645b85037dbSmrg    shift
646b85037dbSmrg  fi
647b85037dbSmrg
648b85037dbSmrg  IFS=" "
649b85037dbSmrg  for arg
650b85037dbSmrg  do
651b85037dbSmrg    case "$arg" in
652b85037dbSmrg    -o)
653b85037dbSmrg      shift
654b85037dbSmrg      ;;
655b85037dbSmrg    $object)
656b85037dbSmrg      shift
657b85037dbSmrg      ;;
658b85037dbSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
659b85037dbSmrg	set fnord "$@"
660b85037dbSmrg	shift
661b85037dbSmrg	shift
662b85037dbSmrg	;;
663b85037dbSmrg    *)
664b85037dbSmrg	set fnord "$@" "$arg"
665b85037dbSmrg	shift
666b85037dbSmrg	shift
667b85037dbSmrg	;;
668b85037dbSmrg    esac
669b85037dbSmrg  done
670b85037dbSmrg  "$@" -E 2>/dev/null |
671b85037dbSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
672b85037dbSmrg  rm -f "$depfile"
673b85037dbSmrg  echo "$object : \\" > "$depfile"
67428515619Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
67528515619Smrg  echo "$tab" >> "$depfile"
676b85037dbSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
677b85037dbSmrg  rm -f "$tmpdepfile"
678b85037dbSmrg  ;;
679b85037dbSmrg
680b85037dbSmrgmsvcmsys)
681b85037dbSmrg  # This case exists only to let depend.m4 do its work.  It works by
682b85037dbSmrg  # looking at the text of this script.  This case will never be run,
683b85037dbSmrg  # since it is checked for above.
684b85037dbSmrg  exit 1
685b85037dbSmrg  ;;
686b85037dbSmrg
687b85037dbSmrgnone)
688b85037dbSmrg  exec "$@"
689b85037dbSmrg  ;;
690b85037dbSmrg
691b85037dbSmrg*)
692b85037dbSmrg  echo "Unknown depmode $depmode" 1>&2
693b85037dbSmrg  exit 1
694b85037dbSmrg  ;;
695b85037dbSmrgesac
696b85037dbSmrg
697b85037dbSmrgexit 0
698b85037dbSmrg
699b85037dbSmrg# Local Variables:
700b85037dbSmrg# mode: shell-script
701b85037dbSmrg# sh-indentation: 2
702b85037dbSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
703b85037dbSmrg# time-stamp-start: "scriptversion="
704b85037dbSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
705b85037dbSmrg# time-stamp-time-zone: "UTC"
706b85037dbSmrg# time-stamp-end: "; # UTC"
707b85037dbSmrg# End:
708