1382ff0afSmrg#! /bin/sh
2382ff0afSmrg# depcomp - compile a program generating dependencies as side-effects
3382ff0afSmrg
4382ff0afSmrgscriptversion=2005-07-09.11
5382ff0afSmrg
6382ff0afSmrg# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
7382ff0afSmrg
8382ff0afSmrg# This program is free software; you can redistribute it and/or modify
9382ff0afSmrg# it under the terms of the GNU General Public License as published by
10382ff0afSmrg# the Free Software Foundation; either version 2, or (at your option)
11382ff0afSmrg# any later version.
12382ff0afSmrg
13382ff0afSmrg# This program is distributed in the hope that it will be useful,
14382ff0afSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15382ff0afSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16382ff0afSmrg# GNU General Public License for more details.
17382ff0afSmrg
18382ff0afSmrg# You should have received a copy of the GNU General Public License
19382ff0afSmrg# along with this program; if not, write to the Free Software
20382ff0afSmrg# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21382ff0afSmrg# 02110-1301, USA.
22382ff0afSmrg
23382ff0afSmrg# As a special exception to the GNU General Public License, if you
24382ff0afSmrg# distribute this file as part of a program that contains a
25382ff0afSmrg# configuration script generated by Autoconf, you may include it under
26382ff0afSmrg# the same distribution terms that you use for the rest of that program.
27382ff0afSmrg
28382ff0afSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
29382ff0afSmrg
30382ff0afSmrgcase $1 in
31382ff0afSmrg  '')
32382ff0afSmrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
33382ff0afSmrg     exit 1;
34382ff0afSmrg     ;;
35382ff0afSmrg  -h | --h*)
36382ff0afSmrg    cat <<\EOF
37382ff0afSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
38382ff0afSmrg
39382ff0afSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
40382ff0afSmrgas side-effects.
41382ff0afSmrg
42382ff0afSmrgEnvironment variables:
43382ff0afSmrg  depmode     Dependency tracking mode.
44382ff0afSmrg  source      Source file read by `PROGRAMS ARGS'.
45382ff0afSmrg  object      Object file output by `PROGRAMS ARGS'.
46382ff0afSmrg  DEPDIR      directory where to store dependencies.
47382ff0afSmrg  depfile     Dependency file to output.
48382ff0afSmrg  tmpdepfile  Temporary file to use when outputing dependencies.
49382ff0afSmrg  libtool     Whether libtool is used (yes/no).
50382ff0afSmrg
51382ff0afSmrgReport bugs to <bug-automake@gnu.org>.
52382ff0afSmrgEOF
53382ff0afSmrg    exit $?
54382ff0afSmrg    ;;
55382ff0afSmrg  -v | --v*)
56382ff0afSmrg    echo "depcomp $scriptversion"
57382ff0afSmrg    exit $?
58382ff0afSmrg    ;;
59382ff0afSmrgesac
60382ff0afSmrg
61382ff0afSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
62382ff0afSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
63382ff0afSmrg  exit 1
64382ff0afSmrgfi
65382ff0afSmrg
66382ff0afSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
67382ff0afSmrgdepfile=${depfile-`echo "$object" |
68382ff0afSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
69382ff0afSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
70382ff0afSmrg
71382ff0afSmrgrm -f "$tmpdepfile"
72382ff0afSmrg
73382ff0afSmrg# Some modes work just like other modes, but use different flags.  We
74382ff0afSmrg# parameterize here, but still list the modes in the big case below,
75382ff0afSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
76382ff0afSmrg# here, because this file can only contain one case statement.
77382ff0afSmrgif test "$depmode" = hp; then
78382ff0afSmrg  # HP compiler uses -M and no extra arg.
79382ff0afSmrg  gccflag=-M
80382ff0afSmrg  depmode=gcc
81382ff0afSmrgfi
82382ff0afSmrg
83382ff0afSmrgif test "$depmode" = dashXmstdout; then
84382ff0afSmrg   # This is just like dashmstdout with a different argument.
85382ff0afSmrg   dashmflag=-xM
86382ff0afSmrg   depmode=dashmstdout
87382ff0afSmrgfi
88382ff0afSmrg
89382ff0afSmrgcase "$depmode" in
90382ff0afSmrggcc3)
91382ff0afSmrg## gcc 3 implements dependency tracking that does exactly what
92382ff0afSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
93382ff0afSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
94382ff0afSmrg  "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
95382ff0afSmrg  stat=$?
96382ff0afSmrg  if test $stat -eq 0; then :
97382ff0afSmrg  else
98382ff0afSmrg    rm -f "$tmpdepfile"
99382ff0afSmrg    exit $stat
100382ff0afSmrg  fi
101382ff0afSmrg  mv "$tmpdepfile" "$depfile"
102382ff0afSmrg  ;;
103382ff0afSmrg
104382ff0afSmrggcc)
105382ff0afSmrg## There are various ways to get dependency output from gcc.  Here's
106382ff0afSmrg## why we pick this rather obscure method:
107382ff0afSmrg## - Don't want to use -MD because we'd like the dependencies to end
108382ff0afSmrg##   up in a subdir.  Having to rename by hand is ugly.
109382ff0afSmrg##   (We might end up doing this anyway to support other compilers.)
110382ff0afSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
111382ff0afSmrg##   -MM, not -M (despite what the docs say).
112382ff0afSmrg## - Using -M directly means running the compiler twice (even worse
113382ff0afSmrg##   than renaming).
114382ff0afSmrg  if test -z "$gccflag"; then
115382ff0afSmrg    gccflag=-MD,
116382ff0afSmrg  fi
117382ff0afSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
118382ff0afSmrg  stat=$?
119382ff0afSmrg  if test $stat -eq 0; then :
120382ff0afSmrg  else
121382ff0afSmrg    rm -f "$tmpdepfile"
122382ff0afSmrg    exit $stat
123382ff0afSmrg  fi
124382ff0afSmrg  rm -f "$depfile"
125382ff0afSmrg  echo "$object : \\" > "$depfile"
126382ff0afSmrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
127382ff0afSmrg## The second -e expression handles DOS-style file names with drive letters.
128382ff0afSmrg  sed -e 's/^[^:]*: / /' \
129382ff0afSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
130382ff0afSmrg## This next piece of magic avoids the `deleted header file' problem.
131382ff0afSmrg## The problem is that when a header file which appears in a .P file
132382ff0afSmrg## is deleted, the dependency causes make to die (because there is
133382ff0afSmrg## typically no way to rebuild the header).  We avoid this by adding
134382ff0afSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
135382ff0afSmrg## this for us directly.
136382ff0afSmrg  tr ' ' '
137382ff0afSmrg' < "$tmpdepfile" |
138382ff0afSmrg## Some versions of gcc put a space before the `:'.  On the theory
139382ff0afSmrg## that the space means something, we add a space to the output as
140382ff0afSmrg## well.
141382ff0afSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
142382ff0afSmrg## correctly.  Breaking it into two sed invocations is a workaround.
143382ff0afSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
144382ff0afSmrg  rm -f "$tmpdepfile"
145382ff0afSmrg  ;;
146382ff0afSmrg
147382ff0afSmrghp)
148382ff0afSmrg  # This case exists only to let depend.m4 do its work.  It works by
149382ff0afSmrg  # looking at the text of this script.  This case will never be run,
150382ff0afSmrg  # since it is checked for above.
151382ff0afSmrg  exit 1
152382ff0afSmrg  ;;
153382ff0afSmrg
154382ff0afSmrgsgi)
155382ff0afSmrg  if test "$libtool" = yes; then
156382ff0afSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
157382ff0afSmrg  else
158382ff0afSmrg    "$@" -MDupdate "$tmpdepfile"
159382ff0afSmrg  fi
160382ff0afSmrg  stat=$?
161382ff0afSmrg  if test $stat -eq 0; then :
162382ff0afSmrg  else
163382ff0afSmrg    rm -f "$tmpdepfile"
164382ff0afSmrg    exit $stat
165382ff0afSmrg  fi
166382ff0afSmrg  rm -f "$depfile"
167382ff0afSmrg
168382ff0afSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
169382ff0afSmrg    echo "$object : \\" > "$depfile"
170382ff0afSmrg
171382ff0afSmrg    # Clip off the initial element (the dependent).  Don't try to be
172382ff0afSmrg    # clever and replace this with sed code, as IRIX sed won't handle
173382ff0afSmrg    # lines with more than a fixed number of characters (4096 in
174382ff0afSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
175382ff0afSmrg    # the IRIX cc adds comments like `#:fec' to the end of the
176382ff0afSmrg    # dependency line.
177382ff0afSmrg    tr ' ' '
178382ff0afSmrg' < "$tmpdepfile" \
179382ff0afSmrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
180382ff0afSmrg    tr '
181382ff0afSmrg' ' ' >> $depfile
182382ff0afSmrg    echo >> $depfile
183382ff0afSmrg
184382ff0afSmrg    # The second pass generates a dummy entry for each header file.
185382ff0afSmrg    tr ' ' '
186382ff0afSmrg' < "$tmpdepfile" \
187382ff0afSmrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
188382ff0afSmrg   >> $depfile
189382ff0afSmrg  else
190382ff0afSmrg    # The sourcefile does not contain any dependencies, so just
191382ff0afSmrg    # store a dummy comment line, to avoid errors with the Makefile
192382ff0afSmrg    # "include basename.Plo" scheme.
193382ff0afSmrg    echo "#dummy" > "$depfile"
194382ff0afSmrg  fi
195382ff0afSmrg  rm -f "$tmpdepfile"
196382ff0afSmrg  ;;
197382ff0afSmrg
198382ff0afSmrgaix)
199382ff0afSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
200382ff0afSmrg  # in a .u file.  In older versions, this file always lives in the
201382ff0afSmrg  # current directory.  Also, the AIX compiler puts `$object:' at the
202382ff0afSmrg  # start of each line; $object doesn't have directory information.
203382ff0afSmrg  # Version 6 uses the directory in both cases.
204382ff0afSmrg  stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
205382ff0afSmrg  tmpdepfile="$stripped.u"
206382ff0afSmrg  if test "$libtool" = yes; then
207382ff0afSmrg    "$@" -Wc,-M
208382ff0afSmrg  else
209382ff0afSmrg    "$@" -M
210382ff0afSmrg  fi
211382ff0afSmrg  stat=$?
212382ff0afSmrg
213382ff0afSmrg  if test -f "$tmpdepfile"; then :
214382ff0afSmrg  else
215382ff0afSmrg    stripped=`echo "$stripped" | sed 's,^.*/,,'`
216382ff0afSmrg    tmpdepfile="$stripped.u"
217382ff0afSmrg  fi
218382ff0afSmrg
219382ff0afSmrg  if test $stat -eq 0; then :
220382ff0afSmrg  else
221382ff0afSmrg    rm -f "$tmpdepfile"
222382ff0afSmrg    exit $stat
223382ff0afSmrg  fi
224382ff0afSmrg
225382ff0afSmrg  if test -f "$tmpdepfile"; then
226382ff0afSmrg    outname="$stripped.o"
227382ff0afSmrg    # Each line is of the form `foo.o: dependent.h'.
228382ff0afSmrg    # Do two passes, one to just change these to
229382ff0afSmrg    # `$object: dependent.h' and one to simply `dependent.h:'.
230382ff0afSmrg    sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
231382ff0afSmrg    sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
232382ff0afSmrg  else
233382ff0afSmrg    # The sourcefile does not contain any dependencies, so just
234382ff0afSmrg    # store a dummy comment line, to avoid errors with the Makefile
235382ff0afSmrg    # "include basename.Plo" scheme.
236382ff0afSmrg    echo "#dummy" > "$depfile"
237382ff0afSmrg  fi
238382ff0afSmrg  rm -f "$tmpdepfile"
239382ff0afSmrg  ;;
240382ff0afSmrg
241382ff0afSmrgicc)
242382ff0afSmrg  # Intel's C compiler understands `-MD -MF file'.  However on
243382ff0afSmrg  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
244382ff0afSmrg  # ICC 7.0 will fill foo.d with something like
245382ff0afSmrg  #    foo.o: sub/foo.c
246382ff0afSmrg  #    foo.o: sub/foo.h
247382ff0afSmrg  # which is wrong.  We want:
248382ff0afSmrg  #    sub/foo.o: sub/foo.c
249382ff0afSmrg  #    sub/foo.o: sub/foo.h
250382ff0afSmrg  #    sub/foo.c:
251382ff0afSmrg  #    sub/foo.h:
252382ff0afSmrg  # ICC 7.1 will output
253382ff0afSmrg  #    foo.o: sub/foo.c sub/foo.h
254382ff0afSmrg  # and will wrap long lines using \ :
255382ff0afSmrg  #    foo.o: sub/foo.c ... \
256382ff0afSmrg  #     sub/foo.h ... \
257382ff0afSmrg  #     ...
258382ff0afSmrg
259382ff0afSmrg  "$@" -MD -MF "$tmpdepfile"
260382ff0afSmrg  stat=$?
261382ff0afSmrg  if test $stat -eq 0; then :
262382ff0afSmrg  else
263382ff0afSmrg    rm -f "$tmpdepfile"
264382ff0afSmrg    exit $stat
265382ff0afSmrg  fi
266382ff0afSmrg  rm -f "$depfile"
267382ff0afSmrg  # Each line is of the form `foo.o: dependent.h',
268382ff0afSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
269382ff0afSmrg  # Do two passes, one to just change these to
270382ff0afSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
271382ff0afSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
272382ff0afSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
273382ff0afSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
274382ff0afSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
275382ff0afSmrg    sed -e 's/$/ :/' >> "$depfile"
276382ff0afSmrg  rm -f "$tmpdepfile"
277382ff0afSmrg  ;;
278382ff0afSmrg
279382ff0afSmrgtru64)
280382ff0afSmrg   # The Tru64 compiler uses -MD to generate dependencies as a side
281382ff0afSmrg   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
282382ff0afSmrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
283382ff0afSmrg   # dependencies in `foo.d' instead, so we check for that too.
284382ff0afSmrg   # Subdirectories are respected.
285382ff0afSmrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
286382ff0afSmrg   test "x$dir" = "x$object" && dir=
287382ff0afSmrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
288382ff0afSmrg
289382ff0afSmrg   if test "$libtool" = yes; then
290382ff0afSmrg      # With Tru64 cc, shared objects can also be used to make a
291382ff0afSmrg      # static library.  This mecanism is used in libtool 1.4 series to
292382ff0afSmrg      # handle both shared and static libraries in a single compilation.
293382ff0afSmrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
294382ff0afSmrg      #
295382ff0afSmrg      # With libtool 1.5 this exception was removed, and libtool now
296382ff0afSmrg      # generates 2 separate objects for the 2 libraries.  These two
297382ff0afSmrg      # compilations output dependencies in in $dir.libs/$base.o.d and
298382ff0afSmrg      # in $dir$base.o.d.  We have to check for both files, because
299382ff0afSmrg      # one of the two compilations can be disabled.  We should prefer
300382ff0afSmrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
301382ff0afSmrg      # automatically cleaned when .libs/ is deleted, while ignoring
302382ff0afSmrg      # the former would cause a distcleancheck panic.
303382ff0afSmrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
304382ff0afSmrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
305382ff0afSmrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
306382ff0afSmrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
307382ff0afSmrg      "$@" -Wc,-MD
308382ff0afSmrg   else
309382ff0afSmrg      tmpdepfile1=$dir$base.o.d
310382ff0afSmrg      tmpdepfile2=$dir$base.d
311382ff0afSmrg      tmpdepfile3=$dir$base.d
312382ff0afSmrg      tmpdepfile4=$dir$base.d
313382ff0afSmrg      "$@" -MD
314382ff0afSmrg   fi
315382ff0afSmrg
316382ff0afSmrg   stat=$?
317382ff0afSmrg   if test $stat -eq 0; then :
318382ff0afSmrg   else
319382ff0afSmrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
320382ff0afSmrg      exit $stat
321382ff0afSmrg   fi
322382ff0afSmrg
323382ff0afSmrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
324382ff0afSmrg   do
325382ff0afSmrg     test -f "$tmpdepfile" && break
326382ff0afSmrg   done
327382ff0afSmrg   if test -f "$tmpdepfile"; then
328382ff0afSmrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
329382ff0afSmrg      # That's a tab and a space in the [].
330382ff0afSmrg      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
331382ff0afSmrg   else
332382ff0afSmrg      echo "#dummy" > "$depfile"
333382ff0afSmrg   fi
334382ff0afSmrg   rm -f "$tmpdepfile"
335382ff0afSmrg   ;;
336382ff0afSmrg
337382ff0afSmrg#nosideeffect)
338382ff0afSmrg  # This comment above is used by automake to tell side-effect
339382ff0afSmrg  # dependency tracking mechanisms from slower ones.
340382ff0afSmrg
341382ff0afSmrgdashmstdout)
342382ff0afSmrg  # Important note: in order to support this mode, a compiler *must*
343382ff0afSmrg  # always write the preprocessed file to stdout, regardless of -o.
344382ff0afSmrg  "$@" || exit $?
345382ff0afSmrg
346382ff0afSmrg  # Remove the call to Libtool.
347382ff0afSmrg  if test "$libtool" = yes; then
348382ff0afSmrg    while test $1 != '--mode=compile'; do
349382ff0afSmrg      shift
350382ff0afSmrg    done
351382ff0afSmrg    shift
352382ff0afSmrg  fi
353382ff0afSmrg
354382ff0afSmrg  # Remove `-o $object'.
355382ff0afSmrg  IFS=" "
356382ff0afSmrg  for arg
357382ff0afSmrg  do
358382ff0afSmrg    case $arg in
359382ff0afSmrg    -o)
360382ff0afSmrg      shift
361382ff0afSmrg      ;;
362382ff0afSmrg    $object)
363382ff0afSmrg      shift
364382ff0afSmrg      ;;
365382ff0afSmrg    *)
366382ff0afSmrg      set fnord "$@" "$arg"
367382ff0afSmrg      shift # fnord
368382ff0afSmrg      shift # $arg
369382ff0afSmrg      ;;
370382ff0afSmrg    esac
371382ff0afSmrg  done
372382ff0afSmrg
373382ff0afSmrg  test -z "$dashmflag" && dashmflag=-M
374382ff0afSmrg  # Require at least two characters before searching for `:'
375382ff0afSmrg  # in the target name.  This is to cope with DOS-style filenames:
376382ff0afSmrg  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
377382ff0afSmrg  "$@" $dashmflag |
378382ff0afSmrg    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
379382ff0afSmrg  rm -f "$depfile"
380382ff0afSmrg  cat < "$tmpdepfile" > "$depfile"
381382ff0afSmrg  tr ' ' '
382382ff0afSmrg' < "$tmpdepfile" | \
383382ff0afSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
384382ff0afSmrg## correctly.  Breaking it into two sed invocations is a workaround.
385382ff0afSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
386382ff0afSmrg  rm -f "$tmpdepfile"
387382ff0afSmrg  ;;
388382ff0afSmrg
389382ff0afSmrgdashXmstdout)
390382ff0afSmrg  # This case only exists to satisfy depend.m4.  It is never actually
391382ff0afSmrg  # run, as this mode is specially recognized in the preamble.
392382ff0afSmrg  exit 1
393382ff0afSmrg  ;;
394382ff0afSmrg
395382ff0afSmrgmakedepend)
396382ff0afSmrg  "$@" || exit $?
397382ff0afSmrg  # Remove any Libtool call
398382ff0afSmrg  if test "$libtool" = yes; then
399382ff0afSmrg    while test $1 != '--mode=compile'; do
400382ff0afSmrg      shift
401382ff0afSmrg    done
402382ff0afSmrg    shift
403382ff0afSmrg  fi
404382ff0afSmrg  # X makedepend
405382ff0afSmrg  shift
406382ff0afSmrg  cleared=no
407382ff0afSmrg  for arg in "$@"; do
408382ff0afSmrg    case $cleared in
409382ff0afSmrg    no)
410382ff0afSmrg      set ""; shift
411382ff0afSmrg      cleared=yes ;;
412382ff0afSmrg    esac
413382ff0afSmrg    case "$arg" in
414382ff0afSmrg    -D*|-I*)
415382ff0afSmrg      set fnord "$@" "$arg"; shift ;;
416382ff0afSmrg    # Strip any option that makedepend may not understand.  Remove
417382ff0afSmrg    # the object too, otherwise makedepend will parse it as a source file.
418382ff0afSmrg    -*|$object)
419382ff0afSmrg      ;;
420382ff0afSmrg    *)
421382ff0afSmrg      set fnord "$@" "$arg"; shift ;;
422382ff0afSmrg    esac
423382ff0afSmrg  done
424382ff0afSmrg  obj_suffix="`echo $object | sed 's/^.*\././'`"
425382ff0afSmrg  touch "$tmpdepfile"
426382ff0afSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
427382ff0afSmrg  rm -f "$depfile"
428382ff0afSmrg  cat < "$tmpdepfile" > "$depfile"
429382ff0afSmrg  sed '1,2d' "$tmpdepfile" | tr ' ' '
430382ff0afSmrg' | \
431382ff0afSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
432382ff0afSmrg## correctly.  Breaking it into two sed invocations is a workaround.
433382ff0afSmrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
434382ff0afSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
435382ff0afSmrg  ;;
436382ff0afSmrg
437382ff0afSmrgcpp)
438382ff0afSmrg  # Important note: in order to support this mode, a compiler *must*
439382ff0afSmrg  # always write the preprocessed file to stdout.
440382ff0afSmrg  "$@" || exit $?
441382ff0afSmrg
442382ff0afSmrg  # Remove the call to Libtool.
443382ff0afSmrg  if test "$libtool" = yes; then
444382ff0afSmrg    while test $1 != '--mode=compile'; do
445382ff0afSmrg      shift
446382ff0afSmrg    done
447382ff0afSmrg    shift
448382ff0afSmrg  fi
449382ff0afSmrg
450382ff0afSmrg  # Remove `-o $object'.
451382ff0afSmrg  IFS=" "
452382ff0afSmrg  for arg
453382ff0afSmrg  do
454382ff0afSmrg    case $arg in
455382ff0afSmrg    -o)
456382ff0afSmrg      shift
457382ff0afSmrg      ;;
458382ff0afSmrg    $object)
459382ff0afSmrg      shift
460382ff0afSmrg      ;;
461382ff0afSmrg    *)
462382ff0afSmrg      set fnord "$@" "$arg"
463382ff0afSmrg      shift # fnord
464382ff0afSmrg      shift # $arg
465382ff0afSmrg      ;;
466382ff0afSmrg    esac
467382ff0afSmrg  done
468382ff0afSmrg
469382ff0afSmrg  "$@" -E |
470382ff0afSmrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
471382ff0afSmrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
472382ff0afSmrg    sed '$ s: \\$::' > "$tmpdepfile"
473382ff0afSmrg  rm -f "$depfile"
474382ff0afSmrg  echo "$object : \\" > "$depfile"
475382ff0afSmrg  cat < "$tmpdepfile" >> "$depfile"
476382ff0afSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
477382ff0afSmrg  rm -f "$tmpdepfile"
478382ff0afSmrg  ;;
479382ff0afSmrg
480382ff0afSmrgmsvisualcpp)
481382ff0afSmrg  # Important note: in order to support this mode, a compiler *must*
482382ff0afSmrg  # always write the preprocessed file to stdout, regardless of -o,
483382ff0afSmrg  # because we must use -o when running libtool.
484382ff0afSmrg  "$@" || exit $?
485382ff0afSmrg  IFS=" "
486382ff0afSmrg  for arg
487382ff0afSmrg  do
488382ff0afSmrg    case "$arg" in
489382ff0afSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
490382ff0afSmrg	set fnord "$@"
491382ff0afSmrg	shift
492382ff0afSmrg	shift
493382ff0afSmrg	;;
494382ff0afSmrg    *)
495382ff0afSmrg	set fnord "$@" "$arg"
496382ff0afSmrg	shift
497382ff0afSmrg	shift
498382ff0afSmrg	;;
499382ff0afSmrg    esac
500382ff0afSmrg  done
501382ff0afSmrg  "$@" -E |
502382ff0afSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
503382ff0afSmrg  rm -f "$depfile"
504382ff0afSmrg  echo "$object : \\" > "$depfile"
505382ff0afSmrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
506382ff0afSmrg  echo "	" >> "$depfile"
507382ff0afSmrg  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
508382ff0afSmrg  rm -f "$tmpdepfile"
509382ff0afSmrg  ;;
510382ff0afSmrg
511382ff0afSmrgnone)
512382ff0afSmrg  exec "$@"
513382ff0afSmrg  ;;
514382ff0afSmrg
515382ff0afSmrg*)
516382ff0afSmrg  echo "Unknown depmode $depmode" 1>&2
517382ff0afSmrg  exit 1
518382ff0afSmrg  ;;
519382ff0afSmrgesac
520382ff0afSmrg
521382ff0afSmrgexit 0
522382ff0afSmrg
523382ff0afSmrg# Local Variables:
524382ff0afSmrg# mode: shell-script
525382ff0afSmrg# sh-indentation: 2
526382ff0afSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
527382ff0afSmrg# time-stamp-start: "scriptversion="
528382ff0afSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
529382ff0afSmrg# time-stamp-end: "$"
530382ff0afSmrg# End:
531