10e20ee16Smrg#! /bin/sh
20e20ee16Smrg# depcomp - compile a program generating dependencies as side-effects
33e6697d4Smrg
48b648e79Smrgscriptversion=2024-06-19.01; # UTC
53e6697d4Smrg
68b648e79Smrg# Copyright (C) 1999-2024 Free Software Foundation, Inc.
70e20ee16Smrg
80e20ee16Smrg# This program is free software; you can redistribute it and/or modify
90e20ee16Smrg# it under the terms of the GNU General Public License as published by
100e20ee16Smrg# the Free Software Foundation; either version 2, or (at your option)
110e20ee16Smrg# any later version.
120e20ee16Smrg
130e20ee16Smrg# This program is distributed in the hope that it will be useful,
140e20ee16Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
150e20ee16Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
160e20ee16Smrg# GNU General Public License for more details.
170e20ee16Smrg
180e20ee16Smrg# You should have received a copy of the GNU General Public License
19fc34a306Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
200e20ee16Smrg
210e20ee16Smrg# As a special exception to the GNU General Public License, if you
220e20ee16Smrg# distribute this file as part of a program that contains a
230e20ee16Smrg# configuration script generated by Autoconf, you may include it under
240e20ee16Smrg# the same distribution terms that you use for the rest of that program.
250e20ee16Smrg
260e20ee16Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
270e20ee16Smrg
283e6697d4Smrgcase $1 in
293e6697d4Smrg  '')
302f167a42Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
312f167a42Smrg    exit 1;
322f167a42Smrg    ;;
333e6697d4Smrg  -h | --h*)
343e6697d4Smrg    cat <<\EOF
353e6697d4SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
363e6697d4Smrg
373e6697d4SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
383e6697d4Smrgas side-effects.
393e6697d4Smrg
403e6697d4SmrgEnvironment variables:
413e6697d4Smrg  depmode     Dependency tracking mode.
422f167a42Smrg  source      Source file read by 'PROGRAMS ARGS'.
432f167a42Smrg  object      Object file output by 'PROGRAMS ARGS'.
443e6697d4Smrg  DEPDIR      directory where to store dependencies.
453e6697d4Smrg  depfile     Dependency file to output.
462f167a42Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
473e6697d4Smrg  libtool     Whether libtool is used (yes/no).
483e6697d4Smrg
493e6697d4SmrgReport bugs to <bug-automake@gnu.org>.
508b648e79SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
518b648e79SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>.
523e6697d4SmrgEOF
533e6697d4Smrg    exit $?
543e6697d4Smrg    ;;
553e6697d4Smrg  -v | --v*)
568b648e79Smrg    echo "depcomp (GNU Automake) $scriptversion"
573e6697d4Smrg    exit $?
583e6697d4Smrg    ;;
593e6697d4Smrgesac
603e6697d4Smrg
612f167a42Smrg# Get the directory component of the given path, and save it in the
622f167a42Smrg# global variables '$dir'.  Note that this directory component will
632f167a42Smrg# be either empty or ending with a '/' character.  This is deliberate.
642f167a42Smrgset_dir_from ()
652f167a42Smrg{
662f167a42Smrg  case $1 in
672f167a42Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
682f167a42Smrg      *) dir=;;
692f167a42Smrg  esac
702f167a42Smrg}
712f167a42Smrg
722f167a42Smrg# Get the suffix-stripped basename of the given path, and save it the
732f167a42Smrg# global variable '$base'.
742f167a42Smrgset_base_from ()
752f167a42Smrg{
762f167a42Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
772f167a42Smrg}
782f167a42Smrg
792f167a42Smrg# If no dependency file was actually created by the compiler invocation,
802f167a42Smrg# we still have to create a dummy depfile, to avoid errors with the
812f167a42Smrg# Makefile "include basename.Plo" scheme.
822f167a42Smrgmake_dummy_depfile ()
832f167a42Smrg{
842f167a42Smrg  echo "#dummy" > "$depfile"
852f167a42Smrg}
862f167a42Smrg
872f167a42Smrg# Factor out some common post-processing of the generated depfile.
882f167a42Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
892f167a42Smrgaix_post_process_depfile ()
902f167a42Smrg{
912f167a42Smrg  # If the compiler actually managed to produce a dependency file,
922f167a42Smrg  # post-process it.
932f167a42Smrg  if test -f "$tmpdepfile"; then
942f167a42Smrg    # Each line is of the form 'foo.o: dependency.h'.
952f167a42Smrg    # Do two passes, one to just change these to
962f167a42Smrg    #   $object: dependency.h
972f167a42Smrg    # and one to simply output
982f167a42Smrg    #   dependency.h:
992f167a42Smrg    # which is needed to avoid the deleted-header problem.
1002f167a42Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
1012f167a42Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1022f167a42Smrg    } > "$depfile"
1032f167a42Smrg    rm -f "$tmpdepfile"
1042f167a42Smrg  else
1052f167a42Smrg    make_dummy_depfile
1062f167a42Smrg  fi
1072f167a42Smrg}
1082f167a42Smrg
1092f167a42Smrg# A tabulation character.
1102f167a42Smrgtab='	'
1112f167a42Smrg# A newline character.
1122f167a42Smrgnl='
1132f167a42Smrg'
1142f167a42Smrg# Character ranges might be problematic outside the C locale.
1152f167a42Smrg# These definitions help.
1162f167a42Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1172f167a42Smrglower=abcdefghijklmnopqrstuvwxyz
1182f167a42Smrgalpha=${upper}${lower}
1192f167a42Smrg
1200e20ee16Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1210e20ee16Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1220e20ee16Smrg  exit 1
1230e20ee16Smrgfi
1240e20ee16Smrg
1253e6697d4Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1263e6697d4Smrgdepfile=${depfile-`echo "$object" |
1273e6697d4Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1280e20ee16Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1290e20ee16Smrg
1300e20ee16Smrgrm -f "$tmpdepfile"
1310e20ee16Smrg
1328b648e79Smrg# Avoid interference from the environment.
1332f167a42Smrggccflag= dashmflag=
1342f167a42Smrg
1350e20ee16Smrg# Some modes work just like other modes, but use different flags.  We
1360e20ee16Smrg# parameterize here, but still list the modes in the big case below,
1370e20ee16Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1380e20ee16Smrg# here, because this file can only contain one case statement.
1390e20ee16Smrgif test "$depmode" = hp; then
1400e20ee16Smrg  # HP compiler uses -M and no extra arg.
1410e20ee16Smrg  gccflag=-M
1420e20ee16Smrg  depmode=gcc
1430e20ee16Smrgfi
1440e20ee16Smrg
1450e20ee16Smrgif test "$depmode" = dashXmstdout; then
1462f167a42Smrg  # This is just like dashmstdout with a different argument.
1472f167a42Smrg  dashmflag=-xM
1482f167a42Smrg  depmode=dashmstdout
1490e20ee16Smrgfi
1500e20ee16Smrg
1513e6697d4Smrgcygpath_u="cygpath -u -f -"
1523e6697d4Smrgif test "$depmode" = msvcmsys; then
1532f167a42Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1542f167a42Smrg  # Just convert the backslash-escaped backslashes to single forward
1552f167a42Smrg  # slashes to satisfy depend.m4
1562f167a42Smrg  cygpath_u='sed s,\\\\,/,g'
1572f167a42Smrg  depmode=msvisualcpp
1582f167a42Smrgfi
1592f167a42Smrg
1602f167a42Smrgif test "$depmode" = msvc7msys; then
1612f167a42Smrg  # This is just like msvc7 but w/o cygpath translation.
1622f167a42Smrg  # Just convert the backslash-escaped backslashes to single forward
1632f167a42Smrg  # slashes to satisfy depend.m4
1642f167a42Smrg  cygpath_u='sed s,\\\\,/,g'
1652f167a42Smrg  depmode=msvc7
1662f167a42Smrgfi
1672f167a42Smrg
1682f167a42Smrgif test "$depmode" = xlc; then
1692f167a42Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1702f167a42Smrg  gccflag=-qmakedep=gcc,-MF
1712f167a42Smrg  depmode=gcc
1723e6697d4Smrgfi
1733e6697d4Smrg
1740e20ee16Smrgcase "$depmode" in
1750e20ee16Smrggcc3)
1760e20ee16Smrg## gcc 3 implements dependency tracking that does exactly what
1770e20ee16Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1780e20ee16Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1793e6697d4Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1803e6697d4Smrg## the command line argument order; so add the flags where they
1813e6697d4Smrg## appear in depend2.am.  Note that the slowdown incurred here
1823e6697d4Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1833e6697d4Smrg  for arg
1843e6697d4Smrg  do
1853e6697d4Smrg    case $arg in
1863e6697d4Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1873e6697d4Smrg    *)  set fnord "$@" "$arg" ;;
1883e6697d4Smrg    esac
1893e6697d4Smrg    shift # fnord
1903e6697d4Smrg    shift # $arg
1913e6697d4Smrg  done
1923e6697d4Smrg  "$@"
1930e20ee16Smrg  stat=$?
1942f167a42Smrg  if test $stat -ne 0; then
1950e20ee16Smrg    rm -f "$tmpdepfile"
1960e20ee16Smrg    exit $stat
1970e20ee16Smrg  fi
1980e20ee16Smrg  mv "$tmpdepfile" "$depfile"
1990e20ee16Smrg  ;;
2000e20ee16Smrg
2010e20ee16Smrggcc)
2028b648e79Smrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers.
2038b648e79Smrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler.
2042f167a42Smrg## (see the conditional assignment to $gccflag above).
2050e20ee16Smrg## There are various ways to get dependency output from gcc.  Here's
2060e20ee16Smrg## why we pick this rather obscure method:
2070e20ee16Smrg## - Don't want to use -MD because we'd like the dependencies to end
2080e20ee16Smrg##   up in a subdir.  Having to rename by hand is ugly.
2090e20ee16Smrg##   (We might end up doing this anyway to support other compilers.)
2100e20ee16Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2112f167a42Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2122f167a42Smrg##   supported by the other compilers which use the 'gcc' depmode.
2130e20ee16Smrg## - Using -M directly means running the compiler twice (even worse
2140e20ee16Smrg##   than renaming).
2150e20ee16Smrg  if test -z "$gccflag"; then
2160e20ee16Smrg    gccflag=-MD,
2170e20ee16Smrg  fi
2180e20ee16Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
2190e20ee16Smrg  stat=$?
2202f167a42Smrg  if test $stat -ne 0; then
2210e20ee16Smrg    rm -f "$tmpdepfile"
2220e20ee16Smrg    exit $stat
2230e20ee16Smrg  fi
2240e20ee16Smrg  rm -f "$depfile"
2250e20ee16Smrg  echo "$object : \\" > "$depfile"
2262f167a42Smrg  # The second -e expression handles DOS-style file names with drive
2272f167a42Smrg  # letters.
2280e20ee16Smrg  sed -e 's/^[^:]*: / /' \
2290e20ee16Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2302f167a42Smrg## This next piece of magic avoids the "deleted header file" problem.
2310e20ee16Smrg## The problem is that when a header file which appears in a .P file
2320e20ee16Smrg## is deleted, the dependency causes make to die (because there is
2330e20ee16Smrg## typically no way to rebuild the header).  We avoid this by adding
2340e20ee16Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2350e20ee16Smrg## this for us directly.
2362f167a42Smrg## Some versions of gcc put a space before the ':'.  On the theory
2370e20ee16Smrg## that the space means something, we add a space to the output as
2382f167a42Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2392f167a42Smrg## to the object.  Take care to not repeat it in the output.
2400e20ee16Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
2410e20ee16Smrg## correctly.  Breaking it into two sed invocations is a workaround.
2422f167a42Smrg  tr ' ' "$nl" < "$tmpdepfile" \
2432f167a42Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2442f167a42Smrg    | sed -e 's/$/ :/' >> "$depfile"
2450e20ee16Smrg  rm -f "$tmpdepfile"
2460e20ee16Smrg  ;;
2470e20ee16Smrg
2480e20ee16Smrghp)
2490e20ee16Smrg  # This case exists only to let depend.m4 do its work.  It works by
2500e20ee16Smrg  # looking at the text of this script.  This case will never be run,
2510e20ee16Smrg  # since it is checked for above.
2520e20ee16Smrg  exit 1
2530e20ee16Smrg  ;;
2540e20ee16Smrg
2550e20ee16Smrgsgi)
2560e20ee16Smrg  if test "$libtool" = yes; then
2570e20ee16Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2580e20ee16Smrg  else
2590e20ee16Smrg    "$@" -MDupdate "$tmpdepfile"
2600e20ee16Smrg  fi
2610e20ee16Smrg  stat=$?
2622f167a42Smrg  if test $stat -ne 0; then
2630e20ee16Smrg    rm -f "$tmpdepfile"
2640e20ee16Smrg    exit $stat
2650e20ee16Smrg  fi
2660e20ee16Smrg  rm -f "$depfile"
2670e20ee16Smrg
2680e20ee16Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2690e20ee16Smrg    echo "$object : \\" > "$depfile"
2700e20ee16Smrg    # Clip off the initial element (the dependent).  Don't try to be
2710e20ee16Smrg    # clever and replace this with sed code, as IRIX sed won't handle
2720e20ee16Smrg    # lines with more than a fixed number of characters (4096 in
2730e20ee16Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2742f167a42Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
2750e20ee16Smrg    # dependency line.
2762f167a42Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2772f167a42Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2782f167a42Smrg      | tr "$nl" ' ' >> "$depfile"
2793e6697d4Smrg    echo >> "$depfile"
2800e20ee16Smrg    # The second pass generates a dummy entry for each header file.
2812f167a42Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2822f167a42Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2832f167a42Smrg      >> "$depfile"
2840e20ee16Smrg  else
2852f167a42Smrg    make_dummy_depfile
2860e20ee16Smrg  fi
2870e20ee16Smrg  rm -f "$tmpdepfile"
2880e20ee16Smrg  ;;
2890e20ee16Smrg
2902f167a42Smrgxlc)
2912f167a42Smrg  # This case exists only to let depend.m4 do its work.  It works by
2922f167a42Smrg  # looking at the text of this script.  This case will never be run,
2932f167a42Smrg  # since it is checked for above.
2942f167a42Smrg  exit 1
2952f167a42Smrg  ;;
2962f167a42Smrg
2970e20ee16Smrgaix)
2980e20ee16Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2990e20ee16Smrg  # in a .u file.  In older versions, this file always lives in the
3002f167a42Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3010e20ee16Smrg  # start of each line; $object doesn't have directory information.
3020e20ee16Smrg  # Version 6 uses the directory in both cases.
3032f167a42Smrg  set_dir_from "$object"
3042f167a42Smrg  set_base_from "$object"
3050e20ee16Smrg  if test "$libtool" = yes; then
3063e6697d4Smrg    tmpdepfile1=$dir$base.u
3073e6697d4Smrg    tmpdepfile2=$base.u
3083e6697d4Smrg    tmpdepfile3=$dir.libs/$base.u
3090e20ee16Smrg    "$@" -Wc,-M
3100e20ee16Smrg  else
3113e6697d4Smrg    tmpdepfile1=$dir$base.u
3123e6697d4Smrg    tmpdepfile2=$dir$base.u
3133e6697d4Smrg    tmpdepfile3=$dir$base.u
3140e20ee16Smrg    "$@" -M
3150e20ee16Smrg  fi
3160e20ee16Smrg  stat=$?
3172f167a42Smrg  if test $stat -ne 0; then
3183e6697d4Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3190e20ee16Smrg    exit $stat
3200e20ee16Smrg  fi
3210e20ee16Smrg
3223e6697d4Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3233e6697d4Smrg  do
3243e6697d4Smrg    test -f "$tmpdepfile" && break
3253e6697d4Smrg  done
3262f167a42Smrg  aix_post_process_depfile
3272f167a42Smrg  ;;
3282f167a42Smrg
3292f167a42Smrgtcc)
3302f167a42Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3312f167a42Smrg  # FIXME: That version still under development at the moment of writing.
3322f167a42Smrg  #        Make that this statement remains true also for stable, released
3332f167a42Smrg  #        versions.
3342f167a42Smrg  # It will wrap lines (doesn't matter whether long or short) with a
3352f167a42Smrg  # trailing '\', as in:
3362f167a42Smrg  #
3372f167a42Smrg  #   foo.o : \
3382f167a42Smrg  #    foo.c \
3392f167a42Smrg  #    foo.h \
3402f167a42Smrg  #
3412f167a42Smrg  # It will put a trailing '\' even on the last line, and will use leading
3422f167a42Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3432f167a42Smrg  # "Emit spaces for -MD").
3442f167a42Smrg  "$@" -MD -MF "$tmpdepfile"
3452f167a42Smrg  stat=$?
3462f167a42Smrg  if test $stat -ne 0; then
3472f167a42Smrg    rm -f "$tmpdepfile"
3482f167a42Smrg    exit $stat
3490e20ee16Smrg  fi
3502f167a42Smrg  rm -f "$depfile"
3512f167a42Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3522f167a42Smrg  # We have to change lines of the first kind to '$object: \'.
3532f167a42Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3542f167a42Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3552f167a42Smrg  # dummy dependency, to avoid the deleted-header problem.
3562f167a42Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3570e20ee16Smrg  rm -f "$tmpdepfile"
3580e20ee16Smrg  ;;
3590e20ee16Smrg
3602f167a42Smrg## The order of this option in the case statement is important, since the
3612f167a42Smrg## shell code in configure will try each of these formats in the order
3622f167a42Smrg## listed in this file.  A plain '-MD' option would be understood by many
3632f167a42Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3642f167a42Smrgpgcc)
3652f167a42Smrg  # Portland's C compiler understands '-MD'.
3662f167a42Smrg  # Will always output deps to 'file.d' where file is the root name of the
3672f167a42Smrg  # source file under compilation, even if file resides in a subdirectory.
3682f167a42Smrg  # The object file name does not affect the name of the '.d' file.
3692f167a42Smrg  # pgcc 10.2 will output
3700e20ee16Smrg  #    foo.o: sub/foo.c sub/foo.h
3712f167a42Smrg  # and will wrap long lines using '\' :
3720e20ee16Smrg  #    foo.o: sub/foo.c ... \
3730e20ee16Smrg  #     sub/foo.h ... \
3740e20ee16Smrg  #     ...
3752f167a42Smrg  set_dir_from "$object"
3762f167a42Smrg  # Use the source, not the object, to determine the base name, since
3772f167a42Smrg  # that's sadly what pgcc will do too.
3782f167a42Smrg  set_base_from "$source"
3792f167a42Smrg  tmpdepfile=$base.d
3802f167a42Smrg
3812f167a42Smrg  # For projects that build the same source file twice into different object
3822f167a42Smrg  # files, the pgcc approach of using the *source* file root name can cause
3832f167a42Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3842f167a42Smrg  # the same $tmpdepfile.
3852f167a42Smrg  lockdir=$base.d-lock
3862f167a42Smrg  trap "
3872f167a42Smrg    echo '$0: caught signal, cleaning up...' >&2
3882f167a42Smrg    rmdir '$lockdir'
3892f167a42Smrg    exit 1
3902f167a42Smrg  " 1 2 13 15
3912f167a42Smrg  numtries=100
3922f167a42Smrg  i=$numtries
3932f167a42Smrg  while test $i -gt 0; do
3942f167a42Smrg    # mkdir is a portable test-and-set.
3952f167a42Smrg    if mkdir "$lockdir" 2>/dev/null; then
3962f167a42Smrg      # This process acquired the lock.
3972f167a42Smrg      "$@" -MD
3982f167a42Smrg      stat=$?
3992f167a42Smrg      # Release the lock.
4002f167a42Smrg      rmdir "$lockdir"
4012f167a42Smrg      break
4022f167a42Smrg    else
4032f167a42Smrg      # If the lock is being held by a different process, wait
4042f167a42Smrg      # until the winning process is done or we timeout.
4052f167a42Smrg      while test -d "$lockdir" && test $i -gt 0; do
4062f167a42Smrg        sleep 1
4072f167a42Smrg        i=`expr $i - 1`
4082f167a42Smrg      done
4092f167a42Smrg    fi
4102f167a42Smrg    i=`expr $i - 1`
4112f167a42Smrg  done
4122f167a42Smrg  trap - 1 2 13 15
4132f167a42Smrg  if test $i -le 0; then
4142f167a42Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4152f167a42Smrg    echo "$0: check lockdir '$lockdir'" >&2
4162f167a42Smrg    exit 1
4172f167a42Smrg  fi
4180e20ee16Smrg
4192f167a42Smrg  if test $stat -ne 0; then
4200e20ee16Smrg    rm -f "$tmpdepfile"
4210e20ee16Smrg    exit $stat
4220e20ee16Smrg  fi
4230e20ee16Smrg  rm -f "$depfile"
4240e20ee16Smrg  # Each line is of the form `foo.o: dependent.h',
4250e20ee16Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4260e20ee16Smrg  # Do two passes, one to just change these to
4270e20ee16Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4280e20ee16Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4290e20ee16Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4300e20ee16Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
4312f167a42Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4322f167a42Smrg    | sed -e 's/$/ :/' >> "$depfile"
4330e20ee16Smrg  rm -f "$tmpdepfile"
4340e20ee16Smrg  ;;
4350e20ee16Smrg
4363e6697d4Smrghp2)
4373e6697d4Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4383e6697d4Smrg  # compilers, which have integrated preprocessors.  The correct option
4393e6697d4Smrg  # to use with these is +Maked; it writes dependencies to a file named
4403e6697d4Smrg  # 'foo.d', which lands next to the object file, wherever that
4413e6697d4Smrg  # happens to be.
4423e6697d4Smrg  # Much of this is similar to the tru64 case; see comments there.
4432f167a42Smrg  set_dir_from  "$object"
4442f167a42Smrg  set_base_from "$object"
4453e6697d4Smrg  if test "$libtool" = yes; then
4463e6697d4Smrg    tmpdepfile1=$dir$base.d
4473e6697d4Smrg    tmpdepfile2=$dir.libs/$base.d
4483e6697d4Smrg    "$@" -Wc,+Maked
4493e6697d4Smrg  else
4503e6697d4Smrg    tmpdepfile1=$dir$base.d
4513e6697d4Smrg    tmpdepfile2=$dir$base.d
4523e6697d4Smrg    "$@" +Maked
4533e6697d4Smrg  fi
4543e6697d4Smrg  stat=$?
4552f167a42Smrg  if test $stat -ne 0; then
4563e6697d4Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4573e6697d4Smrg     exit $stat
4583e6697d4Smrg  fi
4593e6697d4Smrg
4603e6697d4Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4613e6697d4Smrg  do
4623e6697d4Smrg    test -f "$tmpdepfile" && break
4633e6697d4Smrg  done
4643e6697d4Smrg  if test -f "$tmpdepfile"; then
4652f167a42Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4662f167a42Smrg    # Add 'dependent.h:' lines.
4673e6697d4Smrg    sed -ne '2,${
4682f167a42Smrg               s/^ *//
4692f167a42Smrg               s/ \\*$//
4702f167a42Smrg               s/$/:/
4712f167a42Smrg               p
4722f167a42Smrg             }' "$tmpdepfile" >> "$depfile"
4733e6697d4Smrg  else
4742f167a42Smrg    make_dummy_depfile
4753e6697d4Smrg  fi
4763e6697d4Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4773e6697d4Smrg  ;;
4783e6697d4Smrg
4790e20ee16Smrgtru64)
4802f167a42Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4812f167a42Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4822f167a42Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4832f167a42Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4842f167a42Smrg  # Subdirectories are respected.
4852f167a42Smrg  set_dir_from  "$object"
4862f167a42Smrg  set_base_from "$object"
4872f167a42Smrg
4882f167a42Smrg  if test "$libtool" = yes; then
4892f167a42Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4902f167a42Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4912f167a42Smrg    # in $dir$base.o.d.  We have to check for both files, because
4922f167a42Smrg    # one of the two compilations can be disabled.  We should prefer
4932f167a42Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4942f167a42Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4952f167a42Smrg    # the former would cause a distcleancheck panic.
4962f167a42Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4972f167a42Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4982f167a42Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4992f167a42Smrg    "$@" -Wc,-MD
5002f167a42Smrg  else
5012f167a42Smrg    tmpdepfile1=$dir$base.d
5022f167a42Smrg    tmpdepfile2=$dir$base.d
5032f167a42Smrg    tmpdepfile3=$dir$base.d
5042f167a42Smrg    "$@" -MD
5052f167a42Smrg  fi
5062f167a42Smrg
5072f167a42Smrg  stat=$?
5082f167a42Smrg  if test $stat -ne 0; then
5092f167a42Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5102f167a42Smrg    exit $stat
5112f167a42Smrg  fi
5122f167a42Smrg
5132f167a42Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5142f167a42Smrg  do
5152f167a42Smrg    test -f "$tmpdepfile" && break
5162f167a42Smrg  done
5172f167a42Smrg  # Same post-processing that is required for AIX mode.
5182f167a42Smrg  aix_post_process_depfile
5192f167a42Smrg  ;;
5202f167a42Smrg
5212f167a42Smrgmsvc7)
5222f167a42Smrg  if test "$libtool" = yes; then
5232f167a42Smrg    showIncludes=-Wc,-showIncludes
5242f167a42Smrg  else
5252f167a42Smrg    showIncludes=-showIncludes
5262f167a42Smrg  fi
5272f167a42Smrg  "$@" $showIncludes > "$tmpdepfile"
5282f167a42Smrg  stat=$?
5292f167a42Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5302f167a42Smrg  if test $stat -ne 0; then
5312f167a42Smrg    rm -f "$tmpdepfile"
5322f167a42Smrg    exit $stat
5332f167a42Smrg  fi
5342f167a42Smrg  rm -f "$depfile"
5352f167a42Smrg  echo "$object : \\" > "$depfile"
5362f167a42Smrg  # The first sed program below extracts the file names and escapes
5372f167a42Smrg  # backslashes for cygpath.  The second sed program outputs the file
5382f167a42Smrg  # name when reading, but also accumulates all include files in the
5392f167a42Smrg  # hold buffer in order to output them again at the end.  This only
5402f167a42Smrg  # works with sed implementations that can handle large buffers.
5412f167a42Smrg  sed < "$tmpdepfile" -n '
5422f167a42Smrg/^Note: including file:  *\(.*\)/ {
5432f167a42Smrg  s//\1/
5442f167a42Smrg  s/\\/\\\\/g
5452f167a42Smrg  p
5462f167a42Smrg}' | $cygpath_u | sort -u | sed -n '
5472f167a42Smrgs/ /\\ /g
5482f167a42Smrgs/\(.*\)/'"$tab"'\1 \\/p
5492f167a42Smrgs/.\(.*\) \\/\1:/
5502f167a42SmrgH
5512f167a42Smrg$ {
5522f167a42Smrg  s/.*/'"$tab"'/
5532f167a42Smrg  G
5542f167a42Smrg  p
5552f167a42Smrg}' >> "$depfile"
5562f167a42Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5572f167a42Smrg  rm -f "$tmpdepfile"
5582f167a42Smrg  ;;
5592f167a42Smrg
5602f167a42Smrgmsvc7msys)
5612f167a42Smrg  # This case exists only to let depend.m4 do its work.  It works by
5622f167a42Smrg  # looking at the text of this script.  This case will never be run,
5632f167a42Smrg  # since it is checked for above.
5642f167a42Smrg  exit 1
5652f167a42Smrg  ;;
5660e20ee16Smrg
5670e20ee16Smrg#nosideeffect)
5680e20ee16Smrg  # This comment above is used by automake to tell side-effect
5690e20ee16Smrg  # dependency tracking mechanisms from slower ones.
5700e20ee16Smrg
5710e20ee16Smrgdashmstdout)
5720e20ee16Smrg  # Important note: in order to support this mode, a compiler *must*
5730e20ee16Smrg  # always write the preprocessed file to stdout, regardless of -o.
5740e20ee16Smrg  "$@" || exit $?
5750e20ee16Smrg
5760e20ee16Smrg  # Remove the call to Libtool.
5770e20ee16Smrg  if test "$libtool" = yes; then
5783e6697d4Smrg    while test "X$1" != 'X--mode=compile'; do
5790e20ee16Smrg      shift
5800e20ee16Smrg    done
5810e20ee16Smrg    shift
5820e20ee16Smrg  fi
5830e20ee16Smrg
5842f167a42Smrg  # Remove '-o $object'.
5850e20ee16Smrg  IFS=" "
5860e20ee16Smrg  for arg
5870e20ee16Smrg  do
5880e20ee16Smrg    case $arg in
5890e20ee16Smrg    -o)
5900e20ee16Smrg      shift
5910e20ee16Smrg      ;;
5920e20ee16Smrg    $object)
5930e20ee16Smrg      shift
5940e20ee16Smrg      ;;
5950e20ee16Smrg    *)
5960e20ee16Smrg      set fnord "$@" "$arg"
5970e20ee16Smrg      shift # fnord
5980e20ee16Smrg      shift # $arg
5990e20ee16Smrg      ;;
6000e20ee16Smrg    esac
6010e20ee16Smrg  done
6020e20ee16Smrg
6030e20ee16Smrg  test -z "$dashmflag" && dashmflag=-M
6042f167a42Smrg  # Require at least two characters before searching for ':'
6050e20ee16Smrg  # in the target name.  This is to cope with DOS-style filenames:
6062f167a42Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6070e20ee16Smrg  "$@" $dashmflag |
6082f167a42Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6090e20ee16Smrg  rm -f "$depfile"
6100e20ee16Smrg  cat < "$tmpdepfile" > "$depfile"
6112f167a42Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6122f167a42Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6132f167a42Smrg  tr ' ' "$nl" < "$tmpdepfile" \
6142f167a42Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6152f167a42Smrg    | sed -e 's/$/ :/' >> "$depfile"
6160e20ee16Smrg  rm -f "$tmpdepfile"
6170e20ee16Smrg  ;;
6180e20ee16Smrg
6190e20ee16SmrgdashXmstdout)
6200e20ee16Smrg  # This case only exists to satisfy depend.m4.  It is never actually
6210e20ee16Smrg  # run, as this mode is specially recognized in the preamble.
6220e20ee16Smrg  exit 1
6230e20ee16Smrg  ;;
6240e20ee16Smrg
6250e20ee16Smrgmakedepend)
6260e20ee16Smrg  "$@" || exit $?
6270e20ee16Smrg  # Remove any Libtool call
6280e20ee16Smrg  if test "$libtool" = yes; then
6293e6697d4Smrg    while test "X$1" != 'X--mode=compile'; do
6300e20ee16Smrg      shift
6310e20ee16Smrg    done
6320e20ee16Smrg    shift
6330e20ee16Smrg  fi
6340e20ee16Smrg  # X makedepend
6350e20ee16Smrg  shift
6363e6697d4Smrg  cleared=no eat=no
6373e6697d4Smrg  for arg
6383e6697d4Smrg  do
6390e20ee16Smrg    case $cleared in
6400e20ee16Smrg    no)
6410e20ee16Smrg      set ""; shift
6420e20ee16Smrg      cleared=yes ;;
6430e20ee16Smrg    esac
6443e6697d4Smrg    if test $eat = yes; then
6453e6697d4Smrg      eat=no
6463e6697d4Smrg      continue
6473e6697d4Smrg    fi
6480e20ee16Smrg    case "$arg" in
6490e20ee16Smrg    -D*|-I*)
6500e20ee16Smrg      set fnord "$@" "$arg"; shift ;;
6510e20ee16Smrg    # Strip any option that makedepend may not understand.  Remove
6520e20ee16Smrg    # the object too, otherwise makedepend will parse it as a source file.
6533e6697d4Smrg    -arch)
6543e6697d4Smrg      eat=yes ;;
6550e20ee16Smrg    -*|$object)
6560e20ee16Smrg      ;;
6570e20ee16Smrg    *)
6580e20ee16Smrg      set fnord "$@" "$arg"; shift ;;
6590e20ee16Smrg    esac
6600e20ee16Smrg  done
6613e6697d4Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6620e20ee16Smrg  touch "$tmpdepfile"
6630e20ee16Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6640e20ee16Smrg  rm -f "$depfile"
6652f167a42Smrg  # makedepend may prepend the VPATH from the source file name to the object.
6662f167a42Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6672f167a42Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6682f167a42Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6692f167a42Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6702f167a42Smrg  sed '1,2d' "$tmpdepfile" \
6712f167a42Smrg    | tr ' ' "$nl" \
6722f167a42Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6732f167a42Smrg    | sed -e 's/$/ :/' >> "$depfile"
6740e20ee16Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6750e20ee16Smrg  ;;
6760e20ee16Smrg
6770e20ee16Smrgcpp)
6780e20ee16Smrg  # Important note: in order to support this mode, a compiler *must*
6790e20ee16Smrg  # always write the preprocessed file to stdout.
6800e20ee16Smrg  "$@" || exit $?
6810e20ee16Smrg
6820e20ee16Smrg  # Remove the call to Libtool.
6830e20ee16Smrg  if test "$libtool" = yes; then
6843e6697d4Smrg    while test "X$1" != 'X--mode=compile'; do
6850e20ee16Smrg      shift
6860e20ee16Smrg    done
6870e20ee16Smrg    shift
6880e20ee16Smrg  fi
6890e20ee16Smrg
6902f167a42Smrg  # Remove '-o $object'.
6910e20ee16Smrg  IFS=" "
6920e20ee16Smrg  for arg
6930e20ee16Smrg  do
6940e20ee16Smrg    case $arg in
6950e20ee16Smrg    -o)
6960e20ee16Smrg      shift
6970e20ee16Smrg      ;;
6980e20ee16Smrg    $object)
6990e20ee16Smrg      shift
7000e20ee16Smrg      ;;
7010e20ee16Smrg    *)
7020e20ee16Smrg      set fnord "$@" "$arg"
7030e20ee16Smrg      shift # fnord
7040e20ee16Smrg      shift # $arg
7050e20ee16Smrg      ;;
7060e20ee16Smrg    esac
7070e20ee16Smrg  done
7080e20ee16Smrg
7092f167a42Smrg  "$@" -E \
7102f167a42Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7112f167a42Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7122f167a42Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
7130e20ee16Smrg  rm -f "$depfile"
7140e20ee16Smrg  echo "$object : \\" > "$depfile"
7150e20ee16Smrg  cat < "$tmpdepfile" >> "$depfile"
7160e20ee16Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7170e20ee16Smrg  rm -f "$tmpdepfile"
7180e20ee16Smrg  ;;
7190e20ee16Smrg
7200e20ee16Smrgmsvisualcpp)
7210e20ee16Smrg  # Important note: in order to support this mode, a compiler *must*
7223e6697d4Smrg  # always write the preprocessed file to stdout.
7230e20ee16Smrg  "$@" || exit $?
7243e6697d4Smrg
7253e6697d4Smrg  # Remove the call to Libtool.
7263e6697d4Smrg  if test "$libtool" = yes; then
7273e6697d4Smrg    while test "X$1" != 'X--mode=compile'; do
7283e6697d4Smrg      shift
7293e6697d4Smrg    done
7303e6697d4Smrg    shift
7313e6697d4Smrg  fi
7323e6697d4Smrg
7330e20ee16Smrg  IFS=" "
7340e20ee16Smrg  for arg
7350e20ee16Smrg  do
7360e20ee16Smrg    case "$arg" in
7373e6697d4Smrg    -o)
7383e6697d4Smrg      shift
7393e6697d4Smrg      ;;
7403e6697d4Smrg    $object)
7413e6697d4Smrg      shift
7423e6697d4Smrg      ;;
7430e20ee16Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7442f167a42Smrg        set fnord "$@"
7452f167a42Smrg        shift
7462f167a42Smrg        shift
7472f167a42Smrg        ;;
7480e20ee16Smrg    *)
7492f167a42Smrg        set fnord "$@" "$arg"
7502f167a42Smrg        shift
7512f167a42Smrg        shift
7522f167a42Smrg        ;;
7530e20ee16Smrg    esac
7540e20ee16Smrg  done
7553e6697d4Smrg  "$@" -E 2>/dev/null |
7563e6697d4Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7570e20ee16Smrg  rm -f "$depfile"
7580e20ee16Smrg  echo "$object : \\" > "$depfile"
7592f167a42Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7602f167a42Smrg  echo "$tab" >> "$depfile"
7613e6697d4Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7620e20ee16Smrg  rm -f "$tmpdepfile"
7630e20ee16Smrg  ;;
7640e20ee16Smrg
7653e6697d4Smrgmsvcmsys)
7663e6697d4Smrg  # This case exists only to let depend.m4 do its work.  It works by
7673e6697d4Smrg  # looking at the text of this script.  This case will never be run,
7683e6697d4Smrg  # since it is checked for above.
7693e6697d4Smrg  exit 1
7703e6697d4Smrg  ;;
7713e6697d4Smrg
7720e20ee16Smrgnone)
7730e20ee16Smrg  exec "$@"
7740e20ee16Smrg  ;;
7750e20ee16Smrg
7760e20ee16Smrg*)
7770e20ee16Smrg  echo "Unknown depmode $depmode" 1>&2
7780e20ee16Smrg  exit 1
7790e20ee16Smrg  ;;
7800e20ee16Smrgesac
7810e20ee16Smrg
7820e20ee16Smrgexit 0
7833e6697d4Smrg
7843e6697d4Smrg# Local Variables:
7853e6697d4Smrg# mode: shell-script
7863e6697d4Smrg# sh-indentation: 2
787fc34a306Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
7883e6697d4Smrg# time-stamp-start: "scriptversion="
7893e6697d4Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
790fc34a306Smrg# time-stamp-time-zone: "UTC0"
7913e6697d4Smrg# time-stamp-end: "; # UTC"
7923e6697d4Smrg# End:
793