14d9b34d9Smrg#! /bin/sh
24d9b34d9Smrg# depcomp - compile a program generating dependencies as side-effects
34d9b34d9Smrg
4ddb28773Smrgscriptversion=2018-03-07.03; # UTC
54d9b34d9Smrg
6ddb28773Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
74d9b34d9Smrg
84d9b34d9Smrg# This program is free software; you can redistribute it and/or modify
94d9b34d9Smrg# it under the terms of the GNU General Public License as published by
104d9b34d9Smrg# the Free Software Foundation; either version 2, or (at your option)
114d9b34d9Smrg# any later version.
124d9b34d9Smrg
134d9b34d9Smrg# This program is distributed in the hope that it will be useful,
144d9b34d9Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
154d9b34d9Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
164d9b34d9Smrg# GNU General Public License for more details.
174d9b34d9Smrg
184d9b34d9Smrg# You should have received a copy of the GNU General Public License
19ddb28773Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
204d9b34d9Smrg
214d9b34d9Smrg# As a special exception to the GNU General Public License, if you
224d9b34d9Smrg# distribute this file as part of a program that contains a
234d9b34d9Smrg# configuration script generated by Autoconf, you may include it under
244d9b34d9Smrg# the same distribution terms that you use for the rest of that program.
254d9b34d9Smrg
264d9b34d9Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
274d9b34d9Smrg
284d9b34d9Smrgcase $1 in
294d9b34d9Smrg  '')
3019d64aeeSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
3119d64aeeSmrg    exit 1;
3219d64aeeSmrg    ;;
334d9b34d9Smrg  -h | --h*)
344d9b34d9Smrg    cat <<\EOF
354d9b34d9SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
364d9b34d9Smrg
374d9b34d9SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
384d9b34d9Smrgas side-effects.
394d9b34d9Smrg
404d9b34d9SmrgEnvironment variables:
414d9b34d9Smrg  depmode     Dependency tracking mode.
4219d64aeeSmrg  source      Source file read by 'PROGRAMS ARGS'.
4319d64aeeSmrg  object      Object file output by 'PROGRAMS ARGS'.
444d9b34d9Smrg  DEPDIR      directory where to store dependencies.
454d9b34d9Smrg  depfile     Dependency file to output.
46498372abSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
474d9b34d9Smrg  libtool     Whether libtool is used (yes/no).
484d9b34d9Smrg
494d9b34d9SmrgReport bugs to <bug-automake@gnu.org>.
504d9b34d9SmrgEOF
514d9b34d9Smrg    exit $?
524d9b34d9Smrg    ;;
534d9b34d9Smrg  -v | --v*)
544d9b34d9Smrg    echo "depcomp $scriptversion"
554d9b34d9Smrg    exit $?
564d9b34d9Smrg    ;;
574d9b34d9Smrgesac
584d9b34d9Smrg
5919d64aeeSmrg# Get the directory component of the given path, and save it in the
6019d64aeeSmrg# global variables '$dir'.  Note that this directory component will
6119d64aeeSmrg# be either empty or ending with a '/' character.  This is deliberate.
6219d64aeeSmrgset_dir_from ()
6319d64aeeSmrg{
6419d64aeeSmrg  case $1 in
6519d64aeeSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
6619d64aeeSmrg      *) dir=;;
6719d64aeeSmrg  esac
6819d64aeeSmrg}
6919d64aeeSmrg
7019d64aeeSmrg# Get the suffix-stripped basename of the given path, and save it the
7119d64aeeSmrg# global variable '$base'.
7219d64aeeSmrgset_base_from ()
7319d64aeeSmrg{
7419d64aeeSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
7519d64aeeSmrg}
7619d64aeeSmrg
7719d64aeeSmrg# If no dependency file was actually created by the compiler invocation,
7819d64aeeSmrg# we still have to create a dummy depfile, to avoid errors with the
7919d64aeeSmrg# Makefile "include basename.Plo" scheme.
8019d64aeeSmrgmake_dummy_depfile ()
8119d64aeeSmrg{
8219d64aeeSmrg  echo "#dummy" > "$depfile"
8319d64aeeSmrg}
8419d64aeeSmrg
8519d64aeeSmrg# Factor out some common post-processing of the generated depfile.
8619d64aeeSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
8719d64aeeSmrgaix_post_process_depfile ()
8819d64aeeSmrg{
8919d64aeeSmrg  # If the compiler actually managed to produce a dependency file,
9019d64aeeSmrg  # post-process it.
9119d64aeeSmrg  if test -f "$tmpdepfile"; then
9219d64aeeSmrg    # Each line is of the form 'foo.o: dependency.h'.
9319d64aeeSmrg    # Do two passes, one to just change these to
9419d64aeeSmrg    #   $object: dependency.h
9519d64aeeSmrg    # and one to simply output
9619d64aeeSmrg    #   dependency.h:
9719d64aeeSmrg    # which is needed to avoid the deleted-header problem.
9819d64aeeSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
9919d64aeeSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
10019d64aeeSmrg    } > "$depfile"
10119d64aeeSmrg    rm -f "$tmpdepfile"
10219d64aeeSmrg  else
10319d64aeeSmrg    make_dummy_depfile
10419d64aeeSmrg  fi
10519d64aeeSmrg}
10619d64aeeSmrg
10719d64aeeSmrg# A tabulation character.
10819d64aeeSmrgtab='	'
10919d64aeeSmrg# A newline character.
11019d64aeeSmrgnl='
11119d64aeeSmrg'
11219d64aeeSmrg# Character ranges might be problematic outside the C locale.
11319d64aeeSmrg# These definitions help.
11419d64aeeSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
11519d64aeeSmrglower=abcdefghijklmnopqrstuvwxyz
11619d64aeeSmrgdigits=0123456789
11719d64aeeSmrgalpha=${upper}${lower}
11819d64aeeSmrg
1194d9b34d9Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1204d9b34d9Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1214d9b34d9Smrg  exit 1
1224d9b34d9Smrgfi
1234d9b34d9Smrg
1244d9b34d9Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1254d9b34d9Smrgdepfile=${depfile-`echo "$object" |
1264d9b34d9Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1274d9b34d9Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1284d9b34d9Smrg
1294d9b34d9Smrgrm -f "$tmpdepfile"
1304d9b34d9Smrg
13119d64aeeSmrg# Avoid interferences from the environment.
13219d64aeeSmrggccflag= dashmflag=
13319d64aeeSmrg
1344d9b34d9Smrg# Some modes work just like other modes, but use different flags.  We
1354d9b34d9Smrg# parameterize here, but still list the modes in the big case below,
1364d9b34d9Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1374d9b34d9Smrg# here, because this file can only contain one case statement.
1384d9b34d9Smrgif test "$depmode" = hp; then
1394d9b34d9Smrg  # HP compiler uses -M and no extra arg.
1404d9b34d9Smrg  gccflag=-M
1414d9b34d9Smrg  depmode=gcc
1424d9b34d9Smrgfi
1434d9b34d9Smrg
1444d9b34d9Smrgif test "$depmode" = dashXmstdout; then
14519d64aeeSmrg  # This is just like dashmstdout with a different argument.
14619d64aeeSmrg  dashmflag=-xM
14719d64aeeSmrg  depmode=dashmstdout
1484d9b34d9Smrgfi
1494d9b34d9Smrg
1508512f934Smrgcygpath_u="cygpath -u -f -"
1518512f934Smrgif test "$depmode" = msvcmsys; then
15219d64aeeSmrg  # This is just like msvisualcpp but w/o cygpath translation.
15319d64aeeSmrg  # Just convert the backslash-escaped backslashes to single forward
15419d64aeeSmrg  # slashes to satisfy depend.m4
15519d64aeeSmrg  cygpath_u='sed s,\\\\,/,g'
15619d64aeeSmrg  depmode=msvisualcpp
1578512f934Smrgfi
1588512f934Smrg
159498372abSmrgif test "$depmode" = msvc7msys; then
16019d64aeeSmrg  # This is just like msvc7 but w/o cygpath translation.
16119d64aeeSmrg  # Just convert the backslash-escaped backslashes to single forward
16219d64aeeSmrg  # slashes to satisfy depend.m4
16319d64aeeSmrg  cygpath_u='sed s,\\\\,/,g'
16419d64aeeSmrg  depmode=msvc7
16519d64aeeSmrgfi
16619d64aeeSmrg
16719d64aeeSmrgif test "$depmode" = xlc; then
16819d64aeeSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
16919d64aeeSmrg  gccflag=-qmakedep=gcc,-MF
17019d64aeeSmrg  depmode=gcc
171498372abSmrgfi
172498372abSmrg
1734d9b34d9Smrgcase "$depmode" in
1744d9b34d9Smrggcc3)
1754d9b34d9Smrg## gcc 3 implements dependency tracking that does exactly what
1764d9b34d9Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1774d9b34d9Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1784d9b34d9Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1794d9b34d9Smrg## the command line argument order; so add the flags where they
1804d9b34d9Smrg## appear in depend2.am.  Note that the slowdown incurred here
1814d9b34d9Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1824d9b34d9Smrg  for arg
1834d9b34d9Smrg  do
1844d9b34d9Smrg    case $arg in
1854d9b34d9Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1864d9b34d9Smrg    *)  set fnord "$@" "$arg" ;;
1874d9b34d9Smrg    esac
1884d9b34d9Smrg    shift # fnord
1894d9b34d9Smrg    shift # $arg
1904d9b34d9Smrg  done
1914d9b34d9Smrg  "$@"
1924d9b34d9Smrg  stat=$?
19319d64aeeSmrg  if test $stat -ne 0; then
1944d9b34d9Smrg    rm -f "$tmpdepfile"
1954d9b34d9Smrg    exit $stat
1964d9b34d9Smrg  fi
1974d9b34d9Smrg  mv "$tmpdepfile" "$depfile"
1984d9b34d9Smrg  ;;
1994d9b34d9Smrg
2004d9b34d9Smrggcc)
20119d64aeeSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
20219d64aeeSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
20319d64aeeSmrg## (see the conditional assignment to $gccflag above).
2044d9b34d9Smrg## There are various ways to get dependency output from gcc.  Here's
2054d9b34d9Smrg## why we pick this rather obscure method:
2064d9b34d9Smrg## - Don't want to use -MD because we'd like the dependencies to end
2074d9b34d9Smrg##   up in a subdir.  Having to rename by hand is ugly.
2084d9b34d9Smrg##   (We might end up doing this anyway to support other compilers.)
2094d9b34d9Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
21019d64aeeSmrg##   -MM, not -M (despite what the docs say).  Also, it might not be
21119d64aeeSmrg##   supported by the other compilers which use the 'gcc' depmode.
2124d9b34d9Smrg## - Using -M directly means running the compiler twice (even worse
2134d9b34d9Smrg##   than renaming).
2144d9b34d9Smrg  if test -z "$gccflag"; then
2154d9b34d9Smrg    gccflag=-MD,
2164d9b34d9Smrg  fi
2174d9b34d9Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
2184d9b34d9Smrg  stat=$?
21919d64aeeSmrg  if test $stat -ne 0; then
2204d9b34d9Smrg    rm -f "$tmpdepfile"
2214d9b34d9Smrg    exit $stat
2224d9b34d9Smrg  fi
2234d9b34d9Smrg  rm -f "$depfile"
2244d9b34d9Smrg  echo "$object : \\" > "$depfile"
22519d64aeeSmrg  # The second -e expression handles DOS-style file names with drive
22619d64aeeSmrg  # letters.
2274d9b34d9Smrg  sed -e 's/^[^:]*: / /' \
2284d9b34d9Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
22919d64aeeSmrg## This next piece of magic avoids the "deleted header file" problem.
2304d9b34d9Smrg## The problem is that when a header file which appears in a .P file
2314d9b34d9Smrg## is deleted, the dependency causes make to die (because there is
2324d9b34d9Smrg## typically no way to rebuild the header).  We avoid this by adding
2334d9b34d9Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2344d9b34d9Smrg## this for us directly.
23519d64aeeSmrg## Some versions of gcc put a space before the ':'.  On the theory
2364d9b34d9Smrg## that the space means something, we add a space to the output as
237498372abSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238498372abSmrg## to the object.  Take care to not repeat it in the output.
2394d9b34d9Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
2404d9b34d9Smrg## correctly.  Breaking it into two sed invocations is a workaround.
24119d64aeeSmrg  tr ' ' "$nl" < "$tmpdepfile" \
24219d64aeeSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
24319d64aeeSmrg    | sed -e 's/$/ :/' >> "$depfile"
2444d9b34d9Smrg  rm -f "$tmpdepfile"
2454d9b34d9Smrg  ;;
2464d9b34d9Smrg
2474d9b34d9Smrghp)
2484d9b34d9Smrg  # This case exists only to let depend.m4 do its work.  It works by
2494d9b34d9Smrg  # looking at the text of this script.  This case will never be run,
2504d9b34d9Smrg  # since it is checked for above.
2514d9b34d9Smrg  exit 1
2524d9b34d9Smrg  ;;
2534d9b34d9Smrg
2544d9b34d9Smrgsgi)
2554d9b34d9Smrg  if test "$libtool" = yes; then
2564d9b34d9Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2574d9b34d9Smrg  else
2584d9b34d9Smrg    "$@" -MDupdate "$tmpdepfile"
2594d9b34d9Smrg  fi
2604d9b34d9Smrg  stat=$?
26119d64aeeSmrg  if test $stat -ne 0; then
2624d9b34d9Smrg    rm -f "$tmpdepfile"
2634d9b34d9Smrg    exit $stat
2644d9b34d9Smrg  fi
2654d9b34d9Smrg  rm -f "$depfile"
2664d9b34d9Smrg
2674d9b34d9Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2684d9b34d9Smrg    echo "$object : \\" > "$depfile"
2694d9b34d9Smrg    # Clip off the initial element (the dependent).  Don't try to be
2704d9b34d9Smrg    # clever and replace this with sed code, as IRIX sed won't handle
2714d9b34d9Smrg    # lines with more than a fixed number of characters (4096 in
2724d9b34d9Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
27319d64aeeSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
2744d9b34d9Smrg    # dependency line.
27519d64aeeSmrg    tr ' ' "$nl" < "$tmpdepfile" \
27619d64aeeSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
27719d64aeeSmrg      | tr "$nl" ' ' >> "$depfile"
2788512f934Smrg    echo >> "$depfile"
2794d9b34d9Smrg    # The second pass generates a dummy entry for each header file.
28019d64aeeSmrg    tr ' ' "$nl" < "$tmpdepfile" \
28119d64aeeSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
28219d64aeeSmrg      >> "$depfile"
2834d9b34d9Smrg  else
28419d64aeeSmrg    make_dummy_depfile
2854d9b34d9Smrg  fi
2864d9b34d9Smrg  rm -f "$tmpdepfile"
2874d9b34d9Smrg  ;;
2884d9b34d9Smrg
28919d64aeeSmrgxlc)
29019d64aeeSmrg  # This case exists only to let depend.m4 do its work.  It works by
29119d64aeeSmrg  # looking at the text of this script.  This case will never be run,
29219d64aeeSmrg  # since it is checked for above.
29319d64aeeSmrg  exit 1
29419d64aeeSmrg  ;;
29519d64aeeSmrg
2964d9b34d9Smrgaix)
2974d9b34d9Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2984d9b34d9Smrg  # in a .u file.  In older versions, this file always lives in the
29919d64aeeSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3004d9b34d9Smrg  # start of each line; $object doesn't have directory information.
3014d9b34d9Smrg  # Version 6 uses the directory in both cases.
30219d64aeeSmrg  set_dir_from "$object"
30319d64aeeSmrg  set_base_from "$object"
3044d9b34d9Smrg  if test "$libtool" = yes; then
3058512f934Smrg    tmpdepfile1=$dir$base.u
3068512f934Smrg    tmpdepfile2=$base.u
3078512f934Smrg    tmpdepfile3=$dir.libs/$base.u
3084d9b34d9Smrg    "$@" -Wc,-M
3094d9b34d9Smrg  else
3108512f934Smrg    tmpdepfile1=$dir$base.u
3118512f934Smrg    tmpdepfile2=$dir$base.u
3128512f934Smrg    tmpdepfile3=$dir$base.u
3134d9b34d9Smrg    "$@" -M
3144d9b34d9Smrg  fi
3154d9b34d9Smrg  stat=$?
31619d64aeeSmrg  if test $stat -ne 0; then
3178512f934Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3184d9b34d9Smrg    exit $stat
3194d9b34d9Smrg  fi
3204d9b34d9Smrg
3218512f934Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3228512f934Smrg  do
3238512f934Smrg    test -f "$tmpdepfile" && break
3248512f934Smrg  done
32519d64aeeSmrg  aix_post_process_depfile
32619d64aeeSmrg  ;;
32719d64aeeSmrg
32819d64aeeSmrgtcc)
32919d64aeeSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
33019d64aeeSmrg  # FIXME: That version still under development at the moment of writing.
33119d64aeeSmrg  #        Make that this statement remains true also for stable, released
33219d64aeeSmrg  #        versions.
33319d64aeeSmrg  # It will wrap lines (doesn't matter whether long or short) with a
33419d64aeeSmrg  # trailing '\', as in:
33519d64aeeSmrg  #
33619d64aeeSmrg  #   foo.o : \
33719d64aeeSmrg  #    foo.c \
33819d64aeeSmrg  #    foo.h \
33919d64aeeSmrg  #
34019d64aeeSmrg  # It will put a trailing '\' even on the last line, and will use leading
34119d64aeeSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
34219d64aeeSmrg  # "Emit spaces for -MD").
34319d64aeeSmrg  "$@" -MD -MF "$tmpdepfile"
34419d64aeeSmrg  stat=$?
34519d64aeeSmrg  if test $stat -ne 0; then
34619d64aeeSmrg    rm -f "$tmpdepfile"
34719d64aeeSmrg    exit $stat
3484d9b34d9Smrg  fi
34919d64aeeSmrg  rm -f "$depfile"
35019d64aeeSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
35119d64aeeSmrg  # We have to change lines of the first kind to '$object: \'.
35219d64aeeSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
35319d64aeeSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
35419d64aeeSmrg  # dummy dependency, to avoid the deleted-header problem.
35519d64aeeSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3564d9b34d9Smrg  rm -f "$tmpdepfile"
3574d9b34d9Smrg  ;;
3584d9b34d9Smrg
35919d64aeeSmrg## The order of this option in the case statement is important, since the
36019d64aeeSmrg## shell code in configure will try each of these formats in the order
36119d64aeeSmrg## listed in this file.  A plain '-MD' option would be understood by many
36219d64aeeSmrg## compilers, so we must ensure this comes after the gcc and icc options.
36319d64aeeSmrgpgcc)
36419d64aeeSmrg  # Portland's C compiler understands '-MD'.
36519d64aeeSmrg  # Will always output deps to 'file.d' where file is the root name of the
36619d64aeeSmrg  # source file under compilation, even if file resides in a subdirectory.
36719d64aeeSmrg  # The object file name does not affect the name of the '.d' file.
36819d64aeeSmrg  # pgcc 10.2 will output
3694d9b34d9Smrg  #    foo.o: sub/foo.c sub/foo.h
37019d64aeeSmrg  # and will wrap long lines using '\' :
3714d9b34d9Smrg  #    foo.o: sub/foo.c ... \
3724d9b34d9Smrg  #     sub/foo.h ... \
3734d9b34d9Smrg  #     ...
37419d64aeeSmrg  set_dir_from "$object"
37519d64aeeSmrg  # Use the source, not the object, to determine the base name, since
37619d64aeeSmrg  # that's sadly what pgcc will do too.
37719d64aeeSmrg  set_base_from "$source"
37819d64aeeSmrg  tmpdepfile=$base.d
37919d64aeeSmrg
38019d64aeeSmrg  # For projects that build the same source file twice into different object
38119d64aeeSmrg  # files, the pgcc approach of using the *source* file root name can cause
38219d64aeeSmrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
38319d64aeeSmrg  # the same $tmpdepfile.
38419d64aeeSmrg  lockdir=$base.d-lock
38519d64aeeSmrg  trap "
38619d64aeeSmrg    echo '$0: caught signal, cleaning up...' >&2
38719d64aeeSmrg    rmdir '$lockdir'
38819d64aeeSmrg    exit 1
38919d64aeeSmrg  " 1 2 13 15
39019d64aeeSmrg  numtries=100
39119d64aeeSmrg  i=$numtries
39219d64aeeSmrg  while test $i -gt 0; do
39319d64aeeSmrg    # mkdir is a portable test-and-set.
39419d64aeeSmrg    if mkdir "$lockdir" 2>/dev/null; then
39519d64aeeSmrg      # This process acquired the lock.
39619d64aeeSmrg      "$@" -MD
39719d64aeeSmrg      stat=$?
39819d64aeeSmrg      # Release the lock.
39919d64aeeSmrg      rmdir "$lockdir"
40019d64aeeSmrg      break
40119d64aeeSmrg    else
40219d64aeeSmrg      # If the lock is being held by a different process, wait
40319d64aeeSmrg      # until the winning process is done or we timeout.
40419d64aeeSmrg      while test -d "$lockdir" && test $i -gt 0; do
40519d64aeeSmrg        sleep 1
40619d64aeeSmrg        i=`expr $i - 1`
40719d64aeeSmrg      done
40819d64aeeSmrg    fi
40919d64aeeSmrg    i=`expr $i - 1`
41019d64aeeSmrg  done
41119d64aeeSmrg  trap - 1 2 13 15
41219d64aeeSmrg  if test $i -le 0; then
41319d64aeeSmrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
41419d64aeeSmrg    echo "$0: check lockdir '$lockdir'" >&2
41519d64aeeSmrg    exit 1
41619d64aeeSmrg  fi
4174d9b34d9Smrg
41819d64aeeSmrg  if test $stat -ne 0; then
4194d9b34d9Smrg    rm -f "$tmpdepfile"
4204d9b34d9Smrg    exit $stat
4214d9b34d9Smrg  fi
4224d9b34d9Smrg  rm -f "$depfile"
4234d9b34d9Smrg  # Each line is of the form `foo.o: dependent.h',
4244d9b34d9Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4254d9b34d9Smrg  # Do two passes, one to just change these to
4264d9b34d9Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4274d9b34d9Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4284d9b34d9Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4294d9b34d9Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
43019d64aeeSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
43119d64aeeSmrg    | sed -e 's/$/ :/' >> "$depfile"
4324d9b34d9Smrg  rm -f "$tmpdepfile"
4334d9b34d9Smrg  ;;
4344d9b34d9Smrg
4354d9b34d9Smrghp2)
4364d9b34d9Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4374d9b34d9Smrg  # compilers, which have integrated preprocessors.  The correct option
4384d9b34d9Smrg  # to use with these is +Maked; it writes dependencies to a file named
4394d9b34d9Smrg  # 'foo.d', which lands next to the object file, wherever that
4404d9b34d9Smrg  # happens to be.
4414d9b34d9Smrg  # Much of this is similar to the tru64 case; see comments there.
44219d64aeeSmrg  set_dir_from  "$object"
44319d64aeeSmrg  set_base_from "$object"
4444d9b34d9Smrg  if test "$libtool" = yes; then
4454d9b34d9Smrg    tmpdepfile1=$dir$base.d
4464d9b34d9Smrg    tmpdepfile2=$dir.libs/$base.d
4474d9b34d9Smrg    "$@" -Wc,+Maked
4484d9b34d9Smrg  else
4494d9b34d9Smrg    tmpdepfile1=$dir$base.d
4504d9b34d9Smrg    tmpdepfile2=$dir$base.d
4514d9b34d9Smrg    "$@" +Maked
4524d9b34d9Smrg  fi
4534d9b34d9Smrg  stat=$?
45419d64aeeSmrg  if test $stat -ne 0; then
4554d9b34d9Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4564d9b34d9Smrg     exit $stat
4574d9b34d9Smrg  fi
4584d9b34d9Smrg
4594d9b34d9Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4604d9b34d9Smrg  do
4614d9b34d9Smrg    test -f "$tmpdepfile" && break
4624d9b34d9Smrg  done
4634d9b34d9Smrg  if test -f "$tmpdepfile"; then
46419d64aeeSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
46519d64aeeSmrg    # Add 'dependent.h:' lines.
4668512f934Smrg    sed -ne '2,${
46719d64aeeSmrg               s/^ *//
46819d64aeeSmrg               s/ \\*$//
46919d64aeeSmrg               s/$/:/
47019d64aeeSmrg               p
47119d64aeeSmrg             }' "$tmpdepfile" >> "$depfile"
4724d9b34d9Smrg  else
47319d64aeeSmrg    make_dummy_depfile
4744d9b34d9Smrg  fi
4754d9b34d9Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4764d9b34d9Smrg  ;;
4774d9b34d9Smrg
4784d9b34d9Smrgtru64)
47919d64aeeSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
48019d64aeeSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
48119d64aeeSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
48219d64aeeSmrg  # dependencies in 'foo.d' instead, so we check for that too.
48319d64aeeSmrg  # Subdirectories are respected.
48419d64aeeSmrg  set_dir_from  "$object"
48519d64aeeSmrg  set_base_from "$object"
48619d64aeeSmrg
48719d64aeeSmrg  if test "$libtool" = yes; then
48819d64aeeSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
48919d64aeeSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
49019d64aeeSmrg    # in $dir$base.o.d.  We have to check for both files, because
49119d64aeeSmrg    # one of the two compilations can be disabled.  We should prefer
49219d64aeeSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
49319d64aeeSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
49419d64aeeSmrg    # the former would cause a distcleancheck panic.
49519d64aeeSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
49619d64aeeSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
49719d64aeeSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
49819d64aeeSmrg    "$@" -Wc,-MD
49919d64aeeSmrg  else
50019d64aeeSmrg    tmpdepfile1=$dir$base.d
50119d64aeeSmrg    tmpdepfile2=$dir$base.d
50219d64aeeSmrg    tmpdepfile3=$dir$base.d
50319d64aeeSmrg    "$@" -MD
50419d64aeeSmrg  fi
50519d64aeeSmrg
50619d64aeeSmrg  stat=$?
50719d64aeeSmrg  if test $stat -ne 0; then
50819d64aeeSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
50919d64aeeSmrg    exit $stat
51019d64aeeSmrg  fi
51119d64aeeSmrg
51219d64aeeSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
51319d64aeeSmrg  do
51419d64aeeSmrg    test -f "$tmpdepfile" && break
51519d64aeeSmrg  done
51619d64aeeSmrg  # Same post-processing that is required for AIX mode.
51719d64aeeSmrg  aix_post_process_depfile
51819d64aeeSmrg  ;;
5194d9b34d9Smrg
520498372abSmrgmsvc7)
521498372abSmrg  if test "$libtool" = yes; then
522498372abSmrg    showIncludes=-Wc,-showIncludes
523498372abSmrg  else
524498372abSmrg    showIncludes=-showIncludes
525498372abSmrg  fi
526498372abSmrg  "$@" $showIncludes > "$tmpdepfile"
527498372abSmrg  stat=$?
528498372abSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
52919d64aeeSmrg  if test $stat -ne 0; then
530498372abSmrg    rm -f "$tmpdepfile"
531498372abSmrg    exit $stat
532498372abSmrg  fi
533498372abSmrg  rm -f "$depfile"
534498372abSmrg  echo "$object : \\" > "$depfile"
535498372abSmrg  # The first sed program below extracts the file names and escapes
536498372abSmrg  # backslashes for cygpath.  The second sed program outputs the file
537498372abSmrg  # name when reading, but also accumulates all include files in the
538498372abSmrg  # hold buffer in order to output them again at the end.  This only
539498372abSmrg  # works with sed implementations that can handle large buffers.
540498372abSmrg  sed < "$tmpdepfile" -n '
541498372abSmrg/^Note: including file:  *\(.*\)/ {
542498372abSmrg  s//\1/
543498372abSmrg  s/\\/\\\\/g
544498372abSmrg  p
545498372abSmrg}' | $cygpath_u | sort -u | sed -n '
546498372abSmrgs/ /\\ /g
54719d64aeeSmrgs/\(.*\)/'"$tab"'\1 \\/p
548498372abSmrgs/.\(.*\) \\/\1:/
549498372abSmrgH
550498372abSmrg$ {
55119d64aeeSmrg  s/.*/'"$tab"'/
552498372abSmrg  G
553498372abSmrg  p
554498372abSmrg}' >> "$depfile"
55519d64aeeSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556498372abSmrg  rm -f "$tmpdepfile"
557498372abSmrg  ;;
558498372abSmrg
559498372abSmrgmsvc7msys)
560498372abSmrg  # This case exists only to let depend.m4 do its work.  It works by
561498372abSmrg  # looking at the text of this script.  This case will never be run,
562498372abSmrg  # since it is checked for above.
563498372abSmrg  exit 1
564498372abSmrg  ;;
565498372abSmrg
5664d9b34d9Smrg#nosideeffect)
5674d9b34d9Smrg  # This comment above is used by automake to tell side-effect
5684d9b34d9Smrg  # dependency tracking mechanisms from slower ones.
5694d9b34d9Smrg
5704d9b34d9Smrgdashmstdout)
5714d9b34d9Smrg  # Important note: in order to support this mode, a compiler *must*
5724d9b34d9Smrg  # always write the preprocessed file to stdout, regardless of -o.
5734d9b34d9Smrg  "$@" || exit $?
5744d9b34d9Smrg
5754d9b34d9Smrg  # Remove the call to Libtool.
5764d9b34d9Smrg  if test "$libtool" = yes; then
5778512f934Smrg    while test "X$1" != 'X--mode=compile'; do
5784d9b34d9Smrg      shift
5794d9b34d9Smrg    done
5804d9b34d9Smrg    shift
5814d9b34d9Smrg  fi
5824d9b34d9Smrg
58319d64aeeSmrg  # Remove '-o $object'.
5844d9b34d9Smrg  IFS=" "
5854d9b34d9Smrg  for arg
5864d9b34d9Smrg  do
5874d9b34d9Smrg    case $arg in
5884d9b34d9Smrg    -o)
5894d9b34d9Smrg      shift
5904d9b34d9Smrg      ;;
5914d9b34d9Smrg    $object)
5924d9b34d9Smrg      shift
5934d9b34d9Smrg      ;;
5944d9b34d9Smrg    *)
5954d9b34d9Smrg      set fnord "$@" "$arg"
5964d9b34d9Smrg      shift # fnord
5974d9b34d9Smrg      shift # $arg
5984d9b34d9Smrg      ;;
5994d9b34d9Smrg    esac
6004d9b34d9Smrg  done
6014d9b34d9Smrg
6024d9b34d9Smrg  test -z "$dashmflag" && dashmflag=-M
60319d64aeeSmrg  # Require at least two characters before searching for ':'
6044d9b34d9Smrg  # in the target name.  This is to cope with DOS-style filenames:
60519d64aeeSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6064d9b34d9Smrg  "$@" $dashmflag |
60719d64aeeSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6084d9b34d9Smrg  rm -f "$depfile"
6094d9b34d9Smrg  cat < "$tmpdepfile" > "$depfile"
61019d64aeeSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
61119d64aeeSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
61219d64aeeSmrg  tr ' ' "$nl" < "$tmpdepfile" \
61319d64aeeSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
61419d64aeeSmrg    | sed -e 's/$/ :/' >> "$depfile"
6154d9b34d9Smrg  rm -f "$tmpdepfile"
6164d9b34d9Smrg  ;;
6174d9b34d9Smrg
6184d9b34d9SmrgdashXmstdout)
6194d9b34d9Smrg  # This case only exists to satisfy depend.m4.  It is never actually
6204d9b34d9Smrg  # run, as this mode is specially recognized in the preamble.
6214d9b34d9Smrg  exit 1
6224d9b34d9Smrg  ;;
6234d9b34d9Smrg
6244d9b34d9Smrgmakedepend)
6254d9b34d9Smrg  "$@" || exit $?
6264d9b34d9Smrg  # Remove any Libtool call
6274d9b34d9Smrg  if test "$libtool" = yes; then
6288512f934Smrg    while test "X$1" != 'X--mode=compile'; do
6294d9b34d9Smrg      shift
6304d9b34d9Smrg    done
6314d9b34d9Smrg    shift
6324d9b34d9Smrg  fi
6334d9b34d9Smrg  # X makedepend
6344d9b34d9Smrg  shift
6358512f934Smrg  cleared=no eat=no
6368512f934Smrg  for arg
6378512f934Smrg  do
6384d9b34d9Smrg    case $cleared in
6394d9b34d9Smrg    no)
6404d9b34d9Smrg      set ""; shift
6414d9b34d9Smrg      cleared=yes ;;
6424d9b34d9Smrg    esac
6438512f934Smrg    if test $eat = yes; then
6448512f934Smrg      eat=no
6458512f934Smrg      continue
6468512f934Smrg    fi
6474d9b34d9Smrg    case "$arg" in
6484d9b34d9Smrg    -D*|-I*)
6494d9b34d9Smrg      set fnord "$@" "$arg"; shift ;;
6504d9b34d9Smrg    # Strip any option that makedepend may not understand.  Remove
6514d9b34d9Smrg    # the object too, otherwise makedepend will parse it as a source file.
6528512f934Smrg    -arch)
6538512f934Smrg      eat=yes ;;
6544d9b34d9Smrg    -*|$object)
6554d9b34d9Smrg      ;;
6564d9b34d9Smrg    *)
6574d9b34d9Smrg      set fnord "$@" "$arg"; shift ;;
6584d9b34d9Smrg    esac
6594d9b34d9Smrg  done
6608512f934Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6614d9b34d9Smrg  touch "$tmpdepfile"
6624d9b34d9Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6634d9b34d9Smrg  rm -f "$depfile"
664498372abSmrg  # makedepend may prepend the VPATH from the source file name to the object.
665498372abSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666498372abSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
66719d64aeeSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
66819d64aeeSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
66919d64aeeSmrg  sed '1,2d' "$tmpdepfile" \
67019d64aeeSmrg    | tr ' ' "$nl" \
67119d64aeeSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
67219d64aeeSmrg    | sed -e 's/$/ :/' >> "$depfile"
6734d9b34d9Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6744d9b34d9Smrg  ;;
6754d9b34d9Smrg
6764d9b34d9Smrgcpp)
6774d9b34d9Smrg  # Important note: in order to support this mode, a compiler *must*
6784d9b34d9Smrg  # always write the preprocessed file to stdout.
6794d9b34d9Smrg  "$@" || exit $?
6804d9b34d9Smrg
6814d9b34d9Smrg  # Remove the call to Libtool.
6824d9b34d9Smrg  if test "$libtool" = yes; then
6838512f934Smrg    while test "X$1" != 'X--mode=compile'; do
6844d9b34d9Smrg      shift
6854d9b34d9Smrg    done
6864d9b34d9Smrg    shift
6874d9b34d9Smrg  fi
6884d9b34d9Smrg
68919d64aeeSmrg  # Remove '-o $object'.
6904d9b34d9Smrg  IFS=" "
6914d9b34d9Smrg  for arg
6924d9b34d9Smrg  do
6934d9b34d9Smrg    case $arg in
6944d9b34d9Smrg    -o)
6954d9b34d9Smrg      shift
6964d9b34d9Smrg      ;;
6974d9b34d9Smrg    $object)
6984d9b34d9Smrg      shift
6994d9b34d9Smrg      ;;
7004d9b34d9Smrg    *)
7014d9b34d9Smrg      set fnord "$@" "$arg"
7024d9b34d9Smrg      shift # fnord
7034d9b34d9Smrg      shift # $arg
7044d9b34d9Smrg      ;;
7054d9b34d9Smrg    esac
7064d9b34d9Smrg  done
7074d9b34d9Smrg
70819d64aeeSmrg  "$@" -E \
70919d64aeeSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71019d64aeeSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71119d64aeeSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
7124d9b34d9Smrg  rm -f "$depfile"
7134d9b34d9Smrg  echo "$object : \\" > "$depfile"
7144d9b34d9Smrg  cat < "$tmpdepfile" >> "$depfile"
7154d9b34d9Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7164d9b34d9Smrg  rm -f "$tmpdepfile"
7174d9b34d9Smrg  ;;
7184d9b34d9Smrg
7194d9b34d9Smrgmsvisualcpp)
7204d9b34d9Smrg  # Important note: in order to support this mode, a compiler *must*
7218512f934Smrg  # always write the preprocessed file to stdout.
7224d9b34d9Smrg  "$@" || exit $?
7238512f934Smrg
7248512f934Smrg  # Remove the call to Libtool.
7258512f934Smrg  if test "$libtool" = yes; then
7268512f934Smrg    while test "X$1" != 'X--mode=compile'; do
7278512f934Smrg      shift
7288512f934Smrg    done
7298512f934Smrg    shift
7308512f934Smrg  fi
7318512f934Smrg
7324d9b34d9Smrg  IFS=" "
7334d9b34d9Smrg  for arg
7344d9b34d9Smrg  do
7354d9b34d9Smrg    case "$arg" in
7368512f934Smrg    -o)
7378512f934Smrg      shift
7388512f934Smrg      ;;
7398512f934Smrg    $object)
7408512f934Smrg      shift
7418512f934Smrg      ;;
7424d9b34d9Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
74319d64aeeSmrg        set fnord "$@"
74419d64aeeSmrg        shift
74519d64aeeSmrg        shift
74619d64aeeSmrg        ;;
7474d9b34d9Smrg    *)
74819d64aeeSmrg        set fnord "$@" "$arg"
74919d64aeeSmrg        shift
75019d64aeeSmrg        shift
75119d64aeeSmrg        ;;
7524d9b34d9Smrg    esac
7534d9b34d9Smrg  done
7548512f934Smrg  "$@" -E 2>/dev/null |
7558512f934Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7564d9b34d9Smrg  rm -f "$depfile"
7574d9b34d9Smrg  echo "$object : \\" > "$depfile"
75819d64aeeSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
75919d64aeeSmrg  echo "$tab" >> "$depfile"
7608512f934Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7614d9b34d9Smrg  rm -f "$tmpdepfile"
7624d9b34d9Smrg  ;;
7634d9b34d9Smrg
7648512f934Smrgmsvcmsys)
7658512f934Smrg  # This case exists only to let depend.m4 do its work.  It works by
7668512f934Smrg  # looking at the text of this script.  This case will never be run,
7678512f934Smrg  # since it is checked for above.
7688512f934Smrg  exit 1
7698512f934Smrg  ;;
7708512f934Smrg
7714d9b34d9Smrgnone)
7724d9b34d9Smrg  exec "$@"
7734d9b34d9Smrg  ;;
7744d9b34d9Smrg
7754d9b34d9Smrg*)
7764d9b34d9Smrg  echo "Unknown depmode $depmode" 1>&2
7774d9b34d9Smrg  exit 1
7784d9b34d9Smrg  ;;
7794d9b34d9Smrgesac
7804d9b34d9Smrg
7814d9b34d9Smrgexit 0
7824d9b34d9Smrg
7834d9b34d9Smrg# Local Variables:
7844d9b34d9Smrg# mode: shell-script
7854d9b34d9Smrg# sh-indentation: 2
786ddb28773Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
7874d9b34d9Smrg# time-stamp-start: "scriptversion="
7884d9b34d9Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789ddb28773Smrg# time-stamp-time-zone: "UTC0"
7908512f934Smrg# time-stamp-end: "; # UTC"
7914d9b34d9Smrg# End:
792