depcomp revision 0a392d7e
14a041c5bSmacallan#! /bin/sh
24a041c5bSmacallan# depcomp - compile a program generating dependencies as side-effects
34a041c5bSmacallan
40a392d7eSmrgscriptversion=2013-05-30.07; # UTC
54a041c5bSmacallan
60a392d7eSmrg# Copyright (C) 1999-2014 Free Software Foundation, Inc.
74a041c5bSmacallan
84a041c5bSmacallan# This program is free software; you can redistribute it and/or modify
94a041c5bSmacallan# it under the terms of the GNU General Public License as published by
104a041c5bSmacallan# the Free Software Foundation; either version 2, or (at your option)
114a041c5bSmacallan# any later version.
124a041c5bSmacallan
134a041c5bSmacallan# This program is distributed in the hope that it will be useful,
144a041c5bSmacallan# but WITHOUT ANY WARRANTY; without even the implied warranty of
154a041c5bSmacallan# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
164a041c5bSmacallan# GNU General Public License for more details.
174a041c5bSmacallan
184a041c5bSmacallan# You should have received a copy of the GNU General Public License
1954b44505Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
204a041c5bSmacallan
214a041c5bSmacallan# As a special exception to the GNU General Public License, if you
224a041c5bSmacallan# distribute this file as part of a program that contains a
234a041c5bSmacallan# configuration script generated by Autoconf, you may include it under
244a041c5bSmacallan# the same distribution terms that you use for the rest of that program.
254a041c5bSmacallan
264a041c5bSmacallan# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
274a041c5bSmacallan
284a041c5bSmacallancase $1 in
294a041c5bSmacallan  '')
300a392d7eSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
310a392d7eSmrg    exit 1;
320a392d7eSmrg    ;;
334a041c5bSmacallan  -h | --h*)
344a041c5bSmacallan    cat <<\EOF
354a041c5bSmacallanUsage: depcomp [--help] [--version] PROGRAM [ARGS]
364a041c5bSmacallan
374a041c5bSmacallanRun PROGRAMS ARGS to compile a file, generating dependencies
384a041c5bSmacallanas side-effects.
394a041c5bSmacallan
404a041c5bSmacallanEnvironment variables:
414a041c5bSmacallan  depmode     Dependency tracking mode.
4254b44505Smrg  source      Source file read by 'PROGRAMS ARGS'.
4354b44505Smrg  object      Object file output by 'PROGRAMS ARGS'.
444a041c5bSmacallan  DEPDIR      directory where to store dependencies.
454a041c5bSmacallan  depfile     Dependency file to output.
4654b44505Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
474a041c5bSmacallan  libtool     Whether libtool is used (yes/no).
484a041c5bSmacallan
494a041c5bSmacallanReport bugs to <bug-automake@gnu.org>.
504a041c5bSmacallanEOF
514a041c5bSmacallan    exit $?
524a041c5bSmacallan    ;;
534a041c5bSmacallan  -v | --v*)
544a041c5bSmacallan    echo "depcomp $scriptversion"
554a041c5bSmacallan    exit $?
564a041c5bSmacallan    ;;
574a041c5bSmacallanesac
584a041c5bSmacallan
590a392d7eSmrg# Get the directory component of the given path, and save it in the
600a392d7eSmrg# global variables '$dir'.  Note that this directory component will
610a392d7eSmrg# be either empty or ending with a '/' character.  This is deliberate.
620a392d7eSmrgset_dir_from ()
630a392d7eSmrg{
640a392d7eSmrg  case $1 in
650a392d7eSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
660a392d7eSmrg      *) dir=;;
670a392d7eSmrg  esac
680a392d7eSmrg}
690a392d7eSmrg
700a392d7eSmrg# Get the suffix-stripped basename of the given path, and save it the
710a392d7eSmrg# global variable '$base'.
720a392d7eSmrgset_base_from ()
730a392d7eSmrg{
740a392d7eSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
750a392d7eSmrg}
760a392d7eSmrg
770a392d7eSmrg# If no dependency file was actually created by the compiler invocation,
780a392d7eSmrg# we still have to create a dummy depfile, to avoid errors with the
790a392d7eSmrg# Makefile "include basename.Plo" scheme.
800a392d7eSmrgmake_dummy_depfile ()
810a392d7eSmrg{
820a392d7eSmrg  echo "#dummy" > "$depfile"
830a392d7eSmrg}
840a392d7eSmrg
850a392d7eSmrg# Factor out some common post-processing of the generated depfile.
860a392d7eSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
870a392d7eSmrgaix_post_process_depfile ()
880a392d7eSmrg{
890a392d7eSmrg  # If the compiler actually managed to produce a dependency file,
900a392d7eSmrg  # post-process it.
910a392d7eSmrg  if test -f "$tmpdepfile"; then
920a392d7eSmrg    # Each line is of the form 'foo.o: dependency.h'.
930a392d7eSmrg    # Do two passes, one to just change these to
940a392d7eSmrg    #   $object: dependency.h
950a392d7eSmrg    # and one to simply output
960a392d7eSmrg    #   dependency.h:
970a392d7eSmrg    # which is needed to avoid the deleted-header problem.
980a392d7eSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
990a392d7eSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1000a392d7eSmrg    } > "$depfile"
1010a392d7eSmrg    rm -f "$tmpdepfile"
1020a392d7eSmrg  else
1030a392d7eSmrg    make_dummy_depfile
1040a392d7eSmrg  fi
1050a392d7eSmrg}
1060a392d7eSmrg
10754b44505Smrg# A tabulation character.
10854b44505Smrgtab='	'
10954b44505Smrg# A newline character.
11054b44505Smrgnl='
11154b44505Smrg'
1120a392d7eSmrg# Character ranges might be problematic outside the C locale.
1130a392d7eSmrg# These definitions help.
1140a392d7eSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1150a392d7eSmrglower=abcdefghijklmnopqrstuvwxyz
1160a392d7eSmrgdigits=0123456789
1170a392d7eSmrgalpha=${upper}${lower}
11854b44505Smrg
1194a041c5bSmacallanif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1204a041c5bSmacallan  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1214a041c5bSmacallan  exit 1
1224a041c5bSmacallanfi
1234a041c5bSmacallan
1244a041c5bSmacallan# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1254a041c5bSmacallandepfile=${depfile-`echo "$object" |
1264a041c5bSmacallan  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1274a041c5bSmacallantmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1284a041c5bSmacallan
1294a041c5bSmacallanrm -f "$tmpdepfile"
1304a041c5bSmacallan
13154b44505Smrg# Avoid interferences from the environment.
13254b44505Smrggccflag= dashmflag=
13354b44505Smrg
1344a041c5bSmacallan# Some modes work just like other modes, but use different flags.  We
1354a041c5bSmacallan# parameterize here, but still list the modes in the big case below,
1364a041c5bSmacallan# to make depend.m4 easier to write.  Note that we *cannot* use a case
1374a041c5bSmacallan# here, because this file can only contain one case statement.
1384a041c5bSmacallanif test "$depmode" = hp; then
1394a041c5bSmacallan  # HP compiler uses -M and no extra arg.
1404a041c5bSmacallan  gccflag=-M
1414a041c5bSmacallan  depmode=gcc
1424a041c5bSmacallanfi
1434a041c5bSmacallan
1444a041c5bSmacallanif test "$depmode" = dashXmstdout; then
1450a392d7eSmrg  # This is just like dashmstdout with a different argument.
1460a392d7eSmrg  dashmflag=-xM
1470a392d7eSmrg  depmode=dashmstdout
1484a041c5bSmacallanfi
1494a041c5bSmacallan
15054b44505Smrgcygpath_u="cygpath -u -f -"
15154b44505Smrgif test "$depmode" = msvcmsys; then
1520a392d7eSmrg  # This is just like msvisualcpp but w/o cygpath translation.
1530a392d7eSmrg  # Just convert the backslash-escaped backslashes to single forward
1540a392d7eSmrg  # slashes to satisfy depend.m4
1550a392d7eSmrg  cygpath_u='sed s,\\\\,/,g'
1560a392d7eSmrg  depmode=msvisualcpp
15754b44505Smrgfi
15854b44505Smrg
15954b44505Smrgif test "$depmode" = msvc7msys; then
1600a392d7eSmrg  # This is just like msvc7 but w/o cygpath translation.
1610a392d7eSmrg  # Just convert the backslash-escaped backslashes to single forward
1620a392d7eSmrg  # slashes to satisfy depend.m4
1630a392d7eSmrg  cygpath_u='sed s,\\\\,/,g'
1640a392d7eSmrg  depmode=msvc7
16554b44505Smrgfi
16654b44505Smrg
16754b44505Smrgif test "$depmode" = xlc; then
1680a392d7eSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1690a392d7eSmrg  gccflag=-qmakedep=gcc,-MF
1700a392d7eSmrg  depmode=gcc
17154b44505Smrgfi
17254b44505Smrg
1734a041c5bSmacallancase "$depmode" in
1744a041c5bSmacallangcc3)
1754a041c5bSmacallan## gcc 3 implements dependency tracking that does exactly what
1764a041c5bSmacallan## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1774a041c5bSmacallan## it if -MD -MP comes after the -MF stuff.  Hmm.
1784a041c5bSmacallan## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1794a041c5bSmacallan## the command line argument order; so add the flags where they
1804a041c5bSmacallan## appear in depend2.am.  Note that the slowdown incurred here
1814a041c5bSmacallan## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1824a041c5bSmacallan  for arg
1834a041c5bSmacallan  do
1844a041c5bSmacallan    case $arg in
1854a041c5bSmacallan    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1864a041c5bSmacallan    *)  set fnord "$@" "$arg" ;;
1874a041c5bSmacallan    esac
1884a041c5bSmacallan    shift # fnord
1894a041c5bSmacallan    shift # $arg
1904a041c5bSmacallan  done
1914a041c5bSmacallan  "$@"
1924a041c5bSmacallan  stat=$?
1930a392d7eSmrg  if test $stat -ne 0; then
1944a041c5bSmacallan    rm -f "$tmpdepfile"
1954a041c5bSmacallan    exit $stat
1964a041c5bSmacallan  fi
1974a041c5bSmacallan  mv "$tmpdepfile" "$depfile"
1984a041c5bSmacallan  ;;
1994a041c5bSmacallan
2004a041c5bSmacallangcc)
20154b44505Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
20254b44505Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
20354b44505Smrg## (see the conditional assignment to $gccflag above).
2044a041c5bSmacallan## There are various ways to get dependency output from gcc.  Here's
2054a041c5bSmacallan## why we pick this rather obscure method:
2064a041c5bSmacallan## - Don't want to use -MD because we'd like the dependencies to end
2074a041c5bSmacallan##   up in a subdir.  Having to rename by hand is ugly.
2084a041c5bSmacallan##   (We might end up doing this anyway to support other compilers.)
2094a041c5bSmacallan## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
21054b44505Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
21154b44505Smrg##   supported by the other compilers which use the 'gcc' depmode.
2124a041c5bSmacallan## - Using -M directly means running the compiler twice (even worse
2134a041c5bSmacallan##   than renaming).
2144a041c5bSmacallan  if test -z "$gccflag"; then
2154a041c5bSmacallan    gccflag=-MD,
2164a041c5bSmacallan  fi
2174a041c5bSmacallan  "$@" -Wp,"$gccflag$tmpdepfile"
2184a041c5bSmacallan  stat=$?
2190a392d7eSmrg  if test $stat -ne 0; then
2204a041c5bSmacallan    rm -f "$tmpdepfile"
2214a041c5bSmacallan    exit $stat
2224a041c5bSmacallan  fi
2234a041c5bSmacallan  rm -f "$depfile"
2244a041c5bSmacallan  echo "$object : \\" > "$depfile"
2250a392d7eSmrg  # The second -e expression handles DOS-style file names with drive
2260a392d7eSmrg  # letters.
2274a041c5bSmacallan  sed -e 's/^[^:]*: / /' \
2284a041c5bSmacallan      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
22954b44505Smrg## This next piece of magic avoids the "deleted header file" problem.
2304a041c5bSmacallan## The problem is that when a header file which appears in a .P file
2314a041c5bSmacallan## is deleted, the dependency causes make to die (because there is
2324a041c5bSmacallan## typically no way to rebuild the header).  We avoid this by adding
2334a041c5bSmacallan## dummy dependencies for each header file.  Too bad gcc doesn't do
2344a041c5bSmacallan## this for us directly.
23554b44505Smrg## Some versions of gcc put a space before the ':'.  On the theory
2364a041c5bSmacallan## that the space means something, we add a space to the output as
23754b44505Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
23854b44505Smrg## to the object.  Take care to not repeat it in the output.
2394a041c5bSmacallan## Some versions of the HPUX 10.20 sed can't process this invocation
2404a041c5bSmacallan## correctly.  Breaking it into two sed invocations is a workaround.
2410a392d7eSmrg  tr ' ' "$nl" < "$tmpdepfile" \
2420a392d7eSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2430a392d7eSmrg    | sed -e 's/$/ :/' >> "$depfile"
2444a041c5bSmacallan  rm -f "$tmpdepfile"
2454a041c5bSmacallan  ;;
2464a041c5bSmacallan
2474a041c5bSmacallanhp)
2484a041c5bSmacallan  # This case exists only to let depend.m4 do its work.  It works by
2494a041c5bSmacallan  # looking at the text of this script.  This case will never be run,
2504a041c5bSmacallan  # since it is checked for above.
2514a041c5bSmacallan  exit 1
2524a041c5bSmacallan  ;;
2534a041c5bSmacallan
2544a041c5bSmacallansgi)
2554a041c5bSmacallan  if test "$libtool" = yes; then
2564a041c5bSmacallan    "$@" "-Wp,-MDupdate,$tmpdepfile"
2574a041c5bSmacallan  else
2584a041c5bSmacallan    "$@" -MDupdate "$tmpdepfile"
2594a041c5bSmacallan  fi
2604a041c5bSmacallan  stat=$?
2610a392d7eSmrg  if test $stat -ne 0; then
2624a041c5bSmacallan    rm -f "$tmpdepfile"
2634a041c5bSmacallan    exit $stat
2644a041c5bSmacallan  fi
2654a041c5bSmacallan  rm -f "$depfile"
2664a041c5bSmacallan
2674a041c5bSmacallan  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2684a041c5bSmacallan    echo "$object : \\" > "$depfile"
2694a041c5bSmacallan    # Clip off the initial element (the dependent).  Don't try to be
2704a041c5bSmacallan    # clever and replace this with sed code, as IRIX sed won't handle
2714a041c5bSmacallan    # lines with more than a fixed number of characters (4096 in
2724a041c5bSmacallan    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
27354b44505Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
2744a041c5bSmacallan    # dependency line.
27554b44505Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2760a392d7eSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2770a392d7eSmrg      | tr "$nl" ' ' >> "$depfile"
27854b44505Smrg    echo >> "$depfile"
2794a041c5bSmacallan    # The second pass generates a dummy entry for each header file.
28054b44505Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2810a392d7eSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2820a392d7eSmrg      >> "$depfile"
2834a041c5bSmacallan  else
2840a392d7eSmrg    make_dummy_depfile
2854a041c5bSmacallan  fi
2864a041c5bSmacallan  rm -f "$tmpdepfile"
2874a041c5bSmacallan  ;;
2884a041c5bSmacallan
28954b44505Smrgxlc)
29054b44505Smrg  # This case exists only to let depend.m4 do its work.  It works by
29154b44505Smrg  # looking at the text of this script.  This case will never be run,
29254b44505Smrg  # since it is checked for above.
29354b44505Smrg  exit 1
29454b44505Smrg  ;;
29554b44505Smrg
2964a041c5bSmacallanaix)
2974a041c5bSmacallan  # The C for AIX Compiler uses -M and outputs the dependencies
2984a041c5bSmacallan  # in a .u file.  In older versions, this file always lives in the
29954b44505Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3004a041c5bSmacallan  # start of each line; $object doesn't have directory information.
3014a041c5bSmacallan  # Version 6 uses the directory in both cases.
3020a392d7eSmrg  set_dir_from "$object"
3030a392d7eSmrg  set_base_from "$object"
3044a041c5bSmacallan  if test "$libtool" = yes; then
3054a041c5bSmacallan    tmpdepfile1=$dir$base.u
3064a041c5bSmacallan    tmpdepfile2=$base.u
3074a041c5bSmacallan    tmpdepfile3=$dir.libs/$base.u
3084a041c5bSmacallan    "$@" -Wc,-M
3094a041c5bSmacallan  else
3104a041c5bSmacallan    tmpdepfile1=$dir$base.u
3114a041c5bSmacallan    tmpdepfile2=$dir$base.u
3124a041c5bSmacallan    tmpdepfile3=$dir$base.u
3134a041c5bSmacallan    "$@" -M
3144a041c5bSmacallan  fi
3154a041c5bSmacallan  stat=$?
3160a392d7eSmrg  if test $stat -ne 0; then
3174a041c5bSmacallan    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3184a041c5bSmacallan    exit $stat
3194a041c5bSmacallan  fi
3204a041c5bSmacallan
3214a041c5bSmacallan  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3224a041c5bSmacallan  do
3234a041c5bSmacallan    test -f "$tmpdepfile" && break
3244a041c5bSmacallan  done
3250a392d7eSmrg  aix_post_process_depfile
3264a041c5bSmacallan  ;;
3274a041c5bSmacallan
3280a392d7eSmrgtcc)
3290a392d7eSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3300a392d7eSmrg  # FIXME: That version still under development at the moment of writing.
3310a392d7eSmrg  #        Make that this statement remains true also for stable, released
3320a392d7eSmrg  #        versions.
3330a392d7eSmrg  # It will wrap lines (doesn't matter whether long or short) with a
3340a392d7eSmrg  # trailing '\', as in:
3350a392d7eSmrg  #
3360a392d7eSmrg  #   foo.o : \
3370a392d7eSmrg  #    foo.c \
3380a392d7eSmrg  #    foo.h \
3390a392d7eSmrg  #
3400a392d7eSmrg  # It will put a trailing '\' even on the last line, and will use leading
3410a392d7eSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3420a392d7eSmrg  # "Emit spaces for -MD").
3434a041c5bSmacallan  "$@" -MD -MF "$tmpdepfile"
3444a041c5bSmacallan  stat=$?
3450a392d7eSmrg  if test $stat -ne 0; then
3464a041c5bSmacallan    rm -f "$tmpdepfile"
3474a041c5bSmacallan    exit $stat
3484a041c5bSmacallan  fi
3494a041c5bSmacallan  rm -f "$depfile"
3500a392d7eSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3510a392d7eSmrg  # We have to change lines of the first kind to '$object: \'.
3520a392d7eSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3530a392d7eSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3540a392d7eSmrg  # dummy dependency, to avoid the deleted-header problem.
3550a392d7eSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35654b44505Smrg  rm -f "$tmpdepfile"
35754b44505Smrg  ;;
35854b44505Smrg
35954b44505Smrg## The order of this option in the case statement is important, since the
36054b44505Smrg## shell code in configure will try each of these formats in the order
36154b44505Smrg## listed in this file.  A plain '-MD' option would be understood by many
36254b44505Smrg## compilers, so we must ensure this comes after the gcc and icc options.
36354b44505Smrgpgcc)
36454b44505Smrg  # Portland's C compiler understands '-MD'.
36554b44505Smrg  # Will always output deps to 'file.d' where file is the root name of the
36654b44505Smrg  # source file under compilation, even if file resides in a subdirectory.
36754b44505Smrg  # The object file name does not affect the name of the '.d' file.
36854b44505Smrg  # pgcc 10.2 will output
36954b44505Smrg  #    foo.o: sub/foo.c sub/foo.h
37054b44505Smrg  # and will wrap long lines using '\' :
37154b44505Smrg  #    foo.o: sub/foo.c ... \
37254b44505Smrg  #     sub/foo.h ... \
37354b44505Smrg  #     ...
3740a392d7eSmrg  set_dir_from "$object"
37554b44505Smrg  # Use the source, not the object, to determine the base name, since
37654b44505Smrg  # that's sadly what pgcc will do too.
3770a392d7eSmrg  set_base_from "$source"
3780a392d7eSmrg  tmpdepfile=$base.d
37954b44505Smrg
38054b44505Smrg  # For projects that build the same source file twice into different object
38154b44505Smrg  # files, the pgcc approach of using the *source* file root name can cause
38254b44505Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
38354b44505Smrg  # the same $tmpdepfile.
3840a392d7eSmrg  lockdir=$base.d-lock
3850a392d7eSmrg  trap "
3860a392d7eSmrg    echo '$0: caught signal, cleaning up...' >&2
3870a392d7eSmrg    rmdir '$lockdir'
3880a392d7eSmrg    exit 1
3890a392d7eSmrg  " 1 2 13 15
39054b44505Smrg  numtries=100
39154b44505Smrg  i=$numtries
3920a392d7eSmrg  while test $i -gt 0; do
39354b44505Smrg    # mkdir is a portable test-and-set.
3940a392d7eSmrg    if mkdir "$lockdir" 2>/dev/null; then
39554b44505Smrg      # This process acquired the lock.
39654b44505Smrg      "$@" -MD
39754b44505Smrg      stat=$?
39854b44505Smrg      # Release the lock.
3990a392d7eSmrg      rmdir "$lockdir"
40054b44505Smrg      break
40154b44505Smrg    else
4020a392d7eSmrg      # If the lock is being held by a different process, wait
4030a392d7eSmrg      # until the winning process is done or we timeout.
4040a392d7eSmrg      while test -d "$lockdir" && test $i -gt 0; do
40554b44505Smrg        sleep 1
40654b44505Smrg        i=`expr $i - 1`
40754b44505Smrg      done
40854b44505Smrg    fi
40954b44505Smrg    i=`expr $i - 1`
41054b44505Smrg  done
41154b44505Smrg  trap - 1 2 13 15
41254b44505Smrg  if test $i -le 0; then
41354b44505Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
41454b44505Smrg    echo "$0: check lockdir '$lockdir'" >&2
41554b44505Smrg    exit 1
41654b44505Smrg  fi
41754b44505Smrg
41854b44505Smrg  if test $stat -ne 0; then
41954b44505Smrg    rm -f "$tmpdepfile"
42054b44505Smrg    exit $stat
42154b44505Smrg  fi
42254b44505Smrg  rm -f "$depfile"
4234a041c5bSmacallan  # Each line is of the form `foo.o: dependent.h',
4244a041c5bSmacallan  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4254a041c5bSmacallan  # Do two passes, one to just change these to
4264a041c5bSmacallan  # `$object: dependent.h' and one to simply `dependent.h:'.
4274a041c5bSmacallan  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4284a041c5bSmacallan  # Some versions of the HPUX 10.20 sed can't process this invocation
4294a041c5bSmacallan  # correctly.  Breaking it into two sed invocations is a workaround.
4300a392d7eSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4310a392d7eSmrg    | sed -e 's/$/ :/' >> "$depfile"
4324a041c5bSmacallan  rm -f "$tmpdepfile"
4334a041c5bSmacallan  ;;
4344a041c5bSmacallan
4354a041c5bSmacallanhp2)
4364a041c5bSmacallan  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4374a041c5bSmacallan  # compilers, which have integrated preprocessors.  The correct option
4384a041c5bSmacallan  # to use with these is +Maked; it writes dependencies to a file named
4394a041c5bSmacallan  # 'foo.d', which lands next to the object file, wherever that
4404a041c5bSmacallan  # happens to be.
4414a041c5bSmacallan  # Much of this is similar to the tru64 case; see comments there.
4420a392d7eSmrg  set_dir_from  "$object"
4430a392d7eSmrg  set_base_from "$object"
4444a041c5bSmacallan  if test "$libtool" = yes; then
4454a041c5bSmacallan    tmpdepfile1=$dir$base.d
4464a041c5bSmacallan    tmpdepfile2=$dir.libs/$base.d
4474a041c5bSmacallan    "$@" -Wc,+Maked
4484a041c5bSmacallan  else
4494a041c5bSmacallan    tmpdepfile1=$dir$base.d
4504a041c5bSmacallan    tmpdepfile2=$dir$base.d
4514a041c5bSmacallan    "$@" +Maked
4524a041c5bSmacallan  fi
4534a041c5bSmacallan  stat=$?
4540a392d7eSmrg  if test $stat -ne 0; then
4554a041c5bSmacallan     rm -f "$tmpdepfile1" "$tmpdepfile2"
4564a041c5bSmacallan     exit $stat
4574a041c5bSmacallan  fi
4584a041c5bSmacallan
4594a041c5bSmacallan  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4604a041c5bSmacallan  do
4614a041c5bSmacallan    test -f "$tmpdepfile" && break
4624a041c5bSmacallan  done
4634a041c5bSmacallan  if test -f "$tmpdepfile"; then
4640a392d7eSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
46554b44505Smrg    # Add 'dependent.h:' lines.
46654b44505Smrg    sed -ne '2,${
4670a392d7eSmrg               s/^ *//
4680a392d7eSmrg               s/ \\*$//
4690a392d7eSmrg               s/$/:/
4700a392d7eSmrg               p
4710a392d7eSmrg             }' "$tmpdepfile" >> "$depfile"
4724a041c5bSmacallan  else
4730a392d7eSmrg    make_dummy_depfile
4744a041c5bSmacallan  fi
4754a041c5bSmacallan  rm -f "$tmpdepfile" "$tmpdepfile2"
4764a041c5bSmacallan  ;;
4774a041c5bSmacallan
4784a041c5bSmacallantru64)
4790a392d7eSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4800a392d7eSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4810a392d7eSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4820a392d7eSmrg  # dependencies in 'foo.d' instead, so we check for that too.
4830a392d7eSmrg  # Subdirectories are respected.
4840a392d7eSmrg  set_dir_from  "$object"
4850a392d7eSmrg  set_base_from "$object"
4860a392d7eSmrg
4870a392d7eSmrg  if test "$libtool" = yes; then
4880a392d7eSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4890a392d7eSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4900a392d7eSmrg    # in $dir$base.o.d.  We have to check for both files, because
4910a392d7eSmrg    # one of the two compilations can be disabled.  We should prefer
4920a392d7eSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4930a392d7eSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
4940a392d7eSmrg    # the former would cause a distcleancheck panic.
4950a392d7eSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4960a392d7eSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4970a392d7eSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4980a392d7eSmrg    "$@" -Wc,-MD
4990a392d7eSmrg  else
5000a392d7eSmrg    tmpdepfile1=$dir$base.d
5010a392d7eSmrg    tmpdepfile2=$dir$base.d
5020a392d7eSmrg    tmpdepfile3=$dir$base.d
5030a392d7eSmrg    "$@" -MD
5040a392d7eSmrg  fi
5050a392d7eSmrg
5060a392d7eSmrg  stat=$?
5070a392d7eSmrg  if test $stat -ne 0; then
5080a392d7eSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5090a392d7eSmrg    exit $stat
5100a392d7eSmrg  fi
5110a392d7eSmrg
5120a392d7eSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5130a392d7eSmrg  do
5140a392d7eSmrg    test -f "$tmpdepfile" && break
5150a392d7eSmrg  done
5160a392d7eSmrg  # Same post-processing that is required for AIX mode.
5170a392d7eSmrg  aix_post_process_depfile
5180a392d7eSmrg  ;;
5194a041c5bSmacallan
52054b44505Smrgmsvc7)
52154b44505Smrg  if test "$libtool" = yes; then
52254b44505Smrg    showIncludes=-Wc,-showIncludes
52354b44505Smrg  else
52454b44505Smrg    showIncludes=-showIncludes
52554b44505Smrg  fi
52654b44505Smrg  "$@" $showIncludes > "$tmpdepfile"
52754b44505Smrg  stat=$?
52854b44505Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5290a392d7eSmrg  if test $stat -ne 0; then
53054b44505Smrg    rm -f "$tmpdepfile"
53154b44505Smrg    exit $stat
53254b44505Smrg  fi
53354b44505Smrg  rm -f "$depfile"
53454b44505Smrg  echo "$object : \\" > "$depfile"
53554b44505Smrg  # The first sed program below extracts the file names and escapes
53654b44505Smrg  # backslashes for cygpath.  The second sed program outputs the file
53754b44505Smrg  # name when reading, but also accumulates all include files in the
53854b44505Smrg  # hold buffer in order to output them again at the end.  This only
53954b44505Smrg  # works with sed implementations that can handle large buffers.
54054b44505Smrg  sed < "$tmpdepfile" -n '
54154b44505Smrg/^Note: including file:  *\(.*\)/ {
54254b44505Smrg  s//\1/
54354b44505Smrg  s/\\/\\\\/g
54454b44505Smrg  p
54554b44505Smrg}' | $cygpath_u | sort -u | sed -n '
54654b44505Smrgs/ /\\ /g
54754b44505Smrgs/\(.*\)/'"$tab"'\1 \\/p
54854b44505Smrgs/.\(.*\) \\/\1:/
54954b44505SmrgH
55054b44505Smrg$ {
55154b44505Smrg  s/.*/'"$tab"'/
55254b44505Smrg  G
55354b44505Smrg  p
55454b44505Smrg}' >> "$depfile"
5550a392d7eSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
55654b44505Smrg  rm -f "$tmpdepfile"
55754b44505Smrg  ;;
55854b44505Smrg
55954b44505Smrgmsvc7msys)
56054b44505Smrg  # This case exists only to let depend.m4 do its work.  It works by
56154b44505Smrg  # looking at the text of this script.  This case will never be run,
56254b44505Smrg  # since it is checked for above.
56354b44505Smrg  exit 1
56454b44505Smrg  ;;
56554b44505Smrg
5664a041c5bSmacallan#nosideeffect)
5674a041c5bSmacallan  # This comment above is used by automake to tell side-effect
5684a041c5bSmacallan  # dependency tracking mechanisms from slower ones.
5694a041c5bSmacallan
5704a041c5bSmacallandashmstdout)
5714a041c5bSmacallan  # Important note: in order to support this mode, a compiler *must*
5724a041c5bSmacallan  # always write the preprocessed file to stdout, regardless of -o.
5734a041c5bSmacallan  "$@" || exit $?
5744a041c5bSmacallan
5754a041c5bSmacallan  # Remove the call to Libtool.
5764a041c5bSmacallan  if test "$libtool" = yes; then
57754b44505Smrg    while test "X$1" != 'X--mode=compile'; do
5784a041c5bSmacallan      shift
5794a041c5bSmacallan    done
5804a041c5bSmacallan    shift
5814a041c5bSmacallan  fi
5824a041c5bSmacallan
58354b44505Smrg  # Remove '-o $object'.
5844a041c5bSmacallan  IFS=" "
5854a041c5bSmacallan  for arg
5864a041c5bSmacallan  do
5874a041c5bSmacallan    case $arg in
5884a041c5bSmacallan    -o)
5894a041c5bSmacallan      shift
5904a041c5bSmacallan      ;;
5914a041c5bSmacallan    $object)
5924a041c5bSmacallan      shift
5934a041c5bSmacallan      ;;
5944a041c5bSmacallan    *)
5954a041c5bSmacallan      set fnord "$@" "$arg"
5964a041c5bSmacallan      shift # fnord
5974a041c5bSmacallan      shift # $arg
5984a041c5bSmacallan      ;;
5994a041c5bSmacallan    esac
6004a041c5bSmacallan  done
6014a041c5bSmacallan
6024a041c5bSmacallan  test -z "$dashmflag" && dashmflag=-M
60354b44505Smrg  # Require at least two characters before searching for ':'
6044a041c5bSmacallan  # in the target name.  This is to cope with DOS-style filenames:
60554b44505Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6064a041c5bSmacallan  "$@" $dashmflag |
6070a392d7eSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6084a041c5bSmacallan  rm -f "$depfile"
6094a041c5bSmacallan  cat < "$tmpdepfile" > "$depfile"
6100a392d7eSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6110a392d7eSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6120a392d7eSmrg  tr ' ' "$nl" < "$tmpdepfile" \
6130a392d7eSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6140a392d7eSmrg    | sed -e 's/$/ :/' >> "$depfile"
6154a041c5bSmacallan  rm -f "$tmpdepfile"
6164a041c5bSmacallan  ;;
6174a041c5bSmacallan
6184a041c5bSmacallandashXmstdout)
6194a041c5bSmacallan  # This case only exists to satisfy depend.m4.  It is never actually
6204a041c5bSmacallan  # run, as this mode is specially recognized in the preamble.
6214a041c5bSmacallan  exit 1
6224a041c5bSmacallan  ;;
6234a041c5bSmacallan
6244a041c5bSmacallanmakedepend)
6254a041c5bSmacallan  "$@" || exit $?
6264a041c5bSmacallan  # Remove any Libtool call
6274a041c5bSmacallan  if test "$libtool" = yes; then
62854b44505Smrg    while test "X$1" != 'X--mode=compile'; do
6294a041c5bSmacallan      shift
6304a041c5bSmacallan    done
6314a041c5bSmacallan    shift
6324a041c5bSmacallan  fi
6334a041c5bSmacallan  # X makedepend
6344a041c5bSmacallan  shift
63554b44505Smrg  cleared=no eat=no
63654b44505Smrg  for arg
63754b44505Smrg  do
6384a041c5bSmacallan    case $cleared in
6394a041c5bSmacallan    no)
6404a041c5bSmacallan      set ""; shift
6414a041c5bSmacallan      cleared=yes ;;
6424a041c5bSmacallan    esac
64354b44505Smrg    if test $eat = yes; then
64454b44505Smrg      eat=no
64554b44505Smrg      continue
64654b44505Smrg    fi
6474a041c5bSmacallan    case "$arg" in
6484a041c5bSmacallan    -D*|-I*)
6494a041c5bSmacallan      set fnord "$@" "$arg"; shift ;;
6504a041c5bSmacallan    # Strip any option that makedepend may not understand.  Remove
6514a041c5bSmacallan    # the object too, otherwise makedepend will parse it as a source file.
65254b44505Smrg    -arch)
65354b44505Smrg      eat=yes ;;
6544a041c5bSmacallan    -*|$object)
6554a041c5bSmacallan      ;;
6564a041c5bSmacallan    *)
6574a041c5bSmacallan      set fnord "$@" "$arg"; shift ;;
6584a041c5bSmacallan    esac
6594a041c5bSmacallan  done
66054b44505Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6614a041c5bSmacallan  touch "$tmpdepfile"
6624a041c5bSmacallan  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6634a041c5bSmacallan  rm -f "$depfile"
66454b44505Smrg  # makedepend may prepend the VPATH from the source file name to the object.
66554b44505Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
66654b44505Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6670a392d7eSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6680a392d7eSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6690a392d7eSmrg  sed '1,2d' "$tmpdepfile" \
6700a392d7eSmrg    | tr ' ' "$nl" \
6710a392d7eSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6720a392d7eSmrg    | sed -e 's/$/ :/' >> "$depfile"
6734a041c5bSmacallan  rm -f "$tmpdepfile" "$tmpdepfile".bak
6744a041c5bSmacallan  ;;
6754a041c5bSmacallan
6764a041c5bSmacallancpp)
6774a041c5bSmacallan  # Important note: in order to support this mode, a compiler *must*
6784a041c5bSmacallan  # always write the preprocessed file to stdout.
6794a041c5bSmacallan  "$@" || exit $?
6804a041c5bSmacallan
6814a041c5bSmacallan  # Remove the call to Libtool.
6824a041c5bSmacallan  if test "$libtool" = yes; then
68354b44505Smrg    while test "X$1" != 'X--mode=compile'; do
6844a041c5bSmacallan      shift
6854a041c5bSmacallan    done
6864a041c5bSmacallan    shift
6874a041c5bSmacallan  fi
6884a041c5bSmacallan
68954b44505Smrg  # Remove '-o $object'.
6904a041c5bSmacallan  IFS=" "
6914a041c5bSmacallan  for arg
6924a041c5bSmacallan  do
6934a041c5bSmacallan    case $arg in
6944a041c5bSmacallan    -o)
6954a041c5bSmacallan      shift
6964a041c5bSmacallan      ;;
6974a041c5bSmacallan    $object)
6984a041c5bSmacallan      shift
6994a041c5bSmacallan      ;;
7004a041c5bSmacallan    *)
7014a041c5bSmacallan      set fnord "$@" "$arg"
7024a041c5bSmacallan      shift # fnord
7034a041c5bSmacallan      shift # $arg
7044a041c5bSmacallan      ;;
7054a041c5bSmacallan    esac
7064a041c5bSmacallan  done
7074a041c5bSmacallan
7080a392d7eSmrg  "$@" -E \
7090a392d7eSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7100a392d7eSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7110a392d7eSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
7124a041c5bSmacallan  rm -f "$depfile"
7134a041c5bSmacallan  echo "$object : \\" > "$depfile"
7144a041c5bSmacallan  cat < "$tmpdepfile" >> "$depfile"
7154a041c5bSmacallan  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7164a041c5bSmacallan  rm -f "$tmpdepfile"
7174a041c5bSmacallan  ;;
7184a041c5bSmacallan
7194a041c5bSmacallanmsvisualcpp)
7204a041c5bSmacallan  # Important note: in order to support this mode, a compiler *must*
72154b44505Smrg  # always write the preprocessed file to stdout.
7224a041c5bSmacallan  "$@" || exit $?
72354b44505Smrg
72454b44505Smrg  # Remove the call to Libtool.
72554b44505Smrg  if test "$libtool" = yes; then
72654b44505Smrg    while test "X$1" != 'X--mode=compile'; do
72754b44505Smrg      shift
72854b44505Smrg    done
72954b44505Smrg    shift
73054b44505Smrg  fi
73154b44505Smrg
7324a041c5bSmacallan  IFS=" "
7334a041c5bSmacallan  for arg
7344a041c5bSmacallan  do
7354a041c5bSmacallan    case "$arg" in
73654b44505Smrg    -o)
73754b44505Smrg      shift
73854b44505Smrg      ;;
73954b44505Smrg    $object)
74054b44505Smrg      shift
74154b44505Smrg      ;;
7424a041c5bSmacallan    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7430a392d7eSmrg        set fnord "$@"
7440a392d7eSmrg        shift
7450a392d7eSmrg        shift
7460a392d7eSmrg        ;;
7474a041c5bSmacallan    *)
7480a392d7eSmrg        set fnord "$@" "$arg"
7490a392d7eSmrg        shift
7500a392d7eSmrg        shift
7510a392d7eSmrg        ;;
7524a041c5bSmacallan    esac
7534a041c5bSmacallan  done
75454b44505Smrg  "$@" -E 2>/dev/null |
75554b44505Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7564a041c5bSmacallan  rm -f "$depfile"
7574a041c5bSmacallan  echo "$object : \\" > "$depfile"
75854b44505Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
75954b44505Smrg  echo "$tab" >> "$depfile"
76054b44505Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7614a041c5bSmacallan  rm -f "$tmpdepfile"
7624a041c5bSmacallan  ;;
7634a041c5bSmacallan
76454b44505Smrgmsvcmsys)
76554b44505Smrg  # This case exists only to let depend.m4 do its work.  It works by
76654b44505Smrg  # looking at the text of this script.  This case will never be run,
76754b44505Smrg  # since it is checked for above.
76854b44505Smrg  exit 1
76954b44505Smrg  ;;
77054b44505Smrg
7714a041c5bSmacallannone)
7724a041c5bSmacallan  exec "$@"
7734a041c5bSmacallan  ;;
7744a041c5bSmacallan
7754a041c5bSmacallan*)
7764a041c5bSmacallan  echo "Unknown depmode $depmode" 1>&2
7774a041c5bSmacallan  exit 1
7784a041c5bSmacallan  ;;
7794a041c5bSmacallanesac
7804a041c5bSmacallan
7814a041c5bSmacallanexit 0
7824a041c5bSmacallan
7834a041c5bSmacallan# Local Variables:
7844a041c5bSmacallan# mode: shell-script
7854a041c5bSmacallan# sh-indentation: 2
7864a041c5bSmacallan# eval: (add-hook 'write-file-hooks 'time-stamp)
7874a041c5bSmacallan# time-stamp-start: "scriptversion="
7884a041c5bSmacallan# time-stamp-format: "%:y-%02m-%02d.%02H"
78954b44505Smrg# time-stamp-time-zone: "UTC"
79054b44505Smrg# time-stamp-end: "; # UTC"
7914a041c5bSmacallan# End:
792