depcomp revision f1ee322d
1c43cc173Smrg#! /bin/sh
2c43cc173Smrg# depcomp - compile a program generating dependencies as side-effects
3c43cc173Smrg
4f1ee322dSmrgscriptversion=2012-03-27.16; # UTC
5c43cc173Smrg
6f1ee322dSmrg# Copyright (C) 1999-2012 Free Software Foundation, Inc.
7c43cc173Smrg
8c43cc173Smrg# This program is free software; you can redistribute it and/or modify
9c43cc173Smrg# it under the terms of the GNU General Public License as published by
10c43cc173Smrg# the Free Software Foundation; either version 2, or (at your option)
11c43cc173Smrg# any later version.
12c43cc173Smrg
13c43cc173Smrg# This program is distributed in the hope that it will be useful,
14c43cc173Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15c43cc173Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c43cc173Smrg# GNU General Public License for more details.
17c43cc173Smrg
18c43cc173Smrg# You should have received a copy of the GNU General Public License
19c27c18e8Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20c43cc173Smrg
21c43cc173Smrg# As a special exception to the GNU General Public License, if you
22c43cc173Smrg# distribute this file as part of a program that contains a
23c43cc173Smrg# configuration script generated by Autoconf, you may include it under
24c43cc173Smrg# the same distribution terms that you use for the rest of that program.
25c43cc173Smrg
26c43cc173Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27c43cc173Smrg
28c43cc173Smrgcase $1 in
29c43cc173Smrg  '')
30f1ee322dSmrg     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31c43cc173Smrg     exit 1;
32c43cc173Smrg     ;;
33c43cc173Smrg  -h | --h*)
34c43cc173Smrg    cat <<\EOF
35c43cc173SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36c43cc173Smrg
37c43cc173SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38c43cc173Smrgas side-effects.
39c43cc173Smrg
40c43cc173SmrgEnvironment variables:
41c43cc173Smrg  depmode     Dependency tracking mode.
42f1ee322dSmrg  source      Source file read by 'PROGRAMS ARGS'.
43f1ee322dSmrg  object      Object file output by 'PROGRAMS ARGS'.
44c43cc173Smrg  DEPDIR      directory where to store dependencies.
45c43cc173Smrg  depfile     Dependency file to output.
46f1ee322dSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
47c43cc173Smrg  libtool     Whether libtool is used (yes/no).
48c43cc173Smrg
49c43cc173SmrgReport bugs to <bug-automake@gnu.org>.
50c43cc173SmrgEOF
51c43cc173Smrg    exit $?
52c43cc173Smrg    ;;
53c43cc173Smrg  -v | --v*)
54c43cc173Smrg    echo "depcomp $scriptversion"
55c43cc173Smrg    exit $?
56c43cc173Smrg    ;;
57c43cc173Smrgesac
58c43cc173Smrg
59f1ee322dSmrg# A tabulation character.
60f1ee322dSmrgtab='	'
61f1ee322dSmrg# A newline character.
62f1ee322dSmrgnl='
63f1ee322dSmrg'
64f1ee322dSmrg
65c43cc173Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
66c43cc173Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
67c43cc173Smrg  exit 1
68c43cc173Smrgfi
69c43cc173Smrg
70c43cc173Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
71c43cc173Smrgdepfile=${depfile-`echo "$object" |
72c43cc173Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
73c43cc173Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
74c43cc173Smrg
75c43cc173Smrgrm -f "$tmpdepfile"
76c43cc173Smrg
77c43cc173Smrg# Some modes work just like other modes, but use different flags.  We
78c43cc173Smrg# parameterize here, but still list the modes in the big case below,
79c43cc173Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
80c43cc173Smrg# here, because this file can only contain one case statement.
81c43cc173Smrgif test "$depmode" = hp; then
82c43cc173Smrg  # HP compiler uses -M and no extra arg.
83c43cc173Smrg  gccflag=-M
84c43cc173Smrg  depmode=gcc
85c43cc173Smrgfi
86c43cc173Smrg
87c43cc173Smrgif test "$depmode" = dashXmstdout; then
88c43cc173Smrg   # This is just like dashmstdout with a different argument.
89c43cc173Smrg   dashmflag=-xM
90c43cc173Smrg   depmode=dashmstdout
91c43cc173Smrgfi
92c43cc173Smrg
93c27c18e8Smrgcygpath_u="cygpath -u -f -"
94c27c18e8Smrgif test "$depmode" = msvcmsys; then
95c27c18e8Smrg   # This is just like msvisualcpp but w/o cygpath translation.
96c27c18e8Smrg   # Just convert the backslash-escaped backslashes to single forward
97c27c18e8Smrg   # slashes to satisfy depend.m4
98f1ee322dSmrg   cygpath_u='sed s,\\\\,/,g'
99c27c18e8Smrg   depmode=msvisualcpp
100c27c18e8Smrgfi
101c27c18e8Smrg
102f1ee322dSmrgif test "$depmode" = msvc7msys; then
103f1ee322dSmrg   # This is just like msvc7 but w/o cygpath translation.
104f1ee322dSmrg   # Just convert the backslash-escaped backslashes to single forward
105f1ee322dSmrg   # slashes to satisfy depend.m4
106f1ee322dSmrg   cygpath_u='sed s,\\\\,/,g'
107f1ee322dSmrg   depmode=msvc7
108f1ee322dSmrgfi
109f1ee322dSmrg
110f1ee322dSmrgif test "$depmode" = xlc; then
111f1ee322dSmrg   # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency informations.
112f1ee322dSmrg   gccflag=-qmakedep=gcc,-MF
113f1ee322dSmrg   depmode=gcc
114f1ee322dSmrgfi
115f1ee322dSmrg
116c43cc173Smrgcase "$depmode" in
117c43cc173Smrggcc3)
118c43cc173Smrg## gcc 3 implements dependency tracking that does exactly what
119c43cc173Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
120c43cc173Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
121c43cc173Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
122c43cc173Smrg## the command line argument order; so add the flags where they
123c43cc173Smrg## appear in depend2.am.  Note that the slowdown incurred here
124c43cc173Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
125c43cc173Smrg  for arg
126c43cc173Smrg  do
127c43cc173Smrg    case $arg in
128c43cc173Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
129c43cc173Smrg    *)  set fnord "$@" "$arg" ;;
130c43cc173Smrg    esac
131c43cc173Smrg    shift # fnord
132c43cc173Smrg    shift # $arg
133c43cc173Smrg  done
134c43cc173Smrg  "$@"
135c43cc173Smrg  stat=$?
136c43cc173Smrg  if test $stat -eq 0; then :
137c43cc173Smrg  else
138c43cc173Smrg    rm -f "$tmpdepfile"
139c43cc173Smrg    exit $stat
140c43cc173Smrg  fi
141c43cc173Smrg  mv "$tmpdepfile" "$depfile"
142c43cc173Smrg  ;;
143c43cc173Smrg
144c43cc173Smrggcc)
145c43cc173Smrg## There are various ways to get dependency output from gcc.  Here's
146c43cc173Smrg## why we pick this rather obscure method:
147c43cc173Smrg## - Don't want to use -MD because we'd like the dependencies to end
148c43cc173Smrg##   up in a subdir.  Having to rename by hand is ugly.
149c43cc173Smrg##   (We might end up doing this anyway to support other compilers.)
150c43cc173Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
151c43cc173Smrg##   -MM, not -M (despite what the docs say).
152c43cc173Smrg## - Using -M directly means running the compiler twice (even worse
153c43cc173Smrg##   than renaming).
154c43cc173Smrg  if test -z "$gccflag"; then
155c43cc173Smrg    gccflag=-MD,
156c43cc173Smrg  fi
157c43cc173Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
158c43cc173Smrg  stat=$?
159c43cc173Smrg  if test $stat -eq 0; then :
160c43cc173Smrg  else
161c43cc173Smrg    rm -f "$tmpdepfile"
162c43cc173Smrg    exit $stat
163c43cc173Smrg  fi
164c43cc173Smrg  rm -f "$depfile"
165c43cc173Smrg  echo "$object : \\" > "$depfile"
166c43cc173Smrg  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
167c43cc173Smrg## The second -e expression handles DOS-style file names with drive letters.
168c43cc173Smrg  sed -e 's/^[^:]*: / /' \
169c43cc173Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
170f1ee322dSmrg## This next piece of magic avoids the "deleted header file" problem.
171c43cc173Smrg## The problem is that when a header file which appears in a .P file
172c43cc173Smrg## is deleted, the dependency causes make to die (because there is
173c43cc173Smrg## typically no way to rebuild the header).  We avoid this by adding
174c43cc173Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
175c43cc173Smrg## this for us directly.
176f1ee322dSmrg  tr ' ' "$nl" < "$tmpdepfile" |
177f1ee322dSmrg## Some versions of gcc put a space before the ':'.  On the theory
178c43cc173Smrg## that the space means something, we add a space to the output as
179f1ee322dSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
180f1ee322dSmrg## to the object.  Take care to not repeat it in the output.
181c43cc173Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
182c43cc173Smrg## correctly.  Breaking it into two sed invocations is a workaround.
183f1ee322dSmrg    sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
184f1ee322dSmrg      | sed -e 's/$/ :/' >> "$depfile"
185c43cc173Smrg  rm -f "$tmpdepfile"
186c43cc173Smrg  ;;
187c43cc173Smrg
188c43cc173Smrghp)
189c43cc173Smrg  # This case exists only to let depend.m4 do its work.  It works by
190c43cc173Smrg  # looking at the text of this script.  This case will never be run,
191c43cc173Smrg  # since it is checked for above.
192c43cc173Smrg  exit 1
193c43cc173Smrg  ;;
194c43cc173Smrg
195c43cc173Smrgsgi)
196c43cc173Smrg  if test "$libtool" = yes; then
197c43cc173Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
198c43cc173Smrg  else
199c43cc173Smrg    "$@" -MDupdate "$tmpdepfile"
200c43cc173Smrg  fi
201c43cc173Smrg  stat=$?
202c43cc173Smrg  if test $stat -eq 0; then :
203c43cc173Smrg  else
204c43cc173Smrg    rm -f "$tmpdepfile"
205c43cc173Smrg    exit $stat
206c43cc173Smrg  fi
207c43cc173Smrg  rm -f "$depfile"
208c43cc173Smrg
209c43cc173Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
210c43cc173Smrg    echo "$object : \\" > "$depfile"
211c43cc173Smrg
212c43cc173Smrg    # Clip off the initial element (the dependent).  Don't try to be
213c43cc173Smrg    # clever and replace this with sed code, as IRIX sed won't handle
214c43cc173Smrg    # lines with more than a fixed number of characters (4096 in
215c43cc173Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
216f1ee322dSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
217c43cc173Smrg    # dependency line.
218f1ee322dSmrg    tr ' ' "$nl" < "$tmpdepfile" \
219c43cc173Smrg    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
220f1ee322dSmrg    tr "$nl" ' ' >> "$depfile"
221c27c18e8Smrg    echo >> "$depfile"
222c43cc173Smrg
223c43cc173Smrg    # The second pass generates a dummy entry for each header file.
224f1ee322dSmrg    tr ' ' "$nl" < "$tmpdepfile" \
225c43cc173Smrg   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
226c27c18e8Smrg   >> "$depfile"
227c43cc173Smrg  else
228c43cc173Smrg    # The sourcefile does not contain any dependencies, so just
229c43cc173Smrg    # store a dummy comment line, to avoid errors with the Makefile
230c43cc173Smrg    # "include basename.Plo" scheme.
231c43cc173Smrg    echo "#dummy" > "$depfile"
232c43cc173Smrg  fi
233c43cc173Smrg  rm -f "$tmpdepfile"
234c43cc173Smrg  ;;
235c43cc173Smrg
236f1ee322dSmrgxlc)
237f1ee322dSmrg  # This case exists only to let depend.m4 do its work.  It works by
238f1ee322dSmrg  # looking at the text of this script.  This case will never be run,
239f1ee322dSmrg  # since it is checked for above.
240f1ee322dSmrg  exit 1
241f1ee322dSmrg  ;;
242f1ee322dSmrg
243c43cc173Smrgaix)
244c43cc173Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
245c43cc173Smrg  # in a .u file.  In older versions, this file always lives in the
246f1ee322dSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
247c43cc173Smrg  # start of each line; $object doesn't have directory information.
248c43cc173Smrg  # Version 6 uses the directory in both cases.
249c27c18e8Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
250c27c18e8Smrg  test "x$dir" = "x$object" && dir=
251c27c18e8Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
252c43cc173Smrg  if test "$libtool" = yes; then
253c27c18e8Smrg    tmpdepfile1=$dir$base.u
254c27c18e8Smrg    tmpdepfile2=$base.u
255c27c18e8Smrg    tmpdepfile3=$dir.libs/$base.u
256c43cc173Smrg    "$@" -Wc,-M
257c43cc173Smrg  else
258c27c18e8Smrg    tmpdepfile1=$dir$base.u
259c27c18e8Smrg    tmpdepfile2=$dir$base.u
260c27c18e8Smrg    tmpdepfile3=$dir$base.u
261c43cc173Smrg    "$@" -M
262c43cc173Smrg  fi
263c43cc173Smrg  stat=$?
264c43cc173Smrg
265c43cc173Smrg  if test $stat -eq 0; then :
266c43cc173Smrg  else
267c27c18e8Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
268c43cc173Smrg    exit $stat
269c43cc173Smrg  fi
270c43cc173Smrg
271c27c18e8Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
272c27c18e8Smrg  do
273c27c18e8Smrg    test -f "$tmpdepfile" && break
274c27c18e8Smrg  done
275c43cc173Smrg  if test -f "$tmpdepfile"; then
276f1ee322dSmrg    # Each line is of the form 'foo.o: dependent.h'.
277c43cc173Smrg    # Do two passes, one to just change these to
278f1ee322dSmrg    # '$object: dependent.h' and one to simply 'dependent.h:'.
279c27c18e8Smrg    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
280f1ee322dSmrg    sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
281c43cc173Smrg  else
282c43cc173Smrg    # The sourcefile does not contain any dependencies, so just
283c43cc173Smrg    # store a dummy comment line, to avoid errors with the Makefile
284c43cc173Smrg    # "include basename.Plo" scheme.
285c43cc173Smrg    echo "#dummy" > "$depfile"
286c43cc173Smrg  fi
287c43cc173Smrg  rm -f "$tmpdepfile"
288c43cc173Smrg  ;;
289c43cc173Smrg
290c43cc173Smrgicc)
291f1ee322dSmrg  # Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'.
292f1ee322dSmrg  # However on
293f1ee322dSmrg  #    $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c
294c43cc173Smrg  # ICC 7.0 will fill foo.d with something like
295c43cc173Smrg  #    foo.o: sub/foo.c
296c43cc173Smrg  #    foo.o: sub/foo.h
297f1ee322dSmrg  # which is wrong.  We want
298c43cc173Smrg  #    sub/foo.o: sub/foo.c
299c43cc173Smrg  #    sub/foo.o: sub/foo.h
300c43cc173Smrg  #    sub/foo.c:
301c43cc173Smrg  #    sub/foo.h:
302c43cc173Smrg  # ICC 7.1 will output
303c43cc173Smrg  #    foo.o: sub/foo.c sub/foo.h
304f1ee322dSmrg  # and will wrap long lines using '\':
305c43cc173Smrg  #    foo.o: sub/foo.c ... \
306c43cc173Smrg  #     sub/foo.h ... \
307c43cc173Smrg  #     ...
308f1ee322dSmrg  # tcc 0.9.26 (FIXME still under development at the moment of writing)
309f1ee322dSmrg  # will emit a similar output, but also prepend the continuation lines
310f1ee322dSmrg  # with horizontal tabulation characters.
311c43cc173Smrg  "$@" -MD -MF "$tmpdepfile"
312c43cc173Smrg  stat=$?
313c43cc173Smrg  if test $stat -eq 0; then :
314c43cc173Smrg  else
315c43cc173Smrg    rm -f "$tmpdepfile"
316c43cc173Smrg    exit $stat
317c43cc173Smrg  fi
318c43cc173Smrg  rm -f "$depfile"
319f1ee322dSmrg  # Each line is of the form 'foo.o: dependent.h',
320f1ee322dSmrg  # or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'.
321c43cc173Smrg  # Do two passes, one to just change these to
322f1ee322dSmrg  # '$object: dependent.h' and one to simply 'dependent.h:'.
323f1ee322dSmrg  sed -e "s/^[ $tab][ $tab]*/  /" -e "s,^[^:]*:,$object :," \
324f1ee322dSmrg    < "$tmpdepfile" > "$depfile"
325f1ee322dSmrg  sed '
326f1ee322dSmrg    s/[ '"$tab"'][ '"$tab"']*/ /g
327f1ee322dSmrg    s/^ *//
328f1ee322dSmrg    s/ *\\*$//
329f1ee322dSmrg    s/^[^:]*: *//
330f1ee322dSmrg    /^$/d
331f1ee322dSmrg    /:$/d
332f1ee322dSmrg    s/$/ :/
333f1ee322dSmrg  ' < "$tmpdepfile" >> "$depfile"
334c43cc173Smrg  rm -f "$tmpdepfile"
335c43cc173Smrg  ;;
336c43cc173Smrg
337c43cc173Smrghp2)
338c43cc173Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
339c43cc173Smrg  # compilers, which have integrated preprocessors.  The correct option
340c43cc173Smrg  # to use with these is +Maked; it writes dependencies to a file named
341c43cc173Smrg  # 'foo.d', which lands next to the object file, wherever that
342c43cc173Smrg  # happens to be.
343c43cc173Smrg  # Much of this is similar to the tru64 case; see comments there.
344c43cc173Smrg  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
345c43cc173Smrg  test "x$dir" = "x$object" && dir=
346c43cc173Smrg  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
347c43cc173Smrg  if test "$libtool" = yes; then
348c43cc173Smrg    tmpdepfile1=$dir$base.d
349c43cc173Smrg    tmpdepfile2=$dir.libs/$base.d
350c43cc173Smrg    "$@" -Wc,+Maked
351c43cc173Smrg  else
352c43cc173Smrg    tmpdepfile1=$dir$base.d
353c43cc173Smrg    tmpdepfile2=$dir$base.d
354c43cc173Smrg    "$@" +Maked
355c43cc173Smrg  fi
356c43cc173Smrg  stat=$?
357c43cc173Smrg  if test $stat -eq 0; then :
358c43cc173Smrg  else
359c43cc173Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
360c43cc173Smrg     exit $stat
361c43cc173Smrg  fi
362c43cc173Smrg
363c43cc173Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
364c43cc173Smrg  do
365c43cc173Smrg    test -f "$tmpdepfile" && break
366c43cc173Smrg  done
367c43cc173Smrg  if test -f "$tmpdepfile"; then
368c43cc173Smrg    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
369f1ee322dSmrg    # Add 'dependent.h:' lines.
370c27c18e8Smrg    sed -ne '2,${
371c27c18e8Smrg	       s/^ *//
372c27c18e8Smrg	       s/ \\*$//
373c27c18e8Smrg	       s/$/:/
374c27c18e8Smrg	       p
375c27c18e8Smrg	     }' "$tmpdepfile" >> "$depfile"
376c43cc173Smrg  else
377c43cc173Smrg    echo "#dummy" > "$depfile"
378c43cc173Smrg  fi
379c43cc173Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
380c43cc173Smrg  ;;
381c43cc173Smrg
382c43cc173Smrgtru64)
383c43cc173Smrg   # The Tru64 compiler uses -MD to generate dependencies as a side
384f1ee322dSmrg   # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
385c43cc173Smrg   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
386f1ee322dSmrg   # dependencies in 'foo.d' instead, so we check for that too.
387c43cc173Smrg   # Subdirectories are respected.
388c43cc173Smrg   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
389c43cc173Smrg   test "x$dir" = "x$object" && dir=
390c43cc173Smrg   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
391c43cc173Smrg
392c43cc173Smrg   if test "$libtool" = yes; then
393c43cc173Smrg      # With Tru64 cc, shared objects can also be used to make a
394c43cc173Smrg      # static library.  This mechanism is used in libtool 1.4 series to
395c43cc173Smrg      # handle both shared and static libraries in a single compilation.
396c43cc173Smrg      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
397c43cc173Smrg      #
398c43cc173Smrg      # With libtool 1.5 this exception was removed, and libtool now
399c43cc173Smrg      # generates 2 separate objects for the 2 libraries.  These two
400c43cc173Smrg      # compilations output dependencies in $dir.libs/$base.o.d and
401c43cc173Smrg      # in $dir$base.o.d.  We have to check for both files, because
402c43cc173Smrg      # one of the two compilations can be disabled.  We should prefer
403c43cc173Smrg      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
404c43cc173Smrg      # automatically cleaned when .libs/ is deleted, while ignoring
405c43cc173Smrg      # the former would cause a distcleancheck panic.
406c43cc173Smrg      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
407c43cc173Smrg      tmpdepfile2=$dir$base.o.d          # libtool 1.5
408c43cc173Smrg      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
409c43cc173Smrg      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
410c43cc173Smrg      "$@" -Wc,-MD
411c43cc173Smrg   else
412c43cc173Smrg      tmpdepfile1=$dir$base.o.d
413c43cc173Smrg      tmpdepfile2=$dir$base.d
414c43cc173Smrg      tmpdepfile3=$dir$base.d
415c43cc173Smrg      tmpdepfile4=$dir$base.d
416c43cc173Smrg      "$@" -MD
417c43cc173Smrg   fi
418c43cc173Smrg
419c43cc173Smrg   stat=$?
420c43cc173Smrg   if test $stat -eq 0; then :
421c43cc173Smrg   else
422c43cc173Smrg      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
423c43cc173Smrg      exit $stat
424c43cc173Smrg   fi
425c43cc173Smrg
426c43cc173Smrg   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
427c43cc173Smrg   do
428c43cc173Smrg     test -f "$tmpdepfile" && break
429c43cc173Smrg   done
430c43cc173Smrg   if test -f "$tmpdepfile"; then
431c43cc173Smrg      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
432f1ee322dSmrg      sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
433c43cc173Smrg   else
434c43cc173Smrg      echo "#dummy" > "$depfile"
435c43cc173Smrg   fi
436c43cc173Smrg   rm -f "$tmpdepfile"
437c43cc173Smrg   ;;
438c43cc173Smrg
439f1ee322dSmrgmsvc7)
440f1ee322dSmrg  if test "$libtool" = yes; then
441f1ee322dSmrg    showIncludes=-Wc,-showIncludes
442f1ee322dSmrg  else
443f1ee322dSmrg    showIncludes=-showIncludes
444f1ee322dSmrg  fi
445f1ee322dSmrg  "$@" $showIncludes > "$tmpdepfile"
446f1ee322dSmrg  stat=$?
447f1ee322dSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
448f1ee322dSmrg  if test "$stat" = 0; then :
449f1ee322dSmrg  else
450f1ee322dSmrg    rm -f "$tmpdepfile"
451f1ee322dSmrg    exit $stat
452f1ee322dSmrg  fi
453f1ee322dSmrg  rm -f "$depfile"
454f1ee322dSmrg  echo "$object : \\" > "$depfile"
455f1ee322dSmrg  # The first sed program below extracts the file names and escapes
456f1ee322dSmrg  # backslashes for cygpath.  The second sed program outputs the file
457f1ee322dSmrg  # name when reading, but also accumulates all include files in the
458f1ee322dSmrg  # hold buffer in order to output them again at the end.  This only
459f1ee322dSmrg  # works with sed implementations that can handle large buffers.
460f1ee322dSmrg  sed < "$tmpdepfile" -n '
461f1ee322dSmrg/^Note: including file:  *\(.*\)/ {
462f1ee322dSmrg  s//\1/
463f1ee322dSmrg  s/\\/\\\\/g
464f1ee322dSmrg  p
465f1ee322dSmrg}' | $cygpath_u | sort -u | sed -n '
466f1ee322dSmrgs/ /\\ /g
467f1ee322dSmrgs/\(.*\)/'"$tab"'\1 \\/p
468f1ee322dSmrgs/.\(.*\) \\/\1:/
469f1ee322dSmrgH
470f1ee322dSmrg$ {
471f1ee322dSmrg  s/.*/'"$tab"'/
472f1ee322dSmrg  G
473f1ee322dSmrg  p
474f1ee322dSmrg}' >> "$depfile"
475f1ee322dSmrg  rm -f "$tmpdepfile"
476f1ee322dSmrg  ;;
477f1ee322dSmrg
478f1ee322dSmrgmsvc7msys)
479f1ee322dSmrg  # This case exists only to let depend.m4 do its work.  It works by
480f1ee322dSmrg  # looking at the text of this script.  This case will never be run,
481f1ee322dSmrg  # since it is checked for above.
482f1ee322dSmrg  exit 1
483f1ee322dSmrg  ;;
484f1ee322dSmrg
485c43cc173Smrg#nosideeffect)
486c43cc173Smrg  # This comment above is used by automake to tell side-effect
487c43cc173Smrg  # dependency tracking mechanisms from slower ones.
488c43cc173Smrg
489c43cc173Smrgdashmstdout)
490c43cc173Smrg  # Important note: in order to support this mode, a compiler *must*
491c43cc173Smrg  # always write the preprocessed file to stdout, regardless of -o.
492c43cc173Smrg  "$@" || exit $?
493c43cc173Smrg
494c43cc173Smrg  # Remove the call to Libtool.
495c43cc173Smrg  if test "$libtool" = yes; then
496c27c18e8Smrg    while test "X$1" != 'X--mode=compile'; do
497c43cc173Smrg      shift
498c43cc173Smrg    done
499c43cc173Smrg    shift
500c43cc173Smrg  fi
501c43cc173Smrg
502f1ee322dSmrg  # Remove '-o $object'.
503c43cc173Smrg  IFS=" "
504c43cc173Smrg  for arg
505c43cc173Smrg  do
506c43cc173Smrg    case $arg in
507c43cc173Smrg    -o)
508c43cc173Smrg      shift
509c43cc173Smrg      ;;
510c43cc173Smrg    $object)
511c43cc173Smrg      shift
512c43cc173Smrg      ;;
513c43cc173Smrg    *)
514c43cc173Smrg      set fnord "$@" "$arg"
515c43cc173Smrg      shift # fnord
516c43cc173Smrg      shift # $arg
517c43cc173Smrg      ;;
518c43cc173Smrg    esac
519c43cc173Smrg  done
520c43cc173Smrg
521c43cc173Smrg  test -z "$dashmflag" && dashmflag=-M
522f1ee322dSmrg  # Require at least two characters before searching for ':'
523c43cc173Smrg  # in the target name.  This is to cope with DOS-style filenames:
524f1ee322dSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
525c43cc173Smrg  "$@" $dashmflag |
526f1ee322dSmrg    sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile"
527c43cc173Smrg  rm -f "$depfile"
528c43cc173Smrg  cat < "$tmpdepfile" > "$depfile"
529f1ee322dSmrg  tr ' ' "$nl" < "$tmpdepfile" | \
530c43cc173Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
531c43cc173Smrg## correctly.  Breaking it into two sed invocations is a workaround.
532c43cc173Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
533c43cc173Smrg  rm -f "$tmpdepfile"
534c43cc173Smrg  ;;
535c43cc173Smrg
536c43cc173SmrgdashXmstdout)
537c43cc173Smrg  # This case only exists to satisfy depend.m4.  It is never actually
538c43cc173Smrg  # run, as this mode is specially recognized in the preamble.
539c43cc173Smrg  exit 1
540c43cc173Smrg  ;;
541c43cc173Smrg
542c43cc173Smrgmakedepend)
543c43cc173Smrg  "$@" || exit $?
544c43cc173Smrg  # Remove any Libtool call
545c43cc173Smrg  if test "$libtool" = yes; then
546c27c18e8Smrg    while test "X$1" != 'X--mode=compile'; do
547c43cc173Smrg      shift
548c43cc173Smrg    done
549c43cc173Smrg    shift
550c43cc173Smrg  fi
551c43cc173Smrg  # X makedepend
552c43cc173Smrg  shift
553c27c18e8Smrg  cleared=no eat=no
554c27c18e8Smrg  for arg
555c27c18e8Smrg  do
556c43cc173Smrg    case $cleared in
557c43cc173Smrg    no)
558c43cc173Smrg      set ""; shift
559c43cc173Smrg      cleared=yes ;;
560c43cc173Smrg    esac
561c27c18e8Smrg    if test $eat = yes; then
562c27c18e8Smrg      eat=no
563c27c18e8Smrg      continue
564c27c18e8Smrg    fi
565c43cc173Smrg    case "$arg" in
566c43cc173Smrg    -D*|-I*)
567c43cc173Smrg      set fnord "$@" "$arg"; shift ;;
568c43cc173Smrg    # Strip any option that makedepend may not understand.  Remove
569c43cc173Smrg    # the object too, otherwise makedepend will parse it as a source file.
570c27c18e8Smrg    -arch)
571c27c18e8Smrg      eat=yes ;;
572c43cc173Smrg    -*|$object)
573c43cc173Smrg      ;;
574c43cc173Smrg    *)
575c43cc173Smrg      set fnord "$@" "$arg"; shift ;;
576c43cc173Smrg    esac
577c43cc173Smrg  done
578c27c18e8Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
579c43cc173Smrg  touch "$tmpdepfile"
580c43cc173Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
581c43cc173Smrg  rm -f "$depfile"
582f1ee322dSmrg  # makedepend may prepend the VPATH from the source file name to the object.
583f1ee322dSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
584f1ee322dSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
585f1ee322dSmrg  sed '1,2d' "$tmpdepfile" | tr ' ' "$nl" | \
586c43cc173Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
587c43cc173Smrg## correctly.  Breaking it into two sed invocations is a workaround.
588c43cc173Smrg    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
589c43cc173Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
590c43cc173Smrg  ;;
591c43cc173Smrg
592c43cc173Smrgcpp)
593c43cc173Smrg  # Important note: in order to support this mode, a compiler *must*
594c43cc173Smrg  # always write the preprocessed file to stdout.
595c43cc173Smrg  "$@" || exit $?
596c43cc173Smrg
597c43cc173Smrg  # Remove the call to Libtool.
598c43cc173Smrg  if test "$libtool" = yes; then
599c27c18e8Smrg    while test "X$1" != 'X--mode=compile'; do
600c43cc173Smrg      shift
601c43cc173Smrg    done
602c43cc173Smrg    shift
603c43cc173Smrg  fi
604c43cc173Smrg
605f1ee322dSmrg  # Remove '-o $object'.
606c43cc173Smrg  IFS=" "
607c43cc173Smrg  for arg
608c43cc173Smrg  do
609c43cc173Smrg    case $arg in
610c43cc173Smrg    -o)
611c43cc173Smrg      shift
612c43cc173Smrg      ;;
613c43cc173Smrg    $object)
614c43cc173Smrg      shift
615c43cc173Smrg      ;;
616c43cc173Smrg    *)
617c43cc173Smrg      set fnord "$@" "$arg"
618c43cc173Smrg      shift # fnord
619c43cc173Smrg      shift # $arg
620c43cc173Smrg      ;;
621c43cc173Smrg    esac
622c43cc173Smrg  done
623c43cc173Smrg
624c43cc173Smrg  "$@" -E |
625c43cc173Smrg    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
626c43cc173Smrg       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
627c43cc173Smrg    sed '$ s: \\$::' > "$tmpdepfile"
628c43cc173Smrg  rm -f "$depfile"
629c43cc173Smrg  echo "$object : \\" > "$depfile"
630c43cc173Smrg  cat < "$tmpdepfile" >> "$depfile"
631c43cc173Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
632c43cc173Smrg  rm -f "$tmpdepfile"
633c43cc173Smrg  ;;
634c43cc173Smrg
635c43cc173Smrgmsvisualcpp)
636c43cc173Smrg  # Important note: in order to support this mode, a compiler *must*
637c27c18e8Smrg  # always write the preprocessed file to stdout.
638c43cc173Smrg  "$@" || exit $?
639c27c18e8Smrg
640c27c18e8Smrg  # Remove the call to Libtool.
641c27c18e8Smrg  if test "$libtool" = yes; then
642c27c18e8Smrg    while test "X$1" != 'X--mode=compile'; do
643c27c18e8Smrg      shift
644c27c18e8Smrg    done
645c27c18e8Smrg    shift
646c27c18e8Smrg  fi
647c27c18e8Smrg
648c43cc173Smrg  IFS=" "
649c43cc173Smrg  for arg
650c43cc173Smrg  do
651c43cc173Smrg    case "$arg" in
652c27c18e8Smrg    -o)
653c27c18e8Smrg      shift
654c27c18e8Smrg      ;;
655c27c18e8Smrg    $object)
656c27c18e8Smrg      shift
657c27c18e8Smrg      ;;
658c43cc173Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
659c43cc173Smrg	set fnord "$@"
660c43cc173Smrg	shift
661c43cc173Smrg	shift
662c43cc173Smrg	;;
663c43cc173Smrg    *)
664c43cc173Smrg	set fnord "$@" "$arg"
665c43cc173Smrg	shift
666c43cc173Smrg	shift
667c43cc173Smrg	;;
668c43cc173Smrg    esac
669c43cc173Smrg  done
670c27c18e8Smrg  "$@" -E 2>/dev/null |
671c27c18e8Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
672c43cc173Smrg  rm -f "$depfile"
673c43cc173Smrg  echo "$object : \\" > "$depfile"
674f1ee322dSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
675f1ee322dSmrg  echo "$tab" >> "$depfile"
676c27c18e8Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
677c43cc173Smrg  rm -f "$tmpdepfile"
678c43cc173Smrg  ;;
679c43cc173Smrg
680c27c18e8Smrgmsvcmsys)
681c27c18e8Smrg  # This case exists only to let depend.m4 do its work.  It works by
682c27c18e8Smrg  # looking at the text of this script.  This case will never be run,
683c27c18e8Smrg  # since it is checked for above.
684c27c18e8Smrg  exit 1
685c27c18e8Smrg  ;;
686c27c18e8Smrg
687c43cc173Smrgnone)
688c43cc173Smrg  exec "$@"
689c43cc173Smrg  ;;
690c43cc173Smrg
691c43cc173Smrg*)
692c43cc173Smrg  echo "Unknown depmode $depmode" 1>&2
693c43cc173Smrg  exit 1
694c43cc173Smrg  ;;
695c43cc173Smrgesac
696c43cc173Smrg
697c43cc173Smrgexit 0
698c43cc173Smrg
699c43cc173Smrg# Local Variables:
700c43cc173Smrg# mode: shell-script
701c43cc173Smrg# sh-indentation: 2
702c43cc173Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
703c43cc173Smrg# time-stamp-start: "scriptversion="
704c43cc173Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
705c27c18e8Smrg# time-stamp-time-zone: "UTC"
706c27c18e8Smrg# time-stamp-end: "; # UTC"
707c43cc173Smrg# End:
708