depcomp revision 6c3c2bce
17a0395d0Smrg#! /bin/sh
27a0395d0Smrg# depcomp - compile a program generating dependencies as side-effects
37a0395d0Smrg
46c3c2bceSmrgscriptversion=2018-03-07.03; # UTC
57a0395d0Smrg
66c3c2bceSmrg# Copyright (C) 1999-2018 Free Software Foundation, Inc.
77a0395d0Smrg
87a0395d0Smrg# This program is free software; you can redistribute it and/or modify
97a0395d0Smrg# it under the terms of the GNU General Public License as published by
107a0395d0Smrg# the Free Software Foundation; either version 2, or (at your option)
117a0395d0Smrg# any later version.
127a0395d0Smrg
137a0395d0Smrg# This program is distributed in the hope that it will be useful,
147a0395d0Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
157a0395d0Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
167a0395d0Smrg# GNU General Public License for more details.
177a0395d0Smrg
187a0395d0Smrg# You should have received a copy of the GNU General Public License
196c3c2bceSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
207a0395d0Smrg
217a0395d0Smrg# As a special exception to the GNU General Public License, if you
227a0395d0Smrg# distribute this file as part of a program that contains a
237a0395d0Smrg# configuration script generated by Autoconf, you may include it under
247a0395d0Smrg# the same distribution terms that you use for the rest of that program.
257a0395d0Smrg
267a0395d0Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
277a0395d0Smrg
287a0395d0Smrgcase $1 in
297a0395d0Smrg  '')
309a011757Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
319a011757Smrg    exit 1;
329a011757Smrg    ;;
337a0395d0Smrg  -h | --h*)
347a0395d0Smrg    cat <<\EOF
357a0395d0SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
367a0395d0Smrg
377a0395d0SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
387a0395d0Smrgas side-effects.
397a0395d0Smrg
407a0395d0SmrgEnvironment variables:
417a0395d0Smrg  depmode     Dependency tracking mode.
428abc0ccfSmrg  source      Source file read by 'PROGRAMS ARGS'.
438abc0ccfSmrg  object      Object file output by 'PROGRAMS ARGS'.
447a0395d0Smrg  DEPDIR      directory where to store dependencies.
457a0395d0Smrg  depfile     Dependency file to output.
468abc0ccfSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
477a0395d0Smrg  libtool     Whether libtool is used (yes/no).
487a0395d0Smrg
497a0395d0SmrgReport bugs to <bug-automake@gnu.org>.
507a0395d0SmrgEOF
517a0395d0Smrg    exit $?
527a0395d0Smrg    ;;
537a0395d0Smrg  -v | --v*)
547a0395d0Smrg    echo "depcomp $scriptversion"
557a0395d0Smrg    exit $?
567a0395d0Smrg    ;;
577a0395d0Smrgesac
587a0395d0Smrg
599a011757Smrg# Get the directory component of the given path, and save it in the
609a011757Smrg# global variables '$dir'.  Note that this directory component will
619a011757Smrg# be either empty or ending with a '/' character.  This is deliberate.
629a011757Smrgset_dir_from ()
639a011757Smrg{
649a011757Smrg  case $1 in
659a011757Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
669a011757Smrg      *) dir=;;
679a011757Smrg  esac
689a011757Smrg}
699a011757Smrg
709a011757Smrg# Get the suffix-stripped basename of the given path, and save it the
719a011757Smrg# global variable '$base'.
729a011757Smrgset_base_from ()
739a011757Smrg{
749a011757Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
759a011757Smrg}
769a011757Smrg
779a011757Smrg# If no dependency file was actually created by the compiler invocation,
789a011757Smrg# we still have to create a dummy depfile, to avoid errors with the
799a011757Smrg# Makefile "include basename.Plo" scheme.
809a011757Smrgmake_dummy_depfile ()
819a011757Smrg{
829a011757Smrg  echo "#dummy" > "$depfile"
839a011757Smrg}
849a011757Smrg
859a011757Smrg# Factor out some common post-processing of the generated depfile.
869a011757Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
879a011757Smrgaix_post_process_depfile ()
889a011757Smrg{
899a011757Smrg  # If the compiler actually managed to produce a dependency file,
909a011757Smrg  # post-process it.
919a011757Smrg  if test -f "$tmpdepfile"; then
929a011757Smrg    # Each line is of the form 'foo.o: dependency.h'.
939a011757Smrg    # Do two passes, one to just change these to
949a011757Smrg    #   $object: dependency.h
959a011757Smrg    # and one to simply output
969a011757Smrg    #   dependency.h:
979a011757Smrg    # which is needed to avoid the deleted-header problem.
989a011757Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
999a011757Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1009a011757Smrg    } > "$depfile"
1019a011757Smrg    rm -f "$tmpdepfile"
1029a011757Smrg  else
1039a011757Smrg    make_dummy_depfile
1049a011757Smrg  fi
1059a011757Smrg}
1069a011757Smrg
1078abc0ccfSmrg# A tabulation character.
1088abc0ccfSmrgtab='	'
1098abc0ccfSmrg# A newline character.
1108abc0ccfSmrgnl='
1118abc0ccfSmrg'
1129a011757Smrg# Character ranges might be problematic outside the C locale.
1139a011757Smrg# These definitions help.
1149a011757Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1159a011757Smrglower=abcdefghijklmnopqrstuvwxyz
1169a011757Smrgdigits=0123456789
1179a011757Smrgalpha=${upper}${lower}
1188abc0ccfSmrg
1197a0395d0Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1207a0395d0Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1217a0395d0Smrg  exit 1
1227a0395d0Smrgfi
1237a0395d0Smrg
1247a0395d0Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1257a0395d0Smrgdepfile=${depfile-`echo "$object" |
1267a0395d0Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1277a0395d0Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1287a0395d0Smrg
1297a0395d0Smrgrm -f "$tmpdepfile"
1307a0395d0Smrg
1319a011757Smrg# Avoid interferences from the environment.
1329a011757Smrggccflag= dashmflag=
1339a011757Smrg
1347a0395d0Smrg# Some modes work just like other modes, but use different flags.  We
1357a0395d0Smrg# parameterize here, but still list the modes in the big case below,
1367a0395d0Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1377a0395d0Smrg# here, because this file can only contain one case statement.
1387a0395d0Smrgif test "$depmode" = hp; then
1397a0395d0Smrg  # HP compiler uses -M and no extra arg.
1407a0395d0Smrg  gccflag=-M
1417a0395d0Smrg  depmode=gcc
1427a0395d0Smrgfi
1437a0395d0Smrg
1447a0395d0Smrgif test "$depmode" = dashXmstdout; then
1459a011757Smrg  # This is just like dashmstdout with a different argument.
1469a011757Smrg  dashmflag=-xM
1479a011757Smrg  depmode=dashmstdout
1487a0395d0Smrgfi
1497a0395d0Smrg
1507366012aSmrgcygpath_u="cygpath -u -f -"
1517366012aSmrgif test "$depmode" = msvcmsys; then
1529a011757Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1539a011757Smrg  # Just convert the backslash-escaped backslashes to single forward
1549a011757Smrg  # slashes to satisfy depend.m4
1559a011757Smrg  cygpath_u='sed s,\\\\,/,g'
1569a011757Smrg  depmode=msvisualcpp
1577366012aSmrgfi
1587366012aSmrg
1598abc0ccfSmrgif test "$depmode" = msvc7msys; then
1609a011757Smrg  # This is just like msvc7 but w/o cygpath translation.
1619a011757Smrg  # Just convert the backslash-escaped backslashes to single forward
1629a011757Smrg  # slashes to satisfy depend.m4
1639a011757Smrg  cygpath_u='sed s,\\\\,/,g'
1649a011757Smrg  depmode=msvc7
1658abc0ccfSmrgfi
1668abc0ccfSmrg
1678abc0ccfSmrgif test "$depmode" = xlc; then
1689a011757Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1699a011757Smrg  gccflag=-qmakedep=gcc,-MF
1709a011757Smrg  depmode=gcc
1718abc0ccfSmrgfi
1728abc0ccfSmrg
1737a0395d0Smrgcase "$depmode" in
1747a0395d0Smrggcc3)
1757a0395d0Smrg## gcc 3 implements dependency tracking that does exactly what
1767a0395d0Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1777a0395d0Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1787a0395d0Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1797a0395d0Smrg## the command line argument order; so add the flags where they
1807a0395d0Smrg## appear in depend2.am.  Note that the slowdown incurred here
1817a0395d0Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1827a0395d0Smrg  for arg
1837a0395d0Smrg  do
1847a0395d0Smrg    case $arg in
1857a0395d0Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1867a0395d0Smrg    *)  set fnord "$@" "$arg" ;;
1877a0395d0Smrg    esac
1887a0395d0Smrg    shift # fnord
1897a0395d0Smrg    shift # $arg
1907a0395d0Smrg  done
1917a0395d0Smrg  "$@"
1927a0395d0Smrg  stat=$?
1939a011757Smrg  if test $stat -ne 0; then
1947a0395d0Smrg    rm -f "$tmpdepfile"
1957a0395d0Smrg    exit $stat
1967a0395d0Smrg  fi
1977a0395d0Smrg  mv "$tmpdepfile" "$depfile"
1987a0395d0Smrg  ;;
1997a0395d0Smrg
2007a0395d0Smrggcc)
2019a011757Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2029a011757Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2039a011757Smrg## (see the conditional assignment to $gccflag above).
2047a0395d0Smrg## There are various ways to get dependency output from gcc.  Here's
2057a0395d0Smrg## why we pick this rather obscure method:
2067a0395d0Smrg## - Don't want to use -MD because we'd like the dependencies to end
2077a0395d0Smrg##   up in a subdir.  Having to rename by hand is ugly.
2087a0395d0Smrg##   (We might end up doing this anyway to support other compilers.)
2097a0395d0Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2109a011757Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2119a011757Smrg##   supported by the other compilers which use the 'gcc' depmode.
2127a0395d0Smrg## - Using -M directly means running the compiler twice (even worse
2137a0395d0Smrg##   than renaming).
2147a0395d0Smrg  if test -z "$gccflag"; then
2157a0395d0Smrg    gccflag=-MD,
2167a0395d0Smrg  fi
2177a0395d0Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
2187a0395d0Smrg  stat=$?
2199a011757Smrg  if test $stat -ne 0; then
2207a0395d0Smrg    rm -f "$tmpdepfile"
2217a0395d0Smrg    exit $stat
2227a0395d0Smrg  fi
2237a0395d0Smrg  rm -f "$depfile"
2247a0395d0Smrg  echo "$object : \\" > "$depfile"
2259a011757Smrg  # The second -e expression handles DOS-style file names with drive
2269a011757Smrg  # letters.
2277a0395d0Smrg  sed -e 's/^[^:]*: / /' \
2287a0395d0Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2298abc0ccfSmrg## This next piece of magic avoids the "deleted header file" problem.
2307a0395d0Smrg## The problem is that when a header file which appears in a .P file
2317a0395d0Smrg## is deleted, the dependency causes make to die (because there is
2327a0395d0Smrg## typically no way to rebuild the header).  We avoid this by adding
2337a0395d0Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2347a0395d0Smrg## this for us directly.
2358abc0ccfSmrg## Some versions of gcc put a space before the ':'.  On the theory
2367a0395d0Smrg## that the space means something, we add a space to the output as
2378abc0ccfSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2388abc0ccfSmrg## to the object.  Take care to not repeat it in the output.
2397a0395d0Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
2407a0395d0Smrg## correctly.  Breaking it into two sed invocations is a workaround.
2419a011757Smrg  tr ' ' "$nl" < "$tmpdepfile" \
2429a011757Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2439a011757Smrg    | sed -e 's/$/ :/' >> "$depfile"
2447a0395d0Smrg  rm -f "$tmpdepfile"
2457a0395d0Smrg  ;;
2467a0395d0Smrg
2477a0395d0Smrghp)
2487a0395d0Smrg  # This case exists only to let depend.m4 do its work.  It works by
2497a0395d0Smrg  # looking at the text of this script.  This case will never be run,
2507a0395d0Smrg  # since it is checked for above.
2517a0395d0Smrg  exit 1
2527a0395d0Smrg  ;;
2537a0395d0Smrg
2547a0395d0Smrgsgi)
2557a0395d0Smrg  if test "$libtool" = yes; then
2567a0395d0Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2577a0395d0Smrg  else
2587a0395d0Smrg    "$@" -MDupdate "$tmpdepfile"
2597a0395d0Smrg  fi
2607a0395d0Smrg  stat=$?
2619a011757Smrg  if test $stat -ne 0; then
2627a0395d0Smrg    rm -f "$tmpdepfile"
2637a0395d0Smrg    exit $stat
2647a0395d0Smrg  fi
2657a0395d0Smrg  rm -f "$depfile"
2667a0395d0Smrg
2677a0395d0Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2687a0395d0Smrg    echo "$object : \\" > "$depfile"
2697a0395d0Smrg    # Clip off the initial element (the dependent).  Don't try to be
2707a0395d0Smrg    # clever and replace this with sed code, as IRIX sed won't handle
2717a0395d0Smrg    # lines with more than a fixed number of characters (4096 in
2727a0395d0Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2738abc0ccfSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
2747a0395d0Smrg    # dependency line.
2758abc0ccfSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2769a011757Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2779a011757Smrg      | tr "$nl" ' ' >> "$depfile"
2787366012aSmrg    echo >> "$depfile"
2797a0395d0Smrg    # The second pass generates a dummy entry for each header file.
2808abc0ccfSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2819a011757Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2829a011757Smrg      >> "$depfile"
2837a0395d0Smrg  else
2849a011757Smrg    make_dummy_depfile
2857a0395d0Smrg  fi
2867a0395d0Smrg  rm -f "$tmpdepfile"
2877a0395d0Smrg  ;;
2887a0395d0Smrg
2898abc0ccfSmrgxlc)
2908abc0ccfSmrg  # This case exists only to let depend.m4 do its work.  It works by
2918abc0ccfSmrg  # looking at the text of this script.  This case will never be run,
2928abc0ccfSmrg  # since it is checked for above.
2938abc0ccfSmrg  exit 1
2948abc0ccfSmrg  ;;
2958abc0ccfSmrg
2967a0395d0Smrgaix)
2977a0395d0Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2987a0395d0Smrg  # in a .u file.  In older versions, this file always lives in the
2998abc0ccfSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3007a0395d0Smrg  # start of each line; $object doesn't have directory information.
3017a0395d0Smrg  # Version 6 uses the directory in both cases.
3029a011757Smrg  set_dir_from "$object"
3039a011757Smrg  set_base_from "$object"
3047a0395d0Smrg  if test "$libtool" = yes; then
3057a0395d0Smrg    tmpdepfile1=$dir$base.u
3067a0395d0Smrg    tmpdepfile2=$base.u
3077a0395d0Smrg    tmpdepfile3=$dir.libs/$base.u
3087a0395d0Smrg    "$@" -Wc,-M
3097a0395d0Smrg  else
3107a0395d0Smrg    tmpdepfile1=$dir$base.u
3117a0395d0Smrg    tmpdepfile2=$dir$base.u
3127a0395d0Smrg    tmpdepfile3=$dir$base.u
3137a0395d0Smrg    "$@" -M
3147a0395d0Smrg  fi
3157a0395d0Smrg  stat=$?
3169a011757Smrg  if test $stat -ne 0; then
3177a0395d0Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3187a0395d0Smrg    exit $stat
3197a0395d0Smrg  fi
3207a0395d0Smrg
3217a0395d0Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3227a0395d0Smrg  do
3237a0395d0Smrg    test -f "$tmpdepfile" && break
3247a0395d0Smrg  done
3259a011757Smrg  aix_post_process_depfile
3269a011757Smrg  ;;
3279a011757Smrg
3289a011757Smrgtcc)
3299a011757Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3309a011757Smrg  # FIXME: That version still under development at the moment of writing.
3319a011757Smrg  #        Make that this statement remains true also for stable, released
3329a011757Smrg  #        versions.
3339a011757Smrg  # It will wrap lines (doesn't matter whether long or short) with a
3349a011757Smrg  # trailing '\', as in:
3359a011757Smrg  #
3369a011757Smrg  #   foo.o : \
3379a011757Smrg  #    foo.c \
3389a011757Smrg  #    foo.h \
3399a011757Smrg  #
3409a011757Smrg  # It will put a trailing '\' even on the last line, and will use leading
3419a011757Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3429a011757Smrg  # "Emit spaces for -MD").
3439a011757Smrg  "$@" -MD -MF "$tmpdepfile"
3449a011757Smrg  stat=$?
3459a011757Smrg  if test $stat -ne 0; then
3469a011757Smrg    rm -f "$tmpdepfile"
3479a011757Smrg    exit $stat
3487a0395d0Smrg  fi
3499a011757Smrg  rm -f "$depfile"
3509a011757Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3519a011757Smrg  # We have to change lines of the first kind to '$object: \'.
3529a011757Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3539a011757Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3549a011757Smrg  # dummy dependency, to avoid the deleted-header problem.
3559a011757Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3567a0395d0Smrg  rm -f "$tmpdepfile"
3577a0395d0Smrg  ;;
3587a0395d0Smrg
3599a011757Smrg## The order of this option in the case statement is important, since the
3609a011757Smrg## shell code in configure will try each of these formats in the order
3619a011757Smrg## listed in this file.  A plain '-MD' option would be understood by many
3629a011757Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3639a011757Smrgpgcc)
3649a011757Smrg  # Portland's C compiler understands '-MD'.
3659a011757Smrg  # Will always output deps to 'file.d' where file is the root name of the
3669a011757Smrg  # source file under compilation, even if file resides in a subdirectory.
3679a011757Smrg  # The object file name does not affect the name of the '.d' file.
3689a011757Smrg  # pgcc 10.2 will output
3697a0395d0Smrg  #    foo.o: sub/foo.c sub/foo.h
3709a011757Smrg  # and will wrap long lines using '\' :
3717a0395d0Smrg  #    foo.o: sub/foo.c ... \
3727a0395d0Smrg  #     sub/foo.h ... \
3737a0395d0Smrg  #     ...
3749a011757Smrg  set_dir_from "$object"
3759a011757Smrg  # Use the source, not the object, to determine the base name, since
3769a011757Smrg  # that's sadly what pgcc will do too.
3779a011757Smrg  set_base_from "$source"
3789a011757Smrg  tmpdepfile=$base.d
3799a011757Smrg
3809a011757Smrg  # For projects that build the same source file twice into different object
3819a011757Smrg  # files, the pgcc approach of using the *source* file root name can cause
3829a011757Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3839a011757Smrg  # the same $tmpdepfile.
3849a011757Smrg  lockdir=$base.d-lock
3859a011757Smrg  trap "
3869a011757Smrg    echo '$0: caught signal, cleaning up...' >&2
3879a011757Smrg    rmdir '$lockdir'
3889a011757Smrg    exit 1
3899a011757Smrg  " 1 2 13 15
3909a011757Smrg  numtries=100
3919a011757Smrg  i=$numtries
3929a011757Smrg  while test $i -gt 0; do
3939a011757Smrg    # mkdir is a portable test-and-set.
3949a011757Smrg    if mkdir "$lockdir" 2>/dev/null; then
3959a011757Smrg      # This process acquired the lock.
3969a011757Smrg      "$@" -MD
3979a011757Smrg      stat=$?
3989a011757Smrg      # Release the lock.
3999a011757Smrg      rmdir "$lockdir"
4009a011757Smrg      break
4019a011757Smrg    else
4029a011757Smrg      # If the lock is being held by a different process, wait
4039a011757Smrg      # until the winning process is done or we timeout.
4049a011757Smrg      while test -d "$lockdir" && test $i -gt 0; do
4059a011757Smrg        sleep 1
4069a011757Smrg        i=`expr $i - 1`
4079a011757Smrg      done
4089a011757Smrg    fi
4099a011757Smrg    i=`expr $i - 1`
4109a011757Smrg  done
4119a011757Smrg  trap - 1 2 13 15
4129a011757Smrg  if test $i -le 0; then
4139a011757Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4149a011757Smrg    echo "$0: check lockdir '$lockdir'" >&2
4159a011757Smrg    exit 1
4169a011757Smrg  fi
4179a011757Smrg
4189a011757Smrg  if test $stat -ne 0; then
4197a0395d0Smrg    rm -f "$tmpdepfile"
4207a0395d0Smrg    exit $stat
4217a0395d0Smrg  fi
4227a0395d0Smrg  rm -f "$depfile"
4239a011757Smrg  # Each line is of the form `foo.o: dependent.h',
4249a011757Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4257a0395d0Smrg  # Do two passes, one to just change these to
4269a011757Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4279a011757Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4289a011757Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4299a011757Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
4309a011757Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4319a011757Smrg    | sed -e 's/$/ :/' >> "$depfile"
4327a0395d0Smrg  rm -f "$tmpdepfile"
4337a0395d0Smrg  ;;
4347a0395d0Smrg
4357a0395d0Smrghp2)
4367a0395d0Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4377a0395d0Smrg  # compilers, which have integrated preprocessors.  The correct option
4387a0395d0Smrg  # to use with these is +Maked; it writes dependencies to a file named
4397a0395d0Smrg  # 'foo.d', which lands next to the object file, wherever that
4407a0395d0Smrg  # happens to be.
4417a0395d0Smrg  # Much of this is similar to the tru64 case; see comments there.
4429a011757Smrg  set_dir_from  "$object"
4439a011757Smrg  set_base_from "$object"
4447a0395d0Smrg  if test "$libtool" = yes; then
4457a0395d0Smrg    tmpdepfile1=$dir$base.d
4467a0395d0Smrg    tmpdepfile2=$dir.libs/$base.d
4477a0395d0Smrg    "$@" -Wc,+Maked
4487a0395d0Smrg  else
4497a0395d0Smrg    tmpdepfile1=$dir$base.d
4507a0395d0Smrg    tmpdepfile2=$dir$base.d
4517a0395d0Smrg    "$@" +Maked
4527a0395d0Smrg  fi
4537a0395d0Smrg  stat=$?
4549a011757Smrg  if test $stat -ne 0; then
4557a0395d0Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4567a0395d0Smrg     exit $stat
4577a0395d0Smrg  fi
4587a0395d0Smrg
4597a0395d0Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4607a0395d0Smrg  do
4617a0395d0Smrg    test -f "$tmpdepfile" && break
4627a0395d0Smrg  done
4637a0395d0Smrg  if test -f "$tmpdepfile"; then
4649a011757Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4658abc0ccfSmrg    # Add 'dependent.h:' lines.
4667366012aSmrg    sed -ne '2,${
4679a011757Smrg               s/^ *//
4689a011757Smrg               s/ \\*$//
4699a011757Smrg               s/$/:/
4709a011757Smrg               p
4719a011757Smrg             }' "$tmpdepfile" >> "$depfile"
4727a0395d0Smrg  else
4739a011757Smrg    make_dummy_depfile
4747a0395d0Smrg  fi
4757a0395d0Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4767a0395d0Smrg  ;;
4777a0395d0Smrg
4787a0395d0Smrgtru64)
4799a011757Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4809a011757Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4819a011757Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4829a011757Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4839a011757Smrg  # Subdirectories are respected.
4849a011757Smrg  set_dir_from  "$object"
4859a011757Smrg  set_base_from "$object"
4869a011757Smrg
4879a011757Smrg  if test "$libtool" = yes; then
4889a011757Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4899a011757Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4909a011757Smrg    # in $dir$base.o.d.  We have to check for both files, because
4919a011757Smrg    # one of the two compilations can be disabled.  We should prefer
4929a011757Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4939a011757Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4949a011757Smrg    # the former would cause a distcleancheck panic.
4959a011757Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4969a011757Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4979a011757Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4989a011757Smrg    "$@" -Wc,-MD
4999a011757Smrg  else
5009a011757Smrg    tmpdepfile1=$dir$base.d
5019a011757Smrg    tmpdepfile2=$dir$base.d
5029a011757Smrg    tmpdepfile3=$dir$base.d
5039a011757Smrg    "$@" -MD
5049a011757Smrg  fi
5059a011757Smrg
5069a011757Smrg  stat=$?
5079a011757Smrg  if test $stat -ne 0; then
5089a011757Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5099a011757Smrg    exit $stat
5109a011757Smrg  fi
5119a011757Smrg
5129a011757Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5139a011757Smrg  do
5149a011757Smrg    test -f "$tmpdepfile" && break
5159a011757Smrg  done
5169a011757Smrg  # Same post-processing that is required for AIX mode.
5179a011757Smrg  aix_post_process_depfile
5189a011757Smrg  ;;
5197a0395d0Smrg
5208abc0ccfSmrgmsvc7)
5218abc0ccfSmrg  if test "$libtool" = yes; then
5228abc0ccfSmrg    showIncludes=-Wc,-showIncludes
5238abc0ccfSmrg  else
5248abc0ccfSmrg    showIncludes=-showIncludes
5258abc0ccfSmrg  fi
5268abc0ccfSmrg  "$@" $showIncludes > "$tmpdepfile"
5278abc0ccfSmrg  stat=$?
5288abc0ccfSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
5299a011757Smrg  if test $stat -ne 0; then
5308abc0ccfSmrg    rm -f "$tmpdepfile"
5318abc0ccfSmrg    exit $stat
5328abc0ccfSmrg  fi
5338abc0ccfSmrg  rm -f "$depfile"
5348abc0ccfSmrg  echo "$object : \\" > "$depfile"
5358abc0ccfSmrg  # The first sed program below extracts the file names and escapes
5368abc0ccfSmrg  # backslashes for cygpath.  The second sed program outputs the file
5378abc0ccfSmrg  # name when reading, but also accumulates all include files in the
5388abc0ccfSmrg  # hold buffer in order to output them again at the end.  This only
5398abc0ccfSmrg  # works with sed implementations that can handle large buffers.
5408abc0ccfSmrg  sed < "$tmpdepfile" -n '
5418abc0ccfSmrg/^Note: including file:  *\(.*\)/ {
5428abc0ccfSmrg  s//\1/
5438abc0ccfSmrg  s/\\/\\\\/g
5448abc0ccfSmrg  p
5458abc0ccfSmrg}' | $cygpath_u | sort -u | sed -n '
5468abc0ccfSmrgs/ /\\ /g
5478abc0ccfSmrgs/\(.*\)/'"$tab"'\1 \\/p
5488abc0ccfSmrgs/.\(.*\) \\/\1:/
5498abc0ccfSmrgH
5508abc0ccfSmrg$ {
5518abc0ccfSmrg  s/.*/'"$tab"'/
5528abc0ccfSmrg  G
5538abc0ccfSmrg  p
5548abc0ccfSmrg}' >> "$depfile"
5559a011757Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5568abc0ccfSmrg  rm -f "$tmpdepfile"
5578abc0ccfSmrg  ;;
5588abc0ccfSmrg
5598abc0ccfSmrgmsvc7msys)
5608abc0ccfSmrg  # This case exists only to let depend.m4 do its work.  It works by
5618abc0ccfSmrg  # looking at the text of this script.  This case will never be run,
5628abc0ccfSmrg  # since it is checked for above.
5638abc0ccfSmrg  exit 1
5648abc0ccfSmrg  ;;
5658abc0ccfSmrg
5667a0395d0Smrg#nosideeffect)
5677a0395d0Smrg  # This comment above is used by automake to tell side-effect
5687a0395d0Smrg  # dependency tracking mechanisms from slower ones.
5697a0395d0Smrg
5707a0395d0Smrgdashmstdout)
5717a0395d0Smrg  # Important note: in order to support this mode, a compiler *must*
5727a0395d0Smrg  # always write the preprocessed file to stdout, regardless of -o.
5737a0395d0Smrg  "$@" || exit $?
5747a0395d0Smrg
5757a0395d0Smrg  # Remove the call to Libtool.
5767a0395d0Smrg  if test "$libtool" = yes; then
5777366012aSmrg    while test "X$1" != 'X--mode=compile'; do
5787a0395d0Smrg      shift
5797a0395d0Smrg    done
5807a0395d0Smrg    shift
5817a0395d0Smrg  fi
5827a0395d0Smrg
5838abc0ccfSmrg  # Remove '-o $object'.
5847a0395d0Smrg  IFS=" "
5857a0395d0Smrg  for arg
5867a0395d0Smrg  do
5877a0395d0Smrg    case $arg in
5887a0395d0Smrg    -o)
5897a0395d0Smrg      shift
5907a0395d0Smrg      ;;
5917a0395d0Smrg    $object)
5927a0395d0Smrg      shift
5937a0395d0Smrg      ;;
5947a0395d0Smrg    *)
5957a0395d0Smrg      set fnord "$@" "$arg"
5967a0395d0Smrg      shift # fnord
5977a0395d0Smrg      shift # $arg
5987a0395d0Smrg      ;;
5997a0395d0Smrg    esac
6007a0395d0Smrg  done
6017a0395d0Smrg
6027a0395d0Smrg  test -z "$dashmflag" && dashmflag=-M
6038abc0ccfSmrg  # Require at least two characters before searching for ':'
6047a0395d0Smrg  # in the target name.  This is to cope with DOS-style filenames:
6058abc0ccfSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6067a0395d0Smrg  "$@" $dashmflag |
6079a011757Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6087a0395d0Smrg  rm -f "$depfile"
6097a0395d0Smrg  cat < "$tmpdepfile" > "$depfile"
6109a011757Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6119a011757Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6129a011757Smrg  tr ' ' "$nl" < "$tmpdepfile" \
6139a011757Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6149a011757Smrg    | sed -e 's/$/ :/' >> "$depfile"
6157a0395d0Smrg  rm -f "$tmpdepfile"
6167a0395d0Smrg  ;;
6177a0395d0Smrg
6187a0395d0SmrgdashXmstdout)
6197a0395d0Smrg  # This case only exists to satisfy depend.m4.  It is never actually
6207a0395d0Smrg  # run, as this mode is specially recognized in the preamble.
6217a0395d0Smrg  exit 1
6227a0395d0Smrg  ;;
6237a0395d0Smrg
6247a0395d0Smrgmakedepend)
6257a0395d0Smrg  "$@" || exit $?
6267a0395d0Smrg  # Remove any Libtool call
6277a0395d0Smrg  if test "$libtool" = yes; then
6287366012aSmrg    while test "X$1" != 'X--mode=compile'; do
6297a0395d0Smrg      shift
6307a0395d0Smrg    done
6317a0395d0Smrg    shift
6327a0395d0Smrg  fi
6337a0395d0Smrg  # X makedepend
6347a0395d0Smrg  shift
6357366012aSmrg  cleared=no eat=no
6367366012aSmrg  for arg
6377366012aSmrg  do
6387a0395d0Smrg    case $cleared in
6397a0395d0Smrg    no)
6407a0395d0Smrg      set ""; shift
6417a0395d0Smrg      cleared=yes ;;
6427a0395d0Smrg    esac
6437366012aSmrg    if test $eat = yes; then
6447366012aSmrg      eat=no
6457366012aSmrg      continue
6467366012aSmrg    fi
6477a0395d0Smrg    case "$arg" in
6487a0395d0Smrg    -D*|-I*)
6497a0395d0Smrg      set fnord "$@" "$arg"; shift ;;
6507a0395d0Smrg    # Strip any option that makedepend may not understand.  Remove
6517a0395d0Smrg    # the object too, otherwise makedepend will parse it as a source file.
6527366012aSmrg    -arch)
6537366012aSmrg      eat=yes ;;
6547a0395d0Smrg    -*|$object)
6557a0395d0Smrg      ;;
6567a0395d0Smrg    *)
6577a0395d0Smrg      set fnord "$@" "$arg"; shift ;;
6587a0395d0Smrg    esac
6597a0395d0Smrg  done
6607366012aSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6617a0395d0Smrg  touch "$tmpdepfile"
6627a0395d0Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6637a0395d0Smrg  rm -f "$depfile"
6648abc0ccfSmrg  # makedepend may prepend the VPATH from the source file name to the object.
6658abc0ccfSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6668abc0ccfSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6679a011757Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6689a011757Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6699a011757Smrg  sed '1,2d' "$tmpdepfile" \
6709a011757Smrg    | tr ' ' "$nl" \
6719a011757Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6729a011757Smrg    | sed -e 's/$/ :/' >> "$depfile"
6737a0395d0Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6747a0395d0Smrg  ;;
6757a0395d0Smrg
6767a0395d0Smrgcpp)
6777a0395d0Smrg  # Important note: in order to support this mode, a compiler *must*
6787a0395d0Smrg  # always write the preprocessed file to stdout.
6797a0395d0Smrg  "$@" || exit $?
6807a0395d0Smrg
6817a0395d0Smrg  # Remove the call to Libtool.
6827a0395d0Smrg  if test "$libtool" = yes; then
6837366012aSmrg    while test "X$1" != 'X--mode=compile'; do
6847a0395d0Smrg      shift
6857a0395d0Smrg    done
6867a0395d0Smrg    shift
6877a0395d0Smrg  fi
6887a0395d0Smrg
6898abc0ccfSmrg  # Remove '-o $object'.
6907a0395d0Smrg  IFS=" "
6917a0395d0Smrg  for arg
6927a0395d0Smrg  do
6937a0395d0Smrg    case $arg in
6947a0395d0Smrg    -o)
6957a0395d0Smrg      shift
6967a0395d0Smrg      ;;
6977a0395d0Smrg    $object)
6987a0395d0Smrg      shift
6997a0395d0Smrg      ;;
7007a0395d0Smrg    *)
7017a0395d0Smrg      set fnord "$@" "$arg"
7027a0395d0Smrg      shift # fnord
7037a0395d0Smrg      shift # $arg
7047a0395d0Smrg      ;;
7057a0395d0Smrg    esac
7067a0395d0Smrg  done
7077a0395d0Smrg
7089a011757Smrg  "$@" -E \
7099a011757Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7109a011757Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7119a011757Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
7127a0395d0Smrg  rm -f "$depfile"
7137a0395d0Smrg  echo "$object : \\" > "$depfile"
7147a0395d0Smrg  cat < "$tmpdepfile" >> "$depfile"
7157a0395d0Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7167a0395d0Smrg  rm -f "$tmpdepfile"
7177a0395d0Smrg  ;;
7187a0395d0Smrg
7197a0395d0Smrgmsvisualcpp)
7207a0395d0Smrg  # Important note: in order to support this mode, a compiler *must*
7217366012aSmrg  # always write the preprocessed file to stdout.
7227a0395d0Smrg  "$@" || exit $?
7237366012aSmrg
7247366012aSmrg  # Remove the call to Libtool.
7257366012aSmrg  if test "$libtool" = yes; then
7267366012aSmrg    while test "X$1" != 'X--mode=compile'; do
7277366012aSmrg      shift
7287366012aSmrg    done
7297366012aSmrg    shift
7307366012aSmrg  fi
7317366012aSmrg
7327a0395d0Smrg  IFS=" "
7337a0395d0Smrg  for arg
7347a0395d0Smrg  do
7357a0395d0Smrg    case "$arg" in
7367366012aSmrg    -o)
7377366012aSmrg      shift
7387366012aSmrg      ;;
7397366012aSmrg    $object)
7407366012aSmrg      shift
7417366012aSmrg      ;;
7427a0395d0Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7439a011757Smrg        set fnord "$@"
7449a011757Smrg        shift
7459a011757Smrg        shift
7469a011757Smrg        ;;
7477a0395d0Smrg    *)
7489a011757Smrg        set fnord "$@" "$arg"
7499a011757Smrg        shift
7509a011757Smrg        shift
7519a011757Smrg        ;;
7527a0395d0Smrg    esac
7537a0395d0Smrg  done
7547366012aSmrg  "$@" -E 2>/dev/null |
7557366012aSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7567a0395d0Smrg  rm -f "$depfile"
7577a0395d0Smrg  echo "$object : \\" > "$depfile"
7588abc0ccfSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7598abc0ccfSmrg  echo "$tab" >> "$depfile"
7607366012aSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7617a0395d0Smrg  rm -f "$tmpdepfile"
7627a0395d0Smrg  ;;
7637a0395d0Smrg
7647366012aSmrgmsvcmsys)
7657366012aSmrg  # This case exists only to let depend.m4 do its work.  It works by
7667366012aSmrg  # looking at the text of this script.  This case will never be run,
7677366012aSmrg  # since it is checked for above.
7687366012aSmrg  exit 1
7697366012aSmrg  ;;
7707366012aSmrg
7717a0395d0Smrgnone)
7727a0395d0Smrg  exec "$@"
7737a0395d0Smrg  ;;
7747a0395d0Smrg
7757a0395d0Smrg*)
7767a0395d0Smrg  echo "Unknown depmode $depmode" 1>&2
7777a0395d0Smrg  exit 1
7787a0395d0Smrg  ;;
7797a0395d0Smrgesac
7807a0395d0Smrg
7817a0395d0Smrgexit 0
7827a0395d0Smrg
7837a0395d0Smrg# Local Variables:
7847a0395d0Smrg# mode: shell-script
7857a0395d0Smrg# sh-indentation: 2
7866c3c2bceSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
7877a0395d0Smrg# time-stamp-start: "scriptversion="
7887a0395d0Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7896c3c2bceSmrg# time-stamp-time-zone: "UTC0"
7907366012aSmrg# time-stamp-end: "; # UTC"
7917a0395d0Smrg# End:
792