16c321187Smrg#! /bin/sh
26c321187Smrg# depcomp - compile a program generating dependencies as side-effects
36c321187Smrg
49dedec0cSmrgscriptversion=2018-03-07.03; # UTC
56c321187Smrg
69dedec0cSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
76c321187Smrg
86c321187Smrg# This program is free software; you can redistribute it and/or modify
96c321187Smrg# it under the terms of the GNU General Public License as published by
106c321187Smrg# the Free Software Foundation; either version 2, or (at your option)
116c321187Smrg# any later version.
126c321187Smrg
136c321187Smrg# This program is distributed in the hope that it will be useful,
146c321187Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
156c321187Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
166c321187Smrg# GNU General Public License for more details.
176c321187Smrg
186c321187Smrg# You should have received a copy of the GNU General Public License
199dedec0cSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
206c321187Smrg
216c321187Smrg# As a special exception to the GNU General Public License, if you
226c321187Smrg# distribute this file as part of a program that contains a
236c321187Smrg# configuration script generated by Autoconf, you may include it under
246c321187Smrg# the same distribution terms that you use for the rest of that program.
256c321187Smrg
266c321187Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
276c321187Smrg
286c321187Smrgcase $1 in
296c321187Smrg  '')
309d0b5e55Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
319d0b5e55Smrg    exit 1;
329d0b5e55Smrg    ;;
336c321187Smrg  -h | --h*)
346c321187Smrg    cat <<\EOF
356c321187SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
366c321187Smrg
376c321187SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
386c321187Smrgas side-effects.
396c321187Smrg
406c321187SmrgEnvironment variables:
416c321187Smrg  depmode     Dependency tracking mode.
429d0b5e55Smrg  source      Source file read by 'PROGRAMS ARGS'.
439d0b5e55Smrg  object      Object file output by 'PROGRAMS ARGS'.
446c321187Smrg  DEPDIR      directory where to store dependencies.
456c321187Smrg  depfile     Dependency file to output.
469d0b5e55Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
476c321187Smrg  libtool     Whether libtool is used (yes/no).
486c321187Smrg
496c321187SmrgReport bugs to <bug-automake@gnu.org>.
506c321187SmrgEOF
516c321187Smrg    exit $?
526c321187Smrg    ;;
536c321187Smrg  -v | --v*)
546c321187Smrg    echo "depcomp $scriptversion"
556c321187Smrg    exit $?
566c321187Smrg    ;;
576c321187Smrgesac
586c321187Smrg
599d0b5e55Smrg# Get the directory component of the given path, and save it in the
609d0b5e55Smrg# global variables '$dir'.  Note that this directory component will
619d0b5e55Smrg# be either empty or ending with a '/' character.  This is deliberate.
629d0b5e55Smrgset_dir_from ()
639d0b5e55Smrg{
649d0b5e55Smrg  case $1 in
659d0b5e55Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
669d0b5e55Smrg      *) dir=;;
679d0b5e55Smrg  esac
689d0b5e55Smrg}
699d0b5e55Smrg
709d0b5e55Smrg# Get the suffix-stripped basename of the given path, and save it the
719d0b5e55Smrg# global variable '$base'.
729d0b5e55Smrgset_base_from ()
739d0b5e55Smrg{
749d0b5e55Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
759d0b5e55Smrg}
769d0b5e55Smrg
779d0b5e55Smrg# If no dependency file was actually created by the compiler invocation,
789d0b5e55Smrg# we still have to create a dummy depfile, to avoid errors with the
799d0b5e55Smrg# Makefile "include basename.Plo" scheme.
809d0b5e55Smrgmake_dummy_depfile ()
819d0b5e55Smrg{
829d0b5e55Smrg  echo "#dummy" > "$depfile"
839d0b5e55Smrg}
849d0b5e55Smrg
859d0b5e55Smrg# Factor out some common post-processing of the generated depfile.
869d0b5e55Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
879d0b5e55Smrgaix_post_process_depfile ()
889d0b5e55Smrg{
899d0b5e55Smrg  # If the compiler actually managed to produce a dependency file,
909d0b5e55Smrg  # post-process it.
919d0b5e55Smrg  if test -f "$tmpdepfile"; then
929d0b5e55Smrg    # Each line is of the form 'foo.o: dependency.h'.
939d0b5e55Smrg    # Do two passes, one to just change these to
949d0b5e55Smrg    #   $object: dependency.h
959d0b5e55Smrg    # and one to simply output
969d0b5e55Smrg    #   dependency.h:
979d0b5e55Smrg    # which is needed to avoid the deleted-header problem.
989d0b5e55Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
999d0b5e55Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1009d0b5e55Smrg    } > "$depfile"
1019d0b5e55Smrg    rm -f "$tmpdepfile"
1029d0b5e55Smrg  else
1039d0b5e55Smrg    make_dummy_depfile
1049d0b5e55Smrg  fi
1059d0b5e55Smrg}
1069d0b5e55Smrg
1079d0b5e55Smrg# A tabulation character.
1089d0b5e55Smrgtab='	'
1099d0b5e55Smrg# A newline character.
1109d0b5e55Smrgnl='
1119d0b5e55Smrg'
1129d0b5e55Smrg# Character ranges might be problematic outside the C locale.
1139d0b5e55Smrg# These definitions help.
1149d0b5e55Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1159d0b5e55Smrglower=abcdefghijklmnopqrstuvwxyz
1169d0b5e55Smrgdigits=0123456789
1179d0b5e55Smrgalpha=${upper}${lower}
1189d0b5e55Smrg
1196c321187Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1206c321187Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1216c321187Smrg  exit 1
1226c321187Smrgfi
1236c321187Smrg
1246c321187Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1256c321187Smrgdepfile=${depfile-`echo "$object" |
1266c321187Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1276c321187Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1286c321187Smrg
1296c321187Smrgrm -f "$tmpdepfile"
1306c321187Smrg
1319d0b5e55Smrg# Avoid interferences from the environment.
1329d0b5e55Smrggccflag= dashmflag=
1339d0b5e55Smrg
1346c321187Smrg# Some modes work just like other modes, but use different flags.  We
1356c321187Smrg# parameterize here, but still list the modes in the big case below,
1366c321187Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1376c321187Smrg# here, because this file can only contain one case statement.
1386c321187Smrgif test "$depmode" = hp; then
1396c321187Smrg  # HP compiler uses -M and no extra arg.
1406c321187Smrg  gccflag=-M
1416c321187Smrg  depmode=gcc
1426c321187Smrgfi
1436c321187Smrg
1446c321187Smrgif test "$depmode" = dashXmstdout; then
1459d0b5e55Smrg  # This is just like dashmstdout with a different argument.
1469d0b5e55Smrg  dashmflag=-xM
1479d0b5e55Smrg  depmode=dashmstdout
1486c321187Smrgfi
1496c321187Smrg
15093493779Smrgcygpath_u="cygpath -u -f -"
15193493779Smrgif test "$depmode" = msvcmsys; then
1529d0b5e55Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1539d0b5e55Smrg  # Just convert the backslash-escaped backslashes to single forward
1549d0b5e55Smrg  # slashes to satisfy depend.m4
1559d0b5e55Smrg  cygpath_u='sed s,\\\\,/,g'
1569d0b5e55Smrg  depmode=msvisualcpp
1579d0b5e55Smrgfi
1589d0b5e55Smrg
1599d0b5e55Smrgif test "$depmode" = msvc7msys; then
1609d0b5e55Smrg  # This is just like msvc7 but w/o cygpath translation.
1619d0b5e55Smrg  # Just convert the backslash-escaped backslashes to single forward
1629d0b5e55Smrg  # slashes to satisfy depend.m4
1639d0b5e55Smrg  cygpath_u='sed s,\\\\,/,g'
1649d0b5e55Smrg  depmode=msvc7
1659d0b5e55Smrgfi
1669d0b5e55Smrg
1679d0b5e55Smrgif test "$depmode" = xlc; then
1689d0b5e55Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1699d0b5e55Smrg  gccflag=-qmakedep=gcc,-MF
1709d0b5e55Smrg  depmode=gcc
17193493779Smrgfi
17293493779Smrg
1736c321187Smrgcase "$depmode" in
1746c321187Smrggcc3)
1756c321187Smrg## gcc 3 implements dependency tracking that does exactly what
1766c321187Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1776c321187Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1786c321187Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1796c321187Smrg## the command line argument order; so add the flags where they
1806c321187Smrg## appear in depend2.am.  Note that the slowdown incurred here
1816c321187Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1826c321187Smrg  for arg
1836c321187Smrg  do
1846c321187Smrg    case $arg in
1856c321187Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1866c321187Smrg    *)  set fnord "$@" "$arg" ;;
1876c321187Smrg    esac
1886c321187Smrg    shift # fnord
1896c321187Smrg    shift # $arg
1906c321187Smrg  done
1916c321187Smrg  "$@"
1926c321187Smrg  stat=$?
1939d0b5e55Smrg  if test $stat -ne 0; then
1946c321187Smrg    rm -f "$tmpdepfile"
1956c321187Smrg    exit $stat
1966c321187Smrg  fi
1976c321187Smrg  mv "$tmpdepfile" "$depfile"
1986c321187Smrg  ;;
1996c321187Smrg
2006c321187Smrggcc)
2019d0b5e55Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2029d0b5e55Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2039d0b5e55Smrg## (see the conditional assignment to $gccflag above).
2046c321187Smrg## There are various ways to get dependency output from gcc.  Here's
2056c321187Smrg## why we pick this rather obscure method:
2066c321187Smrg## - Don't want to use -MD because we'd like the dependencies to end
2076c321187Smrg##   up in a subdir.  Having to rename by hand is ugly.
2086c321187Smrg##   (We might end up doing this anyway to support other compilers.)
2096c321187Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2109d0b5e55Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2119d0b5e55Smrg##   supported by the other compilers which use the 'gcc' depmode.
2126c321187Smrg## - Using -M directly means running the compiler twice (even worse
2136c321187Smrg##   than renaming).
2146c321187Smrg  if test -z "$gccflag"; then
2156c321187Smrg    gccflag=-MD,
2166c321187Smrg  fi
2176c321187Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
2186c321187Smrg  stat=$?
2199d0b5e55Smrg  if test $stat -ne 0; then
2206c321187Smrg    rm -f "$tmpdepfile"
2216c321187Smrg    exit $stat
2226c321187Smrg  fi
2236c321187Smrg  rm -f "$depfile"
2246c321187Smrg  echo "$object : \\" > "$depfile"
2259d0b5e55Smrg  # The second -e expression handles DOS-style file names with drive
2269d0b5e55Smrg  # letters.
2276c321187Smrg  sed -e 's/^[^:]*: / /' \
2286c321187Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2299d0b5e55Smrg## This next piece of magic avoids the "deleted header file" problem.
2306c321187Smrg## The problem is that when a header file which appears in a .P file
2316c321187Smrg## is deleted, the dependency causes make to die (because there is
2326c321187Smrg## typically no way to rebuild the header).  We avoid this by adding
2336c321187Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2346c321187Smrg## this for us directly.
2359d0b5e55Smrg## Some versions of gcc put a space before the ':'.  On the theory
2366c321187Smrg## that the space means something, we add a space to the output as
2379d0b5e55Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2389d0b5e55Smrg## to the object.  Take care to not repeat it in the output.
2396c321187Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
2406c321187Smrg## correctly.  Breaking it into two sed invocations is a workaround.
2419d0b5e55Smrg  tr ' ' "$nl" < "$tmpdepfile" \
2429d0b5e55Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2439d0b5e55Smrg    | sed -e 's/$/ :/' >> "$depfile"
2446c321187Smrg  rm -f "$tmpdepfile"
2456c321187Smrg  ;;
2466c321187Smrg
2476c321187Smrghp)
2486c321187Smrg  # This case exists only to let depend.m4 do its work.  It works by
2496c321187Smrg  # looking at the text of this script.  This case will never be run,
2506c321187Smrg  # since it is checked for above.
2516c321187Smrg  exit 1
2526c321187Smrg  ;;
2536c321187Smrg
2546c321187Smrgsgi)
2556c321187Smrg  if test "$libtool" = yes; then
2566c321187Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2576c321187Smrg  else
2586c321187Smrg    "$@" -MDupdate "$tmpdepfile"
2596c321187Smrg  fi
2606c321187Smrg  stat=$?
2619d0b5e55Smrg  if test $stat -ne 0; then
2626c321187Smrg    rm -f "$tmpdepfile"
2636c321187Smrg    exit $stat
2646c321187Smrg  fi
2656c321187Smrg  rm -f "$depfile"
2666c321187Smrg
2676c321187Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2686c321187Smrg    echo "$object : \\" > "$depfile"
2696c321187Smrg    # Clip off the initial element (the dependent).  Don't try to be
2706c321187Smrg    # clever and replace this with sed code, as IRIX sed won't handle
2716c321187Smrg    # lines with more than a fixed number of characters (4096 in
2726c321187Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2739d0b5e55Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
2746c321187Smrg    # dependency line.
2759d0b5e55Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2769d0b5e55Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2779d0b5e55Smrg      | tr "$nl" ' ' >> "$depfile"
27893493779Smrg    echo >> "$depfile"
2796c321187Smrg    # The second pass generates a dummy entry for each header file.
2809d0b5e55Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2819d0b5e55Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2829d0b5e55Smrg      >> "$depfile"
2836c321187Smrg  else
2849d0b5e55Smrg    make_dummy_depfile
2856c321187Smrg  fi
2866c321187Smrg  rm -f "$tmpdepfile"
2876c321187Smrg  ;;
2886c321187Smrg
2899d0b5e55Smrgxlc)
2909d0b5e55Smrg  # This case exists only to let depend.m4 do its work.  It works by
2919d0b5e55Smrg  # looking at the text of this script.  This case will never be run,
2929d0b5e55Smrg  # since it is checked for above.
2939d0b5e55Smrg  exit 1
2949d0b5e55Smrg  ;;
2959d0b5e55Smrg
2966c321187Smrgaix)
2976c321187Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2986c321187Smrg  # in a .u file.  In older versions, this file always lives in the
2999d0b5e55Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3006c321187Smrg  # start of each line; $object doesn't have directory information.
3016c321187Smrg  # Version 6 uses the directory in both cases.
3029d0b5e55Smrg  set_dir_from "$object"
3039d0b5e55Smrg  set_base_from "$object"
3046c321187Smrg  if test "$libtool" = yes; then
30593493779Smrg    tmpdepfile1=$dir$base.u
30693493779Smrg    tmpdepfile2=$base.u
30793493779Smrg    tmpdepfile3=$dir.libs/$base.u
3086c321187Smrg    "$@" -Wc,-M
3096c321187Smrg  else
31093493779Smrg    tmpdepfile1=$dir$base.u
31193493779Smrg    tmpdepfile2=$dir$base.u
31293493779Smrg    tmpdepfile3=$dir$base.u
3136c321187Smrg    "$@" -M
3146c321187Smrg  fi
3156c321187Smrg  stat=$?
3169d0b5e55Smrg  if test $stat -ne 0; then
31793493779Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3186c321187Smrg    exit $stat
3196c321187Smrg  fi
3206c321187Smrg
32193493779Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
32293493779Smrg  do
32393493779Smrg    test -f "$tmpdepfile" && break
32493493779Smrg  done
3259d0b5e55Smrg  aix_post_process_depfile
3269d0b5e55Smrg  ;;
3279d0b5e55Smrg
3289d0b5e55Smrgtcc)
3299d0b5e55Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3309d0b5e55Smrg  # FIXME: That version still under development at the moment of writing.
3319d0b5e55Smrg  #        Make that this statement remains true also for stable, released
3329d0b5e55Smrg  #        versions.
3339d0b5e55Smrg  # It will wrap lines (doesn't matter whether long or short) with a
3349d0b5e55Smrg  # trailing '\', as in:
3359d0b5e55Smrg  #
3369d0b5e55Smrg  #   foo.o : \
3379d0b5e55Smrg  #    foo.c \
3389d0b5e55Smrg  #    foo.h \
3399d0b5e55Smrg  #
3409d0b5e55Smrg  # It will put a trailing '\' even on the last line, and will use leading
3419d0b5e55Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3429d0b5e55Smrg  # "Emit spaces for -MD").
3439d0b5e55Smrg  "$@" -MD -MF "$tmpdepfile"
3449d0b5e55Smrg  stat=$?
3459d0b5e55Smrg  if test $stat -ne 0; then
3469d0b5e55Smrg    rm -f "$tmpdepfile"
3479d0b5e55Smrg    exit $stat
3486c321187Smrg  fi
3499d0b5e55Smrg  rm -f "$depfile"
3509d0b5e55Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3519d0b5e55Smrg  # We have to change lines of the first kind to '$object: \'.
3529d0b5e55Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3539d0b5e55Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3549d0b5e55Smrg  # dummy dependency, to avoid the deleted-header problem.
3559d0b5e55Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3566c321187Smrg  rm -f "$tmpdepfile"
3576c321187Smrg  ;;
3586c321187Smrg
3599d0b5e55Smrg## The order of this option in the case statement is important, since the
3609d0b5e55Smrg## shell code in configure will try each of these formats in the order
3619d0b5e55Smrg## listed in this file.  A plain '-MD' option would be understood by many
3629d0b5e55Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3639d0b5e55Smrgpgcc)
3649d0b5e55Smrg  # Portland's C compiler understands '-MD'.
3659d0b5e55Smrg  # Will always output deps to 'file.d' where file is the root name of the
3669d0b5e55Smrg  # source file under compilation, even if file resides in a subdirectory.
3679d0b5e55Smrg  # The object file name does not affect the name of the '.d' file.
3689d0b5e55Smrg  # pgcc 10.2 will output
3696c321187Smrg  #    foo.o: sub/foo.c sub/foo.h
3709d0b5e55Smrg  # and will wrap long lines using '\' :
3716c321187Smrg  #    foo.o: sub/foo.c ... \
3726c321187Smrg  #     sub/foo.h ... \
3736c321187Smrg  #     ...
3749d0b5e55Smrg  set_dir_from "$object"
3759d0b5e55Smrg  # Use the source, not the object, to determine the base name, since
3769d0b5e55Smrg  # that's sadly what pgcc will do too.
3779d0b5e55Smrg  set_base_from "$source"
3789d0b5e55Smrg  tmpdepfile=$base.d
3799d0b5e55Smrg
3809d0b5e55Smrg  # For projects that build the same source file twice into different object
3819d0b5e55Smrg  # files, the pgcc approach of using the *source* file root name can cause
3829d0b5e55Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3839d0b5e55Smrg  # the same $tmpdepfile.
3849d0b5e55Smrg  lockdir=$base.d-lock
3859d0b5e55Smrg  trap "
3869d0b5e55Smrg    echo '$0: caught signal, cleaning up...' >&2
3879d0b5e55Smrg    rmdir '$lockdir'
3889d0b5e55Smrg    exit 1
3899d0b5e55Smrg  " 1 2 13 15
3909d0b5e55Smrg  numtries=100
3919d0b5e55Smrg  i=$numtries
3929d0b5e55Smrg  while test $i -gt 0; do
3939d0b5e55Smrg    # mkdir is a portable test-and-set.
3949d0b5e55Smrg    if mkdir "$lockdir" 2>/dev/null; then
3959d0b5e55Smrg      # This process acquired the lock.
3969d0b5e55Smrg      "$@" -MD
3979d0b5e55Smrg      stat=$?
3989d0b5e55Smrg      # Release the lock.
3999d0b5e55Smrg      rmdir "$lockdir"
4009d0b5e55Smrg      break
4019d0b5e55Smrg    else
4029d0b5e55Smrg      # If the lock is being held by a different process, wait
4039d0b5e55Smrg      # until the winning process is done or we timeout.
4049d0b5e55Smrg      while test -d "$lockdir" && test $i -gt 0; do
4059d0b5e55Smrg        sleep 1
4069d0b5e55Smrg        i=`expr $i - 1`
4079d0b5e55Smrg      done
4089d0b5e55Smrg    fi
4099d0b5e55Smrg    i=`expr $i - 1`
4109d0b5e55Smrg  done
4119d0b5e55Smrg  trap - 1 2 13 15
4129d0b5e55Smrg  if test $i -le 0; then
4139d0b5e55Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4149d0b5e55Smrg    echo "$0: check lockdir '$lockdir'" >&2
4159d0b5e55Smrg    exit 1
4169d0b5e55Smrg  fi
4176c321187Smrg
4189d0b5e55Smrg  if test $stat -ne 0; then
4196c321187Smrg    rm -f "$tmpdepfile"
4206c321187Smrg    exit $stat
4216c321187Smrg  fi
4226c321187Smrg  rm -f "$depfile"
4236c321187Smrg  # Each line is of the form `foo.o: dependent.h',
4246c321187Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4256c321187Smrg  # Do two passes, one to just change these to
4266c321187Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4276c321187Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4286c321187Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4296c321187Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
4309d0b5e55Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4319d0b5e55Smrg    | sed -e 's/$/ :/' >> "$depfile"
4326c321187Smrg  rm -f "$tmpdepfile"
4336c321187Smrg  ;;
4346c321187Smrg
4356c321187Smrghp2)
4366c321187Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4376c321187Smrg  # compilers, which have integrated preprocessors.  The correct option
4386c321187Smrg  # to use with these is +Maked; it writes dependencies to a file named
4396c321187Smrg  # 'foo.d', which lands next to the object file, wherever that
4406c321187Smrg  # happens to be.
4416c321187Smrg  # Much of this is similar to the tru64 case; see comments there.
4429d0b5e55Smrg  set_dir_from  "$object"
4439d0b5e55Smrg  set_base_from "$object"
4446c321187Smrg  if test "$libtool" = yes; then
4456c321187Smrg    tmpdepfile1=$dir$base.d
4466c321187Smrg    tmpdepfile2=$dir.libs/$base.d
4476c321187Smrg    "$@" -Wc,+Maked
4486c321187Smrg  else
4496c321187Smrg    tmpdepfile1=$dir$base.d
4506c321187Smrg    tmpdepfile2=$dir$base.d
4516c321187Smrg    "$@" +Maked
4526c321187Smrg  fi
4536c321187Smrg  stat=$?
4549d0b5e55Smrg  if test $stat -ne 0; then
4556c321187Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4566c321187Smrg     exit $stat
4576c321187Smrg  fi
4586c321187Smrg
4596c321187Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4606c321187Smrg  do
4616c321187Smrg    test -f "$tmpdepfile" && break
4626c321187Smrg  done
4636c321187Smrg  if test -f "$tmpdepfile"; then
4649d0b5e55Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4659d0b5e55Smrg    # Add 'dependent.h:' lines.
46693493779Smrg    sed -ne '2,${
4679d0b5e55Smrg               s/^ *//
4689d0b5e55Smrg               s/ \\*$//
4699d0b5e55Smrg               s/$/:/
4709d0b5e55Smrg               p
4719d0b5e55Smrg             }' "$tmpdepfile" >> "$depfile"
4726c321187Smrg  else
4739d0b5e55Smrg    make_dummy_depfile
4746c321187Smrg  fi
4756c321187Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4766c321187Smrg  ;;
4776c321187Smrg
4786c321187Smrgtru64)
4799d0b5e55Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4809d0b5e55Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4819d0b5e55Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4829d0b5e55Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4839d0b5e55Smrg  # Subdirectories are respected.
4849d0b5e55Smrg  set_dir_from  "$object"
4859d0b5e55Smrg  set_base_from "$object"
4869d0b5e55Smrg
4879d0b5e55Smrg  if test "$libtool" = yes; then
4889d0b5e55Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4899d0b5e55Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4909d0b5e55Smrg    # in $dir$base.o.d.  We have to check for both files, because
4919d0b5e55Smrg    # one of the two compilations can be disabled.  We should prefer
4929d0b5e55Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4939d0b5e55Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4949d0b5e55Smrg    # the former would cause a distcleancheck panic.
4959d0b5e55Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4969d0b5e55Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4979d0b5e55Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4989d0b5e55Smrg    "$@" -Wc,-MD
4999d0b5e55Smrg  else
5009d0b5e55Smrg    tmpdepfile1=$dir$base.d
5019d0b5e55Smrg    tmpdepfile2=$dir$base.d
5029d0b5e55Smrg    tmpdepfile3=$dir$base.d
5039d0b5e55Smrg    "$@" -MD
5049d0b5e55Smrg  fi
5059d0b5e55Smrg
5069d0b5e55Smrg  stat=$?
5079d0b5e55Smrg  if test $stat -ne 0; then
5089d0b5e55Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5099d0b5e55Smrg    exit $stat
5109d0b5e55Smrg  fi
5119d0b5e55Smrg
5129d0b5e55Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5139d0b5e55Smrg  do
5149d0b5e55Smrg    test -f "$tmpdepfile" && break
5159d0b5e55Smrg  done
5169d0b5e55Smrg  # Same post-processing that is required for AIX mode.
5179d0b5e55Smrg  aix_post_process_depfile
5189d0b5e55Smrg  ;;
5199d0b5e55Smrg
5209d0b5e55Smrgmsvc7)
5219d0b5e55Smrg  if test "$libtool" = yes; then
5229d0b5e55Smrg    showIncludes=-Wc,-showIncludes
5239d0b5e55Smrg  else
5249d0b5e55Smrg    showIncludes=-showIncludes
5259d0b5e55Smrg  fi
5269d0b5e55Smrg  "$@" $showIncludes > "$tmpdepfile"
5279d0b5e55Smrg  stat=$?
5289d0b5e55Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5299d0b5e55Smrg  if test $stat -ne 0; then
5309d0b5e55Smrg    rm -f "$tmpdepfile"
5319d0b5e55Smrg    exit $stat
5329d0b5e55Smrg  fi
5339d0b5e55Smrg  rm -f "$depfile"
5349d0b5e55Smrg  echo "$object : \\" > "$depfile"
5359d0b5e55Smrg  # The first sed program below extracts the file names and escapes
5369d0b5e55Smrg  # backslashes for cygpath.  The second sed program outputs the file
5379d0b5e55Smrg  # name when reading, but also accumulates all include files in the
5389d0b5e55Smrg  # hold buffer in order to output them again at the end.  This only
5399d0b5e55Smrg  # works with sed implementations that can handle large buffers.
5409d0b5e55Smrg  sed < "$tmpdepfile" -n '
5419d0b5e55Smrg/^Note: including file:  *\(.*\)/ {
5429d0b5e55Smrg  s//\1/
5439d0b5e55Smrg  s/\\/\\\\/g
5449d0b5e55Smrg  p
5459d0b5e55Smrg}' | $cygpath_u | sort -u | sed -n '
5469d0b5e55Smrgs/ /\\ /g
5479d0b5e55Smrgs/\(.*\)/'"$tab"'\1 \\/p
5489d0b5e55Smrgs/.\(.*\) \\/\1:/
5499d0b5e55SmrgH
5509d0b5e55Smrg$ {
5519d0b5e55Smrg  s/.*/'"$tab"'/
5529d0b5e55Smrg  G
5539d0b5e55Smrg  p
5549d0b5e55Smrg}' >> "$depfile"
5559d0b5e55Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5569d0b5e55Smrg  rm -f "$tmpdepfile"
5579d0b5e55Smrg  ;;
5589d0b5e55Smrg
5599d0b5e55Smrgmsvc7msys)
5609d0b5e55Smrg  # This case exists only to let depend.m4 do its work.  It works by
5619d0b5e55Smrg  # looking at the text of this script.  This case will never be run,
5629d0b5e55Smrg  # since it is checked for above.
5639d0b5e55Smrg  exit 1
5649d0b5e55Smrg  ;;
5656c321187Smrg
5666c321187Smrg#nosideeffect)
5676c321187Smrg  # This comment above is used by automake to tell side-effect
5686c321187Smrg  # dependency tracking mechanisms from slower ones.
5696c321187Smrg
5706c321187Smrgdashmstdout)
5716c321187Smrg  # Important note: in order to support this mode, a compiler *must*
5726c321187Smrg  # always write the preprocessed file to stdout, regardless of -o.
5736c321187Smrg  "$@" || exit $?
5746c321187Smrg
5756c321187Smrg  # Remove the call to Libtool.
5766c321187Smrg  if test "$libtool" = yes; then
57793493779Smrg    while test "X$1" != 'X--mode=compile'; do
5786c321187Smrg      shift
5796c321187Smrg    done
5806c321187Smrg    shift
5816c321187Smrg  fi
5826c321187Smrg
5839d0b5e55Smrg  # Remove '-o $object'.
5846c321187Smrg  IFS=" "
5856c321187Smrg  for arg
5866c321187Smrg  do
5876c321187Smrg    case $arg in
5886c321187Smrg    -o)
5896c321187Smrg      shift
5906c321187Smrg      ;;
5916c321187Smrg    $object)
5926c321187Smrg      shift
5936c321187Smrg      ;;
5946c321187Smrg    *)
5956c321187Smrg      set fnord "$@" "$arg"
5966c321187Smrg      shift # fnord
5976c321187Smrg      shift # $arg
5986c321187Smrg      ;;
5996c321187Smrg    esac
6006c321187Smrg  done
6016c321187Smrg
6026c321187Smrg  test -z "$dashmflag" && dashmflag=-M
6039d0b5e55Smrg  # Require at least two characters before searching for ':'
6046c321187Smrg  # in the target name.  This is to cope with DOS-style filenames:
6059d0b5e55Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6066c321187Smrg  "$@" $dashmflag |
6079d0b5e55Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6086c321187Smrg  rm -f "$depfile"
6096c321187Smrg  cat < "$tmpdepfile" > "$depfile"
6109d0b5e55Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6119d0b5e55Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6129d0b5e55Smrg  tr ' ' "$nl" < "$tmpdepfile" \
6139d0b5e55Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6149d0b5e55Smrg    | sed -e 's/$/ :/' >> "$depfile"
6156c321187Smrg  rm -f "$tmpdepfile"
6166c321187Smrg  ;;
6176c321187Smrg
6186c321187SmrgdashXmstdout)
6196c321187Smrg  # This case only exists to satisfy depend.m4.  It is never actually
6206c321187Smrg  # run, as this mode is specially recognized in the preamble.
6216c321187Smrg  exit 1
6226c321187Smrg  ;;
6236c321187Smrg
6246c321187Smrgmakedepend)
6256c321187Smrg  "$@" || exit $?
6266c321187Smrg  # Remove any Libtool call
6276c321187Smrg  if test "$libtool" = yes; then
62893493779Smrg    while test "X$1" != 'X--mode=compile'; do
6296c321187Smrg      shift
6306c321187Smrg    done
6316c321187Smrg    shift
6326c321187Smrg  fi
6336c321187Smrg  # X makedepend
6346c321187Smrg  shift
63593493779Smrg  cleared=no eat=no
63693493779Smrg  for arg
63793493779Smrg  do
6386c321187Smrg    case $cleared in
6396c321187Smrg    no)
6406c321187Smrg      set ""; shift
6416c321187Smrg      cleared=yes ;;
6426c321187Smrg    esac
64393493779Smrg    if test $eat = yes; then
64493493779Smrg      eat=no
64593493779Smrg      continue
64693493779Smrg    fi
6476c321187Smrg    case "$arg" in
6486c321187Smrg    -D*|-I*)
6496c321187Smrg      set fnord "$@" "$arg"; shift ;;
6506c321187Smrg    # Strip any option that makedepend may not understand.  Remove
6516c321187Smrg    # the object too, otherwise makedepend will parse it as a source file.
65293493779Smrg    -arch)
65393493779Smrg      eat=yes ;;
6546c321187Smrg    -*|$object)
6556c321187Smrg      ;;
6566c321187Smrg    *)
6576c321187Smrg      set fnord "$@" "$arg"; shift ;;
6586c321187Smrg    esac
6596c321187Smrg  done
66093493779Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6616c321187Smrg  touch "$tmpdepfile"
6626c321187Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6636c321187Smrg  rm -f "$depfile"
6649d0b5e55Smrg  # makedepend may prepend the VPATH from the source file name to the object.
6659d0b5e55Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6669d0b5e55Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6679d0b5e55Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6689d0b5e55Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6699d0b5e55Smrg  sed '1,2d' "$tmpdepfile" \
6709d0b5e55Smrg    | tr ' ' "$nl" \
6719d0b5e55Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6729d0b5e55Smrg    | sed -e 's/$/ :/' >> "$depfile"
6736c321187Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6746c321187Smrg  ;;
6756c321187Smrg
6766c321187Smrgcpp)
6776c321187Smrg  # Important note: in order to support this mode, a compiler *must*
6786c321187Smrg  # always write the preprocessed file to stdout.
6796c321187Smrg  "$@" || exit $?
6806c321187Smrg
6816c321187Smrg  # Remove the call to Libtool.
6826c321187Smrg  if test "$libtool" = yes; then
68393493779Smrg    while test "X$1" != 'X--mode=compile'; do
6846c321187Smrg      shift
6856c321187Smrg    done
6866c321187Smrg    shift
6876c321187Smrg  fi
6886c321187Smrg
6899d0b5e55Smrg  # Remove '-o $object'.
6906c321187Smrg  IFS=" "
6916c321187Smrg  for arg
6926c321187Smrg  do
6936c321187Smrg    case $arg in
6946c321187Smrg    -o)
6956c321187Smrg      shift
6966c321187Smrg      ;;
6976c321187Smrg    $object)
6986c321187Smrg      shift
6996c321187Smrg      ;;
7006c321187Smrg    *)
7016c321187Smrg      set fnord "$@" "$arg"
7026c321187Smrg      shift # fnord
7036c321187Smrg      shift # $arg
7046c321187Smrg      ;;
7056c321187Smrg    esac
7066c321187Smrg  done
7076c321187Smrg
7089d0b5e55Smrg  "$@" -E \
7099d0b5e55Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7109d0b5e55Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7119d0b5e55Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
7126c321187Smrg  rm -f "$depfile"
7136c321187Smrg  echo "$object : \\" > "$depfile"
7146c321187Smrg  cat < "$tmpdepfile" >> "$depfile"
7156c321187Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7166c321187Smrg  rm -f "$tmpdepfile"
7176c321187Smrg  ;;
7186c321187Smrg
7196c321187Smrgmsvisualcpp)
7206c321187Smrg  # Important note: in order to support this mode, a compiler *must*
72193493779Smrg  # always write the preprocessed file to stdout.
7226c321187Smrg  "$@" || exit $?
72393493779Smrg
72493493779Smrg  # Remove the call to Libtool.
72593493779Smrg  if test "$libtool" = yes; then
72693493779Smrg    while test "X$1" != 'X--mode=compile'; do
72793493779Smrg      shift
72893493779Smrg    done
72993493779Smrg    shift
73093493779Smrg  fi
73193493779Smrg
7326c321187Smrg  IFS=" "
7336c321187Smrg  for arg
7346c321187Smrg  do
7356c321187Smrg    case "$arg" in
73693493779Smrg    -o)
73793493779Smrg      shift
73893493779Smrg      ;;
73993493779Smrg    $object)
74093493779Smrg      shift
74193493779Smrg      ;;
7426c321187Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7439d0b5e55Smrg        set fnord "$@"
7449d0b5e55Smrg        shift
7459d0b5e55Smrg        shift
7469d0b5e55Smrg        ;;
7476c321187Smrg    *)
7489d0b5e55Smrg        set fnord "$@" "$arg"
7499d0b5e55Smrg        shift
7509d0b5e55Smrg        shift
7519d0b5e55Smrg        ;;
7526c321187Smrg    esac
7536c321187Smrg  done
75493493779Smrg  "$@" -E 2>/dev/null |
75593493779Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7566c321187Smrg  rm -f "$depfile"
7576c321187Smrg  echo "$object : \\" > "$depfile"
7589d0b5e55Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7599d0b5e55Smrg  echo "$tab" >> "$depfile"
76093493779Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7616c321187Smrg  rm -f "$tmpdepfile"
7626c321187Smrg  ;;
7636c321187Smrg
76493493779Smrgmsvcmsys)
76593493779Smrg  # This case exists only to let depend.m4 do its work.  It works by
76693493779Smrg  # looking at the text of this script.  This case will never be run,
76793493779Smrg  # since it is checked for above.
76893493779Smrg  exit 1
76993493779Smrg  ;;
77093493779Smrg
7716c321187Smrgnone)
7726c321187Smrg  exec "$@"
7736c321187Smrg  ;;
7746c321187Smrg
7756c321187Smrg*)
7766c321187Smrg  echo "Unknown depmode $depmode" 1>&2
7776c321187Smrg  exit 1
7786c321187Smrg  ;;
7796c321187Smrgesac
7806c321187Smrg
7816c321187Smrgexit 0
7826c321187Smrg
7836c321187Smrg# Local Variables:
7846c321187Smrg# mode: shell-script
7856c321187Smrg# sh-indentation: 2
7869dedec0cSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
7876c321187Smrg# time-stamp-start: "scriptversion="
7886c321187Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7899dedec0cSmrg# time-stamp-time-zone: "UTC0"
79093493779Smrg# time-stamp-end: "; # UTC"
7916c321187Smrg# End:
792