depcomp revision 8bd17e5f
1b042e37fSmrg#! /bin/sh
2b042e37fSmrg# depcomp - compile a program generating dependencies as side-effects
3b042e37fSmrg
48bd17e5fSmrgscriptversion=2012-10-18.11; # UTC
5b042e37fSmrg
68bd17e5fSmrg# Copyright (C) 1999-2013 Free Software Foundation, Inc.
7b042e37fSmrg
8b042e37fSmrg# This program is free software; you can redistribute it and/or modify
9b042e37fSmrg# it under the terms of the GNU General Public License as published by
10b042e37fSmrg# the Free Software Foundation; either version 2, or (at your option)
11b042e37fSmrg# any later version.
12b042e37fSmrg
13b042e37fSmrg# This program is distributed in the hope that it will be useful,
14b042e37fSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15b042e37fSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16b042e37fSmrg# GNU General Public License for more details.
17b042e37fSmrg
18b042e37fSmrg# You should have received a copy of the GNU General Public License
19706b6b52Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20b042e37fSmrg
21b042e37fSmrg# As a special exception to the GNU General Public License, if you
22b042e37fSmrg# distribute this file as part of a program that contains a
23b042e37fSmrg# configuration script generated by Autoconf, you may include it under
24b042e37fSmrg# the same distribution terms that you use for the rest of that program.
25b042e37fSmrg
26b042e37fSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27b042e37fSmrg
28b042e37fSmrgcase $1 in
29b042e37fSmrg  '')
308bd17e5fSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
318bd17e5fSmrg    exit 1;
328bd17e5fSmrg    ;;
33b042e37fSmrg  -h | --h*)
34b042e37fSmrg    cat <<\EOF
35b042e37fSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36b042e37fSmrg
37b042e37fSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38b042e37fSmrgas side-effects.
39b042e37fSmrg
40b042e37fSmrgEnvironment variables:
41b042e37fSmrg  depmode     Dependency tracking mode.
428bd17e5fSmrg  source      Source file read by 'PROGRAMS ARGS'.
438bd17e5fSmrg  object      Object file output by 'PROGRAMS ARGS'.
44b042e37fSmrg  DEPDIR      directory where to store dependencies.
45b042e37fSmrg  depfile     Dependency file to output.
460597fb56Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
47b042e37fSmrg  libtool     Whether libtool is used (yes/no).
48b042e37fSmrg
49b042e37fSmrgReport bugs to <bug-automake@gnu.org>.
50b042e37fSmrgEOF
51b042e37fSmrg    exit $?
52b042e37fSmrg    ;;
53b042e37fSmrg  -v | --v*)
54b042e37fSmrg    echo "depcomp $scriptversion"
55b042e37fSmrg    exit $?
56b042e37fSmrg    ;;
57b042e37fSmrgesac
58b042e37fSmrg
598bd17e5fSmrg# Get the directory component of the given path, and save it in the
608bd17e5fSmrg# global variables '$dir'.  Note that this directory component will
618bd17e5fSmrg# be either empty or ending with a '/' character.  This is deliberate.
628bd17e5fSmrgset_dir_from ()
638bd17e5fSmrg{
648bd17e5fSmrg  case $1 in
658bd17e5fSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
668bd17e5fSmrg      *) dir=;;
678bd17e5fSmrg  esac
688bd17e5fSmrg}
698bd17e5fSmrg
708bd17e5fSmrg# Get the suffix-stripped basename of the given path, and save it the
718bd17e5fSmrg# global variable '$base'.
728bd17e5fSmrgset_base_from ()
738bd17e5fSmrg{
748bd17e5fSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
758bd17e5fSmrg}
768bd17e5fSmrg
778bd17e5fSmrg# If no dependency file was actually created by the compiler invocation,
788bd17e5fSmrg# we still have to create a dummy depfile, to avoid errors with the
798bd17e5fSmrg# Makefile "include basename.Plo" scheme.
808bd17e5fSmrgmake_dummy_depfile ()
818bd17e5fSmrg{
828bd17e5fSmrg  echo "#dummy" > "$depfile"
838bd17e5fSmrg}
848bd17e5fSmrg
858bd17e5fSmrg# Factor out some common post-processing of the generated depfile.
868bd17e5fSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
878bd17e5fSmrgaix_post_process_depfile ()
888bd17e5fSmrg{
898bd17e5fSmrg  # If the compiler actually managed to produce a dependency file,
908bd17e5fSmrg  # post-process it.
918bd17e5fSmrg  if test -f "$tmpdepfile"; then
928bd17e5fSmrg    # Each line is of the form 'foo.o: dependency.h'.
938bd17e5fSmrg    # Do two passes, one to just change these to
948bd17e5fSmrg    #   $object: dependency.h
958bd17e5fSmrg    # and one to simply output
968bd17e5fSmrg    #   dependency.h:
978bd17e5fSmrg    # which is needed to avoid the deleted-header problem.
988bd17e5fSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
998bd17e5fSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1008bd17e5fSmrg    } > "$depfile"
1018bd17e5fSmrg    rm -f "$tmpdepfile"
1028bd17e5fSmrg  else
1038bd17e5fSmrg    make_dummy_depfile
1048bd17e5fSmrg  fi
1058bd17e5fSmrg}
1068bd17e5fSmrg
1078bd17e5fSmrg# A tabulation character.
1088bd17e5fSmrgtab='	'
1098bd17e5fSmrg# A newline character.
1108bd17e5fSmrgnl='
1118bd17e5fSmrg'
1128bd17e5fSmrg# Character ranges might be problematic outside the C locale.
1138bd17e5fSmrg# These definitions help.
1148bd17e5fSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1158bd17e5fSmrglower=abcdefghijklmnopqrstuvwxyz
1168bd17e5fSmrgdigits=0123456789
1178bd17e5fSmrgalpha=${upper}${lower}
1188bd17e5fSmrg
119b042e37fSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120b042e37fSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121b042e37fSmrg  exit 1
122b042e37fSmrgfi
123b042e37fSmrg
124b042e37fSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125b042e37fSmrgdepfile=${depfile-`echo "$object" |
126b042e37fSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127b042e37fSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128b042e37fSmrg
129b042e37fSmrgrm -f "$tmpdepfile"
130b042e37fSmrg
1318bd17e5fSmrg# Avoid interferences from the environment.
1328bd17e5fSmrggccflag= dashmflag=
1338bd17e5fSmrg
134b042e37fSmrg# Some modes work just like other modes, but use different flags.  We
135b042e37fSmrg# parameterize here, but still list the modes in the big case below,
136b042e37fSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137b042e37fSmrg# here, because this file can only contain one case statement.
138b042e37fSmrgif test "$depmode" = hp; then
139b042e37fSmrg  # HP compiler uses -M and no extra arg.
140b042e37fSmrg  gccflag=-M
141b042e37fSmrg  depmode=gcc
142b042e37fSmrgfi
143b042e37fSmrg
144b042e37fSmrgif test "$depmode" = dashXmstdout; then
1458bd17e5fSmrg  # This is just like dashmstdout with a different argument.
1468bd17e5fSmrg  dashmflag=-xM
1478bd17e5fSmrg  depmode=dashmstdout
148b042e37fSmrgfi
149b042e37fSmrg
150706b6b52Smrgcygpath_u="cygpath -u -f -"
151706b6b52Smrgif test "$depmode" = msvcmsys; then
1528bd17e5fSmrg  # This is just like msvisualcpp but w/o cygpath translation.
1538bd17e5fSmrg  # Just convert the backslash-escaped backslashes to single forward
1548bd17e5fSmrg  # slashes to satisfy depend.m4
1558bd17e5fSmrg  cygpath_u='sed s,\\\\,/,g'
1568bd17e5fSmrg  depmode=msvisualcpp
157706b6b52Smrgfi
158706b6b52Smrg
1590597fb56Smrgif test "$depmode" = msvc7msys; then
1608bd17e5fSmrg  # This is just like msvc7 but w/o cygpath translation.
1618bd17e5fSmrg  # Just convert the backslash-escaped backslashes to single forward
1628bd17e5fSmrg  # slashes to satisfy depend.m4
1638bd17e5fSmrg  cygpath_u='sed s,\\\\,/,g'
1648bd17e5fSmrg  depmode=msvc7
1658bd17e5fSmrgfi
1668bd17e5fSmrg
1678bd17e5fSmrgif test "$depmode" = xlc; then
1688bd17e5fSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1698bd17e5fSmrg  gccflag=-qmakedep=gcc,-MF
1708bd17e5fSmrg  depmode=gcc
1710597fb56Smrgfi
1720597fb56Smrg
173b042e37fSmrgcase "$depmode" in
174b042e37fSmrggcc3)
175b042e37fSmrg## gcc 3 implements dependency tracking that does exactly what
176b042e37fSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177b042e37fSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178b042e37fSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179b042e37fSmrg## the command line argument order; so add the flags where they
180b042e37fSmrg## appear in depend2.am.  Note that the slowdown incurred here
181b042e37fSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182b042e37fSmrg  for arg
183b042e37fSmrg  do
184b042e37fSmrg    case $arg in
185b042e37fSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186b042e37fSmrg    *)  set fnord "$@" "$arg" ;;
187b042e37fSmrg    esac
188b042e37fSmrg    shift # fnord
189b042e37fSmrg    shift # $arg
190b042e37fSmrg  done
191b042e37fSmrg  "$@"
192b042e37fSmrg  stat=$?
1938bd17e5fSmrg  if test $stat -ne 0; then
194b042e37fSmrg    rm -f "$tmpdepfile"
195b042e37fSmrg    exit $stat
196b042e37fSmrg  fi
197b042e37fSmrg  mv "$tmpdepfile" "$depfile"
198b042e37fSmrg  ;;
199b042e37fSmrg
200b042e37fSmrggcc)
2018bd17e5fSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2028bd17e5fSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2038bd17e5fSmrg## (see the conditional assignment to $gccflag above).
204b042e37fSmrg## There are various ways to get dependency output from gcc.  Here's
205b042e37fSmrg## why we pick this rather obscure method:
206b042e37fSmrg## - Don't want to use -MD because we'd like the dependencies to end
207b042e37fSmrg##   up in a subdir.  Having to rename by hand is ugly.
208b042e37fSmrg##   (We might end up doing this anyway to support other compilers.)
209b042e37fSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2108bd17e5fSmrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2118bd17e5fSmrg##   supported by the other compilers which use the 'gcc' depmode.
212b042e37fSmrg## - Using -M directly means running the compiler twice (even worse
213b042e37fSmrg##   than renaming).
214b042e37fSmrg  if test -z "$gccflag"; then
215b042e37fSmrg    gccflag=-MD,
216b042e37fSmrg  fi
217b042e37fSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
218b042e37fSmrg  stat=$?
2198bd17e5fSmrg  if test $stat -ne 0; then
220b042e37fSmrg    rm -f "$tmpdepfile"
221b042e37fSmrg    exit $stat
222b042e37fSmrg  fi
223b042e37fSmrg  rm -f "$depfile"
224b042e37fSmrg  echo "$object : \\" > "$depfile"
2258bd17e5fSmrg  # The second -e expression handles DOS-style file names with drive
2268bd17e5fSmrg  # letters.
227b042e37fSmrg  sed -e 's/^[^:]*: / /' \
228b042e37fSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2298bd17e5fSmrg## This next piece of magic avoids the "deleted header file" problem.
230b042e37fSmrg## The problem is that when a header file which appears in a .P file
231b042e37fSmrg## is deleted, the dependency causes make to die (because there is
232b042e37fSmrg## typically no way to rebuild the header).  We avoid this by adding
233b042e37fSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234b042e37fSmrg## this for us directly.
2358bd17e5fSmrg## Some versions of gcc put a space before the ':'.  On the theory
236b042e37fSmrg## that the space means something, we add a space to the output as
2370597fb56Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2380597fb56Smrg## to the object.  Take care to not repeat it in the output.
239b042e37fSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
240b042e37fSmrg## correctly.  Breaking it into two sed invocations is a workaround.
2418bd17e5fSmrg  tr ' ' "$nl" < "$tmpdepfile" \
2428bd17e5fSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2438bd17e5fSmrg    | sed -e 's/$/ :/' >> "$depfile"
244b042e37fSmrg  rm -f "$tmpdepfile"
245b042e37fSmrg  ;;
246b042e37fSmrg
247b042e37fSmrghp)
248b042e37fSmrg  # This case exists only to let depend.m4 do its work.  It works by
249b042e37fSmrg  # looking at the text of this script.  This case will never be run,
250b042e37fSmrg  # since it is checked for above.
251b042e37fSmrg  exit 1
252b042e37fSmrg  ;;
253b042e37fSmrg
254b042e37fSmrgsgi)
255b042e37fSmrg  if test "$libtool" = yes; then
256b042e37fSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257b042e37fSmrg  else
258b042e37fSmrg    "$@" -MDupdate "$tmpdepfile"
259b042e37fSmrg  fi
260b042e37fSmrg  stat=$?
2618bd17e5fSmrg  if test $stat -ne 0; then
262b042e37fSmrg    rm -f "$tmpdepfile"
263b042e37fSmrg    exit $stat
264b042e37fSmrg  fi
265b042e37fSmrg  rm -f "$depfile"
266b042e37fSmrg
267b042e37fSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268b042e37fSmrg    echo "$object : \\" > "$depfile"
269b042e37fSmrg    # Clip off the initial element (the dependent).  Don't try to be
270b042e37fSmrg    # clever and replace this with sed code, as IRIX sed won't handle
271b042e37fSmrg    # lines with more than a fixed number of characters (4096 in
272b042e37fSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2738bd17e5fSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
274b042e37fSmrg    # dependency line.
2758bd17e5fSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2768bd17e5fSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2778bd17e5fSmrg      | tr "$nl" ' ' >> "$depfile"
278706b6b52Smrg    echo >> "$depfile"
279b042e37fSmrg    # The second pass generates a dummy entry for each header file.
2808bd17e5fSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2818bd17e5fSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2828bd17e5fSmrg      >> "$depfile"
283b042e37fSmrg  else
2848bd17e5fSmrg    make_dummy_depfile
285b042e37fSmrg  fi
286b042e37fSmrg  rm -f "$tmpdepfile"
287b042e37fSmrg  ;;
288b042e37fSmrg
2898bd17e5fSmrgxlc)
2908bd17e5fSmrg  # This case exists only to let depend.m4 do its work.  It works by
2918bd17e5fSmrg  # looking at the text of this script.  This case will never be run,
2928bd17e5fSmrg  # since it is checked for above.
2938bd17e5fSmrg  exit 1
2948bd17e5fSmrg  ;;
2958bd17e5fSmrg
296b042e37fSmrgaix)
297b042e37fSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
298b042e37fSmrg  # in a .u file.  In older versions, this file always lives in the
2998bd17e5fSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300b042e37fSmrg  # start of each line; $object doesn't have directory information.
301b042e37fSmrg  # Version 6 uses the directory in both cases.
3028bd17e5fSmrg  set_dir_from "$object"
3038bd17e5fSmrg  set_base_from "$object"
304b042e37fSmrg  if test "$libtool" = yes; then
305706b6b52Smrg    tmpdepfile1=$dir$base.u
306706b6b52Smrg    tmpdepfile2=$base.u
307706b6b52Smrg    tmpdepfile3=$dir.libs/$base.u
308b042e37fSmrg    "$@" -Wc,-M
309b042e37fSmrg  else
310706b6b52Smrg    tmpdepfile1=$dir$base.u
311706b6b52Smrg    tmpdepfile2=$dir$base.u
312706b6b52Smrg    tmpdepfile3=$dir$base.u
313b042e37fSmrg    "$@" -M
314b042e37fSmrg  fi
315b042e37fSmrg  stat=$?
3168bd17e5fSmrg  if test $stat -ne 0; then
317706b6b52Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318b042e37fSmrg    exit $stat
319b042e37fSmrg  fi
320b042e37fSmrg
321706b6b52Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322706b6b52Smrg  do
323706b6b52Smrg    test -f "$tmpdepfile" && break
324706b6b52Smrg  done
3258bd17e5fSmrg  aix_post_process_depfile
3268bd17e5fSmrg  ;;
3278bd17e5fSmrg
3288bd17e5fSmrgtcc)
3298bd17e5fSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3308bd17e5fSmrg  # FIXME: That version still under development at the moment of writing.
3318bd17e5fSmrg  #        Make that this statement remains true also for stable, released
3328bd17e5fSmrg  #        versions.
3338bd17e5fSmrg  # It will wrap lines (doesn't matter whether long or short) with a
3348bd17e5fSmrg  # trailing '\', as in:
3358bd17e5fSmrg  #
3368bd17e5fSmrg  #   foo.o : \
3378bd17e5fSmrg  #    foo.c \
3388bd17e5fSmrg  #    foo.h \
3398bd17e5fSmrg  #
3408bd17e5fSmrg  # It will put a trailing '\' even on the last line, and will use leading
3418bd17e5fSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3428bd17e5fSmrg  # "Emit spaces for -MD").
3438bd17e5fSmrg  "$@" -MD -MF "$tmpdepfile"
3448bd17e5fSmrg  stat=$?
3458bd17e5fSmrg  if test $stat -ne 0; then
3468bd17e5fSmrg    rm -f "$tmpdepfile"
3478bd17e5fSmrg    exit $stat
348b042e37fSmrg  fi
3498bd17e5fSmrg  rm -f "$depfile"
3508bd17e5fSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3518bd17e5fSmrg  # We have to change lines of the first kind to '$object: \'.
3528bd17e5fSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3538bd17e5fSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3548bd17e5fSmrg  # dummy dependency, to avoid the deleted-header problem.
3558bd17e5fSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356b042e37fSmrg  rm -f "$tmpdepfile"
357b042e37fSmrg  ;;
358b042e37fSmrg
3598bd17e5fSmrg## The order of this option in the case statement is important, since the
3608bd17e5fSmrg## shell code in configure will try each of these formats in the order
3618bd17e5fSmrg## listed in this file.  A plain '-MD' option would be understood by many
3628bd17e5fSmrg## compilers, so we must ensure this comes after the gcc and icc options.
3638bd17e5fSmrgpgcc)
3648bd17e5fSmrg  # Portland's C compiler understands '-MD'.
3658bd17e5fSmrg  # Will always output deps to 'file.d' where file is the root name of the
3668bd17e5fSmrg  # source file under compilation, even if file resides in a subdirectory.
3678bd17e5fSmrg  # The object file name does not affect the name of the '.d' file.
3688bd17e5fSmrg  # pgcc 10.2 will output
369b042e37fSmrg  #    foo.o: sub/foo.c sub/foo.h
3708bd17e5fSmrg  # and will wrap long lines using '\' :
371b042e37fSmrg  #    foo.o: sub/foo.c ... \
372b042e37fSmrg  #     sub/foo.h ... \
373b042e37fSmrg  #     ...
3748bd17e5fSmrg  set_dir_from "$object"
3758bd17e5fSmrg  # Use the source, not the object, to determine the base name, since
3768bd17e5fSmrg  # that's sadly what pgcc will do too.
3778bd17e5fSmrg  set_base_from "$source"
3788bd17e5fSmrg  tmpdepfile=$base.d
3798bd17e5fSmrg
3808bd17e5fSmrg  # For projects that build the same source file twice into different object
3818bd17e5fSmrg  # files, the pgcc approach of using the *source* file root name can cause
3828bd17e5fSmrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3838bd17e5fSmrg  # the same $tmpdepfile.
3848bd17e5fSmrg  lockdir=$base.d-lock
3858bd17e5fSmrg  trap "
3868bd17e5fSmrg    echo '$0: caught signal, cleaning up...' >&2
3878bd17e5fSmrg    rmdir '$lockdir'
3888bd17e5fSmrg    exit 1
3898bd17e5fSmrg  " 1 2 13 15
3908bd17e5fSmrg  numtries=100
3918bd17e5fSmrg  i=$numtries
3928bd17e5fSmrg  while test $i -gt 0; do
3938bd17e5fSmrg    # mkdir is a portable test-and-set.
3948bd17e5fSmrg    if mkdir "$lockdir" 2>/dev/null; then
3958bd17e5fSmrg      # This process acquired the lock.
3968bd17e5fSmrg      "$@" -MD
3978bd17e5fSmrg      stat=$?
3988bd17e5fSmrg      # Release the lock.
3998bd17e5fSmrg      rmdir "$lockdir"
4008bd17e5fSmrg      break
4018bd17e5fSmrg    else
4028bd17e5fSmrg      # If the lock is being held by a different process, wait
4038bd17e5fSmrg      # until the winning process is done or we timeout.
4048bd17e5fSmrg      while test -d "$lockdir" && test $i -gt 0; do
4058bd17e5fSmrg        sleep 1
4068bd17e5fSmrg        i=`expr $i - 1`
4078bd17e5fSmrg      done
4088bd17e5fSmrg    fi
4098bd17e5fSmrg    i=`expr $i - 1`
4108bd17e5fSmrg  done
4118bd17e5fSmrg  trap - 1 2 13 15
4128bd17e5fSmrg  if test $i -le 0; then
4138bd17e5fSmrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4148bd17e5fSmrg    echo "$0: check lockdir '$lockdir'" >&2
4158bd17e5fSmrg    exit 1
4168bd17e5fSmrg  fi
417b042e37fSmrg
4188bd17e5fSmrg  if test $stat -ne 0; then
419b042e37fSmrg    rm -f "$tmpdepfile"
420b042e37fSmrg    exit $stat
421b042e37fSmrg  fi
422b042e37fSmrg  rm -f "$depfile"
423b042e37fSmrg  # Each line is of the form `foo.o: dependent.h',
424b042e37fSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425b042e37fSmrg  # Do two passes, one to just change these to
426b042e37fSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427b042e37fSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428b042e37fSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429b042e37fSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
4308bd17e5fSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4318bd17e5fSmrg    | sed -e 's/$/ :/' >> "$depfile"
432b042e37fSmrg  rm -f "$tmpdepfile"
433b042e37fSmrg  ;;
434b042e37fSmrg
435b042e37fSmrghp2)
436b042e37fSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437b042e37fSmrg  # compilers, which have integrated preprocessors.  The correct option
438b042e37fSmrg  # to use with these is +Maked; it writes dependencies to a file named
439b042e37fSmrg  # 'foo.d', which lands next to the object file, wherever that
440b042e37fSmrg  # happens to be.
441b042e37fSmrg  # Much of this is similar to the tru64 case; see comments there.
4428bd17e5fSmrg  set_dir_from  "$object"
4438bd17e5fSmrg  set_base_from "$object"
444b042e37fSmrg  if test "$libtool" = yes; then
445b042e37fSmrg    tmpdepfile1=$dir$base.d
446b042e37fSmrg    tmpdepfile2=$dir.libs/$base.d
447b042e37fSmrg    "$@" -Wc,+Maked
448b042e37fSmrg  else
449b042e37fSmrg    tmpdepfile1=$dir$base.d
450b042e37fSmrg    tmpdepfile2=$dir$base.d
451b042e37fSmrg    "$@" +Maked
452b042e37fSmrg  fi
453b042e37fSmrg  stat=$?
4548bd17e5fSmrg  if test $stat -ne 0; then
455b042e37fSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456b042e37fSmrg     exit $stat
457b042e37fSmrg  fi
458b042e37fSmrg
459b042e37fSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460b042e37fSmrg  do
461b042e37fSmrg    test -f "$tmpdepfile" && break
462b042e37fSmrg  done
463b042e37fSmrg  if test -f "$tmpdepfile"; then
4648bd17e5fSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4658bd17e5fSmrg    # Add 'dependent.h:' lines.
466706b6b52Smrg    sed -ne '2,${
4678bd17e5fSmrg               s/^ *//
4688bd17e5fSmrg               s/ \\*$//
4698bd17e5fSmrg               s/$/:/
4708bd17e5fSmrg               p
4718bd17e5fSmrg             }' "$tmpdepfile" >> "$depfile"
472b042e37fSmrg  else
4738bd17e5fSmrg    make_dummy_depfile
474b042e37fSmrg  fi
475b042e37fSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476b042e37fSmrg  ;;
477b042e37fSmrg
478b042e37fSmrgtru64)
4798bd17e5fSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4808bd17e5fSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4818bd17e5fSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4828bd17e5fSmrg  # dependencies in 'foo.d' instead, so we check for that too.
4838bd17e5fSmrg  # Subdirectories are respected.
4848bd17e5fSmrg  set_dir_from  "$object"
4858bd17e5fSmrg  set_base_from "$object"
4868bd17e5fSmrg
4878bd17e5fSmrg  if test "$libtool" = yes; then
4888bd17e5fSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4898bd17e5fSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4908bd17e5fSmrg    # in $dir$base.o.d.  We have to check for both files, because
4918bd17e5fSmrg    # one of the two compilations can be disabled.  We should prefer
4928bd17e5fSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4938bd17e5fSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
4948bd17e5fSmrg    # the former would cause a distcleancheck panic.
4958bd17e5fSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4968bd17e5fSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4978bd17e5fSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4988bd17e5fSmrg    "$@" -Wc,-MD
4998bd17e5fSmrg  else
5008bd17e5fSmrg    tmpdepfile1=$dir$base.d
5018bd17e5fSmrg    tmpdepfile2=$dir$base.d
5028bd17e5fSmrg    tmpdepfile3=$dir$base.d
5038bd17e5fSmrg    "$@" -MD
5048bd17e5fSmrg  fi
5058bd17e5fSmrg
5068bd17e5fSmrg  stat=$?
5078bd17e5fSmrg  if test $stat -ne 0; then
5088bd17e5fSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5098bd17e5fSmrg    exit $stat
5108bd17e5fSmrg  fi
5118bd17e5fSmrg
5128bd17e5fSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5138bd17e5fSmrg  do
5148bd17e5fSmrg    test -f "$tmpdepfile" && break
5158bd17e5fSmrg  done
5168bd17e5fSmrg  # Same post-processing that is required for AIX mode.
5178bd17e5fSmrg  aix_post_process_depfile
5188bd17e5fSmrg  ;;
519b042e37fSmrg
5200597fb56Smrgmsvc7)
5210597fb56Smrg  if test "$libtool" = yes; then
5220597fb56Smrg    showIncludes=-Wc,-showIncludes
5230597fb56Smrg  else
5240597fb56Smrg    showIncludes=-showIncludes
5250597fb56Smrg  fi
5260597fb56Smrg  "$@" $showIncludes > "$tmpdepfile"
5270597fb56Smrg  stat=$?
5280597fb56Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5298bd17e5fSmrg  if test $stat -ne 0; then
5300597fb56Smrg    rm -f "$tmpdepfile"
5310597fb56Smrg    exit $stat
5320597fb56Smrg  fi
5330597fb56Smrg  rm -f "$depfile"
5340597fb56Smrg  echo "$object : \\" > "$depfile"
5350597fb56Smrg  # The first sed program below extracts the file names and escapes
5360597fb56Smrg  # backslashes for cygpath.  The second sed program outputs the file
5370597fb56Smrg  # name when reading, but also accumulates all include files in the
5380597fb56Smrg  # hold buffer in order to output them again at the end.  This only
5390597fb56Smrg  # works with sed implementations that can handle large buffers.
5400597fb56Smrg  sed < "$tmpdepfile" -n '
5410597fb56Smrg/^Note: including file:  *\(.*\)/ {
5420597fb56Smrg  s//\1/
5430597fb56Smrg  s/\\/\\\\/g
5440597fb56Smrg  p
5450597fb56Smrg}' | $cygpath_u | sort -u | sed -n '
5460597fb56Smrgs/ /\\ /g
5478bd17e5fSmrgs/\(.*\)/'"$tab"'\1 \\/p
5480597fb56Smrgs/.\(.*\) \\/\1:/
5490597fb56SmrgH
5500597fb56Smrg$ {
5518bd17e5fSmrg  s/.*/'"$tab"'/
5520597fb56Smrg  G
5530597fb56Smrg  p
5540597fb56Smrg}' >> "$depfile"
5550597fb56Smrg  rm -f "$tmpdepfile"
5560597fb56Smrg  ;;
5570597fb56Smrg
5580597fb56Smrgmsvc7msys)
5590597fb56Smrg  # This case exists only to let depend.m4 do its work.  It works by
5600597fb56Smrg  # looking at the text of this script.  This case will never be run,
5610597fb56Smrg  # since it is checked for above.
5620597fb56Smrg  exit 1
5630597fb56Smrg  ;;
5640597fb56Smrg
565b042e37fSmrg#nosideeffect)
566b042e37fSmrg  # This comment above is used by automake to tell side-effect
567b042e37fSmrg  # dependency tracking mechanisms from slower ones.
568b042e37fSmrg
569b042e37fSmrgdashmstdout)
570b042e37fSmrg  # Important note: in order to support this mode, a compiler *must*
571b042e37fSmrg  # always write the preprocessed file to stdout, regardless of -o.
572b042e37fSmrg  "$@" || exit $?
573b042e37fSmrg
574b042e37fSmrg  # Remove the call to Libtool.
575b042e37fSmrg  if test "$libtool" = yes; then
576706b6b52Smrg    while test "X$1" != 'X--mode=compile'; do
577b042e37fSmrg      shift
578b042e37fSmrg    done
579b042e37fSmrg    shift
580b042e37fSmrg  fi
581b042e37fSmrg
5828bd17e5fSmrg  # Remove '-o $object'.
583b042e37fSmrg  IFS=" "
584b042e37fSmrg  for arg
585b042e37fSmrg  do
586b042e37fSmrg    case $arg in
587b042e37fSmrg    -o)
588b042e37fSmrg      shift
589b042e37fSmrg      ;;
590b042e37fSmrg    $object)
591b042e37fSmrg      shift
592b042e37fSmrg      ;;
593b042e37fSmrg    *)
594b042e37fSmrg      set fnord "$@" "$arg"
595b042e37fSmrg      shift # fnord
596b042e37fSmrg      shift # $arg
597b042e37fSmrg      ;;
598b042e37fSmrg    esac
599b042e37fSmrg  done
600b042e37fSmrg
601b042e37fSmrg  test -z "$dashmflag" && dashmflag=-M
6028bd17e5fSmrg  # Require at least two characters before searching for ':'
603b042e37fSmrg  # in the target name.  This is to cope with DOS-style filenames:
6048bd17e5fSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
605b042e37fSmrg  "$@" $dashmflag |
6068bd17e5fSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
607b042e37fSmrg  rm -f "$depfile"
608b042e37fSmrg  cat < "$tmpdepfile" > "$depfile"
6098bd17e5fSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6108bd17e5fSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6118bd17e5fSmrg  tr ' ' "$nl" < "$tmpdepfile" \
6128bd17e5fSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6138bd17e5fSmrg    | sed -e 's/$/ :/' >> "$depfile"
614b042e37fSmrg  rm -f "$tmpdepfile"
615b042e37fSmrg  ;;
616b042e37fSmrg
617b042e37fSmrgdashXmstdout)
618b042e37fSmrg  # This case only exists to satisfy depend.m4.  It is never actually
619b042e37fSmrg  # run, as this mode is specially recognized in the preamble.
620b042e37fSmrg  exit 1
621b042e37fSmrg  ;;
622b042e37fSmrg
623b042e37fSmrgmakedepend)
624b042e37fSmrg  "$@" || exit $?
625b042e37fSmrg  # Remove any Libtool call
626b042e37fSmrg  if test "$libtool" = yes; then
627706b6b52Smrg    while test "X$1" != 'X--mode=compile'; do
628b042e37fSmrg      shift
629b042e37fSmrg    done
630b042e37fSmrg    shift
631b042e37fSmrg  fi
632b042e37fSmrg  # X makedepend
633b042e37fSmrg  shift
634706b6b52Smrg  cleared=no eat=no
635706b6b52Smrg  for arg
636706b6b52Smrg  do
637b042e37fSmrg    case $cleared in
638b042e37fSmrg    no)
639b042e37fSmrg      set ""; shift
640b042e37fSmrg      cleared=yes ;;
641b042e37fSmrg    esac
642706b6b52Smrg    if test $eat = yes; then
643706b6b52Smrg      eat=no
644706b6b52Smrg      continue
645706b6b52Smrg    fi
646b042e37fSmrg    case "$arg" in
647b042e37fSmrg    -D*|-I*)
648b042e37fSmrg      set fnord "$@" "$arg"; shift ;;
649b042e37fSmrg    # Strip any option that makedepend may not understand.  Remove
650b042e37fSmrg    # the object too, otherwise makedepend will parse it as a source file.
651706b6b52Smrg    -arch)
652706b6b52Smrg      eat=yes ;;
653b042e37fSmrg    -*|$object)
654b042e37fSmrg      ;;
655b042e37fSmrg    *)
656b042e37fSmrg      set fnord "$@" "$arg"; shift ;;
657b042e37fSmrg    esac
658b042e37fSmrg  done
659706b6b52Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
660b042e37fSmrg  touch "$tmpdepfile"
661b042e37fSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
662b042e37fSmrg  rm -f "$depfile"
6630597fb56Smrg  # makedepend may prepend the VPATH from the source file name to the object.
6640597fb56Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6650597fb56Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6668bd17e5fSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6678bd17e5fSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6688bd17e5fSmrg  sed '1,2d' "$tmpdepfile" \
6698bd17e5fSmrg    | tr ' ' "$nl" \
6708bd17e5fSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6718bd17e5fSmrg    | sed -e 's/$/ :/' >> "$depfile"
672b042e37fSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
673b042e37fSmrg  ;;
674b042e37fSmrg
675b042e37fSmrgcpp)
676b042e37fSmrg  # Important note: in order to support this mode, a compiler *must*
677b042e37fSmrg  # always write the preprocessed file to stdout.
678b042e37fSmrg  "$@" || exit $?
679b042e37fSmrg
680b042e37fSmrg  # Remove the call to Libtool.
681b042e37fSmrg  if test "$libtool" = yes; then
682706b6b52Smrg    while test "X$1" != 'X--mode=compile'; do
683b042e37fSmrg      shift
684b042e37fSmrg    done
685b042e37fSmrg    shift
686b042e37fSmrg  fi
687b042e37fSmrg
6888bd17e5fSmrg  # Remove '-o $object'.
689b042e37fSmrg  IFS=" "
690b042e37fSmrg  for arg
691b042e37fSmrg  do
692b042e37fSmrg    case $arg in
693b042e37fSmrg    -o)
694b042e37fSmrg      shift
695b042e37fSmrg      ;;
696b042e37fSmrg    $object)
697b042e37fSmrg      shift
698b042e37fSmrg      ;;
699b042e37fSmrg    *)
700b042e37fSmrg      set fnord "$@" "$arg"
701b042e37fSmrg      shift # fnord
702b042e37fSmrg      shift # $arg
703b042e37fSmrg      ;;
704b042e37fSmrg    esac
705b042e37fSmrg  done
706b042e37fSmrg
7078bd17e5fSmrg  "$@" -E \
7088bd17e5fSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7098bd17e5fSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7108bd17e5fSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
711b042e37fSmrg  rm -f "$depfile"
712b042e37fSmrg  echo "$object : \\" > "$depfile"
713b042e37fSmrg  cat < "$tmpdepfile" >> "$depfile"
714b042e37fSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
715b042e37fSmrg  rm -f "$tmpdepfile"
716b042e37fSmrg  ;;
717b042e37fSmrg
718b042e37fSmrgmsvisualcpp)
719b042e37fSmrg  # Important note: in order to support this mode, a compiler *must*
720706b6b52Smrg  # always write the preprocessed file to stdout.
721b042e37fSmrg  "$@" || exit $?
722706b6b52Smrg
723706b6b52Smrg  # Remove the call to Libtool.
724706b6b52Smrg  if test "$libtool" = yes; then
725706b6b52Smrg    while test "X$1" != 'X--mode=compile'; do
726706b6b52Smrg      shift
727706b6b52Smrg    done
728706b6b52Smrg    shift
729706b6b52Smrg  fi
730706b6b52Smrg
731b042e37fSmrg  IFS=" "
732b042e37fSmrg  for arg
733b042e37fSmrg  do
734b042e37fSmrg    case "$arg" in
735706b6b52Smrg    -o)
736706b6b52Smrg      shift
737706b6b52Smrg      ;;
738706b6b52Smrg    $object)
739706b6b52Smrg      shift
740706b6b52Smrg      ;;
741b042e37fSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7428bd17e5fSmrg        set fnord "$@"
7438bd17e5fSmrg        shift
7448bd17e5fSmrg        shift
7458bd17e5fSmrg        ;;
746b042e37fSmrg    *)
7478bd17e5fSmrg        set fnord "$@" "$arg"
7488bd17e5fSmrg        shift
7498bd17e5fSmrg        shift
7508bd17e5fSmrg        ;;
751b042e37fSmrg    esac
752b042e37fSmrg  done
753706b6b52Smrg  "$@" -E 2>/dev/null |
754706b6b52Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
755b042e37fSmrg  rm -f "$depfile"
756b042e37fSmrg  echo "$object : \\" > "$depfile"
7578bd17e5fSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7588bd17e5fSmrg  echo "$tab" >> "$depfile"
759706b6b52Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
760b042e37fSmrg  rm -f "$tmpdepfile"
761b042e37fSmrg  ;;
762b042e37fSmrg
763706b6b52Smrgmsvcmsys)
764706b6b52Smrg  # This case exists only to let depend.m4 do its work.  It works by
765706b6b52Smrg  # looking at the text of this script.  This case will never be run,
766706b6b52Smrg  # since it is checked for above.
767706b6b52Smrg  exit 1
768706b6b52Smrg  ;;
769706b6b52Smrg
770b042e37fSmrgnone)
771b042e37fSmrg  exec "$@"
772b042e37fSmrg  ;;
773b042e37fSmrg
774b042e37fSmrg*)
775b042e37fSmrg  echo "Unknown depmode $depmode" 1>&2
776b042e37fSmrg  exit 1
777b042e37fSmrg  ;;
778b042e37fSmrgesac
779b042e37fSmrg
780b042e37fSmrgexit 0
781b042e37fSmrg
782b042e37fSmrg# Local Variables:
783b042e37fSmrg# mode: shell-script
784b042e37fSmrg# sh-indentation: 2
785b042e37fSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
786b042e37fSmrg# time-stamp-start: "scriptversion="
787b042e37fSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
788706b6b52Smrg# time-stamp-time-zone: "UTC"
789706b6b52Smrg# time-stamp-end: "; # UTC"
790b042e37fSmrg# End:
791