xref: /aosp_15_r20/external/strace/depcomp (revision cf84ac9a129d8ea9952db616b4e9b904c4bdde56)
1*cf84ac9aSAndroid Build Coastguard Worker#! /bin/sh
2*cf84ac9aSAndroid Build Coastguard Worker# depcomp - compile a program generating dependencies as side-effects
3*cf84ac9aSAndroid Build Coastguard Worker
4*cf84ac9aSAndroid Build Coastguard Workerscriptversion=2013-05-30.07; # UTC
5*cf84ac9aSAndroid Build Coastguard Worker
6*cf84ac9aSAndroid Build Coastguard Worker# Copyright (C) 1999-2013 Free Software Foundation, Inc.
7*cf84ac9aSAndroid Build Coastguard Worker
8*cf84ac9aSAndroid Build Coastguard Worker# This program is free software; you can redistribute it and/or modify
9*cf84ac9aSAndroid Build Coastguard Worker# it under the terms of the GNU General Public License as published by
10*cf84ac9aSAndroid Build Coastguard Worker# the Free Software Foundation; either version 2, or (at your option)
11*cf84ac9aSAndroid Build Coastguard Worker# any later version.
12*cf84ac9aSAndroid Build Coastguard Worker
13*cf84ac9aSAndroid Build Coastguard Worker# This program is distributed in the hope that it will be useful,
14*cf84ac9aSAndroid Build Coastguard Worker# but WITHOUT ANY WARRANTY; without even the implied warranty of
15*cf84ac9aSAndroid Build Coastguard Worker# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*cf84ac9aSAndroid Build Coastguard Worker# GNU General Public License for more details.
17*cf84ac9aSAndroid Build Coastguard Worker
18*cf84ac9aSAndroid Build Coastguard Worker# You should have received a copy of the GNU General Public License
19*cf84ac9aSAndroid Build Coastguard Worker# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20*cf84ac9aSAndroid Build Coastguard Worker
21*cf84ac9aSAndroid Build Coastguard Worker# As a special exception to the GNU General Public License, if you
22*cf84ac9aSAndroid Build Coastguard Worker# distribute this file as part of a program that contains a
23*cf84ac9aSAndroid Build Coastguard Worker# configuration script generated by Autoconf, you may include it under
24*cf84ac9aSAndroid Build Coastguard Worker# the same distribution terms that you use for the rest of that program.
25*cf84ac9aSAndroid Build Coastguard Worker
26*cf84ac9aSAndroid Build Coastguard Worker# Originally written by Alexandre Oliva <[email protected]>.
27*cf84ac9aSAndroid Build Coastguard Worker
28*cf84ac9aSAndroid Build Coastguard Workercase $1 in
29*cf84ac9aSAndroid Build Coastguard Worker  '')
30*cf84ac9aSAndroid Build Coastguard Worker    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31*cf84ac9aSAndroid Build Coastguard Worker    exit 1;
32*cf84ac9aSAndroid Build Coastguard Worker    ;;
33*cf84ac9aSAndroid Build Coastguard Worker  -h | --h*)
34*cf84ac9aSAndroid Build Coastguard Worker    cat <<\EOF
35*cf84ac9aSAndroid Build Coastguard WorkerUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36*cf84ac9aSAndroid Build Coastguard Worker
37*cf84ac9aSAndroid Build Coastguard WorkerRun PROGRAMS ARGS to compile a file, generating dependencies
38*cf84ac9aSAndroid Build Coastguard Workeras side-effects.
39*cf84ac9aSAndroid Build Coastguard Worker
40*cf84ac9aSAndroid Build Coastguard WorkerEnvironment variables:
41*cf84ac9aSAndroid Build Coastguard Worker  depmode     Dependency tracking mode.
42*cf84ac9aSAndroid Build Coastguard Worker  source      Source file read by 'PROGRAMS ARGS'.
43*cf84ac9aSAndroid Build Coastguard Worker  object      Object file output by 'PROGRAMS ARGS'.
44*cf84ac9aSAndroid Build Coastguard Worker  DEPDIR      directory where to store dependencies.
45*cf84ac9aSAndroid Build Coastguard Worker  depfile     Dependency file to output.
46*cf84ac9aSAndroid Build Coastguard Worker  tmpdepfile  Temporary file to use when outputting dependencies.
47*cf84ac9aSAndroid Build Coastguard Worker  libtool     Whether libtool is used (yes/no).
48*cf84ac9aSAndroid Build Coastguard Worker
49*cf84ac9aSAndroid Build Coastguard WorkerReport bugs to <bug-automake@gnu.org>.
50*cf84ac9aSAndroid Build Coastguard WorkerEOF
51*cf84ac9aSAndroid Build Coastguard Worker    exit $?
52*cf84ac9aSAndroid Build Coastguard Worker    ;;
53*cf84ac9aSAndroid Build Coastguard Worker  -v | --v*)
54*cf84ac9aSAndroid Build Coastguard Worker    echo "depcomp $scriptversion"
55*cf84ac9aSAndroid Build Coastguard Worker    exit $?
56*cf84ac9aSAndroid Build Coastguard Worker    ;;
57*cf84ac9aSAndroid Build Coastguard Workeresac
58*cf84ac9aSAndroid Build Coastguard Worker
59*cf84ac9aSAndroid Build Coastguard Worker# Get the directory component of the given path, and save it in the
60*cf84ac9aSAndroid Build Coastguard Worker# global variables '$dir'.  Note that this directory component will
61*cf84ac9aSAndroid Build Coastguard Worker# be either empty or ending with a '/' character.  This is deliberate.
62*cf84ac9aSAndroid Build Coastguard Workerset_dir_from ()
63*cf84ac9aSAndroid Build Coastguard Worker{
64*cf84ac9aSAndroid Build Coastguard Worker  case $1 in
65*cf84ac9aSAndroid Build Coastguard Worker    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66*cf84ac9aSAndroid Build Coastguard Worker      *) dir=;;
67*cf84ac9aSAndroid Build Coastguard Worker  esac
68*cf84ac9aSAndroid Build Coastguard Worker}
69*cf84ac9aSAndroid Build Coastguard Worker
70*cf84ac9aSAndroid Build Coastguard Worker# Get the suffix-stripped basename of the given path, and save it the
71*cf84ac9aSAndroid Build Coastguard Worker# global variable '$base'.
72*cf84ac9aSAndroid Build Coastguard Workerset_base_from ()
73*cf84ac9aSAndroid Build Coastguard Worker{
74*cf84ac9aSAndroid Build Coastguard Worker  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75*cf84ac9aSAndroid Build Coastguard Worker}
76*cf84ac9aSAndroid Build Coastguard Worker
77*cf84ac9aSAndroid Build Coastguard Worker# If no dependency file was actually created by the compiler invocation,
78*cf84ac9aSAndroid Build Coastguard Worker# we still have to create a dummy depfile, to avoid errors with the
79*cf84ac9aSAndroid Build Coastguard Worker# Makefile "include basename.Plo" scheme.
80*cf84ac9aSAndroid Build Coastguard Workermake_dummy_depfile ()
81*cf84ac9aSAndroid Build Coastguard Worker{
82*cf84ac9aSAndroid Build Coastguard Worker  echo "#dummy" > "$depfile"
83*cf84ac9aSAndroid Build Coastguard Worker}
84*cf84ac9aSAndroid Build Coastguard Worker
85*cf84ac9aSAndroid Build Coastguard Worker# Factor out some common post-processing of the generated depfile.
86*cf84ac9aSAndroid Build Coastguard Worker# Requires the auxiliary global variable '$tmpdepfile' to be set.
87*cf84ac9aSAndroid Build Coastguard Workeraix_post_process_depfile ()
88*cf84ac9aSAndroid Build Coastguard Worker{
89*cf84ac9aSAndroid Build Coastguard Worker  # If the compiler actually managed to produce a dependency file,
90*cf84ac9aSAndroid Build Coastguard Worker  # post-process it.
91*cf84ac9aSAndroid Build Coastguard Worker  if test -f "$tmpdepfile"; then
92*cf84ac9aSAndroid Build Coastguard Worker    # Each line is of the form 'foo.o: dependency.h'.
93*cf84ac9aSAndroid Build Coastguard Worker    # Do two passes, one to just change these to
94*cf84ac9aSAndroid Build Coastguard Worker    #   $object: dependency.h
95*cf84ac9aSAndroid Build Coastguard Worker    # and one to simply output
96*cf84ac9aSAndroid Build Coastguard Worker    #   dependency.h:
97*cf84ac9aSAndroid Build Coastguard Worker    # which is needed to avoid the deleted-header problem.
98*cf84ac9aSAndroid Build Coastguard Worker    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99*cf84ac9aSAndroid Build Coastguard Worker      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100*cf84ac9aSAndroid Build Coastguard Worker    } > "$depfile"
101*cf84ac9aSAndroid Build Coastguard Worker    rm -f "$tmpdepfile"
102*cf84ac9aSAndroid Build Coastguard Worker  else
103*cf84ac9aSAndroid Build Coastguard Worker    make_dummy_depfile
104*cf84ac9aSAndroid Build Coastguard Worker  fi
105*cf84ac9aSAndroid Build Coastguard Worker}
106*cf84ac9aSAndroid Build Coastguard Worker
107*cf84ac9aSAndroid Build Coastguard Worker# A tabulation character.
108*cf84ac9aSAndroid Build Coastguard Workertab='	'
109*cf84ac9aSAndroid Build Coastguard Worker# A newline character.
110*cf84ac9aSAndroid Build Coastguard Workernl='
111*cf84ac9aSAndroid Build Coastguard Worker'
112*cf84ac9aSAndroid Build Coastguard Worker# Character ranges might be problematic outside the C locale.
113*cf84ac9aSAndroid Build Coastguard Worker# These definitions help.
114*cf84ac9aSAndroid Build Coastguard Workerupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115*cf84ac9aSAndroid Build Coastguard Workerlower=abcdefghijklmnopqrstuvwxyz
116*cf84ac9aSAndroid Build Coastguard Workerdigits=0123456789
117*cf84ac9aSAndroid Build Coastguard Workeralpha=${upper}${lower}
118*cf84ac9aSAndroid Build Coastguard Worker
119*cf84ac9aSAndroid Build Coastguard Workerif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120*cf84ac9aSAndroid Build Coastguard Worker  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121*cf84ac9aSAndroid Build Coastguard Worker  exit 1
122*cf84ac9aSAndroid Build Coastguard Workerfi
123*cf84ac9aSAndroid Build Coastguard Worker
124*cf84ac9aSAndroid Build Coastguard Worker# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125*cf84ac9aSAndroid Build Coastguard Workerdepfile=${depfile-`echo "$object" |
126*cf84ac9aSAndroid Build Coastguard Worker  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127*cf84ac9aSAndroid Build Coastguard Workertmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128*cf84ac9aSAndroid Build Coastguard Worker
129*cf84ac9aSAndroid Build Coastguard Workerrm -f "$tmpdepfile"
130*cf84ac9aSAndroid Build Coastguard Worker
131*cf84ac9aSAndroid Build Coastguard Worker# Avoid interferences from the environment.
132*cf84ac9aSAndroid Build Coastguard Workergccflag= dashmflag=
133*cf84ac9aSAndroid Build Coastguard Worker
134*cf84ac9aSAndroid Build Coastguard Worker# Some modes work just like other modes, but use different flags.  We
135*cf84ac9aSAndroid Build Coastguard Worker# parameterize here, but still list the modes in the big case below,
136*cf84ac9aSAndroid Build Coastguard Worker# to make depend.m4 easier to write.  Note that we *cannot* use a case
137*cf84ac9aSAndroid Build Coastguard Worker# here, because this file can only contain one case statement.
138*cf84ac9aSAndroid Build Coastguard Workerif test "$depmode" = hp; then
139*cf84ac9aSAndroid Build Coastguard Worker  # HP compiler uses -M and no extra arg.
140*cf84ac9aSAndroid Build Coastguard Worker  gccflag=-M
141*cf84ac9aSAndroid Build Coastguard Worker  depmode=gcc
142*cf84ac9aSAndroid Build Coastguard Workerfi
143*cf84ac9aSAndroid Build Coastguard Worker
144*cf84ac9aSAndroid Build Coastguard Workerif test "$depmode" = dashXmstdout; then
145*cf84ac9aSAndroid Build Coastguard Worker  # This is just like dashmstdout with a different argument.
146*cf84ac9aSAndroid Build Coastguard Worker  dashmflag=-xM
147*cf84ac9aSAndroid Build Coastguard Worker  depmode=dashmstdout
148*cf84ac9aSAndroid Build Coastguard Workerfi
149*cf84ac9aSAndroid Build Coastguard Worker
150*cf84ac9aSAndroid Build Coastguard Workercygpath_u="cygpath -u -f -"
151*cf84ac9aSAndroid Build Coastguard Workerif test "$depmode" = msvcmsys; then
152*cf84ac9aSAndroid Build Coastguard Worker  # This is just like msvisualcpp but w/o cygpath translation.
153*cf84ac9aSAndroid Build Coastguard Worker  # Just convert the backslash-escaped backslashes to single forward
154*cf84ac9aSAndroid Build Coastguard Worker  # slashes to satisfy depend.m4
155*cf84ac9aSAndroid Build Coastguard Worker  cygpath_u='sed s,\\\\,/,g'
156*cf84ac9aSAndroid Build Coastguard Worker  depmode=msvisualcpp
157*cf84ac9aSAndroid Build Coastguard Workerfi
158*cf84ac9aSAndroid Build Coastguard Worker
159*cf84ac9aSAndroid Build Coastguard Workerif test "$depmode" = msvc7msys; then
160*cf84ac9aSAndroid Build Coastguard Worker  # This is just like msvc7 but w/o cygpath translation.
161*cf84ac9aSAndroid Build Coastguard Worker  # Just convert the backslash-escaped backslashes to single forward
162*cf84ac9aSAndroid Build Coastguard Worker  # slashes to satisfy depend.m4
163*cf84ac9aSAndroid Build Coastguard Worker  cygpath_u='sed s,\\\\,/,g'
164*cf84ac9aSAndroid Build Coastguard Worker  depmode=msvc7
165*cf84ac9aSAndroid Build Coastguard Workerfi
166*cf84ac9aSAndroid Build Coastguard Worker
167*cf84ac9aSAndroid Build Coastguard Workerif test "$depmode" = xlc; then
168*cf84ac9aSAndroid Build Coastguard Worker  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169*cf84ac9aSAndroid Build Coastguard Worker  gccflag=-qmakedep=gcc,-MF
170*cf84ac9aSAndroid Build Coastguard Worker  depmode=gcc
171*cf84ac9aSAndroid Build Coastguard Workerfi
172*cf84ac9aSAndroid Build Coastguard Worker
173*cf84ac9aSAndroid Build Coastguard Workercase "$depmode" in
174*cf84ac9aSAndroid Build Coastguard Workergcc3)
175*cf84ac9aSAndroid Build Coastguard Worker## gcc 3 implements dependency tracking that does exactly what
176*cf84ac9aSAndroid Build Coastguard Worker## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177*cf84ac9aSAndroid Build Coastguard Worker## it if -MD -MP comes after the -MF stuff.  Hmm.
178*cf84ac9aSAndroid Build Coastguard Worker## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179*cf84ac9aSAndroid Build Coastguard Worker## the command line argument order; so add the flags where they
180*cf84ac9aSAndroid Build Coastguard Worker## appear in depend2.am.  Note that the slowdown incurred here
181*cf84ac9aSAndroid Build Coastguard Worker## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182*cf84ac9aSAndroid Build Coastguard Worker  for arg
183*cf84ac9aSAndroid Build Coastguard Worker  do
184*cf84ac9aSAndroid Build Coastguard Worker    case $arg in
185*cf84ac9aSAndroid Build Coastguard Worker    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186*cf84ac9aSAndroid Build Coastguard Worker    *)  set fnord "$@" "$arg" ;;
187*cf84ac9aSAndroid Build Coastguard Worker    esac
188*cf84ac9aSAndroid Build Coastguard Worker    shift # fnord
189*cf84ac9aSAndroid Build Coastguard Worker    shift # $arg
190*cf84ac9aSAndroid Build Coastguard Worker  done
191*cf84ac9aSAndroid Build Coastguard Worker  "$@"
192*cf84ac9aSAndroid Build Coastguard Worker  stat=$?
193*cf84ac9aSAndroid Build Coastguard Worker  if test $stat -ne 0; then
194*cf84ac9aSAndroid Build Coastguard Worker    rm -f "$tmpdepfile"
195*cf84ac9aSAndroid Build Coastguard Worker    exit $stat
196*cf84ac9aSAndroid Build Coastguard Worker  fi
197*cf84ac9aSAndroid Build Coastguard Worker  mv "$tmpdepfile" "$depfile"
198*cf84ac9aSAndroid Build Coastguard Worker  ;;
199*cf84ac9aSAndroid Build Coastguard Worker
200*cf84ac9aSAndroid Build Coastguard Workergcc)
201*cf84ac9aSAndroid Build Coastguard Worker## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202*cf84ac9aSAndroid Build Coastguard Worker## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203*cf84ac9aSAndroid Build Coastguard Worker## (see the conditional assignment to $gccflag above).
204*cf84ac9aSAndroid Build Coastguard Worker## There are various ways to get dependency output from gcc.  Here's
205*cf84ac9aSAndroid Build Coastguard Worker## why we pick this rather obscure method:
206*cf84ac9aSAndroid Build Coastguard Worker## - Don't want to use -MD because we'd like the dependencies to end
207*cf84ac9aSAndroid Build Coastguard Worker##   up in a subdir.  Having to rename by hand is ugly.
208*cf84ac9aSAndroid Build Coastguard Worker##   (We might end up doing this anyway to support other compilers.)
209*cf84ac9aSAndroid Build Coastguard Worker## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210*cf84ac9aSAndroid Build Coastguard Worker##   -MM, not -M (despite what the docs say).  Also, it might not be
211*cf84ac9aSAndroid Build Coastguard Worker##   supported by the other compilers which use the 'gcc' depmode.
212*cf84ac9aSAndroid Build Coastguard Worker## - Using -M directly means running the compiler twice (even worse
213*cf84ac9aSAndroid Build Coastguard Worker##   than renaming).
214*cf84ac9aSAndroid Build Coastguard Worker  if test -z "$gccflag"; then
215*cf84ac9aSAndroid Build Coastguard Worker    gccflag=-MD,
216*cf84ac9aSAndroid Build Coastguard Worker  fi
217*cf84ac9aSAndroid Build Coastguard Worker  "$@" -Wp,"$gccflag$tmpdepfile"
218*cf84ac9aSAndroid Build Coastguard Worker  stat=$?
219*cf84ac9aSAndroid Build Coastguard Worker  if test $stat -ne 0; then
220*cf84ac9aSAndroid Build Coastguard Worker    rm -f "$tmpdepfile"
221*cf84ac9aSAndroid Build Coastguard Worker    exit $stat
222*cf84ac9aSAndroid Build Coastguard Worker  fi
223*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$depfile"
224*cf84ac9aSAndroid Build Coastguard Worker  echo "$object : \\" > "$depfile"
225*cf84ac9aSAndroid Build Coastguard Worker  # The second -e expression handles DOS-style file names with drive
226*cf84ac9aSAndroid Build Coastguard Worker  # letters.
227*cf84ac9aSAndroid Build Coastguard Worker  sed -e 's/^[^:]*: / /' \
228*cf84ac9aSAndroid Build Coastguard Worker      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229*cf84ac9aSAndroid Build Coastguard Worker## This next piece of magic avoids the "deleted header file" problem.
230*cf84ac9aSAndroid Build Coastguard Worker## The problem is that when a header file which appears in a .P file
231*cf84ac9aSAndroid Build Coastguard Worker## is deleted, the dependency causes make to die (because there is
232*cf84ac9aSAndroid Build Coastguard Worker## typically no way to rebuild the header).  We avoid this by adding
233*cf84ac9aSAndroid Build Coastguard Worker## dummy dependencies for each header file.  Too bad gcc doesn't do
234*cf84ac9aSAndroid Build Coastguard Worker## this for us directly.
235*cf84ac9aSAndroid Build Coastguard Worker## Some versions of gcc put a space before the ':'.  On the theory
236*cf84ac9aSAndroid Build Coastguard Worker## that the space means something, we add a space to the output as
237*cf84ac9aSAndroid Build Coastguard Worker## well.  hp depmode also adds that space, but also prefixes the VPATH
238*cf84ac9aSAndroid Build Coastguard Worker## to the object.  Take care to not repeat it in the output.
239*cf84ac9aSAndroid Build Coastguard Worker## Some versions of the HPUX 10.20 sed can't process this invocation
240*cf84ac9aSAndroid Build Coastguard Worker## correctly.  Breaking it into two sed invocations is a workaround.
241*cf84ac9aSAndroid Build Coastguard Worker  tr ' ' "$nl" < "$tmpdepfile" \
242*cf84ac9aSAndroid Build Coastguard Worker    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243*cf84ac9aSAndroid Build Coastguard Worker    | sed -e 's/$/ :/' >> "$depfile"
244*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$tmpdepfile"
245*cf84ac9aSAndroid Build Coastguard Worker  ;;
246*cf84ac9aSAndroid Build Coastguard Worker
247*cf84ac9aSAndroid Build Coastguard Workerhp)
248*cf84ac9aSAndroid Build Coastguard Worker  # This case exists only to let depend.m4 do its work.  It works by
249*cf84ac9aSAndroid Build Coastguard Worker  # looking at the text of this script.  This case will never be run,
250*cf84ac9aSAndroid Build Coastguard Worker  # since it is checked for above.
251*cf84ac9aSAndroid Build Coastguard Worker  exit 1
252*cf84ac9aSAndroid Build Coastguard Worker  ;;
253*cf84ac9aSAndroid Build Coastguard Worker
254*cf84ac9aSAndroid Build Coastguard Workersgi)
255*cf84ac9aSAndroid Build Coastguard Worker  if test "$libtool" = yes; then
256*cf84ac9aSAndroid Build Coastguard Worker    "$@" "-Wp,-MDupdate,$tmpdepfile"
257*cf84ac9aSAndroid Build Coastguard Worker  else
258*cf84ac9aSAndroid Build Coastguard Worker    "$@" -MDupdate "$tmpdepfile"
259*cf84ac9aSAndroid Build Coastguard Worker  fi
260*cf84ac9aSAndroid Build Coastguard Worker  stat=$?
261*cf84ac9aSAndroid Build Coastguard Worker  if test $stat -ne 0; then
262*cf84ac9aSAndroid Build Coastguard Worker    rm -f "$tmpdepfile"
263*cf84ac9aSAndroid Build Coastguard Worker    exit $stat
264*cf84ac9aSAndroid Build Coastguard Worker  fi
265*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$depfile"
266*cf84ac9aSAndroid Build Coastguard Worker
267*cf84ac9aSAndroid Build Coastguard Worker  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268*cf84ac9aSAndroid Build Coastguard Worker    echo "$object : \\" > "$depfile"
269*cf84ac9aSAndroid Build Coastguard Worker    # Clip off the initial element (the dependent).  Don't try to be
270*cf84ac9aSAndroid Build Coastguard Worker    # clever and replace this with sed code, as IRIX sed won't handle
271*cf84ac9aSAndroid Build Coastguard Worker    # lines with more than a fixed number of characters (4096 in
272*cf84ac9aSAndroid Build Coastguard Worker    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273*cf84ac9aSAndroid Build Coastguard Worker    # the IRIX cc adds comments like '#:fec' to the end of the
274*cf84ac9aSAndroid Build Coastguard Worker    # dependency line.
275*cf84ac9aSAndroid Build Coastguard Worker    tr ' ' "$nl" < "$tmpdepfile" \
276*cf84ac9aSAndroid Build Coastguard Worker      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277*cf84ac9aSAndroid Build Coastguard Worker      | tr "$nl" ' ' >> "$depfile"
278*cf84ac9aSAndroid Build Coastguard Worker    echo >> "$depfile"
279*cf84ac9aSAndroid Build Coastguard Worker    # The second pass generates a dummy entry for each header file.
280*cf84ac9aSAndroid Build Coastguard Worker    tr ' ' "$nl" < "$tmpdepfile" \
281*cf84ac9aSAndroid Build Coastguard Worker      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282*cf84ac9aSAndroid Build Coastguard Worker      >> "$depfile"
283*cf84ac9aSAndroid Build Coastguard Worker  else
284*cf84ac9aSAndroid Build Coastguard Worker    make_dummy_depfile
285*cf84ac9aSAndroid Build Coastguard Worker  fi
286*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$tmpdepfile"
287*cf84ac9aSAndroid Build Coastguard Worker  ;;
288*cf84ac9aSAndroid Build Coastguard Worker
289*cf84ac9aSAndroid Build Coastguard Workerxlc)
290*cf84ac9aSAndroid Build Coastguard Worker  # This case exists only to let depend.m4 do its work.  It works by
291*cf84ac9aSAndroid Build Coastguard Worker  # looking at the text of this script.  This case will never be run,
292*cf84ac9aSAndroid Build Coastguard Worker  # since it is checked for above.
293*cf84ac9aSAndroid Build Coastguard Worker  exit 1
294*cf84ac9aSAndroid Build Coastguard Worker  ;;
295*cf84ac9aSAndroid Build Coastguard Worker
296*cf84ac9aSAndroid Build Coastguard Workeraix)
297*cf84ac9aSAndroid Build Coastguard Worker  # The C for AIX Compiler uses -M and outputs the dependencies
298*cf84ac9aSAndroid Build Coastguard Worker  # in a .u file.  In older versions, this file always lives in the
299*cf84ac9aSAndroid Build Coastguard Worker  # current directory.  Also, the AIX compiler puts '$object:' at the
300*cf84ac9aSAndroid Build Coastguard Worker  # start of each line; $object doesn't have directory information.
301*cf84ac9aSAndroid Build Coastguard Worker  # Version 6 uses the directory in both cases.
302*cf84ac9aSAndroid Build Coastguard Worker  set_dir_from "$object"
303*cf84ac9aSAndroid Build Coastguard Worker  set_base_from "$object"
304*cf84ac9aSAndroid Build Coastguard Worker  if test "$libtool" = yes; then
305*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile1=$dir$base.u
306*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile2=$base.u
307*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile3=$dir.libs/$base.u
308*cf84ac9aSAndroid Build Coastguard Worker    "$@" -Wc,-M
309*cf84ac9aSAndroid Build Coastguard Worker  else
310*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile1=$dir$base.u
311*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile2=$dir$base.u
312*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile3=$dir$base.u
313*cf84ac9aSAndroid Build Coastguard Worker    "$@" -M
314*cf84ac9aSAndroid Build Coastguard Worker  fi
315*cf84ac9aSAndroid Build Coastguard Worker  stat=$?
316*cf84ac9aSAndroid Build Coastguard Worker  if test $stat -ne 0; then
317*cf84ac9aSAndroid Build Coastguard Worker    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318*cf84ac9aSAndroid Build Coastguard Worker    exit $stat
319*cf84ac9aSAndroid Build Coastguard Worker  fi
320*cf84ac9aSAndroid Build Coastguard Worker
321*cf84ac9aSAndroid Build Coastguard Worker  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322*cf84ac9aSAndroid Build Coastguard Worker  do
323*cf84ac9aSAndroid Build Coastguard Worker    test -f "$tmpdepfile" && break
324*cf84ac9aSAndroid Build Coastguard Worker  done
325*cf84ac9aSAndroid Build Coastguard Worker  aix_post_process_depfile
326*cf84ac9aSAndroid Build Coastguard Worker  ;;
327*cf84ac9aSAndroid Build Coastguard Worker
328*cf84ac9aSAndroid Build Coastguard Workertcc)
329*cf84ac9aSAndroid Build Coastguard Worker  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330*cf84ac9aSAndroid Build Coastguard Worker  # FIXME: That version still under development at the moment of writing.
331*cf84ac9aSAndroid Build Coastguard Worker  #        Make that this statement remains true also for stable, released
332*cf84ac9aSAndroid Build Coastguard Worker  #        versions.
333*cf84ac9aSAndroid Build Coastguard Worker  # It will wrap lines (doesn't matter whether long or short) with a
334*cf84ac9aSAndroid Build Coastguard Worker  # trailing '\', as in:
335*cf84ac9aSAndroid Build Coastguard Worker  #
336*cf84ac9aSAndroid Build Coastguard Worker  #   foo.o : \
337*cf84ac9aSAndroid Build Coastguard Worker  #    foo.c \
338*cf84ac9aSAndroid Build Coastguard Worker  #    foo.h \
339*cf84ac9aSAndroid Build Coastguard Worker  #
340*cf84ac9aSAndroid Build Coastguard Worker  # It will put a trailing '\' even on the last line, and will use leading
341*cf84ac9aSAndroid Build Coastguard Worker  # spaces rather than leading tabs (at least since its commit 0394caf7
342*cf84ac9aSAndroid Build Coastguard Worker  # "Emit spaces for -MD").
343*cf84ac9aSAndroid Build Coastguard Worker  "$@" -MD -MF "$tmpdepfile"
344*cf84ac9aSAndroid Build Coastguard Worker  stat=$?
345*cf84ac9aSAndroid Build Coastguard Worker  if test $stat -ne 0; then
346*cf84ac9aSAndroid Build Coastguard Worker    rm -f "$tmpdepfile"
347*cf84ac9aSAndroid Build Coastguard Worker    exit $stat
348*cf84ac9aSAndroid Build Coastguard Worker  fi
349*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$depfile"
350*cf84ac9aSAndroid Build Coastguard Worker  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351*cf84ac9aSAndroid Build Coastguard Worker  # We have to change lines of the first kind to '$object: \'.
352*cf84ac9aSAndroid Build Coastguard Worker  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353*cf84ac9aSAndroid Build Coastguard Worker  # And for each line of the second kind, we have to emit a 'dep.h:'
354*cf84ac9aSAndroid Build Coastguard Worker  # dummy dependency, to avoid the deleted-header problem.
355*cf84ac9aSAndroid Build Coastguard Worker  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$tmpdepfile"
357*cf84ac9aSAndroid Build Coastguard Worker  ;;
358*cf84ac9aSAndroid Build Coastguard Worker
359*cf84ac9aSAndroid Build Coastguard Worker## The order of this option in the case statement is important, since the
360*cf84ac9aSAndroid Build Coastguard Worker## shell code in configure will try each of these formats in the order
361*cf84ac9aSAndroid Build Coastguard Worker## listed in this file.  A plain '-MD' option would be understood by many
362*cf84ac9aSAndroid Build Coastguard Worker## compilers, so we must ensure this comes after the gcc and icc options.
363*cf84ac9aSAndroid Build Coastguard Workerpgcc)
364*cf84ac9aSAndroid Build Coastguard Worker  # Portland's C compiler understands '-MD'.
365*cf84ac9aSAndroid Build Coastguard Worker  # Will always output deps to 'file.d' where file is the root name of the
366*cf84ac9aSAndroid Build Coastguard Worker  # source file under compilation, even if file resides in a subdirectory.
367*cf84ac9aSAndroid Build Coastguard Worker  # The object file name does not affect the name of the '.d' file.
368*cf84ac9aSAndroid Build Coastguard Worker  # pgcc 10.2 will output
369*cf84ac9aSAndroid Build Coastguard Worker  #    foo.o: sub/foo.c sub/foo.h
370*cf84ac9aSAndroid Build Coastguard Worker  # and will wrap long lines using '\' :
371*cf84ac9aSAndroid Build Coastguard Worker  #    foo.o: sub/foo.c ... \
372*cf84ac9aSAndroid Build Coastguard Worker  #     sub/foo.h ... \
373*cf84ac9aSAndroid Build Coastguard Worker  #     ...
374*cf84ac9aSAndroid Build Coastguard Worker  set_dir_from "$object"
375*cf84ac9aSAndroid Build Coastguard Worker  # Use the source, not the object, to determine the base name, since
376*cf84ac9aSAndroid Build Coastguard Worker  # that's sadly what pgcc will do too.
377*cf84ac9aSAndroid Build Coastguard Worker  set_base_from "$source"
378*cf84ac9aSAndroid Build Coastguard Worker  tmpdepfile=$base.d
379*cf84ac9aSAndroid Build Coastguard Worker
380*cf84ac9aSAndroid Build Coastguard Worker  # For projects that build the same source file twice into different object
381*cf84ac9aSAndroid Build Coastguard Worker  # files, the pgcc approach of using the *source* file root name can cause
382*cf84ac9aSAndroid Build Coastguard Worker  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383*cf84ac9aSAndroid Build Coastguard Worker  # the same $tmpdepfile.
384*cf84ac9aSAndroid Build Coastguard Worker  lockdir=$base.d-lock
385*cf84ac9aSAndroid Build Coastguard Worker  trap "
386*cf84ac9aSAndroid Build Coastguard Worker    echo '$0: caught signal, cleaning up...' >&2
387*cf84ac9aSAndroid Build Coastguard Worker    rmdir '$lockdir'
388*cf84ac9aSAndroid Build Coastguard Worker    exit 1
389*cf84ac9aSAndroid Build Coastguard Worker  " 1 2 13 15
390*cf84ac9aSAndroid Build Coastguard Worker  numtries=100
391*cf84ac9aSAndroid Build Coastguard Worker  i=$numtries
392*cf84ac9aSAndroid Build Coastguard Worker  while test $i -gt 0; do
393*cf84ac9aSAndroid Build Coastguard Worker    # mkdir is a portable test-and-set.
394*cf84ac9aSAndroid Build Coastguard Worker    if mkdir "$lockdir" 2>/dev/null; then
395*cf84ac9aSAndroid Build Coastguard Worker      # This process acquired the lock.
396*cf84ac9aSAndroid Build Coastguard Worker      "$@" -MD
397*cf84ac9aSAndroid Build Coastguard Worker      stat=$?
398*cf84ac9aSAndroid Build Coastguard Worker      # Release the lock.
399*cf84ac9aSAndroid Build Coastguard Worker      rmdir "$lockdir"
400*cf84ac9aSAndroid Build Coastguard Worker      break
401*cf84ac9aSAndroid Build Coastguard Worker    else
402*cf84ac9aSAndroid Build Coastguard Worker      # If the lock is being held by a different process, wait
403*cf84ac9aSAndroid Build Coastguard Worker      # until the winning process is done or we timeout.
404*cf84ac9aSAndroid Build Coastguard Worker      while test -d "$lockdir" && test $i -gt 0; do
405*cf84ac9aSAndroid Build Coastguard Worker        sleep 1
406*cf84ac9aSAndroid Build Coastguard Worker        i=`expr $i - 1`
407*cf84ac9aSAndroid Build Coastguard Worker      done
408*cf84ac9aSAndroid Build Coastguard Worker    fi
409*cf84ac9aSAndroid Build Coastguard Worker    i=`expr $i - 1`
410*cf84ac9aSAndroid Build Coastguard Worker  done
411*cf84ac9aSAndroid Build Coastguard Worker  trap - 1 2 13 15
412*cf84ac9aSAndroid Build Coastguard Worker  if test $i -le 0; then
413*cf84ac9aSAndroid Build Coastguard Worker    echo "$0: failed to acquire lock after $numtries attempts" >&2
414*cf84ac9aSAndroid Build Coastguard Worker    echo "$0: check lockdir '$lockdir'" >&2
415*cf84ac9aSAndroid Build Coastguard Worker    exit 1
416*cf84ac9aSAndroid Build Coastguard Worker  fi
417*cf84ac9aSAndroid Build Coastguard Worker
418*cf84ac9aSAndroid Build Coastguard Worker  if test $stat -ne 0; then
419*cf84ac9aSAndroid Build Coastguard Worker    rm -f "$tmpdepfile"
420*cf84ac9aSAndroid Build Coastguard Worker    exit $stat
421*cf84ac9aSAndroid Build Coastguard Worker  fi
422*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$depfile"
423*cf84ac9aSAndroid Build Coastguard Worker  # Each line is of the form `foo.o: dependent.h',
424*cf84ac9aSAndroid Build Coastguard Worker  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425*cf84ac9aSAndroid Build Coastguard Worker  # Do two passes, one to just change these to
426*cf84ac9aSAndroid Build Coastguard Worker  # `$object: dependent.h' and one to simply `dependent.h:'.
427*cf84ac9aSAndroid Build Coastguard Worker  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428*cf84ac9aSAndroid Build Coastguard Worker  # Some versions of the HPUX 10.20 sed can't process this invocation
429*cf84ac9aSAndroid Build Coastguard Worker  # correctly.  Breaking it into two sed invocations is a workaround.
430*cf84ac9aSAndroid Build Coastguard Worker  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431*cf84ac9aSAndroid Build Coastguard Worker    | sed -e 's/$/ :/' >> "$depfile"
432*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$tmpdepfile"
433*cf84ac9aSAndroid Build Coastguard Worker  ;;
434*cf84ac9aSAndroid Build Coastguard Worker
435*cf84ac9aSAndroid Build Coastguard Workerhp2)
436*cf84ac9aSAndroid Build Coastguard Worker  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437*cf84ac9aSAndroid Build Coastguard Worker  # compilers, which have integrated preprocessors.  The correct option
438*cf84ac9aSAndroid Build Coastguard Worker  # to use with these is +Maked; it writes dependencies to a file named
439*cf84ac9aSAndroid Build Coastguard Worker  # 'foo.d', which lands next to the object file, wherever that
440*cf84ac9aSAndroid Build Coastguard Worker  # happens to be.
441*cf84ac9aSAndroid Build Coastguard Worker  # Much of this is similar to the tru64 case; see comments there.
442*cf84ac9aSAndroid Build Coastguard Worker  set_dir_from  "$object"
443*cf84ac9aSAndroid Build Coastguard Worker  set_base_from "$object"
444*cf84ac9aSAndroid Build Coastguard Worker  if test "$libtool" = yes; then
445*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile1=$dir$base.d
446*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile2=$dir.libs/$base.d
447*cf84ac9aSAndroid Build Coastguard Worker    "$@" -Wc,+Maked
448*cf84ac9aSAndroid Build Coastguard Worker  else
449*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile1=$dir$base.d
450*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile2=$dir$base.d
451*cf84ac9aSAndroid Build Coastguard Worker    "$@" +Maked
452*cf84ac9aSAndroid Build Coastguard Worker  fi
453*cf84ac9aSAndroid Build Coastguard Worker  stat=$?
454*cf84ac9aSAndroid Build Coastguard Worker  if test $stat -ne 0; then
455*cf84ac9aSAndroid Build Coastguard Worker     rm -f "$tmpdepfile1" "$tmpdepfile2"
456*cf84ac9aSAndroid Build Coastguard Worker     exit $stat
457*cf84ac9aSAndroid Build Coastguard Worker  fi
458*cf84ac9aSAndroid Build Coastguard Worker
459*cf84ac9aSAndroid Build Coastguard Worker  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460*cf84ac9aSAndroid Build Coastguard Worker  do
461*cf84ac9aSAndroid Build Coastguard Worker    test -f "$tmpdepfile" && break
462*cf84ac9aSAndroid Build Coastguard Worker  done
463*cf84ac9aSAndroid Build Coastguard Worker  if test -f "$tmpdepfile"; then
464*cf84ac9aSAndroid Build Coastguard Worker    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465*cf84ac9aSAndroid Build Coastguard Worker    # Add 'dependent.h:' lines.
466*cf84ac9aSAndroid Build Coastguard Worker    sed -ne '2,${
467*cf84ac9aSAndroid Build Coastguard Worker               s/^ *//
468*cf84ac9aSAndroid Build Coastguard Worker               s/ \\*$//
469*cf84ac9aSAndroid Build Coastguard Worker               s/$/:/
470*cf84ac9aSAndroid Build Coastguard Worker               p
471*cf84ac9aSAndroid Build Coastguard Worker             }' "$tmpdepfile" >> "$depfile"
472*cf84ac9aSAndroid Build Coastguard Worker  else
473*cf84ac9aSAndroid Build Coastguard Worker    make_dummy_depfile
474*cf84ac9aSAndroid Build Coastguard Worker  fi
475*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$tmpdepfile" "$tmpdepfile2"
476*cf84ac9aSAndroid Build Coastguard Worker  ;;
477*cf84ac9aSAndroid Build Coastguard Worker
478*cf84ac9aSAndroid Build Coastguard Workertru64)
479*cf84ac9aSAndroid Build Coastguard Worker  # The Tru64 compiler uses -MD to generate dependencies as a side
480*cf84ac9aSAndroid Build Coastguard Worker  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481*cf84ac9aSAndroid Build Coastguard Worker  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482*cf84ac9aSAndroid Build Coastguard Worker  # dependencies in 'foo.d' instead, so we check for that too.
483*cf84ac9aSAndroid Build Coastguard Worker  # Subdirectories are respected.
484*cf84ac9aSAndroid Build Coastguard Worker  set_dir_from  "$object"
485*cf84ac9aSAndroid Build Coastguard Worker  set_base_from "$object"
486*cf84ac9aSAndroid Build Coastguard Worker
487*cf84ac9aSAndroid Build Coastguard Worker  if test "$libtool" = yes; then
488*cf84ac9aSAndroid Build Coastguard Worker    # Libtool generates 2 separate objects for the 2 libraries.  These
489*cf84ac9aSAndroid Build Coastguard Worker    # two compilations output dependencies in $dir.libs/$base.o.d and
490*cf84ac9aSAndroid Build Coastguard Worker    # in $dir$base.o.d.  We have to check for both files, because
491*cf84ac9aSAndroid Build Coastguard Worker    # one of the two compilations can be disabled.  We should prefer
492*cf84ac9aSAndroid Build Coastguard Worker    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493*cf84ac9aSAndroid Build Coastguard Worker    # automatically cleaned when .libs/ is deleted, while ignoring
494*cf84ac9aSAndroid Build Coastguard Worker    # the former would cause a distcleancheck panic.
495*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498*cf84ac9aSAndroid Build Coastguard Worker    "$@" -Wc,-MD
499*cf84ac9aSAndroid Build Coastguard Worker  else
500*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile1=$dir$base.d
501*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile2=$dir$base.d
502*cf84ac9aSAndroid Build Coastguard Worker    tmpdepfile3=$dir$base.d
503*cf84ac9aSAndroid Build Coastguard Worker    "$@" -MD
504*cf84ac9aSAndroid Build Coastguard Worker  fi
505*cf84ac9aSAndroid Build Coastguard Worker
506*cf84ac9aSAndroid Build Coastguard Worker  stat=$?
507*cf84ac9aSAndroid Build Coastguard Worker  if test $stat -ne 0; then
508*cf84ac9aSAndroid Build Coastguard Worker    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509*cf84ac9aSAndroid Build Coastguard Worker    exit $stat
510*cf84ac9aSAndroid Build Coastguard Worker  fi
511*cf84ac9aSAndroid Build Coastguard Worker
512*cf84ac9aSAndroid Build Coastguard Worker  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513*cf84ac9aSAndroid Build Coastguard Worker  do
514*cf84ac9aSAndroid Build Coastguard Worker    test -f "$tmpdepfile" && break
515*cf84ac9aSAndroid Build Coastguard Worker  done
516*cf84ac9aSAndroid Build Coastguard Worker  # Same post-processing that is required for AIX mode.
517*cf84ac9aSAndroid Build Coastguard Worker  aix_post_process_depfile
518*cf84ac9aSAndroid Build Coastguard Worker  ;;
519*cf84ac9aSAndroid Build Coastguard Worker
520*cf84ac9aSAndroid Build Coastguard Workermsvc7)
521*cf84ac9aSAndroid Build Coastguard Worker  if test "$libtool" = yes; then
522*cf84ac9aSAndroid Build Coastguard Worker    showIncludes=-Wc,-showIncludes
523*cf84ac9aSAndroid Build Coastguard Worker  else
524*cf84ac9aSAndroid Build Coastguard Worker    showIncludes=-showIncludes
525*cf84ac9aSAndroid Build Coastguard Worker  fi
526*cf84ac9aSAndroid Build Coastguard Worker  "$@" $showIncludes > "$tmpdepfile"
527*cf84ac9aSAndroid Build Coastguard Worker  stat=$?
528*cf84ac9aSAndroid Build Coastguard Worker  grep -v '^Note: including file: ' "$tmpdepfile"
529*cf84ac9aSAndroid Build Coastguard Worker  if test $stat -ne 0; then
530*cf84ac9aSAndroid Build Coastguard Worker    rm -f "$tmpdepfile"
531*cf84ac9aSAndroid Build Coastguard Worker    exit $stat
532*cf84ac9aSAndroid Build Coastguard Worker  fi
533*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$depfile"
534*cf84ac9aSAndroid Build Coastguard Worker  echo "$object : \\" > "$depfile"
535*cf84ac9aSAndroid Build Coastguard Worker  # The first sed program below extracts the file names and escapes
536*cf84ac9aSAndroid Build Coastguard Worker  # backslashes for cygpath.  The second sed program outputs the file
537*cf84ac9aSAndroid Build Coastguard Worker  # name when reading, but also accumulates all include files in the
538*cf84ac9aSAndroid Build Coastguard Worker  # hold buffer in order to output them again at the end.  This only
539*cf84ac9aSAndroid Build Coastguard Worker  # works with sed implementations that can handle large buffers.
540*cf84ac9aSAndroid Build Coastguard Worker  sed < "$tmpdepfile" -n '
541*cf84ac9aSAndroid Build Coastguard Worker/^Note: including file:  *\(.*\)/ {
542*cf84ac9aSAndroid Build Coastguard Worker  s//\1/
543*cf84ac9aSAndroid Build Coastguard Worker  s/\\/\\\\/g
544*cf84ac9aSAndroid Build Coastguard Worker  p
545*cf84ac9aSAndroid Build Coastguard Worker}' | $cygpath_u | sort -u | sed -n '
546*cf84ac9aSAndroid Build Coastguard Workers/ /\\ /g
547*cf84ac9aSAndroid Build Coastguard Workers/\(.*\)/'"$tab"'\1 \\/p
548*cf84ac9aSAndroid Build Coastguard Workers/.\(.*\) \\/\1:/
549*cf84ac9aSAndroid Build Coastguard WorkerH
550*cf84ac9aSAndroid Build Coastguard Worker$ {
551*cf84ac9aSAndroid Build Coastguard Worker  s/.*/'"$tab"'/
552*cf84ac9aSAndroid Build Coastguard Worker  G
553*cf84ac9aSAndroid Build Coastguard Worker  p
554*cf84ac9aSAndroid Build Coastguard Worker}' >> "$depfile"
555*cf84ac9aSAndroid Build Coastguard Worker  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$tmpdepfile"
557*cf84ac9aSAndroid Build Coastguard Worker  ;;
558*cf84ac9aSAndroid Build Coastguard Worker
559*cf84ac9aSAndroid Build Coastguard Workermsvc7msys)
560*cf84ac9aSAndroid Build Coastguard Worker  # This case exists only to let depend.m4 do its work.  It works by
561*cf84ac9aSAndroid Build Coastguard Worker  # looking at the text of this script.  This case will never be run,
562*cf84ac9aSAndroid Build Coastguard Worker  # since it is checked for above.
563*cf84ac9aSAndroid Build Coastguard Worker  exit 1
564*cf84ac9aSAndroid Build Coastguard Worker  ;;
565*cf84ac9aSAndroid Build Coastguard Worker
566*cf84ac9aSAndroid Build Coastguard Worker#nosideeffect)
567*cf84ac9aSAndroid Build Coastguard Worker  # This comment above is used by automake to tell side-effect
568*cf84ac9aSAndroid Build Coastguard Worker  # dependency tracking mechanisms from slower ones.
569*cf84ac9aSAndroid Build Coastguard Worker
570*cf84ac9aSAndroid Build Coastguard Workerdashmstdout)
571*cf84ac9aSAndroid Build Coastguard Worker  # Important note: in order to support this mode, a compiler *must*
572*cf84ac9aSAndroid Build Coastguard Worker  # always write the preprocessed file to stdout, regardless of -o.
573*cf84ac9aSAndroid Build Coastguard Worker  "$@" || exit $?
574*cf84ac9aSAndroid Build Coastguard Worker
575*cf84ac9aSAndroid Build Coastguard Worker  # Remove the call to Libtool.
576*cf84ac9aSAndroid Build Coastguard Worker  if test "$libtool" = yes; then
577*cf84ac9aSAndroid Build Coastguard Worker    while test "X$1" != 'X--mode=compile'; do
578*cf84ac9aSAndroid Build Coastguard Worker      shift
579*cf84ac9aSAndroid Build Coastguard Worker    done
580*cf84ac9aSAndroid Build Coastguard Worker    shift
581*cf84ac9aSAndroid Build Coastguard Worker  fi
582*cf84ac9aSAndroid Build Coastguard Worker
583*cf84ac9aSAndroid Build Coastguard Worker  # Remove '-o $object'.
584*cf84ac9aSAndroid Build Coastguard Worker  IFS=" "
585*cf84ac9aSAndroid Build Coastguard Worker  for arg
586*cf84ac9aSAndroid Build Coastguard Worker  do
587*cf84ac9aSAndroid Build Coastguard Worker    case $arg in
588*cf84ac9aSAndroid Build Coastguard Worker    -o)
589*cf84ac9aSAndroid Build Coastguard Worker      shift
590*cf84ac9aSAndroid Build Coastguard Worker      ;;
591*cf84ac9aSAndroid Build Coastguard Worker    $object)
592*cf84ac9aSAndroid Build Coastguard Worker      shift
593*cf84ac9aSAndroid Build Coastguard Worker      ;;
594*cf84ac9aSAndroid Build Coastguard Worker    *)
595*cf84ac9aSAndroid Build Coastguard Worker      set fnord "$@" "$arg"
596*cf84ac9aSAndroid Build Coastguard Worker      shift # fnord
597*cf84ac9aSAndroid Build Coastguard Worker      shift # $arg
598*cf84ac9aSAndroid Build Coastguard Worker      ;;
599*cf84ac9aSAndroid Build Coastguard Worker    esac
600*cf84ac9aSAndroid Build Coastguard Worker  done
601*cf84ac9aSAndroid Build Coastguard Worker
602*cf84ac9aSAndroid Build Coastguard Worker  test -z "$dashmflag" && dashmflag=-M
603*cf84ac9aSAndroid Build Coastguard Worker  # Require at least two characters before searching for ':'
604*cf84ac9aSAndroid Build Coastguard Worker  # in the target name.  This is to cope with DOS-style filenames:
605*cf84ac9aSAndroid Build Coastguard Worker  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606*cf84ac9aSAndroid Build Coastguard Worker  "$@" $dashmflag |
607*cf84ac9aSAndroid Build Coastguard Worker    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$depfile"
609*cf84ac9aSAndroid Build Coastguard Worker  cat < "$tmpdepfile" > "$depfile"
610*cf84ac9aSAndroid Build Coastguard Worker  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611*cf84ac9aSAndroid Build Coastguard Worker  # correctly.  Breaking it into two sed invocations is a workaround.
612*cf84ac9aSAndroid Build Coastguard Worker  tr ' ' "$nl" < "$tmpdepfile" \
613*cf84ac9aSAndroid Build Coastguard Worker    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614*cf84ac9aSAndroid Build Coastguard Worker    | sed -e 's/$/ :/' >> "$depfile"
615*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$tmpdepfile"
616*cf84ac9aSAndroid Build Coastguard Worker  ;;
617*cf84ac9aSAndroid Build Coastguard Worker
618*cf84ac9aSAndroid Build Coastguard WorkerdashXmstdout)
619*cf84ac9aSAndroid Build Coastguard Worker  # This case only exists to satisfy depend.m4.  It is never actually
620*cf84ac9aSAndroid Build Coastguard Worker  # run, as this mode is specially recognized in the preamble.
621*cf84ac9aSAndroid Build Coastguard Worker  exit 1
622*cf84ac9aSAndroid Build Coastguard Worker  ;;
623*cf84ac9aSAndroid Build Coastguard Worker
624*cf84ac9aSAndroid Build Coastguard Workermakedepend)
625*cf84ac9aSAndroid Build Coastguard Worker  "$@" || exit $?
626*cf84ac9aSAndroid Build Coastguard Worker  # Remove any Libtool call
627*cf84ac9aSAndroid Build Coastguard Worker  if test "$libtool" = yes; then
628*cf84ac9aSAndroid Build Coastguard Worker    while test "X$1" != 'X--mode=compile'; do
629*cf84ac9aSAndroid Build Coastguard Worker      shift
630*cf84ac9aSAndroid Build Coastguard Worker    done
631*cf84ac9aSAndroid Build Coastguard Worker    shift
632*cf84ac9aSAndroid Build Coastguard Worker  fi
633*cf84ac9aSAndroid Build Coastguard Worker  # X makedepend
634*cf84ac9aSAndroid Build Coastguard Worker  shift
635*cf84ac9aSAndroid Build Coastguard Worker  cleared=no eat=no
636*cf84ac9aSAndroid Build Coastguard Worker  for arg
637*cf84ac9aSAndroid Build Coastguard Worker  do
638*cf84ac9aSAndroid Build Coastguard Worker    case $cleared in
639*cf84ac9aSAndroid Build Coastguard Worker    no)
640*cf84ac9aSAndroid Build Coastguard Worker      set ""; shift
641*cf84ac9aSAndroid Build Coastguard Worker      cleared=yes ;;
642*cf84ac9aSAndroid Build Coastguard Worker    esac
643*cf84ac9aSAndroid Build Coastguard Worker    if test $eat = yes; then
644*cf84ac9aSAndroid Build Coastguard Worker      eat=no
645*cf84ac9aSAndroid Build Coastguard Worker      continue
646*cf84ac9aSAndroid Build Coastguard Worker    fi
647*cf84ac9aSAndroid Build Coastguard Worker    case "$arg" in
648*cf84ac9aSAndroid Build Coastguard Worker    -D*|-I*)
649*cf84ac9aSAndroid Build Coastguard Worker      set fnord "$@" "$arg"; shift ;;
650*cf84ac9aSAndroid Build Coastguard Worker    # Strip any option that makedepend may not understand.  Remove
651*cf84ac9aSAndroid Build Coastguard Worker    # the object too, otherwise makedepend will parse it as a source file.
652*cf84ac9aSAndroid Build Coastguard Worker    -arch)
653*cf84ac9aSAndroid Build Coastguard Worker      eat=yes ;;
654*cf84ac9aSAndroid Build Coastguard Worker    -*|$object)
655*cf84ac9aSAndroid Build Coastguard Worker      ;;
656*cf84ac9aSAndroid Build Coastguard Worker    *)
657*cf84ac9aSAndroid Build Coastguard Worker      set fnord "$@" "$arg"; shift ;;
658*cf84ac9aSAndroid Build Coastguard Worker    esac
659*cf84ac9aSAndroid Build Coastguard Worker  done
660*cf84ac9aSAndroid Build Coastguard Worker  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661*cf84ac9aSAndroid Build Coastguard Worker  touch "$tmpdepfile"
662*cf84ac9aSAndroid Build Coastguard Worker  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$depfile"
664*cf84ac9aSAndroid Build Coastguard Worker  # makedepend may prepend the VPATH from the source file name to the object.
665*cf84ac9aSAndroid Build Coastguard Worker  # No need to regex-escape $object, excess matching of '.' is harmless.
666*cf84ac9aSAndroid Build Coastguard Worker  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667*cf84ac9aSAndroid Build Coastguard Worker  # Some versions of the HPUX 10.20 sed can't process the last invocation
668*cf84ac9aSAndroid Build Coastguard Worker  # correctly.  Breaking it into two sed invocations is a workaround.
669*cf84ac9aSAndroid Build Coastguard Worker  sed '1,2d' "$tmpdepfile" \
670*cf84ac9aSAndroid Build Coastguard Worker    | tr ' ' "$nl" \
671*cf84ac9aSAndroid Build Coastguard Worker    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672*cf84ac9aSAndroid Build Coastguard Worker    | sed -e 's/$/ :/' >> "$depfile"
673*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$tmpdepfile" "$tmpdepfile".bak
674*cf84ac9aSAndroid Build Coastguard Worker  ;;
675*cf84ac9aSAndroid Build Coastguard Worker
676*cf84ac9aSAndroid Build Coastguard Workercpp)
677*cf84ac9aSAndroid Build Coastguard Worker  # Important note: in order to support this mode, a compiler *must*
678*cf84ac9aSAndroid Build Coastguard Worker  # always write the preprocessed file to stdout.
679*cf84ac9aSAndroid Build Coastguard Worker  "$@" || exit $?
680*cf84ac9aSAndroid Build Coastguard Worker
681*cf84ac9aSAndroid Build Coastguard Worker  # Remove the call to Libtool.
682*cf84ac9aSAndroid Build Coastguard Worker  if test "$libtool" = yes; then
683*cf84ac9aSAndroid Build Coastguard Worker    while test "X$1" != 'X--mode=compile'; do
684*cf84ac9aSAndroid Build Coastguard Worker      shift
685*cf84ac9aSAndroid Build Coastguard Worker    done
686*cf84ac9aSAndroid Build Coastguard Worker    shift
687*cf84ac9aSAndroid Build Coastguard Worker  fi
688*cf84ac9aSAndroid Build Coastguard Worker
689*cf84ac9aSAndroid Build Coastguard Worker  # Remove '-o $object'.
690*cf84ac9aSAndroid Build Coastguard Worker  IFS=" "
691*cf84ac9aSAndroid Build Coastguard Worker  for arg
692*cf84ac9aSAndroid Build Coastguard Worker  do
693*cf84ac9aSAndroid Build Coastguard Worker    case $arg in
694*cf84ac9aSAndroid Build Coastguard Worker    -o)
695*cf84ac9aSAndroid Build Coastguard Worker      shift
696*cf84ac9aSAndroid Build Coastguard Worker      ;;
697*cf84ac9aSAndroid Build Coastguard Worker    $object)
698*cf84ac9aSAndroid Build Coastguard Worker      shift
699*cf84ac9aSAndroid Build Coastguard Worker      ;;
700*cf84ac9aSAndroid Build Coastguard Worker    *)
701*cf84ac9aSAndroid Build Coastguard Worker      set fnord "$@" "$arg"
702*cf84ac9aSAndroid Build Coastguard Worker      shift # fnord
703*cf84ac9aSAndroid Build Coastguard Worker      shift # $arg
704*cf84ac9aSAndroid Build Coastguard Worker      ;;
705*cf84ac9aSAndroid Build Coastguard Worker    esac
706*cf84ac9aSAndroid Build Coastguard Worker  done
707*cf84ac9aSAndroid Build Coastguard Worker
708*cf84ac9aSAndroid Build Coastguard Worker  "$@" -E \
709*cf84ac9aSAndroid Build Coastguard Worker    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710*cf84ac9aSAndroid Build Coastguard Worker             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711*cf84ac9aSAndroid Build Coastguard Worker    | sed '$ s: \\$::' > "$tmpdepfile"
712*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$depfile"
713*cf84ac9aSAndroid Build Coastguard Worker  echo "$object : \\" > "$depfile"
714*cf84ac9aSAndroid Build Coastguard Worker  cat < "$tmpdepfile" >> "$depfile"
715*cf84ac9aSAndroid Build Coastguard Worker  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$tmpdepfile"
717*cf84ac9aSAndroid Build Coastguard Worker  ;;
718*cf84ac9aSAndroid Build Coastguard Worker
719*cf84ac9aSAndroid Build Coastguard Workermsvisualcpp)
720*cf84ac9aSAndroid Build Coastguard Worker  # Important note: in order to support this mode, a compiler *must*
721*cf84ac9aSAndroid Build Coastguard Worker  # always write the preprocessed file to stdout.
722*cf84ac9aSAndroid Build Coastguard Worker  "$@" || exit $?
723*cf84ac9aSAndroid Build Coastguard Worker
724*cf84ac9aSAndroid Build Coastguard Worker  # Remove the call to Libtool.
725*cf84ac9aSAndroid Build Coastguard Worker  if test "$libtool" = yes; then
726*cf84ac9aSAndroid Build Coastguard Worker    while test "X$1" != 'X--mode=compile'; do
727*cf84ac9aSAndroid Build Coastguard Worker      shift
728*cf84ac9aSAndroid Build Coastguard Worker    done
729*cf84ac9aSAndroid Build Coastguard Worker    shift
730*cf84ac9aSAndroid Build Coastguard Worker  fi
731*cf84ac9aSAndroid Build Coastguard Worker
732*cf84ac9aSAndroid Build Coastguard Worker  IFS=" "
733*cf84ac9aSAndroid Build Coastguard Worker  for arg
734*cf84ac9aSAndroid Build Coastguard Worker  do
735*cf84ac9aSAndroid Build Coastguard Worker    case "$arg" in
736*cf84ac9aSAndroid Build Coastguard Worker    -o)
737*cf84ac9aSAndroid Build Coastguard Worker      shift
738*cf84ac9aSAndroid Build Coastguard Worker      ;;
739*cf84ac9aSAndroid Build Coastguard Worker    $object)
740*cf84ac9aSAndroid Build Coastguard Worker      shift
741*cf84ac9aSAndroid Build Coastguard Worker      ;;
742*cf84ac9aSAndroid Build Coastguard Worker    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743*cf84ac9aSAndroid Build Coastguard Worker        set fnord "$@"
744*cf84ac9aSAndroid Build Coastguard Worker        shift
745*cf84ac9aSAndroid Build Coastguard Worker        shift
746*cf84ac9aSAndroid Build Coastguard Worker        ;;
747*cf84ac9aSAndroid Build Coastguard Worker    *)
748*cf84ac9aSAndroid Build Coastguard Worker        set fnord "$@" "$arg"
749*cf84ac9aSAndroid Build Coastguard Worker        shift
750*cf84ac9aSAndroid Build Coastguard Worker        shift
751*cf84ac9aSAndroid Build Coastguard Worker        ;;
752*cf84ac9aSAndroid Build Coastguard Worker    esac
753*cf84ac9aSAndroid Build Coastguard Worker  done
754*cf84ac9aSAndroid Build Coastguard Worker  "$@" -E 2>/dev/null |
755*cf84ac9aSAndroid Build Coastguard Worker  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$depfile"
757*cf84ac9aSAndroid Build Coastguard Worker  echo "$object : \\" > "$depfile"
758*cf84ac9aSAndroid Build Coastguard Worker  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759*cf84ac9aSAndroid Build Coastguard Worker  echo "$tab" >> "$depfile"
760*cf84ac9aSAndroid Build Coastguard Worker  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761*cf84ac9aSAndroid Build Coastguard Worker  rm -f "$tmpdepfile"
762*cf84ac9aSAndroid Build Coastguard Worker  ;;
763*cf84ac9aSAndroid Build Coastguard Worker
764*cf84ac9aSAndroid Build Coastguard Workermsvcmsys)
765*cf84ac9aSAndroid Build Coastguard Worker  # This case exists only to let depend.m4 do its work.  It works by
766*cf84ac9aSAndroid Build Coastguard Worker  # looking at the text of this script.  This case will never be run,
767*cf84ac9aSAndroid Build Coastguard Worker  # since it is checked for above.
768*cf84ac9aSAndroid Build Coastguard Worker  exit 1
769*cf84ac9aSAndroid Build Coastguard Worker  ;;
770*cf84ac9aSAndroid Build Coastguard Worker
771*cf84ac9aSAndroid Build Coastguard Workernone)
772*cf84ac9aSAndroid Build Coastguard Worker  exec "$@"
773*cf84ac9aSAndroid Build Coastguard Worker  ;;
774*cf84ac9aSAndroid Build Coastguard Worker
775*cf84ac9aSAndroid Build Coastguard Worker*)
776*cf84ac9aSAndroid Build Coastguard Worker  echo "Unknown depmode $depmode" 1>&2
777*cf84ac9aSAndroid Build Coastguard Worker  exit 1
778*cf84ac9aSAndroid Build Coastguard Worker  ;;
779*cf84ac9aSAndroid Build Coastguard Workeresac
780*cf84ac9aSAndroid Build Coastguard Worker
781*cf84ac9aSAndroid Build Coastguard Workerexit 0
782*cf84ac9aSAndroid Build Coastguard Worker
783*cf84ac9aSAndroid Build Coastguard Worker# Local Variables:
784*cf84ac9aSAndroid Build Coastguard Worker# mode: shell-script
785*cf84ac9aSAndroid Build Coastguard Worker# sh-indentation: 2
786*cf84ac9aSAndroid Build Coastguard Worker# eval: (add-hook 'write-file-hooks 'time-stamp)
787*cf84ac9aSAndroid Build Coastguard Worker# time-stamp-start: "scriptversion="
788*cf84ac9aSAndroid Build Coastguard Worker# time-stamp-format: "%:y-%02m-%02d.%02H"
789*cf84ac9aSAndroid Build Coastguard Worker# time-stamp-time-zone: "UTC"
790*cf84ac9aSAndroid Build Coastguard Worker# time-stamp-end: "; # UTC"
791*cf84ac9aSAndroid Build Coastguard Worker# End:
792