10fa2845dSmrg#! /bin/sh
20fa2845dSmrg# depcomp - compile a program generating dependencies as side-effects
30fa2845dSmrg
4a0d387c7Smrgscriptversion=2018-03-07.03; # UTC
50fa2845dSmrg
6a0d387c7Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
70fa2845dSmrg
80fa2845dSmrg# This program is free software; you can redistribute it and/or modify
90fa2845dSmrg# it under the terms of the GNU General Public License as published by
100fa2845dSmrg# the Free Software Foundation; either version 2, or (at your option)
110fa2845dSmrg# any later version.
120fa2845dSmrg
130fa2845dSmrg# This program is distributed in the hope that it will be useful,
140fa2845dSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
150fa2845dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
160fa2845dSmrg# GNU General Public License for more details.
170fa2845dSmrg
180fa2845dSmrg# You should have received a copy of the GNU General Public License
19a0d387c7Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
200fa2845dSmrg
210fa2845dSmrg# As a special exception to the GNU General Public License, if you
220fa2845dSmrg# distribute this file as part of a program that contains a
230fa2845dSmrg# configuration script generated by Autoconf, you may include it under
240fa2845dSmrg# the same distribution terms that you use for the rest of that program.
250fa2845dSmrg
260fa2845dSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
270fa2845dSmrg
280fa2845dSmrgcase $1 in
290fa2845dSmrg  '')
30f66be5ecSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31f66be5ecSmrg    exit 1;
32f66be5ecSmrg    ;;
330fa2845dSmrg  -h | --h*)
340fa2845dSmrg    cat <<\EOF
350fa2845dSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
360fa2845dSmrg
370fa2845dSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
380fa2845dSmrgas side-effects.
390fa2845dSmrg
400fa2845dSmrgEnvironment variables:
410fa2845dSmrg  depmode     Dependency tracking mode.
42f66be5ecSmrg  source      Source file read by 'PROGRAMS ARGS'.
43f66be5ecSmrg  object      Object file output by 'PROGRAMS ARGS'.
440fa2845dSmrg  DEPDIR      directory where to store dependencies.
450fa2845dSmrg  depfile     Dependency file to output.
46f66be5ecSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
470fa2845dSmrg  libtool     Whether libtool is used (yes/no).
480fa2845dSmrg
490fa2845dSmrgReport bugs to <bug-automake@gnu.org>.
500fa2845dSmrgEOF
510fa2845dSmrg    exit $?
520fa2845dSmrg    ;;
530fa2845dSmrg  -v | --v*)
540fa2845dSmrg    echo "depcomp $scriptversion"
550fa2845dSmrg    exit $?
560fa2845dSmrg    ;;
570fa2845dSmrgesac
580fa2845dSmrg
59f66be5ecSmrg# Get the directory component of the given path, and save it in the
60f66be5ecSmrg# global variables '$dir'.  Note that this directory component will
61f66be5ecSmrg# be either empty or ending with a '/' character.  This is deliberate.
62f66be5ecSmrgset_dir_from ()
63f66be5ecSmrg{
64f66be5ecSmrg  case $1 in
65f66be5ecSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66f66be5ecSmrg      *) dir=;;
67f66be5ecSmrg  esac
68f66be5ecSmrg}
69f66be5ecSmrg
70f66be5ecSmrg# Get the suffix-stripped basename of the given path, and save it the
71f66be5ecSmrg# global variable '$base'.
72f66be5ecSmrgset_base_from ()
73f66be5ecSmrg{
74f66be5ecSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75f66be5ecSmrg}
76f66be5ecSmrg
77f66be5ecSmrg# If no dependency file was actually created by the compiler invocation,
78f66be5ecSmrg# we still have to create a dummy depfile, to avoid errors with the
79f66be5ecSmrg# Makefile "include basename.Plo" scheme.
80f66be5ecSmrgmake_dummy_depfile ()
81f66be5ecSmrg{
82f66be5ecSmrg  echo "#dummy" > "$depfile"
83f66be5ecSmrg}
84f66be5ecSmrg
85f66be5ecSmrg# Factor out some common post-processing of the generated depfile.
86f66be5ecSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87f66be5ecSmrgaix_post_process_depfile ()
88f66be5ecSmrg{
89f66be5ecSmrg  # If the compiler actually managed to produce a dependency file,
90f66be5ecSmrg  # post-process it.
91f66be5ecSmrg  if test -f "$tmpdepfile"; then
92f66be5ecSmrg    # Each line is of the form 'foo.o: dependency.h'.
93f66be5ecSmrg    # Do two passes, one to just change these to
94f66be5ecSmrg    #   $object: dependency.h
95f66be5ecSmrg    # and one to simply output
96f66be5ecSmrg    #   dependency.h:
97f66be5ecSmrg    # which is needed to avoid the deleted-header problem.
98f66be5ecSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99f66be5ecSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100f66be5ecSmrg    } > "$depfile"
101f66be5ecSmrg    rm -f "$tmpdepfile"
102f66be5ecSmrg  else
103f66be5ecSmrg    make_dummy_depfile
104f66be5ecSmrg  fi
105f66be5ecSmrg}
106f66be5ecSmrg
107f66be5ecSmrg# A tabulation character.
108f66be5ecSmrgtab='	'
109f66be5ecSmrg# A newline character.
110f66be5ecSmrgnl='
111f66be5ecSmrg'
112f66be5ecSmrg# Character ranges might be problematic outside the C locale.
113f66be5ecSmrg# These definitions help.
114f66be5ecSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115f66be5ecSmrglower=abcdefghijklmnopqrstuvwxyz
116f66be5ecSmrgdigits=0123456789
117f66be5ecSmrgalpha=${upper}${lower}
118f66be5ecSmrg
1190fa2845dSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1200fa2845dSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1210fa2845dSmrg  exit 1
1220fa2845dSmrgfi
1230fa2845dSmrg
1240fa2845dSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1250fa2845dSmrgdepfile=${depfile-`echo "$object" |
1260fa2845dSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1270fa2845dSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1280fa2845dSmrg
1290fa2845dSmrgrm -f "$tmpdepfile"
1300fa2845dSmrg
131f66be5ecSmrg# Avoid interferences from the environment.
132f66be5ecSmrggccflag= dashmflag=
133f66be5ecSmrg
1340fa2845dSmrg# Some modes work just like other modes, but use different flags.  We
1350fa2845dSmrg# parameterize here, but still list the modes in the big case below,
1360fa2845dSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1370fa2845dSmrg# here, because this file can only contain one case statement.
1380fa2845dSmrgif test "$depmode" = hp; then
1390fa2845dSmrg  # HP compiler uses -M and no extra arg.
1400fa2845dSmrg  gccflag=-M
1410fa2845dSmrg  depmode=gcc
1420fa2845dSmrgfi
1430fa2845dSmrg
1440fa2845dSmrgif test "$depmode" = dashXmstdout; then
145f66be5ecSmrg  # This is just like dashmstdout with a different argument.
146f66be5ecSmrg  dashmflag=-xM
147f66be5ecSmrg  depmode=dashmstdout
1480fa2845dSmrgfi
1490fa2845dSmrg
1507888fd0eSmrgcygpath_u="cygpath -u -f -"
1517888fd0eSmrgif test "$depmode" = msvcmsys; then
152f66be5ecSmrg  # This is just like msvisualcpp but w/o cygpath translation.
153f66be5ecSmrg  # Just convert the backslash-escaped backslashes to single forward
154f66be5ecSmrg  # slashes to satisfy depend.m4
155f66be5ecSmrg  cygpath_u='sed s,\\\\,/,g'
156f66be5ecSmrg  depmode=msvisualcpp
157f66be5ecSmrgfi
158f66be5ecSmrg
159f66be5ecSmrgif test "$depmode" = msvc7msys; then
160f66be5ecSmrg  # This is just like msvc7 but w/o cygpath translation.
161f66be5ecSmrg  # Just convert the backslash-escaped backslashes to single forward
162f66be5ecSmrg  # slashes to satisfy depend.m4
163f66be5ecSmrg  cygpath_u='sed s,\\\\,/,g'
164f66be5ecSmrg  depmode=msvc7
165f66be5ecSmrgfi
166f66be5ecSmrg
167f66be5ecSmrgif test "$depmode" = xlc; then
168f66be5ecSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169f66be5ecSmrg  gccflag=-qmakedep=gcc,-MF
170f66be5ecSmrg  depmode=gcc
1717888fd0eSmrgfi
1727888fd0eSmrg
1730fa2845dSmrgcase "$depmode" in
1740fa2845dSmrggcc3)
1750fa2845dSmrg## gcc 3 implements dependency tracking that does exactly what
1760fa2845dSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1770fa2845dSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1780fa2845dSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1790fa2845dSmrg## the command line argument order; so add the flags where they
1800fa2845dSmrg## appear in depend2.am.  Note that the slowdown incurred here
1810fa2845dSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1820fa2845dSmrg  for arg
1830fa2845dSmrg  do
1840fa2845dSmrg    case $arg in
1850fa2845dSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1860fa2845dSmrg    *)  set fnord "$@" "$arg" ;;
1870fa2845dSmrg    esac
1880fa2845dSmrg    shift # fnord
1890fa2845dSmrg    shift # $arg
1900fa2845dSmrg  done
1910fa2845dSmrg  "$@"
1920fa2845dSmrg  stat=$?
193f66be5ecSmrg  if test $stat -ne 0; then
1940fa2845dSmrg    rm -f "$tmpdepfile"
1950fa2845dSmrg    exit $stat
1960fa2845dSmrg  fi
1970fa2845dSmrg  mv "$tmpdepfile" "$depfile"
1980fa2845dSmrg  ;;
1990fa2845dSmrg
2000fa2845dSmrggcc)
201f66be5ecSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202f66be5ecSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203f66be5ecSmrg## (see the conditional assignment to $gccflag above).
2040fa2845dSmrg## There are various ways to get dependency output from gcc.  Here's
2050fa2845dSmrg## why we pick this rather obscure method:
2060fa2845dSmrg## - Don't want to use -MD because we'd like the dependencies to end
2070fa2845dSmrg##   up in a subdir.  Having to rename by hand is ugly.
2080fa2845dSmrg##   (We might end up doing this anyway to support other compilers.)
2090fa2845dSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210f66be5ecSmrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211f66be5ecSmrg##   supported by the other compilers which use the 'gcc' depmode.
2120fa2845dSmrg## - Using -M directly means running the compiler twice (even worse
2130fa2845dSmrg##   than renaming).
2140fa2845dSmrg  if test -z "$gccflag"; then
2150fa2845dSmrg    gccflag=-MD,
2160fa2845dSmrg  fi
2170fa2845dSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
2180fa2845dSmrg  stat=$?
219f66be5ecSmrg  if test $stat -ne 0; then
2200fa2845dSmrg    rm -f "$tmpdepfile"
2210fa2845dSmrg    exit $stat
2220fa2845dSmrg  fi
2230fa2845dSmrg  rm -f "$depfile"
2240fa2845dSmrg  echo "$object : \\" > "$depfile"
225f66be5ecSmrg  # The second -e expression handles DOS-style file names with drive
226f66be5ecSmrg  # letters.
2270fa2845dSmrg  sed -e 's/^[^:]*: / /' \
2280fa2845dSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229f66be5ecSmrg## This next piece of magic avoids the "deleted header file" problem.
2300fa2845dSmrg## The problem is that when a header file which appears in a .P file
2310fa2845dSmrg## is deleted, the dependency causes make to die (because there is
2320fa2845dSmrg## typically no way to rebuild the header).  We avoid this by adding
2330fa2845dSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2340fa2845dSmrg## this for us directly.
235f66be5ecSmrg## Some versions of gcc put a space before the ':'.  On the theory
2360fa2845dSmrg## that the space means something, we add a space to the output as
237f66be5ecSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238f66be5ecSmrg## to the object.  Take care to not repeat it in the output.
2390fa2845dSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
2400fa2845dSmrg## correctly.  Breaking it into two sed invocations is a workaround.
241f66be5ecSmrg  tr ' ' "$nl" < "$tmpdepfile" \
242f66be5ecSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243f66be5ecSmrg    | sed -e 's/$/ :/' >> "$depfile"
2440fa2845dSmrg  rm -f "$tmpdepfile"
2450fa2845dSmrg  ;;
2460fa2845dSmrg
2470fa2845dSmrghp)
2480fa2845dSmrg  # This case exists only to let depend.m4 do its work.  It works by
2490fa2845dSmrg  # looking at the text of this script.  This case will never be run,
2500fa2845dSmrg  # since it is checked for above.
2510fa2845dSmrg  exit 1
2520fa2845dSmrg  ;;
2530fa2845dSmrg
2540fa2845dSmrgsgi)
2550fa2845dSmrg  if test "$libtool" = yes; then
2560fa2845dSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2570fa2845dSmrg  else
2580fa2845dSmrg    "$@" -MDupdate "$tmpdepfile"
2590fa2845dSmrg  fi
2600fa2845dSmrg  stat=$?
261f66be5ecSmrg  if test $stat -ne 0; then
2620fa2845dSmrg    rm -f "$tmpdepfile"
2630fa2845dSmrg    exit $stat
2640fa2845dSmrg  fi
2650fa2845dSmrg  rm -f "$depfile"
2660fa2845dSmrg
2670fa2845dSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2680fa2845dSmrg    echo "$object : \\" > "$depfile"
2690fa2845dSmrg    # Clip off the initial element (the dependent).  Don't try to be
2700fa2845dSmrg    # clever and replace this with sed code, as IRIX sed won't handle
2710fa2845dSmrg    # lines with more than a fixed number of characters (4096 in
2720fa2845dSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273f66be5ecSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
2740fa2845dSmrg    # dependency line.
275f66be5ecSmrg    tr ' ' "$nl" < "$tmpdepfile" \
276f66be5ecSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277f66be5ecSmrg      | tr "$nl" ' ' >> "$depfile"
2787888fd0eSmrg    echo >> "$depfile"
2790fa2845dSmrg    # The second pass generates a dummy entry for each header file.
280f66be5ecSmrg    tr ' ' "$nl" < "$tmpdepfile" \
281f66be5ecSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282f66be5ecSmrg      >> "$depfile"
2830fa2845dSmrg  else
284f66be5ecSmrg    make_dummy_depfile
2850fa2845dSmrg  fi
2860fa2845dSmrg  rm -f "$tmpdepfile"
2870fa2845dSmrg  ;;
2880fa2845dSmrg
289f66be5ecSmrgxlc)
290f66be5ecSmrg  # This case exists only to let depend.m4 do its work.  It works by
291f66be5ecSmrg  # looking at the text of this script.  This case will never be run,
292f66be5ecSmrg  # since it is checked for above.
293f66be5ecSmrg  exit 1
294f66be5ecSmrg  ;;
295f66be5ecSmrg
2960fa2845dSmrgaix)
2970fa2845dSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
2980fa2845dSmrg  # in a .u file.  In older versions, this file always lives in the
299f66be5ecSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3000fa2845dSmrg  # start of each line; $object doesn't have directory information.
3010fa2845dSmrg  # Version 6 uses the directory in both cases.
302f66be5ecSmrg  set_dir_from "$object"
303f66be5ecSmrg  set_base_from "$object"
3040fa2845dSmrg  if test "$libtool" = yes; then
3057888fd0eSmrg    tmpdepfile1=$dir$base.u
3067888fd0eSmrg    tmpdepfile2=$base.u
3077888fd0eSmrg    tmpdepfile3=$dir.libs/$base.u
3080fa2845dSmrg    "$@" -Wc,-M
3090fa2845dSmrg  else
3107888fd0eSmrg    tmpdepfile1=$dir$base.u
3117888fd0eSmrg    tmpdepfile2=$dir$base.u
3127888fd0eSmrg    tmpdepfile3=$dir$base.u
3130fa2845dSmrg    "$@" -M
3140fa2845dSmrg  fi
3150fa2845dSmrg  stat=$?
316f66be5ecSmrg  if test $stat -ne 0; then
3177888fd0eSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3180fa2845dSmrg    exit $stat
3190fa2845dSmrg  fi
3200fa2845dSmrg
3217888fd0eSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3227888fd0eSmrg  do
3237888fd0eSmrg    test -f "$tmpdepfile" && break
3247888fd0eSmrg  done
325f66be5ecSmrg  aix_post_process_depfile
326f66be5ecSmrg  ;;
327f66be5ecSmrg
328f66be5ecSmrgtcc)
329f66be5ecSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330f66be5ecSmrg  # FIXME: That version still under development at the moment of writing.
331f66be5ecSmrg  #        Make that this statement remains true also for stable, released
332f66be5ecSmrg  #        versions.
333f66be5ecSmrg  # It will wrap lines (doesn't matter whether long or short) with a
334f66be5ecSmrg  # trailing '\', as in:
335f66be5ecSmrg  #
336f66be5ecSmrg  #   foo.o : \
337f66be5ecSmrg  #    foo.c \
338f66be5ecSmrg  #    foo.h \
339f66be5ecSmrg  #
340f66be5ecSmrg  # It will put a trailing '\' even on the last line, and will use leading
341f66be5ecSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342f66be5ecSmrg  # "Emit spaces for -MD").
343f66be5ecSmrg  "$@" -MD -MF "$tmpdepfile"
344f66be5ecSmrg  stat=$?
345f66be5ecSmrg  if test $stat -ne 0; then
346f66be5ecSmrg    rm -f "$tmpdepfile"
347f66be5ecSmrg    exit $stat
3480fa2845dSmrg  fi
349f66be5ecSmrg  rm -f "$depfile"
350f66be5ecSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351f66be5ecSmrg  # We have to change lines of the first kind to '$object: \'.
352f66be5ecSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353f66be5ecSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354f66be5ecSmrg  # dummy dependency, to avoid the deleted-header problem.
355f66be5ecSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3560fa2845dSmrg  rm -f "$tmpdepfile"
3570fa2845dSmrg  ;;
3580fa2845dSmrg
359f66be5ecSmrg## The order of this option in the case statement is important, since the
360f66be5ecSmrg## shell code in configure will try each of these formats in the order
361f66be5ecSmrg## listed in this file.  A plain '-MD' option would be understood by many
362f66be5ecSmrg## compilers, so we must ensure this comes after the gcc and icc options.
363f66be5ecSmrgpgcc)
364f66be5ecSmrg  # Portland's C compiler understands '-MD'.
365f66be5ecSmrg  # Will always output deps to 'file.d' where file is the root name of the
366f66be5ecSmrg  # source file under compilation, even if file resides in a subdirectory.
367f66be5ecSmrg  # The object file name does not affect the name of the '.d' file.
368f66be5ecSmrg  # pgcc 10.2 will output
3690fa2845dSmrg  #    foo.o: sub/foo.c sub/foo.h
370f66be5ecSmrg  # and will wrap long lines using '\' :
3710fa2845dSmrg  #    foo.o: sub/foo.c ... \
3720fa2845dSmrg  #     sub/foo.h ... \
3730fa2845dSmrg  #     ...
374f66be5ecSmrg  set_dir_from "$object"
375f66be5ecSmrg  # Use the source, not the object, to determine the base name, since
376f66be5ecSmrg  # that's sadly what pgcc will do too.
377f66be5ecSmrg  set_base_from "$source"
378f66be5ecSmrg  tmpdepfile=$base.d
379f66be5ecSmrg
380f66be5ecSmrg  # For projects that build the same source file twice into different object
381f66be5ecSmrg  # files, the pgcc approach of using the *source* file root name can cause
382f66be5ecSmrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383f66be5ecSmrg  # the same $tmpdepfile.
384f66be5ecSmrg  lockdir=$base.d-lock
385f66be5ecSmrg  trap "
386f66be5ecSmrg    echo '$0: caught signal, cleaning up...' >&2
387f66be5ecSmrg    rmdir '$lockdir'
388f66be5ecSmrg    exit 1
389f66be5ecSmrg  " 1 2 13 15
390f66be5ecSmrg  numtries=100
391f66be5ecSmrg  i=$numtries
392f66be5ecSmrg  while test $i -gt 0; do
393f66be5ecSmrg    # mkdir is a portable test-and-set.
394f66be5ecSmrg    if mkdir "$lockdir" 2>/dev/null; then
395f66be5ecSmrg      # This process acquired the lock.
396f66be5ecSmrg      "$@" -MD
397f66be5ecSmrg      stat=$?
398f66be5ecSmrg      # Release the lock.
399f66be5ecSmrg      rmdir "$lockdir"
400f66be5ecSmrg      break
401f66be5ecSmrg    else
402f66be5ecSmrg      # If the lock is being held by a different process, wait
403f66be5ecSmrg      # until the winning process is done or we timeout.
404f66be5ecSmrg      while test -d "$lockdir" && test $i -gt 0; do
405f66be5ecSmrg        sleep 1
406f66be5ecSmrg        i=`expr $i - 1`
407f66be5ecSmrg      done
408f66be5ecSmrg    fi
409f66be5ecSmrg    i=`expr $i - 1`
410f66be5ecSmrg  done
411f66be5ecSmrg  trap - 1 2 13 15
412f66be5ecSmrg  if test $i -le 0; then
413f66be5ecSmrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414f66be5ecSmrg    echo "$0: check lockdir '$lockdir'" >&2
415f66be5ecSmrg    exit 1
416f66be5ecSmrg  fi
4170fa2845dSmrg
418f66be5ecSmrg  if test $stat -ne 0; then
4190fa2845dSmrg    rm -f "$tmpdepfile"
4200fa2845dSmrg    exit $stat
4210fa2845dSmrg  fi
4220fa2845dSmrg  rm -f "$depfile"
4230fa2845dSmrg  # Each line is of the form `foo.o: dependent.h',
4240fa2845dSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4250fa2845dSmrg  # Do two passes, one to just change these to
4260fa2845dSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4270fa2845dSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4280fa2845dSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4290fa2845dSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
430f66be5ecSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431f66be5ecSmrg    | sed -e 's/$/ :/' >> "$depfile"
4320fa2845dSmrg  rm -f "$tmpdepfile"
4330fa2845dSmrg  ;;
4340fa2845dSmrg
4350fa2845dSmrghp2)
4360fa2845dSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4370fa2845dSmrg  # compilers, which have integrated preprocessors.  The correct option
4380fa2845dSmrg  # to use with these is +Maked; it writes dependencies to a file named
4390fa2845dSmrg  # 'foo.d', which lands next to the object file, wherever that
4400fa2845dSmrg  # happens to be.
4410fa2845dSmrg  # Much of this is similar to the tru64 case; see comments there.
442f66be5ecSmrg  set_dir_from  "$object"
443f66be5ecSmrg  set_base_from "$object"
4440fa2845dSmrg  if test "$libtool" = yes; then
4450fa2845dSmrg    tmpdepfile1=$dir$base.d
4460fa2845dSmrg    tmpdepfile2=$dir.libs/$base.d
4470fa2845dSmrg    "$@" -Wc,+Maked
4480fa2845dSmrg  else
4490fa2845dSmrg    tmpdepfile1=$dir$base.d
4500fa2845dSmrg    tmpdepfile2=$dir$base.d
4510fa2845dSmrg    "$@" +Maked
4520fa2845dSmrg  fi
4530fa2845dSmrg  stat=$?
454f66be5ecSmrg  if test $stat -ne 0; then
4550fa2845dSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4560fa2845dSmrg     exit $stat
4570fa2845dSmrg  fi
4580fa2845dSmrg
4590fa2845dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4600fa2845dSmrg  do
4610fa2845dSmrg    test -f "$tmpdepfile" && break
4620fa2845dSmrg  done
4630fa2845dSmrg  if test -f "$tmpdepfile"; then
464f66be5ecSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465f66be5ecSmrg    # Add 'dependent.h:' lines.
4667888fd0eSmrg    sed -ne '2,${
467f66be5ecSmrg               s/^ *//
468f66be5ecSmrg               s/ \\*$//
469f66be5ecSmrg               s/$/:/
470f66be5ecSmrg               p
471f66be5ecSmrg             }' "$tmpdepfile" >> "$depfile"
4720fa2845dSmrg  else
473f66be5ecSmrg    make_dummy_depfile
4740fa2845dSmrg  fi
4750fa2845dSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4760fa2845dSmrg  ;;
4770fa2845dSmrg
4780fa2845dSmrgtru64)
479f66be5ecSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480f66be5ecSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481f66be5ecSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482f66be5ecSmrg  # dependencies in 'foo.d' instead, so we check for that too.
483f66be5ecSmrg  # Subdirectories are respected.
484f66be5ecSmrg  set_dir_from  "$object"
485f66be5ecSmrg  set_base_from "$object"
486f66be5ecSmrg
487f66be5ecSmrg  if test "$libtool" = yes; then
488f66be5ecSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489f66be5ecSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490f66be5ecSmrg    # in $dir$base.o.d.  We have to check for both files, because
491f66be5ecSmrg    # one of the two compilations can be disabled.  We should prefer
492f66be5ecSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493f66be5ecSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
494f66be5ecSmrg    # the former would cause a distcleancheck panic.
495f66be5ecSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496f66be5ecSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497f66be5ecSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498f66be5ecSmrg    "$@" -Wc,-MD
499f66be5ecSmrg  else
500f66be5ecSmrg    tmpdepfile1=$dir$base.d
501f66be5ecSmrg    tmpdepfile2=$dir$base.d
502f66be5ecSmrg    tmpdepfile3=$dir$base.d
503f66be5ecSmrg    "$@" -MD
504f66be5ecSmrg  fi
505f66be5ecSmrg
506f66be5ecSmrg  stat=$?
507f66be5ecSmrg  if test $stat -ne 0; then
508f66be5ecSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509f66be5ecSmrg    exit $stat
510f66be5ecSmrg  fi
511f66be5ecSmrg
512f66be5ecSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513f66be5ecSmrg  do
514f66be5ecSmrg    test -f "$tmpdepfile" && break
515f66be5ecSmrg  done
516f66be5ecSmrg  # Same post-processing that is required for AIX mode.
517f66be5ecSmrg  aix_post_process_depfile
518f66be5ecSmrg  ;;
519f66be5ecSmrg
520f66be5ecSmrgmsvc7)
521f66be5ecSmrg  if test "$libtool" = yes; then
522f66be5ecSmrg    showIncludes=-Wc,-showIncludes
523f66be5ecSmrg  else
524f66be5ecSmrg    showIncludes=-showIncludes
525f66be5ecSmrg  fi
526f66be5ecSmrg  "$@" $showIncludes > "$tmpdepfile"
527f66be5ecSmrg  stat=$?
528f66be5ecSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
529f66be5ecSmrg  if test $stat -ne 0; then
530f66be5ecSmrg    rm -f "$tmpdepfile"
531f66be5ecSmrg    exit $stat
532f66be5ecSmrg  fi
533f66be5ecSmrg  rm -f "$depfile"
534f66be5ecSmrg  echo "$object : \\" > "$depfile"
535f66be5ecSmrg  # The first sed program below extracts the file names and escapes
536f66be5ecSmrg  # backslashes for cygpath.  The second sed program outputs the file
537f66be5ecSmrg  # name when reading, but also accumulates all include files in the
538f66be5ecSmrg  # hold buffer in order to output them again at the end.  This only
539f66be5ecSmrg  # works with sed implementations that can handle large buffers.
540f66be5ecSmrg  sed < "$tmpdepfile" -n '
541f66be5ecSmrg/^Note: including file:  *\(.*\)/ {
542f66be5ecSmrg  s//\1/
543f66be5ecSmrg  s/\\/\\\\/g
544f66be5ecSmrg  p
545f66be5ecSmrg}' | $cygpath_u | sort -u | sed -n '
546f66be5ecSmrgs/ /\\ /g
547f66be5ecSmrgs/\(.*\)/'"$tab"'\1 \\/p
548f66be5ecSmrgs/.\(.*\) \\/\1:/
549f66be5ecSmrgH
550f66be5ecSmrg$ {
551f66be5ecSmrg  s/.*/'"$tab"'/
552f66be5ecSmrg  G
553f66be5ecSmrg  p
554f66be5ecSmrg}' >> "$depfile"
555f66be5ecSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556f66be5ecSmrg  rm -f "$tmpdepfile"
557f66be5ecSmrg  ;;
558f66be5ecSmrg
559f66be5ecSmrgmsvc7msys)
560f66be5ecSmrg  # This case exists only to let depend.m4 do its work.  It works by
561f66be5ecSmrg  # looking at the text of this script.  This case will never be run,
562f66be5ecSmrg  # since it is checked for above.
563f66be5ecSmrg  exit 1
564f66be5ecSmrg  ;;
5650fa2845dSmrg
5660fa2845dSmrg#nosideeffect)
5670fa2845dSmrg  # This comment above is used by automake to tell side-effect
5680fa2845dSmrg  # dependency tracking mechanisms from slower ones.
5690fa2845dSmrg
5700fa2845dSmrgdashmstdout)
5710fa2845dSmrg  # Important note: in order to support this mode, a compiler *must*
5720fa2845dSmrg  # always write the preprocessed file to stdout, regardless of -o.
5730fa2845dSmrg  "$@" || exit $?
5740fa2845dSmrg
5750fa2845dSmrg  # Remove the call to Libtool.
5760fa2845dSmrg  if test "$libtool" = yes; then
5777888fd0eSmrg    while test "X$1" != 'X--mode=compile'; do
5780fa2845dSmrg      shift
5790fa2845dSmrg    done
5800fa2845dSmrg    shift
5810fa2845dSmrg  fi
5820fa2845dSmrg
583f66be5ecSmrg  # Remove '-o $object'.
5840fa2845dSmrg  IFS=" "
5850fa2845dSmrg  for arg
5860fa2845dSmrg  do
5870fa2845dSmrg    case $arg in
5880fa2845dSmrg    -o)
5890fa2845dSmrg      shift
5900fa2845dSmrg      ;;
5910fa2845dSmrg    $object)
5920fa2845dSmrg      shift
5930fa2845dSmrg      ;;
5940fa2845dSmrg    *)
5950fa2845dSmrg      set fnord "$@" "$arg"
5960fa2845dSmrg      shift # fnord
5970fa2845dSmrg      shift # $arg
5980fa2845dSmrg      ;;
5990fa2845dSmrg    esac
6000fa2845dSmrg  done
6010fa2845dSmrg
6020fa2845dSmrg  test -z "$dashmflag" && dashmflag=-M
603f66be5ecSmrg  # Require at least two characters before searching for ':'
6040fa2845dSmrg  # in the target name.  This is to cope with DOS-style filenames:
605f66be5ecSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6060fa2845dSmrg  "$@" $dashmflag |
607f66be5ecSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6080fa2845dSmrg  rm -f "$depfile"
6090fa2845dSmrg  cat < "$tmpdepfile" > "$depfile"
610f66be5ecSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611f66be5ecSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
612f66be5ecSmrg  tr ' ' "$nl" < "$tmpdepfile" \
613f66be5ecSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614f66be5ecSmrg    | sed -e 's/$/ :/' >> "$depfile"
6150fa2845dSmrg  rm -f "$tmpdepfile"
6160fa2845dSmrg  ;;
6170fa2845dSmrg
6180fa2845dSmrgdashXmstdout)
6190fa2845dSmrg  # This case only exists to satisfy depend.m4.  It is never actually
6200fa2845dSmrg  # run, as this mode is specially recognized in the preamble.
6210fa2845dSmrg  exit 1
6220fa2845dSmrg  ;;
6230fa2845dSmrg
6240fa2845dSmrgmakedepend)
6250fa2845dSmrg  "$@" || exit $?
6260fa2845dSmrg  # Remove any Libtool call
6270fa2845dSmrg  if test "$libtool" = yes; then
6287888fd0eSmrg    while test "X$1" != 'X--mode=compile'; do
6290fa2845dSmrg      shift
6300fa2845dSmrg    done
6310fa2845dSmrg    shift
6320fa2845dSmrg  fi
6330fa2845dSmrg  # X makedepend
6340fa2845dSmrg  shift
6357888fd0eSmrg  cleared=no eat=no
6367888fd0eSmrg  for arg
6377888fd0eSmrg  do
6380fa2845dSmrg    case $cleared in
6390fa2845dSmrg    no)
6400fa2845dSmrg      set ""; shift
6410fa2845dSmrg      cleared=yes ;;
6420fa2845dSmrg    esac
6437888fd0eSmrg    if test $eat = yes; then
6447888fd0eSmrg      eat=no
6457888fd0eSmrg      continue
6467888fd0eSmrg    fi
6470fa2845dSmrg    case "$arg" in
6480fa2845dSmrg    -D*|-I*)
6490fa2845dSmrg      set fnord "$@" "$arg"; shift ;;
6500fa2845dSmrg    # Strip any option that makedepend may not understand.  Remove
6510fa2845dSmrg    # the object too, otherwise makedepend will parse it as a source file.
6527888fd0eSmrg    -arch)
6537888fd0eSmrg      eat=yes ;;
6540fa2845dSmrg    -*|$object)
6550fa2845dSmrg      ;;
6560fa2845dSmrg    *)
6570fa2845dSmrg      set fnord "$@" "$arg"; shift ;;
6580fa2845dSmrg    esac
6590fa2845dSmrg  done
6607888fd0eSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6610fa2845dSmrg  touch "$tmpdepfile"
6620fa2845dSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6630fa2845dSmrg  rm -f "$depfile"
664f66be5ecSmrg  # makedepend may prepend the VPATH from the source file name to the object.
665f66be5ecSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666f66be5ecSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667f66be5ecSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668f66be5ecSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
669f66be5ecSmrg  sed '1,2d' "$tmpdepfile" \
670f66be5ecSmrg    | tr ' ' "$nl" \
671f66be5ecSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672f66be5ecSmrg    | sed -e 's/$/ :/' >> "$depfile"
6730fa2845dSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6740fa2845dSmrg  ;;
6750fa2845dSmrg
6760fa2845dSmrgcpp)
6770fa2845dSmrg  # Important note: in order to support this mode, a compiler *must*
6780fa2845dSmrg  # always write the preprocessed file to stdout.
6790fa2845dSmrg  "$@" || exit $?
6800fa2845dSmrg
6810fa2845dSmrg  # Remove the call to Libtool.
6820fa2845dSmrg  if test "$libtool" = yes; then
6837888fd0eSmrg    while test "X$1" != 'X--mode=compile'; do
6840fa2845dSmrg      shift
6850fa2845dSmrg    done
6860fa2845dSmrg    shift
6870fa2845dSmrg  fi
6880fa2845dSmrg
689f66be5ecSmrg  # Remove '-o $object'.
6900fa2845dSmrg  IFS=" "
6910fa2845dSmrg  for arg
6920fa2845dSmrg  do
6930fa2845dSmrg    case $arg in
6940fa2845dSmrg    -o)
6950fa2845dSmrg      shift
6960fa2845dSmrg      ;;
6970fa2845dSmrg    $object)
6980fa2845dSmrg      shift
6990fa2845dSmrg      ;;
7000fa2845dSmrg    *)
7010fa2845dSmrg      set fnord "$@" "$arg"
7020fa2845dSmrg      shift # fnord
7030fa2845dSmrg      shift # $arg
7040fa2845dSmrg      ;;
7050fa2845dSmrg    esac
7060fa2845dSmrg  done
7070fa2845dSmrg
708f66be5ecSmrg  "$@" -E \
709f66be5ecSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710f66be5ecSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711f66be5ecSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
7120fa2845dSmrg  rm -f "$depfile"
7130fa2845dSmrg  echo "$object : \\" > "$depfile"
7140fa2845dSmrg  cat < "$tmpdepfile" >> "$depfile"
7150fa2845dSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7160fa2845dSmrg  rm -f "$tmpdepfile"
7170fa2845dSmrg  ;;
7180fa2845dSmrg
7190fa2845dSmrgmsvisualcpp)
7200fa2845dSmrg  # Important note: in order to support this mode, a compiler *must*
7217888fd0eSmrg  # always write the preprocessed file to stdout.
7220fa2845dSmrg  "$@" || exit $?
7237888fd0eSmrg
7247888fd0eSmrg  # Remove the call to Libtool.
7257888fd0eSmrg  if test "$libtool" = yes; then
7267888fd0eSmrg    while test "X$1" != 'X--mode=compile'; do
7277888fd0eSmrg      shift
7287888fd0eSmrg    done
7297888fd0eSmrg    shift
7307888fd0eSmrg  fi
7317888fd0eSmrg
7320fa2845dSmrg  IFS=" "
7330fa2845dSmrg  for arg
7340fa2845dSmrg  do
7350fa2845dSmrg    case "$arg" in
7367888fd0eSmrg    -o)
7377888fd0eSmrg      shift
7387888fd0eSmrg      ;;
7397888fd0eSmrg    $object)
7407888fd0eSmrg      shift
7417888fd0eSmrg      ;;
7420fa2845dSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743f66be5ecSmrg        set fnord "$@"
744f66be5ecSmrg        shift
745f66be5ecSmrg        shift
746f66be5ecSmrg        ;;
7470fa2845dSmrg    *)
748f66be5ecSmrg        set fnord "$@" "$arg"
749f66be5ecSmrg        shift
750f66be5ecSmrg        shift
751f66be5ecSmrg        ;;
7520fa2845dSmrg    esac
7530fa2845dSmrg  done
7547888fd0eSmrg  "$@" -E 2>/dev/null |
7557888fd0eSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7560fa2845dSmrg  rm -f "$depfile"
7570fa2845dSmrg  echo "$object : \\" > "$depfile"
758f66be5ecSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759f66be5ecSmrg  echo "$tab" >> "$depfile"
7607888fd0eSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7610fa2845dSmrg  rm -f "$tmpdepfile"
7620fa2845dSmrg  ;;
7630fa2845dSmrg
7647888fd0eSmrgmsvcmsys)
7657888fd0eSmrg  # This case exists only to let depend.m4 do its work.  It works by
7667888fd0eSmrg  # looking at the text of this script.  This case will never be run,
7677888fd0eSmrg  # since it is checked for above.
7687888fd0eSmrg  exit 1
7697888fd0eSmrg  ;;
7707888fd0eSmrg
7710fa2845dSmrgnone)
7720fa2845dSmrg  exec "$@"
7730fa2845dSmrg  ;;
7740fa2845dSmrg
7750fa2845dSmrg*)
7760fa2845dSmrg  echo "Unknown depmode $depmode" 1>&2
7770fa2845dSmrg  exit 1
7780fa2845dSmrg  ;;
7790fa2845dSmrgesac
7800fa2845dSmrg
7810fa2845dSmrgexit 0
7820fa2845dSmrg
7830fa2845dSmrg# Local Variables:
7840fa2845dSmrg# mode: shell-script
7850fa2845dSmrg# sh-indentation: 2
786a0d387c7Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
7870fa2845dSmrg# time-stamp-start: "scriptversion="
7880fa2845dSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789a0d387c7Smrg# time-stamp-time-zone: "UTC0"
7907888fd0eSmrg# time-stamp-end: "; # UTC"
7910fa2845dSmrg# End:
792