depcomp revision 8831d3fb
1100ae103Smrg#! /bin/sh
2100ae103Smrg# depcomp - compile a program generating dependencies as side-effects
3100ae103Smrg
48831d3fbSmrgscriptversion=2011-12-04.11; # UTC
5100ae103Smrg
68831d3fbSmrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
78831d3fbSmrg# 2011 Free Software Foundation, Inc.
8100ae103Smrg
9100ae103Smrg# This program is free software; you can redistribute it and/or modify
10100ae103Smrg# it under the terms of the GNU General Public License as published by
11100ae103Smrg# the Free Software Foundation; either version 2, or (at your option)
12100ae103Smrg# any later version.
13100ae103Smrg
14100ae103Smrg# This program is distributed in the hope that it will be useful,
15100ae103Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16100ae103Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17100ae103Smrg# GNU General Public License for more details.
18100ae103Smrg
19100ae103Smrg# You should have received a copy of the GNU General Public License
20165cb819Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21100ae103Smrg
22100ae103Smrg# As a special exception to the GNU General Public License, if you
23100ae103Smrg# distribute this file as part of a program that contains a
24100ae103Smrg# configuration script generated by Autoconf, you may include it under
25100ae103Smrg# the same distribution terms that you use for the rest of that program.
26100ae103Smrg
27100ae103Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
28100ae103Smrg
29100ae103Smrgcase $1 in
30100ae103Smrg  '')
31100ae103Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
32100ae103Smrg     exit 1;
33100ae103Smrg     ;;
34100ae103Smrg  -h | --h*)
35100ae103Smrg    cat <<\EOF
36100ae103SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
37100ae103Smrg
38100ae103SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
39100ae103Smrgas side-effects.
40100ae103Smrg
41100ae103SmrgEnvironment variables:
42100ae103Smrg  depmode     Dependency tracking mode.
43100ae103Smrg  source      Source file read by `PROGRAMS ARGS'.
44100ae103Smrg  object      Object file output by `PROGRAMS ARGS'.
45100ae103Smrg  DEPDIR      directory where to store dependencies.
46100ae103Smrg  depfile     Dependency file to output.
478831d3fbSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
48100ae103Smrg  libtool     Whether libtool is used (yes/no).
49100ae103Smrg
50100ae103SmrgReport bugs to <bug-automake@gnu.org>.
51100ae103SmrgEOF
52100ae103Smrg    exit $?
53100ae103Smrg    ;;
54100ae103Smrg  -v | --v*)
55100ae103Smrg    echo "depcomp $scriptversion"
56100ae103Smrg    exit $?
57100ae103Smrg    ;;
58100ae103Smrgesac
59100ae103Smrg
60100ae103Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
61100ae103Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
62100ae103Smrg  exit 1
63100ae103Smrgfi
64100ae103Smrg
65100ae103Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
66100ae103Smrgdepfile=${depfile-`echo "$object" |
67100ae103Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
68100ae103Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
69100ae103Smrg
70100ae103Smrgrm -f "$tmpdepfile"
71100ae103Smrg
72100ae103Smrg# Some modes work just like other modes, but use different flags.  We
73100ae103Smrg# parameterize here, but still list the modes in the big case below,
74100ae103Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
75100ae103Smrg# here, because this file can only contain one case statement.
76100ae103Smrgif test "$depmode" = hp; then
77100ae103Smrg  # HP compiler uses -M and no extra arg.
78100ae103Smrg  gccflag=-M
79100ae103Smrg  depmode=gcc
80100ae103Smrgfi
81100ae103Smrg
82100ae103Smrgif test "$depmode" = dashXmstdout; then
83100ae103Smrg   # This is just like dashmstdout with a different argument.
84100ae103Smrg   dashmflag=-xM
85100ae103Smrg   depmode=dashmstdout
86100ae103Smrgfi
87100ae103Smrg
88165cb819Smrgcygpath_u="cygpath -u -f -"
89165cb819Smrgif test "$depmode" = msvcmsys; then
90165cb819Smrg   # This is just like msvisualcpp but w/o cygpath translation.
91165cb819Smrg   # Just convert the backslash-escaped backslashes to single forward
92165cb819Smrg   # slashes to satisfy depend.m4
938831d3fbSmrg   cygpath_u='sed s,\\\\,/,g'
94165cb819Smrg   depmode=msvisualcpp
95165cb819Smrgfi
96165cb819Smrg
978831d3fbSmrgif test "$depmode" = msvc7msys; then
988831d3fbSmrg   # This is just like msvc7 but w/o cygpath translation.
998831d3fbSmrg   # Just convert the backslash-escaped backslashes to single forward
1008831d3fbSmrg   # slashes to satisfy depend.m4
1018831d3fbSmrg   cygpath_u='sed s,\\\\,/,g'
1028831d3fbSmrg   depmode=msvc7
1038831d3fbSmrgfi
1048831d3fbSmrg
105100ae103Smrgcase "$depmode" in
106100ae103Smrggcc3)
107100ae103Smrg## gcc 3 implements dependency tracking that does exactly what
108100ae103Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
109100ae103Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
110165cb819Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
111165cb819Smrg## the command line argument order; so add the flags where they
112165cb819Smrg## appear in depend2.am.  Note that the slowdown incurred here
113165cb819Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
114165cb819Smrg  for arg
115165cb819Smrg  do
116165cb819Smrg    case $arg in
117165cb819Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
118165cb819Smrg    *)  set fnord "$@" "$arg" ;;
119165cb819Smrg    esac
120165cb819Smrg    shift # fnord
121165cb819Smrg    shift # $arg
122165cb819Smrg  done
123165cb819Smrg  "$@"
124100ae103Smrg  stat=$?
125100ae103Smrg  if test $stat -eq 0; then :
126100ae103Smrg  else
127100ae103Smrg    rm -f "$tmpdepfile"
128100ae103Smrg    exit $stat
129100ae103Smrg  fi
130100ae103Smrg  mv "$tmpdepfile" "$depfile"
131100ae103Smrg  ;;
132100ae103Smrg
133100ae103Smrggcc)
134100ae103Smrg## There are various ways to get dependency output from gcc.  Here's
135100ae103Smrg## why we pick this rather obscure method:
136100ae103Smrg## - Don't want to use -MD because we'd like the dependencies to end
137100ae103Smrg##   up in a subdir.  Having to rename by hand is ugly.
138100ae103Smrg##   (We might end up doing this anyway to support other compilers.)
139100ae103Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
140100ae103Smrg##   -MM, not -M (despite what the docs say).
141100ae103Smrg## - Using -M directly means running the compiler twice (even worse
142100ae103Smrg##   than renaming).
143100ae103Smrg  if test -z "$gccflag"; then
144100ae103Smrg    gccflag=-MD,
145100ae103Smrg  fi
146100ae103Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
147100ae103Smrg  stat=$?
148100ae103Smrg  if test $stat -eq 0; then :
149100ae103Smrg  else
150100ae103Smrg    rm -f "$tmpdepfile"
151100ae103Smrg    exit $stat
152100ae103Smrg  fi
153100ae103Smrg  rm -f "$depfile"
154100ae103Smrg  echo "$object : \\" > "$depfile"
155100ae103Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
156100ae103Smrg## The second -e expression handles DOS-style file names with drive letters.
157100ae103Smrg  sed -e 's/^[^:]*: / /' \
158100ae103Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
159100ae103Smrg## This next piece of magic avoids the `deleted header file' problem.
160100ae103Smrg## The problem is that when a header file which appears in a .P file
161100ae103Smrg## is deleted, the dependency causes make to die (because there is
162100ae103Smrg## typically no way to rebuild the header).  We avoid this by adding
163100ae103Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
164100ae103Smrg## this for us directly.
165100ae103Smrg  tr ' ' '
166100ae103Smrg' < "$tmpdepfile" |
167100ae103Smrg## Some versions of gcc put a space before the `:'.  On the theory
168100ae103Smrg## that the space means something, we add a space to the output as
1698831d3fbSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
1708831d3fbSmrg## to the object.  Take care to not repeat it in the output.
171100ae103Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
172100ae103Smrg## correctly.  Breaking it into two sed invocations is a workaround.
1738831d3fbSmrg    sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
1748831d3fbSmrg      | sed -e 's/$/ :/' >> "$depfile"
175100ae103Smrg  rm -f "$tmpdepfile"
176100ae103Smrg  ;;
177100ae103Smrg
178100ae103Smrghp)
179100ae103Smrg  # This case exists only to let depend.m4 do its work.  It works by
180100ae103Smrg  # looking at the text of this script.  This case will never be run,
181100ae103Smrg  # since it is checked for above.
182100ae103Smrg  exit 1
183100ae103Smrg  ;;
184100ae103Smrg
185100ae103Smrgsgi)
186100ae103Smrg  if test "$libtool" = yes; then
187100ae103Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
188100ae103Smrg  else
189100ae103Smrg    "$@" -MDupdate "$tmpdepfile"
190100ae103Smrg  fi
191100ae103Smrg  stat=$?
192100ae103Smrg  if test $stat -eq 0; then :
193100ae103Smrg  else
194100ae103Smrg    rm -f "$tmpdepfile"
195100ae103Smrg    exit $stat
196100ae103Smrg  fi
197100ae103Smrg  rm -f "$depfile"
198100ae103Smrg
199100ae103Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
200100ae103Smrg    echo "$object : \\" > "$depfile"
201100ae103Smrg
202100ae103Smrg    # Clip off the initial element (the dependent).  Don't try to be
203100ae103Smrg    # clever and replace this with sed code, as IRIX sed won't handle
204100ae103Smrg    # lines with more than a fixed number of characters (4096 in
205100ae103Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
206100ae103Smrg    # the IRIX cc adds comments like `#:fec' to the end of the
207100ae103Smrg    # dependency line.
208100ae103Smrg    tr ' ' '
209100ae103Smrg' < "$tmpdepfile" \
210100ae103Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
211100ae103Smrg    tr '
212165cb819Smrg' ' ' >> "$depfile"
213165cb819Smrg    echo >> "$depfile"
214100ae103Smrg
215100ae103Smrg    # The second pass generates a dummy entry for each header file.
216100ae103Smrg    tr ' ' '
217100ae103Smrg' < "$tmpdepfile" \
218100ae103Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
219165cb819Smrg   >> "$depfile"
220100ae103Smrg  else
221100ae103Smrg    # The sourcefile does not contain any dependencies, so just
222100ae103Smrg    # store a dummy comment line, to avoid errors with the Makefile
223100ae103Smrg    # "include basename.Plo" scheme.
224100ae103Smrg    echo "#dummy" > "$depfile"
225100ae103Smrg  fi
226100ae103Smrg  rm -f "$tmpdepfile"
227100ae103Smrg  ;;
228100ae103Smrg
229100ae103Smrgaix)
230100ae103Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
231100ae103Smrg  # in a .u file.  In older versions, this file always lives in the
232100ae103Smrg  # current directory.  Also, the AIX compiler puts `$object:' at the
233100ae103Smrg  # start of each line; $object doesn't have directory information.
234100ae103Smrg  # Version 6 uses the directory in both cases.
235165cb819Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
236165cb819Smrg  test "x$dir" = "x$object" && dir=
237165cb819Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
238100ae103Smrg  if test "$libtool" = yes; then
239165cb819Smrg    tmpdepfile1=$dir$base.u
240165cb819Smrg    tmpdepfile2=$base.u
241165cb819Smrg    tmpdepfile3=$dir.libs/$base.u
242100ae103Smrg    "$@" -Wc,-M
243100ae103Smrg  else
244165cb819Smrg    tmpdepfile1=$dir$base.u
245165cb819Smrg    tmpdepfile2=$dir$base.u
246165cb819Smrg    tmpdepfile3=$dir$base.u
247100ae103Smrg    "$@" -M
248100ae103Smrg  fi
249100ae103Smrg  stat=$?
250100ae103Smrg
251100ae103Smrg  if test $stat -eq 0; then :
252100ae103Smrg  else
253165cb819Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
254100ae103Smrg    exit $stat
255100ae103Smrg  fi
256100ae103Smrg
257165cb819Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
258165cb819Smrg  do
259165cb819Smrg    test -f "$tmpdepfile" && break
260165cb819Smrg  done
261100ae103Smrg  if test -f "$tmpdepfile"; then
262100ae103Smrg    # Each line is of the form `foo.o: dependent.h'.
263100ae103Smrg    # Do two passes, one to just change these to
264100ae103Smrg    # `$object: dependent.h' and one to simply `dependent.h:'.
265165cb819Smrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
266165cb819Smrg    # That's a tab and a space in the [].
267165cb819Smrg    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
268100ae103Smrg  else
269100ae103Smrg    # The sourcefile does not contain any dependencies, so just
270100ae103Smrg    # store a dummy comment line, to avoid errors with the Makefile
271100ae103Smrg    # "include basename.Plo" scheme.
272100ae103Smrg    echo "#dummy" > "$depfile"
273100ae103Smrg  fi
274100ae103Smrg  rm -f "$tmpdepfile"
275100ae103Smrg  ;;
276100ae103Smrg
277100ae103Smrgicc)
278100ae103Smrg  # Intel's C compiler understands `-MD -MF file'.  However on
279100ae103Smrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
280100ae103Smrg  # ICC 7.0 will fill foo.d with something like
281100ae103Smrg  #    foo.o: sub/foo.c
282100ae103Smrg  #    foo.o: sub/foo.h
283100ae103Smrg  # which is wrong.  We want:
284100ae103Smrg  #    sub/foo.o: sub/foo.c
285100ae103Smrg  #    sub/foo.o: sub/foo.h
286100ae103Smrg  #    sub/foo.c:
287100ae103Smrg  #    sub/foo.h:
288100ae103Smrg  # ICC 7.1 will output
289100ae103Smrg  #    foo.o: sub/foo.c sub/foo.h
290100ae103Smrg  # and will wrap long lines using \ :
291100ae103Smrg  #    foo.o: sub/foo.c ... \
292100ae103Smrg  #     sub/foo.h ... \
293100ae103Smrg  #     ...
294100ae103Smrg
295100ae103Smrg  "$@" -MD -MF "$tmpdepfile"
296100ae103Smrg  stat=$?
297100ae103Smrg  if test $stat -eq 0; then :
298100ae103Smrg  else
299100ae103Smrg    rm -f "$tmpdepfile"
300100ae103Smrg    exit $stat
301100ae103Smrg  fi
302100ae103Smrg  rm -f "$depfile"
303100ae103Smrg  # Each line is of the form `foo.o: dependent.h',
304100ae103Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
305100ae103Smrg  # Do two passes, one to just change these to
306100ae103Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
307100ae103Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
308100ae103Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
309100ae103Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
310100ae103Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
311100ae103Smrg    sed -e 's/$/ :/' >> "$depfile"
312100ae103Smrg  rm -f "$tmpdepfile"
313100ae103Smrg  ;;
314100ae103Smrg
315165cb819Smrghp2)
316165cb819Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
317165cb819Smrg  # compilers, which have integrated preprocessors.  The correct option
318165cb819Smrg  # to use with these is +Maked; it writes dependencies to a file named
319165cb819Smrg  # 'foo.d', which lands next to the object file, wherever that
320165cb819Smrg  # happens to be.
321165cb819Smrg  # Much of this is similar to the tru64 case; see comments there.
322165cb819Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
323165cb819Smrg  test "x$dir" = "x$object" && dir=
324165cb819Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
325165cb819Smrg  if test "$libtool" = yes; then
326165cb819Smrg    tmpdepfile1=$dir$base.d
327165cb819Smrg    tmpdepfile2=$dir.libs/$base.d
328165cb819Smrg    "$@" -Wc,+Maked
329165cb819Smrg  else
330165cb819Smrg    tmpdepfile1=$dir$base.d
331165cb819Smrg    tmpdepfile2=$dir$base.d
332165cb819Smrg    "$@" +Maked
333165cb819Smrg  fi
334165cb819Smrg  stat=$?
335165cb819Smrg  if test $stat -eq 0; then :
336165cb819Smrg  else
337165cb819Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
338165cb819Smrg     exit $stat
339165cb819Smrg  fi
340165cb819Smrg
341165cb819Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
342165cb819Smrg  do
343165cb819Smrg    test -f "$tmpdepfile" && break
344165cb819Smrg  done
345165cb819Smrg  if test -f "$tmpdepfile"; then
346165cb819Smrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
347165cb819Smrg    # Add `dependent.h:' lines.
348165cb819Smrg    sed -ne '2,${
349165cb819Smrg	       s/^ *//
350165cb819Smrg	       s/ \\*$//
351165cb819Smrg	       s/$/:/
352165cb819Smrg	       p
353165cb819Smrg	     }' "$tmpdepfile" >> "$depfile"
354165cb819Smrg  else
355165cb819Smrg    echo "#dummy" > "$depfile"
356165cb819Smrg  fi
357165cb819Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
358165cb819Smrg  ;;
359165cb819Smrg
360100ae103Smrgtru64)
361100ae103Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
362100ae103Smrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
363100ae103Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
364100ae103Smrg   # dependencies in `foo.d' instead, so we check for that too.
365100ae103Smrg   # Subdirectories are respected.
366100ae103Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
367100ae103Smrg   test "x$dir" = "x$object" && dir=
368100ae103Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
369100ae103Smrg
370100ae103Smrg   if test "$libtool" = yes; then
371100ae103Smrg      # With Tru64 cc, shared objects can also be used to make a
372165cb819Smrg      # static library.  This mechanism is used in libtool 1.4 series to
373100ae103Smrg      # handle both shared and static libraries in a single compilation.
374100ae103Smrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
375100ae103Smrg      #
376100ae103Smrg      # With libtool 1.5 this exception was removed, and libtool now
377100ae103Smrg      # generates 2 separate objects for the 2 libraries.  These two
378165cb819Smrg      # compilations output dependencies in $dir.libs/$base.o.d and
379100ae103Smrg      # in $dir$base.o.d.  We have to check for both files, because
380100ae103Smrg      # one of the two compilations can be disabled.  We should prefer
381100ae103Smrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
382100ae103Smrg      # automatically cleaned when .libs/ is deleted, while ignoring
383100ae103Smrg      # the former would cause a distcleancheck panic.
384100ae103Smrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
385100ae103Smrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
386100ae103Smrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
387100ae103Smrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
388100ae103Smrg      "$@" -Wc,-MD
389100ae103Smrg   else
390100ae103Smrg      tmpdepfile1=$dir$base.o.d
391100ae103Smrg      tmpdepfile2=$dir$base.d
392100ae103Smrg      tmpdepfile3=$dir$base.d
393100ae103Smrg      tmpdepfile4=$dir$base.d
394100ae103Smrg      "$@" -MD
395100ae103Smrg   fi
396100ae103Smrg
397100ae103Smrg   stat=$?
398100ae103Smrg   if test $stat -eq 0; then :
399100ae103Smrg   else
400100ae103Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
401100ae103Smrg      exit $stat
402100ae103Smrg   fi
403100ae103Smrg
404100ae103Smrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
405100ae103Smrg   do
406100ae103Smrg     test -f "$tmpdepfile" && break
407100ae103Smrg   done
408100ae103Smrg   if test -f "$tmpdepfile"; then
409100ae103Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
410100ae103Smrg      # That's a tab and a space in the [].
411100ae103Smrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
412100ae103Smrg   else
413100ae103Smrg      echo "#dummy" > "$depfile"
414100ae103Smrg   fi
415100ae103Smrg   rm -f "$tmpdepfile"
416100ae103Smrg   ;;
417100ae103Smrg
4188831d3fbSmrgmsvc7)
4198831d3fbSmrg  if test "$libtool" = yes; then
4208831d3fbSmrg    showIncludes=-Wc,-showIncludes
4218831d3fbSmrg  else
4228831d3fbSmrg    showIncludes=-showIncludes
4238831d3fbSmrg  fi
4248831d3fbSmrg  "$@" $showIncludes > "$tmpdepfile"
4258831d3fbSmrg  stat=$?
4268831d3fbSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
4278831d3fbSmrg  if test "$stat" = 0; then :
4288831d3fbSmrg  else
4298831d3fbSmrg    rm -f "$tmpdepfile"
4308831d3fbSmrg    exit $stat
4318831d3fbSmrg  fi
4328831d3fbSmrg  rm -f "$depfile"
4338831d3fbSmrg  echo "$object : \\" > "$depfile"
4348831d3fbSmrg  # The first sed program below extracts the file names and escapes
4358831d3fbSmrg  # backslashes for cygpath.  The second sed program outputs the file
4368831d3fbSmrg  # name when reading, but also accumulates all include files in the
4378831d3fbSmrg  # hold buffer in order to output them again at the end.  This only
4388831d3fbSmrg  # works with sed implementations that can handle large buffers.
4398831d3fbSmrg  sed < "$tmpdepfile" -n '
4408831d3fbSmrg/^Note: including file:  *\(.*\)/ {
4418831d3fbSmrg  s//\1/
4428831d3fbSmrg  s/\\/\\\\/g
4438831d3fbSmrg  p
4448831d3fbSmrg}' | $cygpath_u | sort -u | sed -n '
4458831d3fbSmrgs/ /\\ /g
4468831d3fbSmrgs/\(.*\)/	\1 \\/p
4478831d3fbSmrgs/.\(.*\) \\/\1:/
4488831d3fbSmrgH
4498831d3fbSmrg$ {
4508831d3fbSmrg  s/.*/	/
4518831d3fbSmrg  G
4528831d3fbSmrg  p
4538831d3fbSmrg}' >> "$depfile"
4548831d3fbSmrg  rm -f "$tmpdepfile"
4558831d3fbSmrg  ;;
4568831d3fbSmrg
4578831d3fbSmrgmsvc7msys)
4588831d3fbSmrg  # This case exists only to let depend.m4 do its work.  It works by
4598831d3fbSmrg  # looking at the text of this script.  This case will never be run,
4608831d3fbSmrg  # since it is checked for above.
4618831d3fbSmrg  exit 1
4628831d3fbSmrg  ;;
4638831d3fbSmrg
464100ae103Smrg#nosideeffect)
465100ae103Smrg  # This comment above is used by automake to tell side-effect
466100ae103Smrg  # dependency tracking mechanisms from slower ones.
467100ae103Smrg
468100ae103Smrgdashmstdout)
469100ae103Smrg  # Important note: in order to support this mode, a compiler *must*
470100ae103Smrg  # always write the preprocessed file to stdout, regardless of -o.
471100ae103Smrg  "$@" || exit $?
472100ae103Smrg
473100ae103Smrg  # Remove the call to Libtool.
474100ae103Smrg  if test "$libtool" = yes; then
475165cb819Smrg    while test "X$1" != 'X--mode=compile'; do
476100ae103Smrg      shift
477100ae103Smrg    done
478100ae103Smrg    shift
479100ae103Smrg  fi
480100ae103Smrg
481100ae103Smrg  # Remove `-o $object'.
482100ae103Smrg  IFS=" "
483100ae103Smrg  for arg
484100ae103Smrg  do
485100ae103Smrg    case $arg in
486100ae103Smrg    -o)
487100ae103Smrg      shift
488100ae103Smrg      ;;
489100ae103Smrg    $object)
490100ae103Smrg      shift
491100ae103Smrg      ;;
492100ae103Smrg    *)
493100ae103Smrg      set fnord "$@" "$arg"
494100ae103Smrg      shift # fnord
495100ae103Smrg      shift # $arg
496100ae103Smrg      ;;
497100ae103Smrg    esac
498100ae103Smrg  done
499100ae103Smrg
500100ae103Smrg  test -z "$dashmflag" && dashmflag=-M
501100ae103Smrg  # Require at least two characters before searching for `:'
502100ae103Smrg  # in the target name.  This is to cope with DOS-style filenames:
503100ae103Smrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
504100ae103Smrg  "$@" $dashmflag |
505100ae103Smrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
506100ae103Smrg  rm -f "$depfile"
507100ae103Smrg  cat < "$tmpdepfile" > "$depfile"
508100ae103Smrg  tr ' ' '
509100ae103Smrg' < "$tmpdepfile" | \
510100ae103Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
511100ae103Smrg## correctly.  Breaking it into two sed invocations is a workaround.
512100ae103Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
513100ae103Smrg  rm -f "$tmpdepfile"
514100ae103Smrg  ;;
515100ae103Smrg
516100ae103SmrgdashXmstdout)
517100ae103Smrg  # This case only exists to satisfy depend.m4.  It is never actually
518100ae103Smrg  # run, as this mode is specially recognized in the preamble.
519100ae103Smrg  exit 1
520100ae103Smrg  ;;
521100ae103Smrg
522100ae103Smrgmakedepend)
523100ae103Smrg  "$@" || exit $?
524100ae103Smrg  # Remove any Libtool call
525100ae103Smrg  if test "$libtool" = yes; then
526165cb819Smrg    while test "X$1" != 'X--mode=compile'; do
527100ae103Smrg      shift
528100ae103Smrg    done
529100ae103Smrg    shift
530100ae103Smrg  fi
531100ae103Smrg  # X makedepend
532100ae103Smrg  shift
533165cb819Smrg  cleared=no eat=no
534165cb819Smrg  for arg
535165cb819Smrg  do
536100ae103Smrg    case $cleared in
537100ae103Smrg    no)
538100ae103Smrg      set ""; shift
539100ae103Smrg      cleared=yes ;;
540100ae103Smrg    esac
541165cb819Smrg    if test $eat = yes; then
542165cb819Smrg      eat=no
543165cb819Smrg      continue
544165cb819Smrg    fi
545100ae103Smrg    case "$arg" in
546100ae103Smrg    -D*|-I*)
547100ae103Smrg      set fnord "$@" "$arg"; shift ;;
548100ae103Smrg    # Strip any option that makedepend may not understand.  Remove
549100ae103Smrg    # the object too, otherwise makedepend will parse it as a source file.
550165cb819Smrg    -arch)
551165cb819Smrg      eat=yes ;;
552100ae103Smrg    -*|$object)
553100ae103Smrg      ;;
554100ae103Smrg    *)
555100ae103Smrg      set fnord "$@" "$arg"; shift ;;
556100ae103Smrg    esac
557100ae103Smrg  done
558165cb819Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
559100ae103Smrg  touch "$tmpdepfile"
560100ae103Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
561100ae103Smrg  rm -f "$depfile"
5628831d3fbSmrg  # makedepend may prepend the VPATH from the source file name to the object.
5638831d3fbSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
5648831d3fbSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
565100ae103Smrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
566100ae103Smrg' | \
567100ae103Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
568100ae103Smrg## correctly.  Breaking it into two sed invocations is a workaround.
569100ae103Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
570100ae103Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
571100ae103Smrg  ;;
572100ae103Smrg
573100ae103Smrgcpp)
574100ae103Smrg  # Important note: in order to support this mode, a compiler *must*
575100ae103Smrg  # always write the preprocessed file to stdout.
576100ae103Smrg  "$@" || exit $?
577100ae103Smrg
578100ae103Smrg  # Remove the call to Libtool.
579100ae103Smrg  if test "$libtool" = yes; then
580165cb819Smrg    while test "X$1" != 'X--mode=compile'; do
581100ae103Smrg      shift
582100ae103Smrg    done
583100ae103Smrg    shift
584100ae103Smrg  fi
585100ae103Smrg
586100ae103Smrg  # Remove `-o $object'.
587100ae103Smrg  IFS=" "
588100ae103Smrg  for arg
589100ae103Smrg  do
590100ae103Smrg    case $arg in
591100ae103Smrg    -o)
592100ae103Smrg      shift
593100ae103Smrg      ;;
594100ae103Smrg    $object)
595100ae103Smrg      shift
596100ae103Smrg      ;;
597100ae103Smrg    *)
598100ae103Smrg      set fnord "$@" "$arg"
599100ae103Smrg      shift # fnord
600100ae103Smrg      shift # $arg
601100ae103Smrg      ;;
602100ae103Smrg    esac
603100ae103Smrg  done
604100ae103Smrg
605100ae103Smrg  "$@" -E |
606100ae103Smrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
607100ae103Smrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
608100ae103Smrg    sed '$ s: \\$::' > "$tmpdepfile"
609100ae103Smrg  rm -f "$depfile"
610100ae103Smrg  echo "$object : \\" > "$depfile"
611100ae103Smrg  cat < "$tmpdepfile" >> "$depfile"
612100ae103Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
613100ae103Smrg  rm -f "$tmpdepfile"
614100ae103Smrg  ;;
615100ae103Smrg
616100ae103Smrgmsvisualcpp)
617100ae103Smrg  # Important note: in order to support this mode, a compiler *must*
618165cb819Smrg  # always write the preprocessed file to stdout.
619100ae103Smrg  "$@" || exit $?
620165cb819Smrg
621165cb819Smrg  # Remove the call to Libtool.
622165cb819Smrg  if test "$libtool" = yes; then
623165cb819Smrg    while test "X$1" != 'X--mode=compile'; do
624165cb819Smrg      shift
625165cb819Smrg    done
626165cb819Smrg    shift
627165cb819Smrg  fi
628165cb819Smrg
629100ae103Smrg  IFS=" "
630100ae103Smrg  for arg
631100ae103Smrg  do
632100ae103Smrg    case "$arg" in
633165cb819Smrg    -o)
634165cb819Smrg      shift
635165cb819Smrg      ;;
636165cb819Smrg    $object)
637165cb819Smrg      shift
638165cb819Smrg      ;;
639100ae103Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
640100ae103Smrg	set fnord "$@"
641100ae103Smrg	shift
642100ae103Smrg	shift
643100ae103Smrg	;;
644100ae103Smrg    *)
645100ae103Smrg	set fnord "$@" "$arg"
646100ae103Smrg	shift
647100ae103Smrg	shift
648100ae103Smrg	;;
649100ae103Smrg    esac
650100ae103Smrg  done
651165cb819Smrg  "$@" -E 2>/dev/null |
652165cb819Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
653100ae103Smrg  rm -f "$depfile"
654100ae103Smrg  echo "$object : \\" > "$depfile"
655165cb819Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
656100ae103Smrg  echo "	" >> "$depfile"
657165cb819Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
658100ae103Smrg  rm -f "$tmpdepfile"
659100ae103Smrg  ;;
660100ae103Smrg
661165cb819Smrgmsvcmsys)
662165cb819Smrg  # This case exists only to let depend.m4 do its work.  It works by
663165cb819Smrg  # looking at the text of this script.  This case will never be run,
664165cb819Smrg  # since it is checked for above.
665165cb819Smrg  exit 1
666165cb819Smrg  ;;
667165cb819Smrg
668100ae103Smrgnone)
669100ae103Smrg  exec "$@"
670100ae103Smrg  ;;
671100ae103Smrg
672100ae103Smrg*)
673100ae103Smrg  echo "Unknown depmode $depmode" 1>&2
674100ae103Smrg  exit 1
675100ae103Smrg  ;;
676100ae103Smrgesac
677100ae103Smrg
678100ae103Smrgexit 0
679100ae103Smrg
680100ae103Smrg# Local Variables:
681100ae103Smrg# mode: shell-script
682100ae103Smrg# sh-indentation: 2
683100ae103Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
684100ae103Smrg# time-stamp-start: "scriptversion="
685100ae103Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
686165cb819Smrg# time-stamp-time-zone: "UTC"
687165cb819Smrg# time-stamp-end: "; # UTC"
688100ae103Smrg# End:
689