depcomp revision a39bb051
1c19de146Smrg#! /bin/sh
2c19de146Smrg# depcomp - compile a program generating dependencies as side-effects
39ef7378bSmrg
4a39bb051Smrgscriptversion=2013-05-30.07; # UTC
59ef7378bSmrg
6a39bb051Smrg# Copyright (C) 1999-2014 Free Software Foundation, Inc.
7c19de146Smrg
8c19de146Smrg# This program is free software; you can redistribute it and/or modify
9c19de146Smrg# it under the terms of the GNU General Public License as published by
10c19de146Smrg# the Free Software Foundation; either version 2, or (at your option)
11c19de146Smrg# any later version.
12c19de146Smrg
13c19de146Smrg# This program is distributed in the hope that it will be useful,
14c19de146Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15c19de146Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c19de146Smrg# GNU General Public License for more details.
17c19de146Smrg
18c19de146Smrg# You should have received a copy of the GNU General Public License
199ef7378bSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20c19de146Smrg
21c19de146Smrg# As a special exception to the GNU General Public License, if you
22c19de146Smrg# distribute this file as part of a program that contains a
23c19de146Smrg# configuration script generated by Autoconf, you may include it under
24c19de146Smrg# the same distribution terms that you use for the rest of that program.
25c19de146Smrg
26c19de146Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27c19de146Smrg
289ef7378bSmrgcase $1 in
299ef7378bSmrg  '')
30a39bb051Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31a39bb051Smrg    exit 1;
32a39bb051Smrg    ;;
339ef7378bSmrg  -h | --h*)
349ef7378bSmrg    cat <<\EOF
359ef7378bSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
369ef7378bSmrg
379ef7378bSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
389ef7378bSmrgas side-effects.
399ef7378bSmrg
409ef7378bSmrgEnvironment variables:
419ef7378bSmrg  depmode     Dependency tracking mode.
42a39bb051Smrg  source      Source file read by 'PROGRAMS ARGS'.
43a39bb051Smrg  object      Object file output by 'PROGRAMS ARGS'.
449ef7378bSmrg  DEPDIR      directory where to store dependencies.
459ef7378bSmrg  depfile     Dependency file to output.
46a39bb051Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
479ef7378bSmrg  libtool     Whether libtool is used (yes/no).
489ef7378bSmrg
499ef7378bSmrgReport bugs to <bug-automake@gnu.org>.
509ef7378bSmrgEOF
519ef7378bSmrg    exit $?
529ef7378bSmrg    ;;
539ef7378bSmrg  -v | --v*)
549ef7378bSmrg    echo "depcomp $scriptversion"
559ef7378bSmrg    exit $?
569ef7378bSmrg    ;;
579ef7378bSmrgesac
589ef7378bSmrg
59a39bb051Smrg# Get the directory component of the given path, and save it in the
60a39bb051Smrg# global variables '$dir'.  Note that this directory component will
61a39bb051Smrg# be either empty or ending with a '/' character.  This is deliberate.
62a39bb051Smrgset_dir_from ()
63a39bb051Smrg{
64a39bb051Smrg  case $1 in
65a39bb051Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66a39bb051Smrg      *) dir=;;
67a39bb051Smrg  esac
68a39bb051Smrg}
69a39bb051Smrg
70a39bb051Smrg# Get the suffix-stripped basename of the given path, and save it the
71a39bb051Smrg# global variable '$base'.
72a39bb051Smrgset_base_from ()
73a39bb051Smrg{
74a39bb051Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75a39bb051Smrg}
76a39bb051Smrg
77a39bb051Smrg# If no dependency file was actually created by the compiler invocation,
78a39bb051Smrg# we still have to create a dummy depfile, to avoid errors with the
79a39bb051Smrg# Makefile "include basename.Plo" scheme.
80a39bb051Smrgmake_dummy_depfile ()
81a39bb051Smrg{
82a39bb051Smrg  echo "#dummy" > "$depfile"
83a39bb051Smrg}
84a39bb051Smrg
85a39bb051Smrg# Factor out some common post-processing of the generated depfile.
86a39bb051Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87a39bb051Smrgaix_post_process_depfile ()
88a39bb051Smrg{
89a39bb051Smrg  # If the compiler actually managed to produce a dependency file,
90a39bb051Smrg  # post-process it.
91a39bb051Smrg  if test -f "$tmpdepfile"; then
92a39bb051Smrg    # Each line is of the form 'foo.o: dependency.h'.
93a39bb051Smrg    # Do two passes, one to just change these to
94a39bb051Smrg    #   $object: dependency.h
95a39bb051Smrg    # and one to simply output
96a39bb051Smrg    #   dependency.h:
97a39bb051Smrg    # which is needed to avoid the deleted-header problem.
98a39bb051Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99a39bb051Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100a39bb051Smrg    } > "$depfile"
101a39bb051Smrg    rm -f "$tmpdepfile"
102a39bb051Smrg  else
103a39bb051Smrg    make_dummy_depfile
104a39bb051Smrg  fi
105a39bb051Smrg}
106a39bb051Smrg
107a39bb051Smrg# A tabulation character.
108a39bb051Smrgtab='	'
109a39bb051Smrg# A newline character.
110a39bb051Smrgnl='
111a39bb051Smrg'
112a39bb051Smrg# Character ranges might be problematic outside the C locale.
113a39bb051Smrg# These definitions help.
114a39bb051Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115a39bb051Smrglower=abcdefghijklmnopqrstuvwxyz
116a39bb051Smrgdigits=0123456789
117a39bb051Smrgalpha=${upper}${lower}
118a39bb051Smrg
119c19de146Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120c19de146Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121c19de146Smrg  exit 1
122c19de146Smrgfi
123c19de146Smrg
1249ef7378bSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1259ef7378bSmrgdepfile=${depfile-`echo "$object" |
1269ef7378bSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127c19de146Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128c19de146Smrg
129c19de146Smrgrm -f "$tmpdepfile"
130c19de146Smrg
131a39bb051Smrg# Avoid interferences from the environment.
132a39bb051Smrggccflag= dashmflag=
133a39bb051Smrg
134c19de146Smrg# Some modes work just like other modes, but use different flags.  We
135c19de146Smrg# parameterize here, but still list the modes in the big case below,
136c19de146Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137c19de146Smrg# here, because this file can only contain one case statement.
138c19de146Smrgif test "$depmode" = hp; then
139c19de146Smrg  # HP compiler uses -M and no extra arg.
140c19de146Smrg  gccflag=-M
141c19de146Smrg  depmode=gcc
142c19de146Smrgfi
143c19de146Smrg
144c19de146Smrgif test "$depmode" = dashXmstdout; then
145a39bb051Smrg  # This is just like dashmstdout with a different argument.
146a39bb051Smrg  dashmflag=-xM
147a39bb051Smrg  depmode=dashmstdout
148c19de146Smrgfi
149c19de146Smrg
1509ef7378bSmrgcygpath_u="cygpath -u -f -"
1519ef7378bSmrgif test "$depmode" = msvcmsys; then
152a39bb051Smrg  # This is just like msvisualcpp but w/o cygpath translation.
153a39bb051Smrg  # Just convert the backslash-escaped backslashes to single forward
154a39bb051Smrg  # slashes to satisfy depend.m4
155a39bb051Smrg  cygpath_u='sed s,\\\\,/,g'
156a39bb051Smrg  depmode=msvisualcpp
157a39bb051Smrgfi
158a39bb051Smrg
159a39bb051Smrgif test "$depmode" = msvc7msys; then
160a39bb051Smrg  # This is just like msvc7 but w/o cygpath translation.
161a39bb051Smrg  # Just convert the backslash-escaped backslashes to single forward
162a39bb051Smrg  # slashes to satisfy depend.m4
163a39bb051Smrg  cygpath_u='sed s,\\\\,/,g'
164a39bb051Smrg  depmode=msvc7
165a39bb051Smrgfi
166a39bb051Smrg
167a39bb051Smrgif test "$depmode" = xlc; then
168a39bb051Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169a39bb051Smrg  gccflag=-qmakedep=gcc,-MF
170a39bb051Smrg  depmode=gcc
1719ef7378bSmrgfi
1729ef7378bSmrg
173c19de146Smrgcase "$depmode" in
174c19de146Smrggcc3)
175c19de146Smrg## gcc 3 implements dependency tracking that does exactly what
176c19de146Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177c19de146Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1789ef7378bSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1799ef7378bSmrg## the command line argument order; so add the flags where they
1809ef7378bSmrg## appear in depend2.am.  Note that the slowdown incurred here
1819ef7378bSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1829ef7378bSmrg  for arg
1839ef7378bSmrg  do
1849ef7378bSmrg    case $arg in
1859ef7378bSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1869ef7378bSmrg    *)  set fnord "$@" "$arg" ;;
1879ef7378bSmrg    esac
1889ef7378bSmrg    shift # fnord
1899ef7378bSmrg    shift # $arg
1909ef7378bSmrg  done
1919ef7378bSmrg  "$@"
192c19de146Smrg  stat=$?
193a39bb051Smrg  if test $stat -ne 0; then
194c19de146Smrg    rm -f "$tmpdepfile"
195c19de146Smrg    exit $stat
196c19de146Smrg  fi
197c19de146Smrg  mv "$tmpdepfile" "$depfile"
198c19de146Smrg  ;;
199c19de146Smrg
200c19de146Smrggcc)
201a39bb051Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202a39bb051Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203a39bb051Smrg## (see the conditional assignment to $gccflag above).
204c19de146Smrg## There are various ways to get dependency output from gcc.  Here's
205c19de146Smrg## why we pick this rather obscure method:
206c19de146Smrg## - Don't want to use -MD because we'd like the dependencies to end
207c19de146Smrg##   up in a subdir.  Having to rename by hand is ugly.
208c19de146Smrg##   (We might end up doing this anyway to support other compilers.)
209c19de146Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210a39bb051Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211a39bb051Smrg##   supported by the other compilers which use the 'gcc' depmode.
212c19de146Smrg## - Using -M directly means running the compiler twice (even worse
213c19de146Smrg##   than renaming).
214c19de146Smrg  if test -z "$gccflag"; then
215c19de146Smrg    gccflag=-MD,
216c19de146Smrg  fi
217c19de146Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
218c19de146Smrg  stat=$?
219a39bb051Smrg  if test $stat -ne 0; then
220c19de146Smrg    rm -f "$tmpdepfile"
221c19de146Smrg    exit $stat
222c19de146Smrg  fi
223c19de146Smrg  rm -f "$depfile"
224c19de146Smrg  echo "$object : \\" > "$depfile"
225a39bb051Smrg  # The second -e expression handles DOS-style file names with drive
226a39bb051Smrg  # letters.
227c19de146Smrg  sed -e 's/^[^:]*: / /' \
228c19de146Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229a39bb051Smrg## This next piece of magic avoids the "deleted header file" problem.
230c19de146Smrg## The problem is that when a header file which appears in a .P file
231c19de146Smrg## is deleted, the dependency causes make to die (because there is
232c19de146Smrg## typically no way to rebuild the header).  We avoid this by adding
233c19de146Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234c19de146Smrg## this for us directly.
235a39bb051Smrg## Some versions of gcc put a space before the ':'.  On the theory
236c19de146Smrg## that the space means something, we add a space to the output as
237a39bb051Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238a39bb051Smrg## to the object.  Take care to not repeat it in the output.
239c19de146Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
240c19de146Smrg## correctly.  Breaking it into two sed invocations is a workaround.
241a39bb051Smrg  tr ' ' "$nl" < "$tmpdepfile" \
242a39bb051Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243a39bb051Smrg    | sed -e 's/$/ :/' >> "$depfile"
244c19de146Smrg  rm -f "$tmpdepfile"
245c19de146Smrg  ;;
246c19de146Smrg
247c19de146Smrghp)
248c19de146Smrg  # This case exists only to let depend.m4 do its work.  It works by
249c19de146Smrg  # looking at the text of this script.  This case will never be run,
250c19de146Smrg  # since it is checked for above.
251c19de146Smrg  exit 1
252c19de146Smrg  ;;
253c19de146Smrg
254c19de146Smrgsgi)
255c19de146Smrg  if test "$libtool" = yes; then
256c19de146Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257c19de146Smrg  else
258c19de146Smrg    "$@" -MDupdate "$tmpdepfile"
259c19de146Smrg  fi
260c19de146Smrg  stat=$?
261a39bb051Smrg  if test $stat -ne 0; then
262c19de146Smrg    rm -f "$tmpdepfile"
263c19de146Smrg    exit $stat
264c19de146Smrg  fi
265c19de146Smrg  rm -f "$depfile"
266c19de146Smrg
267c19de146Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268c19de146Smrg    echo "$object : \\" > "$depfile"
269c19de146Smrg    # Clip off the initial element (the dependent).  Don't try to be
270c19de146Smrg    # clever and replace this with sed code, as IRIX sed won't handle
271c19de146Smrg    # lines with more than a fixed number of characters (4096 in
272c19de146Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273a39bb051Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
274c19de146Smrg    # dependency line.
275a39bb051Smrg    tr ' ' "$nl" < "$tmpdepfile" \
276a39bb051Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277a39bb051Smrg      | tr "$nl" ' ' >> "$depfile"
2789ef7378bSmrg    echo >> "$depfile"
279c19de146Smrg    # The second pass generates a dummy entry for each header file.
280a39bb051Smrg    tr ' ' "$nl" < "$tmpdepfile" \
281a39bb051Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282a39bb051Smrg      >> "$depfile"
283c19de146Smrg  else
284a39bb051Smrg    make_dummy_depfile
285c19de146Smrg  fi
286c19de146Smrg  rm -f "$tmpdepfile"
287c19de146Smrg  ;;
288c19de146Smrg
289a39bb051Smrgxlc)
290a39bb051Smrg  # This case exists only to let depend.m4 do its work.  It works by
291a39bb051Smrg  # looking at the text of this script.  This case will never be run,
292a39bb051Smrg  # since it is checked for above.
293a39bb051Smrg  exit 1
294a39bb051Smrg  ;;
295a39bb051Smrg
296c19de146Smrgaix)
297c19de146Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
298c19de146Smrg  # in a .u file.  In older versions, this file always lives in the
299a39bb051Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300c19de146Smrg  # start of each line; $object doesn't have directory information.
301c19de146Smrg  # Version 6 uses the directory in both cases.
302a39bb051Smrg  set_dir_from "$object"
303a39bb051Smrg  set_base_from "$object"
304c19de146Smrg  if test "$libtool" = yes; then
3059ef7378bSmrg    tmpdepfile1=$dir$base.u
3069ef7378bSmrg    tmpdepfile2=$base.u
3079ef7378bSmrg    tmpdepfile3=$dir.libs/$base.u
308c19de146Smrg    "$@" -Wc,-M
309c19de146Smrg  else
3109ef7378bSmrg    tmpdepfile1=$dir$base.u
3119ef7378bSmrg    tmpdepfile2=$dir$base.u
3129ef7378bSmrg    tmpdepfile3=$dir$base.u
313c19de146Smrg    "$@" -M
314c19de146Smrg  fi
315c19de146Smrg  stat=$?
316a39bb051Smrg  if test $stat -ne 0; then
3179ef7378bSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318c19de146Smrg    exit $stat
319c19de146Smrg  fi
320c19de146Smrg
3219ef7378bSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3229ef7378bSmrg  do
3239ef7378bSmrg    test -f "$tmpdepfile" && break
3249ef7378bSmrg  done
325a39bb051Smrg  aix_post_process_depfile
326a39bb051Smrg  ;;
327a39bb051Smrg
328a39bb051Smrgtcc)
329a39bb051Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330a39bb051Smrg  # FIXME: That version still under development at the moment of writing.
331a39bb051Smrg  #        Make that this statement remains true also for stable, released
332a39bb051Smrg  #        versions.
333a39bb051Smrg  # It will wrap lines (doesn't matter whether long or short) with a
334a39bb051Smrg  # trailing '\', as in:
335a39bb051Smrg  #
336a39bb051Smrg  #   foo.o : \
337a39bb051Smrg  #    foo.c \
338a39bb051Smrg  #    foo.h \
339a39bb051Smrg  #
340a39bb051Smrg  # It will put a trailing '\' even on the last line, and will use leading
341a39bb051Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342a39bb051Smrg  # "Emit spaces for -MD").
343a39bb051Smrg  "$@" -MD -MF "$tmpdepfile"
344a39bb051Smrg  stat=$?
345a39bb051Smrg  if test $stat -ne 0; then
346a39bb051Smrg    rm -f "$tmpdepfile"
347a39bb051Smrg    exit $stat
348c19de146Smrg  fi
349a39bb051Smrg  rm -f "$depfile"
350a39bb051Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351a39bb051Smrg  # We have to change lines of the first kind to '$object: \'.
352a39bb051Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353a39bb051Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354a39bb051Smrg  # dummy dependency, to avoid the deleted-header problem.
355a39bb051Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356c19de146Smrg  rm -f "$tmpdepfile"
357c19de146Smrg  ;;
358c19de146Smrg
359a39bb051Smrg## The order of this option in the case statement is important, since the
360a39bb051Smrg## shell code in configure will try each of these formats in the order
361a39bb051Smrg## listed in this file.  A plain '-MD' option would be understood by many
362a39bb051Smrg## compilers, so we must ensure this comes after the gcc and icc options.
363a39bb051Smrgpgcc)
364a39bb051Smrg  # Portland's C compiler understands '-MD'.
365a39bb051Smrg  # Will always output deps to 'file.d' where file is the root name of the
366a39bb051Smrg  # source file under compilation, even if file resides in a subdirectory.
367a39bb051Smrg  # The object file name does not affect the name of the '.d' file.
368a39bb051Smrg  # pgcc 10.2 will output
369c19de146Smrg  #    foo.o: sub/foo.c sub/foo.h
370a39bb051Smrg  # and will wrap long lines using '\' :
371c19de146Smrg  #    foo.o: sub/foo.c ... \
372c19de146Smrg  #     sub/foo.h ... \
373c19de146Smrg  #     ...
374a39bb051Smrg  set_dir_from "$object"
375a39bb051Smrg  # Use the source, not the object, to determine the base name, since
376a39bb051Smrg  # that's sadly what pgcc will do too.
377a39bb051Smrg  set_base_from "$source"
378a39bb051Smrg  tmpdepfile=$base.d
379a39bb051Smrg
380a39bb051Smrg  # For projects that build the same source file twice into different object
381a39bb051Smrg  # files, the pgcc approach of using the *source* file root name can cause
382a39bb051Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383a39bb051Smrg  # the same $tmpdepfile.
384a39bb051Smrg  lockdir=$base.d-lock
385a39bb051Smrg  trap "
386a39bb051Smrg    echo '$0: caught signal, cleaning up...' >&2
387a39bb051Smrg    rmdir '$lockdir'
388a39bb051Smrg    exit 1
389a39bb051Smrg  " 1 2 13 15
390a39bb051Smrg  numtries=100
391a39bb051Smrg  i=$numtries
392a39bb051Smrg  while test $i -gt 0; do
393a39bb051Smrg    # mkdir is a portable test-and-set.
394a39bb051Smrg    if mkdir "$lockdir" 2>/dev/null; then
395a39bb051Smrg      # This process acquired the lock.
396a39bb051Smrg      "$@" -MD
397a39bb051Smrg      stat=$?
398a39bb051Smrg      # Release the lock.
399a39bb051Smrg      rmdir "$lockdir"
400a39bb051Smrg      break
401a39bb051Smrg    else
402a39bb051Smrg      # If the lock is being held by a different process, wait
403a39bb051Smrg      # until the winning process is done or we timeout.
404a39bb051Smrg      while test -d "$lockdir" && test $i -gt 0; do
405a39bb051Smrg        sleep 1
406a39bb051Smrg        i=`expr $i - 1`
407a39bb051Smrg      done
408a39bb051Smrg    fi
409a39bb051Smrg    i=`expr $i - 1`
410a39bb051Smrg  done
411a39bb051Smrg  trap - 1 2 13 15
412a39bb051Smrg  if test $i -le 0; then
413a39bb051Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414a39bb051Smrg    echo "$0: check lockdir '$lockdir'" >&2
415a39bb051Smrg    exit 1
416a39bb051Smrg  fi
417c19de146Smrg
418a39bb051Smrg  if test $stat -ne 0; then
419c19de146Smrg    rm -f "$tmpdepfile"
420c19de146Smrg    exit $stat
421c19de146Smrg  fi
422c19de146Smrg  rm -f "$depfile"
423c19de146Smrg  # Each line is of the form `foo.o: dependent.h',
424c19de146Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425c19de146Smrg  # Do two passes, one to just change these to
426c19de146Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427c19de146Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428c19de146Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429c19de146Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
430a39bb051Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431a39bb051Smrg    | sed -e 's/$/ :/' >> "$depfile"
432c19de146Smrg  rm -f "$tmpdepfile"
433c19de146Smrg  ;;
434c19de146Smrg
4359ef7378bSmrghp2)
4369ef7378bSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4379ef7378bSmrg  # compilers, which have integrated preprocessors.  The correct option
4389ef7378bSmrg  # to use with these is +Maked; it writes dependencies to a file named
4399ef7378bSmrg  # 'foo.d', which lands next to the object file, wherever that
4409ef7378bSmrg  # happens to be.
4419ef7378bSmrg  # Much of this is similar to the tru64 case; see comments there.
442a39bb051Smrg  set_dir_from  "$object"
443a39bb051Smrg  set_base_from "$object"
4449ef7378bSmrg  if test "$libtool" = yes; then
4459ef7378bSmrg    tmpdepfile1=$dir$base.d
4469ef7378bSmrg    tmpdepfile2=$dir.libs/$base.d
4479ef7378bSmrg    "$@" -Wc,+Maked
4489ef7378bSmrg  else
4499ef7378bSmrg    tmpdepfile1=$dir$base.d
4509ef7378bSmrg    tmpdepfile2=$dir$base.d
4519ef7378bSmrg    "$@" +Maked
4529ef7378bSmrg  fi
4539ef7378bSmrg  stat=$?
454a39bb051Smrg  if test $stat -ne 0; then
4559ef7378bSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4569ef7378bSmrg     exit $stat
4579ef7378bSmrg  fi
4589ef7378bSmrg
4599ef7378bSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4609ef7378bSmrg  do
4619ef7378bSmrg    test -f "$tmpdepfile" && break
4629ef7378bSmrg  done
4639ef7378bSmrg  if test -f "$tmpdepfile"; then
464a39bb051Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465a39bb051Smrg    # Add 'dependent.h:' lines.
4669ef7378bSmrg    sed -ne '2,${
467a39bb051Smrg               s/^ *//
468a39bb051Smrg               s/ \\*$//
469a39bb051Smrg               s/$/:/
470a39bb051Smrg               p
471a39bb051Smrg             }' "$tmpdepfile" >> "$depfile"
4729ef7378bSmrg  else
473a39bb051Smrg    make_dummy_depfile
4749ef7378bSmrg  fi
4759ef7378bSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4769ef7378bSmrg  ;;
4779ef7378bSmrg
478c19de146Smrgtru64)
479a39bb051Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480a39bb051Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481a39bb051Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482a39bb051Smrg  # dependencies in 'foo.d' instead, so we check for that too.
483a39bb051Smrg  # Subdirectories are respected.
484a39bb051Smrg  set_dir_from  "$object"
485a39bb051Smrg  set_base_from "$object"
486a39bb051Smrg
487a39bb051Smrg  if test "$libtool" = yes; then
488a39bb051Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489a39bb051Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490a39bb051Smrg    # in $dir$base.o.d.  We have to check for both files, because
491a39bb051Smrg    # one of the two compilations can be disabled.  We should prefer
492a39bb051Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493a39bb051Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
494a39bb051Smrg    # the former would cause a distcleancheck panic.
495a39bb051Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496a39bb051Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497a39bb051Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498a39bb051Smrg    "$@" -Wc,-MD
499a39bb051Smrg  else
500a39bb051Smrg    tmpdepfile1=$dir$base.d
501a39bb051Smrg    tmpdepfile2=$dir$base.d
502a39bb051Smrg    tmpdepfile3=$dir$base.d
503a39bb051Smrg    "$@" -MD
504a39bb051Smrg  fi
505a39bb051Smrg
506a39bb051Smrg  stat=$?
507a39bb051Smrg  if test $stat -ne 0; then
508a39bb051Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509a39bb051Smrg    exit $stat
510a39bb051Smrg  fi
511a39bb051Smrg
512a39bb051Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513a39bb051Smrg  do
514a39bb051Smrg    test -f "$tmpdepfile" && break
515a39bb051Smrg  done
516a39bb051Smrg  # Same post-processing that is required for AIX mode.
517a39bb051Smrg  aix_post_process_depfile
518a39bb051Smrg  ;;
519a39bb051Smrg
520a39bb051Smrgmsvc7)
521a39bb051Smrg  if test "$libtool" = yes; then
522a39bb051Smrg    showIncludes=-Wc,-showIncludes
523a39bb051Smrg  else
524a39bb051Smrg    showIncludes=-showIncludes
525a39bb051Smrg  fi
526a39bb051Smrg  "$@" $showIncludes > "$tmpdepfile"
527a39bb051Smrg  stat=$?
528a39bb051Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
529a39bb051Smrg  if test $stat -ne 0; then
530a39bb051Smrg    rm -f "$tmpdepfile"
531a39bb051Smrg    exit $stat
532a39bb051Smrg  fi
533a39bb051Smrg  rm -f "$depfile"
534a39bb051Smrg  echo "$object : \\" > "$depfile"
535a39bb051Smrg  # The first sed program below extracts the file names and escapes
536a39bb051Smrg  # backslashes for cygpath.  The second sed program outputs the file
537a39bb051Smrg  # name when reading, but also accumulates all include files in the
538a39bb051Smrg  # hold buffer in order to output them again at the end.  This only
539a39bb051Smrg  # works with sed implementations that can handle large buffers.
540a39bb051Smrg  sed < "$tmpdepfile" -n '
541a39bb051Smrg/^Note: including file:  *\(.*\)/ {
542a39bb051Smrg  s//\1/
543a39bb051Smrg  s/\\/\\\\/g
544a39bb051Smrg  p
545a39bb051Smrg}' | $cygpath_u | sort -u | sed -n '
546a39bb051Smrgs/ /\\ /g
547a39bb051Smrgs/\(.*\)/'"$tab"'\1 \\/p
548a39bb051Smrgs/.\(.*\) \\/\1:/
549a39bb051SmrgH
550a39bb051Smrg$ {
551a39bb051Smrg  s/.*/'"$tab"'/
552a39bb051Smrg  G
553a39bb051Smrg  p
554a39bb051Smrg}' >> "$depfile"
555a39bb051Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556a39bb051Smrg  rm -f "$tmpdepfile"
557a39bb051Smrg  ;;
558a39bb051Smrg
559a39bb051Smrgmsvc7msys)
560a39bb051Smrg  # This case exists only to let depend.m4 do its work.  It works by
561a39bb051Smrg  # looking at the text of this script.  This case will never be run,
562a39bb051Smrg  # since it is checked for above.
563a39bb051Smrg  exit 1
564a39bb051Smrg  ;;
565c19de146Smrg
566c19de146Smrg#nosideeffect)
567c19de146Smrg  # This comment above is used by automake to tell side-effect
568c19de146Smrg  # dependency tracking mechanisms from slower ones.
569c19de146Smrg
570c19de146Smrgdashmstdout)
571c19de146Smrg  # Important note: in order to support this mode, a compiler *must*
572c19de146Smrg  # always write the preprocessed file to stdout, regardless of -o.
573c19de146Smrg  "$@" || exit $?
574c19de146Smrg
575c19de146Smrg  # Remove the call to Libtool.
576c19de146Smrg  if test "$libtool" = yes; then
5779ef7378bSmrg    while test "X$1" != 'X--mode=compile'; do
578c19de146Smrg      shift
579c19de146Smrg    done
580c19de146Smrg    shift
581c19de146Smrg  fi
582c19de146Smrg
583a39bb051Smrg  # Remove '-o $object'.
584c19de146Smrg  IFS=" "
585c19de146Smrg  for arg
586c19de146Smrg  do
587c19de146Smrg    case $arg in
588c19de146Smrg    -o)
589c19de146Smrg      shift
590c19de146Smrg      ;;
591c19de146Smrg    $object)
592c19de146Smrg      shift
593c19de146Smrg      ;;
594c19de146Smrg    *)
595c19de146Smrg      set fnord "$@" "$arg"
596c19de146Smrg      shift # fnord
597c19de146Smrg      shift # $arg
598c19de146Smrg      ;;
599c19de146Smrg    esac
600c19de146Smrg  done
601c19de146Smrg
602c19de146Smrg  test -z "$dashmflag" && dashmflag=-M
603a39bb051Smrg  # Require at least two characters before searching for ':'
604c19de146Smrg  # in the target name.  This is to cope with DOS-style filenames:
605a39bb051Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606c19de146Smrg  "$@" $dashmflag |
607a39bb051Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608c19de146Smrg  rm -f "$depfile"
609c19de146Smrg  cat < "$tmpdepfile" > "$depfile"
610a39bb051Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611a39bb051Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
612a39bb051Smrg  tr ' ' "$nl" < "$tmpdepfile" \
613a39bb051Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614a39bb051Smrg    | sed -e 's/$/ :/' >> "$depfile"
615c19de146Smrg  rm -f "$tmpdepfile"
616c19de146Smrg  ;;
617c19de146Smrg
618c19de146SmrgdashXmstdout)
619c19de146Smrg  # This case only exists to satisfy depend.m4.  It is never actually
620c19de146Smrg  # run, as this mode is specially recognized in the preamble.
621c19de146Smrg  exit 1
622c19de146Smrg  ;;
623c19de146Smrg
624c19de146Smrgmakedepend)
625c19de146Smrg  "$@" || exit $?
626c19de146Smrg  # Remove any Libtool call
627c19de146Smrg  if test "$libtool" = yes; then
6289ef7378bSmrg    while test "X$1" != 'X--mode=compile'; do
629c19de146Smrg      shift
630c19de146Smrg    done
631c19de146Smrg    shift
632c19de146Smrg  fi
633c19de146Smrg  # X makedepend
634c19de146Smrg  shift
6359ef7378bSmrg  cleared=no eat=no
6369ef7378bSmrg  for arg
6379ef7378bSmrg  do
638c19de146Smrg    case $cleared in
639c19de146Smrg    no)
640c19de146Smrg      set ""; shift
641c19de146Smrg      cleared=yes ;;
642c19de146Smrg    esac
6439ef7378bSmrg    if test $eat = yes; then
6449ef7378bSmrg      eat=no
6459ef7378bSmrg      continue
6469ef7378bSmrg    fi
647c19de146Smrg    case "$arg" in
648c19de146Smrg    -D*|-I*)
649c19de146Smrg      set fnord "$@" "$arg"; shift ;;
650c19de146Smrg    # Strip any option that makedepend may not understand.  Remove
651c19de146Smrg    # the object too, otherwise makedepend will parse it as a source file.
6529ef7378bSmrg    -arch)
6539ef7378bSmrg      eat=yes ;;
654c19de146Smrg    -*|$object)
655c19de146Smrg      ;;
656c19de146Smrg    *)
657c19de146Smrg      set fnord "$@" "$arg"; shift ;;
658c19de146Smrg    esac
659c19de146Smrg  done
6609ef7378bSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661c19de146Smrg  touch "$tmpdepfile"
662c19de146Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663c19de146Smrg  rm -f "$depfile"
664a39bb051Smrg  # makedepend may prepend the VPATH from the source file name to the object.
665a39bb051Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666a39bb051Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667a39bb051Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668a39bb051Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
669a39bb051Smrg  sed '1,2d' "$tmpdepfile" \
670a39bb051Smrg    | tr ' ' "$nl" \
671a39bb051Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672a39bb051Smrg    | sed -e 's/$/ :/' >> "$depfile"
673c19de146Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674c19de146Smrg  ;;
675c19de146Smrg
676c19de146Smrgcpp)
677c19de146Smrg  # Important note: in order to support this mode, a compiler *must*
678c19de146Smrg  # always write the preprocessed file to stdout.
679c19de146Smrg  "$@" || exit $?
680c19de146Smrg
681c19de146Smrg  # Remove the call to Libtool.
682c19de146Smrg  if test "$libtool" = yes; then
6839ef7378bSmrg    while test "X$1" != 'X--mode=compile'; do
684c19de146Smrg      shift
685c19de146Smrg    done
686c19de146Smrg    shift
687c19de146Smrg  fi
688c19de146Smrg
689a39bb051Smrg  # Remove '-o $object'.
690c19de146Smrg  IFS=" "
691c19de146Smrg  for arg
692c19de146Smrg  do
693c19de146Smrg    case $arg in
694c19de146Smrg    -o)
695c19de146Smrg      shift
696c19de146Smrg      ;;
697c19de146Smrg    $object)
698c19de146Smrg      shift
699c19de146Smrg      ;;
700c19de146Smrg    *)
701c19de146Smrg      set fnord "$@" "$arg"
702c19de146Smrg      shift # fnord
703c19de146Smrg      shift # $arg
704c19de146Smrg      ;;
705c19de146Smrg    esac
706c19de146Smrg  done
707c19de146Smrg
708a39bb051Smrg  "$@" -E \
709a39bb051Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710a39bb051Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711a39bb051Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
712c19de146Smrg  rm -f "$depfile"
713c19de146Smrg  echo "$object : \\" > "$depfile"
714c19de146Smrg  cat < "$tmpdepfile" >> "$depfile"
715c19de146Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716c19de146Smrg  rm -f "$tmpdepfile"
717c19de146Smrg  ;;
718c19de146Smrg
719c19de146Smrgmsvisualcpp)
720c19de146Smrg  # Important note: in order to support this mode, a compiler *must*
7219ef7378bSmrg  # always write the preprocessed file to stdout.
722c19de146Smrg  "$@" || exit $?
7239ef7378bSmrg
7249ef7378bSmrg  # Remove the call to Libtool.
7259ef7378bSmrg  if test "$libtool" = yes; then
7269ef7378bSmrg    while test "X$1" != 'X--mode=compile'; do
7279ef7378bSmrg      shift
7289ef7378bSmrg    done
7299ef7378bSmrg    shift
7309ef7378bSmrg  fi
7319ef7378bSmrg
732c19de146Smrg  IFS=" "
733c19de146Smrg  for arg
734c19de146Smrg  do
735c19de146Smrg    case "$arg" in
7369ef7378bSmrg    -o)
7379ef7378bSmrg      shift
7389ef7378bSmrg      ;;
7399ef7378bSmrg    $object)
7409ef7378bSmrg      shift
7419ef7378bSmrg      ;;
742c19de146Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743a39bb051Smrg        set fnord "$@"
744a39bb051Smrg        shift
745a39bb051Smrg        shift
746a39bb051Smrg        ;;
747c19de146Smrg    *)
748a39bb051Smrg        set fnord "$@" "$arg"
749a39bb051Smrg        shift
750a39bb051Smrg        shift
751a39bb051Smrg        ;;
752c19de146Smrg    esac
753c19de146Smrg  done
7549ef7378bSmrg  "$@" -E 2>/dev/null |
7559ef7378bSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756c19de146Smrg  rm -f "$depfile"
757c19de146Smrg  echo "$object : \\" > "$depfile"
758a39bb051Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759a39bb051Smrg  echo "$tab" >> "$depfile"
7609ef7378bSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761c19de146Smrg  rm -f "$tmpdepfile"
762c19de146Smrg  ;;
763c19de146Smrg
7649ef7378bSmrgmsvcmsys)
7659ef7378bSmrg  # This case exists only to let depend.m4 do its work.  It works by
7669ef7378bSmrg  # looking at the text of this script.  This case will never be run,
7679ef7378bSmrg  # since it is checked for above.
7689ef7378bSmrg  exit 1
7699ef7378bSmrg  ;;
7709ef7378bSmrg
771c19de146Smrgnone)
772c19de146Smrg  exec "$@"
773c19de146Smrg  ;;
774c19de146Smrg
775c19de146Smrg*)
776c19de146Smrg  echo "Unknown depmode $depmode" 1>&2
777c19de146Smrg  exit 1
778c19de146Smrg  ;;
779c19de146Smrgesac
780c19de146Smrg
781c19de146Smrgexit 0
7829ef7378bSmrg
7839ef7378bSmrg# Local Variables:
7849ef7378bSmrg# mode: shell-script
7859ef7378bSmrg# sh-indentation: 2
7869ef7378bSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
7879ef7378bSmrg# time-stamp-start: "scriptversion="
7889ef7378bSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7899ef7378bSmrg# time-stamp-time-zone: "UTC"
7909ef7378bSmrg# time-stamp-end: "; # UTC"
7919ef7378bSmrg# End:
792