depcomp revision 9384b2f3
1966bf024Smrg#! /bin/sh
2966bf024Smrg# depcomp - compile a program generating dependencies as side-effects
39384b2f3Smrg
49384b2f3Smrgscriptversion=2012-10-18.11; # UTC
59384b2f3Smrg
69384b2f3Smrg# Copyright (C) 1999-2013 Free Software Foundation, Inc.
7966bf024Smrg
8966bf024Smrg# This program is free software; you can redistribute it and/or modify
9966bf024Smrg# it under the terms of the GNU General Public License as published by
10966bf024Smrg# the Free Software Foundation; either version 2, or (at your option)
11966bf024Smrg# any later version.
12966bf024Smrg
13966bf024Smrg# This program is distributed in the hope that it will be useful,
14966bf024Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15966bf024Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16966bf024Smrg# GNU General Public License for more details.
17966bf024Smrg
18966bf024Smrg# You should have received a copy of the GNU General Public License
199384b2f3Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20966bf024Smrg
21966bf024Smrg# As a special exception to the GNU General Public License, if you
22966bf024Smrg# distribute this file as part of a program that contains a
23966bf024Smrg# configuration script generated by Autoconf, you may include it under
24966bf024Smrg# the same distribution terms that you use for the rest of that program.
25966bf024Smrg
26966bf024Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27966bf024Smrg
289384b2f3Smrgcase $1 in
299384b2f3Smrg  '')
309384b2f3Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
319384b2f3Smrg    exit 1;
329384b2f3Smrg    ;;
339384b2f3Smrg  -h | --h*)
349384b2f3Smrg    cat <<\EOF
359384b2f3SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
369384b2f3Smrg
379384b2f3SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
389384b2f3Smrgas side-effects.
399384b2f3Smrg
409384b2f3SmrgEnvironment variables:
419384b2f3Smrg  depmode     Dependency tracking mode.
429384b2f3Smrg  source      Source file read by 'PROGRAMS ARGS'.
439384b2f3Smrg  object      Object file output by 'PROGRAMS ARGS'.
449384b2f3Smrg  DEPDIR      directory where to store dependencies.
459384b2f3Smrg  depfile     Dependency file to output.
469384b2f3Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
479384b2f3Smrg  libtool     Whether libtool is used (yes/no).
489384b2f3Smrg
499384b2f3SmrgReport bugs to <bug-automake@gnu.org>.
509384b2f3SmrgEOF
519384b2f3Smrg    exit $?
529384b2f3Smrg    ;;
539384b2f3Smrg  -v | --v*)
549384b2f3Smrg    echo "depcomp $scriptversion"
559384b2f3Smrg    exit $?
569384b2f3Smrg    ;;
579384b2f3Smrgesac
589384b2f3Smrg
599384b2f3Smrg# Get the directory component of the given path, and save it in the
609384b2f3Smrg# global variables '$dir'.  Note that this directory component will
619384b2f3Smrg# be either empty or ending with a '/' character.  This is deliberate.
629384b2f3Smrgset_dir_from ()
639384b2f3Smrg{
649384b2f3Smrg  case $1 in
659384b2f3Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
669384b2f3Smrg      *) dir=;;
679384b2f3Smrg  esac
689384b2f3Smrg}
699384b2f3Smrg
709384b2f3Smrg# Get the suffix-stripped basename of the given path, and save it the
719384b2f3Smrg# global variable '$base'.
729384b2f3Smrgset_base_from ()
739384b2f3Smrg{
749384b2f3Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
759384b2f3Smrg}
769384b2f3Smrg
779384b2f3Smrg# If no dependency file was actually created by the compiler invocation,
789384b2f3Smrg# we still have to create a dummy depfile, to avoid errors with the
799384b2f3Smrg# Makefile "include basename.Plo" scheme.
809384b2f3Smrgmake_dummy_depfile ()
819384b2f3Smrg{
829384b2f3Smrg  echo "#dummy" > "$depfile"
839384b2f3Smrg}
849384b2f3Smrg
859384b2f3Smrg# Factor out some common post-processing of the generated depfile.
869384b2f3Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
879384b2f3Smrgaix_post_process_depfile ()
889384b2f3Smrg{
899384b2f3Smrg  # If the compiler actually managed to produce a dependency file,
909384b2f3Smrg  # post-process it.
919384b2f3Smrg  if test -f "$tmpdepfile"; then
929384b2f3Smrg    # Each line is of the form 'foo.o: dependency.h'.
939384b2f3Smrg    # Do two passes, one to just change these to
949384b2f3Smrg    #   $object: dependency.h
959384b2f3Smrg    # and one to simply output
969384b2f3Smrg    #   dependency.h:
979384b2f3Smrg    # which is needed to avoid the deleted-header problem.
989384b2f3Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
999384b2f3Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1009384b2f3Smrg    } > "$depfile"
1019384b2f3Smrg    rm -f "$tmpdepfile"
1029384b2f3Smrg  else
1039384b2f3Smrg    make_dummy_depfile
1049384b2f3Smrg  fi
1059384b2f3Smrg}
1069384b2f3Smrg
1079384b2f3Smrg# A tabulation character.
1089384b2f3Smrgtab='	'
1099384b2f3Smrg# A newline character.
1109384b2f3Smrgnl='
1119384b2f3Smrg'
1129384b2f3Smrg# Character ranges might be problematic outside the C locale.
1139384b2f3Smrg# These definitions help.
1149384b2f3Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1159384b2f3Smrglower=abcdefghijklmnopqrstuvwxyz
1169384b2f3Smrgdigits=0123456789
1179384b2f3Smrgalpha=${upper}${lower}
1189384b2f3Smrg
119966bf024Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120966bf024Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121966bf024Smrg  exit 1
122966bf024Smrgfi
123966bf024Smrg
1249384b2f3Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1259384b2f3Smrgdepfile=${depfile-`echo "$object" |
1269384b2f3Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127966bf024Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128966bf024Smrg
129966bf024Smrgrm -f "$tmpdepfile"
130966bf024Smrg
1319384b2f3Smrg# Avoid interferences from the environment.
1329384b2f3Smrggccflag= dashmflag=
1339384b2f3Smrg
134966bf024Smrg# Some modes work just like other modes, but use different flags.  We
135966bf024Smrg# parameterize here, but still list the modes in the big case below,
136966bf024Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137966bf024Smrg# here, because this file can only contain one case statement.
138966bf024Smrgif test "$depmode" = hp; then
139966bf024Smrg  # HP compiler uses -M and no extra arg.
140966bf024Smrg  gccflag=-M
141966bf024Smrg  depmode=gcc
142966bf024Smrgfi
143966bf024Smrg
144966bf024Smrgif test "$depmode" = dashXmstdout; then
1459384b2f3Smrg  # This is just like dashmstdout with a different argument.
1469384b2f3Smrg  dashmflag=-xM
1479384b2f3Smrg  depmode=dashmstdout
1489384b2f3Smrgfi
1499384b2f3Smrg
1509384b2f3Smrgcygpath_u="cygpath -u -f -"
1519384b2f3Smrgif test "$depmode" = msvcmsys; then
1529384b2f3Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1539384b2f3Smrg  # Just convert the backslash-escaped backslashes to single forward
1549384b2f3Smrg  # slashes to satisfy depend.m4
1559384b2f3Smrg  cygpath_u='sed s,\\\\,/,g'
1569384b2f3Smrg  depmode=msvisualcpp
1579384b2f3Smrgfi
1589384b2f3Smrg
1599384b2f3Smrgif test "$depmode" = msvc7msys; then
1609384b2f3Smrg  # This is just like msvc7 but w/o cygpath translation.
1619384b2f3Smrg  # Just convert the backslash-escaped backslashes to single forward
1629384b2f3Smrg  # slashes to satisfy depend.m4
1639384b2f3Smrg  cygpath_u='sed s,\\\\,/,g'
1649384b2f3Smrg  depmode=msvc7
1659384b2f3Smrgfi
1669384b2f3Smrg
1679384b2f3Smrgif test "$depmode" = xlc; then
1689384b2f3Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1699384b2f3Smrg  gccflag=-qmakedep=gcc,-MF
1709384b2f3Smrg  depmode=gcc
171966bf024Smrgfi
172966bf024Smrg
173966bf024Smrgcase "$depmode" in
174966bf024Smrggcc3)
175966bf024Smrg## gcc 3 implements dependency tracking that does exactly what
176966bf024Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177966bf024Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1789384b2f3Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1799384b2f3Smrg## the command line argument order; so add the flags where they
1809384b2f3Smrg## appear in depend2.am.  Note that the slowdown incurred here
1819384b2f3Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1829384b2f3Smrg  for arg
1839384b2f3Smrg  do
1849384b2f3Smrg    case $arg in
1859384b2f3Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1869384b2f3Smrg    *)  set fnord "$@" "$arg" ;;
1879384b2f3Smrg    esac
1889384b2f3Smrg    shift # fnord
1899384b2f3Smrg    shift # $arg
1909384b2f3Smrg  done
1919384b2f3Smrg  "$@"
192966bf024Smrg  stat=$?
1939384b2f3Smrg  if test $stat -ne 0; then
194966bf024Smrg    rm -f "$tmpdepfile"
195966bf024Smrg    exit $stat
196966bf024Smrg  fi
197966bf024Smrg  mv "$tmpdepfile" "$depfile"
198966bf024Smrg  ;;
199966bf024Smrg
200966bf024Smrggcc)
2019384b2f3Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2029384b2f3Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2039384b2f3Smrg## (see the conditional assignment to $gccflag above).
204966bf024Smrg## There are various ways to get dependency output from gcc.  Here's
205966bf024Smrg## why we pick this rather obscure method:
206966bf024Smrg## - Don't want to use -MD because we'd like the dependencies to end
207966bf024Smrg##   up in a subdir.  Having to rename by hand is ugly.
208966bf024Smrg##   (We might end up doing this anyway to support other compilers.)
209966bf024Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2109384b2f3Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2119384b2f3Smrg##   supported by the other compilers which use the 'gcc' depmode.
212966bf024Smrg## - Using -M directly means running the compiler twice (even worse
213966bf024Smrg##   than renaming).
214966bf024Smrg  if test -z "$gccflag"; then
215966bf024Smrg    gccflag=-MD,
216966bf024Smrg  fi
217966bf024Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
218966bf024Smrg  stat=$?
2199384b2f3Smrg  if test $stat -ne 0; then
220966bf024Smrg    rm -f "$tmpdepfile"
221966bf024Smrg    exit $stat
222966bf024Smrg  fi
223966bf024Smrg  rm -f "$depfile"
224966bf024Smrg  echo "$object : \\" > "$depfile"
2259384b2f3Smrg  # The second -e expression handles DOS-style file names with drive
2269384b2f3Smrg  # letters.
227966bf024Smrg  sed -e 's/^[^:]*: / /' \
228966bf024Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2299384b2f3Smrg## This next piece of magic avoids the "deleted header file" problem.
230966bf024Smrg## The problem is that when a header file which appears in a .P file
231966bf024Smrg## is deleted, the dependency causes make to die (because there is
232966bf024Smrg## typically no way to rebuild the header).  We avoid this by adding
233966bf024Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234966bf024Smrg## this for us directly.
2359384b2f3Smrg## Some versions of gcc put a space before the ':'.  On the theory
236966bf024Smrg## that the space means something, we add a space to the output as
2379384b2f3Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2389384b2f3Smrg## to the object.  Take care to not repeat it in the output.
239966bf024Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
240966bf024Smrg## correctly.  Breaking it into two sed invocations is a workaround.
2419384b2f3Smrg  tr ' ' "$nl" < "$tmpdepfile" \
2429384b2f3Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2439384b2f3Smrg    | sed -e 's/$/ :/' >> "$depfile"
244966bf024Smrg  rm -f "$tmpdepfile"
245966bf024Smrg  ;;
246966bf024Smrg
247966bf024Smrghp)
248966bf024Smrg  # This case exists only to let depend.m4 do its work.  It works by
249966bf024Smrg  # looking at the text of this script.  This case will never be run,
250966bf024Smrg  # since it is checked for above.
251966bf024Smrg  exit 1
252966bf024Smrg  ;;
253966bf024Smrg
254966bf024Smrgsgi)
255966bf024Smrg  if test "$libtool" = yes; then
256966bf024Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257966bf024Smrg  else
258966bf024Smrg    "$@" -MDupdate "$tmpdepfile"
259966bf024Smrg  fi
260966bf024Smrg  stat=$?
2619384b2f3Smrg  if test $stat -ne 0; then
262966bf024Smrg    rm -f "$tmpdepfile"
263966bf024Smrg    exit $stat
264966bf024Smrg  fi
265966bf024Smrg  rm -f "$depfile"
266966bf024Smrg
267966bf024Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268966bf024Smrg    echo "$object : \\" > "$depfile"
269966bf024Smrg    # Clip off the initial element (the dependent).  Don't try to be
270966bf024Smrg    # clever and replace this with sed code, as IRIX sed won't handle
271966bf024Smrg    # lines with more than a fixed number of characters (4096 in
272966bf024Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2739384b2f3Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
274966bf024Smrg    # dependency line.
2759384b2f3Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2769384b2f3Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2779384b2f3Smrg      | tr "$nl" ' ' >> "$depfile"
2789384b2f3Smrg    echo >> "$depfile"
279966bf024Smrg    # The second pass generates a dummy entry for each header file.
2809384b2f3Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2819384b2f3Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2829384b2f3Smrg      >> "$depfile"
283966bf024Smrg  else
2849384b2f3Smrg    make_dummy_depfile
285966bf024Smrg  fi
286966bf024Smrg  rm -f "$tmpdepfile"
287966bf024Smrg  ;;
288966bf024Smrg
2899384b2f3Smrgxlc)
2909384b2f3Smrg  # This case exists only to let depend.m4 do its work.  It works by
2919384b2f3Smrg  # looking at the text of this script.  This case will never be run,
2929384b2f3Smrg  # since it is checked for above.
2939384b2f3Smrg  exit 1
2949384b2f3Smrg  ;;
2959384b2f3Smrg
296966bf024Smrgaix)
297966bf024Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
298966bf024Smrg  # in a .u file.  In older versions, this file always lives in the
2999384b2f3Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300966bf024Smrg  # start of each line; $object doesn't have directory information.
301966bf024Smrg  # Version 6 uses the directory in both cases.
3029384b2f3Smrg  set_dir_from "$object"
3039384b2f3Smrg  set_base_from "$object"
304966bf024Smrg  if test "$libtool" = yes; then
3059384b2f3Smrg    tmpdepfile1=$dir$base.u
3069384b2f3Smrg    tmpdepfile2=$base.u
3079384b2f3Smrg    tmpdepfile3=$dir.libs/$base.u
308966bf024Smrg    "$@" -Wc,-M
309966bf024Smrg  else
3109384b2f3Smrg    tmpdepfile1=$dir$base.u
3119384b2f3Smrg    tmpdepfile2=$dir$base.u
3129384b2f3Smrg    tmpdepfile3=$dir$base.u
313966bf024Smrg    "$@" -M
314966bf024Smrg  fi
315966bf024Smrg  stat=$?
3169384b2f3Smrg  if test $stat -ne 0; then
3179384b2f3Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3189384b2f3Smrg    exit $stat
319966bf024Smrg  fi
320966bf024Smrg
3219384b2f3Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3229384b2f3Smrg  do
3239384b2f3Smrg    test -f "$tmpdepfile" && break
3249384b2f3Smrg  done
3259384b2f3Smrg  aix_post_process_depfile
3269384b2f3Smrg  ;;
3279384b2f3Smrg
3289384b2f3Smrgtcc)
3299384b2f3Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3309384b2f3Smrg  # FIXME: That version still under development at the moment of writing.
3319384b2f3Smrg  #        Make that this statement remains true also for stable, released
3329384b2f3Smrg  #        versions.
3339384b2f3Smrg  # It will wrap lines (doesn't matter whether long or short) with a
3349384b2f3Smrg  # trailing '\', as in:
3359384b2f3Smrg  #
3369384b2f3Smrg  #   foo.o : \
3379384b2f3Smrg  #    foo.c \
3389384b2f3Smrg  #    foo.h \
3399384b2f3Smrg  #
3409384b2f3Smrg  # It will put a trailing '\' even on the last line, and will use leading
3419384b2f3Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3429384b2f3Smrg  # "Emit spaces for -MD").
3439384b2f3Smrg  "$@" -MD -MF "$tmpdepfile"
3449384b2f3Smrg  stat=$?
3459384b2f3Smrg  if test $stat -ne 0; then
346966bf024Smrg    rm -f "$tmpdepfile"
347966bf024Smrg    exit $stat
348966bf024Smrg  fi
3499384b2f3Smrg  rm -f "$depfile"
3509384b2f3Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3519384b2f3Smrg  # We have to change lines of the first kind to '$object: \'.
3529384b2f3Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3539384b2f3Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3549384b2f3Smrg  # dummy dependency, to avoid the deleted-header problem.
3559384b2f3Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356966bf024Smrg  rm -f "$tmpdepfile"
357966bf024Smrg  ;;
358966bf024Smrg
3599384b2f3Smrg## The order of this option in the case statement is important, since the
3609384b2f3Smrg## shell code in configure will try each of these formats in the order
3619384b2f3Smrg## listed in this file.  A plain '-MD' option would be understood by many
3629384b2f3Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3639384b2f3Smrgpgcc)
3649384b2f3Smrg  # Portland's C compiler understands '-MD'.
3659384b2f3Smrg  # Will always output deps to 'file.d' where file is the root name of the
3669384b2f3Smrg  # source file under compilation, even if file resides in a subdirectory.
3679384b2f3Smrg  # The object file name does not affect the name of the '.d' file.
3689384b2f3Smrg  # pgcc 10.2 will output
369966bf024Smrg  #    foo.o: sub/foo.c sub/foo.h
3709384b2f3Smrg  # and will wrap long lines using '\' :
371966bf024Smrg  #    foo.o: sub/foo.c ... \
372966bf024Smrg  #     sub/foo.h ... \
373966bf024Smrg  #     ...
3749384b2f3Smrg  set_dir_from "$object"
3759384b2f3Smrg  # Use the source, not the object, to determine the base name, since
3769384b2f3Smrg  # that's sadly what pgcc will do too.
3779384b2f3Smrg  set_base_from "$source"
3789384b2f3Smrg  tmpdepfile=$base.d
3799384b2f3Smrg
3809384b2f3Smrg  # For projects that build the same source file twice into different object
3819384b2f3Smrg  # files, the pgcc approach of using the *source* file root name can cause
3829384b2f3Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3839384b2f3Smrg  # the same $tmpdepfile.
3849384b2f3Smrg  lockdir=$base.d-lock
3859384b2f3Smrg  trap "
3869384b2f3Smrg    echo '$0: caught signal, cleaning up...' >&2
3879384b2f3Smrg    rmdir '$lockdir'
3889384b2f3Smrg    exit 1
3899384b2f3Smrg  " 1 2 13 15
3909384b2f3Smrg  numtries=100
3919384b2f3Smrg  i=$numtries
3929384b2f3Smrg  while test $i -gt 0; do
3939384b2f3Smrg    # mkdir is a portable test-and-set.
3949384b2f3Smrg    if mkdir "$lockdir" 2>/dev/null; then
3959384b2f3Smrg      # This process acquired the lock.
3969384b2f3Smrg      "$@" -MD
3979384b2f3Smrg      stat=$?
3989384b2f3Smrg      # Release the lock.
3999384b2f3Smrg      rmdir "$lockdir"
4009384b2f3Smrg      break
4019384b2f3Smrg    else
4029384b2f3Smrg      # If the lock is being held by a different process, wait
4039384b2f3Smrg      # until the winning process is done or we timeout.
4049384b2f3Smrg      while test -d "$lockdir" && test $i -gt 0; do
4059384b2f3Smrg        sleep 1
4069384b2f3Smrg        i=`expr $i - 1`
4079384b2f3Smrg      done
4089384b2f3Smrg    fi
4099384b2f3Smrg    i=`expr $i - 1`
4109384b2f3Smrg  done
4119384b2f3Smrg  trap - 1 2 13 15
4129384b2f3Smrg  if test $i -le 0; then
4139384b2f3Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4149384b2f3Smrg    echo "$0: check lockdir '$lockdir'" >&2
4159384b2f3Smrg    exit 1
4169384b2f3Smrg  fi
417966bf024Smrg
4189384b2f3Smrg  if test $stat -ne 0; then
419966bf024Smrg    rm -f "$tmpdepfile"
420966bf024Smrg    exit $stat
421966bf024Smrg  fi
422966bf024Smrg  rm -f "$depfile"
423966bf024Smrg  # Each line is of the form `foo.o: dependent.h',
424966bf024Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425966bf024Smrg  # Do two passes, one to just change these to
426966bf024Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427966bf024Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428966bf024Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429966bf024Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
4309384b2f3Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4319384b2f3Smrg    | sed -e 's/$/ :/' >> "$depfile"
432966bf024Smrg  rm -f "$tmpdepfile"
433966bf024Smrg  ;;
434966bf024Smrg
4359384b2f3Smrghp2)
4369384b2f3Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4379384b2f3Smrg  # compilers, which have integrated preprocessors.  The correct option
4389384b2f3Smrg  # to use with these is +Maked; it writes dependencies to a file named
4399384b2f3Smrg  # 'foo.d', which lands next to the object file, wherever that
4409384b2f3Smrg  # happens to be.
4419384b2f3Smrg  # Much of this is similar to the tru64 case; see comments there.
4429384b2f3Smrg  set_dir_from  "$object"
4439384b2f3Smrg  set_base_from "$object"
4449384b2f3Smrg  if test "$libtool" = yes; then
4459384b2f3Smrg    tmpdepfile1=$dir$base.d
4469384b2f3Smrg    tmpdepfile2=$dir.libs/$base.d
4479384b2f3Smrg    "$@" -Wc,+Maked
4489384b2f3Smrg  else
4499384b2f3Smrg    tmpdepfile1=$dir$base.d
4509384b2f3Smrg    tmpdepfile2=$dir$base.d
4519384b2f3Smrg    "$@" +Maked
4529384b2f3Smrg  fi
4539384b2f3Smrg  stat=$?
4549384b2f3Smrg  if test $stat -ne 0; then
4559384b2f3Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4569384b2f3Smrg     exit $stat
4579384b2f3Smrg  fi
4589384b2f3Smrg
4599384b2f3Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4609384b2f3Smrg  do
4619384b2f3Smrg    test -f "$tmpdepfile" && break
4629384b2f3Smrg  done
4639384b2f3Smrg  if test -f "$tmpdepfile"; then
4649384b2f3Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4659384b2f3Smrg    # Add 'dependent.h:' lines.
4669384b2f3Smrg    sed -ne '2,${
4679384b2f3Smrg               s/^ *//
4689384b2f3Smrg               s/ \\*$//
4699384b2f3Smrg               s/$/:/
4709384b2f3Smrg               p
4719384b2f3Smrg             }' "$tmpdepfile" >> "$depfile"
4729384b2f3Smrg  else
4739384b2f3Smrg    make_dummy_depfile
4749384b2f3Smrg  fi
4759384b2f3Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4769384b2f3Smrg  ;;
4779384b2f3Smrg
478966bf024Smrgtru64)
4799384b2f3Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4809384b2f3Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4819384b2f3Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4829384b2f3Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4839384b2f3Smrg  # Subdirectories are respected.
4849384b2f3Smrg  set_dir_from  "$object"
4859384b2f3Smrg  set_base_from "$object"
4869384b2f3Smrg
4879384b2f3Smrg  if test "$libtool" = yes; then
4889384b2f3Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4899384b2f3Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4909384b2f3Smrg    # in $dir$base.o.d.  We have to check for both files, because
4919384b2f3Smrg    # one of the two compilations can be disabled.  We should prefer
4929384b2f3Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4939384b2f3Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4949384b2f3Smrg    # the former would cause a distcleancheck panic.
4959384b2f3Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4969384b2f3Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4979384b2f3Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4989384b2f3Smrg    "$@" -Wc,-MD
4999384b2f3Smrg  else
5009384b2f3Smrg    tmpdepfile1=$dir$base.d
5019384b2f3Smrg    tmpdepfile2=$dir$base.d
5029384b2f3Smrg    tmpdepfile3=$dir$base.d
5039384b2f3Smrg    "$@" -MD
5049384b2f3Smrg  fi
5059384b2f3Smrg
5069384b2f3Smrg  stat=$?
5079384b2f3Smrg  if test $stat -ne 0; then
5089384b2f3Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5099384b2f3Smrg    exit $stat
5109384b2f3Smrg  fi
5119384b2f3Smrg
5129384b2f3Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5139384b2f3Smrg  do
5149384b2f3Smrg    test -f "$tmpdepfile" && break
5159384b2f3Smrg  done
5169384b2f3Smrg  # Same post-processing that is required for AIX mode.
5179384b2f3Smrg  aix_post_process_depfile
5189384b2f3Smrg  ;;
5199384b2f3Smrg
5209384b2f3Smrgmsvc7)
5219384b2f3Smrg  if test "$libtool" = yes; then
5229384b2f3Smrg    showIncludes=-Wc,-showIncludes
5239384b2f3Smrg  else
5249384b2f3Smrg    showIncludes=-showIncludes
5259384b2f3Smrg  fi
5269384b2f3Smrg  "$@" $showIncludes > "$tmpdepfile"
5279384b2f3Smrg  stat=$?
5289384b2f3Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5299384b2f3Smrg  if test $stat -ne 0; then
5309384b2f3Smrg    rm -f "$tmpdepfile"
5319384b2f3Smrg    exit $stat
5329384b2f3Smrg  fi
5339384b2f3Smrg  rm -f "$depfile"
5349384b2f3Smrg  echo "$object : \\" > "$depfile"
5359384b2f3Smrg  # The first sed program below extracts the file names and escapes
5369384b2f3Smrg  # backslashes for cygpath.  The second sed program outputs the file
5379384b2f3Smrg  # name when reading, but also accumulates all include files in the
5389384b2f3Smrg  # hold buffer in order to output them again at the end.  This only
5399384b2f3Smrg  # works with sed implementations that can handle large buffers.
5409384b2f3Smrg  sed < "$tmpdepfile" -n '
5419384b2f3Smrg/^Note: including file:  *\(.*\)/ {
5429384b2f3Smrg  s//\1/
5439384b2f3Smrg  s/\\/\\\\/g
5449384b2f3Smrg  p
5459384b2f3Smrg}' | $cygpath_u | sort -u | sed -n '
5469384b2f3Smrgs/ /\\ /g
5479384b2f3Smrgs/\(.*\)/'"$tab"'\1 \\/p
5489384b2f3Smrgs/.\(.*\) \\/\1:/
5499384b2f3SmrgH
5509384b2f3Smrg$ {
5519384b2f3Smrg  s/.*/'"$tab"'/
5529384b2f3Smrg  G
5539384b2f3Smrg  p
5549384b2f3Smrg}' >> "$depfile"
5559384b2f3Smrg  rm -f "$tmpdepfile"
5569384b2f3Smrg  ;;
5579384b2f3Smrg
5589384b2f3Smrgmsvc7msys)
5599384b2f3Smrg  # This case exists only to let depend.m4 do its work.  It works by
5609384b2f3Smrg  # looking at the text of this script.  This case will never be run,
5619384b2f3Smrg  # since it is checked for above.
5629384b2f3Smrg  exit 1
5639384b2f3Smrg  ;;
564966bf024Smrg
565966bf024Smrg#nosideeffect)
566966bf024Smrg  # This comment above is used by automake to tell side-effect
567966bf024Smrg  # dependency tracking mechanisms from slower ones.
568966bf024Smrg
569966bf024Smrgdashmstdout)
570966bf024Smrg  # Important note: in order to support this mode, a compiler *must*
571966bf024Smrg  # always write the preprocessed file to stdout, regardless of -o.
572966bf024Smrg  "$@" || exit $?
573966bf024Smrg
574966bf024Smrg  # Remove the call to Libtool.
575966bf024Smrg  if test "$libtool" = yes; then
5769384b2f3Smrg    while test "X$1" != 'X--mode=compile'; do
577966bf024Smrg      shift
578966bf024Smrg    done
579966bf024Smrg    shift
580966bf024Smrg  fi
581966bf024Smrg
5829384b2f3Smrg  # Remove '-o $object'.
583966bf024Smrg  IFS=" "
584966bf024Smrg  for arg
585966bf024Smrg  do
586966bf024Smrg    case $arg in
587966bf024Smrg    -o)
588966bf024Smrg      shift
589966bf024Smrg      ;;
590966bf024Smrg    $object)
591966bf024Smrg      shift
592966bf024Smrg      ;;
593966bf024Smrg    *)
594966bf024Smrg      set fnord "$@" "$arg"
595966bf024Smrg      shift # fnord
596966bf024Smrg      shift # $arg
597966bf024Smrg      ;;
598966bf024Smrg    esac
599966bf024Smrg  done
600966bf024Smrg
601966bf024Smrg  test -z "$dashmflag" && dashmflag=-M
6029384b2f3Smrg  # Require at least two characters before searching for ':'
603966bf024Smrg  # in the target name.  This is to cope with DOS-style filenames:
6049384b2f3Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
605966bf024Smrg  "$@" $dashmflag |
6069384b2f3Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
607966bf024Smrg  rm -f "$depfile"
608966bf024Smrg  cat < "$tmpdepfile" > "$depfile"
6099384b2f3Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6109384b2f3Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6119384b2f3Smrg  tr ' ' "$nl" < "$tmpdepfile" \
6129384b2f3Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6139384b2f3Smrg    | sed -e 's/$/ :/' >> "$depfile"
614966bf024Smrg  rm -f "$tmpdepfile"
615966bf024Smrg  ;;
616966bf024Smrg
617966bf024SmrgdashXmstdout)
618966bf024Smrg  # This case only exists to satisfy depend.m4.  It is never actually
619966bf024Smrg  # run, as this mode is specially recognized in the preamble.
620966bf024Smrg  exit 1
621966bf024Smrg  ;;
622966bf024Smrg
623966bf024Smrgmakedepend)
624966bf024Smrg  "$@" || exit $?
625966bf024Smrg  # Remove any Libtool call
626966bf024Smrg  if test "$libtool" = yes; then
6279384b2f3Smrg    while test "X$1" != 'X--mode=compile'; do
628966bf024Smrg      shift
629966bf024Smrg    done
630966bf024Smrg    shift
631966bf024Smrg  fi
632966bf024Smrg  # X makedepend
633966bf024Smrg  shift
6349384b2f3Smrg  cleared=no eat=no
6359384b2f3Smrg  for arg
6369384b2f3Smrg  do
637966bf024Smrg    case $cleared in
638966bf024Smrg    no)
639966bf024Smrg      set ""; shift
640966bf024Smrg      cleared=yes ;;
641966bf024Smrg    esac
6429384b2f3Smrg    if test $eat = yes; then
6439384b2f3Smrg      eat=no
6449384b2f3Smrg      continue
6459384b2f3Smrg    fi
646966bf024Smrg    case "$arg" in
647966bf024Smrg    -D*|-I*)
648966bf024Smrg      set fnord "$@" "$arg"; shift ;;
649966bf024Smrg    # Strip any option that makedepend may not understand.  Remove
650966bf024Smrg    # the object too, otherwise makedepend will parse it as a source file.
6519384b2f3Smrg    -arch)
6529384b2f3Smrg      eat=yes ;;
653966bf024Smrg    -*|$object)
654966bf024Smrg      ;;
655966bf024Smrg    *)
656966bf024Smrg      set fnord "$@" "$arg"; shift ;;
657966bf024Smrg    esac
658966bf024Smrg  done
6599384b2f3Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
660966bf024Smrg  touch "$tmpdepfile"
661966bf024Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
662966bf024Smrg  rm -f "$depfile"
6639384b2f3Smrg  # makedepend may prepend the VPATH from the source file name to the object.
6649384b2f3Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6659384b2f3Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6669384b2f3Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6679384b2f3Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6689384b2f3Smrg  sed '1,2d' "$tmpdepfile" \
6699384b2f3Smrg    | tr ' ' "$nl" \
6709384b2f3Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6719384b2f3Smrg    | sed -e 's/$/ :/' >> "$depfile"
672966bf024Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
673966bf024Smrg  ;;
674966bf024Smrg
675966bf024Smrgcpp)
676966bf024Smrg  # Important note: in order to support this mode, a compiler *must*
677966bf024Smrg  # always write the preprocessed file to stdout.
678966bf024Smrg  "$@" || exit $?
679966bf024Smrg
680966bf024Smrg  # Remove the call to Libtool.
681966bf024Smrg  if test "$libtool" = yes; then
6829384b2f3Smrg    while test "X$1" != 'X--mode=compile'; do
683966bf024Smrg      shift
684966bf024Smrg    done
685966bf024Smrg    shift
686966bf024Smrg  fi
687966bf024Smrg
6889384b2f3Smrg  # Remove '-o $object'.
689966bf024Smrg  IFS=" "
690966bf024Smrg  for arg
691966bf024Smrg  do
692966bf024Smrg    case $arg in
693966bf024Smrg    -o)
694966bf024Smrg      shift
695966bf024Smrg      ;;
696966bf024Smrg    $object)
697966bf024Smrg      shift
698966bf024Smrg      ;;
699966bf024Smrg    *)
700966bf024Smrg      set fnord "$@" "$arg"
701966bf024Smrg      shift # fnord
702966bf024Smrg      shift # $arg
703966bf024Smrg      ;;
704966bf024Smrg    esac
705966bf024Smrg  done
706966bf024Smrg
7079384b2f3Smrg  "$@" -E \
7089384b2f3Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7099384b2f3Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7109384b2f3Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
711966bf024Smrg  rm -f "$depfile"
712966bf024Smrg  echo "$object : \\" > "$depfile"
713966bf024Smrg  cat < "$tmpdepfile" >> "$depfile"
714966bf024Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
715966bf024Smrg  rm -f "$tmpdepfile"
716966bf024Smrg  ;;
717966bf024Smrg
718966bf024Smrgmsvisualcpp)
719966bf024Smrg  # Important note: in order to support this mode, a compiler *must*
7209384b2f3Smrg  # always write the preprocessed file to stdout.
721966bf024Smrg  "$@" || exit $?
7229384b2f3Smrg
7239384b2f3Smrg  # Remove the call to Libtool.
7249384b2f3Smrg  if test "$libtool" = yes; then
7259384b2f3Smrg    while test "X$1" != 'X--mode=compile'; do
7269384b2f3Smrg      shift
7279384b2f3Smrg    done
7289384b2f3Smrg    shift
7299384b2f3Smrg  fi
7309384b2f3Smrg
731966bf024Smrg  IFS=" "
732966bf024Smrg  for arg
733966bf024Smrg  do
734966bf024Smrg    case "$arg" in
7359384b2f3Smrg    -o)
7369384b2f3Smrg      shift
7379384b2f3Smrg      ;;
7389384b2f3Smrg    $object)
7399384b2f3Smrg      shift
7409384b2f3Smrg      ;;
741966bf024Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7429384b2f3Smrg        set fnord "$@"
7439384b2f3Smrg        shift
7449384b2f3Smrg        shift
7459384b2f3Smrg        ;;
746966bf024Smrg    *)
7479384b2f3Smrg        set fnord "$@" "$arg"
7489384b2f3Smrg        shift
7499384b2f3Smrg        shift
7509384b2f3Smrg        ;;
751966bf024Smrg    esac
752966bf024Smrg  done
7539384b2f3Smrg  "$@" -E 2>/dev/null |
7549384b2f3Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
755966bf024Smrg  rm -f "$depfile"
756966bf024Smrg  echo "$object : \\" > "$depfile"
7579384b2f3Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7589384b2f3Smrg  echo "$tab" >> "$depfile"
7599384b2f3Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
760966bf024Smrg  rm -f "$tmpdepfile"
761966bf024Smrg  ;;
762966bf024Smrg
7639384b2f3Smrgmsvcmsys)
7649384b2f3Smrg  # This case exists only to let depend.m4 do its work.  It works by
7659384b2f3Smrg  # looking at the text of this script.  This case will never be run,
7669384b2f3Smrg  # since it is checked for above.
7679384b2f3Smrg  exit 1
7689384b2f3Smrg  ;;
7699384b2f3Smrg
770966bf024Smrgnone)
771966bf024Smrg  exec "$@"
772966bf024Smrg  ;;
773966bf024Smrg
774966bf024Smrg*)
775966bf024Smrg  echo "Unknown depmode $depmode" 1>&2
776966bf024Smrg  exit 1
777966bf024Smrg  ;;
778966bf024Smrgesac
779966bf024Smrg
780966bf024Smrgexit 0
7819384b2f3Smrg
7829384b2f3Smrg# Local Variables:
7839384b2f3Smrg# mode: shell-script
7849384b2f3Smrg# sh-indentation: 2
7859384b2f3Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
7869384b2f3Smrg# time-stamp-start: "scriptversion="
7879384b2f3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7889384b2f3Smrg# time-stamp-time-zone: "UTC"
7899384b2f3Smrg# time-stamp-end: "; # UTC"
7909384b2f3Smrg# End:
791