depcomp revision 3458e6c2
12c7c4e3dSmrg#! /bin/sh
22c7c4e3dSmrg# depcomp - compile a program generating dependencies as side-effects
38650bb69Smrg
43458e6c2Smrgscriptversion=2018-03-07.03; # UTC
58650bb69Smrg
63458e6c2Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
72c7c4e3dSmrg
82c7c4e3dSmrg# This program is free software; you can redistribute it and/or modify
92c7c4e3dSmrg# it under the terms of the GNU General Public License as published by
102c7c4e3dSmrg# the Free Software Foundation; either version 2, or (at your option)
112c7c4e3dSmrg# any later version.
122c7c4e3dSmrg
132c7c4e3dSmrg# This program is distributed in the hope that it will be useful,
142c7c4e3dSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
152c7c4e3dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
162c7c4e3dSmrg# GNU General Public License for more details.
172c7c4e3dSmrg
182c7c4e3dSmrg# You should have received a copy of the GNU General Public License
193458e6c2Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
202c7c4e3dSmrg
212c7c4e3dSmrg# As a special exception to the GNU General Public License, if you
222c7c4e3dSmrg# distribute this file as part of a program that contains a
232c7c4e3dSmrg# configuration script generated by Autoconf, you may include it under
242c7c4e3dSmrg# the same distribution terms that you use for the rest of that program.
252c7c4e3dSmrg
262c7c4e3dSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
272c7c4e3dSmrg
288650bb69Smrgcase $1 in
298650bb69Smrg  '')
302becc446Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
312becc446Smrg    exit 1;
322becc446Smrg    ;;
338650bb69Smrg  -h | --h*)
348650bb69Smrg    cat <<\EOF
358650bb69SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
368650bb69Smrg
378650bb69SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
388650bb69Smrgas side-effects.
398650bb69Smrg
408650bb69SmrgEnvironment variables:
418650bb69Smrg  depmode     Dependency tracking mode.
422becc446Smrg  source      Source file read by 'PROGRAMS ARGS'.
432becc446Smrg  object      Object file output by 'PROGRAMS ARGS'.
448650bb69Smrg  DEPDIR      directory where to store dependencies.
458650bb69Smrg  depfile     Dependency file to output.
462becc446Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
478650bb69Smrg  libtool     Whether libtool is used (yes/no).
488650bb69Smrg
498650bb69SmrgReport bugs to <bug-automake@gnu.org>.
508650bb69SmrgEOF
518650bb69Smrg    exit $?
528650bb69Smrg    ;;
538650bb69Smrg  -v | --v*)
548650bb69Smrg    echo "depcomp $scriptversion"
558650bb69Smrg    exit $?
568650bb69Smrg    ;;
578650bb69Smrgesac
588650bb69Smrg
592becc446Smrg# Get the directory component of the given path, and save it in the
602becc446Smrg# global variables '$dir'.  Note that this directory component will
612becc446Smrg# be either empty or ending with a '/' character.  This is deliberate.
622becc446Smrgset_dir_from ()
632becc446Smrg{
642becc446Smrg  case $1 in
652becc446Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
662becc446Smrg      *) dir=;;
672becc446Smrg  esac
682becc446Smrg}
692becc446Smrg
702becc446Smrg# Get the suffix-stripped basename of the given path, and save it the
712becc446Smrg# global variable '$base'.
722becc446Smrgset_base_from ()
732becc446Smrg{
742becc446Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
752becc446Smrg}
762becc446Smrg
772becc446Smrg# If no dependency file was actually created by the compiler invocation,
782becc446Smrg# we still have to create a dummy depfile, to avoid errors with the
792becc446Smrg# Makefile "include basename.Plo" scheme.
802becc446Smrgmake_dummy_depfile ()
812becc446Smrg{
822becc446Smrg  echo "#dummy" > "$depfile"
832becc446Smrg}
842becc446Smrg
852becc446Smrg# Factor out some common post-processing of the generated depfile.
862becc446Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
872becc446Smrgaix_post_process_depfile ()
882becc446Smrg{
892becc446Smrg  # If the compiler actually managed to produce a dependency file,
902becc446Smrg  # post-process it.
912becc446Smrg  if test -f "$tmpdepfile"; then
922becc446Smrg    # Each line is of the form 'foo.o: dependency.h'.
932becc446Smrg    # Do two passes, one to just change these to
942becc446Smrg    #   $object: dependency.h
952becc446Smrg    # and one to simply output
962becc446Smrg    #   dependency.h:
972becc446Smrg    # which is needed to avoid the deleted-header problem.
982becc446Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
992becc446Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1002becc446Smrg    } > "$depfile"
1012becc446Smrg    rm -f "$tmpdepfile"
1022becc446Smrg  else
1032becc446Smrg    make_dummy_depfile
1042becc446Smrg  fi
1052becc446Smrg}
1062becc446Smrg
1072becc446Smrg# A tabulation character.
1082becc446Smrgtab='	'
1092becc446Smrg# A newline character.
1102becc446Smrgnl='
1112becc446Smrg'
1122becc446Smrg# Character ranges might be problematic outside the C locale.
1132becc446Smrg# These definitions help.
1142becc446Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1152becc446Smrglower=abcdefghijklmnopqrstuvwxyz
1162becc446Smrgdigits=0123456789
1172becc446Smrgalpha=${upper}${lower}
1182becc446Smrg
1192c7c4e3dSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1202c7c4e3dSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1212c7c4e3dSmrg  exit 1
1222c7c4e3dSmrgfi
1232c7c4e3dSmrg
1248650bb69Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1258650bb69Smrgdepfile=${depfile-`echo "$object" |
1268650bb69Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1272c7c4e3dSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1282c7c4e3dSmrg
1292c7c4e3dSmrgrm -f "$tmpdepfile"
1302c7c4e3dSmrg
1312becc446Smrg# Avoid interferences from the environment.
1322becc446Smrggccflag= dashmflag=
1332becc446Smrg
1342c7c4e3dSmrg# Some modes work just like other modes, but use different flags.  We
1352c7c4e3dSmrg# parameterize here, but still list the modes in the big case below,
1362c7c4e3dSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1372c7c4e3dSmrg# here, because this file can only contain one case statement.
1382c7c4e3dSmrgif test "$depmode" = hp; then
1392c7c4e3dSmrg  # HP compiler uses -M and no extra arg.
1402c7c4e3dSmrg  gccflag=-M
1412c7c4e3dSmrg  depmode=gcc
1422c7c4e3dSmrgfi
1432c7c4e3dSmrg
1442c7c4e3dSmrgif test "$depmode" = dashXmstdout; then
1452becc446Smrg  # This is just like dashmstdout with a different argument.
1462becc446Smrg  dashmflag=-xM
1472becc446Smrg  depmode=dashmstdout
1482c7c4e3dSmrgfi
1492c7c4e3dSmrg
1508650bb69Smrgcygpath_u="cygpath -u -f -"
1518650bb69Smrgif test "$depmode" = msvcmsys; then
1522becc446Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1532becc446Smrg  # Just convert the backslash-escaped backslashes to single forward
1542becc446Smrg  # slashes to satisfy depend.m4
1552becc446Smrg  cygpath_u='sed s,\\\\,/,g'
1562becc446Smrg  depmode=msvisualcpp
1572becc446Smrgfi
1582becc446Smrg
1592becc446Smrgif test "$depmode" = msvc7msys; then
1602becc446Smrg  # This is just like msvc7 but w/o cygpath translation.
1612becc446Smrg  # Just convert the backslash-escaped backslashes to single forward
1622becc446Smrg  # slashes to satisfy depend.m4
1632becc446Smrg  cygpath_u='sed s,\\\\,/,g'
1642becc446Smrg  depmode=msvc7
1652becc446Smrgfi
1662becc446Smrg
1672becc446Smrgif test "$depmode" = xlc; then
1682becc446Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1692becc446Smrg  gccflag=-qmakedep=gcc,-MF
1702becc446Smrg  depmode=gcc
1718650bb69Smrgfi
1728650bb69Smrg
1732c7c4e3dSmrgcase "$depmode" in
1742c7c4e3dSmrggcc3)
1752c7c4e3dSmrg## gcc 3 implements dependency tracking that does exactly what
1762c7c4e3dSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1772c7c4e3dSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1788650bb69Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1798650bb69Smrg## the command line argument order; so add the flags where they
1808650bb69Smrg## appear in depend2.am.  Note that the slowdown incurred here
1818650bb69Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1828650bb69Smrg  for arg
1838650bb69Smrg  do
1848650bb69Smrg    case $arg in
1858650bb69Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1868650bb69Smrg    *)  set fnord "$@" "$arg" ;;
1878650bb69Smrg    esac
1888650bb69Smrg    shift # fnord
1898650bb69Smrg    shift # $arg
1908650bb69Smrg  done
1918650bb69Smrg  "$@"
1922c7c4e3dSmrg  stat=$?
1932becc446Smrg  if test $stat -ne 0; then
1942c7c4e3dSmrg    rm -f "$tmpdepfile"
1952c7c4e3dSmrg    exit $stat
1962c7c4e3dSmrg  fi
1972c7c4e3dSmrg  mv "$tmpdepfile" "$depfile"
1982c7c4e3dSmrg  ;;
1992c7c4e3dSmrg
2002c7c4e3dSmrggcc)
2012becc446Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2022becc446Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2032becc446Smrg## (see the conditional assignment to $gccflag above).
2042c7c4e3dSmrg## There are various ways to get dependency output from gcc.  Here's
2052c7c4e3dSmrg## why we pick this rather obscure method:
2062c7c4e3dSmrg## - Don't want to use -MD because we'd like the dependencies to end
2072c7c4e3dSmrg##   up in a subdir.  Having to rename by hand is ugly.
2082c7c4e3dSmrg##   (We might end up doing this anyway to support other compilers.)
2092c7c4e3dSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2102becc446Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2112becc446Smrg##   supported by the other compilers which use the 'gcc' depmode.
2122c7c4e3dSmrg## - Using -M directly means running the compiler twice (even worse
2132c7c4e3dSmrg##   than renaming).
2142c7c4e3dSmrg  if test -z "$gccflag"; then
2152c7c4e3dSmrg    gccflag=-MD,
2162c7c4e3dSmrg  fi
2172c7c4e3dSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
2182c7c4e3dSmrg  stat=$?
2192becc446Smrg  if test $stat -ne 0; then
2202c7c4e3dSmrg    rm -f "$tmpdepfile"
2212c7c4e3dSmrg    exit $stat
2222c7c4e3dSmrg  fi
2232c7c4e3dSmrg  rm -f "$depfile"
2242c7c4e3dSmrg  echo "$object : \\" > "$depfile"
2252becc446Smrg  # The second -e expression handles DOS-style file names with drive
2262becc446Smrg  # letters.
2272c7c4e3dSmrg  sed -e 's/^[^:]*: / /' \
2282c7c4e3dSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2292becc446Smrg## This next piece of magic avoids the "deleted header file" problem.
2302c7c4e3dSmrg## The problem is that when a header file which appears in a .P file
2312c7c4e3dSmrg## is deleted, the dependency causes make to die (because there is
2322c7c4e3dSmrg## typically no way to rebuild the header).  We avoid this by adding
2332c7c4e3dSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2342c7c4e3dSmrg## this for us directly.
2352becc446Smrg## Some versions of gcc put a space before the ':'.  On the theory
2362c7c4e3dSmrg## that the space means something, we add a space to the output as
2372becc446Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2382becc446Smrg## to the object.  Take care to not repeat it in the output.
2392c7c4e3dSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
2402c7c4e3dSmrg## correctly.  Breaking it into two sed invocations is a workaround.
2412becc446Smrg  tr ' ' "$nl" < "$tmpdepfile" \
2422becc446Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2432becc446Smrg    | sed -e 's/$/ :/' >> "$depfile"
2442c7c4e3dSmrg  rm -f "$tmpdepfile"
2452c7c4e3dSmrg  ;;
2462c7c4e3dSmrg
2472c7c4e3dSmrghp)
2482c7c4e3dSmrg  # This case exists only to let depend.m4 do its work.  It works by
2492c7c4e3dSmrg  # looking at the text of this script.  This case will never be run,
2502c7c4e3dSmrg  # since it is checked for above.
2512c7c4e3dSmrg  exit 1
2522c7c4e3dSmrg  ;;
2532c7c4e3dSmrg
2542c7c4e3dSmrgsgi)
2552c7c4e3dSmrg  if test "$libtool" = yes; then
2562c7c4e3dSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2572c7c4e3dSmrg  else
2582c7c4e3dSmrg    "$@" -MDupdate "$tmpdepfile"
2592c7c4e3dSmrg  fi
2602c7c4e3dSmrg  stat=$?
2612becc446Smrg  if test $stat -ne 0; then
2622c7c4e3dSmrg    rm -f "$tmpdepfile"
2632c7c4e3dSmrg    exit $stat
2642c7c4e3dSmrg  fi
2652c7c4e3dSmrg  rm -f "$depfile"
2662c7c4e3dSmrg
2672c7c4e3dSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2682c7c4e3dSmrg    echo "$object : \\" > "$depfile"
2692c7c4e3dSmrg    # Clip off the initial element (the dependent).  Don't try to be
2702c7c4e3dSmrg    # clever and replace this with sed code, as IRIX sed won't handle
2712c7c4e3dSmrg    # lines with more than a fixed number of characters (4096 in
2722c7c4e3dSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2732becc446Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
2742c7c4e3dSmrg    # dependency line.
2752becc446Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2762becc446Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2772becc446Smrg      | tr "$nl" ' ' >> "$depfile"
2788650bb69Smrg    echo >> "$depfile"
2792c7c4e3dSmrg    # The second pass generates a dummy entry for each header file.
2802becc446Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2812becc446Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2822becc446Smrg      >> "$depfile"
2832c7c4e3dSmrg  else
2842becc446Smrg    make_dummy_depfile
2852c7c4e3dSmrg  fi
2862c7c4e3dSmrg  rm -f "$tmpdepfile"
2872c7c4e3dSmrg  ;;
2882c7c4e3dSmrg
2892becc446Smrgxlc)
2902becc446Smrg  # This case exists only to let depend.m4 do its work.  It works by
2912becc446Smrg  # looking at the text of this script.  This case will never be run,
2922becc446Smrg  # since it is checked for above.
2932becc446Smrg  exit 1
2942becc446Smrg  ;;
2952becc446Smrg
2962c7c4e3dSmrgaix)
2972c7c4e3dSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
2982c7c4e3dSmrg  # in a .u file.  In older versions, this file always lives in the
2992becc446Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3002c7c4e3dSmrg  # start of each line; $object doesn't have directory information.
3012c7c4e3dSmrg  # Version 6 uses the directory in both cases.
3022becc446Smrg  set_dir_from "$object"
3032becc446Smrg  set_base_from "$object"
3042c7c4e3dSmrg  if test "$libtool" = yes; then
3058650bb69Smrg    tmpdepfile1=$dir$base.u
3068650bb69Smrg    tmpdepfile2=$base.u
3078650bb69Smrg    tmpdepfile3=$dir.libs/$base.u
3082c7c4e3dSmrg    "$@" -Wc,-M
3092c7c4e3dSmrg  else
3108650bb69Smrg    tmpdepfile1=$dir$base.u
3118650bb69Smrg    tmpdepfile2=$dir$base.u
3128650bb69Smrg    tmpdepfile3=$dir$base.u
3132c7c4e3dSmrg    "$@" -M
3142c7c4e3dSmrg  fi
3152c7c4e3dSmrg  stat=$?
3162becc446Smrg  if test $stat -ne 0; then
3178650bb69Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3182c7c4e3dSmrg    exit $stat
3192c7c4e3dSmrg  fi
3202c7c4e3dSmrg
3218650bb69Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3228650bb69Smrg  do
3238650bb69Smrg    test -f "$tmpdepfile" && break
3248650bb69Smrg  done
3252becc446Smrg  aix_post_process_depfile
3262becc446Smrg  ;;
3272becc446Smrg
3282becc446Smrgtcc)
3292becc446Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3302becc446Smrg  # FIXME: That version still under development at the moment of writing.
3312becc446Smrg  #        Make that this statement remains true also for stable, released
3322becc446Smrg  #        versions.
3332becc446Smrg  # It will wrap lines (doesn't matter whether long or short) with a
3342becc446Smrg  # trailing '\', as in:
3352becc446Smrg  #
3362becc446Smrg  #   foo.o : \
3372becc446Smrg  #    foo.c \
3382becc446Smrg  #    foo.h \
3392becc446Smrg  #
3402becc446Smrg  # It will put a trailing '\' even on the last line, and will use leading
3412becc446Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3422becc446Smrg  # "Emit spaces for -MD").
3432becc446Smrg  "$@" -MD -MF "$tmpdepfile"
3442becc446Smrg  stat=$?
3452becc446Smrg  if test $stat -ne 0; then
3462becc446Smrg    rm -f "$tmpdepfile"
3472becc446Smrg    exit $stat
3482c7c4e3dSmrg  fi
3492becc446Smrg  rm -f "$depfile"
3502becc446Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3512becc446Smrg  # We have to change lines of the first kind to '$object: \'.
3522becc446Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3532becc446Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3542becc446Smrg  # dummy dependency, to avoid the deleted-header problem.
3552becc446Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3562c7c4e3dSmrg  rm -f "$tmpdepfile"
3572c7c4e3dSmrg  ;;
3582c7c4e3dSmrg
3592becc446Smrg## The order of this option in the case statement is important, since the
3602becc446Smrg## shell code in configure will try each of these formats in the order
3612becc446Smrg## listed in this file.  A plain '-MD' option would be understood by many
3622becc446Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3632becc446Smrgpgcc)
3642becc446Smrg  # Portland's C compiler understands '-MD'.
3652becc446Smrg  # Will always output deps to 'file.d' where file is the root name of the
3662becc446Smrg  # source file under compilation, even if file resides in a subdirectory.
3672becc446Smrg  # The object file name does not affect the name of the '.d' file.
3682becc446Smrg  # pgcc 10.2 will output
3692c7c4e3dSmrg  #    foo.o: sub/foo.c sub/foo.h
3702becc446Smrg  # and will wrap long lines using '\' :
3712c7c4e3dSmrg  #    foo.o: sub/foo.c ... \
3722c7c4e3dSmrg  #     sub/foo.h ... \
3732c7c4e3dSmrg  #     ...
3742becc446Smrg  set_dir_from "$object"
3752becc446Smrg  # Use the source, not the object, to determine the base name, since
3762becc446Smrg  # that's sadly what pgcc will do too.
3772becc446Smrg  set_base_from "$source"
3782becc446Smrg  tmpdepfile=$base.d
3792becc446Smrg
3802becc446Smrg  # For projects that build the same source file twice into different object
3812becc446Smrg  # files, the pgcc approach of using the *source* file root name can cause
3822becc446Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3832becc446Smrg  # the same $tmpdepfile.
3842becc446Smrg  lockdir=$base.d-lock
3852becc446Smrg  trap "
3862becc446Smrg    echo '$0: caught signal, cleaning up...' >&2
3872becc446Smrg    rmdir '$lockdir'
3882becc446Smrg    exit 1
3892becc446Smrg  " 1 2 13 15
3902becc446Smrg  numtries=100
3912becc446Smrg  i=$numtries
3922becc446Smrg  while test $i -gt 0; do
3932becc446Smrg    # mkdir is a portable test-and-set.
3942becc446Smrg    if mkdir "$lockdir" 2>/dev/null; then
3952becc446Smrg      # This process acquired the lock.
3962becc446Smrg      "$@" -MD
3972becc446Smrg      stat=$?
3982becc446Smrg      # Release the lock.
3992becc446Smrg      rmdir "$lockdir"
4002becc446Smrg      break
4012becc446Smrg    else
4022becc446Smrg      # If the lock is being held by a different process, wait
4032becc446Smrg      # until the winning process is done or we timeout.
4042becc446Smrg      while test -d "$lockdir" && test $i -gt 0; do
4052becc446Smrg        sleep 1
4062becc446Smrg        i=`expr $i - 1`
4072becc446Smrg      done
4082becc446Smrg    fi
4092becc446Smrg    i=`expr $i - 1`
4102becc446Smrg  done
4112becc446Smrg  trap - 1 2 13 15
4122becc446Smrg  if test $i -le 0; then
4132becc446Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4142becc446Smrg    echo "$0: check lockdir '$lockdir'" >&2
4152becc446Smrg    exit 1
4162becc446Smrg  fi
4172c7c4e3dSmrg
4182becc446Smrg  if test $stat -ne 0; then
4192c7c4e3dSmrg    rm -f "$tmpdepfile"
4202c7c4e3dSmrg    exit $stat
4212c7c4e3dSmrg  fi
4222c7c4e3dSmrg  rm -f "$depfile"
4232c7c4e3dSmrg  # Each line is of the form `foo.o: dependent.h',
4242c7c4e3dSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4252c7c4e3dSmrg  # Do two passes, one to just change these to
4262c7c4e3dSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4272c7c4e3dSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4282c7c4e3dSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4292c7c4e3dSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
4302becc446Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4312becc446Smrg    | sed -e 's/$/ :/' >> "$depfile"
4322c7c4e3dSmrg  rm -f "$tmpdepfile"
4332c7c4e3dSmrg  ;;
4342c7c4e3dSmrg
4358650bb69Smrghp2)
4368650bb69Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4378650bb69Smrg  # compilers, which have integrated preprocessors.  The correct option
4388650bb69Smrg  # to use with these is +Maked; it writes dependencies to a file named
4398650bb69Smrg  # 'foo.d', which lands next to the object file, wherever that
4408650bb69Smrg  # happens to be.
4418650bb69Smrg  # Much of this is similar to the tru64 case; see comments there.
4422becc446Smrg  set_dir_from  "$object"
4432becc446Smrg  set_base_from "$object"
4448650bb69Smrg  if test "$libtool" = yes; then
4458650bb69Smrg    tmpdepfile1=$dir$base.d
4468650bb69Smrg    tmpdepfile2=$dir.libs/$base.d
4478650bb69Smrg    "$@" -Wc,+Maked
4488650bb69Smrg  else
4498650bb69Smrg    tmpdepfile1=$dir$base.d
4508650bb69Smrg    tmpdepfile2=$dir$base.d
4518650bb69Smrg    "$@" +Maked
4528650bb69Smrg  fi
4538650bb69Smrg  stat=$?
4542becc446Smrg  if test $stat -ne 0; then
4558650bb69Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4568650bb69Smrg     exit $stat
4578650bb69Smrg  fi
4588650bb69Smrg
4598650bb69Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4608650bb69Smrg  do
4618650bb69Smrg    test -f "$tmpdepfile" && break
4628650bb69Smrg  done
4638650bb69Smrg  if test -f "$tmpdepfile"; then
4642becc446Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4652becc446Smrg    # Add 'dependent.h:' lines.
4668650bb69Smrg    sed -ne '2,${
4672becc446Smrg               s/^ *//
4682becc446Smrg               s/ \\*$//
4692becc446Smrg               s/$/:/
4702becc446Smrg               p
4712becc446Smrg             }' "$tmpdepfile" >> "$depfile"
4728650bb69Smrg  else
4732becc446Smrg    make_dummy_depfile
4748650bb69Smrg  fi
4758650bb69Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4768650bb69Smrg  ;;
4778650bb69Smrg
4782c7c4e3dSmrgtru64)
4792becc446Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4802becc446Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4812becc446Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4822becc446Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4832becc446Smrg  # Subdirectories are respected.
4842becc446Smrg  set_dir_from  "$object"
4852becc446Smrg  set_base_from "$object"
4862becc446Smrg
4872becc446Smrg  if test "$libtool" = yes; then
4882becc446Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4892becc446Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4902becc446Smrg    # in $dir$base.o.d.  We have to check for both files, because
4912becc446Smrg    # one of the two compilations can be disabled.  We should prefer
4922becc446Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4932becc446Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4942becc446Smrg    # the former would cause a distcleancheck panic.
4952becc446Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4962becc446Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4972becc446Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4982becc446Smrg    "$@" -Wc,-MD
4992becc446Smrg  else
5002becc446Smrg    tmpdepfile1=$dir$base.d
5012becc446Smrg    tmpdepfile2=$dir$base.d
5022becc446Smrg    tmpdepfile3=$dir$base.d
5032becc446Smrg    "$@" -MD
5042becc446Smrg  fi
5052becc446Smrg
5062becc446Smrg  stat=$?
5072becc446Smrg  if test $stat -ne 0; then
5082becc446Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5092becc446Smrg    exit $stat
5102becc446Smrg  fi
5112becc446Smrg
5122becc446Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5132becc446Smrg  do
5142becc446Smrg    test -f "$tmpdepfile" && break
5152becc446Smrg  done
5162becc446Smrg  # Same post-processing that is required for AIX mode.
5172becc446Smrg  aix_post_process_depfile
5182becc446Smrg  ;;
5192becc446Smrg
5202becc446Smrgmsvc7)
5212becc446Smrg  if test "$libtool" = yes; then
5222becc446Smrg    showIncludes=-Wc,-showIncludes
5232becc446Smrg  else
5242becc446Smrg    showIncludes=-showIncludes
5252becc446Smrg  fi
5262becc446Smrg  "$@" $showIncludes > "$tmpdepfile"
5272becc446Smrg  stat=$?
5282becc446Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5292becc446Smrg  if test $stat -ne 0; then
5302becc446Smrg    rm -f "$tmpdepfile"
5312becc446Smrg    exit $stat
5322becc446Smrg  fi
5332becc446Smrg  rm -f "$depfile"
5342becc446Smrg  echo "$object : \\" > "$depfile"
5352becc446Smrg  # The first sed program below extracts the file names and escapes
5362becc446Smrg  # backslashes for cygpath.  The second sed program outputs the file
5372becc446Smrg  # name when reading, but also accumulates all include files in the
5382becc446Smrg  # hold buffer in order to output them again at the end.  This only
5392becc446Smrg  # works with sed implementations that can handle large buffers.
5402becc446Smrg  sed < "$tmpdepfile" -n '
5412becc446Smrg/^Note: including file:  *\(.*\)/ {
5422becc446Smrg  s//\1/
5432becc446Smrg  s/\\/\\\\/g
5442becc446Smrg  p
5452becc446Smrg}' | $cygpath_u | sort -u | sed -n '
5462becc446Smrgs/ /\\ /g
5472becc446Smrgs/\(.*\)/'"$tab"'\1 \\/p
5482becc446Smrgs/.\(.*\) \\/\1:/
5492becc446SmrgH
5502becc446Smrg$ {
5512becc446Smrg  s/.*/'"$tab"'/
5522becc446Smrg  G
5532becc446Smrg  p
5542becc446Smrg}' >> "$depfile"
5552becc446Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5562becc446Smrg  rm -f "$tmpdepfile"
5572becc446Smrg  ;;
5582becc446Smrg
5592becc446Smrgmsvc7msys)
5602becc446Smrg  # This case exists only to let depend.m4 do its work.  It works by
5612becc446Smrg  # looking at the text of this script.  This case will never be run,
5622becc446Smrg  # since it is checked for above.
5632becc446Smrg  exit 1
5642becc446Smrg  ;;
5652c7c4e3dSmrg
5662c7c4e3dSmrg#nosideeffect)
5672c7c4e3dSmrg  # This comment above is used by automake to tell side-effect
5682c7c4e3dSmrg  # dependency tracking mechanisms from slower ones.
5692c7c4e3dSmrg
5702c7c4e3dSmrgdashmstdout)
5712c7c4e3dSmrg  # Important note: in order to support this mode, a compiler *must*
5722c7c4e3dSmrg  # always write the preprocessed file to stdout, regardless of -o.
5732c7c4e3dSmrg  "$@" || exit $?
5742c7c4e3dSmrg
5752c7c4e3dSmrg  # Remove the call to Libtool.
5762c7c4e3dSmrg  if test "$libtool" = yes; then
5778650bb69Smrg    while test "X$1" != 'X--mode=compile'; do
5782c7c4e3dSmrg      shift
5792c7c4e3dSmrg    done
5802c7c4e3dSmrg    shift
5812c7c4e3dSmrg  fi
5822c7c4e3dSmrg
5832becc446Smrg  # Remove '-o $object'.
5842c7c4e3dSmrg  IFS=" "
5852c7c4e3dSmrg  for arg
5862c7c4e3dSmrg  do
5872c7c4e3dSmrg    case $arg in
5882c7c4e3dSmrg    -o)
5892c7c4e3dSmrg      shift
5902c7c4e3dSmrg      ;;
5912c7c4e3dSmrg    $object)
5922c7c4e3dSmrg      shift
5932c7c4e3dSmrg      ;;
5942c7c4e3dSmrg    *)
5952c7c4e3dSmrg      set fnord "$@" "$arg"
5962c7c4e3dSmrg      shift # fnord
5972c7c4e3dSmrg      shift # $arg
5982c7c4e3dSmrg      ;;
5992c7c4e3dSmrg    esac
6002c7c4e3dSmrg  done
6012c7c4e3dSmrg
6022c7c4e3dSmrg  test -z "$dashmflag" && dashmflag=-M
6032becc446Smrg  # Require at least two characters before searching for ':'
6042c7c4e3dSmrg  # in the target name.  This is to cope with DOS-style filenames:
6052becc446Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6062c7c4e3dSmrg  "$@" $dashmflag |
6072becc446Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6082c7c4e3dSmrg  rm -f "$depfile"
6092c7c4e3dSmrg  cat < "$tmpdepfile" > "$depfile"
6102becc446Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6112becc446Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6122becc446Smrg  tr ' ' "$nl" < "$tmpdepfile" \
6132becc446Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6142becc446Smrg    | sed -e 's/$/ :/' >> "$depfile"
6152c7c4e3dSmrg  rm -f "$tmpdepfile"
6162c7c4e3dSmrg  ;;
6172c7c4e3dSmrg
6182c7c4e3dSmrgdashXmstdout)
6192c7c4e3dSmrg  # This case only exists to satisfy depend.m4.  It is never actually
6202c7c4e3dSmrg  # run, as this mode is specially recognized in the preamble.
6212c7c4e3dSmrg  exit 1
6222c7c4e3dSmrg  ;;
6232c7c4e3dSmrg
6242c7c4e3dSmrgmakedepend)
6252c7c4e3dSmrg  "$@" || exit $?
6262c7c4e3dSmrg  # Remove any Libtool call
6272c7c4e3dSmrg  if test "$libtool" = yes; then
6288650bb69Smrg    while test "X$1" != 'X--mode=compile'; do
6292c7c4e3dSmrg      shift
6302c7c4e3dSmrg    done
6312c7c4e3dSmrg    shift
6322c7c4e3dSmrg  fi
6332c7c4e3dSmrg  # X makedepend
6342c7c4e3dSmrg  shift
6358650bb69Smrg  cleared=no eat=no
6368650bb69Smrg  for arg
6378650bb69Smrg  do
6382c7c4e3dSmrg    case $cleared in
6392c7c4e3dSmrg    no)
6402c7c4e3dSmrg      set ""; shift
6412c7c4e3dSmrg      cleared=yes ;;
6422c7c4e3dSmrg    esac
6438650bb69Smrg    if test $eat = yes; then
6448650bb69Smrg      eat=no
6458650bb69Smrg      continue
6468650bb69Smrg    fi
6472c7c4e3dSmrg    case "$arg" in
6482c7c4e3dSmrg    -D*|-I*)
6492c7c4e3dSmrg      set fnord "$@" "$arg"; shift ;;
6502c7c4e3dSmrg    # Strip any option that makedepend may not understand.  Remove
6512c7c4e3dSmrg    # the object too, otherwise makedepend will parse it as a source file.
6528650bb69Smrg    -arch)
6538650bb69Smrg      eat=yes ;;
6542c7c4e3dSmrg    -*|$object)
6552c7c4e3dSmrg      ;;
6562c7c4e3dSmrg    *)
6572c7c4e3dSmrg      set fnord "$@" "$arg"; shift ;;
6582c7c4e3dSmrg    esac
6592c7c4e3dSmrg  done
6608650bb69Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6612c7c4e3dSmrg  touch "$tmpdepfile"
6622c7c4e3dSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6632c7c4e3dSmrg  rm -f "$depfile"
6642becc446Smrg  # makedepend may prepend the VPATH from the source file name to the object.
6652becc446Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6662becc446Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6672becc446Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6682becc446Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6692becc446Smrg  sed '1,2d' "$tmpdepfile" \
6702becc446Smrg    | tr ' ' "$nl" \
6712becc446Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6722becc446Smrg    | sed -e 's/$/ :/' >> "$depfile"
6732c7c4e3dSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6742c7c4e3dSmrg  ;;
6752c7c4e3dSmrg
6762c7c4e3dSmrgcpp)
6772c7c4e3dSmrg  # Important note: in order to support this mode, a compiler *must*
6782c7c4e3dSmrg  # always write the preprocessed file to stdout.
6792c7c4e3dSmrg  "$@" || exit $?
6802c7c4e3dSmrg
6812c7c4e3dSmrg  # Remove the call to Libtool.
6822c7c4e3dSmrg  if test "$libtool" = yes; then
6838650bb69Smrg    while test "X$1" != 'X--mode=compile'; do
6842c7c4e3dSmrg      shift
6852c7c4e3dSmrg    done
6862c7c4e3dSmrg    shift
6872c7c4e3dSmrg  fi
6882c7c4e3dSmrg
6892becc446Smrg  # Remove '-o $object'.
6902c7c4e3dSmrg  IFS=" "
6912c7c4e3dSmrg  for arg
6922c7c4e3dSmrg  do
6932c7c4e3dSmrg    case $arg in
6942c7c4e3dSmrg    -o)
6952c7c4e3dSmrg      shift
6962c7c4e3dSmrg      ;;
6972c7c4e3dSmrg    $object)
6982c7c4e3dSmrg      shift
6992c7c4e3dSmrg      ;;
7002c7c4e3dSmrg    *)
7012c7c4e3dSmrg      set fnord "$@" "$arg"
7022c7c4e3dSmrg      shift # fnord
7032c7c4e3dSmrg      shift # $arg
7042c7c4e3dSmrg      ;;
7052c7c4e3dSmrg    esac
7062c7c4e3dSmrg  done
7072c7c4e3dSmrg
7082becc446Smrg  "$@" -E \
7092becc446Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7102becc446Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7112becc446Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
7122c7c4e3dSmrg  rm -f "$depfile"
7132c7c4e3dSmrg  echo "$object : \\" > "$depfile"
7142c7c4e3dSmrg  cat < "$tmpdepfile" >> "$depfile"
7152c7c4e3dSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7162c7c4e3dSmrg  rm -f "$tmpdepfile"
7172c7c4e3dSmrg  ;;
7182c7c4e3dSmrg
7192c7c4e3dSmrgmsvisualcpp)
7202c7c4e3dSmrg  # Important note: in order to support this mode, a compiler *must*
7218650bb69Smrg  # always write the preprocessed file to stdout.
7222c7c4e3dSmrg  "$@" || exit $?
7238650bb69Smrg
7248650bb69Smrg  # Remove the call to Libtool.
7258650bb69Smrg  if test "$libtool" = yes; then
7268650bb69Smrg    while test "X$1" != 'X--mode=compile'; do
7278650bb69Smrg      shift
7288650bb69Smrg    done
7298650bb69Smrg    shift
7308650bb69Smrg  fi
7318650bb69Smrg
7322c7c4e3dSmrg  IFS=" "
7332c7c4e3dSmrg  for arg
7342c7c4e3dSmrg  do
7352c7c4e3dSmrg    case "$arg" in
7368650bb69Smrg    -o)
7378650bb69Smrg      shift
7388650bb69Smrg      ;;
7398650bb69Smrg    $object)
7408650bb69Smrg      shift
7418650bb69Smrg      ;;
7422c7c4e3dSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7432becc446Smrg        set fnord "$@"
7442becc446Smrg        shift
7452becc446Smrg        shift
7462becc446Smrg        ;;
7472c7c4e3dSmrg    *)
7482becc446Smrg        set fnord "$@" "$arg"
7492becc446Smrg        shift
7502becc446Smrg        shift
7512becc446Smrg        ;;
7522c7c4e3dSmrg    esac
7532c7c4e3dSmrg  done
7548650bb69Smrg  "$@" -E 2>/dev/null |
7558650bb69Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7562c7c4e3dSmrg  rm -f "$depfile"
7572c7c4e3dSmrg  echo "$object : \\" > "$depfile"
7582becc446Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7592becc446Smrg  echo "$tab" >> "$depfile"
7608650bb69Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7612c7c4e3dSmrg  rm -f "$tmpdepfile"
7622c7c4e3dSmrg  ;;
7632c7c4e3dSmrg
7648650bb69Smrgmsvcmsys)
7658650bb69Smrg  # This case exists only to let depend.m4 do its work.  It works by
7668650bb69Smrg  # looking at the text of this script.  This case will never be run,
7678650bb69Smrg  # since it is checked for above.
7688650bb69Smrg  exit 1
7698650bb69Smrg  ;;
7708650bb69Smrg
7712c7c4e3dSmrgnone)
7722c7c4e3dSmrg  exec "$@"
7732c7c4e3dSmrg  ;;
7742c7c4e3dSmrg
7752c7c4e3dSmrg*)
7762c7c4e3dSmrg  echo "Unknown depmode $depmode" 1>&2
7772c7c4e3dSmrg  exit 1
7782c7c4e3dSmrg  ;;
7792c7c4e3dSmrgesac
7802c7c4e3dSmrg
7812c7c4e3dSmrgexit 0
7828650bb69Smrg
7838650bb69Smrg# Local Variables:
7848650bb69Smrg# mode: shell-script
7858650bb69Smrg# sh-indentation: 2
7863458e6c2Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
7878650bb69Smrg# time-stamp-start: "scriptversion="
7888650bb69Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7893458e6c2Smrg# time-stamp-time-zone: "UTC0"
7908650bb69Smrg# time-stamp-end: "; # UTC"
7918650bb69Smrg# End:
792