depcomp revision 5a81ca49
132b578d3Smrg#! /bin/sh
232b578d3Smrg# depcomp - compile a program generating dependencies as side-effects
332b578d3Smrg
45a81ca49Smrgscriptversion=2013-05-30.07; # UTC
532b578d3Smrg
65a81ca49Smrg# Copyright (C) 1999-2014 Free Software Foundation, Inc.
732b578d3Smrg
832b578d3Smrg# This program is free software; you can redistribute it and/or modify
932b578d3Smrg# it under the terms of the GNU General Public License as published by
1032b578d3Smrg# the Free Software Foundation; either version 2, or (at your option)
1132b578d3Smrg# any later version.
1232b578d3Smrg
1332b578d3Smrg# This program is distributed in the hope that it will be useful,
1432b578d3Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1532b578d3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1632b578d3Smrg# GNU General Public License for more details.
1732b578d3Smrg
1832b578d3Smrg# You should have received a copy of the GNU General Public License
192a51b5beSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2032b578d3Smrg
2132b578d3Smrg# As a special exception to the GNU General Public License, if you
2232b578d3Smrg# distribute this file as part of a program that contains a
2332b578d3Smrg# configuration script generated by Autoconf, you may include it under
2432b578d3Smrg# the same distribution terms that you use for the rest of that program.
2532b578d3Smrg
2632b578d3Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2732b578d3Smrg
2832b578d3Smrgcase $1 in
2932b578d3Smrg  '')
305a81ca49Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
315a81ca49Smrg    exit 1;
325a81ca49Smrg    ;;
3332b578d3Smrg  -h | --h*)
3432b578d3Smrg    cat <<\EOF
3532b578d3SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3632b578d3Smrg
3732b578d3SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3832b578d3Smrgas side-effects.
3932b578d3Smrg
4032b578d3SmrgEnvironment variables:
4132b578d3Smrg  depmode     Dependency tracking mode.
425a81ca49Smrg  source      Source file read by 'PROGRAMS ARGS'.
435a81ca49Smrg  object      Object file output by 'PROGRAMS ARGS'.
4432b578d3Smrg  DEPDIR      directory where to store dependencies.
4532b578d3Smrg  depfile     Dependency file to output.
46e35d4d8eSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
4732b578d3Smrg  libtool     Whether libtool is used (yes/no).
4832b578d3Smrg
4932b578d3SmrgReport bugs to <bug-automake@gnu.org>.
5032b578d3SmrgEOF
5132b578d3Smrg    exit $?
5232b578d3Smrg    ;;
5332b578d3Smrg  -v | --v*)
5432b578d3Smrg    echo "depcomp $scriptversion"
5532b578d3Smrg    exit $?
5632b578d3Smrg    ;;
5732b578d3Smrgesac
5832b578d3Smrg
595a81ca49Smrg# Get the directory component of the given path, and save it in the
605a81ca49Smrg# global variables '$dir'.  Note that this directory component will
615a81ca49Smrg# be either empty or ending with a '/' character.  This is deliberate.
625a81ca49Smrgset_dir_from ()
635a81ca49Smrg{
645a81ca49Smrg  case $1 in
655a81ca49Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
665a81ca49Smrg      *) dir=;;
675a81ca49Smrg  esac
685a81ca49Smrg}
695a81ca49Smrg
705a81ca49Smrg# Get the suffix-stripped basename of the given path, and save it the
715a81ca49Smrg# global variable '$base'.
725a81ca49Smrgset_base_from ()
735a81ca49Smrg{
745a81ca49Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
755a81ca49Smrg}
765a81ca49Smrg
775a81ca49Smrg# If no dependency file was actually created by the compiler invocation,
785a81ca49Smrg# we still have to create a dummy depfile, to avoid errors with the
795a81ca49Smrg# Makefile "include basename.Plo" scheme.
805a81ca49Smrgmake_dummy_depfile ()
815a81ca49Smrg{
825a81ca49Smrg  echo "#dummy" > "$depfile"
835a81ca49Smrg}
845a81ca49Smrg
855a81ca49Smrg# Factor out some common post-processing of the generated depfile.
865a81ca49Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
875a81ca49Smrgaix_post_process_depfile ()
885a81ca49Smrg{
895a81ca49Smrg  # If the compiler actually managed to produce a dependency file,
905a81ca49Smrg  # post-process it.
915a81ca49Smrg  if test -f "$tmpdepfile"; then
925a81ca49Smrg    # Each line is of the form 'foo.o: dependency.h'.
935a81ca49Smrg    # Do two passes, one to just change these to
945a81ca49Smrg    #   $object: dependency.h
955a81ca49Smrg    # and one to simply output
965a81ca49Smrg    #   dependency.h:
975a81ca49Smrg    # which is needed to avoid the deleted-header problem.
985a81ca49Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
995a81ca49Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1005a81ca49Smrg    } > "$depfile"
1015a81ca49Smrg    rm -f "$tmpdepfile"
1025a81ca49Smrg  else
1035a81ca49Smrg    make_dummy_depfile
1045a81ca49Smrg  fi
1055a81ca49Smrg}
1065a81ca49Smrg
1075a81ca49Smrg# A tabulation character.
1085a81ca49Smrgtab='	'
1095a81ca49Smrg# A newline character.
1105a81ca49Smrgnl='
1115a81ca49Smrg'
1125a81ca49Smrg# Character ranges might be problematic outside the C locale.
1135a81ca49Smrg# These definitions help.
1145a81ca49Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1155a81ca49Smrglower=abcdefghijklmnopqrstuvwxyz
1165a81ca49Smrgdigits=0123456789
1175a81ca49Smrgalpha=${upper}${lower}
1185a81ca49Smrg
11932b578d3Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12032b578d3Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12132b578d3Smrg  exit 1
12232b578d3Smrgfi
12332b578d3Smrg
12432b578d3Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12532b578d3Smrgdepfile=${depfile-`echo "$object" |
12632b578d3Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12732b578d3Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12832b578d3Smrg
12932b578d3Smrgrm -f "$tmpdepfile"
13032b578d3Smrg
1315a81ca49Smrg# Avoid interferences from the environment.
1325a81ca49Smrggccflag= dashmflag=
1335a81ca49Smrg
13432b578d3Smrg# Some modes work just like other modes, but use different flags.  We
13532b578d3Smrg# parameterize here, but still list the modes in the big case below,
13632b578d3Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13732b578d3Smrg# here, because this file can only contain one case statement.
13832b578d3Smrgif test "$depmode" = hp; then
13932b578d3Smrg  # HP compiler uses -M and no extra arg.
14032b578d3Smrg  gccflag=-M
14132b578d3Smrg  depmode=gcc
14232b578d3Smrgfi
14332b578d3Smrg
14432b578d3Smrgif test "$depmode" = dashXmstdout; then
1455a81ca49Smrg  # This is just like dashmstdout with a different argument.
1465a81ca49Smrg  dashmflag=-xM
1475a81ca49Smrg  depmode=dashmstdout
14832b578d3Smrgfi
14932b578d3Smrg
1502a51b5beSmrgcygpath_u="cygpath -u -f -"
1512a51b5beSmrgif test "$depmode" = msvcmsys; then
1525a81ca49Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1535a81ca49Smrg  # Just convert the backslash-escaped backslashes to single forward
1545a81ca49Smrg  # slashes to satisfy depend.m4
1555a81ca49Smrg  cygpath_u='sed s,\\\\,/,g'
1565a81ca49Smrg  depmode=msvisualcpp
1572a51b5beSmrgfi
1582a51b5beSmrg
159e35d4d8eSmrgif test "$depmode" = msvc7msys; then
1605a81ca49Smrg  # This is just like msvc7 but w/o cygpath translation.
1615a81ca49Smrg  # Just convert the backslash-escaped backslashes to single forward
1625a81ca49Smrg  # slashes to satisfy depend.m4
1635a81ca49Smrg  cygpath_u='sed s,\\\\,/,g'
1645a81ca49Smrg  depmode=msvc7
1655a81ca49Smrgfi
1665a81ca49Smrg
1675a81ca49Smrgif test "$depmode" = xlc; then
1685a81ca49Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1695a81ca49Smrg  gccflag=-qmakedep=gcc,-MF
1705a81ca49Smrg  depmode=gcc
171e35d4d8eSmrgfi
172e35d4d8eSmrg
17332b578d3Smrgcase "$depmode" in
17432b578d3Smrggcc3)
17532b578d3Smrg## gcc 3 implements dependency tracking that does exactly what
17632b578d3Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17732b578d3Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
17832b578d3Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
17932b578d3Smrg## the command line argument order; so add the flags where they
18032b578d3Smrg## appear in depend2.am.  Note that the slowdown incurred here
18132b578d3Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
18232b578d3Smrg  for arg
18332b578d3Smrg  do
18432b578d3Smrg    case $arg in
18532b578d3Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
18632b578d3Smrg    *)  set fnord "$@" "$arg" ;;
18732b578d3Smrg    esac
18832b578d3Smrg    shift # fnord
18932b578d3Smrg    shift # $arg
19032b578d3Smrg  done
19132b578d3Smrg  "$@"
19232b578d3Smrg  stat=$?
1935a81ca49Smrg  if test $stat -ne 0; then
19432b578d3Smrg    rm -f "$tmpdepfile"
19532b578d3Smrg    exit $stat
19632b578d3Smrg  fi
19732b578d3Smrg  mv "$tmpdepfile" "$depfile"
19832b578d3Smrg  ;;
19932b578d3Smrg
20032b578d3Smrggcc)
2015a81ca49Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2025a81ca49Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2035a81ca49Smrg## (see the conditional assignment to $gccflag above).
20432b578d3Smrg## There are various ways to get dependency output from gcc.  Here's
20532b578d3Smrg## why we pick this rather obscure method:
20632b578d3Smrg## - Don't want to use -MD because we'd like the dependencies to end
20732b578d3Smrg##   up in a subdir.  Having to rename by hand is ugly.
20832b578d3Smrg##   (We might end up doing this anyway to support other compilers.)
20932b578d3Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2105a81ca49Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2115a81ca49Smrg##   supported by the other compilers which use the 'gcc' depmode.
21232b578d3Smrg## - Using -M directly means running the compiler twice (even worse
21332b578d3Smrg##   than renaming).
21432b578d3Smrg  if test -z "$gccflag"; then
21532b578d3Smrg    gccflag=-MD,
21632b578d3Smrg  fi
21732b578d3Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
21832b578d3Smrg  stat=$?
2195a81ca49Smrg  if test $stat -ne 0; then
22032b578d3Smrg    rm -f "$tmpdepfile"
22132b578d3Smrg    exit $stat
22232b578d3Smrg  fi
22332b578d3Smrg  rm -f "$depfile"
22432b578d3Smrg  echo "$object : \\" > "$depfile"
2255a81ca49Smrg  # The second -e expression handles DOS-style file names with drive
2265a81ca49Smrg  # letters.
22732b578d3Smrg  sed -e 's/^[^:]*: / /' \
22832b578d3Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2295a81ca49Smrg## This next piece of magic avoids the "deleted header file" problem.
23032b578d3Smrg## The problem is that when a header file which appears in a .P file
23132b578d3Smrg## is deleted, the dependency causes make to die (because there is
23232b578d3Smrg## typically no way to rebuild the header).  We avoid this by adding
23332b578d3Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23432b578d3Smrg## this for us directly.
2355a81ca49Smrg## Some versions of gcc put a space before the ':'.  On the theory
23632b578d3Smrg## that the space means something, we add a space to the output as
237e35d4d8eSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238e35d4d8eSmrg## to the object.  Take care to not repeat it in the output.
23932b578d3Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
24032b578d3Smrg## correctly.  Breaking it into two sed invocations is a workaround.
2415a81ca49Smrg  tr ' ' "$nl" < "$tmpdepfile" \
2425a81ca49Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2435a81ca49Smrg    | sed -e 's/$/ :/' >> "$depfile"
24432b578d3Smrg  rm -f "$tmpdepfile"
24532b578d3Smrg  ;;
24632b578d3Smrg
24732b578d3Smrghp)
24832b578d3Smrg  # This case exists only to let depend.m4 do its work.  It works by
24932b578d3Smrg  # looking at the text of this script.  This case will never be run,
25032b578d3Smrg  # since it is checked for above.
25132b578d3Smrg  exit 1
25232b578d3Smrg  ;;
25332b578d3Smrg
25432b578d3Smrgsgi)
25532b578d3Smrg  if test "$libtool" = yes; then
25632b578d3Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25732b578d3Smrg  else
25832b578d3Smrg    "$@" -MDupdate "$tmpdepfile"
25932b578d3Smrg  fi
26032b578d3Smrg  stat=$?
2615a81ca49Smrg  if test $stat -ne 0; then
26232b578d3Smrg    rm -f "$tmpdepfile"
26332b578d3Smrg    exit $stat
26432b578d3Smrg  fi
26532b578d3Smrg  rm -f "$depfile"
26632b578d3Smrg
26732b578d3Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26832b578d3Smrg    echo "$object : \\" > "$depfile"
26932b578d3Smrg    # Clip off the initial element (the dependent).  Don't try to be
27032b578d3Smrg    # clever and replace this with sed code, as IRIX sed won't handle
27132b578d3Smrg    # lines with more than a fixed number of characters (4096 in
27232b578d3Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2735a81ca49Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
27432b578d3Smrg    # dependency line.
2755a81ca49Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2765a81ca49Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2775a81ca49Smrg      | tr "$nl" ' ' >> "$depfile"
2782a51b5beSmrg    echo >> "$depfile"
27932b578d3Smrg    # The second pass generates a dummy entry for each header file.
2805a81ca49Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2815a81ca49Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2825a81ca49Smrg      >> "$depfile"
28332b578d3Smrg  else
2845a81ca49Smrg    make_dummy_depfile
28532b578d3Smrg  fi
28632b578d3Smrg  rm -f "$tmpdepfile"
28732b578d3Smrg  ;;
28832b578d3Smrg
2895a81ca49Smrgxlc)
2905a81ca49Smrg  # This case exists only to let depend.m4 do its work.  It works by
2915a81ca49Smrg  # looking at the text of this script.  This case will never be run,
2925a81ca49Smrg  # since it is checked for above.
2935a81ca49Smrg  exit 1
2945a81ca49Smrg  ;;
2955a81ca49Smrg
29632b578d3Smrgaix)
29732b578d3Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
29832b578d3Smrg  # in a .u file.  In older versions, this file always lives in the
2995a81ca49Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30032b578d3Smrg  # start of each line; $object doesn't have directory information.
30132b578d3Smrg  # Version 6 uses the directory in both cases.
3025a81ca49Smrg  set_dir_from "$object"
3035a81ca49Smrg  set_base_from "$object"
30432b578d3Smrg  if test "$libtool" = yes; then
3052a51b5beSmrg    tmpdepfile1=$dir$base.u
3062a51b5beSmrg    tmpdepfile2=$base.u
3072a51b5beSmrg    tmpdepfile3=$dir.libs/$base.u
30832b578d3Smrg    "$@" -Wc,-M
30932b578d3Smrg  else
3102a51b5beSmrg    tmpdepfile1=$dir$base.u
3112a51b5beSmrg    tmpdepfile2=$dir$base.u
3122a51b5beSmrg    tmpdepfile3=$dir$base.u
31332b578d3Smrg    "$@" -M
31432b578d3Smrg  fi
31532b578d3Smrg  stat=$?
3165a81ca49Smrg  if test $stat -ne 0; then
3172a51b5beSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31832b578d3Smrg    exit $stat
31932b578d3Smrg  fi
32032b578d3Smrg
3212a51b5beSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3222a51b5beSmrg  do
3232a51b5beSmrg    test -f "$tmpdepfile" && break
3242a51b5beSmrg  done
3255a81ca49Smrg  aix_post_process_depfile
3265a81ca49Smrg  ;;
3275a81ca49Smrg
3285a81ca49Smrgtcc)
3295a81ca49Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3305a81ca49Smrg  # FIXME: That version still under development at the moment of writing.
3315a81ca49Smrg  #        Make that this statement remains true also for stable, released
3325a81ca49Smrg  #        versions.
3335a81ca49Smrg  # It will wrap lines (doesn't matter whether long or short) with a
3345a81ca49Smrg  # trailing '\', as in:
3355a81ca49Smrg  #
3365a81ca49Smrg  #   foo.o : \
3375a81ca49Smrg  #    foo.c \
3385a81ca49Smrg  #    foo.h \
3395a81ca49Smrg  #
3405a81ca49Smrg  # It will put a trailing '\' even on the last line, and will use leading
3415a81ca49Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3425a81ca49Smrg  # "Emit spaces for -MD").
3435a81ca49Smrg  "$@" -MD -MF "$tmpdepfile"
3445a81ca49Smrg  stat=$?
3455a81ca49Smrg  if test $stat -ne 0; then
3465a81ca49Smrg    rm -f "$tmpdepfile"
3475a81ca49Smrg    exit $stat
34832b578d3Smrg  fi
3495a81ca49Smrg  rm -f "$depfile"
3505a81ca49Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3515a81ca49Smrg  # We have to change lines of the first kind to '$object: \'.
3525a81ca49Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3535a81ca49Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3545a81ca49Smrg  # dummy dependency, to avoid the deleted-header problem.
3555a81ca49Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35632b578d3Smrg  rm -f "$tmpdepfile"
35732b578d3Smrg  ;;
35832b578d3Smrg
3595a81ca49Smrg## The order of this option in the case statement is important, since the
3605a81ca49Smrg## shell code in configure will try each of these formats in the order
3615a81ca49Smrg## listed in this file.  A plain '-MD' option would be understood by many
3625a81ca49Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3635a81ca49Smrgpgcc)
3645a81ca49Smrg  # Portland's C compiler understands '-MD'.
3655a81ca49Smrg  # Will always output deps to 'file.d' where file is the root name of the
3665a81ca49Smrg  # source file under compilation, even if file resides in a subdirectory.
3675a81ca49Smrg  # The object file name does not affect the name of the '.d' file.
3685a81ca49Smrg  # pgcc 10.2 will output
36932b578d3Smrg  #    foo.o: sub/foo.c sub/foo.h
3705a81ca49Smrg  # and will wrap long lines using '\' :
37132b578d3Smrg  #    foo.o: sub/foo.c ... \
37232b578d3Smrg  #     sub/foo.h ... \
37332b578d3Smrg  #     ...
3745a81ca49Smrg  set_dir_from "$object"
3755a81ca49Smrg  # Use the source, not the object, to determine the base name, since
3765a81ca49Smrg  # that's sadly what pgcc will do too.
3775a81ca49Smrg  set_base_from "$source"
3785a81ca49Smrg  tmpdepfile=$base.d
3795a81ca49Smrg
3805a81ca49Smrg  # For projects that build the same source file twice into different object
3815a81ca49Smrg  # files, the pgcc approach of using the *source* file root name can cause
3825a81ca49Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3835a81ca49Smrg  # the same $tmpdepfile.
3845a81ca49Smrg  lockdir=$base.d-lock
3855a81ca49Smrg  trap "
3865a81ca49Smrg    echo '$0: caught signal, cleaning up...' >&2
3875a81ca49Smrg    rmdir '$lockdir'
3885a81ca49Smrg    exit 1
3895a81ca49Smrg  " 1 2 13 15
3905a81ca49Smrg  numtries=100
3915a81ca49Smrg  i=$numtries
3925a81ca49Smrg  while test $i -gt 0; do
3935a81ca49Smrg    # mkdir is a portable test-and-set.
3945a81ca49Smrg    if mkdir "$lockdir" 2>/dev/null; then
3955a81ca49Smrg      # This process acquired the lock.
3965a81ca49Smrg      "$@" -MD
3975a81ca49Smrg      stat=$?
3985a81ca49Smrg      # Release the lock.
3995a81ca49Smrg      rmdir "$lockdir"
4005a81ca49Smrg      break
4015a81ca49Smrg    else
4025a81ca49Smrg      # If the lock is being held by a different process, wait
4035a81ca49Smrg      # until the winning process is done or we timeout.
4045a81ca49Smrg      while test -d "$lockdir" && test $i -gt 0; do
4055a81ca49Smrg        sleep 1
4065a81ca49Smrg        i=`expr $i - 1`
4075a81ca49Smrg      done
4085a81ca49Smrg    fi
4095a81ca49Smrg    i=`expr $i - 1`
4105a81ca49Smrg  done
4115a81ca49Smrg  trap - 1 2 13 15
4125a81ca49Smrg  if test $i -le 0; then
4135a81ca49Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4145a81ca49Smrg    echo "$0: check lockdir '$lockdir'" >&2
4155a81ca49Smrg    exit 1
4165a81ca49Smrg  fi
41732b578d3Smrg
4185a81ca49Smrg  if test $stat -ne 0; then
41932b578d3Smrg    rm -f "$tmpdepfile"
42032b578d3Smrg    exit $stat
42132b578d3Smrg  fi
42232b578d3Smrg  rm -f "$depfile"
42332b578d3Smrg  # Each line is of the form `foo.o: dependent.h',
42432b578d3Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42532b578d3Smrg  # Do two passes, one to just change these to
42632b578d3Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42732b578d3Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42832b578d3Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
42932b578d3Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
4305a81ca49Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4315a81ca49Smrg    | sed -e 's/$/ :/' >> "$depfile"
43232b578d3Smrg  rm -f "$tmpdepfile"
43332b578d3Smrg  ;;
43432b578d3Smrg
43532b578d3Smrghp2)
43632b578d3Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
43732b578d3Smrg  # compilers, which have integrated preprocessors.  The correct option
43832b578d3Smrg  # to use with these is +Maked; it writes dependencies to a file named
43932b578d3Smrg  # 'foo.d', which lands next to the object file, wherever that
44032b578d3Smrg  # happens to be.
44132b578d3Smrg  # Much of this is similar to the tru64 case; see comments there.
4425a81ca49Smrg  set_dir_from  "$object"
4435a81ca49Smrg  set_base_from "$object"
44432b578d3Smrg  if test "$libtool" = yes; then
44532b578d3Smrg    tmpdepfile1=$dir$base.d
44632b578d3Smrg    tmpdepfile2=$dir.libs/$base.d
44732b578d3Smrg    "$@" -Wc,+Maked
44832b578d3Smrg  else
44932b578d3Smrg    tmpdepfile1=$dir$base.d
45032b578d3Smrg    tmpdepfile2=$dir$base.d
45132b578d3Smrg    "$@" +Maked
45232b578d3Smrg  fi
45332b578d3Smrg  stat=$?
4545a81ca49Smrg  if test $stat -ne 0; then
45532b578d3Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
45632b578d3Smrg     exit $stat
45732b578d3Smrg  fi
45832b578d3Smrg
45932b578d3Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
46032b578d3Smrg  do
46132b578d3Smrg    test -f "$tmpdepfile" && break
46232b578d3Smrg  done
46332b578d3Smrg  if test -f "$tmpdepfile"; then
4645a81ca49Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4655a81ca49Smrg    # Add 'dependent.h:' lines.
4662a51b5beSmrg    sed -ne '2,${
4675a81ca49Smrg               s/^ *//
4685a81ca49Smrg               s/ \\*$//
4695a81ca49Smrg               s/$/:/
4705a81ca49Smrg               p
4715a81ca49Smrg             }' "$tmpdepfile" >> "$depfile"
47232b578d3Smrg  else
4735a81ca49Smrg    make_dummy_depfile
47432b578d3Smrg  fi
47532b578d3Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
47632b578d3Smrg  ;;
47732b578d3Smrg
47832b578d3Smrgtru64)
4795a81ca49Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4805a81ca49Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4815a81ca49Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4825a81ca49Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4835a81ca49Smrg  # Subdirectories are respected.
4845a81ca49Smrg  set_dir_from  "$object"
4855a81ca49Smrg  set_base_from "$object"
4865a81ca49Smrg
4875a81ca49Smrg  if test "$libtool" = yes; then
4885a81ca49Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4895a81ca49Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4905a81ca49Smrg    # in $dir$base.o.d.  We have to check for both files, because
4915a81ca49Smrg    # one of the two compilations can be disabled.  We should prefer
4925a81ca49Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4935a81ca49Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4945a81ca49Smrg    # the former would cause a distcleancheck panic.
4955a81ca49Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4965a81ca49Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4975a81ca49Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4985a81ca49Smrg    "$@" -Wc,-MD
4995a81ca49Smrg  else
5005a81ca49Smrg    tmpdepfile1=$dir$base.d
5015a81ca49Smrg    tmpdepfile2=$dir$base.d
5025a81ca49Smrg    tmpdepfile3=$dir$base.d
5035a81ca49Smrg    "$@" -MD
5045a81ca49Smrg  fi
5055a81ca49Smrg
5065a81ca49Smrg  stat=$?
5075a81ca49Smrg  if test $stat -ne 0; then
5085a81ca49Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5095a81ca49Smrg    exit $stat
5105a81ca49Smrg  fi
5115a81ca49Smrg
5125a81ca49Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5135a81ca49Smrg  do
5145a81ca49Smrg    test -f "$tmpdepfile" && break
5155a81ca49Smrg  done
5165a81ca49Smrg  # Same post-processing that is required for AIX mode.
5175a81ca49Smrg  aix_post_process_depfile
5185a81ca49Smrg  ;;
51932b578d3Smrg
520e35d4d8eSmrgmsvc7)
521e35d4d8eSmrg  if test "$libtool" = yes; then
522e35d4d8eSmrg    showIncludes=-Wc,-showIncludes
523e35d4d8eSmrg  else
524e35d4d8eSmrg    showIncludes=-showIncludes
525e35d4d8eSmrg  fi
526e35d4d8eSmrg  "$@" $showIncludes > "$tmpdepfile"
527e35d4d8eSmrg  stat=$?
528e35d4d8eSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
5295a81ca49Smrg  if test $stat -ne 0; then
530e35d4d8eSmrg    rm -f "$tmpdepfile"
531e35d4d8eSmrg    exit $stat
532e35d4d8eSmrg  fi
533e35d4d8eSmrg  rm -f "$depfile"
534e35d4d8eSmrg  echo "$object : \\" > "$depfile"
535e35d4d8eSmrg  # The first sed program below extracts the file names and escapes
536e35d4d8eSmrg  # backslashes for cygpath.  The second sed program outputs the file
537e35d4d8eSmrg  # name when reading, but also accumulates all include files in the
538e35d4d8eSmrg  # hold buffer in order to output them again at the end.  This only
539e35d4d8eSmrg  # works with sed implementations that can handle large buffers.
540e35d4d8eSmrg  sed < "$tmpdepfile" -n '
541e35d4d8eSmrg/^Note: including file:  *\(.*\)/ {
542e35d4d8eSmrg  s//\1/
543e35d4d8eSmrg  s/\\/\\\\/g
544e35d4d8eSmrg  p
545e35d4d8eSmrg}' | $cygpath_u | sort -u | sed -n '
546e35d4d8eSmrgs/ /\\ /g
5475a81ca49Smrgs/\(.*\)/'"$tab"'\1 \\/p
548e35d4d8eSmrgs/.\(.*\) \\/\1:/
549e35d4d8eSmrgH
550e35d4d8eSmrg$ {
5515a81ca49Smrg  s/.*/'"$tab"'/
552e35d4d8eSmrg  G
553e35d4d8eSmrg  p
554e35d4d8eSmrg}' >> "$depfile"
5555a81ca49Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556e35d4d8eSmrg  rm -f "$tmpdepfile"
557e35d4d8eSmrg  ;;
558e35d4d8eSmrg
559e35d4d8eSmrgmsvc7msys)
560e35d4d8eSmrg  # This case exists only to let depend.m4 do its work.  It works by
561e35d4d8eSmrg  # looking at the text of this script.  This case will never be run,
562e35d4d8eSmrg  # since it is checked for above.
563e35d4d8eSmrg  exit 1
564e35d4d8eSmrg  ;;
565e35d4d8eSmrg
56632b578d3Smrg#nosideeffect)
56732b578d3Smrg  # This comment above is used by automake to tell side-effect
56832b578d3Smrg  # dependency tracking mechanisms from slower ones.
56932b578d3Smrg
57032b578d3Smrgdashmstdout)
57132b578d3Smrg  # Important note: in order to support this mode, a compiler *must*
57232b578d3Smrg  # always write the preprocessed file to stdout, regardless of -o.
57332b578d3Smrg  "$@" || exit $?
57432b578d3Smrg
57532b578d3Smrg  # Remove the call to Libtool.
57632b578d3Smrg  if test "$libtool" = yes; then
5772a51b5beSmrg    while test "X$1" != 'X--mode=compile'; do
57832b578d3Smrg      shift
57932b578d3Smrg    done
58032b578d3Smrg    shift
58132b578d3Smrg  fi
58232b578d3Smrg
5835a81ca49Smrg  # Remove '-o $object'.
58432b578d3Smrg  IFS=" "
58532b578d3Smrg  for arg
58632b578d3Smrg  do
58732b578d3Smrg    case $arg in
58832b578d3Smrg    -o)
58932b578d3Smrg      shift
59032b578d3Smrg      ;;
59132b578d3Smrg    $object)
59232b578d3Smrg      shift
59332b578d3Smrg      ;;
59432b578d3Smrg    *)
59532b578d3Smrg      set fnord "$@" "$arg"
59632b578d3Smrg      shift # fnord
59732b578d3Smrg      shift # $arg
59832b578d3Smrg      ;;
59932b578d3Smrg    esac
60032b578d3Smrg  done
60132b578d3Smrg
60232b578d3Smrg  test -z "$dashmflag" && dashmflag=-M
6035a81ca49Smrg  # Require at least two characters before searching for ':'
60432b578d3Smrg  # in the target name.  This is to cope with DOS-style filenames:
6055a81ca49Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60632b578d3Smrg  "$@" $dashmflag |
6075a81ca49Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60832b578d3Smrg  rm -f "$depfile"
60932b578d3Smrg  cat < "$tmpdepfile" > "$depfile"
6105a81ca49Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6115a81ca49Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6125a81ca49Smrg  tr ' ' "$nl" < "$tmpdepfile" \
6135a81ca49Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6145a81ca49Smrg    | sed -e 's/$/ :/' >> "$depfile"
61532b578d3Smrg  rm -f "$tmpdepfile"
61632b578d3Smrg  ;;
61732b578d3Smrg
61832b578d3SmrgdashXmstdout)
61932b578d3Smrg  # This case only exists to satisfy depend.m4.  It is never actually
62032b578d3Smrg  # run, as this mode is specially recognized in the preamble.
62132b578d3Smrg  exit 1
62232b578d3Smrg  ;;
62332b578d3Smrg
62432b578d3Smrgmakedepend)
62532b578d3Smrg  "$@" || exit $?
62632b578d3Smrg  # Remove any Libtool call
62732b578d3Smrg  if test "$libtool" = yes; then
6282a51b5beSmrg    while test "X$1" != 'X--mode=compile'; do
62932b578d3Smrg      shift
63032b578d3Smrg    done
63132b578d3Smrg    shift
63232b578d3Smrg  fi
63332b578d3Smrg  # X makedepend
63432b578d3Smrg  shift
6352a51b5beSmrg  cleared=no eat=no
6362a51b5beSmrg  for arg
6372a51b5beSmrg  do
63832b578d3Smrg    case $cleared in
63932b578d3Smrg    no)
64032b578d3Smrg      set ""; shift
64132b578d3Smrg      cleared=yes ;;
64232b578d3Smrg    esac
6432a51b5beSmrg    if test $eat = yes; then
6442a51b5beSmrg      eat=no
6452a51b5beSmrg      continue
6462a51b5beSmrg    fi
64732b578d3Smrg    case "$arg" in
64832b578d3Smrg    -D*|-I*)
64932b578d3Smrg      set fnord "$@" "$arg"; shift ;;
65032b578d3Smrg    # Strip any option that makedepend may not understand.  Remove
65132b578d3Smrg    # the object too, otherwise makedepend will parse it as a source file.
6522a51b5beSmrg    -arch)
6532a51b5beSmrg      eat=yes ;;
65432b578d3Smrg    -*|$object)
65532b578d3Smrg      ;;
65632b578d3Smrg    *)
65732b578d3Smrg      set fnord "$@" "$arg"; shift ;;
65832b578d3Smrg    esac
65932b578d3Smrg  done
6602a51b5beSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66132b578d3Smrg  touch "$tmpdepfile"
66232b578d3Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66332b578d3Smrg  rm -f "$depfile"
664e35d4d8eSmrg  # makedepend may prepend the VPATH from the source file name to the object.
665e35d4d8eSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666e35d4d8eSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6675a81ca49Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6685a81ca49Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6695a81ca49Smrg  sed '1,2d' "$tmpdepfile" \
6705a81ca49Smrg    | tr ' ' "$nl" \
6715a81ca49Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6725a81ca49Smrg    | sed -e 's/$/ :/' >> "$depfile"
67332b578d3Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67432b578d3Smrg  ;;
67532b578d3Smrg
67632b578d3Smrgcpp)
67732b578d3Smrg  # Important note: in order to support this mode, a compiler *must*
67832b578d3Smrg  # always write the preprocessed file to stdout.
67932b578d3Smrg  "$@" || exit $?
68032b578d3Smrg
68132b578d3Smrg  # Remove the call to Libtool.
68232b578d3Smrg  if test "$libtool" = yes; then
6832a51b5beSmrg    while test "X$1" != 'X--mode=compile'; do
68432b578d3Smrg      shift
68532b578d3Smrg    done
68632b578d3Smrg    shift
68732b578d3Smrg  fi
68832b578d3Smrg
6895a81ca49Smrg  # Remove '-o $object'.
69032b578d3Smrg  IFS=" "
69132b578d3Smrg  for arg
69232b578d3Smrg  do
69332b578d3Smrg    case $arg in
69432b578d3Smrg    -o)
69532b578d3Smrg      shift
69632b578d3Smrg      ;;
69732b578d3Smrg    $object)
69832b578d3Smrg      shift
69932b578d3Smrg      ;;
70032b578d3Smrg    *)
70132b578d3Smrg      set fnord "$@" "$arg"
70232b578d3Smrg      shift # fnord
70332b578d3Smrg      shift # $arg
70432b578d3Smrg      ;;
70532b578d3Smrg    esac
70632b578d3Smrg  done
70732b578d3Smrg
7085a81ca49Smrg  "$@" -E \
7095a81ca49Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7105a81ca49Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7115a81ca49Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
71232b578d3Smrg  rm -f "$depfile"
71332b578d3Smrg  echo "$object : \\" > "$depfile"
71432b578d3Smrg  cat < "$tmpdepfile" >> "$depfile"
71532b578d3Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71632b578d3Smrg  rm -f "$tmpdepfile"
71732b578d3Smrg  ;;
71832b578d3Smrg
71932b578d3Smrgmsvisualcpp)
72032b578d3Smrg  # Important note: in order to support this mode, a compiler *must*
7212a51b5beSmrg  # always write the preprocessed file to stdout.
72232b578d3Smrg  "$@" || exit $?
7232a51b5beSmrg
7242a51b5beSmrg  # Remove the call to Libtool.
7252a51b5beSmrg  if test "$libtool" = yes; then
7262a51b5beSmrg    while test "X$1" != 'X--mode=compile'; do
7272a51b5beSmrg      shift
7282a51b5beSmrg    done
7292a51b5beSmrg    shift
7302a51b5beSmrg  fi
7312a51b5beSmrg
73232b578d3Smrg  IFS=" "
73332b578d3Smrg  for arg
73432b578d3Smrg  do
73532b578d3Smrg    case "$arg" in
7362a51b5beSmrg    -o)
7372a51b5beSmrg      shift
7382a51b5beSmrg      ;;
7392a51b5beSmrg    $object)
7402a51b5beSmrg      shift
7412a51b5beSmrg      ;;
74232b578d3Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7435a81ca49Smrg        set fnord "$@"
7445a81ca49Smrg        shift
7455a81ca49Smrg        shift
7465a81ca49Smrg        ;;
74732b578d3Smrg    *)
7485a81ca49Smrg        set fnord "$@" "$arg"
7495a81ca49Smrg        shift
7505a81ca49Smrg        shift
7515a81ca49Smrg        ;;
75232b578d3Smrg    esac
75332b578d3Smrg  done
7542a51b5beSmrg  "$@" -E 2>/dev/null |
7552a51b5beSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75632b578d3Smrg  rm -f "$depfile"
75732b578d3Smrg  echo "$object : \\" > "$depfile"
7585a81ca49Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7595a81ca49Smrg  echo "$tab" >> "$depfile"
7602a51b5beSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76132b578d3Smrg  rm -f "$tmpdepfile"
76232b578d3Smrg  ;;
76332b578d3Smrg
7642a51b5beSmrgmsvcmsys)
7652a51b5beSmrg  # This case exists only to let depend.m4 do its work.  It works by
7662a51b5beSmrg  # looking at the text of this script.  This case will never be run,
7672a51b5beSmrg  # since it is checked for above.
7682a51b5beSmrg  exit 1
7692a51b5beSmrg  ;;
7702a51b5beSmrg
77132b578d3Smrgnone)
77232b578d3Smrg  exec "$@"
77332b578d3Smrg  ;;
77432b578d3Smrg
77532b578d3Smrg*)
77632b578d3Smrg  echo "Unknown depmode $depmode" 1>&2
77732b578d3Smrg  exit 1
77832b578d3Smrg  ;;
77932b578d3Smrgesac
78032b578d3Smrg
78132b578d3Smrgexit 0
78232b578d3Smrg
78332b578d3Smrg# Local Variables:
78432b578d3Smrg# mode: shell-script
78532b578d3Smrg# sh-indentation: 2
78632b578d3Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
78732b578d3Smrg# time-stamp-start: "scriptversion="
78832b578d3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7892a51b5beSmrg# time-stamp-time-zone: "UTC"
7902a51b5beSmrg# time-stamp-end: "; # UTC"
79132b578d3Smrg# End:
792