xref: /minix3/external/bsd/file/dist/depcomp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1ef01931fSBen Gras#! /bin/sh
2ef01931fSBen Gras# depcomp - compile a program generating dependencies as side-effects
3ef01931fSBen Gras
4*0a6a1f1dSLionel Sambucscriptversion=2013-05-30.07; # UTC
5ef01931fSBen Gras
6*0a6a1f1dSLionel Sambuc# Copyright (C) 1999-2013 Free Software Foundation, Inc.
7ef01931fSBen Gras
8ef01931fSBen Gras# This program is free software; you can redistribute it and/or modify
9ef01931fSBen Gras# it under the terms of the GNU General Public License as published by
10ef01931fSBen Gras# the Free Software Foundation; either version 2, or (at your option)
11ef01931fSBen Gras# any later version.
12ef01931fSBen Gras
13ef01931fSBen Gras# This program is distributed in the hope that it will be useful,
14ef01931fSBen Gras# but WITHOUT ANY WARRANTY; without even the implied warranty of
15ef01931fSBen Gras# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16ef01931fSBen Gras# GNU General Public License for more details.
17ef01931fSBen Gras
18ef01931fSBen Gras# You should have received a copy of the GNU General Public License
19835f6802SDirk Vogt# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20ef01931fSBen Gras
21ef01931fSBen Gras# As a special exception to the GNU General Public License, if you
22ef01931fSBen Gras# distribute this file as part of a program that contains a
23ef01931fSBen Gras# configuration script generated by Autoconf, you may include it under
24ef01931fSBen Gras# the same distribution terms that you use for the rest of that program.
25ef01931fSBen Gras
26ef01931fSBen Gras# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27ef01931fSBen Gras
28ef01931fSBen Grascase $1 in
29ef01931fSBen Gras  '')
3084d9c625SLionel Sambuc    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31ef01931fSBen Gras    exit 1;
32ef01931fSBen Gras    ;;
33ef01931fSBen Gras  -h | --h*)
34ef01931fSBen Gras    cat <<\EOF
35ef01931fSBen GrasUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36ef01931fSBen Gras
37ef01931fSBen GrasRun PROGRAMS ARGS to compile a file, generating dependencies
38ef01931fSBen Grasas side-effects.
39ef01931fSBen Gras
40ef01931fSBen GrasEnvironment variables:
41ef01931fSBen Gras  depmode     Dependency tracking mode.
4284d9c625SLionel Sambuc  source      Source file read by 'PROGRAMS ARGS'.
4384d9c625SLionel Sambuc  object      Object file output by 'PROGRAMS ARGS'.
44ef01931fSBen Gras  DEPDIR      directory where to store dependencies.
45ef01931fSBen Gras  depfile     Dependency file to output.
4684d9c625SLionel Sambuc  tmpdepfile  Temporary file to use when outputting dependencies.
47ef01931fSBen Gras  libtool     Whether libtool is used (yes/no).
48ef01931fSBen Gras
49ef01931fSBen GrasReport bugs to <bug-automake@gnu.org>.
50ef01931fSBen GrasEOF
51ef01931fSBen Gras    exit $?
52ef01931fSBen Gras    ;;
53ef01931fSBen Gras  -v | --v*)
54ef01931fSBen Gras    echo "depcomp $scriptversion"
55ef01931fSBen Gras    exit $?
56ef01931fSBen Gras    ;;
57ef01931fSBen Grasesac
58ef01931fSBen Gras
59*0a6a1f1dSLionel Sambuc# Get the directory component of the given path, and save it in the
60*0a6a1f1dSLionel Sambuc# global variables '$dir'.  Note that this directory component will
61*0a6a1f1dSLionel Sambuc# be either empty or ending with a '/' character.  This is deliberate.
62*0a6a1f1dSLionel Sambucset_dir_from ()
63*0a6a1f1dSLionel Sambuc{
64*0a6a1f1dSLionel Sambuc  case $1 in
65*0a6a1f1dSLionel Sambuc    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66*0a6a1f1dSLionel Sambuc      *) dir=;;
67*0a6a1f1dSLionel Sambuc  esac
68*0a6a1f1dSLionel Sambuc}
69*0a6a1f1dSLionel Sambuc
70*0a6a1f1dSLionel Sambuc# Get the suffix-stripped basename of the given path, and save it the
71*0a6a1f1dSLionel Sambuc# global variable '$base'.
72*0a6a1f1dSLionel Sambucset_base_from ()
73*0a6a1f1dSLionel Sambuc{
74*0a6a1f1dSLionel Sambuc  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75*0a6a1f1dSLionel Sambuc}
76*0a6a1f1dSLionel Sambuc
77*0a6a1f1dSLionel Sambuc# If no dependency file was actually created by the compiler invocation,
78*0a6a1f1dSLionel Sambuc# we still have to create a dummy depfile, to avoid errors with the
79*0a6a1f1dSLionel Sambuc# Makefile "include basename.Plo" scheme.
80*0a6a1f1dSLionel Sambucmake_dummy_depfile ()
81*0a6a1f1dSLionel Sambuc{
82*0a6a1f1dSLionel Sambuc  echo "#dummy" > "$depfile"
83*0a6a1f1dSLionel Sambuc}
84*0a6a1f1dSLionel Sambuc
85*0a6a1f1dSLionel Sambuc# Factor out some common post-processing of the generated depfile.
86*0a6a1f1dSLionel Sambuc# Requires the auxiliary global variable '$tmpdepfile' to be set.
87*0a6a1f1dSLionel Sambucaix_post_process_depfile ()
88*0a6a1f1dSLionel Sambuc{
89*0a6a1f1dSLionel Sambuc  # If the compiler actually managed to produce a dependency file,
90*0a6a1f1dSLionel Sambuc  # post-process it.
91*0a6a1f1dSLionel Sambuc  if test -f "$tmpdepfile"; then
92*0a6a1f1dSLionel Sambuc    # Each line is of the form 'foo.o: dependency.h'.
93*0a6a1f1dSLionel Sambuc    # Do two passes, one to just change these to
94*0a6a1f1dSLionel Sambuc    #   $object: dependency.h
95*0a6a1f1dSLionel Sambuc    # and one to simply output
96*0a6a1f1dSLionel Sambuc    #   dependency.h:
97*0a6a1f1dSLionel Sambuc    # which is needed to avoid the deleted-header problem.
98*0a6a1f1dSLionel Sambuc    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99*0a6a1f1dSLionel Sambuc      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100*0a6a1f1dSLionel Sambuc    } > "$depfile"
101*0a6a1f1dSLionel Sambuc    rm -f "$tmpdepfile"
102*0a6a1f1dSLionel Sambuc  else
103*0a6a1f1dSLionel Sambuc    make_dummy_depfile
104*0a6a1f1dSLionel Sambuc  fi
105*0a6a1f1dSLionel Sambuc}
106*0a6a1f1dSLionel Sambuc
10784d9c625SLionel Sambuc# A tabulation character.
10884d9c625SLionel Sambuctab='	'
10984d9c625SLionel Sambuc# A newline character.
11084d9c625SLionel Sambucnl='
11184d9c625SLionel Sambuc'
112*0a6a1f1dSLionel Sambuc# Character ranges might be problematic outside the C locale.
113*0a6a1f1dSLionel Sambuc# These definitions help.
114*0a6a1f1dSLionel Sambucupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115*0a6a1f1dSLionel Sambuclower=abcdefghijklmnopqrstuvwxyz
116*0a6a1f1dSLionel Sambucdigits=0123456789
117*0a6a1f1dSLionel Sambucalpha=${upper}${lower}
11884d9c625SLionel Sambuc
119ef01931fSBen Grasif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120ef01931fSBen Gras  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121ef01931fSBen Gras  exit 1
122ef01931fSBen Grasfi
123ef01931fSBen Gras
124ef01931fSBen Gras# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125ef01931fSBen Grasdepfile=${depfile-`echo "$object" |
126ef01931fSBen Gras  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127ef01931fSBen Grastmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128ef01931fSBen Gras
129ef01931fSBen Grasrm -f "$tmpdepfile"
130ef01931fSBen Gras
131*0a6a1f1dSLionel Sambuc# Avoid interferences from the environment.
132*0a6a1f1dSLionel Sambucgccflag= dashmflag=
133*0a6a1f1dSLionel Sambuc
134ef01931fSBen Gras# Some modes work just like other modes, but use different flags.  We
135ef01931fSBen Gras# parameterize here, but still list the modes in the big case below,
136ef01931fSBen Gras# to make depend.m4 easier to write.  Note that we *cannot* use a case
137ef01931fSBen Gras# here, because this file can only contain one case statement.
138ef01931fSBen Grasif test "$depmode" = hp; then
139ef01931fSBen Gras  # HP compiler uses -M and no extra arg.
140ef01931fSBen Gras  gccflag=-M
141ef01931fSBen Gras  depmode=gcc
142ef01931fSBen Grasfi
143ef01931fSBen Gras
144ef01931fSBen Grasif test "$depmode" = dashXmstdout; then
145ef01931fSBen Gras  # This is just like dashmstdout with a different argument.
146ef01931fSBen Gras  dashmflag=-xM
147ef01931fSBen Gras  depmode=dashmstdout
148ef01931fSBen Grasfi
149ef01931fSBen Gras
150835f6802SDirk Vogtcygpath_u="cygpath -u -f -"
151835f6802SDirk Vogtif test "$depmode" = msvcmsys; then
152835f6802SDirk Vogt  # This is just like msvisualcpp but w/o cygpath translation.
153835f6802SDirk Vogt  # Just convert the backslash-escaped backslashes to single forward
154835f6802SDirk Vogt  # slashes to satisfy depend.m4
15584d9c625SLionel Sambuc  cygpath_u='sed s,\\\\,/,g'
156835f6802SDirk Vogt  depmode=msvisualcpp
157835f6802SDirk Vogtfi
158835f6802SDirk Vogt
15984d9c625SLionel Sambucif test "$depmode" = msvc7msys; then
16084d9c625SLionel Sambuc  # This is just like msvc7 but w/o cygpath translation.
16184d9c625SLionel Sambuc  # Just convert the backslash-escaped backslashes to single forward
16284d9c625SLionel Sambuc  # slashes to satisfy depend.m4
16384d9c625SLionel Sambuc  cygpath_u='sed s,\\\\,/,g'
16484d9c625SLionel Sambuc  depmode=msvc7
16584d9c625SLionel Sambucfi
16684d9c625SLionel Sambuc
16784d9c625SLionel Sambucif test "$depmode" = xlc; then
168*0a6a1f1dSLionel Sambuc  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
16984d9c625SLionel Sambuc  gccflag=-qmakedep=gcc,-MF
17084d9c625SLionel Sambuc  depmode=gcc
17184d9c625SLionel Sambucfi
17284d9c625SLionel Sambuc
173ef01931fSBen Grascase "$depmode" in
174ef01931fSBen Grasgcc3)
175ef01931fSBen Gras## gcc 3 implements dependency tracking that does exactly what
176ef01931fSBen Gras## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177ef01931fSBen Gras## it if -MD -MP comes after the -MF stuff.  Hmm.
178ef01931fSBen Gras## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179ef01931fSBen Gras## the command line argument order; so add the flags where they
180ef01931fSBen Gras## appear in depend2.am.  Note that the slowdown incurred here
181ef01931fSBen Gras## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182ef01931fSBen Gras  for arg
183ef01931fSBen Gras  do
184ef01931fSBen Gras    case $arg in
185ef01931fSBen Gras    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186ef01931fSBen Gras    *)  set fnord "$@" "$arg" ;;
187ef01931fSBen Gras    esac
188ef01931fSBen Gras    shift # fnord
189ef01931fSBen Gras    shift # $arg
190ef01931fSBen Gras  done
191ef01931fSBen Gras  "$@"
192ef01931fSBen Gras  stat=$?
193*0a6a1f1dSLionel Sambuc  if test $stat -ne 0; then
194ef01931fSBen Gras    rm -f "$tmpdepfile"
195ef01931fSBen Gras    exit $stat
196ef01931fSBen Gras  fi
197ef01931fSBen Gras  mv "$tmpdepfile" "$depfile"
198ef01931fSBen Gras  ;;
199ef01931fSBen Gras
200ef01931fSBen Grasgcc)
201*0a6a1f1dSLionel Sambuc## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202*0a6a1f1dSLionel Sambuc## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203*0a6a1f1dSLionel Sambuc## (see the conditional assignment to $gccflag above).
204ef01931fSBen Gras## There are various ways to get dependency output from gcc.  Here's
205ef01931fSBen Gras## why we pick this rather obscure method:
206ef01931fSBen Gras## - Don't want to use -MD because we'd like the dependencies to end
207ef01931fSBen Gras##   up in a subdir.  Having to rename by hand is ugly.
208ef01931fSBen Gras##   (We might end up doing this anyway to support other compilers.)
209ef01931fSBen Gras## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210*0a6a1f1dSLionel Sambuc##   -MM, not -M (despite what the docs say).  Also, it might not be
211*0a6a1f1dSLionel Sambuc##   supported by the other compilers which use the 'gcc' depmode.
212ef01931fSBen Gras## - Using -M directly means running the compiler twice (even worse
213ef01931fSBen Gras##   than renaming).
214ef01931fSBen Gras  if test -z "$gccflag"; then
215ef01931fSBen Gras    gccflag=-MD,
216ef01931fSBen Gras  fi
217ef01931fSBen Gras  "$@" -Wp,"$gccflag$tmpdepfile"
218ef01931fSBen Gras  stat=$?
219*0a6a1f1dSLionel Sambuc  if test $stat -ne 0; then
220ef01931fSBen Gras    rm -f "$tmpdepfile"
221ef01931fSBen Gras    exit $stat
222ef01931fSBen Gras  fi
223ef01931fSBen Gras  rm -f "$depfile"
224ef01931fSBen Gras  echo "$object : \\" > "$depfile"
225*0a6a1f1dSLionel Sambuc  # The second -e expression handles DOS-style file names with drive
226*0a6a1f1dSLionel Sambuc  # letters.
227ef01931fSBen Gras  sed -e 's/^[^:]*: / /' \
228ef01931fSBen Gras      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
22984d9c625SLionel Sambuc## This next piece of magic avoids the "deleted header file" problem.
230ef01931fSBen Gras## The problem is that when a header file which appears in a .P file
231ef01931fSBen Gras## is deleted, the dependency causes make to die (because there is
232ef01931fSBen Gras## typically no way to rebuild the header).  We avoid this by adding
233ef01931fSBen Gras## dummy dependencies for each header file.  Too bad gcc doesn't do
234ef01931fSBen Gras## this for us directly.
23584d9c625SLionel Sambuc## Some versions of gcc put a space before the ':'.  On the theory
236ef01931fSBen Gras## that the space means something, we add a space to the output as
23784d9c625SLionel Sambuc## well.  hp depmode also adds that space, but also prefixes the VPATH
23884d9c625SLionel Sambuc## to the object.  Take care to not repeat it in the output.
239ef01931fSBen Gras## Some versions of the HPUX 10.20 sed can't process this invocation
240ef01931fSBen Gras## correctly.  Breaking it into two sed invocations is a workaround.
241*0a6a1f1dSLionel Sambuc  tr ' ' "$nl" < "$tmpdepfile" \
242*0a6a1f1dSLionel Sambuc    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
24384d9c625SLionel Sambuc    | sed -e 's/$/ :/' >> "$depfile"
244ef01931fSBen Gras  rm -f "$tmpdepfile"
245ef01931fSBen Gras  ;;
246ef01931fSBen Gras
247ef01931fSBen Grashp)
248ef01931fSBen Gras  # This case exists only to let depend.m4 do its work.  It works by
249ef01931fSBen Gras  # looking at the text of this script.  This case will never be run,
250ef01931fSBen Gras  # since it is checked for above.
251ef01931fSBen Gras  exit 1
252ef01931fSBen Gras  ;;
253ef01931fSBen Gras
254ef01931fSBen Grassgi)
255ef01931fSBen Gras  if test "$libtool" = yes; then
256ef01931fSBen Gras    "$@" "-Wp,-MDupdate,$tmpdepfile"
257ef01931fSBen Gras  else
258ef01931fSBen Gras    "$@" -MDupdate "$tmpdepfile"
259ef01931fSBen Gras  fi
260ef01931fSBen Gras  stat=$?
261*0a6a1f1dSLionel Sambuc  if test $stat -ne 0; then
262ef01931fSBen Gras    rm -f "$tmpdepfile"
263ef01931fSBen Gras    exit $stat
264ef01931fSBen Gras  fi
265ef01931fSBen Gras  rm -f "$depfile"
266ef01931fSBen Gras
267ef01931fSBen Gras  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268ef01931fSBen Gras    echo "$object : \\" > "$depfile"
269ef01931fSBen Gras    # Clip off the initial element (the dependent).  Don't try to be
270ef01931fSBen Gras    # clever and replace this with sed code, as IRIX sed won't handle
271ef01931fSBen Gras    # lines with more than a fixed number of characters (4096 in
272ef01931fSBen Gras    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
27384d9c625SLionel Sambuc    # the IRIX cc adds comments like '#:fec' to the end of the
274ef01931fSBen Gras    # dependency line.
27584d9c625SLionel Sambuc    tr ' ' "$nl" < "$tmpdepfile" \
276*0a6a1f1dSLionel Sambuc      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277*0a6a1f1dSLionel Sambuc      | tr "$nl" ' ' >> "$depfile"
278835f6802SDirk Vogt    echo >> "$depfile"
279ef01931fSBen Gras    # The second pass generates a dummy entry for each header file.
28084d9c625SLionel Sambuc    tr ' ' "$nl" < "$tmpdepfile" \
281ef01931fSBen Gras      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282835f6802SDirk Vogt      >> "$depfile"
283ef01931fSBen Gras  else
284*0a6a1f1dSLionel Sambuc    make_dummy_depfile
285ef01931fSBen Gras  fi
286ef01931fSBen Gras  rm -f "$tmpdepfile"
287ef01931fSBen Gras  ;;
288ef01931fSBen Gras
28984d9c625SLionel Sambucxlc)
29084d9c625SLionel Sambuc  # This case exists only to let depend.m4 do its work.  It works by
29184d9c625SLionel Sambuc  # looking at the text of this script.  This case will never be run,
29284d9c625SLionel Sambuc  # since it is checked for above.
29384d9c625SLionel Sambuc  exit 1
29484d9c625SLionel Sambuc  ;;
29584d9c625SLionel Sambuc
296ef01931fSBen Grasaix)
297ef01931fSBen Gras  # The C for AIX Compiler uses -M and outputs the dependencies
298ef01931fSBen Gras  # in a .u file.  In older versions, this file always lives in the
29984d9c625SLionel Sambuc  # current directory.  Also, the AIX compiler puts '$object:' at the
300ef01931fSBen Gras  # start of each line; $object doesn't have directory information.
301ef01931fSBen Gras  # Version 6 uses the directory in both cases.
302*0a6a1f1dSLionel Sambuc  set_dir_from "$object"
303*0a6a1f1dSLionel Sambuc  set_base_from "$object"
304ef01931fSBen Gras  if test "$libtool" = yes; then
305835f6802SDirk Vogt    tmpdepfile1=$dir$base.u
306835f6802SDirk Vogt    tmpdepfile2=$base.u
307835f6802SDirk Vogt    tmpdepfile3=$dir.libs/$base.u
308ef01931fSBen Gras    "$@" -Wc,-M
309ef01931fSBen Gras  else
310835f6802SDirk Vogt    tmpdepfile1=$dir$base.u
311835f6802SDirk Vogt    tmpdepfile2=$dir$base.u
312835f6802SDirk Vogt    tmpdepfile3=$dir$base.u
313ef01931fSBen Gras    "$@" -M
314ef01931fSBen Gras  fi
315ef01931fSBen Gras  stat=$?
316*0a6a1f1dSLionel Sambuc  if test $stat -ne 0; then
317835f6802SDirk Vogt    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318ef01931fSBen Gras    exit $stat
319ef01931fSBen Gras  fi
320ef01931fSBen Gras
321835f6802SDirk Vogt  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322835f6802SDirk Vogt  do
323835f6802SDirk Vogt    test -f "$tmpdepfile" && break
324835f6802SDirk Vogt  done
325*0a6a1f1dSLionel Sambuc  aix_post_process_depfile
326ef01931fSBen Gras  ;;
327ef01931fSBen Gras
328*0a6a1f1dSLionel Sambuctcc)
329*0a6a1f1dSLionel Sambuc  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330*0a6a1f1dSLionel Sambuc  # FIXME: That version still under development at the moment of writing.
331*0a6a1f1dSLionel Sambuc  #        Make that this statement remains true also for stable, released
332*0a6a1f1dSLionel Sambuc  #        versions.
333*0a6a1f1dSLionel Sambuc  # It will wrap lines (doesn't matter whether long or short) with a
334*0a6a1f1dSLionel Sambuc  # trailing '\', as in:
335*0a6a1f1dSLionel Sambuc  #
336*0a6a1f1dSLionel Sambuc  #   foo.o : \
337*0a6a1f1dSLionel Sambuc  #    foo.c \
338*0a6a1f1dSLionel Sambuc  #    foo.h \
339*0a6a1f1dSLionel Sambuc  #
340*0a6a1f1dSLionel Sambuc  # It will put a trailing '\' even on the last line, and will use leading
341*0a6a1f1dSLionel Sambuc  # spaces rather than leading tabs (at least since its commit 0394caf7
342*0a6a1f1dSLionel Sambuc  # "Emit spaces for -MD").
343ef01931fSBen Gras  "$@" -MD -MF "$tmpdepfile"
344ef01931fSBen Gras  stat=$?
345*0a6a1f1dSLionel Sambuc  if test $stat -ne 0; then
346ef01931fSBen Gras    rm -f "$tmpdepfile"
347ef01931fSBen Gras    exit $stat
348ef01931fSBen Gras  fi
349ef01931fSBen Gras  rm -f "$depfile"
350*0a6a1f1dSLionel Sambuc  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351*0a6a1f1dSLionel Sambuc  # We have to change lines of the first kind to '$object: \'.
352*0a6a1f1dSLionel Sambuc  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353*0a6a1f1dSLionel Sambuc  # And for each line of the second kind, we have to emit a 'dep.h:'
354*0a6a1f1dSLionel Sambuc  # dummy dependency, to avoid the deleted-header problem.
355*0a6a1f1dSLionel Sambuc  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35684d9c625SLionel Sambuc  rm -f "$tmpdepfile"
35784d9c625SLionel Sambuc  ;;
35884d9c625SLionel Sambuc
35984d9c625SLionel Sambuc## The order of this option in the case statement is important, since the
36084d9c625SLionel Sambuc## shell code in configure will try each of these formats in the order
36184d9c625SLionel Sambuc## listed in this file.  A plain '-MD' option would be understood by many
36284d9c625SLionel Sambuc## compilers, so we must ensure this comes after the gcc and icc options.
36384d9c625SLionel Sambucpgcc)
36484d9c625SLionel Sambuc  # Portland's C compiler understands '-MD'.
36584d9c625SLionel Sambuc  # Will always output deps to 'file.d' where file is the root name of the
36684d9c625SLionel Sambuc  # source file under compilation, even if file resides in a subdirectory.
36784d9c625SLionel Sambuc  # The object file name does not affect the name of the '.d' file.
36884d9c625SLionel Sambuc  # pgcc 10.2 will output
36984d9c625SLionel Sambuc  #    foo.o: sub/foo.c sub/foo.h
37084d9c625SLionel Sambuc  # and will wrap long lines using '\' :
37184d9c625SLionel Sambuc  #    foo.o: sub/foo.c ... \
37284d9c625SLionel Sambuc  #     sub/foo.h ... \
37384d9c625SLionel Sambuc  #     ...
374*0a6a1f1dSLionel Sambuc  set_dir_from "$object"
37584d9c625SLionel Sambuc  # Use the source, not the object, to determine the base name, since
37684d9c625SLionel Sambuc  # that's sadly what pgcc will do too.
377*0a6a1f1dSLionel Sambuc  set_base_from "$source"
378*0a6a1f1dSLionel Sambuc  tmpdepfile=$base.d
37984d9c625SLionel Sambuc
38084d9c625SLionel Sambuc  # For projects that build the same source file twice into different object
38184d9c625SLionel Sambuc  # files, the pgcc approach of using the *source* file root name can cause
38284d9c625SLionel Sambuc  # problems in parallel builds.  Use a locking strategy to avoid stomping on
38384d9c625SLionel Sambuc  # the same $tmpdepfile.
384*0a6a1f1dSLionel Sambuc  lockdir=$base.d-lock
385*0a6a1f1dSLionel Sambuc  trap "
386*0a6a1f1dSLionel Sambuc    echo '$0: caught signal, cleaning up...' >&2
387*0a6a1f1dSLionel Sambuc    rmdir '$lockdir'
388*0a6a1f1dSLionel Sambuc    exit 1
389*0a6a1f1dSLionel Sambuc  " 1 2 13 15
39084d9c625SLionel Sambuc  numtries=100
39184d9c625SLionel Sambuc  i=$numtries
39284d9c625SLionel Sambuc  while test $i -gt 0; do
39384d9c625SLionel Sambuc    # mkdir is a portable test-and-set.
394*0a6a1f1dSLionel Sambuc    if mkdir "$lockdir" 2>/dev/null; then
39584d9c625SLionel Sambuc      # This process acquired the lock.
39684d9c625SLionel Sambuc      "$@" -MD
39784d9c625SLionel Sambuc      stat=$?
39884d9c625SLionel Sambuc      # Release the lock.
399*0a6a1f1dSLionel Sambuc      rmdir "$lockdir"
40084d9c625SLionel Sambuc      break
40184d9c625SLionel Sambuc    else
402*0a6a1f1dSLionel Sambuc      # If the lock is being held by a different process, wait
403*0a6a1f1dSLionel Sambuc      # until the winning process is done or we timeout.
404*0a6a1f1dSLionel Sambuc      while test -d "$lockdir" && test $i -gt 0; do
40584d9c625SLionel Sambuc        sleep 1
40684d9c625SLionel Sambuc        i=`expr $i - 1`
40784d9c625SLionel Sambuc      done
40884d9c625SLionel Sambuc    fi
40984d9c625SLionel Sambuc    i=`expr $i - 1`
41084d9c625SLionel Sambuc  done
41184d9c625SLionel Sambuc  trap - 1 2 13 15
41284d9c625SLionel Sambuc  if test $i -le 0; then
41384d9c625SLionel Sambuc    echo "$0: failed to acquire lock after $numtries attempts" >&2
41484d9c625SLionel Sambuc    echo "$0: check lockdir '$lockdir'" >&2
41584d9c625SLionel Sambuc    exit 1
41684d9c625SLionel Sambuc  fi
41784d9c625SLionel Sambuc
41884d9c625SLionel Sambuc  if test $stat -ne 0; then
41984d9c625SLionel Sambuc    rm -f "$tmpdepfile"
42084d9c625SLionel Sambuc    exit $stat
42184d9c625SLionel Sambuc  fi
42284d9c625SLionel Sambuc  rm -f "$depfile"
423ef01931fSBen Gras  # Each line is of the form `foo.o: dependent.h',
424ef01931fSBen Gras  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425ef01931fSBen Gras  # Do two passes, one to just change these to
426ef01931fSBen Gras  # `$object: dependent.h' and one to simply `dependent.h:'.
427ef01931fSBen Gras  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428ef01931fSBen Gras  # Some versions of the HPUX 10.20 sed can't process this invocation
429ef01931fSBen Gras  # correctly.  Breaking it into two sed invocations is a workaround.
430*0a6a1f1dSLionel Sambuc  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431*0a6a1f1dSLionel Sambuc    | sed -e 's/$/ :/' >> "$depfile"
432ef01931fSBen Gras  rm -f "$tmpdepfile"
433ef01931fSBen Gras  ;;
434ef01931fSBen Gras
435ef01931fSBen Grashp2)
436ef01931fSBen Gras  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437ef01931fSBen Gras  # compilers, which have integrated preprocessors.  The correct option
438ef01931fSBen Gras  # to use with these is +Maked; it writes dependencies to a file named
439ef01931fSBen Gras  # 'foo.d', which lands next to the object file, wherever that
440ef01931fSBen Gras  # happens to be.
441ef01931fSBen Gras  # Much of this is similar to the tru64 case; see comments there.
442*0a6a1f1dSLionel Sambuc  set_dir_from  "$object"
443*0a6a1f1dSLionel Sambuc  set_base_from "$object"
444ef01931fSBen Gras  if test "$libtool" = yes; then
445ef01931fSBen Gras    tmpdepfile1=$dir$base.d
446ef01931fSBen Gras    tmpdepfile2=$dir.libs/$base.d
447ef01931fSBen Gras    "$@" -Wc,+Maked
448ef01931fSBen Gras  else
449ef01931fSBen Gras    tmpdepfile1=$dir$base.d
450ef01931fSBen Gras    tmpdepfile2=$dir$base.d
451ef01931fSBen Gras    "$@" +Maked
452ef01931fSBen Gras  fi
453ef01931fSBen Gras  stat=$?
454*0a6a1f1dSLionel Sambuc  if test $stat -ne 0; then
455ef01931fSBen Gras     rm -f "$tmpdepfile1" "$tmpdepfile2"
456ef01931fSBen Gras     exit $stat
457ef01931fSBen Gras  fi
458ef01931fSBen Gras
459ef01931fSBen Gras  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460ef01931fSBen Gras  do
461ef01931fSBen Gras    test -f "$tmpdepfile" && break
462ef01931fSBen Gras  done
463ef01931fSBen Gras  if test -f "$tmpdepfile"; then
464*0a6a1f1dSLionel Sambuc    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
46584d9c625SLionel Sambuc    # Add 'dependent.h:' lines.
466835f6802SDirk Vogt    sed -ne '2,${
467835f6802SDirk Vogt               s/^ *//
468835f6802SDirk Vogt               s/ \\*$//
469835f6802SDirk Vogt               s/$/:/
470835f6802SDirk Vogt               p
471835f6802SDirk Vogt             }' "$tmpdepfile" >> "$depfile"
472ef01931fSBen Gras  else
473*0a6a1f1dSLionel Sambuc    make_dummy_depfile
474ef01931fSBen Gras  fi
475ef01931fSBen Gras  rm -f "$tmpdepfile" "$tmpdepfile2"
476ef01931fSBen Gras  ;;
477ef01931fSBen Gras
478ef01931fSBen Grastru64)
479ef01931fSBen Gras  # The Tru64 compiler uses -MD to generate dependencies as a side
48084d9c625SLionel Sambuc  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481ef01931fSBen Gras  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
48284d9c625SLionel Sambuc  # dependencies in 'foo.d' instead, so we check for that too.
483ef01931fSBen Gras  # Subdirectories are respected.
484*0a6a1f1dSLionel Sambuc  set_dir_from  "$object"
485*0a6a1f1dSLionel Sambuc  set_base_from "$object"
486ef01931fSBen Gras
487ef01931fSBen Gras  if test "$libtool" = yes; then
488*0a6a1f1dSLionel Sambuc    # Libtool generates 2 separate objects for the 2 libraries.  These
489*0a6a1f1dSLionel Sambuc    # two compilations output dependencies in $dir.libs/$base.o.d and
490ef01931fSBen Gras    # in $dir$base.o.d.  We have to check for both files, because
491ef01931fSBen Gras    # one of the two compilations can be disabled.  We should prefer
492ef01931fSBen Gras    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493ef01931fSBen Gras    # automatically cleaned when .libs/ is deleted, while ignoring
494ef01931fSBen Gras    # the former would cause a distcleancheck panic.
495*0a6a1f1dSLionel Sambuc    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496*0a6a1f1dSLionel Sambuc    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497*0a6a1f1dSLionel Sambuc    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498ef01931fSBen Gras    "$@" -Wc,-MD
499ef01931fSBen Gras  else
500*0a6a1f1dSLionel Sambuc    tmpdepfile1=$dir$base.d
501ef01931fSBen Gras    tmpdepfile2=$dir$base.d
502ef01931fSBen Gras    tmpdepfile3=$dir$base.d
503ef01931fSBen Gras    "$@" -MD
504ef01931fSBen Gras  fi
505ef01931fSBen Gras
506ef01931fSBen Gras  stat=$?
507*0a6a1f1dSLionel Sambuc  if test $stat -ne 0; then
508*0a6a1f1dSLionel Sambuc    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509ef01931fSBen Gras    exit $stat
510ef01931fSBen Gras  fi
511ef01931fSBen Gras
512*0a6a1f1dSLionel Sambuc  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513ef01931fSBen Gras  do
514ef01931fSBen Gras    test -f "$tmpdepfile" && break
515ef01931fSBen Gras  done
516*0a6a1f1dSLionel Sambuc  # Same post-processing that is required for AIX mode.
517*0a6a1f1dSLionel Sambuc  aix_post_process_depfile
518ef01931fSBen Gras  ;;
519ef01931fSBen Gras
52084d9c625SLionel Sambucmsvc7)
52184d9c625SLionel Sambuc  if test "$libtool" = yes; then
52284d9c625SLionel Sambuc    showIncludes=-Wc,-showIncludes
52384d9c625SLionel Sambuc  else
52484d9c625SLionel Sambuc    showIncludes=-showIncludes
52584d9c625SLionel Sambuc  fi
52684d9c625SLionel Sambuc  "$@" $showIncludes > "$tmpdepfile"
52784d9c625SLionel Sambuc  stat=$?
52884d9c625SLionel Sambuc  grep -v '^Note: including file: ' "$tmpdepfile"
529*0a6a1f1dSLionel Sambuc  if test $stat -ne 0; then
53084d9c625SLionel Sambuc    rm -f "$tmpdepfile"
53184d9c625SLionel Sambuc    exit $stat
53284d9c625SLionel Sambuc  fi
53384d9c625SLionel Sambuc  rm -f "$depfile"
53484d9c625SLionel Sambuc  echo "$object : \\" > "$depfile"
53584d9c625SLionel Sambuc  # The first sed program below extracts the file names and escapes
53684d9c625SLionel Sambuc  # backslashes for cygpath.  The second sed program outputs the file
53784d9c625SLionel Sambuc  # name when reading, but also accumulates all include files in the
53884d9c625SLionel Sambuc  # hold buffer in order to output them again at the end.  This only
53984d9c625SLionel Sambuc  # works with sed implementations that can handle large buffers.
54084d9c625SLionel Sambuc  sed < "$tmpdepfile" -n '
54184d9c625SLionel Sambuc/^Note: including file:  *\(.*\)/ {
54284d9c625SLionel Sambuc  s//\1/
54384d9c625SLionel Sambuc  s/\\/\\\\/g
54484d9c625SLionel Sambuc  p
54584d9c625SLionel Sambuc}' | $cygpath_u | sort -u | sed -n '
54684d9c625SLionel Sambucs/ /\\ /g
54784d9c625SLionel Sambucs/\(.*\)/'"$tab"'\1 \\/p
54884d9c625SLionel Sambucs/.\(.*\) \\/\1:/
54984d9c625SLionel SambucH
55084d9c625SLionel Sambuc$ {
55184d9c625SLionel Sambuc  s/.*/'"$tab"'/
55284d9c625SLionel Sambuc  G
55384d9c625SLionel Sambuc  p
55484d9c625SLionel Sambuc}' >> "$depfile"
555*0a6a1f1dSLionel Sambuc  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
55684d9c625SLionel Sambuc  rm -f "$tmpdepfile"
55784d9c625SLionel Sambuc  ;;
55884d9c625SLionel Sambuc
55984d9c625SLionel Sambucmsvc7msys)
56084d9c625SLionel Sambuc  # This case exists only to let depend.m4 do its work.  It works by
56184d9c625SLionel Sambuc  # looking at the text of this script.  This case will never be run,
56284d9c625SLionel Sambuc  # since it is checked for above.
56384d9c625SLionel Sambuc  exit 1
56484d9c625SLionel Sambuc  ;;
56584d9c625SLionel Sambuc
566ef01931fSBen Gras#nosideeffect)
567ef01931fSBen Gras  # This comment above is used by automake to tell side-effect
568ef01931fSBen Gras  # dependency tracking mechanisms from slower ones.
569ef01931fSBen Gras
570ef01931fSBen Grasdashmstdout)
571ef01931fSBen Gras  # Important note: in order to support this mode, a compiler *must*
572ef01931fSBen Gras  # always write the preprocessed file to stdout, regardless of -o.
573ef01931fSBen Gras  "$@" || exit $?
574ef01931fSBen Gras
575ef01931fSBen Gras  # Remove the call to Libtool.
576ef01931fSBen Gras  if test "$libtool" = yes; then
577835f6802SDirk Vogt    while test "X$1" != 'X--mode=compile'; do
578ef01931fSBen Gras      shift
579ef01931fSBen Gras    done
580ef01931fSBen Gras    shift
581ef01931fSBen Gras  fi
582ef01931fSBen Gras
58384d9c625SLionel Sambuc  # Remove '-o $object'.
584ef01931fSBen Gras  IFS=" "
585ef01931fSBen Gras  for arg
586ef01931fSBen Gras  do
587ef01931fSBen Gras    case $arg in
588ef01931fSBen Gras    -o)
589ef01931fSBen Gras      shift
590ef01931fSBen Gras      ;;
591ef01931fSBen Gras    $object)
592ef01931fSBen Gras      shift
593ef01931fSBen Gras      ;;
594ef01931fSBen Gras    *)
595ef01931fSBen Gras      set fnord "$@" "$arg"
596ef01931fSBen Gras      shift # fnord
597ef01931fSBen Gras      shift # $arg
598ef01931fSBen Gras      ;;
599ef01931fSBen Gras    esac
600ef01931fSBen Gras  done
601ef01931fSBen Gras
602ef01931fSBen Gras  test -z "$dashmflag" && dashmflag=-M
60384d9c625SLionel Sambuc  # Require at least two characters before searching for ':'
604ef01931fSBen Gras  # in the target name.  This is to cope with DOS-style filenames:
60584d9c625SLionel Sambuc  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606ef01931fSBen Gras  "$@" $dashmflag |
607*0a6a1f1dSLionel Sambuc    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608ef01931fSBen Gras  rm -f "$depfile"
609ef01931fSBen Gras  cat < "$tmpdepfile" > "$depfile"
610*0a6a1f1dSLionel Sambuc  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611*0a6a1f1dSLionel Sambuc  # correctly.  Breaking it into two sed invocations is a workaround.
612*0a6a1f1dSLionel Sambuc  tr ' ' "$nl" < "$tmpdepfile" \
613*0a6a1f1dSLionel Sambuc    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614*0a6a1f1dSLionel Sambuc    | sed -e 's/$/ :/' >> "$depfile"
615ef01931fSBen Gras  rm -f "$tmpdepfile"
616ef01931fSBen Gras  ;;
617ef01931fSBen Gras
618ef01931fSBen GrasdashXmstdout)
619ef01931fSBen Gras  # This case only exists to satisfy depend.m4.  It is never actually
620ef01931fSBen Gras  # run, as this mode is specially recognized in the preamble.
621ef01931fSBen Gras  exit 1
622ef01931fSBen Gras  ;;
623ef01931fSBen Gras
624ef01931fSBen Grasmakedepend)
625ef01931fSBen Gras  "$@" || exit $?
626ef01931fSBen Gras  # Remove any Libtool call
627ef01931fSBen Gras  if test "$libtool" = yes; then
628835f6802SDirk Vogt    while test "X$1" != 'X--mode=compile'; do
629ef01931fSBen Gras      shift
630ef01931fSBen Gras    done
631ef01931fSBen Gras    shift
632ef01931fSBen Gras  fi
633ef01931fSBen Gras  # X makedepend
634ef01931fSBen Gras  shift
635835f6802SDirk Vogt  cleared=no eat=no
636835f6802SDirk Vogt  for arg
637835f6802SDirk Vogt  do
638ef01931fSBen Gras    case $cleared in
639ef01931fSBen Gras    no)
640ef01931fSBen Gras      set ""; shift
641ef01931fSBen Gras      cleared=yes ;;
642ef01931fSBen Gras    esac
643835f6802SDirk Vogt    if test $eat = yes; then
644835f6802SDirk Vogt      eat=no
645835f6802SDirk Vogt      continue
646835f6802SDirk Vogt    fi
647ef01931fSBen Gras    case "$arg" in
648ef01931fSBen Gras    -D*|-I*)
649ef01931fSBen Gras      set fnord "$@" "$arg"; shift ;;
650ef01931fSBen Gras    # Strip any option that makedepend may not understand.  Remove
651ef01931fSBen Gras    # the object too, otherwise makedepend will parse it as a source file.
652835f6802SDirk Vogt    -arch)
653835f6802SDirk Vogt      eat=yes ;;
654ef01931fSBen Gras    -*|$object)
655ef01931fSBen Gras      ;;
656ef01931fSBen Gras    *)
657ef01931fSBen Gras      set fnord "$@" "$arg"; shift ;;
658ef01931fSBen Gras    esac
659ef01931fSBen Gras  done
660835f6802SDirk Vogt  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661ef01931fSBen Gras  touch "$tmpdepfile"
662ef01931fSBen Gras  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663ef01931fSBen Gras  rm -f "$depfile"
66484d9c625SLionel Sambuc  # makedepend may prepend the VPATH from the source file name to the object.
66584d9c625SLionel Sambuc  # No need to regex-escape $object, excess matching of '.' is harmless.
66684d9c625SLionel Sambuc  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667*0a6a1f1dSLionel Sambuc  # Some versions of the HPUX 10.20 sed can't process the last invocation
668*0a6a1f1dSLionel Sambuc  # correctly.  Breaking it into two sed invocations is a workaround.
669*0a6a1f1dSLionel Sambuc  sed '1,2d' "$tmpdepfile" \
670*0a6a1f1dSLionel Sambuc    | tr ' ' "$nl" \
671*0a6a1f1dSLionel Sambuc    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672*0a6a1f1dSLionel Sambuc    | sed -e 's/$/ :/' >> "$depfile"
673ef01931fSBen Gras  rm -f "$tmpdepfile" "$tmpdepfile".bak
674ef01931fSBen Gras  ;;
675ef01931fSBen Gras
676ef01931fSBen Grascpp)
677ef01931fSBen Gras  # Important note: in order to support this mode, a compiler *must*
678ef01931fSBen Gras  # always write the preprocessed file to stdout.
679ef01931fSBen Gras  "$@" || exit $?
680ef01931fSBen Gras
681ef01931fSBen Gras  # Remove the call to Libtool.
682ef01931fSBen Gras  if test "$libtool" = yes; then
683835f6802SDirk Vogt    while test "X$1" != 'X--mode=compile'; do
684ef01931fSBen Gras      shift
685ef01931fSBen Gras    done
686ef01931fSBen Gras    shift
687ef01931fSBen Gras  fi
688ef01931fSBen Gras
68984d9c625SLionel Sambuc  # Remove '-o $object'.
690ef01931fSBen Gras  IFS=" "
691ef01931fSBen Gras  for arg
692ef01931fSBen Gras  do
693ef01931fSBen Gras    case $arg in
694ef01931fSBen Gras    -o)
695ef01931fSBen Gras      shift
696ef01931fSBen Gras      ;;
697ef01931fSBen Gras    $object)
698ef01931fSBen Gras      shift
699ef01931fSBen Gras      ;;
700ef01931fSBen Gras    *)
701ef01931fSBen Gras      set fnord "$@" "$arg"
702ef01931fSBen Gras      shift # fnord
703ef01931fSBen Gras      shift # $arg
704ef01931fSBen Gras      ;;
705ef01931fSBen Gras    esac
706ef01931fSBen Gras  done
707ef01931fSBen Gras
708*0a6a1f1dSLionel Sambuc  "$@" -E \
709*0a6a1f1dSLionel Sambuc    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710*0a6a1f1dSLionel Sambuc             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711*0a6a1f1dSLionel Sambuc    | sed '$ s: \\$::' > "$tmpdepfile"
712ef01931fSBen Gras  rm -f "$depfile"
713ef01931fSBen Gras  echo "$object : \\" > "$depfile"
714ef01931fSBen Gras  cat < "$tmpdepfile" >> "$depfile"
715ef01931fSBen Gras  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716ef01931fSBen Gras  rm -f "$tmpdepfile"
717ef01931fSBen Gras  ;;
718ef01931fSBen Gras
719ef01931fSBen Grasmsvisualcpp)
720ef01931fSBen Gras  # Important note: in order to support this mode, a compiler *must*
721835f6802SDirk Vogt  # always write the preprocessed file to stdout.
722ef01931fSBen Gras  "$@" || exit $?
723835f6802SDirk Vogt
724835f6802SDirk Vogt  # Remove the call to Libtool.
725835f6802SDirk Vogt  if test "$libtool" = yes; then
726835f6802SDirk Vogt    while test "X$1" != 'X--mode=compile'; do
727835f6802SDirk Vogt      shift
728835f6802SDirk Vogt    done
729835f6802SDirk Vogt    shift
730835f6802SDirk Vogt  fi
731835f6802SDirk Vogt
732ef01931fSBen Gras  IFS=" "
733ef01931fSBen Gras  for arg
734ef01931fSBen Gras  do
735ef01931fSBen Gras    case "$arg" in
736835f6802SDirk Vogt    -o)
737835f6802SDirk Vogt      shift
738835f6802SDirk Vogt      ;;
739835f6802SDirk Vogt    $object)
740835f6802SDirk Vogt      shift
741835f6802SDirk Vogt      ;;
742ef01931fSBen Gras    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743ef01931fSBen Gras        set fnord "$@"
744ef01931fSBen Gras        shift
745ef01931fSBen Gras        shift
746ef01931fSBen Gras        ;;
747ef01931fSBen Gras    *)
748ef01931fSBen Gras        set fnord "$@" "$arg"
749ef01931fSBen Gras        shift
750ef01931fSBen Gras        shift
751ef01931fSBen Gras        ;;
752ef01931fSBen Gras    esac
753ef01931fSBen Gras  done
754835f6802SDirk Vogt  "$@" -E 2>/dev/null |
755835f6802SDirk Vogt  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756ef01931fSBen Gras  rm -f "$depfile"
757ef01931fSBen Gras  echo "$object : \\" > "$depfile"
75884d9c625SLionel Sambuc  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
75984d9c625SLionel Sambuc  echo "$tab" >> "$depfile"
760835f6802SDirk Vogt  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761ef01931fSBen Gras  rm -f "$tmpdepfile"
762ef01931fSBen Gras  ;;
763ef01931fSBen Gras
764835f6802SDirk Vogtmsvcmsys)
765835f6802SDirk Vogt  # This case exists only to let depend.m4 do its work.  It works by
766835f6802SDirk Vogt  # looking at the text of this script.  This case will never be run,
767835f6802SDirk Vogt  # since it is checked for above.
768835f6802SDirk Vogt  exit 1
769835f6802SDirk Vogt  ;;
770835f6802SDirk Vogt
771ef01931fSBen Grasnone)
772ef01931fSBen Gras  exec "$@"
773ef01931fSBen Gras  ;;
774ef01931fSBen Gras
775ef01931fSBen Gras*)
776ef01931fSBen Gras  echo "Unknown depmode $depmode" 1>&2
777ef01931fSBen Gras  exit 1
778ef01931fSBen Gras  ;;
779ef01931fSBen Grasesac
780ef01931fSBen Gras
781ef01931fSBen Grasexit 0
782ef01931fSBen Gras
783ef01931fSBen Gras# Local Variables:
784ef01931fSBen Gras# mode: shell-script
785ef01931fSBen Gras# sh-indentation: 2
786ef01931fSBen Gras# eval: (add-hook 'write-file-hooks 'time-stamp)
787ef01931fSBen Gras# time-stamp-start: "scriptversion="
788ef01931fSBen Gras# time-stamp-format: "%:y-%02m-%02d.%02H"
789835f6802SDirk Vogt# time-stamp-time-zone: "UTC"
790835f6802SDirk Vogt# time-stamp-end: "; # UTC"
791ef01931fSBen Gras# End:
792