1fc5a983dSmrg#! /bin/sh
2fc5a983dSmrg# depcomp - compile a program generating dependencies as side-effects
3fc5a983dSmrg
4d422ce2eSmrgscriptversion=2018-03-07.03; # UTC
5fc5a983dSmrg
6d422ce2eSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
7fc5a983dSmrg
8fc5a983dSmrg# This program is free software; you can redistribute it and/or modify
9fc5a983dSmrg# it under the terms of the GNU General Public License as published by
10fc5a983dSmrg# the Free Software Foundation; either version 2, or (at your option)
11fc5a983dSmrg# any later version.
12fc5a983dSmrg
13fc5a983dSmrg# This program is distributed in the hope that it will be useful,
14fc5a983dSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15fc5a983dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16fc5a983dSmrg# GNU General Public License for more details.
17fc5a983dSmrg
18fc5a983dSmrg# You should have received a copy of the GNU General Public License
19d422ce2eSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20fc5a983dSmrg
21fc5a983dSmrg# As a special exception to the GNU General Public License, if you
22fc5a983dSmrg# distribute this file as part of a program that contains a
23fc5a983dSmrg# configuration script generated by Autoconf, you may include it under
24fc5a983dSmrg# the same distribution terms that you use for the rest of that program.
25fc5a983dSmrg
26fc5a983dSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27fc5a983dSmrg
28fc5a983dSmrgcase $1 in
29fc5a983dSmrg  '')
306257f37dSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
316257f37dSmrg    exit 1;
326257f37dSmrg    ;;
33fc5a983dSmrg  -h | --h*)
34fc5a983dSmrg    cat <<\EOF
35fc5a983dSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36fc5a983dSmrg
37fc5a983dSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38fc5a983dSmrgas side-effects.
39fc5a983dSmrg
40fc5a983dSmrgEnvironment variables:
41fc5a983dSmrg  depmode     Dependency tracking mode.
426257f37dSmrg  source      Source file read by 'PROGRAMS ARGS'.
436257f37dSmrg  object      Object file output by 'PROGRAMS ARGS'.
44fc5a983dSmrg  DEPDIR      directory where to store dependencies.
45fc5a983dSmrg  depfile     Dependency file to output.
46bd304fc0Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
47fc5a983dSmrg  libtool     Whether libtool is used (yes/no).
48fc5a983dSmrg
49fc5a983dSmrgReport bugs to <bug-automake@gnu.org>.
50fc5a983dSmrgEOF
51fc5a983dSmrg    exit $?
52fc5a983dSmrg    ;;
53fc5a983dSmrg  -v | --v*)
54fc5a983dSmrg    echo "depcomp $scriptversion"
55fc5a983dSmrg    exit $?
56fc5a983dSmrg    ;;
57fc5a983dSmrgesac
58fc5a983dSmrg
596257f37dSmrg# Get the directory component of the given path, and save it in the
606257f37dSmrg# global variables '$dir'.  Note that this directory component will
616257f37dSmrg# be either empty or ending with a '/' character.  This is deliberate.
626257f37dSmrgset_dir_from ()
636257f37dSmrg{
646257f37dSmrg  case $1 in
656257f37dSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
666257f37dSmrg      *) dir=;;
676257f37dSmrg  esac
686257f37dSmrg}
696257f37dSmrg
706257f37dSmrg# Get the suffix-stripped basename of the given path, and save it the
716257f37dSmrg# global variable '$base'.
726257f37dSmrgset_base_from ()
736257f37dSmrg{
746257f37dSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
756257f37dSmrg}
766257f37dSmrg
776257f37dSmrg# If no dependency file was actually created by the compiler invocation,
786257f37dSmrg# we still have to create a dummy depfile, to avoid errors with the
796257f37dSmrg# Makefile "include basename.Plo" scheme.
806257f37dSmrgmake_dummy_depfile ()
816257f37dSmrg{
826257f37dSmrg  echo "#dummy" > "$depfile"
836257f37dSmrg}
846257f37dSmrg
856257f37dSmrg# Factor out some common post-processing of the generated depfile.
866257f37dSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
876257f37dSmrgaix_post_process_depfile ()
886257f37dSmrg{
896257f37dSmrg  # If the compiler actually managed to produce a dependency file,
906257f37dSmrg  # post-process it.
916257f37dSmrg  if test -f "$tmpdepfile"; then
926257f37dSmrg    # Each line is of the form 'foo.o: dependency.h'.
936257f37dSmrg    # Do two passes, one to just change these to
946257f37dSmrg    #   $object: dependency.h
956257f37dSmrg    # and one to simply output
966257f37dSmrg    #   dependency.h:
976257f37dSmrg    # which is needed to avoid the deleted-header problem.
986257f37dSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
996257f37dSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1006257f37dSmrg    } > "$depfile"
1016257f37dSmrg    rm -f "$tmpdepfile"
1026257f37dSmrg  else
1036257f37dSmrg    make_dummy_depfile
1046257f37dSmrg  fi
1056257f37dSmrg}
1066257f37dSmrg
1076257f37dSmrg# A tabulation character.
1086257f37dSmrgtab='	'
1096257f37dSmrg# A newline character.
1106257f37dSmrgnl='
1116257f37dSmrg'
1126257f37dSmrg# Character ranges might be problematic outside the C locale.
1136257f37dSmrg# These definitions help.
1146257f37dSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1156257f37dSmrglower=abcdefghijklmnopqrstuvwxyz
1166257f37dSmrgdigits=0123456789
1176257f37dSmrgalpha=${upper}${lower}
1186257f37dSmrg
119fc5a983dSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120fc5a983dSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121fc5a983dSmrg  exit 1
122fc5a983dSmrgfi
123fc5a983dSmrg
124fc5a983dSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125fc5a983dSmrgdepfile=${depfile-`echo "$object" |
126fc5a983dSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127fc5a983dSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128fc5a983dSmrg
129fc5a983dSmrgrm -f "$tmpdepfile"
130fc5a983dSmrg
1316257f37dSmrg# Avoid interferences from the environment.
1326257f37dSmrggccflag= dashmflag=
1336257f37dSmrg
134fc5a983dSmrg# Some modes work just like other modes, but use different flags.  We
135fc5a983dSmrg# parameterize here, but still list the modes in the big case below,
136fc5a983dSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137fc5a983dSmrg# here, because this file can only contain one case statement.
138fc5a983dSmrgif test "$depmode" = hp; then
139fc5a983dSmrg  # HP compiler uses -M and no extra arg.
140fc5a983dSmrg  gccflag=-M
141fc5a983dSmrg  depmode=gcc
142fc5a983dSmrgfi
143fc5a983dSmrg
144fc5a983dSmrgif test "$depmode" = dashXmstdout; then
1456257f37dSmrg  # This is just like dashmstdout with a different argument.
1466257f37dSmrg  dashmflag=-xM
1476257f37dSmrg  depmode=dashmstdout
148fc5a983dSmrgfi
149fc5a983dSmrg
150bd304fc0Smrgcygpath_u="cygpath -u -f -"
151bd304fc0Smrgif test "$depmode" = msvcmsys; then
1526257f37dSmrg  # This is just like msvisualcpp but w/o cygpath translation.
1536257f37dSmrg  # Just convert the backslash-escaped backslashes to single forward
1546257f37dSmrg  # slashes to satisfy depend.m4
1556257f37dSmrg  cygpath_u='sed s,\\\\,/,g'
1566257f37dSmrg  depmode=msvisualcpp
157bd304fc0Smrgfi
158bd304fc0Smrg
159bd304fc0Smrgif test "$depmode" = msvc7msys; then
1606257f37dSmrg  # This is just like msvc7 but w/o cygpath translation.
1616257f37dSmrg  # Just convert the backslash-escaped backslashes to single forward
1626257f37dSmrg  # slashes to satisfy depend.m4
1636257f37dSmrg  cygpath_u='sed s,\\\\,/,g'
1646257f37dSmrg  depmode=msvc7
1656257f37dSmrgfi
1666257f37dSmrg
1676257f37dSmrgif test "$depmode" = xlc; then
1686257f37dSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1696257f37dSmrg  gccflag=-qmakedep=gcc,-MF
1706257f37dSmrg  depmode=gcc
171bd304fc0Smrgfi
172bd304fc0Smrg
173fc5a983dSmrgcase "$depmode" in
174fc5a983dSmrggcc3)
175fc5a983dSmrg## gcc 3 implements dependency tracking that does exactly what
176fc5a983dSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177fc5a983dSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178fc5a983dSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179fc5a983dSmrg## the command line argument order; so add the flags where they
180fc5a983dSmrg## appear in depend2.am.  Note that the slowdown incurred here
181fc5a983dSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182fc5a983dSmrg  for arg
183fc5a983dSmrg  do
184fc5a983dSmrg    case $arg in
185fc5a983dSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186fc5a983dSmrg    *)  set fnord "$@" "$arg" ;;
187fc5a983dSmrg    esac
188fc5a983dSmrg    shift # fnord
189fc5a983dSmrg    shift # $arg
190fc5a983dSmrg  done
191fc5a983dSmrg  "$@"
192fc5a983dSmrg  stat=$?
1936257f37dSmrg  if test $stat -ne 0; then
194fc5a983dSmrg    rm -f "$tmpdepfile"
195fc5a983dSmrg    exit $stat
196fc5a983dSmrg  fi
197fc5a983dSmrg  mv "$tmpdepfile" "$depfile"
198fc5a983dSmrg  ;;
199fc5a983dSmrg
200fc5a983dSmrggcc)
2016257f37dSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2026257f37dSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2036257f37dSmrg## (see the conditional assignment to $gccflag above).
204fc5a983dSmrg## There are various ways to get dependency output from gcc.  Here's
205fc5a983dSmrg## why we pick this rather obscure method:
206fc5a983dSmrg## - Don't want to use -MD because we'd like the dependencies to end
207fc5a983dSmrg##   up in a subdir.  Having to rename by hand is ugly.
208fc5a983dSmrg##   (We might end up doing this anyway to support other compilers.)
209fc5a983dSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2106257f37dSmrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2116257f37dSmrg##   supported by the other compilers which use the 'gcc' depmode.
212fc5a983dSmrg## - Using -M directly means running the compiler twice (even worse
213fc5a983dSmrg##   than renaming).
214fc5a983dSmrg  if test -z "$gccflag"; then
215fc5a983dSmrg    gccflag=-MD,
216fc5a983dSmrg  fi
217fc5a983dSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
218fc5a983dSmrg  stat=$?
2196257f37dSmrg  if test $stat -ne 0; then
220fc5a983dSmrg    rm -f "$tmpdepfile"
221fc5a983dSmrg    exit $stat
222fc5a983dSmrg  fi
223fc5a983dSmrg  rm -f "$depfile"
224fc5a983dSmrg  echo "$object : \\" > "$depfile"
2256257f37dSmrg  # The second -e expression handles DOS-style file names with drive
2266257f37dSmrg  # letters.
227fc5a983dSmrg  sed -e 's/^[^:]*: / /' \
228fc5a983dSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2296257f37dSmrg## This next piece of magic avoids the "deleted header file" problem.
230fc5a983dSmrg## The problem is that when a header file which appears in a .P file
231fc5a983dSmrg## is deleted, the dependency causes make to die (because there is
232fc5a983dSmrg## typically no way to rebuild the header).  We avoid this by adding
233fc5a983dSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234fc5a983dSmrg## this for us directly.
2356257f37dSmrg## Some versions of gcc put a space before the ':'.  On the theory
236fc5a983dSmrg## that the space means something, we add a space to the output as
237bd304fc0Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238bd304fc0Smrg## to the object.  Take care to not repeat it in the output.
239fc5a983dSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
240fc5a983dSmrg## correctly.  Breaking it into two sed invocations is a workaround.
2416257f37dSmrg  tr ' ' "$nl" < "$tmpdepfile" \
2426257f37dSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2436257f37dSmrg    | sed -e 's/$/ :/' >> "$depfile"
244fc5a983dSmrg  rm -f "$tmpdepfile"
245fc5a983dSmrg  ;;
246fc5a983dSmrg
247fc5a983dSmrghp)
248fc5a983dSmrg  # This case exists only to let depend.m4 do its work.  It works by
249fc5a983dSmrg  # looking at the text of this script.  This case will never be run,
250fc5a983dSmrg  # since it is checked for above.
251fc5a983dSmrg  exit 1
252fc5a983dSmrg  ;;
253fc5a983dSmrg
254fc5a983dSmrgsgi)
255fc5a983dSmrg  if test "$libtool" = yes; then
256fc5a983dSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257fc5a983dSmrg  else
258fc5a983dSmrg    "$@" -MDupdate "$tmpdepfile"
259fc5a983dSmrg  fi
260fc5a983dSmrg  stat=$?
2616257f37dSmrg  if test $stat -ne 0; then
262fc5a983dSmrg    rm -f "$tmpdepfile"
263fc5a983dSmrg    exit $stat
264fc5a983dSmrg  fi
265fc5a983dSmrg  rm -f "$depfile"
266fc5a983dSmrg
267fc5a983dSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268fc5a983dSmrg    echo "$object : \\" > "$depfile"
269fc5a983dSmrg    # Clip off the initial element (the dependent).  Don't try to be
270fc5a983dSmrg    # clever and replace this with sed code, as IRIX sed won't handle
271fc5a983dSmrg    # lines with more than a fixed number of characters (4096 in
272fc5a983dSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2736257f37dSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
274fc5a983dSmrg    # dependency line.
2756257f37dSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2766257f37dSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2776257f37dSmrg      | tr "$nl" ' ' >> "$depfile"
278bd304fc0Smrg    echo >> "$depfile"
279fc5a983dSmrg    # The second pass generates a dummy entry for each header file.
2806257f37dSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2816257f37dSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2826257f37dSmrg      >> "$depfile"
283fc5a983dSmrg  else
2846257f37dSmrg    make_dummy_depfile
285fc5a983dSmrg  fi
286fc5a983dSmrg  rm -f "$tmpdepfile"
287fc5a983dSmrg  ;;
288fc5a983dSmrg
2896257f37dSmrgxlc)
2906257f37dSmrg  # This case exists only to let depend.m4 do its work.  It works by
2916257f37dSmrg  # looking at the text of this script.  This case will never be run,
2926257f37dSmrg  # since it is checked for above.
2936257f37dSmrg  exit 1
2946257f37dSmrg  ;;
2956257f37dSmrg
296fc5a983dSmrgaix)
297fc5a983dSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
298fc5a983dSmrg  # in a .u file.  In older versions, this file always lives in the
2996257f37dSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300fc5a983dSmrg  # start of each line; $object doesn't have directory information.
301fc5a983dSmrg  # Version 6 uses the directory in both cases.
3026257f37dSmrg  set_dir_from "$object"
3036257f37dSmrg  set_base_from "$object"
304fc5a983dSmrg  if test "$libtool" = yes; then
305fc5a983dSmrg    tmpdepfile1=$dir$base.u
306fc5a983dSmrg    tmpdepfile2=$base.u
307fc5a983dSmrg    tmpdepfile3=$dir.libs/$base.u
308fc5a983dSmrg    "$@" -Wc,-M
309fc5a983dSmrg  else
310fc5a983dSmrg    tmpdepfile1=$dir$base.u
311fc5a983dSmrg    tmpdepfile2=$dir$base.u
312fc5a983dSmrg    tmpdepfile3=$dir$base.u
313fc5a983dSmrg    "$@" -M
314fc5a983dSmrg  fi
315fc5a983dSmrg  stat=$?
3166257f37dSmrg  if test $stat -ne 0; then
317fc5a983dSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318fc5a983dSmrg    exit $stat
319fc5a983dSmrg  fi
320fc5a983dSmrg
321fc5a983dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322fc5a983dSmrg  do
323fc5a983dSmrg    test -f "$tmpdepfile" && break
324fc5a983dSmrg  done
3256257f37dSmrg  aix_post_process_depfile
3266257f37dSmrg  ;;
3276257f37dSmrg
3286257f37dSmrgtcc)
3296257f37dSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3306257f37dSmrg  # FIXME: That version still under development at the moment of writing.
3316257f37dSmrg  #        Make that this statement remains true also for stable, released
3326257f37dSmrg  #        versions.
3336257f37dSmrg  # It will wrap lines (doesn't matter whether long or short) with a
3346257f37dSmrg  # trailing '\', as in:
3356257f37dSmrg  #
3366257f37dSmrg  #   foo.o : \
3376257f37dSmrg  #    foo.c \
3386257f37dSmrg  #    foo.h \
3396257f37dSmrg  #
3406257f37dSmrg  # It will put a trailing '\' even on the last line, and will use leading
3416257f37dSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3426257f37dSmrg  # "Emit spaces for -MD").
3436257f37dSmrg  "$@" -MD -MF "$tmpdepfile"
3446257f37dSmrg  stat=$?
3456257f37dSmrg  if test $stat -ne 0; then
3466257f37dSmrg    rm -f "$tmpdepfile"
3476257f37dSmrg    exit $stat
348fc5a983dSmrg  fi
3496257f37dSmrg  rm -f "$depfile"
3506257f37dSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3516257f37dSmrg  # We have to change lines of the first kind to '$object: \'.
3526257f37dSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3536257f37dSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3546257f37dSmrg  # dummy dependency, to avoid the deleted-header problem.
3556257f37dSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356fc5a983dSmrg  rm -f "$tmpdepfile"
357fc5a983dSmrg  ;;
358fc5a983dSmrg
3596257f37dSmrg## The order of this option in the case statement is important, since the
3606257f37dSmrg## shell code in configure will try each of these formats in the order
3616257f37dSmrg## listed in this file.  A plain '-MD' option would be understood by many
3626257f37dSmrg## compilers, so we must ensure this comes after the gcc and icc options.
3636257f37dSmrgpgcc)
3646257f37dSmrg  # Portland's C compiler understands '-MD'.
3656257f37dSmrg  # Will always output deps to 'file.d' where file is the root name of the
3666257f37dSmrg  # source file under compilation, even if file resides in a subdirectory.
3676257f37dSmrg  # The object file name does not affect the name of the '.d' file.
3686257f37dSmrg  # pgcc 10.2 will output
369fc5a983dSmrg  #    foo.o: sub/foo.c sub/foo.h
3706257f37dSmrg  # and will wrap long lines using '\' :
371fc5a983dSmrg  #    foo.o: sub/foo.c ... \
372fc5a983dSmrg  #     sub/foo.h ... \
373fc5a983dSmrg  #     ...
3746257f37dSmrg  set_dir_from "$object"
3756257f37dSmrg  # Use the source, not the object, to determine the base name, since
3766257f37dSmrg  # that's sadly what pgcc will do too.
3776257f37dSmrg  set_base_from "$source"
3786257f37dSmrg  tmpdepfile=$base.d
3796257f37dSmrg
3806257f37dSmrg  # For projects that build the same source file twice into different object
3816257f37dSmrg  # files, the pgcc approach of using the *source* file root name can cause
3826257f37dSmrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3836257f37dSmrg  # the same $tmpdepfile.
3846257f37dSmrg  lockdir=$base.d-lock
3856257f37dSmrg  trap "
3866257f37dSmrg    echo '$0: caught signal, cleaning up...' >&2
3876257f37dSmrg    rmdir '$lockdir'
3886257f37dSmrg    exit 1
3896257f37dSmrg  " 1 2 13 15
3906257f37dSmrg  numtries=100
3916257f37dSmrg  i=$numtries
3926257f37dSmrg  while test $i -gt 0; do
3936257f37dSmrg    # mkdir is a portable test-and-set.
3946257f37dSmrg    if mkdir "$lockdir" 2>/dev/null; then
3956257f37dSmrg      # This process acquired the lock.
3966257f37dSmrg      "$@" -MD
3976257f37dSmrg      stat=$?
3986257f37dSmrg      # Release the lock.
3996257f37dSmrg      rmdir "$lockdir"
4006257f37dSmrg      break
4016257f37dSmrg    else
4026257f37dSmrg      # If the lock is being held by a different process, wait
4036257f37dSmrg      # until the winning process is done or we timeout.
4046257f37dSmrg      while test -d "$lockdir" && test $i -gt 0; do
4056257f37dSmrg        sleep 1
4066257f37dSmrg        i=`expr $i - 1`
4076257f37dSmrg      done
4086257f37dSmrg    fi
4096257f37dSmrg    i=`expr $i - 1`
4106257f37dSmrg  done
4116257f37dSmrg  trap - 1 2 13 15
4126257f37dSmrg  if test $i -le 0; then
4136257f37dSmrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4146257f37dSmrg    echo "$0: check lockdir '$lockdir'" >&2
4156257f37dSmrg    exit 1
4166257f37dSmrg  fi
417fc5a983dSmrg
4186257f37dSmrg  if test $stat -ne 0; then
419fc5a983dSmrg    rm -f "$tmpdepfile"
420fc5a983dSmrg    exit $stat
421fc5a983dSmrg  fi
422fc5a983dSmrg  rm -f "$depfile"
423fc5a983dSmrg  # Each line is of the form `foo.o: dependent.h',
424fc5a983dSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425fc5a983dSmrg  # Do two passes, one to just change these to
426fc5a983dSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427fc5a983dSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428fc5a983dSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429fc5a983dSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
4306257f37dSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4316257f37dSmrg    | sed -e 's/$/ :/' >> "$depfile"
432fc5a983dSmrg  rm -f "$tmpdepfile"
433fc5a983dSmrg  ;;
434fc5a983dSmrg
435fc5a983dSmrghp2)
436fc5a983dSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437fc5a983dSmrg  # compilers, which have integrated preprocessors.  The correct option
438fc5a983dSmrg  # to use with these is +Maked; it writes dependencies to a file named
439fc5a983dSmrg  # 'foo.d', which lands next to the object file, wherever that
440fc5a983dSmrg  # happens to be.
441fc5a983dSmrg  # Much of this is similar to the tru64 case; see comments there.
4426257f37dSmrg  set_dir_from  "$object"
4436257f37dSmrg  set_base_from "$object"
444fc5a983dSmrg  if test "$libtool" = yes; then
445fc5a983dSmrg    tmpdepfile1=$dir$base.d
446fc5a983dSmrg    tmpdepfile2=$dir.libs/$base.d
447fc5a983dSmrg    "$@" -Wc,+Maked
448fc5a983dSmrg  else
449fc5a983dSmrg    tmpdepfile1=$dir$base.d
450fc5a983dSmrg    tmpdepfile2=$dir$base.d
451fc5a983dSmrg    "$@" +Maked
452fc5a983dSmrg  fi
453fc5a983dSmrg  stat=$?
4546257f37dSmrg  if test $stat -ne 0; then
455fc5a983dSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456fc5a983dSmrg     exit $stat
457fc5a983dSmrg  fi
458fc5a983dSmrg
459fc5a983dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460fc5a983dSmrg  do
461fc5a983dSmrg    test -f "$tmpdepfile" && break
462fc5a983dSmrg  done
463fc5a983dSmrg  if test -f "$tmpdepfile"; then
4646257f37dSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4656257f37dSmrg    # Add 'dependent.h:' lines.
466bd304fc0Smrg    sed -ne '2,${
4676257f37dSmrg               s/^ *//
4686257f37dSmrg               s/ \\*$//
4696257f37dSmrg               s/$/:/
4706257f37dSmrg               p
4716257f37dSmrg             }' "$tmpdepfile" >> "$depfile"
472fc5a983dSmrg  else
4736257f37dSmrg    make_dummy_depfile
474fc5a983dSmrg  fi
475fc5a983dSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476fc5a983dSmrg  ;;
477fc5a983dSmrg
478fc5a983dSmrgtru64)
4796257f37dSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4806257f37dSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4816257f37dSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4826257f37dSmrg  # dependencies in 'foo.d' instead, so we check for that too.
4836257f37dSmrg  # Subdirectories are respected.
4846257f37dSmrg  set_dir_from  "$object"
4856257f37dSmrg  set_base_from "$object"
4866257f37dSmrg
4876257f37dSmrg  if test "$libtool" = yes; then
4886257f37dSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4896257f37dSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4906257f37dSmrg    # in $dir$base.o.d.  We have to check for both files, because
4916257f37dSmrg    # one of the two compilations can be disabled.  We should prefer
4926257f37dSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4936257f37dSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
4946257f37dSmrg    # the former would cause a distcleancheck panic.
4956257f37dSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4966257f37dSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4976257f37dSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4986257f37dSmrg    "$@" -Wc,-MD
4996257f37dSmrg  else
5006257f37dSmrg    tmpdepfile1=$dir$base.d
5016257f37dSmrg    tmpdepfile2=$dir$base.d
5026257f37dSmrg    tmpdepfile3=$dir$base.d
5036257f37dSmrg    "$@" -MD
5046257f37dSmrg  fi
5056257f37dSmrg
5066257f37dSmrg  stat=$?
5076257f37dSmrg  if test $stat -ne 0; then
5086257f37dSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5096257f37dSmrg    exit $stat
5106257f37dSmrg  fi
5116257f37dSmrg
5126257f37dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5136257f37dSmrg  do
5146257f37dSmrg    test -f "$tmpdepfile" && break
5156257f37dSmrg  done
5166257f37dSmrg  # Same post-processing that is required for AIX mode.
5176257f37dSmrg  aix_post_process_depfile
5186257f37dSmrg  ;;
519fc5a983dSmrg
520bd304fc0Smrgmsvc7)
521bd304fc0Smrg  if test "$libtool" = yes; then
522bd304fc0Smrg    showIncludes=-Wc,-showIncludes
523bd304fc0Smrg  else
524bd304fc0Smrg    showIncludes=-showIncludes
525bd304fc0Smrg  fi
526bd304fc0Smrg  "$@" $showIncludes > "$tmpdepfile"
527bd304fc0Smrg  stat=$?
528bd304fc0Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5296257f37dSmrg  if test $stat -ne 0; then
530bd304fc0Smrg    rm -f "$tmpdepfile"
531bd304fc0Smrg    exit $stat
532bd304fc0Smrg  fi
533bd304fc0Smrg  rm -f "$depfile"
534bd304fc0Smrg  echo "$object : \\" > "$depfile"
535bd304fc0Smrg  # The first sed program below extracts the file names and escapes
536bd304fc0Smrg  # backslashes for cygpath.  The second sed program outputs the file
537bd304fc0Smrg  # name when reading, but also accumulates all include files in the
538bd304fc0Smrg  # hold buffer in order to output them again at the end.  This only
539bd304fc0Smrg  # works with sed implementations that can handle large buffers.
540bd304fc0Smrg  sed < "$tmpdepfile" -n '
541bd304fc0Smrg/^Note: including file:  *\(.*\)/ {
542bd304fc0Smrg  s//\1/
543bd304fc0Smrg  s/\\/\\\\/g
544bd304fc0Smrg  p
545bd304fc0Smrg}' | $cygpath_u | sort -u | sed -n '
546bd304fc0Smrgs/ /\\ /g
5476257f37dSmrgs/\(.*\)/'"$tab"'\1 \\/p
548bd304fc0Smrgs/.\(.*\) \\/\1:/
549bd304fc0SmrgH
550bd304fc0Smrg$ {
5516257f37dSmrg  s/.*/'"$tab"'/
552bd304fc0Smrg  G
553bd304fc0Smrg  p
554bd304fc0Smrg}' >> "$depfile"
5556257f37dSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556bd304fc0Smrg  rm -f "$tmpdepfile"
557bd304fc0Smrg  ;;
558bd304fc0Smrg
559bd304fc0Smrgmsvc7msys)
560bd304fc0Smrg  # This case exists only to let depend.m4 do its work.  It works by
561bd304fc0Smrg  # looking at the text of this script.  This case will never be run,
562bd304fc0Smrg  # since it is checked for above.
563bd304fc0Smrg  exit 1
564bd304fc0Smrg  ;;
565bd304fc0Smrg
566fc5a983dSmrg#nosideeffect)
567fc5a983dSmrg  # This comment above is used by automake to tell side-effect
568fc5a983dSmrg  # dependency tracking mechanisms from slower ones.
569fc5a983dSmrg
570fc5a983dSmrgdashmstdout)
571fc5a983dSmrg  # Important note: in order to support this mode, a compiler *must*
572fc5a983dSmrg  # always write the preprocessed file to stdout, regardless of -o.
573fc5a983dSmrg  "$@" || exit $?
574fc5a983dSmrg
575fc5a983dSmrg  # Remove the call to Libtool.
576fc5a983dSmrg  if test "$libtool" = yes; then
577bd304fc0Smrg    while test "X$1" != 'X--mode=compile'; do
578fc5a983dSmrg      shift
579fc5a983dSmrg    done
580fc5a983dSmrg    shift
581fc5a983dSmrg  fi
582fc5a983dSmrg
5836257f37dSmrg  # Remove '-o $object'.
584fc5a983dSmrg  IFS=" "
585fc5a983dSmrg  for arg
586fc5a983dSmrg  do
587fc5a983dSmrg    case $arg in
588fc5a983dSmrg    -o)
589fc5a983dSmrg      shift
590fc5a983dSmrg      ;;
591fc5a983dSmrg    $object)
592fc5a983dSmrg      shift
593fc5a983dSmrg      ;;
594fc5a983dSmrg    *)
595fc5a983dSmrg      set fnord "$@" "$arg"
596fc5a983dSmrg      shift # fnord
597fc5a983dSmrg      shift # $arg
598fc5a983dSmrg      ;;
599fc5a983dSmrg    esac
600fc5a983dSmrg  done
601fc5a983dSmrg
602fc5a983dSmrg  test -z "$dashmflag" && dashmflag=-M
6036257f37dSmrg  # Require at least two characters before searching for ':'
604fc5a983dSmrg  # in the target name.  This is to cope with DOS-style filenames:
6056257f37dSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606fc5a983dSmrg  "$@" $dashmflag |
6076257f37dSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608fc5a983dSmrg  rm -f "$depfile"
609fc5a983dSmrg  cat < "$tmpdepfile" > "$depfile"
6106257f37dSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6116257f37dSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6126257f37dSmrg  tr ' ' "$nl" < "$tmpdepfile" \
6136257f37dSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6146257f37dSmrg    | sed -e 's/$/ :/' >> "$depfile"
615fc5a983dSmrg  rm -f "$tmpdepfile"
616fc5a983dSmrg  ;;
617fc5a983dSmrg
618fc5a983dSmrgdashXmstdout)
619fc5a983dSmrg  # This case only exists to satisfy depend.m4.  It is never actually
620fc5a983dSmrg  # run, as this mode is specially recognized in the preamble.
621fc5a983dSmrg  exit 1
622fc5a983dSmrg  ;;
623fc5a983dSmrg
624fc5a983dSmrgmakedepend)
625fc5a983dSmrg  "$@" || exit $?
626fc5a983dSmrg  # Remove any Libtool call
627fc5a983dSmrg  if test "$libtool" = yes; then
628bd304fc0Smrg    while test "X$1" != 'X--mode=compile'; do
629fc5a983dSmrg      shift
630fc5a983dSmrg    done
631fc5a983dSmrg    shift
632fc5a983dSmrg  fi
633fc5a983dSmrg  # X makedepend
634fc5a983dSmrg  shift
635bd304fc0Smrg  cleared=no eat=no
636bd304fc0Smrg  for arg
637bd304fc0Smrg  do
638fc5a983dSmrg    case $cleared in
639fc5a983dSmrg    no)
640fc5a983dSmrg      set ""; shift
641fc5a983dSmrg      cleared=yes ;;
642fc5a983dSmrg    esac
643bd304fc0Smrg    if test $eat = yes; then
644bd304fc0Smrg      eat=no
645bd304fc0Smrg      continue
646bd304fc0Smrg    fi
647fc5a983dSmrg    case "$arg" in
648fc5a983dSmrg    -D*|-I*)
649fc5a983dSmrg      set fnord "$@" "$arg"; shift ;;
650fc5a983dSmrg    # Strip any option that makedepend may not understand.  Remove
651fc5a983dSmrg    # the object too, otherwise makedepend will parse it as a source file.
652bd304fc0Smrg    -arch)
653bd304fc0Smrg      eat=yes ;;
654fc5a983dSmrg    -*|$object)
655fc5a983dSmrg      ;;
656fc5a983dSmrg    *)
657fc5a983dSmrg      set fnord "$@" "$arg"; shift ;;
658fc5a983dSmrg    esac
659fc5a983dSmrg  done
660bd304fc0Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661fc5a983dSmrg  touch "$tmpdepfile"
662fc5a983dSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663fc5a983dSmrg  rm -f "$depfile"
664bd304fc0Smrg  # makedepend may prepend the VPATH from the source file name to the object.
665bd304fc0Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666bd304fc0Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6676257f37dSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6686257f37dSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6696257f37dSmrg  sed '1,2d' "$tmpdepfile" \
6706257f37dSmrg    | tr ' ' "$nl" \
6716257f37dSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6726257f37dSmrg    | sed -e 's/$/ :/' >> "$depfile"
673fc5a983dSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674fc5a983dSmrg  ;;
675fc5a983dSmrg
676fc5a983dSmrgcpp)
677fc5a983dSmrg  # Important note: in order to support this mode, a compiler *must*
678fc5a983dSmrg  # always write the preprocessed file to stdout.
679fc5a983dSmrg  "$@" || exit $?
680fc5a983dSmrg
681fc5a983dSmrg  # Remove the call to Libtool.
682fc5a983dSmrg  if test "$libtool" = yes; then
683bd304fc0Smrg    while test "X$1" != 'X--mode=compile'; do
684fc5a983dSmrg      shift
685fc5a983dSmrg    done
686fc5a983dSmrg    shift
687fc5a983dSmrg  fi
688fc5a983dSmrg
6896257f37dSmrg  # Remove '-o $object'.
690fc5a983dSmrg  IFS=" "
691fc5a983dSmrg  for arg
692fc5a983dSmrg  do
693fc5a983dSmrg    case $arg in
694fc5a983dSmrg    -o)
695fc5a983dSmrg      shift
696fc5a983dSmrg      ;;
697fc5a983dSmrg    $object)
698fc5a983dSmrg      shift
699fc5a983dSmrg      ;;
700fc5a983dSmrg    *)
701fc5a983dSmrg      set fnord "$@" "$arg"
702fc5a983dSmrg      shift # fnord
703fc5a983dSmrg      shift # $arg
704fc5a983dSmrg      ;;
705fc5a983dSmrg    esac
706fc5a983dSmrg  done
707fc5a983dSmrg
7086257f37dSmrg  "$@" -E \
7096257f37dSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7106257f37dSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7116257f37dSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
712fc5a983dSmrg  rm -f "$depfile"
713fc5a983dSmrg  echo "$object : \\" > "$depfile"
714fc5a983dSmrg  cat < "$tmpdepfile" >> "$depfile"
715fc5a983dSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716fc5a983dSmrg  rm -f "$tmpdepfile"
717fc5a983dSmrg  ;;
718fc5a983dSmrg
719fc5a983dSmrgmsvisualcpp)
720fc5a983dSmrg  # Important note: in order to support this mode, a compiler *must*
721bd304fc0Smrg  # always write the preprocessed file to stdout.
722fc5a983dSmrg  "$@" || exit $?
723bd304fc0Smrg
724bd304fc0Smrg  # Remove the call to Libtool.
725bd304fc0Smrg  if test "$libtool" = yes; then
726bd304fc0Smrg    while test "X$1" != 'X--mode=compile'; do
727bd304fc0Smrg      shift
728bd304fc0Smrg    done
729bd304fc0Smrg    shift
730bd304fc0Smrg  fi
731bd304fc0Smrg
732fc5a983dSmrg  IFS=" "
733fc5a983dSmrg  for arg
734fc5a983dSmrg  do
735fc5a983dSmrg    case "$arg" in
736bd304fc0Smrg    -o)
737bd304fc0Smrg      shift
738bd304fc0Smrg      ;;
739bd304fc0Smrg    $object)
740bd304fc0Smrg      shift
741bd304fc0Smrg      ;;
742fc5a983dSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7436257f37dSmrg        set fnord "$@"
7446257f37dSmrg        shift
7456257f37dSmrg        shift
7466257f37dSmrg        ;;
747fc5a983dSmrg    *)
7486257f37dSmrg        set fnord "$@" "$arg"
7496257f37dSmrg        shift
7506257f37dSmrg        shift
7516257f37dSmrg        ;;
752fc5a983dSmrg    esac
753fc5a983dSmrg  done
754bd304fc0Smrg  "$@" -E 2>/dev/null |
755bd304fc0Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756fc5a983dSmrg  rm -f "$depfile"
757fc5a983dSmrg  echo "$object : \\" > "$depfile"
7586257f37dSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7596257f37dSmrg  echo "$tab" >> "$depfile"
760bd304fc0Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761fc5a983dSmrg  rm -f "$tmpdepfile"
762fc5a983dSmrg  ;;
763fc5a983dSmrg
764bd304fc0Smrgmsvcmsys)
765bd304fc0Smrg  # This case exists only to let depend.m4 do its work.  It works by
766bd304fc0Smrg  # looking at the text of this script.  This case will never be run,
767bd304fc0Smrg  # since it is checked for above.
768bd304fc0Smrg  exit 1
769bd304fc0Smrg  ;;
770bd304fc0Smrg
771fc5a983dSmrgnone)
772fc5a983dSmrg  exec "$@"
773fc5a983dSmrg  ;;
774fc5a983dSmrg
775fc5a983dSmrg*)
776fc5a983dSmrg  echo "Unknown depmode $depmode" 1>&2
777fc5a983dSmrg  exit 1
778fc5a983dSmrg  ;;
779fc5a983dSmrgesac
780fc5a983dSmrg
781fc5a983dSmrgexit 0
782fc5a983dSmrg
783fc5a983dSmrg# Local Variables:
784fc5a983dSmrg# mode: shell-script
785fc5a983dSmrg# sh-indentation: 2
786d422ce2eSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
787fc5a983dSmrg# time-stamp-start: "scriptversion="
788fc5a983dSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789d422ce2eSmrg# time-stamp-time-zone: "UTC0"
790bd304fc0Smrg# time-stamp-end: "; # UTC"
791fc5a983dSmrg# End:
792