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