depcomp revision 0ed7c580
10ed7c580Smrg#! /bin/sh
20ed7c580Smrg# depcomp - compile a program generating dependencies as side-effects
30ed7c580Smrg
40ed7c580Smrgscriptversion=2013-05-30.07; # UTC
50ed7c580Smrg
60ed7c580Smrg# Copyright (C) 1999-2013 Free Software Foundation, Inc.
70ed7c580Smrg
80ed7c580Smrg# This program is free software; you can redistribute it and/or modify
90ed7c580Smrg# it under the terms of the GNU General Public License as published by
100ed7c580Smrg# the Free Software Foundation; either version 2, or (at your option)
110ed7c580Smrg# any later version.
120ed7c580Smrg
130ed7c580Smrg# This program is distributed in the hope that it will be useful,
140ed7c580Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
150ed7c580Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
160ed7c580Smrg# GNU General Public License for more details.
170ed7c580Smrg
180ed7c580Smrg# You should have received a copy of the GNU General Public License
190ed7c580Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
200ed7c580Smrg
210ed7c580Smrg# As a special exception to the GNU General Public License, if you
220ed7c580Smrg# distribute this file as part of a program that contains a
230ed7c580Smrg# configuration script generated by Autoconf, you may include it under
240ed7c580Smrg# the same distribution terms that you use for the rest of that program.
250ed7c580Smrg
260ed7c580Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
270ed7c580Smrg
280ed7c580Smrgcase $1 in
290ed7c580Smrg  '')
300ed7c580Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
310ed7c580Smrg    exit 1;
320ed7c580Smrg    ;;
330ed7c580Smrg  -h | --h*)
340ed7c580Smrg    cat <<\EOF
350ed7c580SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
360ed7c580Smrg
370ed7c580SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
380ed7c580Smrgas side-effects.
390ed7c580Smrg
400ed7c580SmrgEnvironment variables:
410ed7c580Smrg  depmode     Dependency tracking mode.
420ed7c580Smrg  source      Source file read by 'PROGRAMS ARGS'.
430ed7c580Smrg  object      Object file output by 'PROGRAMS ARGS'.
440ed7c580Smrg  DEPDIR      directory where to store dependencies.
450ed7c580Smrg  depfile     Dependency file to output.
460ed7c580Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
470ed7c580Smrg  libtool     Whether libtool is used (yes/no).
480ed7c580Smrg
490ed7c580SmrgReport bugs to <bug-automake@gnu.org>.
500ed7c580SmrgEOF
510ed7c580Smrg    exit $?
520ed7c580Smrg    ;;
530ed7c580Smrg  -v | --v*)
540ed7c580Smrg    echo "depcomp $scriptversion"
550ed7c580Smrg    exit $?
560ed7c580Smrg    ;;
570ed7c580Smrgesac
580ed7c580Smrg
590ed7c580Smrg# Get the directory component of the given path, and save it in the
600ed7c580Smrg# global variables '$dir'.  Note that this directory component will
610ed7c580Smrg# be either empty or ending with a '/' character.  This is deliberate.
620ed7c580Smrgset_dir_from ()
630ed7c580Smrg{
640ed7c580Smrg  case $1 in
650ed7c580Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
660ed7c580Smrg      *) dir=;;
670ed7c580Smrg  esac
680ed7c580Smrg}
690ed7c580Smrg
700ed7c580Smrg# Get the suffix-stripped basename of the given path, and save it the
710ed7c580Smrg# global variable '$base'.
720ed7c580Smrgset_base_from ()
730ed7c580Smrg{
740ed7c580Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
750ed7c580Smrg}
760ed7c580Smrg
770ed7c580Smrg# If no dependency file was actually created by the compiler invocation,
780ed7c580Smrg# we still have to create a dummy depfile, to avoid errors with the
790ed7c580Smrg# Makefile "include basename.Plo" scheme.
800ed7c580Smrgmake_dummy_depfile ()
810ed7c580Smrg{
820ed7c580Smrg  echo "#dummy" > "$depfile"
830ed7c580Smrg}
840ed7c580Smrg
850ed7c580Smrg# Factor out some common post-processing of the generated depfile.
860ed7c580Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
870ed7c580Smrgaix_post_process_depfile ()
880ed7c580Smrg{
890ed7c580Smrg  # If the compiler actually managed to produce a dependency file,
900ed7c580Smrg  # post-process it.
910ed7c580Smrg  if test -f "$tmpdepfile"; then
920ed7c580Smrg    # Each line is of the form 'foo.o: dependency.h'.
930ed7c580Smrg    # Do two passes, one to just change these to
940ed7c580Smrg    #   $object: dependency.h
950ed7c580Smrg    # and one to simply output
960ed7c580Smrg    #   dependency.h:
970ed7c580Smrg    # which is needed to avoid the deleted-header problem.
980ed7c580Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
990ed7c580Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1000ed7c580Smrg    } > "$depfile"
1010ed7c580Smrg    rm -f "$tmpdepfile"
1020ed7c580Smrg  else
1030ed7c580Smrg    make_dummy_depfile
1040ed7c580Smrg  fi
1050ed7c580Smrg}
1060ed7c580Smrg
1070ed7c580Smrg# A tabulation character.
1080ed7c580Smrgtab='	'
1090ed7c580Smrg# A newline character.
1100ed7c580Smrgnl='
1110ed7c580Smrg'
1120ed7c580Smrg# Character ranges might be problematic outside the C locale.
1130ed7c580Smrg# These definitions help.
1140ed7c580Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1150ed7c580Smrglower=abcdefghijklmnopqrstuvwxyz
1160ed7c580Smrgdigits=0123456789
1170ed7c580Smrgalpha=${upper}${lower}
1180ed7c580Smrg
1190ed7c580Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1200ed7c580Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1210ed7c580Smrg  exit 1
1220ed7c580Smrgfi
1230ed7c580Smrg
1240ed7c580Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1250ed7c580Smrgdepfile=${depfile-`echo "$object" |
1260ed7c580Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1270ed7c580Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1280ed7c580Smrg
1290ed7c580Smrgrm -f "$tmpdepfile"
1300ed7c580Smrg
1310ed7c580Smrg# Avoid interferences from the environment.
1320ed7c580Smrggccflag= dashmflag=
1330ed7c580Smrg
1340ed7c580Smrg# Some modes work just like other modes, but use different flags.  We
1350ed7c580Smrg# parameterize here, but still list the modes in the big case below,
1360ed7c580Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1370ed7c580Smrg# here, because this file can only contain one case statement.
1380ed7c580Smrgif test "$depmode" = hp; then
1390ed7c580Smrg  # HP compiler uses -M and no extra arg.
1400ed7c580Smrg  gccflag=-M
1410ed7c580Smrg  depmode=gcc
1420ed7c580Smrgfi
1430ed7c580Smrg
1440ed7c580Smrgif test "$depmode" = dashXmstdout; then
1450ed7c580Smrg  # This is just like dashmstdout with a different argument.
1460ed7c580Smrg  dashmflag=-xM
1470ed7c580Smrg  depmode=dashmstdout
1480ed7c580Smrgfi
1490ed7c580Smrg
1500ed7c580Smrgcygpath_u="cygpath -u -f -"
1510ed7c580Smrgif test "$depmode" = msvcmsys; then
1520ed7c580Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1530ed7c580Smrg  # Just convert the backslash-escaped backslashes to single forward
1540ed7c580Smrg  # slashes to satisfy depend.m4
1550ed7c580Smrg  cygpath_u='sed s,\\\\,/,g'
1560ed7c580Smrg  depmode=msvisualcpp
1570ed7c580Smrgfi
1580ed7c580Smrg
1590ed7c580Smrgif test "$depmode" = msvc7msys; then
1600ed7c580Smrg  # This is just like msvc7 but w/o cygpath translation.
1610ed7c580Smrg  # Just convert the backslash-escaped backslashes to single forward
1620ed7c580Smrg  # slashes to satisfy depend.m4
1630ed7c580Smrg  cygpath_u='sed s,\\\\,/,g'
1640ed7c580Smrg  depmode=msvc7
1650ed7c580Smrgfi
1660ed7c580Smrg
1670ed7c580Smrgif test "$depmode" = xlc; then
1680ed7c580Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1690ed7c580Smrg  gccflag=-qmakedep=gcc,-MF
1700ed7c580Smrg  depmode=gcc
1710ed7c580Smrgfi
1720ed7c580Smrg
1730ed7c580Smrgcase "$depmode" in
1740ed7c580Smrggcc3)
1750ed7c580Smrg## gcc 3 implements dependency tracking that does exactly what
1760ed7c580Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1770ed7c580Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1780ed7c580Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1790ed7c580Smrg## the command line argument order; so add the flags where they
1800ed7c580Smrg## appear in depend2.am.  Note that the slowdown incurred here
1810ed7c580Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1820ed7c580Smrg  for arg
1830ed7c580Smrg  do
1840ed7c580Smrg    case $arg in
1850ed7c580Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1860ed7c580Smrg    *)  set fnord "$@" "$arg" ;;
1870ed7c580Smrg    esac
1880ed7c580Smrg    shift # fnord
1890ed7c580Smrg    shift # $arg
1900ed7c580Smrg  done
1910ed7c580Smrg  "$@"
1920ed7c580Smrg  stat=$?
1930ed7c580Smrg  if test $stat -ne 0; then
1940ed7c580Smrg    rm -f "$tmpdepfile"
1950ed7c580Smrg    exit $stat
1960ed7c580Smrg  fi
1970ed7c580Smrg  mv "$tmpdepfile" "$depfile"
1980ed7c580Smrg  ;;
1990ed7c580Smrg
2000ed7c580Smrggcc)
2010ed7c580Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2020ed7c580Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2030ed7c580Smrg## (see the conditional assignment to $gccflag above).
2040ed7c580Smrg## There are various ways to get dependency output from gcc.  Here's
2050ed7c580Smrg## why we pick this rather obscure method:
2060ed7c580Smrg## - Don't want to use -MD because we'd like the dependencies to end
2070ed7c580Smrg##   up in a subdir.  Having to rename by hand is ugly.
2080ed7c580Smrg##   (We might end up doing this anyway to support other compilers.)
2090ed7c580Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2100ed7c580Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2110ed7c580Smrg##   supported by the other compilers which use the 'gcc' depmode.
2120ed7c580Smrg## - Using -M directly means running the compiler twice (even worse
2130ed7c580Smrg##   than renaming).
2140ed7c580Smrg  if test -z "$gccflag"; then
2150ed7c580Smrg    gccflag=-MD,
2160ed7c580Smrg  fi
2170ed7c580Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
2180ed7c580Smrg  stat=$?
2190ed7c580Smrg  if test $stat -ne 0; then
2200ed7c580Smrg    rm -f "$tmpdepfile"
2210ed7c580Smrg    exit $stat
2220ed7c580Smrg  fi
2230ed7c580Smrg  rm -f "$depfile"
2240ed7c580Smrg  echo "$object : \\" > "$depfile"
2250ed7c580Smrg  # The second -e expression handles DOS-style file names with drive
2260ed7c580Smrg  # letters.
2270ed7c580Smrg  sed -e 's/^[^:]*: / /' \
2280ed7c580Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2290ed7c580Smrg## This next piece of magic avoids the "deleted header file" problem.
2300ed7c580Smrg## The problem is that when a header file which appears in a .P file
2310ed7c580Smrg## is deleted, the dependency causes make to die (because there is
2320ed7c580Smrg## typically no way to rebuild the header).  We avoid this by adding
2330ed7c580Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2340ed7c580Smrg## this for us directly.
2350ed7c580Smrg## Some versions of gcc put a space before the ':'.  On the theory
2360ed7c580Smrg## that the space means something, we add a space to the output as
2370ed7c580Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2380ed7c580Smrg## to the object.  Take care to not repeat it in the output.
2390ed7c580Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
2400ed7c580Smrg## correctly.  Breaking it into two sed invocations is a workaround.
2410ed7c580Smrg  tr ' ' "$nl" < "$tmpdepfile" \
2420ed7c580Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2430ed7c580Smrg    | sed -e 's/$/ :/' >> "$depfile"
2440ed7c580Smrg  rm -f "$tmpdepfile"
2450ed7c580Smrg  ;;
2460ed7c580Smrg
2470ed7c580Smrghp)
2480ed7c580Smrg  # This case exists only to let depend.m4 do its work.  It works by
2490ed7c580Smrg  # looking at the text of this script.  This case will never be run,
2500ed7c580Smrg  # since it is checked for above.
2510ed7c580Smrg  exit 1
2520ed7c580Smrg  ;;
2530ed7c580Smrg
2540ed7c580Smrgsgi)
2550ed7c580Smrg  if test "$libtool" = yes; then
2560ed7c580Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2570ed7c580Smrg  else
2580ed7c580Smrg    "$@" -MDupdate "$tmpdepfile"
2590ed7c580Smrg  fi
2600ed7c580Smrg  stat=$?
2610ed7c580Smrg  if test $stat -ne 0; then
2620ed7c580Smrg    rm -f "$tmpdepfile"
2630ed7c580Smrg    exit $stat
2640ed7c580Smrg  fi
2650ed7c580Smrg  rm -f "$depfile"
2660ed7c580Smrg
2670ed7c580Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2680ed7c580Smrg    echo "$object : \\" > "$depfile"
2690ed7c580Smrg    # Clip off the initial element (the dependent).  Don't try to be
2700ed7c580Smrg    # clever and replace this with sed code, as IRIX sed won't handle
2710ed7c580Smrg    # lines with more than a fixed number of characters (4096 in
2720ed7c580Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2730ed7c580Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
2740ed7c580Smrg    # dependency line.
2750ed7c580Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2760ed7c580Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2770ed7c580Smrg      | tr "$nl" ' ' >> "$depfile"
2780ed7c580Smrg    echo >> "$depfile"
2790ed7c580Smrg    # The second pass generates a dummy entry for each header file.
2800ed7c580Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2810ed7c580Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2820ed7c580Smrg      >> "$depfile"
2830ed7c580Smrg  else
2840ed7c580Smrg    make_dummy_depfile
2850ed7c580Smrg  fi
2860ed7c580Smrg  rm -f "$tmpdepfile"
2870ed7c580Smrg  ;;
2880ed7c580Smrg
2890ed7c580Smrgxlc)
2900ed7c580Smrg  # This case exists only to let depend.m4 do its work.  It works by
2910ed7c580Smrg  # looking at the text of this script.  This case will never be run,
2920ed7c580Smrg  # since it is checked for above.
2930ed7c580Smrg  exit 1
2940ed7c580Smrg  ;;
2950ed7c580Smrg
2960ed7c580Smrgaix)
2970ed7c580Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2980ed7c580Smrg  # in a .u file.  In older versions, this file always lives in the
2990ed7c580Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3000ed7c580Smrg  # start of each line; $object doesn't have directory information.
3010ed7c580Smrg  # Version 6 uses the directory in both cases.
3020ed7c580Smrg  set_dir_from "$object"
3030ed7c580Smrg  set_base_from "$object"
3040ed7c580Smrg  if test "$libtool" = yes; then
3050ed7c580Smrg    tmpdepfile1=$dir$base.u
3060ed7c580Smrg    tmpdepfile2=$base.u
3070ed7c580Smrg    tmpdepfile3=$dir.libs/$base.u
3080ed7c580Smrg    "$@" -Wc,-M
3090ed7c580Smrg  else
3100ed7c580Smrg    tmpdepfile1=$dir$base.u
3110ed7c580Smrg    tmpdepfile2=$dir$base.u
3120ed7c580Smrg    tmpdepfile3=$dir$base.u
3130ed7c580Smrg    "$@" -M
3140ed7c580Smrg  fi
3150ed7c580Smrg  stat=$?
3160ed7c580Smrg  if test $stat -ne 0; then
3170ed7c580Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3180ed7c580Smrg    exit $stat
3190ed7c580Smrg  fi
3200ed7c580Smrg
3210ed7c580Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3220ed7c580Smrg  do
3230ed7c580Smrg    test -f "$tmpdepfile" && break
3240ed7c580Smrg  done
3250ed7c580Smrg  aix_post_process_depfile
3260ed7c580Smrg  ;;
3270ed7c580Smrg
3280ed7c580Smrgtcc)
3290ed7c580Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3300ed7c580Smrg  # FIXME: That version still under development at the moment of writing.
3310ed7c580Smrg  #        Make that this statement remains true also for stable, released
3320ed7c580Smrg  #        versions.
3330ed7c580Smrg  # It will wrap lines (doesn't matter whether long or short) with a
3340ed7c580Smrg  # trailing '\', as in:
3350ed7c580Smrg  #
3360ed7c580Smrg  #   foo.o : \
3370ed7c580Smrg  #    foo.c \
3380ed7c580Smrg  #    foo.h \
3390ed7c580Smrg  #
3400ed7c580Smrg  # It will put a trailing '\' even on the last line, and will use leading
3410ed7c580Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3420ed7c580Smrg  # "Emit spaces for -MD").
3430ed7c580Smrg  "$@" -MD -MF "$tmpdepfile"
3440ed7c580Smrg  stat=$?
3450ed7c580Smrg  if test $stat -ne 0; then
3460ed7c580Smrg    rm -f "$tmpdepfile"
3470ed7c580Smrg    exit $stat
3480ed7c580Smrg  fi
3490ed7c580Smrg  rm -f "$depfile"
3500ed7c580Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3510ed7c580Smrg  # We have to change lines of the first kind to '$object: \'.
3520ed7c580Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3530ed7c580Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3540ed7c580Smrg  # dummy dependency, to avoid the deleted-header problem.
3550ed7c580Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3560ed7c580Smrg  rm -f "$tmpdepfile"
3570ed7c580Smrg  ;;
3580ed7c580Smrg
3590ed7c580Smrg## The order of this option in the case statement is important, since the
3600ed7c580Smrg## shell code in configure will try each of these formats in the order
3610ed7c580Smrg## listed in this file.  A plain '-MD' option would be understood by many
3620ed7c580Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3630ed7c580Smrgpgcc)
3640ed7c580Smrg  # Portland's C compiler understands '-MD'.
3650ed7c580Smrg  # Will always output deps to 'file.d' where file is the root name of the
3660ed7c580Smrg  # source file under compilation, even if file resides in a subdirectory.
3670ed7c580Smrg  # The object file name does not affect the name of the '.d' file.
3680ed7c580Smrg  # pgcc 10.2 will output
3690ed7c580Smrg  #    foo.o: sub/foo.c sub/foo.h
3700ed7c580Smrg  # and will wrap long lines using '\' :
3710ed7c580Smrg  #    foo.o: sub/foo.c ... \
3720ed7c580Smrg  #     sub/foo.h ... \
3730ed7c580Smrg  #     ...
3740ed7c580Smrg  set_dir_from "$object"
3750ed7c580Smrg  # Use the source, not the object, to determine the base name, since
3760ed7c580Smrg  # that's sadly what pgcc will do too.
3770ed7c580Smrg  set_base_from "$source"
3780ed7c580Smrg  tmpdepfile=$base.d
3790ed7c580Smrg
3800ed7c580Smrg  # For projects that build the same source file twice into different object
3810ed7c580Smrg  # files, the pgcc approach of using the *source* file root name can cause
3820ed7c580Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3830ed7c580Smrg  # the same $tmpdepfile.
3840ed7c580Smrg  lockdir=$base.d-lock
3850ed7c580Smrg  trap "
3860ed7c580Smrg    echo '$0: caught signal, cleaning up...' >&2
3870ed7c580Smrg    rmdir '$lockdir'
3880ed7c580Smrg    exit 1
3890ed7c580Smrg  " 1 2 13 15
3900ed7c580Smrg  numtries=100
3910ed7c580Smrg  i=$numtries
3920ed7c580Smrg  while test $i -gt 0; do
3930ed7c580Smrg    # mkdir is a portable test-and-set.
3940ed7c580Smrg    if mkdir "$lockdir" 2>/dev/null; then
3950ed7c580Smrg      # This process acquired the lock.
3960ed7c580Smrg      "$@" -MD
3970ed7c580Smrg      stat=$?
3980ed7c580Smrg      # Release the lock.
3990ed7c580Smrg      rmdir "$lockdir"
4000ed7c580Smrg      break
4010ed7c580Smrg    else
4020ed7c580Smrg      # If the lock is being held by a different process, wait
4030ed7c580Smrg      # until the winning process is done or we timeout.
4040ed7c580Smrg      while test -d "$lockdir" && test $i -gt 0; do
4050ed7c580Smrg        sleep 1
4060ed7c580Smrg        i=`expr $i - 1`
4070ed7c580Smrg      done
4080ed7c580Smrg    fi
4090ed7c580Smrg    i=`expr $i - 1`
4100ed7c580Smrg  done
4110ed7c580Smrg  trap - 1 2 13 15
4120ed7c580Smrg  if test $i -le 0; then
4130ed7c580Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4140ed7c580Smrg    echo "$0: check lockdir '$lockdir'" >&2
4150ed7c580Smrg    exit 1
4160ed7c580Smrg  fi
4170ed7c580Smrg
4180ed7c580Smrg  if test $stat -ne 0; then
4190ed7c580Smrg    rm -f "$tmpdepfile"
4200ed7c580Smrg    exit $stat
4210ed7c580Smrg  fi
4220ed7c580Smrg  rm -f "$depfile"
4230ed7c580Smrg  # Each line is of the form `foo.o: dependent.h',
4240ed7c580Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4250ed7c580Smrg  # Do two passes, one to just change these to
4260ed7c580Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4270ed7c580Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4280ed7c580Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4290ed7c580Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
4300ed7c580Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4310ed7c580Smrg    | sed -e 's/$/ :/' >> "$depfile"
4320ed7c580Smrg  rm -f "$tmpdepfile"
4330ed7c580Smrg  ;;
4340ed7c580Smrg
4350ed7c580Smrghp2)
4360ed7c580Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4370ed7c580Smrg  # compilers, which have integrated preprocessors.  The correct option
4380ed7c580Smrg  # to use with these is +Maked; it writes dependencies to a file named
4390ed7c580Smrg  # 'foo.d', which lands next to the object file, wherever that
4400ed7c580Smrg  # happens to be.
4410ed7c580Smrg  # Much of this is similar to the tru64 case; see comments there.
4420ed7c580Smrg  set_dir_from  "$object"
4430ed7c580Smrg  set_base_from "$object"
4440ed7c580Smrg  if test "$libtool" = yes; then
4450ed7c580Smrg    tmpdepfile1=$dir$base.d
4460ed7c580Smrg    tmpdepfile2=$dir.libs/$base.d
4470ed7c580Smrg    "$@" -Wc,+Maked
4480ed7c580Smrg  else
4490ed7c580Smrg    tmpdepfile1=$dir$base.d
4500ed7c580Smrg    tmpdepfile2=$dir$base.d
4510ed7c580Smrg    "$@" +Maked
4520ed7c580Smrg  fi
4530ed7c580Smrg  stat=$?
4540ed7c580Smrg  if test $stat -ne 0; then
4550ed7c580Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4560ed7c580Smrg     exit $stat
4570ed7c580Smrg  fi
4580ed7c580Smrg
4590ed7c580Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4600ed7c580Smrg  do
4610ed7c580Smrg    test -f "$tmpdepfile" && break
4620ed7c580Smrg  done
4630ed7c580Smrg  if test -f "$tmpdepfile"; then
4640ed7c580Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4650ed7c580Smrg    # Add 'dependent.h:' lines.
4660ed7c580Smrg    sed -ne '2,${
4670ed7c580Smrg               s/^ *//
4680ed7c580Smrg               s/ \\*$//
4690ed7c580Smrg               s/$/:/
4700ed7c580Smrg               p
4710ed7c580Smrg             }' "$tmpdepfile" >> "$depfile"
4720ed7c580Smrg  else
4730ed7c580Smrg    make_dummy_depfile
4740ed7c580Smrg  fi
4750ed7c580Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4760ed7c580Smrg  ;;
4770ed7c580Smrg
4780ed7c580Smrgtru64)
4790ed7c580Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4800ed7c580Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4810ed7c580Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4820ed7c580Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4830ed7c580Smrg  # Subdirectories are respected.
4840ed7c580Smrg  set_dir_from  "$object"
4850ed7c580Smrg  set_base_from "$object"
4860ed7c580Smrg
4870ed7c580Smrg  if test "$libtool" = yes; then
4880ed7c580Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4890ed7c580Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4900ed7c580Smrg    # in $dir$base.o.d.  We have to check for both files, because
4910ed7c580Smrg    # one of the two compilations can be disabled.  We should prefer
4920ed7c580Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4930ed7c580Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4940ed7c580Smrg    # the former would cause a distcleancheck panic.
4950ed7c580Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4960ed7c580Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4970ed7c580Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4980ed7c580Smrg    "$@" -Wc,-MD
4990ed7c580Smrg  else
5000ed7c580Smrg    tmpdepfile1=$dir$base.d
5010ed7c580Smrg    tmpdepfile2=$dir$base.d
5020ed7c580Smrg    tmpdepfile3=$dir$base.d
5030ed7c580Smrg    "$@" -MD
5040ed7c580Smrg  fi
5050ed7c580Smrg
5060ed7c580Smrg  stat=$?
5070ed7c580Smrg  if test $stat -ne 0; then
5080ed7c580Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5090ed7c580Smrg    exit $stat
5100ed7c580Smrg  fi
5110ed7c580Smrg
5120ed7c580Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5130ed7c580Smrg  do
5140ed7c580Smrg    test -f "$tmpdepfile" && break
5150ed7c580Smrg  done
5160ed7c580Smrg  # Same post-processing that is required for AIX mode.
5170ed7c580Smrg  aix_post_process_depfile
5180ed7c580Smrg  ;;
5190ed7c580Smrg
5200ed7c580Smrgmsvc7)
5210ed7c580Smrg  if test "$libtool" = yes; then
5220ed7c580Smrg    showIncludes=-Wc,-showIncludes
5230ed7c580Smrg  else
5240ed7c580Smrg    showIncludes=-showIncludes
5250ed7c580Smrg  fi
5260ed7c580Smrg  "$@" $showIncludes > "$tmpdepfile"
5270ed7c580Smrg  stat=$?
5280ed7c580Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5290ed7c580Smrg  if test $stat -ne 0; then
5300ed7c580Smrg    rm -f "$tmpdepfile"
5310ed7c580Smrg    exit $stat
5320ed7c580Smrg  fi
5330ed7c580Smrg  rm -f "$depfile"
5340ed7c580Smrg  echo "$object : \\" > "$depfile"
5350ed7c580Smrg  # The first sed program below extracts the file names and escapes
5360ed7c580Smrg  # backslashes for cygpath.  The second sed program outputs the file
5370ed7c580Smrg  # name when reading, but also accumulates all include files in the
5380ed7c580Smrg  # hold buffer in order to output them again at the end.  This only
5390ed7c580Smrg  # works with sed implementations that can handle large buffers.
5400ed7c580Smrg  sed < "$tmpdepfile" -n '
5410ed7c580Smrg/^Note: including file:  *\(.*\)/ {
5420ed7c580Smrg  s//\1/
5430ed7c580Smrg  s/\\/\\\\/g
5440ed7c580Smrg  p
5450ed7c580Smrg}' | $cygpath_u | sort -u | sed -n '
5460ed7c580Smrgs/ /\\ /g
5470ed7c580Smrgs/\(.*\)/'"$tab"'\1 \\/p
5480ed7c580Smrgs/.\(.*\) \\/\1:/
5490ed7c580SmrgH
5500ed7c580Smrg$ {
5510ed7c580Smrg  s/.*/'"$tab"'/
5520ed7c580Smrg  G
5530ed7c580Smrg  p
5540ed7c580Smrg}' >> "$depfile"
5550ed7c580Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5560ed7c580Smrg  rm -f "$tmpdepfile"
5570ed7c580Smrg  ;;
5580ed7c580Smrg
5590ed7c580Smrgmsvc7msys)
5600ed7c580Smrg  # This case exists only to let depend.m4 do its work.  It works by
5610ed7c580Smrg  # looking at the text of this script.  This case will never be run,
5620ed7c580Smrg  # since it is checked for above.
5630ed7c580Smrg  exit 1
5640ed7c580Smrg  ;;
5650ed7c580Smrg
5660ed7c580Smrg#nosideeffect)
5670ed7c580Smrg  # This comment above is used by automake to tell side-effect
5680ed7c580Smrg  # dependency tracking mechanisms from slower ones.
5690ed7c580Smrg
5700ed7c580Smrgdashmstdout)
5710ed7c580Smrg  # Important note: in order to support this mode, a compiler *must*
5720ed7c580Smrg  # always write the preprocessed file to stdout, regardless of -o.
5730ed7c580Smrg  "$@" || exit $?
5740ed7c580Smrg
5750ed7c580Smrg  # Remove the call to Libtool.
5760ed7c580Smrg  if test "$libtool" = yes; then
5770ed7c580Smrg    while test "X$1" != 'X--mode=compile'; do
5780ed7c580Smrg      shift
5790ed7c580Smrg    done
5800ed7c580Smrg    shift
5810ed7c580Smrg  fi
5820ed7c580Smrg
5830ed7c580Smrg  # Remove '-o $object'.
5840ed7c580Smrg  IFS=" "
5850ed7c580Smrg  for arg
5860ed7c580Smrg  do
5870ed7c580Smrg    case $arg in
5880ed7c580Smrg    -o)
5890ed7c580Smrg      shift
5900ed7c580Smrg      ;;
5910ed7c580Smrg    $object)
5920ed7c580Smrg      shift
5930ed7c580Smrg      ;;
5940ed7c580Smrg    *)
5950ed7c580Smrg      set fnord "$@" "$arg"
5960ed7c580Smrg      shift # fnord
5970ed7c580Smrg      shift # $arg
5980ed7c580Smrg      ;;
5990ed7c580Smrg    esac
6000ed7c580Smrg  done
6010ed7c580Smrg
6020ed7c580Smrg  test -z "$dashmflag" && dashmflag=-M
6030ed7c580Smrg  # Require at least two characters before searching for ':'
6040ed7c580Smrg  # in the target name.  This is to cope with DOS-style filenames:
6050ed7c580Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6060ed7c580Smrg  "$@" $dashmflag |
6070ed7c580Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6080ed7c580Smrg  rm -f "$depfile"
6090ed7c580Smrg  cat < "$tmpdepfile" > "$depfile"
6100ed7c580Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6110ed7c580Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6120ed7c580Smrg  tr ' ' "$nl" < "$tmpdepfile" \
6130ed7c580Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6140ed7c580Smrg    | sed -e 's/$/ :/' >> "$depfile"
6150ed7c580Smrg  rm -f "$tmpdepfile"
6160ed7c580Smrg  ;;
6170ed7c580Smrg
6180ed7c580SmrgdashXmstdout)
6190ed7c580Smrg  # This case only exists to satisfy depend.m4.  It is never actually
6200ed7c580Smrg  # run, as this mode is specially recognized in the preamble.
6210ed7c580Smrg  exit 1
6220ed7c580Smrg  ;;
6230ed7c580Smrg
6240ed7c580Smrgmakedepend)
6250ed7c580Smrg  "$@" || exit $?
6260ed7c580Smrg  # Remove any Libtool call
6270ed7c580Smrg  if test "$libtool" = yes; then
6280ed7c580Smrg    while test "X$1" != 'X--mode=compile'; do
6290ed7c580Smrg      shift
6300ed7c580Smrg    done
6310ed7c580Smrg    shift
6320ed7c580Smrg  fi
6330ed7c580Smrg  # X makedepend
6340ed7c580Smrg  shift
6350ed7c580Smrg  cleared=no eat=no
6360ed7c580Smrg  for arg
6370ed7c580Smrg  do
6380ed7c580Smrg    case $cleared in
6390ed7c580Smrg    no)
6400ed7c580Smrg      set ""; shift
6410ed7c580Smrg      cleared=yes ;;
6420ed7c580Smrg    esac
6430ed7c580Smrg    if test $eat = yes; then
6440ed7c580Smrg      eat=no
6450ed7c580Smrg      continue
6460ed7c580Smrg    fi
6470ed7c580Smrg    case "$arg" in
6480ed7c580Smrg    -D*|-I*)
6490ed7c580Smrg      set fnord "$@" "$arg"; shift ;;
6500ed7c580Smrg    # Strip any option that makedepend may not understand.  Remove
6510ed7c580Smrg    # the object too, otherwise makedepend will parse it as a source file.
6520ed7c580Smrg    -arch)
6530ed7c580Smrg      eat=yes ;;
6540ed7c580Smrg    -*|$object)
6550ed7c580Smrg      ;;
6560ed7c580Smrg    *)
6570ed7c580Smrg      set fnord "$@" "$arg"; shift ;;
6580ed7c580Smrg    esac
6590ed7c580Smrg  done
6600ed7c580Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6610ed7c580Smrg  touch "$tmpdepfile"
6620ed7c580Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6630ed7c580Smrg  rm -f "$depfile"
6640ed7c580Smrg  # makedepend may prepend the VPATH from the source file name to the object.
6650ed7c580Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6660ed7c580Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6670ed7c580Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6680ed7c580Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6690ed7c580Smrg  sed '1,2d' "$tmpdepfile" \
6700ed7c580Smrg    | tr ' ' "$nl" \
6710ed7c580Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6720ed7c580Smrg    | sed -e 's/$/ :/' >> "$depfile"
6730ed7c580Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6740ed7c580Smrg  ;;
6750ed7c580Smrg
6760ed7c580Smrgcpp)
6770ed7c580Smrg  # Important note: in order to support this mode, a compiler *must*
6780ed7c580Smrg  # always write the preprocessed file to stdout.
6790ed7c580Smrg  "$@" || exit $?
6800ed7c580Smrg
6810ed7c580Smrg  # Remove the call to Libtool.
6820ed7c580Smrg  if test "$libtool" = yes; then
6830ed7c580Smrg    while test "X$1" != 'X--mode=compile'; do
6840ed7c580Smrg      shift
6850ed7c580Smrg    done
6860ed7c580Smrg    shift
6870ed7c580Smrg  fi
6880ed7c580Smrg
6890ed7c580Smrg  # Remove '-o $object'.
6900ed7c580Smrg  IFS=" "
6910ed7c580Smrg  for arg
6920ed7c580Smrg  do
6930ed7c580Smrg    case $arg in
6940ed7c580Smrg    -o)
6950ed7c580Smrg      shift
6960ed7c580Smrg      ;;
6970ed7c580Smrg    $object)
6980ed7c580Smrg      shift
6990ed7c580Smrg      ;;
7000ed7c580Smrg    *)
7010ed7c580Smrg      set fnord "$@" "$arg"
7020ed7c580Smrg      shift # fnord
7030ed7c580Smrg      shift # $arg
7040ed7c580Smrg      ;;
7050ed7c580Smrg    esac
7060ed7c580Smrg  done
7070ed7c580Smrg
7080ed7c580Smrg  "$@" -E \
7090ed7c580Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7100ed7c580Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7110ed7c580Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
7120ed7c580Smrg  rm -f "$depfile"
7130ed7c580Smrg  echo "$object : \\" > "$depfile"
7140ed7c580Smrg  cat < "$tmpdepfile" >> "$depfile"
7150ed7c580Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7160ed7c580Smrg  rm -f "$tmpdepfile"
7170ed7c580Smrg  ;;
7180ed7c580Smrg
7190ed7c580Smrgmsvisualcpp)
7200ed7c580Smrg  # Important note: in order to support this mode, a compiler *must*
7210ed7c580Smrg  # always write the preprocessed file to stdout.
7220ed7c580Smrg  "$@" || exit $?
7230ed7c580Smrg
7240ed7c580Smrg  # Remove the call to Libtool.
7250ed7c580Smrg  if test "$libtool" = yes; then
7260ed7c580Smrg    while test "X$1" != 'X--mode=compile'; do
7270ed7c580Smrg      shift
7280ed7c580Smrg    done
7290ed7c580Smrg    shift
7300ed7c580Smrg  fi
7310ed7c580Smrg
7320ed7c580Smrg  IFS=" "
7330ed7c580Smrg  for arg
7340ed7c580Smrg  do
7350ed7c580Smrg    case "$arg" in
7360ed7c580Smrg    -o)
7370ed7c580Smrg      shift
7380ed7c580Smrg      ;;
7390ed7c580Smrg    $object)
7400ed7c580Smrg      shift
7410ed7c580Smrg      ;;
7420ed7c580Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7430ed7c580Smrg        set fnord "$@"
7440ed7c580Smrg        shift
7450ed7c580Smrg        shift
7460ed7c580Smrg        ;;
7470ed7c580Smrg    *)
7480ed7c580Smrg        set fnord "$@" "$arg"
7490ed7c580Smrg        shift
7500ed7c580Smrg        shift
7510ed7c580Smrg        ;;
7520ed7c580Smrg    esac
7530ed7c580Smrg  done
7540ed7c580Smrg  "$@" -E 2>/dev/null |
7550ed7c580Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7560ed7c580Smrg  rm -f "$depfile"
7570ed7c580Smrg  echo "$object : \\" > "$depfile"
7580ed7c580Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7590ed7c580Smrg  echo "$tab" >> "$depfile"
7600ed7c580Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7610ed7c580Smrg  rm -f "$tmpdepfile"
7620ed7c580Smrg  ;;
7630ed7c580Smrg
7640ed7c580Smrgmsvcmsys)
7650ed7c580Smrg  # This case exists only to let depend.m4 do its work.  It works by
7660ed7c580Smrg  # looking at the text of this script.  This case will never be run,
7670ed7c580Smrg  # since it is checked for above.
7680ed7c580Smrg  exit 1
7690ed7c580Smrg  ;;
7700ed7c580Smrg
7710ed7c580Smrgnone)
7720ed7c580Smrg  exec "$@"
7730ed7c580Smrg  ;;
7740ed7c580Smrg
7750ed7c580Smrg*)
7760ed7c580Smrg  echo "Unknown depmode $depmode" 1>&2
7770ed7c580Smrg  exit 1
7780ed7c580Smrg  ;;
7790ed7c580Smrgesac
7800ed7c580Smrg
7810ed7c580Smrgexit 0
7820ed7c580Smrg
7830ed7c580Smrg# Local Variables:
7840ed7c580Smrg# mode: shell-script
7850ed7c580Smrg# sh-indentation: 2
7860ed7c580Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
7870ed7c580Smrg# time-stamp-start: "scriptversion="
7880ed7c580Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7890ed7c580Smrg# time-stamp-time-zone: "UTC"
7900ed7c580Smrg# time-stamp-end: "; # UTC"
7910ed7c580Smrg# End:
792