14456fccdSmrg#! /bin/sh
24456fccdSmrg# depcomp - compile a program generating dependencies as side-effects
34456fccdSmrg
4b0a0317aSmrgscriptversion=2018-03-07.03; # UTC
54456fccdSmrg
6a7e741d5Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
74456fccdSmrg
84456fccdSmrg# This program is free software; you can redistribute it and/or modify
94456fccdSmrg# it under the terms of the GNU General Public License as published by
104456fccdSmrg# the Free Software Foundation; either version 2, or (at your option)
114456fccdSmrg# any later version.
124456fccdSmrg
134456fccdSmrg# This program is distributed in the hope that it will be useful,
144456fccdSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
154456fccdSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
164456fccdSmrg# GNU General Public License for more details.
174456fccdSmrg
184456fccdSmrg# You should have received a copy of the GNU General Public License
19b0a0317aSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
204456fccdSmrg
214456fccdSmrg# As a special exception to the GNU General Public License, if you
224456fccdSmrg# distribute this file as part of a program that contains a
234456fccdSmrg# configuration script generated by Autoconf, you may include it under
244456fccdSmrg# the same distribution terms that you use for the rest of that program.
254456fccdSmrg
264456fccdSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
274456fccdSmrg
284456fccdSmrgcase $1 in
294456fccdSmrg  '')
303e6c936aSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
313e6c936aSmrg    exit 1;
323e6c936aSmrg    ;;
334456fccdSmrg  -h | --h*)
344456fccdSmrg    cat <<\EOF
354456fccdSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
364456fccdSmrg
374456fccdSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
384456fccdSmrgas side-effects.
394456fccdSmrg
404456fccdSmrgEnvironment variables:
414456fccdSmrg  depmode     Dependency tracking mode.
423e6c936aSmrg  source      Source file read by 'PROGRAMS ARGS'.
433e6c936aSmrg  object      Object file output by 'PROGRAMS ARGS'.
444456fccdSmrg  DEPDIR      directory where to store dependencies.
454456fccdSmrg  depfile     Dependency file to output.
463e6c936aSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
474456fccdSmrg  libtool     Whether libtool is used (yes/no).
484456fccdSmrg
494456fccdSmrgReport bugs to <bug-automake@gnu.org>.
504456fccdSmrgEOF
514456fccdSmrg    exit $?
524456fccdSmrg    ;;
534456fccdSmrg  -v | --v*)
544456fccdSmrg    echo "depcomp $scriptversion"
554456fccdSmrg    exit $?
564456fccdSmrg    ;;
574456fccdSmrgesac
584456fccdSmrg
593e6c936aSmrg# Get the directory component of the given path, and save it in the
603e6c936aSmrg# global variables '$dir'.  Note that this directory component will
613e6c936aSmrg# be either empty or ending with a '/' character.  This is deliberate.
623e6c936aSmrgset_dir_from ()
633e6c936aSmrg{
643e6c936aSmrg  case $1 in
653e6c936aSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
663e6c936aSmrg      *) dir=;;
673e6c936aSmrg  esac
683e6c936aSmrg}
693e6c936aSmrg
703e6c936aSmrg# Get the suffix-stripped basename of the given path, and save it the
713e6c936aSmrg# global variable '$base'.
723e6c936aSmrgset_base_from ()
733e6c936aSmrg{
743e6c936aSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
753e6c936aSmrg}
763e6c936aSmrg
773e6c936aSmrg# If no dependency file was actually created by the compiler invocation,
783e6c936aSmrg# we still have to create a dummy depfile, to avoid errors with the
793e6c936aSmrg# Makefile "include basename.Plo" scheme.
803e6c936aSmrgmake_dummy_depfile ()
813e6c936aSmrg{
823e6c936aSmrg  echo "#dummy" > "$depfile"
833e6c936aSmrg}
843e6c936aSmrg
853e6c936aSmrg# Factor out some common post-processing of the generated depfile.
863e6c936aSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
873e6c936aSmrgaix_post_process_depfile ()
883e6c936aSmrg{
893e6c936aSmrg  # If the compiler actually managed to produce a dependency file,
903e6c936aSmrg  # post-process it.
913e6c936aSmrg  if test -f "$tmpdepfile"; then
923e6c936aSmrg    # Each line is of the form 'foo.o: dependency.h'.
933e6c936aSmrg    # Do two passes, one to just change these to
943e6c936aSmrg    #   $object: dependency.h
953e6c936aSmrg    # and one to simply output
963e6c936aSmrg    #   dependency.h:
973e6c936aSmrg    # which is needed to avoid the deleted-header problem.
983e6c936aSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
993e6c936aSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1003e6c936aSmrg    } > "$depfile"
1013e6c936aSmrg    rm -f "$tmpdepfile"
1023e6c936aSmrg  else
1033e6c936aSmrg    make_dummy_depfile
1043e6c936aSmrg  fi
1053e6c936aSmrg}
1063e6c936aSmrg
1073e6c936aSmrg# A tabulation character.
1083e6c936aSmrgtab='	'
1093e6c936aSmrg# A newline character.
1103e6c936aSmrgnl='
1113e6c936aSmrg'
1123e6c936aSmrg# Character ranges might be problematic outside the C locale.
1133e6c936aSmrg# These definitions help.
1143e6c936aSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1153e6c936aSmrglower=abcdefghijklmnopqrstuvwxyz
1163e6c936aSmrgdigits=0123456789
1173e6c936aSmrgalpha=${upper}${lower}
1183e6c936aSmrg
1194456fccdSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1204456fccdSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1214456fccdSmrg  exit 1
1224456fccdSmrgfi
1234456fccdSmrg
1244456fccdSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1254456fccdSmrgdepfile=${depfile-`echo "$object" |
1264456fccdSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1274456fccdSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1284456fccdSmrg
1294456fccdSmrgrm -f "$tmpdepfile"
1304456fccdSmrg
1313e6c936aSmrg# Avoid interferences from the environment.
1323e6c936aSmrggccflag= dashmflag=
1333e6c936aSmrg
1344456fccdSmrg# Some modes work just like other modes, but use different flags.  We
1354456fccdSmrg# parameterize here, but still list the modes in the big case below,
1364456fccdSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1374456fccdSmrg# here, because this file can only contain one case statement.
1384456fccdSmrgif test "$depmode" = hp; then
1394456fccdSmrg  # HP compiler uses -M and no extra arg.
1404456fccdSmrg  gccflag=-M
1414456fccdSmrg  depmode=gcc
1424456fccdSmrgfi
1434456fccdSmrg
1444456fccdSmrgif test "$depmode" = dashXmstdout; then
1453e6c936aSmrg  # This is just like dashmstdout with a different argument.
1463e6c936aSmrg  dashmflag=-xM
1473e6c936aSmrg  depmode=dashmstdout
1484456fccdSmrgfi
1494456fccdSmrg
15042d69509Smrgcygpath_u="cygpath -u -f -"
15142d69509Smrgif test "$depmode" = msvcmsys; then
1523e6c936aSmrg  # This is just like msvisualcpp but w/o cygpath translation.
1533e6c936aSmrg  # Just convert the backslash-escaped backslashes to single forward
1543e6c936aSmrg  # slashes to satisfy depend.m4
1553e6c936aSmrg  cygpath_u='sed s,\\\\,/,g'
1563e6c936aSmrg  depmode=msvisualcpp
1573e6c936aSmrgfi
1583e6c936aSmrg
1593e6c936aSmrgif test "$depmode" = msvc7msys; then
1603e6c936aSmrg  # This is just like msvc7 but w/o cygpath translation.
1613e6c936aSmrg  # Just convert the backslash-escaped backslashes to single forward
1623e6c936aSmrg  # slashes to satisfy depend.m4
1633e6c936aSmrg  cygpath_u='sed s,\\\\,/,g'
1643e6c936aSmrg  depmode=msvc7
1653e6c936aSmrgfi
1663e6c936aSmrg
1673e6c936aSmrgif test "$depmode" = xlc; then
1683e6c936aSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1693e6c936aSmrg  gccflag=-qmakedep=gcc,-MF
1703e6c936aSmrg  depmode=gcc
17142d69509Smrgfi
17242d69509Smrg
1734456fccdSmrgcase "$depmode" in
1744456fccdSmrggcc3)
1754456fccdSmrg## gcc 3 implements dependency tracking that does exactly what
1764456fccdSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1774456fccdSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
17842d69509Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
17942d69509Smrg## the command line argument order; so add the flags where they
18042d69509Smrg## appear in depend2.am.  Note that the slowdown incurred here
18142d69509Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
18242d69509Smrg  for arg
18342d69509Smrg  do
18442d69509Smrg    case $arg in
18542d69509Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
18642d69509Smrg    *)  set fnord "$@" "$arg" ;;
18742d69509Smrg    esac
18842d69509Smrg    shift # fnord
18942d69509Smrg    shift # $arg
19042d69509Smrg  done
19142d69509Smrg  "$@"
1924456fccdSmrg  stat=$?
1933e6c936aSmrg  if test $stat -ne 0; then
1944456fccdSmrg    rm -f "$tmpdepfile"
1954456fccdSmrg    exit $stat
1964456fccdSmrg  fi
1974456fccdSmrg  mv "$tmpdepfile" "$depfile"
1984456fccdSmrg  ;;
1994456fccdSmrg
2004456fccdSmrggcc)
2013e6c936aSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2023e6c936aSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2033e6c936aSmrg## (see the conditional assignment to $gccflag above).
2044456fccdSmrg## There are various ways to get dependency output from gcc.  Here's
2054456fccdSmrg## why we pick this rather obscure method:
2064456fccdSmrg## - Don't want to use -MD because we'd like the dependencies to end
2074456fccdSmrg##   up in a subdir.  Having to rename by hand is ugly.
2084456fccdSmrg##   (We might end up doing this anyway to support other compilers.)
2094456fccdSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2103e6c936aSmrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2113e6c936aSmrg##   supported by the other compilers which use the 'gcc' depmode.
2124456fccdSmrg## - Using -M directly means running the compiler twice (even worse
2134456fccdSmrg##   than renaming).
2144456fccdSmrg  if test -z "$gccflag"; then
2154456fccdSmrg    gccflag=-MD,
2164456fccdSmrg  fi
2174456fccdSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
2184456fccdSmrg  stat=$?
2193e6c936aSmrg  if test $stat -ne 0; then
2204456fccdSmrg    rm -f "$tmpdepfile"
2214456fccdSmrg    exit $stat
2224456fccdSmrg  fi
2234456fccdSmrg  rm -f "$depfile"
2244456fccdSmrg  echo "$object : \\" > "$depfile"
2253e6c936aSmrg  # The second -e expression handles DOS-style file names with drive
2263e6c936aSmrg  # letters.
2274456fccdSmrg  sed -e 's/^[^:]*: / /' \
2284456fccdSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2293e6c936aSmrg## This next piece of magic avoids the "deleted header file" problem.
2304456fccdSmrg## The problem is that when a header file which appears in a .P file
2314456fccdSmrg## is deleted, the dependency causes make to die (because there is
2324456fccdSmrg## typically no way to rebuild the header).  We avoid this by adding
2334456fccdSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2344456fccdSmrg## this for us directly.
2353e6c936aSmrg## Some versions of gcc put a space before the ':'.  On the theory
2364456fccdSmrg## that the space means something, we add a space to the output as
2373e6c936aSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2383e6c936aSmrg## to the object.  Take care to not repeat it in the output.
2394456fccdSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
2404456fccdSmrg## correctly.  Breaking it into two sed invocations is a workaround.
2413e6c936aSmrg  tr ' ' "$nl" < "$tmpdepfile" \
2423e6c936aSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2433e6c936aSmrg    | sed -e 's/$/ :/' >> "$depfile"
2444456fccdSmrg  rm -f "$tmpdepfile"
2454456fccdSmrg  ;;
2464456fccdSmrg
2474456fccdSmrghp)
2484456fccdSmrg  # This case exists only to let depend.m4 do its work.  It works by
2494456fccdSmrg  # looking at the text of this script.  This case will never be run,
2504456fccdSmrg  # since it is checked for above.
2514456fccdSmrg  exit 1
2524456fccdSmrg  ;;
2534456fccdSmrg
2544456fccdSmrgsgi)
2554456fccdSmrg  if test "$libtool" = yes; then
2564456fccdSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2574456fccdSmrg  else
2584456fccdSmrg    "$@" -MDupdate "$tmpdepfile"
2594456fccdSmrg  fi
2604456fccdSmrg  stat=$?
2613e6c936aSmrg  if test $stat -ne 0; then
2624456fccdSmrg    rm -f "$tmpdepfile"
2634456fccdSmrg    exit $stat
2644456fccdSmrg  fi
2654456fccdSmrg  rm -f "$depfile"
2664456fccdSmrg
2674456fccdSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2684456fccdSmrg    echo "$object : \\" > "$depfile"
2694456fccdSmrg    # Clip off the initial element (the dependent).  Don't try to be
2704456fccdSmrg    # clever and replace this with sed code, as IRIX sed won't handle
2714456fccdSmrg    # lines with more than a fixed number of characters (4096 in
2724456fccdSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2733e6c936aSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
2744456fccdSmrg    # dependency line.
2753e6c936aSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2763e6c936aSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2773e6c936aSmrg      | tr "$nl" ' ' >> "$depfile"
27842d69509Smrg    echo >> "$depfile"
2794456fccdSmrg    # The second pass generates a dummy entry for each header file.
2803e6c936aSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2813e6c936aSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2823e6c936aSmrg      >> "$depfile"
2834456fccdSmrg  else
2843e6c936aSmrg    make_dummy_depfile
2854456fccdSmrg  fi
2864456fccdSmrg  rm -f "$tmpdepfile"
2874456fccdSmrg  ;;
2884456fccdSmrg
2893e6c936aSmrgxlc)
2903e6c936aSmrg  # This case exists only to let depend.m4 do its work.  It works by
2913e6c936aSmrg  # looking at the text of this script.  This case will never be run,
2923e6c936aSmrg  # since it is checked for above.
2933e6c936aSmrg  exit 1
2943e6c936aSmrg  ;;
2953e6c936aSmrg
2964456fccdSmrgaix)
2974456fccdSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
2984456fccdSmrg  # in a .u file.  In older versions, this file always lives in the
2993e6c936aSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3004456fccdSmrg  # start of each line; $object doesn't have directory information.
3014456fccdSmrg  # Version 6 uses the directory in both cases.
3023e6c936aSmrg  set_dir_from "$object"
3033e6c936aSmrg  set_base_from "$object"
3044456fccdSmrg  if test "$libtool" = yes; then
30542d69509Smrg    tmpdepfile1=$dir$base.u
30642d69509Smrg    tmpdepfile2=$base.u
30742d69509Smrg    tmpdepfile3=$dir.libs/$base.u
3084456fccdSmrg    "$@" -Wc,-M
3094456fccdSmrg  else
31042d69509Smrg    tmpdepfile1=$dir$base.u
31142d69509Smrg    tmpdepfile2=$dir$base.u
31242d69509Smrg    tmpdepfile3=$dir$base.u
3134456fccdSmrg    "$@" -M
3144456fccdSmrg  fi
3154456fccdSmrg  stat=$?
3163e6c936aSmrg  if test $stat -ne 0; then
31742d69509Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3184456fccdSmrg    exit $stat
3194456fccdSmrg  fi
3204456fccdSmrg
32142d69509Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
32242d69509Smrg  do
32342d69509Smrg    test -f "$tmpdepfile" && break
32442d69509Smrg  done
3253e6c936aSmrg  aix_post_process_depfile
3263e6c936aSmrg  ;;
3273e6c936aSmrg
3283e6c936aSmrgtcc)
3293e6c936aSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3303e6c936aSmrg  # FIXME: That version still under development at the moment of writing.
3313e6c936aSmrg  #        Make that this statement remains true also for stable, released
3323e6c936aSmrg  #        versions.
3333e6c936aSmrg  # It will wrap lines (doesn't matter whether long or short) with a
3343e6c936aSmrg  # trailing '\', as in:
3353e6c936aSmrg  #
3363e6c936aSmrg  #   foo.o : \
3373e6c936aSmrg  #    foo.c \
3383e6c936aSmrg  #    foo.h \
3393e6c936aSmrg  #
3403e6c936aSmrg  # It will put a trailing '\' even on the last line, and will use leading
3413e6c936aSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3423e6c936aSmrg  # "Emit spaces for -MD").
3433e6c936aSmrg  "$@" -MD -MF "$tmpdepfile"
3443e6c936aSmrg  stat=$?
3453e6c936aSmrg  if test $stat -ne 0; then
3463e6c936aSmrg    rm -f "$tmpdepfile"
3473e6c936aSmrg    exit $stat
3484456fccdSmrg  fi
3493e6c936aSmrg  rm -f "$depfile"
3503e6c936aSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3513e6c936aSmrg  # We have to change lines of the first kind to '$object: \'.
3523e6c936aSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3533e6c936aSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3543e6c936aSmrg  # dummy dependency, to avoid the deleted-header problem.
3553e6c936aSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3564456fccdSmrg  rm -f "$tmpdepfile"
3574456fccdSmrg  ;;
3584456fccdSmrg
3593e6c936aSmrg## The order of this option in the case statement is important, since the
3603e6c936aSmrg## shell code in configure will try each of these formats in the order
3613e6c936aSmrg## listed in this file.  A plain '-MD' option would be understood by many
3623e6c936aSmrg## compilers, so we must ensure this comes after the gcc and icc options.
3633e6c936aSmrgpgcc)
3643e6c936aSmrg  # Portland's C compiler understands '-MD'.
3653e6c936aSmrg  # Will always output deps to 'file.d' where file is the root name of the
3663e6c936aSmrg  # source file under compilation, even if file resides in a subdirectory.
3673e6c936aSmrg  # The object file name does not affect the name of the '.d' file.
3683e6c936aSmrg  # pgcc 10.2 will output
3694456fccdSmrg  #    foo.o: sub/foo.c sub/foo.h
3703e6c936aSmrg  # and will wrap long lines using '\' :
3714456fccdSmrg  #    foo.o: sub/foo.c ... \
3724456fccdSmrg  #     sub/foo.h ... \
3734456fccdSmrg  #     ...
3743e6c936aSmrg  set_dir_from "$object"
3753e6c936aSmrg  # Use the source, not the object, to determine the base name, since
3763e6c936aSmrg  # that's sadly what pgcc will do too.
3773e6c936aSmrg  set_base_from "$source"
3783e6c936aSmrg  tmpdepfile=$base.d
3793e6c936aSmrg
3803e6c936aSmrg  # For projects that build the same source file twice into different object
3813e6c936aSmrg  # files, the pgcc approach of using the *source* file root name can cause
3823e6c936aSmrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3833e6c936aSmrg  # the same $tmpdepfile.
3843e6c936aSmrg  lockdir=$base.d-lock
3853e6c936aSmrg  trap "
3863e6c936aSmrg    echo '$0: caught signal, cleaning up...' >&2
3873e6c936aSmrg    rmdir '$lockdir'
3883e6c936aSmrg    exit 1
3893e6c936aSmrg  " 1 2 13 15
3903e6c936aSmrg  numtries=100
3913e6c936aSmrg  i=$numtries
3923e6c936aSmrg  while test $i -gt 0; do
3933e6c936aSmrg    # mkdir is a portable test-and-set.
3943e6c936aSmrg    if mkdir "$lockdir" 2>/dev/null; then
3953e6c936aSmrg      # This process acquired the lock.
3963e6c936aSmrg      "$@" -MD
3973e6c936aSmrg      stat=$?
3983e6c936aSmrg      # Release the lock.
3993e6c936aSmrg      rmdir "$lockdir"
4003e6c936aSmrg      break
4013e6c936aSmrg    else
4023e6c936aSmrg      # If the lock is being held by a different process, wait
4033e6c936aSmrg      # until the winning process is done or we timeout.
4043e6c936aSmrg      while test -d "$lockdir" && test $i -gt 0; do
4053e6c936aSmrg        sleep 1
4063e6c936aSmrg        i=`expr $i - 1`
4073e6c936aSmrg      done
4083e6c936aSmrg    fi
4093e6c936aSmrg    i=`expr $i - 1`
4103e6c936aSmrg  done
4113e6c936aSmrg  trap - 1 2 13 15
4123e6c936aSmrg  if test $i -le 0; then
4133e6c936aSmrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4143e6c936aSmrg    echo "$0: check lockdir '$lockdir'" >&2
4153e6c936aSmrg    exit 1
4163e6c936aSmrg  fi
4174456fccdSmrg
4183e6c936aSmrg  if test $stat -ne 0; then
4194456fccdSmrg    rm -f "$tmpdepfile"
4204456fccdSmrg    exit $stat
4214456fccdSmrg  fi
4224456fccdSmrg  rm -f "$depfile"
4234456fccdSmrg  # Each line is of the form `foo.o: dependent.h',
4244456fccdSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4254456fccdSmrg  # Do two passes, one to just change these to
4264456fccdSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4274456fccdSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4284456fccdSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4294456fccdSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
4303e6c936aSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4313e6c936aSmrg    | sed -e 's/$/ :/' >> "$depfile"
4324456fccdSmrg  rm -f "$tmpdepfile"
4334456fccdSmrg  ;;
4344456fccdSmrg
43542d69509Smrghp2)
43642d69509Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
43742d69509Smrg  # compilers, which have integrated preprocessors.  The correct option
43842d69509Smrg  # to use with these is +Maked; it writes dependencies to a file named
43942d69509Smrg  # 'foo.d', which lands next to the object file, wherever that
44042d69509Smrg  # happens to be.
44142d69509Smrg  # Much of this is similar to the tru64 case; see comments there.
4423e6c936aSmrg  set_dir_from  "$object"
4433e6c936aSmrg  set_base_from "$object"
44442d69509Smrg  if test "$libtool" = yes; then
44542d69509Smrg    tmpdepfile1=$dir$base.d
44642d69509Smrg    tmpdepfile2=$dir.libs/$base.d
44742d69509Smrg    "$@" -Wc,+Maked
44842d69509Smrg  else
44942d69509Smrg    tmpdepfile1=$dir$base.d
45042d69509Smrg    tmpdepfile2=$dir$base.d
45142d69509Smrg    "$@" +Maked
45242d69509Smrg  fi
45342d69509Smrg  stat=$?
4543e6c936aSmrg  if test $stat -ne 0; then
45542d69509Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
45642d69509Smrg     exit $stat
45742d69509Smrg  fi
45842d69509Smrg
45942d69509Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
46042d69509Smrg  do
46142d69509Smrg    test -f "$tmpdepfile" && break
46242d69509Smrg  done
46342d69509Smrg  if test -f "$tmpdepfile"; then
4643e6c936aSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4653e6c936aSmrg    # Add 'dependent.h:' lines.
46642d69509Smrg    sed -ne '2,${
4673e6c936aSmrg               s/^ *//
4683e6c936aSmrg               s/ \\*$//
4693e6c936aSmrg               s/$/:/
4703e6c936aSmrg               p
4713e6c936aSmrg             }' "$tmpdepfile" >> "$depfile"
47242d69509Smrg  else
4733e6c936aSmrg    make_dummy_depfile
47442d69509Smrg  fi
47542d69509Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
47642d69509Smrg  ;;
47742d69509Smrg
4784456fccdSmrgtru64)
4793e6c936aSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4803e6c936aSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4813e6c936aSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4823e6c936aSmrg  # dependencies in 'foo.d' instead, so we check for that too.
4833e6c936aSmrg  # Subdirectories are respected.
4843e6c936aSmrg  set_dir_from  "$object"
4853e6c936aSmrg  set_base_from "$object"
4863e6c936aSmrg
4873e6c936aSmrg  if test "$libtool" = yes; then
4883e6c936aSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4893e6c936aSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4903e6c936aSmrg    # in $dir$base.o.d.  We have to check for both files, because
4913e6c936aSmrg    # one of the two compilations can be disabled.  We should prefer
4923e6c936aSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4933e6c936aSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
4943e6c936aSmrg    # the former would cause a distcleancheck panic.
4953e6c936aSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4963e6c936aSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4973e6c936aSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4983e6c936aSmrg    "$@" -Wc,-MD
4993e6c936aSmrg  else
5003e6c936aSmrg    tmpdepfile1=$dir$base.d
5013e6c936aSmrg    tmpdepfile2=$dir$base.d
5023e6c936aSmrg    tmpdepfile3=$dir$base.d
5033e6c936aSmrg    "$@" -MD
5043e6c936aSmrg  fi
5053e6c936aSmrg
5063e6c936aSmrg  stat=$?
5073e6c936aSmrg  if test $stat -ne 0; then
5083e6c936aSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5093e6c936aSmrg    exit $stat
5103e6c936aSmrg  fi
5113e6c936aSmrg
5123e6c936aSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5133e6c936aSmrg  do
5143e6c936aSmrg    test -f "$tmpdepfile" && break
5153e6c936aSmrg  done
5163e6c936aSmrg  # Same post-processing that is required for AIX mode.
5173e6c936aSmrg  aix_post_process_depfile
5183e6c936aSmrg  ;;
5193e6c936aSmrg
5203e6c936aSmrgmsvc7)
5213e6c936aSmrg  if test "$libtool" = yes; then
5223e6c936aSmrg    showIncludes=-Wc,-showIncludes
5233e6c936aSmrg  else
5243e6c936aSmrg    showIncludes=-showIncludes
5253e6c936aSmrg  fi
5263e6c936aSmrg  "$@" $showIncludes > "$tmpdepfile"
5273e6c936aSmrg  stat=$?
5283e6c936aSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
5293e6c936aSmrg  if test $stat -ne 0; then
5303e6c936aSmrg    rm -f "$tmpdepfile"
5313e6c936aSmrg    exit $stat
5323e6c936aSmrg  fi
5333e6c936aSmrg  rm -f "$depfile"
5343e6c936aSmrg  echo "$object : \\" > "$depfile"
5353e6c936aSmrg  # The first sed program below extracts the file names and escapes
5363e6c936aSmrg  # backslashes for cygpath.  The second sed program outputs the file
5373e6c936aSmrg  # name when reading, but also accumulates all include files in the
5383e6c936aSmrg  # hold buffer in order to output them again at the end.  This only
5393e6c936aSmrg  # works with sed implementations that can handle large buffers.
5403e6c936aSmrg  sed < "$tmpdepfile" -n '
5413e6c936aSmrg/^Note: including file:  *\(.*\)/ {
5423e6c936aSmrg  s//\1/
5433e6c936aSmrg  s/\\/\\\\/g
5443e6c936aSmrg  p
5453e6c936aSmrg}' | $cygpath_u | sort -u | sed -n '
5463e6c936aSmrgs/ /\\ /g
5473e6c936aSmrgs/\(.*\)/'"$tab"'\1 \\/p
5483e6c936aSmrgs/.\(.*\) \\/\1:/
5493e6c936aSmrgH
5503e6c936aSmrg$ {
5513e6c936aSmrg  s/.*/'"$tab"'/
5523e6c936aSmrg  G
5533e6c936aSmrg  p
5543e6c936aSmrg}' >> "$depfile"
5550f1ac3bcSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5563e6c936aSmrg  rm -f "$tmpdepfile"
5573e6c936aSmrg  ;;
5583e6c936aSmrg
5593e6c936aSmrgmsvc7msys)
5603e6c936aSmrg  # This case exists only to let depend.m4 do its work.  It works by
5613e6c936aSmrg  # looking at the text of this script.  This case will never be run,
5623e6c936aSmrg  # since it is checked for above.
5633e6c936aSmrg  exit 1
5643e6c936aSmrg  ;;
5654456fccdSmrg
5664456fccdSmrg#nosideeffect)
5674456fccdSmrg  # This comment above is used by automake to tell side-effect
5684456fccdSmrg  # dependency tracking mechanisms from slower ones.
5694456fccdSmrg
5704456fccdSmrgdashmstdout)
5714456fccdSmrg  # Important note: in order to support this mode, a compiler *must*
5724456fccdSmrg  # always write the preprocessed file to stdout, regardless of -o.
5734456fccdSmrg  "$@" || exit $?
5744456fccdSmrg
5754456fccdSmrg  # Remove the call to Libtool.
5764456fccdSmrg  if test "$libtool" = yes; then
57742d69509Smrg    while test "X$1" != 'X--mode=compile'; do
5784456fccdSmrg      shift
5794456fccdSmrg    done
5804456fccdSmrg    shift
5814456fccdSmrg  fi
5824456fccdSmrg
5833e6c936aSmrg  # Remove '-o $object'.
5844456fccdSmrg  IFS=" "
5854456fccdSmrg  for arg
5864456fccdSmrg  do
5874456fccdSmrg    case $arg in
5884456fccdSmrg    -o)
5894456fccdSmrg      shift
5904456fccdSmrg      ;;
5914456fccdSmrg    $object)
5924456fccdSmrg      shift
5934456fccdSmrg      ;;
5944456fccdSmrg    *)
5954456fccdSmrg      set fnord "$@" "$arg"
5964456fccdSmrg      shift # fnord
5974456fccdSmrg      shift # $arg
5984456fccdSmrg      ;;
5994456fccdSmrg    esac
6004456fccdSmrg  done
6014456fccdSmrg
6024456fccdSmrg  test -z "$dashmflag" && dashmflag=-M
6033e6c936aSmrg  # Require at least two characters before searching for ':'
6044456fccdSmrg  # in the target name.  This is to cope with DOS-style filenames:
6053e6c936aSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6064456fccdSmrg  "$@" $dashmflag |
6073e6c936aSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6084456fccdSmrg  rm -f "$depfile"
6094456fccdSmrg  cat < "$tmpdepfile" > "$depfile"
6103e6c936aSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6113e6c936aSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6123e6c936aSmrg  tr ' ' "$nl" < "$tmpdepfile" \
6133e6c936aSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6143e6c936aSmrg    | sed -e 's/$/ :/' >> "$depfile"
6154456fccdSmrg  rm -f "$tmpdepfile"
6164456fccdSmrg  ;;
6174456fccdSmrg
6184456fccdSmrgdashXmstdout)
6194456fccdSmrg  # This case only exists to satisfy depend.m4.  It is never actually
6204456fccdSmrg  # run, as this mode is specially recognized in the preamble.
6214456fccdSmrg  exit 1
6224456fccdSmrg  ;;
6234456fccdSmrg
6244456fccdSmrgmakedepend)
6254456fccdSmrg  "$@" || exit $?
6264456fccdSmrg  # Remove any Libtool call
6274456fccdSmrg  if test "$libtool" = yes; then
62842d69509Smrg    while test "X$1" != 'X--mode=compile'; do
6294456fccdSmrg      shift
6304456fccdSmrg    done
6314456fccdSmrg    shift
6324456fccdSmrg  fi
6334456fccdSmrg  # X makedepend
6344456fccdSmrg  shift
63542d69509Smrg  cleared=no eat=no
63642d69509Smrg  for arg
63742d69509Smrg  do
6384456fccdSmrg    case $cleared in
6394456fccdSmrg    no)
6404456fccdSmrg      set ""; shift
6414456fccdSmrg      cleared=yes ;;
6424456fccdSmrg    esac
64342d69509Smrg    if test $eat = yes; then
64442d69509Smrg      eat=no
64542d69509Smrg      continue
64642d69509Smrg    fi
6474456fccdSmrg    case "$arg" in
6484456fccdSmrg    -D*|-I*)
6494456fccdSmrg      set fnord "$@" "$arg"; shift ;;
6504456fccdSmrg    # Strip any option that makedepend may not understand.  Remove
6514456fccdSmrg    # the object too, otherwise makedepend will parse it as a source file.
65242d69509Smrg    -arch)
65342d69509Smrg      eat=yes ;;
6544456fccdSmrg    -*|$object)
6554456fccdSmrg      ;;
6564456fccdSmrg    *)
6574456fccdSmrg      set fnord "$@" "$arg"; shift ;;
6584456fccdSmrg    esac
6594456fccdSmrg  done
66042d69509Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6614456fccdSmrg  touch "$tmpdepfile"
6624456fccdSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6634456fccdSmrg  rm -f "$depfile"
6643e6c936aSmrg  # makedepend may prepend the VPATH from the source file name to the object.
6653e6c936aSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6663e6c936aSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6673e6c936aSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6683e6c936aSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6693e6c936aSmrg  sed '1,2d' "$tmpdepfile" \
6703e6c936aSmrg    | tr ' ' "$nl" \
6713e6c936aSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6723e6c936aSmrg    | sed -e 's/$/ :/' >> "$depfile"
6734456fccdSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6744456fccdSmrg  ;;
6754456fccdSmrg
6764456fccdSmrgcpp)
6774456fccdSmrg  # Important note: in order to support this mode, a compiler *must*
6784456fccdSmrg  # always write the preprocessed file to stdout.
6794456fccdSmrg  "$@" || exit $?
6804456fccdSmrg
6814456fccdSmrg  # Remove the call to Libtool.
6824456fccdSmrg  if test "$libtool" = yes; then
68342d69509Smrg    while test "X$1" != 'X--mode=compile'; do
6844456fccdSmrg      shift
6854456fccdSmrg    done
6864456fccdSmrg    shift
6874456fccdSmrg  fi
6884456fccdSmrg
6893e6c936aSmrg  # Remove '-o $object'.
6904456fccdSmrg  IFS=" "
6914456fccdSmrg  for arg
6924456fccdSmrg  do
6934456fccdSmrg    case $arg in
6944456fccdSmrg    -o)
6954456fccdSmrg      shift
6964456fccdSmrg      ;;
6974456fccdSmrg    $object)
6984456fccdSmrg      shift
6994456fccdSmrg      ;;
7004456fccdSmrg    *)
7014456fccdSmrg      set fnord "$@" "$arg"
7024456fccdSmrg      shift # fnord
7034456fccdSmrg      shift # $arg
7044456fccdSmrg      ;;
7054456fccdSmrg    esac
7064456fccdSmrg  done
7074456fccdSmrg
7083e6c936aSmrg  "$@" -E \
7093e6c936aSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7103e6c936aSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7113e6c936aSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
7124456fccdSmrg  rm -f "$depfile"
7134456fccdSmrg  echo "$object : \\" > "$depfile"
7144456fccdSmrg  cat < "$tmpdepfile" >> "$depfile"
7154456fccdSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7164456fccdSmrg  rm -f "$tmpdepfile"
7174456fccdSmrg  ;;
7184456fccdSmrg
7194456fccdSmrgmsvisualcpp)
7204456fccdSmrg  # Important note: in order to support this mode, a compiler *must*
72142d69509Smrg  # always write the preprocessed file to stdout.
7224456fccdSmrg  "$@" || exit $?
72342d69509Smrg
72442d69509Smrg  # Remove the call to Libtool.
72542d69509Smrg  if test "$libtool" = yes; then
72642d69509Smrg    while test "X$1" != 'X--mode=compile'; do
72742d69509Smrg      shift
72842d69509Smrg    done
72942d69509Smrg    shift
73042d69509Smrg  fi
73142d69509Smrg
7324456fccdSmrg  IFS=" "
7334456fccdSmrg  for arg
7344456fccdSmrg  do
7354456fccdSmrg    case "$arg" in
73642d69509Smrg    -o)
73742d69509Smrg      shift
73842d69509Smrg      ;;
73942d69509Smrg    $object)
74042d69509Smrg      shift
74142d69509Smrg      ;;
7424456fccdSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7433e6c936aSmrg        set fnord "$@"
7443e6c936aSmrg        shift
7453e6c936aSmrg        shift
7463e6c936aSmrg        ;;
7474456fccdSmrg    *)
7483e6c936aSmrg        set fnord "$@" "$arg"
7493e6c936aSmrg        shift
7503e6c936aSmrg        shift
7513e6c936aSmrg        ;;
7524456fccdSmrg    esac
7534456fccdSmrg  done
75442d69509Smrg  "$@" -E 2>/dev/null |
75542d69509Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7564456fccdSmrg  rm -f "$depfile"
7574456fccdSmrg  echo "$object : \\" > "$depfile"
7583e6c936aSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7593e6c936aSmrg  echo "$tab" >> "$depfile"
76042d69509Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7614456fccdSmrg  rm -f "$tmpdepfile"
7624456fccdSmrg  ;;
7634456fccdSmrg
76442d69509Smrgmsvcmsys)
76542d69509Smrg  # This case exists only to let depend.m4 do its work.  It works by
76642d69509Smrg  # looking at the text of this script.  This case will never be run,
76742d69509Smrg  # since it is checked for above.
76842d69509Smrg  exit 1
76942d69509Smrg  ;;
77042d69509Smrg
7714456fccdSmrgnone)
7724456fccdSmrg  exec "$@"
7734456fccdSmrg  ;;
7744456fccdSmrg
7754456fccdSmrg*)
7764456fccdSmrg  echo "Unknown depmode $depmode" 1>&2
7774456fccdSmrg  exit 1
7784456fccdSmrg  ;;
7794456fccdSmrgesac
7804456fccdSmrg
7814456fccdSmrgexit 0
7824456fccdSmrg
7834456fccdSmrg# Local Variables:
7844456fccdSmrg# mode: shell-script
7854456fccdSmrg# sh-indentation: 2
786b0a0317aSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
7874456fccdSmrg# time-stamp-start: "scriptversion="
7884456fccdSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789b0a0317aSmrg# time-stamp-time-zone: "UTC0"
79042d69509Smrg# time-stamp-end: "; # UTC"
7914456fccdSmrg# End:
792