13e747e6dSmrg#! /bin/sh
23e747e6dSmrg# depcomp - compile a program generating dependencies as side-effects
33e747e6dSmrg
46d8e82c3Smrgscriptversion=2018-03-07.03; # UTC
53e747e6dSmrg
66d8e82c3Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
73e747e6dSmrg
83e747e6dSmrg# This program is free software; you can redistribute it and/or modify
93e747e6dSmrg# it under the terms of the GNU General Public License as published by
103e747e6dSmrg# the Free Software Foundation; either version 2, or (at your option)
113e747e6dSmrg# any later version.
123e747e6dSmrg
133e747e6dSmrg# This program is distributed in the hope that it will be useful,
143e747e6dSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
153e747e6dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
163e747e6dSmrg# GNU General Public License for more details.
173e747e6dSmrg
183e747e6dSmrg# You should have received a copy of the GNU General Public License
196d8e82c3Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
203e747e6dSmrg
213e747e6dSmrg# As a special exception to the GNU General Public License, if you
223e747e6dSmrg# distribute this file as part of a program that contains a
233e747e6dSmrg# configuration script generated by Autoconf, you may include it under
243e747e6dSmrg# the same distribution terms that you use for the rest of that program.
253e747e6dSmrg
263e747e6dSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
273e747e6dSmrg
283e747e6dSmrgcase $1 in
293e747e6dSmrg  '')
30c2535118Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31c2535118Smrg    exit 1;
32c2535118Smrg    ;;
333e747e6dSmrg  -h | --h*)
343e747e6dSmrg    cat <<\EOF
353e747e6dSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
363e747e6dSmrg
373e747e6dSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
383e747e6dSmrgas side-effects.
393e747e6dSmrg
403e747e6dSmrgEnvironment variables:
413e747e6dSmrg  depmode     Dependency tracking mode.
42c2535118Smrg  source      Source file read by 'PROGRAMS ARGS'.
43c2535118Smrg  object      Object file output by 'PROGRAMS ARGS'.
443e747e6dSmrg  DEPDIR      directory where to store dependencies.
453e747e6dSmrg  depfile     Dependency file to output.
46c2535118Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
473e747e6dSmrg  libtool     Whether libtool is used (yes/no).
483e747e6dSmrg
493e747e6dSmrgReport bugs to <bug-automake@gnu.org>.
503e747e6dSmrgEOF
513e747e6dSmrg    exit $?
523e747e6dSmrg    ;;
533e747e6dSmrg  -v | --v*)
543e747e6dSmrg    echo "depcomp $scriptversion"
553e747e6dSmrg    exit $?
563e747e6dSmrg    ;;
573e747e6dSmrgesac
583e747e6dSmrg
59c2535118Smrg# Get the directory component of the given path, and save it in the
60c2535118Smrg# global variables '$dir'.  Note that this directory component will
61c2535118Smrg# be either empty or ending with a '/' character.  This is deliberate.
62c2535118Smrgset_dir_from ()
63c2535118Smrg{
64c2535118Smrg  case $1 in
65c2535118Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66c2535118Smrg      *) dir=;;
67c2535118Smrg  esac
68c2535118Smrg}
69c2535118Smrg
70c2535118Smrg# Get the suffix-stripped basename of the given path, and save it the
71c2535118Smrg# global variable '$base'.
72c2535118Smrgset_base_from ()
73c2535118Smrg{
74c2535118Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75c2535118Smrg}
76c2535118Smrg
77c2535118Smrg# If no dependency file was actually created by the compiler invocation,
78c2535118Smrg# we still have to create a dummy depfile, to avoid errors with the
79c2535118Smrg# Makefile "include basename.Plo" scheme.
80c2535118Smrgmake_dummy_depfile ()
81c2535118Smrg{
82c2535118Smrg  echo "#dummy" > "$depfile"
83c2535118Smrg}
84c2535118Smrg
85c2535118Smrg# Factor out some common post-processing of the generated depfile.
86c2535118Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87c2535118Smrgaix_post_process_depfile ()
88c2535118Smrg{
89c2535118Smrg  # If the compiler actually managed to produce a dependency file,
90c2535118Smrg  # post-process it.
91c2535118Smrg  if test -f "$tmpdepfile"; then
92c2535118Smrg    # Each line is of the form 'foo.o: dependency.h'.
93c2535118Smrg    # Do two passes, one to just change these to
94c2535118Smrg    #   $object: dependency.h
95c2535118Smrg    # and one to simply output
96c2535118Smrg    #   dependency.h:
97c2535118Smrg    # which is needed to avoid the deleted-header problem.
98c2535118Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99c2535118Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100c2535118Smrg    } > "$depfile"
101c2535118Smrg    rm -f "$tmpdepfile"
102c2535118Smrg  else
103c2535118Smrg    make_dummy_depfile
104c2535118Smrg  fi
105c2535118Smrg}
106c2535118Smrg
107c2535118Smrg# A tabulation character.
108c2535118Smrgtab='	'
109c2535118Smrg# A newline character.
110c2535118Smrgnl='
111c2535118Smrg'
112c2535118Smrg# Character ranges might be problematic outside the C locale.
113c2535118Smrg# These definitions help.
114c2535118Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115c2535118Smrglower=abcdefghijklmnopqrstuvwxyz
116c2535118Smrgdigits=0123456789
117c2535118Smrgalpha=${upper}${lower}
118c2535118Smrg
1193e747e6dSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1203e747e6dSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1213e747e6dSmrg  exit 1
1223e747e6dSmrgfi
1233e747e6dSmrg
1243e747e6dSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1253e747e6dSmrgdepfile=${depfile-`echo "$object" |
1263e747e6dSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1273e747e6dSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1283e747e6dSmrg
1293e747e6dSmrgrm -f "$tmpdepfile"
1303e747e6dSmrg
131c2535118Smrg# Avoid interferences from the environment.
132c2535118Smrggccflag= dashmflag=
133c2535118Smrg
1343e747e6dSmrg# Some modes work just like other modes, but use different flags.  We
1353e747e6dSmrg# parameterize here, but still list the modes in the big case below,
1363e747e6dSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1373e747e6dSmrg# here, because this file can only contain one case statement.
1383e747e6dSmrgif test "$depmode" = hp; then
1393e747e6dSmrg  # HP compiler uses -M and no extra arg.
1403e747e6dSmrg  gccflag=-M
1413e747e6dSmrg  depmode=gcc
1423e747e6dSmrgfi
1433e747e6dSmrg
1443e747e6dSmrgif test "$depmode" = dashXmstdout; then
145c2535118Smrg  # This is just like dashmstdout with a different argument.
146c2535118Smrg  dashmflag=-xM
147c2535118Smrg  depmode=dashmstdout
1483e747e6dSmrgfi
1493e747e6dSmrg
1507a2631fcSmrgcygpath_u="cygpath -u -f -"
1517a2631fcSmrgif test "$depmode" = msvcmsys; then
152c2535118Smrg  # This is just like msvisualcpp but w/o cygpath translation.
153c2535118Smrg  # Just convert the backslash-escaped backslashes to single forward
154c2535118Smrg  # slashes to satisfy depend.m4
155c2535118Smrg  cygpath_u='sed s,\\\\,/,g'
156c2535118Smrg  depmode=msvisualcpp
157c2535118Smrgfi
158c2535118Smrg
159c2535118Smrgif test "$depmode" = msvc7msys; then
160c2535118Smrg  # This is just like msvc7 but w/o cygpath translation.
161c2535118Smrg  # Just convert the backslash-escaped backslashes to single forward
162c2535118Smrg  # slashes to satisfy depend.m4
163c2535118Smrg  cygpath_u='sed s,\\\\,/,g'
164c2535118Smrg  depmode=msvc7
165c2535118Smrgfi
166c2535118Smrg
167c2535118Smrgif test "$depmode" = xlc; then
168c2535118Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169c2535118Smrg  gccflag=-qmakedep=gcc,-MF
170c2535118Smrg  depmode=gcc
1717a2631fcSmrgfi
1727a2631fcSmrg
1733e747e6dSmrgcase "$depmode" in
1743e747e6dSmrggcc3)
1753e747e6dSmrg## gcc 3 implements dependency tracking that does exactly what
1763e747e6dSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1773e747e6dSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1783e747e6dSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1793e747e6dSmrg## the command line argument order; so add the flags where they
1803e747e6dSmrg## appear in depend2.am.  Note that the slowdown incurred here
1813e747e6dSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1823e747e6dSmrg  for arg
1833e747e6dSmrg  do
1843e747e6dSmrg    case $arg in
1853e747e6dSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1863e747e6dSmrg    *)  set fnord "$@" "$arg" ;;
1873e747e6dSmrg    esac
1883e747e6dSmrg    shift # fnord
1893e747e6dSmrg    shift # $arg
1903e747e6dSmrg  done
1913e747e6dSmrg  "$@"
1923e747e6dSmrg  stat=$?
193c2535118Smrg  if test $stat -ne 0; then
1943e747e6dSmrg    rm -f "$tmpdepfile"
1953e747e6dSmrg    exit $stat
1963e747e6dSmrg  fi
1973e747e6dSmrg  mv "$tmpdepfile" "$depfile"
1983e747e6dSmrg  ;;
1993e747e6dSmrg
2003e747e6dSmrggcc)
201c2535118Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202c2535118Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203c2535118Smrg## (see the conditional assignment to $gccflag above).
2043e747e6dSmrg## There are various ways to get dependency output from gcc.  Here's
2053e747e6dSmrg## why we pick this rather obscure method:
2063e747e6dSmrg## - Don't want to use -MD because we'd like the dependencies to end
2073e747e6dSmrg##   up in a subdir.  Having to rename by hand is ugly.
2083e747e6dSmrg##   (We might end up doing this anyway to support other compilers.)
2093e747e6dSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210c2535118Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211c2535118Smrg##   supported by the other compilers which use the 'gcc' depmode.
2123e747e6dSmrg## - Using -M directly means running the compiler twice (even worse
2133e747e6dSmrg##   than renaming).
2143e747e6dSmrg  if test -z "$gccflag"; then
2153e747e6dSmrg    gccflag=-MD,
2163e747e6dSmrg  fi
2173e747e6dSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
2183e747e6dSmrg  stat=$?
219c2535118Smrg  if test $stat -ne 0; then
2203e747e6dSmrg    rm -f "$tmpdepfile"
2213e747e6dSmrg    exit $stat
2223e747e6dSmrg  fi
2233e747e6dSmrg  rm -f "$depfile"
2243e747e6dSmrg  echo "$object : \\" > "$depfile"
225c2535118Smrg  # The second -e expression handles DOS-style file names with drive
226c2535118Smrg  # letters.
2273e747e6dSmrg  sed -e 's/^[^:]*: / /' \
2283e747e6dSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229c2535118Smrg## This next piece of magic avoids the "deleted header file" problem.
2303e747e6dSmrg## The problem is that when a header file which appears in a .P file
2313e747e6dSmrg## is deleted, the dependency causes make to die (because there is
2323e747e6dSmrg## typically no way to rebuild the header).  We avoid this by adding
2333e747e6dSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2343e747e6dSmrg## this for us directly.
235c2535118Smrg## Some versions of gcc put a space before the ':'.  On the theory
2363e747e6dSmrg## that the space means something, we add a space to the output as
237c2535118Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238c2535118Smrg## to the object.  Take care to not repeat it in the output.
2393e747e6dSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
2403e747e6dSmrg## correctly.  Breaking it into two sed invocations is a workaround.
241c2535118Smrg  tr ' ' "$nl" < "$tmpdepfile" \
242c2535118Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243c2535118Smrg    | sed -e 's/$/ :/' >> "$depfile"
2443e747e6dSmrg  rm -f "$tmpdepfile"
2453e747e6dSmrg  ;;
2463e747e6dSmrg
2473e747e6dSmrghp)
2483e747e6dSmrg  # This case exists only to let depend.m4 do its work.  It works by
2493e747e6dSmrg  # looking at the text of this script.  This case will never be run,
2503e747e6dSmrg  # since it is checked for above.
2513e747e6dSmrg  exit 1
2523e747e6dSmrg  ;;
2533e747e6dSmrg
2543e747e6dSmrgsgi)
2553e747e6dSmrg  if test "$libtool" = yes; then
2563e747e6dSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2573e747e6dSmrg  else
2583e747e6dSmrg    "$@" -MDupdate "$tmpdepfile"
2593e747e6dSmrg  fi
2603e747e6dSmrg  stat=$?
261c2535118Smrg  if test $stat -ne 0; then
2623e747e6dSmrg    rm -f "$tmpdepfile"
2633e747e6dSmrg    exit $stat
2643e747e6dSmrg  fi
2653e747e6dSmrg  rm -f "$depfile"
2663e747e6dSmrg
2673e747e6dSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2683e747e6dSmrg    echo "$object : \\" > "$depfile"
2693e747e6dSmrg    # Clip off the initial element (the dependent).  Don't try to be
2703e747e6dSmrg    # clever and replace this with sed code, as IRIX sed won't handle
2713e747e6dSmrg    # lines with more than a fixed number of characters (4096 in
2723e747e6dSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273c2535118Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
2743e747e6dSmrg    # dependency line.
275c2535118Smrg    tr ' ' "$nl" < "$tmpdepfile" \
276c2535118Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277c2535118Smrg      | tr "$nl" ' ' >> "$depfile"
2787a2631fcSmrg    echo >> "$depfile"
2793e747e6dSmrg    # The second pass generates a dummy entry for each header file.
280c2535118Smrg    tr ' ' "$nl" < "$tmpdepfile" \
281c2535118Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282c2535118Smrg      >> "$depfile"
2833e747e6dSmrg  else
284c2535118Smrg    make_dummy_depfile
2853e747e6dSmrg  fi
2863e747e6dSmrg  rm -f "$tmpdepfile"
2873e747e6dSmrg  ;;
2883e747e6dSmrg
289c2535118Smrgxlc)
290c2535118Smrg  # This case exists only to let depend.m4 do its work.  It works by
291c2535118Smrg  # looking at the text of this script.  This case will never be run,
292c2535118Smrg  # since it is checked for above.
293c2535118Smrg  exit 1
294c2535118Smrg  ;;
295c2535118Smrg
2963e747e6dSmrgaix)
2973e747e6dSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
2983e747e6dSmrg  # in a .u file.  In older versions, this file always lives in the
299c2535118Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3003e747e6dSmrg  # start of each line; $object doesn't have directory information.
3013e747e6dSmrg  # Version 6 uses the directory in both cases.
302c2535118Smrg  set_dir_from "$object"
303c2535118Smrg  set_base_from "$object"
3043e747e6dSmrg  if test "$libtool" = yes; then
3053e747e6dSmrg    tmpdepfile1=$dir$base.u
3063e747e6dSmrg    tmpdepfile2=$base.u
3073e747e6dSmrg    tmpdepfile3=$dir.libs/$base.u
3083e747e6dSmrg    "$@" -Wc,-M
3093e747e6dSmrg  else
3103e747e6dSmrg    tmpdepfile1=$dir$base.u
3113e747e6dSmrg    tmpdepfile2=$dir$base.u
3123e747e6dSmrg    tmpdepfile3=$dir$base.u
3133e747e6dSmrg    "$@" -M
3143e747e6dSmrg  fi
3153e747e6dSmrg  stat=$?
316c2535118Smrg  if test $stat -ne 0; then
3173e747e6dSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3183e747e6dSmrg    exit $stat
3193e747e6dSmrg  fi
3203e747e6dSmrg
3213e747e6dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3223e747e6dSmrg  do
3233e747e6dSmrg    test -f "$tmpdepfile" && break
3243e747e6dSmrg  done
325c2535118Smrg  aix_post_process_depfile
326c2535118Smrg  ;;
327c2535118Smrg
328c2535118Smrgtcc)
329c2535118Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330c2535118Smrg  # FIXME: That version still under development at the moment of writing.
331c2535118Smrg  #        Make that this statement remains true also for stable, released
332c2535118Smrg  #        versions.
333c2535118Smrg  # It will wrap lines (doesn't matter whether long or short) with a
334c2535118Smrg  # trailing '\', as in:
335c2535118Smrg  #
336c2535118Smrg  #   foo.o : \
337c2535118Smrg  #    foo.c \
338c2535118Smrg  #    foo.h \
339c2535118Smrg  #
340c2535118Smrg  # It will put a trailing '\' even on the last line, and will use leading
341c2535118Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342c2535118Smrg  # "Emit spaces for -MD").
343c2535118Smrg  "$@" -MD -MF "$tmpdepfile"
344c2535118Smrg  stat=$?
345c2535118Smrg  if test $stat -ne 0; then
346c2535118Smrg    rm -f "$tmpdepfile"
347c2535118Smrg    exit $stat
3483e747e6dSmrg  fi
349c2535118Smrg  rm -f "$depfile"
350c2535118Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351c2535118Smrg  # We have to change lines of the first kind to '$object: \'.
352c2535118Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353c2535118Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354c2535118Smrg  # dummy dependency, to avoid the deleted-header problem.
355c2535118Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3563e747e6dSmrg  rm -f "$tmpdepfile"
3573e747e6dSmrg  ;;
3583e747e6dSmrg
359c2535118Smrg## The order of this option in the case statement is important, since the
360c2535118Smrg## shell code in configure will try each of these formats in the order
361c2535118Smrg## listed in this file.  A plain '-MD' option would be understood by many
362c2535118Smrg## compilers, so we must ensure this comes after the gcc and icc options.
363c2535118Smrgpgcc)
364c2535118Smrg  # Portland's C compiler understands '-MD'.
365c2535118Smrg  # Will always output deps to 'file.d' where file is the root name of the
366c2535118Smrg  # source file under compilation, even if file resides in a subdirectory.
367c2535118Smrg  # The object file name does not affect the name of the '.d' file.
368c2535118Smrg  # pgcc 10.2 will output
3693e747e6dSmrg  #    foo.o: sub/foo.c sub/foo.h
370c2535118Smrg  # and will wrap long lines using '\' :
3713e747e6dSmrg  #    foo.o: sub/foo.c ... \
3723e747e6dSmrg  #     sub/foo.h ... \
3733e747e6dSmrg  #     ...
374c2535118Smrg  set_dir_from "$object"
375c2535118Smrg  # Use the source, not the object, to determine the base name, since
376c2535118Smrg  # that's sadly what pgcc will do too.
377c2535118Smrg  set_base_from "$source"
378c2535118Smrg  tmpdepfile=$base.d
379c2535118Smrg
380c2535118Smrg  # For projects that build the same source file twice into different object
381c2535118Smrg  # files, the pgcc approach of using the *source* file root name can cause
382c2535118Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383c2535118Smrg  # the same $tmpdepfile.
384c2535118Smrg  lockdir=$base.d-lock
385c2535118Smrg  trap "
386c2535118Smrg    echo '$0: caught signal, cleaning up...' >&2
387c2535118Smrg    rmdir '$lockdir'
388c2535118Smrg    exit 1
389c2535118Smrg  " 1 2 13 15
390c2535118Smrg  numtries=100
391c2535118Smrg  i=$numtries
392c2535118Smrg  while test $i -gt 0; do
393c2535118Smrg    # mkdir is a portable test-and-set.
394c2535118Smrg    if mkdir "$lockdir" 2>/dev/null; then
395c2535118Smrg      # This process acquired the lock.
396c2535118Smrg      "$@" -MD
397c2535118Smrg      stat=$?
398c2535118Smrg      # Release the lock.
399c2535118Smrg      rmdir "$lockdir"
400c2535118Smrg      break
401c2535118Smrg    else
402c2535118Smrg      # If the lock is being held by a different process, wait
403c2535118Smrg      # until the winning process is done or we timeout.
404c2535118Smrg      while test -d "$lockdir" && test $i -gt 0; do
405c2535118Smrg        sleep 1
406c2535118Smrg        i=`expr $i - 1`
407c2535118Smrg      done
408c2535118Smrg    fi
409c2535118Smrg    i=`expr $i - 1`
410c2535118Smrg  done
411c2535118Smrg  trap - 1 2 13 15
412c2535118Smrg  if test $i -le 0; then
413c2535118Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414c2535118Smrg    echo "$0: check lockdir '$lockdir'" >&2
415c2535118Smrg    exit 1
416c2535118Smrg  fi
4173e747e6dSmrg
418c2535118Smrg  if test $stat -ne 0; then
4193e747e6dSmrg    rm -f "$tmpdepfile"
4203e747e6dSmrg    exit $stat
4213e747e6dSmrg  fi
4223e747e6dSmrg  rm -f "$depfile"
4233e747e6dSmrg  # Each line is of the form `foo.o: dependent.h',
4243e747e6dSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4253e747e6dSmrg  # Do two passes, one to just change these to
4263e747e6dSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4273e747e6dSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4283e747e6dSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4293e747e6dSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
430c2535118Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431c2535118Smrg    | sed -e 's/$/ :/' >> "$depfile"
4323e747e6dSmrg  rm -f "$tmpdepfile"
4333e747e6dSmrg  ;;
4343e747e6dSmrg
4353e747e6dSmrghp2)
4363e747e6dSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4373e747e6dSmrg  # compilers, which have integrated preprocessors.  The correct option
4383e747e6dSmrg  # to use with these is +Maked; it writes dependencies to a file named
4393e747e6dSmrg  # 'foo.d', which lands next to the object file, wherever that
4403e747e6dSmrg  # happens to be.
4413e747e6dSmrg  # Much of this is similar to the tru64 case; see comments there.
442c2535118Smrg  set_dir_from  "$object"
443c2535118Smrg  set_base_from "$object"
4443e747e6dSmrg  if test "$libtool" = yes; then
4453e747e6dSmrg    tmpdepfile1=$dir$base.d
4463e747e6dSmrg    tmpdepfile2=$dir.libs/$base.d
4473e747e6dSmrg    "$@" -Wc,+Maked
4483e747e6dSmrg  else
4493e747e6dSmrg    tmpdepfile1=$dir$base.d
4503e747e6dSmrg    tmpdepfile2=$dir$base.d
4513e747e6dSmrg    "$@" +Maked
4523e747e6dSmrg  fi
4533e747e6dSmrg  stat=$?
454c2535118Smrg  if test $stat -ne 0; then
4553e747e6dSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4563e747e6dSmrg     exit $stat
4573e747e6dSmrg  fi
4583e747e6dSmrg
4593e747e6dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4603e747e6dSmrg  do
4613e747e6dSmrg    test -f "$tmpdepfile" && break
4623e747e6dSmrg  done
4633e747e6dSmrg  if test -f "$tmpdepfile"; then
464c2535118Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465c2535118Smrg    # Add 'dependent.h:' lines.
4667a2631fcSmrg    sed -ne '2,${
467c2535118Smrg               s/^ *//
468c2535118Smrg               s/ \\*$//
469c2535118Smrg               s/$/:/
470c2535118Smrg               p
471c2535118Smrg             }' "$tmpdepfile" >> "$depfile"
4723e747e6dSmrg  else
473c2535118Smrg    make_dummy_depfile
4743e747e6dSmrg  fi
4753e747e6dSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4763e747e6dSmrg  ;;
4773e747e6dSmrg
4783e747e6dSmrgtru64)
479c2535118Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480c2535118Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481c2535118Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482c2535118Smrg  # dependencies in 'foo.d' instead, so we check for that too.
483c2535118Smrg  # Subdirectories are respected.
484c2535118Smrg  set_dir_from  "$object"
485c2535118Smrg  set_base_from "$object"
486c2535118Smrg
487c2535118Smrg  if test "$libtool" = yes; then
488c2535118Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489c2535118Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490c2535118Smrg    # in $dir$base.o.d.  We have to check for both files, because
491c2535118Smrg    # one of the two compilations can be disabled.  We should prefer
492c2535118Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493c2535118Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
494c2535118Smrg    # the former would cause a distcleancheck panic.
495c2535118Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496c2535118Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497c2535118Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498c2535118Smrg    "$@" -Wc,-MD
499c2535118Smrg  else
500c2535118Smrg    tmpdepfile1=$dir$base.d
501c2535118Smrg    tmpdepfile2=$dir$base.d
502c2535118Smrg    tmpdepfile3=$dir$base.d
503c2535118Smrg    "$@" -MD
504c2535118Smrg  fi
505c2535118Smrg
506c2535118Smrg  stat=$?
507c2535118Smrg  if test $stat -ne 0; then
508c2535118Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509c2535118Smrg    exit $stat
510c2535118Smrg  fi
511c2535118Smrg
512c2535118Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513c2535118Smrg  do
514c2535118Smrg    test -f "$tmpdepfile" && break
515c2535118Smrg  done
516c2535118Smrg  # Same post-processing that is required for AIX mode.
517c2535118Smrg  aix_post_process_depfile
518c2535118Smrg  ;;
519c2535118Smrg
520c2535118Smrgmsvc7)
521c2535118Smrg  if test "$libtool" = yes; then
522c2535118Smrg    showIncludes=-Wc,-showIncludes
523c2535118Smrg  else
524c2535118Smrg    showIncludes=-showIncludes
525c2535118Smrg  fi
526c2535118Smrg  "$@" $showIncludes > "$tmpdepfile"
527c2535118Smrg  stat=$?
528c2535118Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
529c2535118Smrg  if test $stat -ne 0; then
530c2535118Smrg    rm -f "$tmpdepfile"
531c2535118Smrg    exit $stat
532c2535118Smrg  fi
533c2535118Smrg  rm -f "$depfile"
534c2535118Smrg  echo "$object : \\" > "$depfile"
535c2535118Smrg  # The first sed program below extracts the file names and escapes
536c2535118Smrg  # backslashes for cygpath.  The second sed program outputs the file
537c2535118Smrg  # name when reading, but also accumulates all include files in the
538c2535118Smrg  # hold buffer in order to output them again at the end.  This only
539c2535118Smrg  # works with sed implementations that can handle large buffers.
540c2535118Smrg  sed < "$tmpdepfile" -n '
541c2535118Smrg/^Note: including file:  *\(.*\)/ {
542c2535118Smrg  s//\1/
543c2535118Smrg  s/\\/\\\\/g
544c2535118Smrg  p
545c2535118Smrg}' | $cygpath_u | sort -u | sed -n '
546c2535118Smrgs/ /\\ /g
547c2535118Smrgs/\(.*\)/'"$tab"'\1 \\/p
548c2535118Smrgs/.\(.*\) \\/\1:/
549c2535118SmrgH
550c2535118Smrg$ {
551c2535118Smrg  s/.*/'"$tab"'/
552c2535118Smrg  G
553c2535118Smrg  p
554c2535118Smrg}' >> "$depfile"
555c2535118Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556c2535118Smrg  rm -f "$tmpdepfile"
557c2535118Smrg  ;;
558c2535118Smrg
559c2535118Smrgmsvc7msys)
560c2535118Smrg  # This case exists only to let depend.m4 do its work.  It works by
561c2535118Smrg  # looking at the text of this script.  This case will never be run,
562c2535118Smrg  # since it is checked for above.
563c2535118Smrg  exit 1
564c2535118Smrg  ;;
5653e747e6dSmrg
5663e747e6dSmrg#nosideeffect)
5673e747e6dSmrg  # This comment above is used by automake to tell side-effect
5683e747e6dSmrg  # dependency tracking mechanisms from slower ones.
5693e747e6dSmrg
5703e747e6dSmrgdashmstdout)
5713e747e6dSmrg  # Important note: in order to support this mode, a compiler *must*
5723e747e6dSmrg  # always write the preprocessed file to stdout, regardless of -o.
5733e747e6dSmrg  "$@" || exit $?
5743e747e6dSmrg
5753e747e6dSmrg  # Remove the call to Libtool.
5763e747e6dSmrg  if test "$libtool" = yes; then
5777a2631fcSmrg    while test "X$1" != 'X--mode=compile'; do
5783e747e6dSmrg      shift
5793e747e6dSmrg    done
5803e747e6dSmrg    shift
5813e747e6dSmrg  fi
5823e747e6dSmrg
583c2535118Smrg  # Remove '-o $object'.
5843e747e6dSmrg  IFS=" "
5853e747e6dSmrg  for arg
5863e747e6dSmrg  do
5873e747e6dSmrg    case $arg in
5883e747e6dSmrg    -o)
5893e747e6dSmrg      shift
5903e747e6dSmrg      ;;
5913e747e6dSmrg    $object)
5923e747e6dSmrg      shift
5933e747e6dSmrg      ;;
5943e747e6dSmrg    *)
5953e747e6dSmrg      set fnord "$@" "$arg"
5963e747e6dSmrg      shift # fnord
5973e747e6dSmrg      shift # $arg
5983e747e6dSmrg      ;;
5993e747e6dSmrg    esac
6003e747e6dSmrg  done
6013e747e6dSmrg
6023e747e6dSmrg  test -z "$dashmflag" && dashmflag=-M
603c2535118Smrg  # Require at least two characters before searching for ':'
6043e747e6dSmrg  # in the target name.  This is to cope with DOS-style filenames:
605c2535118Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6063e747e6dSmrg  "$@" $dashmflag |
607c2535118Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6083e747e6dSmrg  rm -f "$depfile"
6093e747e6dSmrg  cat < "$tmpdepfile" > "$depfile"
610c2535118Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611c2535118Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
612c2535118Smrg  tr ' ' "$nl" < "$tmpdepfile" \
613c2535118Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614c2535118Smrg    | sed -e 's/$/ :/' >> "$depfile"
6153e747e6dSmrg  rm -f "$tmpdepfile"
6163e747e6dSmrg  ;;
6173e747e6dSmrg
6183e747e6dSmrgdashXmstdout)
6193e747e6dSmrg  # This case only exists to satisfy depend.m4.  It is never actually
6203e747e6dSmrg  # run, as this mode is specially recognized in the preamble.
6213e747e6dSmrg  exit 1
6223e747e6dSmrg  ;;
6233e747e6dSmrg
6243e747e6dSmrgmakedepend)
6253e747e6dSmrg  "$@" || exit $?
6263e747e6dSmrg  # Remove any Libtool call
6273e747e6dSmrg  if test "$libtool" = yes; then
6287a2631fcSmrg    while test "X$1" != 'X--mode=compile'; do
6293e747e6dSmrg      shift
6303e747e6dSmrg    done
6313e747e6dSmrg    shift
6323e747e6dSmrg  fi
6333e747e6dSmrg  # X makedepend
6343e747e6dSmrg  shift
6357a2631fcSmrg  cleared=no eat=no
6367a2631fcSmrg  for arg
6377a2631fcSmrg  do
6383e747e6dSmrg    case $cleared in
6393e747e6dSmrg    no)
6403e747e6dSmrg      set ""; shift
6413e747e6dSmrg      cleared=yes ;;
6423e747e6dSmrg    esac
6437a2631fcSmrg    if test $eat = yes; then
6447a2631fcSmrg      eat=no
6457a2631fcSmrg      continue
6467a2631fcSmrg    fi
6473e747e6dSmrg    case "$arg" in
6483e747e6dSmrg    -D*|-I*)
6493e747e6dSmrg      set fnord "$@" "$arg"; shift ;;
6503e747e6dSmrg    # Strip any option that makedepend may not understand.  Remove
6513e747e6dSmrg    # the object too, otherwise makedepend will parse it as a source file.
6527a2631fcSmrg    -arch)
6537a2631fcSmrg      eat=yes ;;
6543e747e6dSmrg    -*|$object)
6553e747e6dSmrg      ;;
6563e747e6dSmrg    *)
6573e747e6dSmrg      set fnord "$@" "$arg"; shift ;;
6583e747e6dSmrg    esac
6593e747e6dSmrg  done
6607a2631fcSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6613e747e6dSmrg  touch "$tmpdepfile"
6623e747e6dSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6633e747e6dSmrg  rm -f "$depfile"
664c2535118Smrg  # makedepend may prepend the VPATH from the source file name to the object.
665c2535118Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666c2535118Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667c2535118Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668c2535118Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
669c2535118Smrg  sed '1,2d' "$tmpdepfile" \
670c2535118Smrg    | tr ' ' "$nl" \
671c2535118Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672c2535118Smrg    | sed -e 's/$/ :/' >> "$depfile"
6733e747e6dSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6743e747e6dSmrg  ;;
6753e747e6dSmrg
6763e747e6dSmrgcpp)
6773e747e6dSmrg  # Important note: in order to support this mode, a compiler *must*
6783e747e6dSmrg  # always write the preprocessed file to stdout.
6793e747e6dSmrg  "$@" || exit $?
6803e747e6dSmrg
6813e747e6dSmrg  # Remove the call to Libtool.
6823e747e6dSmrg  if test "$libtool" = yes; then
6837a2631fcSmrg    while test "X$1" != 'X--mode=compile'; do
6843e747e6dSmrg      shift
6853e747e6dSmrg    done
6863e747e6dSmrg    shift
6873e747e6dSmrg  fi
6883e747e6dSmrg
689c2535118Smrg  # Remove '-o $object'.
6903e747e6dSmrg  IFS=" "
6913e747e6dSmrg  for arg
6923e747e6dSmrg  do
6933e747e6dSmrg    case $arg in
6943e747e6dSmrg    -o)
6953e747e6dSmrg      shift
6963e747e6dSmrg      ;;
6973e747e6dSmrg    $object)
6983e747e6dSmrg      shift
6993e747e6dSmrg      ;;
7003e747e6dSmrg    *)
7013e747e6dSmrg      set fnord "$@" "$arg"
7023e747e6dSmrg      shift # fnord
7033e747e6dSmrg      shift # $arg
7043e747e6dSmrg      ;;
7053e747e6dSmrg    esac
7063e747e6dSmrg  done
7073e747e6dSmrg
708c2535118Smrg  "$@" -E \
709c2535118Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710c2535118Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711c2535118Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
7123e747e6dSmrg  rm -f "$depfile"
7133e747e6dSmrg  echo "$object : \\" > "$depfile"
7143e747e6dSmrg  cat < "$tmpdepfile" >> "$depfile"
7153e747e6dSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7163e747e6dSmrg  rm -f "$tmpdepfile"
7173e747e6dSmrg  ;;
7183e747e6dSmrg
7193e747e6dSmrgmsvisualcpp)
7203e747e6dSmrg  # Important note: in order to support this mode, a compiler *must*
7217a2631fcSmrg  # always write the preprocessed file to stdout.
7223e747e6dSmrg  "$@" || exit $?
7237a2631fcSmrg
7247a2631fcSmrg  # Remove the call to Libtool.
7257a2631fcSmrg  if test "$libtool" = yes; then
7267a2631fcSmrg    while test "X$1" != 'X--mode=compile'; do
7277a2631fcSmrg      shift
7287a2631fcSmrg    done
7297a2631fcSmrg    shift
7307a2631fcSmrg  fi
7317a2631fcSmrg
7323e747e6dSmrg  IFS=" "
7333e747e6dSmrg  for arg
7343e747e6dSmrg  do
7353e747e6dSmrg    case "$arg" in
7367a2631fcSmrg    -o)
7377a2631fcSmrg      shift
7387a2631fcSmrg      ;;
7397a2631fcSmrg    $object)
7407a2631fcSmrg      shift
7417a2631fcSmrg      ;;
7423e747e6dSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743c2535118Smrg        set fnord "$@"
744c2535118Smrg        shift
745c2535118Smrg        shift
746c2535118Smrg        ;;
7473e747e6dSmrg    *)
748c2535118Smrg        set fnord "$@" "$arg"
749c2535118Smrg        shift
750c2535118Smrg        shift
751c2535118Smrg        ;;
7523e747e6dSmrg    esac
7533e747e6dSmrg  done
7547a2631fcSmrg  "$@" -E 2>/dev/null |
7557a2631fcSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7563e747e6dSmrg  rm -f "$depfile"
7573e747e6dSmrg  echo "$object : \\" > "$depfile"
758c2535118Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759c2535118Smrg  echo "$tab" >> "$depfile"
7607a2631fcSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7613e747e6dSmrg  rm -f "$tmpdepfile"
7623e747e6dSmrg  ;;
7633e747e6dSmrg
7647a2631fcSmrgmsvcmsys)
7657a2631fcSmrg  # This case exists only to let depend.m4 do its work.  It works by
7667a2631fcSmrg  # looking at the text of this script.  This case will never be run,
7677a2631fcSmrg  # since it is checked for above.
7687a2631fcSmrg  exit 1
7697a2631fcSmrg  ;;
7707a2631fcSmrg
7713e747e6dSmrgnone)
7723e747e6dSmrg  exec "$@"
7733e747e6dSmrg  ;;
7743e747e6dSmrg
7753e747e6dSmrg*)
7763e747e6dSmrg  echo "Unknown depmode $depmode" 1>&2
7773e747e6dSmrg  exit 1
7783e747e6dSmrg  ;;
7793e747e6dSmrgesac
7803e747e6dSmrg
7813e747e6dSmrgexit 0
7823e747e6dSmrg
7833e747e6dSmrg# Local Variables:
7843e747e6dSmrg# mode: shell-script
7853e747e6dSmrg# sh-indentation: 2
7866d8e82c3Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
7873e747e6dSmrg# time-stamp-start: "scriptversion="
7883e747e6dSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7896d8e82c3Smrg# time-stamp-time-zone: "UTC0"
7907a2631fcSmrg# time-stamp-end: "; # UTC"
7913e747e6dSmrg# End:
792