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