depcomp revision f010a93d
115fb4814Smrg#! /bin/sh
215fb4814Smrg# depcomp - compile a program generating dependencies as side-effects
315fb4814Smrg
4f010a93dSmrgscriptversion=2018-03-07.03; # UTC
515fb4814Smrg
6f010a93dSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
715fb4814Smrg
815fb4814Smrg# This program is free software; you can redistribute it and/or modify
915fb4814Smrg# it under the terms of the GNU General Public License as published by
1015fb4814Smrg# the Free Software Foundation; either version 2, or (at your option)
1115fb4814Smrg# any later version.
1215fb4814Smrg
1315fb4814Smrg# This program is distributed in the hope that it will be useful,
1415fb4814Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1515fb4814Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1615fb4814Smrg# GNU General Public License for more details.
1715fb4814Smrg
1815fb4814Smrg# You should have received a copy of the GNU General Public License
19f010a93dSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2015fb4814Smrg
2115fb4814Smrg# As a special exception to the GNU General Public License, if you
2215fb4814Smrg# distribute this file as part of a program that contains a
2315fb4814Smrg# configuration script generated by Autoconf, you may include it under
2415fb4814Smrg# the same distribution terms that you use for the rest of that program.
2515fb4814Smrg
2615fb4814Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2715fb4814Smrg
2815fb4814Smrgcase $1 in
2915fb4814Smrg  '')
30cf503b78Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31cf503b78Smrg    exit 1;
32cf503b78Smrg    ;;
3315fb4814Smrg  -h | --h*)
3415fb4814Smrg    cat <<\EOF
3515fb4814SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3615fb4814Smrg
3715fb4814SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3815fb4814Smrgas side-effects.
3915fb4814Smrg
4015fb4814SmrgEnvironment variables:
4115fb4814Smrg  depmode     Dependency tracking mode.
42cf503b78Smrg  source      Source file read by 'PROGRAMS ARGS'.
43cf503b78Smrg  object      Object file output by 'PROGRAMS ARGS'.
4415fb4814Smrg  DEPDIR      directory where to store dependencies.
4515fb4814Smrg  depfile     Dependency file to output.
46cf503b78Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
4715fb4814Smrg  libtool     Whether libtool is used (yes/no).
4815fb4814Smrg
4915fb4814SmrgReport bugs to <bug-automake@gnu.org>.
5015fb4814SmrgEOF
5115fb4814Smrg    exit $?
5215fb4814Smrg    ;;
5315fb4814Smrg  -v | --v*)
5415fb4814Smrg    echo "depcomp $scriptversion"
5515fb4814Smrg    exit $?
5615fb4814Smrg    ;;
5715fb4814Smrgesac
5815fb4814Smrg
59cf503b78Smrg# Get the directory component of the given path, and save it in the
60cf503b78Smrg# global variables '$dir'.  Note that this directory component will
61cf503b78Smrg# be either empty or ending with a '/' character.  This is deliberate.
62cf503b78Smrgset_dir_from ()
63cf503b78Smrg{
64cf503b78Smrg  case $1 in
65cf503b78Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66cf503b78Smrg      *) dir=;;
67cf503b78Smrg  esac
68cf503b78Smrg}
69cf503b78Smrg
70cf503b78Smrg# Get the suffix-stripped basename of the given path, and save it the
71cf503b78Smrg# global variable '$base'.
72cf503b78Smrgset_base_from ()
73cf503b78Smrg{
74cf503b78Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75cf503b78Smrg}
76cf503b78Smrg
77cf503b78Smrg# If no dependency file was actually created by the compiler invocation,
78cf503b78Smrg# we still have to create a dummy depfile, to avoid errors with the
79cf503b78Smrg# Makefile "include basename.Plo" scheme.
80cf503b78Smrgmake_dummy_depfile ()
81cf503b78Smrg{
82cf503b78Smrg  echo "#dummy" > "$depfile"
83cf503b78Smrg}
84cf503b78Smrg
85cf503b78Smrg# Factor out some common post-processing of the generated depfile.
86cf503b78Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87cf503b78Smrgaix_post_process_depfile ()
88cf503b78Smrg{
89cf503b78Smrg  # If the compiler actually managed to produce a dependency file,
90cf503b78Smrg  # post-process it.
91cf503b78Smrg  if test -f "$tmpdepfile"; then
92cf503b78Smrg    # Each line is of the form 'foo.o: dependency.h'.
93cf503b78Smrg    # Do two passes, one to just change these to
94cf503b78Smrg    #   $object: dependency.h
95cf503b78Smrg    # and one to simply output
96cf503b78Smrg    #   dependency.h:
97cf503b78Smrg    # which is needed to avoid the deleted-header problem.
98cf503b78Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99cf503b78Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100cf503b78Smrg    } > "$depfile"
101cf503b78Smrg    rm -f "$tmpdepfile"
102cf503b78Smrg  else
103cf503b78Smrg    make_dummy_depfile
104cf503b78Smrg  fi
105cf503b78Smrg}
106cf503b78Smrg
107cf503b78Smrg# A tabulation character.
108cf503b78Smrgtab='	'
109cf503b78Smrg# A newline character.
110cf503b78Smrgnl='
111cf503b78Smrg'
112cf503b78Smrg# Character ranges might be problematic outside the C locale.
113cf503b78Smrg# These definitions help.
114cf503b78Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115cf503b78Smrglower=abcdefghijklmnopqrstuvwxyz
116cf503b78Smrgdigits=0123456789
117cf503b78Smrgalpha=${upper}${lower}
118cf503b78Smrg
11915fb4814Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12015fb4814Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12115fb4814Smrg  exit 1
12215fb4814Smrgfi
12315fb4814Smrg
12415fb4814Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12515fb4814Smrgdepfile=${depfile-`echo "$object" |
12615fb4814Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12715fb4814Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12815fb4814Smrg
12915fb4814Smrgrm -f "$tmpdepfile"
13015fb4814Smrg
131cf503b78Smrg# Avoid interferences from the environment.
132cf503b78Smrggccflag= dashmflag=
133cf503b78Smrg
13415fb4814Smrg# Some modes work just like other modes, but use different flags.  We
13515fb4814Smrg# parameterize here, but still list the modes in the big case below,
13615fb4814Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13715fb4814Smrg# here, because this file can only contain one case statement.
13815fb4814Smrgif test "$depmode" = hp; then
13915fb4814Smrg  # HP compiler uses -M and no extra arg.
14015fb4814Smrg  gccflag=-M
14115fb4814Smrg  depmode=gcc
14215fb4814Smrgfi
14315fb4814Smrg
14415fb4814Smrgif test "$depmode" = dashXmstdout; then
145cf503b78Smrg  # This is just like dashmstdout with a different argument.
146cf503b78Smrg  dashmflag=-xM
147cf503b78Smrg  depmode=dashmstdout
14815fb4814Smrgfi
14915fb4814Smrg
150b4d38c65Smrgcygpath_u="cygpath -u -f -"
151b4d38c65Smrgif test "$depmode" = msvcmsys; then
152cf503b78Smrg  # This is just like msvisualcpp but w/o cygpath translation.
153cf503b78Smrg  # Just convert the backslash-escaped backslashes to single forward
154cf503b78Smrg  # slashes to satisfy depend.m4
155cf503b78Smrg  cygpath_u='sed s,\\\\,/,g'
156cf503b78Smrg  depmode=msvisualcpp
157cf503b78Smrgfi
158cf503b78Smrg
159cf503b78Smrgif test "$depmode" = msvc7msys; then
160cf503b78Smrg  # This is just like msvc7 but w/o cygpath translation.
161cf503b78Smrg  # Just convert the backslash-escaped backslashes to single forward
162cf503b78Smrg  # slashes to satisfy depend.m4
163cf503b78Smrg  cygpath_u='sed s,\\\\,/,g'
164cf503b78Smrg  depmode=msvc7
165cf503b78Smrgfi
166cf503b78Smrg
167cf503b78Smrgif test "$depmode" = xlc; then
168cf503b78Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169cf503b78Smrg  gccflag=-qmakedep=gcc,-MF
170cf503b78Smrg  depmode=gcc
171b4d38c65Smrgfi
172b4d38c65Smrg
17315fb4814Smrgcase "$depmode" in
17415fb4814Smrggcc3)
17515fb4814Smrg## gcc 3 implements dependency tracking that does exactly what
17615fb4814Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17715fb4814Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178de78e416Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179de78e416Smrg## the command line argument order; so add the flags where they
180de78e416Smrg## appear in depend2.am.  Note that the slowdown incurred here
181de78e416Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182de78e416Smrg  for arg
183de78e416Smrg  do
184de78e416Smrg    case $arg in
185de78e416Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186de78e416Smrg    *)  set fnord "$@" "$arg" ;;
187de78e416Smrg    esac
188de78e416Smrg    shift # fnord
189de78e416Smrg    shift # $arg
190de78e416Smrg  done
191de78e416Smrg  "$@"
19215fb4814Smrg  stat=$?
193cf503b78Smrg  if test $stat -ne 0; then
19415fb4814Smrg    rm -f "$tmpdepfile"
19515fb4814Smrg    exit $stat
19615fb4814Smrg  fi
19715fb4814Smrg  mv "$tmpdepfile" "$depfile"
19815fb4814Smrg  ;;
19915fb4814Smrg
20015fb4814Smrggcc)
201cf503b78Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202cf503b78Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203cf503b78Smrg## (see the conditional assignment to $gccflag above).
20415fb4814Smrg## There are various ways to get dependency output from gcc.  Here's
20515fb4814Smrg## why we pick this rather obscure method:
20615fb4814Smrg## - Don't want to use -MD because we'd like the dependencies to end
20715fb4814Smrg##   up in a subdir.  Having to rename by hand is ugly.
20815fb4814Smrg##   (We might end up doing this anyway to support other compilers.)
20915fb4814Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210cf503b78Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211cf503b78Smrg##   supported by the other compilers which use the 'gcc' depmode.
21215fb4814Smrg## - Using -M directly means running the compiler twice (even worse
21315fb4814Smrg##   than renaming).
21415fb4814Smrg  if test -z "$gccflag"; then
21515fb4814Smrg    gccflag=-MD,
21615fb4814Smrg  fi
21715fb4814Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
21815fb4814Smrg  stat=$?
219cf503b78Smrg  if test $stat -ne 0; then
22015fb4814Smrg    rm -f "$tmpdepfile"
22115fb4814Smrg    exit $stat
22215fb4814Smrg  fi
22315fb4814Smrg  rm -f "$depfile"
22415fb4814Smrg  echo "$object : \\" > "$depfile"
225cf503b78Smrg  # The second -e expression handles DOS-style file names with drive
226cf503b78Smrg  # letters.
22715fb4814Smrg  sed -e 's/^[^:]*: / /' \
22815fb4814Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229cf503b78Smrg## This next piece of magic avoids the "deleted header file" problem.
23015fb4814Smrg## The problem is that when a header file which appears in a .P file
23115fb4814Smrg## is deleted, the dependency causes make to die (because there is
23215fb4814Smrg## typically no way to rebuild the header).  We avoid this by adding
23315fb4814Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23415fb4814Smrg## this for us directly.
235cf503b78Smrg## Some versions of gcc put a space before the ':'.  On the theory
23615fb4814Smrg## that the space means something, we add a space to the output as
237cf503b78Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238cf503b78Smrg## to the object.  Take care to not repeat it in the output.
23915fb4814Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
24015fb4814Smrg## correctly.  Breaking it into two sed invocations is a workaround.
241cf503b78Smrg  tr ' ' "$nl" < "$tmpdepfile" \
242cf503b78Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243cf503b78Smrg    | sed -e 's/$/ :/' >> "$depfile"
24415fb4814Smrg  rm -f "$tmpdepfile"
24515fb4814Smrg  ;;
24615fb4814Smrg
24715fb4814Smrghp)
24815fb4814Smrg  # This case exists only to let depend.m4 do its work.  It works by
24915fb4814Smrg  # looking at the text of this script.  This case will never be run,
25015fb4814Smrg  # since it is checked for above.
25115fb4814Smrg  exit 1
25215fb4814Smrg  ;;
25315fb4814Smrg
25415fb4814Smrgsgi)
25515fb4814Smrg  if test "$libtool" = yes; then
25615fb4814Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25715fb4814Smrg  else
25815fb4814Smrg    "$@" -MDupdate "$tmpdepfile"
25915fb4814Smrg  fi
26015fb4814Smrg  stat=$?
261cf503b78Smrg  if test $stat -ne 0; then
26215fb4814Smrg    rm -f "$tmpdepfile"
26315fb4814Smrg    exit $stat
26415fb4814Smrg  fi
26515fb4814Smrg  rm -f "$depfile"
26615fb4814Smrg
26715fb4814Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26815fb4814Smrg    echo "$object : \\" > "$depfile"
26915fb4814Smrg    # Clip off the initial element (the dependent).  Don't try to be
27015fb4814Smrg    # clever and replace this with sed code, as IRIX sed won't handle
27115fb4814Smrg    # lines with more than a fixed number of characters (4096 in
27215fb4814Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273cf503b78Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
27415fb4814Smrg    # dependency line.
275cf503b78Smrg    tr ' ' "$nl" < "$tmpdepfile" \
276cf503b78Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277cf503b78Smrg      | tr "$nl" ' ' >> "$depfile"
278b4d38c65Smrg    echo >> "$depfile"
27915fb4814Smrg    # The second pass generates a dummy entry for each header file.
280cf503b78Smrg    tr ' ' "$nl" < "$tmpdepfile" \
281cf503b78Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282cf503b78Smrg      >> "$depfile"
28315fb4814Smrg  else
284cf503b78Smrg    make_dummy_depfile
28515fb4814Smrg  fi
28615fb4814Smrg  rm -f "$tmpdepfile"
28715fb4814Smrg  ;;
28815fb4814Smrg
289cf503b78Smrgxlc)
290cf503b78Smrg  # This case exists only to let depend.m4 do its work.  It works by
291cf503b78Smrg  # looking at the text of this script.  This case will never be run,
292cf503b78Smrg  # since it is checked for above.
293cf503b78Smrg  exit 1
294cf503b78Smrg  ;;
295cf503b78Smrg
29615fb4814Smrgaix)
29715fb4814Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
29815fb4814Smrg  # in a .u file.  In older versions, this file always lives in the
299cf503b78Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30015fb4814Smrg  # start of each line; $object doesn't have directory information.
30115fb4814Smrg  # Version 6 uses the directory in both cases.
302cf503b78Smrg  set_dir_from "$object"
303cf503b78Smrg  set_base_from "$object"
30415fb4814Smrg  if test "$libtool" = yes; then
305b4d38c65Smrg    tmpdepfile1=$dir$base.u
306b4d38c65Smrg    tmpdepfile2=$base.u
307b4d38c65Smrg    tmpdepfile3=$dir.libs/$base.u
30815fb4814Smrg    "$@" -Wc,-M
30915fb4814Smrg  else
310b4d38c65Smrg    tmpdepfile1=$dir$base.u
311b4d38c65Smrg    tmpdepfile2=$dir$base.u
312b4d38c65Smrg    tmpdepfile3=$dir$base.u
31315fb4814Smrg    "$@" -M
31415fb4814Smrg  fi
31515fb4814Smrg  stat=$?
316cf503b78Smrg  if test $stat -ne 0; then
317b4d38c65Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31815fb4814Smrg    exit $stat
31915fb4814Smrg  fi
32015fb4814Smrg
321b4d38c65Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322b4d38c65Smrg  do
323b4d38c65Smrg    test -f "$tmpdepfile" && break
324b4d38c65Smrg  done
325cf503b78Smrg  aix_post_process_depfile
326cf503b78Smrg  ;;
327cf503b78Smrg
328cf503b78Smrgtcc)
329cf503b78Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330cf503b78Smrg  # FIXME: That version still under development at the moment of writing.
331cf503b78Smrg  #        Make that this statement remains true also for stable, released
332cf503b78Smrg  #        versions.
333cf503b78Smrg  # It will wrap lines (doesn't matter whether long or short) with a
334cf503b78Smrg  # trailing '\', as in:
335cf503b78Smrg  #
336cf503b78Smrg  #   foo.o : \
337cf503b78Smrg  #    foo.c \
338cf503b78Smrg  #    foo.h \
339cf503b78Smrg  #
340cf503b78Smrg  # It will put a trailing '\' even on the last line, and will use leading
341cf503b78Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342cf503b78Smrg  # "Emit spaces for -MD").
343cf503b78Smrg  "$@" -MD -MF "$tmpdepfile"
344cf503b78Smrg  stat=$?
345cf503b78Smrg  if test $stat -ne 0; then
346cf503b78Smrg    rm -f "$tmpdepfile"
347cf503b78Smrg    exit $stat
34815fb4814Smrg  fi
349cf503b78Smrg  rm -f "$depfile"
350cf503b78Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351cf503b78Smrg  # We have to change lines of the first kind to '$object: \'.
352cf503b78Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353cf503b78Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354cf503b78Smrg  # dummy dependency, to avoid the deleted-header problem.
355cf503b78Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35615fb4814Smrg  rm -f "$tmpdepfile"
35715fb4814Smrg  ;;
35815fb4814Smrg
359cf503b78Smrg## The order of this option in the case statement is important, since the
360cf503b78Smrg## shell code in configure will try each of these formats in the order
361cf503b78Smrg## listed in this file.  A plain '-MD' option would be understood by many
362cf503b78Smrg## compilers, so we must ensure this comes after the gcc and icc options.
363cf503b78Smrgpgcc)
364cf503b78Smrg  # Portland's C compiler understands '-MD'.
365cf503b78Smrg  # Will always output deps to 'file.d' where file is the root name of the
366cf503b78Smrg  # source file under compilation, even if file resides in a subdirectory.
367cf503b78Smrg  # The object file name does not affect the name of the '.d' file.
368cf503b78Smrg  # pgcc 10.2 will output
36915fb4814Smrg  #    foo.o: sub/foo.c sub/foo.h
370cf503b78Smrg  # and will wrap long lines using '\' :
37115fb4814Smrg  #    foo.o: sub/foo.c ... \
37215fb4814Smrg  #     sub/foo.h ... \
37315fb4814Smrg  #     ...
374cf503b78Smrg  set_dir_from "$object"
375cf503b78Smrg  # Use the source, not the object, to determine the base name, since
376cf503b78Smrg  # that's sadly what pgcc will do too.
377cf503b78Smrg  set_base_from "$source"
378cf503b78Smrg  tmpdepfile=$base.d
379cf503b78Smrg
380cf503b78Smrg  # For projects that build the same source file twice into different object
381cf503b78Smrg  # files, the pgcc approach of using the *source* file root name can cause
382cf503b78Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383cf503b78Smrg  # the same $tmpdepfile.
384cf503b78Smrg  lockdir=$base.d-lock
385cf503b78Smrg  trap "
386cf503b78Smrg    echo '$0: caught signal, cleaning up...' >&2
387cf503b78Smrg    rmdir '$lockdir'
388cf503b78Smrg    exit 1
389cf503b78Smrg  " 1 2 13 15
390cf503b78Smrg  numtries=100
391cf503b78Smrg  i=$numtries
392cf503b78Smrg  while test $i -gt 0; do
393cf503b78Smrg    # mkdir is a portable test-and-set.
394cf503b78Smrg    if mkdir "$lockdir" 2>/dev/null; then
395cf503b78Smrg      # This process acquired the lock.
396cf503b78Smrg      "$@" -MD
397cf503b78Smrg      stat=$?
398cf503b78Smrg      # Release the lock.
399cf503b78Smrg      rmdir "$lockdir"
400cf503b78Smrg      break
401cf503b78Smrg    else
402cf503b78Smrg      # If the lock is being held by a different process, wait
403cf503b78Smrg      # until the winning process is done or we timeout.
404cf503b78Smrg      while test -d "$lockdir" && test $i -gt 0; do
405cf503b78Smrg        sleep 1
406cf503b78Smrg        i=`expr $i - 1`
407cf503b78Smrg      done
408cf503b78Smrg    fi
409cf503b78Smrg    i=`expr $i - 1`
410cf503b78Smrg  done
411cf503b78Smrg  trap - 1 2 13 15
412cf503b78Smrg  if test $i -le 0; then
413cf503b78Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414cf503b78Smrg    echo "$0: check lockdir '$lockdir'" >&2
415cf503b78Smrg    exit 1
416cf503b78Smrg  fi
41715fb4814Smrg
418cf503b78Smrg  if test $stat -ne 0; then
41915fb4814Smrg    rm -f "$tmpdepfile"
42015fb4814Smrg    exit $stat
42115fb4814Smrg  fi
42215fb4814Smrg  rm -f "$depfile"
42315fb4814Smrg  # Each line is of the form `foo.o: dependent.h',
42415fb4814Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42515fb4814Smrg  # Do two passes, one to just change these to
42615fb4814Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42715fb4814Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42815fb4814Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
42915fb4814Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
430cf503b78Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431cf503b78Smrg    | sed -e 's/$/ :/' >> "$depfile"
43215fb4814Smrg  rm -f "$tmpdepfile"
43315fb4814Smrg  ;;
43415fb4814Smrg
435de78e416Smrghp2)
436de78e416Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437de78e416Smrg  # compilers, which have integrated preprocessors.  The correct option
438de78e416Smrg  # to use with these is +Maked; it writes dependencies to a file named
439de78e416Smrg  # 'foo.d', which lands next to the object file, wherever that
440de78e416Smrg  # happens to be.
441de78e416Smrg  # Much of this is similar to the tru64 case; see comments there.
442cf503b78Smrg  set_dir_from  "$object"
443cf503b78Smrg  set_base_from "$object"
444de78e416Smrg  if test "$libtool" = yes; then
445de78e416Smrg    tmpdepfile1=$dir$base.d
446de78e416Smrg    tmpdepfile2=$dir.libs/$base.d
447de78e416Smrg    "$@" -Wc,+Maked
448de78e416Smrg  else
449de78e416Smrg    tmpdepfile1=$dir$base.d
450de78e416Smrg    tmpdepfile2=$dir$base.d
451de78e416Smrg    "$@" +Maked
452de78e416Smrg  fi
453de78e416Smrg  stat=$?
454cf503b78Smrg  if test $stat -ne 0; then
455de78e416Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456de78e416Smrg     exit $stat
457de78e416Smrg  fi
458de78e416Smrg
459de78e416Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460de78e416Smrg  do
461de78e416Smrg    test -f "$tmpdepfile" && break
462de78e416Smrg  done
463de78e416Smrg  if test -f "$tmpdepfile"; then
464cf503b78Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465cf503b78Smrg    # Add 'dependent.h:' lines.
466b4d38c65Smrg    sed -ne '2,${
467cf503b78Smrg               s/^ *//
468cf503b78Smrg               s/ \\*$//
469cf503b78Smrg               s/$/:/
470cf503b78Smrg               p
471cf503b78Smrg             }' "$tmpdepfile" >> "$depfile"
472de78e416Smrg  else
473cf503b78Smrg    make_dummy_depfile
474de78e416Smrg  fi
475de78e416Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476de78e416Smrg  ;;
477de78e416Smrg
47815fb4814Smrgtru64)
479cf503b78Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480cf503b78Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481cf503b78Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482cf503b78Smrg  # dependencies in 'foo.d' instead, so we check for that too.
483cf503b78Smrg  # Subdirectories are respected.
484cf503b78Smrg  set_dir_from  "$object"
485cf503b78Smrg  set_base_from "$object"
486cf503b78Smrg
487cf503b78Smrg  if test "$libtool" = yes; then
488cf503b78Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489cf503b78Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490cf503b78Smrg    # in $dir$base.o.d.  We have to check for both files, because
491cf503b78Smrg    # one of the two compilations can be disabled.  We should prefer
492cf503b78Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493cf503b78Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
494cf503b78Smrg    # the former would cause a distcleancheck panic.
495cf503b78Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496cf503b78Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497cf503b78Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498cf503b78Smrg    "$@" -Wc,-MD
499cf503b78Smrg  else
500cf503b78Smrg    tmpdepfile1=$dir$base.d
501cf503b78Smrg    tmpdepfile2=$dir$base.d
502cf503b78Smrg    tmpdepfile3=$dir$base.d
503cf503b78Smrg    "$@" -MD
504cf503b78Smrg  fi
505cf503b78Smrg
506cf503b78Smrg  stat=$?
507cf503b78Smrg  if test $stat -ne 0; then
508cf503b78Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509cf503b78Smrg    exit $stat
510cf503b78Smrg  fi
511cf503b78Smrg
512cf503b78Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513cf503b78Smrg  do
514cf503b78Smrg    test -f "$tmpdepfile" && break
515cf503b78Smrg  done
516cf503b78Smrg  # Same post-processing that is required for AIX mode.
517cf503b78Smrg  aix_post_process_depfile
518cf503b78Smrg  ;;
519cf503b78Smrg
520cf503b78Smrgmsvc7)
521cf503b78Smrg  if test "$libtool" = yes; then
522cf503b78Smrg    showIncludes=-Wc,-showIncludes
523cf503b78Smrg  else
524cf503b78Smrg    showIncludes=-showIncludes
525cf503b78Smrg  fi
526cf503b78Smrg  "$@" $showIncludes > "$tmpdepfile"
527cf503b78Smrg  stat=$?
528cf503b78Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
529cf503b78Smrg  if test $stat -ne 0; then
530cf503b78Smrg    rm -f "$tmpdepfile"
531cf503b78Smrg    exit $stat
532cf503b78Smrg  fi
533cf503b78Smrg  rm -f "$depfile"
534cf503b78Smrg  echo "$object : \\" > "$depfile"
535cf503b78Smrg  # The first sed program below extracts the file names and escapes
536cf503b78Smrg  # backslashes for cygpath.  The second sed program outputs the file
537cf503b78Smrg  # name when reading, but also accumulates all include files in the
538cf503b78Smrg  # hold buffer in order to output them again at the end.  This only
539cf503b78Smrg  # works with sed implementations that can handle large buffers.
540cf503b78Smrg  sed < "$tmpdepfile" -n '
541cf503b78Smrg/^Note: including file:  *\(.*\)/ {
542cf503b78Smrg  s//\1/
543cf503b78Smrg  s/\\/\\\\/g
544cf503b78Smrg  p
545cf503b78Smrg}' | $cygpath_u | sort -u | sed -n '
546cf503b78Smrgs/ /\\ /g
547cf503b78Smrgs/\(.*\)/'"$tab"'\1 \\/p
548cf503b78Smrgs/.\(.*\) \\/\1:/
549cf503b78SmrgH
550cf503b78Smrg$ {
551cf503b78Smrg  s/.*/'"$tab"'/
552cf503b78Smrg  G
553cf503b78Smrg  p
554cf503b78Smrg}' >> "$depfile"
555f010a93dSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556cf503b78Smrg  rm -f "$tmpdepfile"
557cf503b78Smrg  ;;
558cf503b78Smrg
559cf503b78Smrgmsvc7msys)
560cf503b78Smrg  # This case exists only to let depend.m4 do its work.  It works by
561cf503b78Smrg  # looking at the text of this script.  This case will never be run,
562cf503b78Smrg  # since it is checked for above.
563cf503b78Smrg  exit 1
564cf503b78Smrg  ;;
56515fb4814Smrg
56615fb4814Smrg#nosideeffect)
56715fb4814Smrg  # This comment above is used by automake to tell side-effect
56815fb4814Smrg  # dependency tracking mechanisms from slower ones.
56915fb4814Smrg
57015fb4814Smrgdashmstdout)
57115fb4814Smrg  # Important note: in order to support this mode, a compiler *must*
57215fb4814Smrg  # always write the preprocessed file to stdout, regardless of -o.
57315fb4814Smrg  "$@" || exit $?
57415fb4814Smrg
57515fb4814Smrg  # Remove the call to Libtool.
57615fb4814Smrg  if test "$libtool" = yes; then
577b4d38c65Smrg    while test "X$1" != 'X--mode=compile'; do
57815fb4814Smrg      shift
57915fb4814Smrg    done
58015fb4814Smrg    shift
58115fb4814Smrg  fi
58215fb4814Smrg
583cf503b78Smrg  # Remove '-o $object'.
58415fb4814Smrg  IFS=" "
58515fb4814Smrg  for arg
58615fb4814Smrg  do
58715fb4814Smrg    case $arg in
58815fb4814Smrg    -o)
58915fb4814Smrg      shift
59015fb4814Smrg      ;;
59115fb4814Smrg    $object)
59215fb4814Smrg      shift
59315fb4814Smrg      ;;
59415fb4814Smrg    *)
59515fb4814Smrg      set fnord "$@" "$arg"
59615fb4814Smrg      shift # fnord
59715fb4814Smrg      shift # $arg
59815fb4814Smrg      ;;
59915fb4814Smrg    esac
60015fb4814Smrg  done
60115fb4814Smrg
60215fb4814Smrg  test -z "$dashmflag" && dashmflag=-M
603cf503b78Smrg  # Require at least two characters before searching for ':'
60415fb4814Smrg  # in the target name.  This is to cope with DOS-style filenames:
605cf503b78Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60615fb4814Smrg  "$@" $dashmflag |
607cf503b78Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60815fb4814Smrg  rm -f "$depfile"
60915fb4814Smrg  cat < "$tmpdepfile" > "$depfile"
610cf503b78Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611cf503b78Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
612cf503b78Smrg  tr ' ' "$nl" < "$tmpdepfile" \
613cf503b78Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614cf503b78Smrg    | sed -e 's/$/ :/' >> "$depfile"
61515fb4814Smrg  rm -f "$tmpdepfile"
61615fb4814Smrg  ;;
61715fb4814Smrg
61815fb4814SmrgdashXmstdout)
61915fb4814Smrg  # This case only exists to satisfy depend.m4.  It is never actually
62015fb4814Smrg  # run, as this mode is specially recognized in the preamble.
62115fb4814Smrg  exit 1
62215fb4814Smrg  ;;
62315fb4814Smrg
62415fb4814Smrgmakedepend)
62515fb4814Smrg  "$@" || exit $?
62615fb4814Smrg  # Remove any Libtool call
62715fb4814Smrg  if test "$libtool" = yes; then
628b4d38c65Smrg    while test "X$1" != 'X--mode=compile'; do
62915fb4814Smrg      shift
63015fb4814Smrg    done
63115fb4814Smrg    shift
63215fb4814Smrg  fi
63315fb4814Smrg  # X makedepend
63415fb4814Smrg  shift
635b4d38c65Smrg  cleared=no eat=no
636b4d38c65Smrg  for arg
637b4d38c65Smrg  do
63815fb4814Smrg    case $cleared in
63915fb4814Smrg    no)
64015fb4814Smrg      set ""; shift
64115fb4814Smrg      cleared=yes ;;
64215fb4814Smrg    esac
643b4d38c65Smrg    if test $eat = yes; then
644b4d38c65Smrg      eat=no
645b4d38c65Smrg      continue
646b4d38c65Smrg    fi
64715fb4814Smrg    case "$arg" in
64815fb4814Smrg    -D*|-I*)
64915fb4814Smrg      set fnord "$@" "$arg"; shift ;;
65015fb4814Smrg    # Strip any option that makedepend may not understand.  Remove
65115fb4814Smrg    # the object too, otherwise makedepend will parse it as a source file.
652b4d38c65Smrg    -arch)
653b4d38c65Smrg      eat=yes ;;
65415fb4814Smrg    -*|$object)
65515fb4814Smrg      ;;
65615fb4814Smrg    *)
65715fb4814Smrg      set fnord "$@" "$arg"; shift ;;
65815fb4814Smrg    esac
65915fb4814Smrg  done
660b4d38c65Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66115fb4814Smrg  touch "$tmpdepfile"
66215fb4814Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66315fb4814Smrg  rm -f "$depfile"
664cf503b78Smrg  # makedepend may prepend the VPATH from the source file name to the object.
665cf503b78Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666cf503b78Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667cf503b78Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668cf503b78Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
669cf503b78Smrg  sed '1,2d' "$tmpdepfile" \
670cf503b78Smrg    | tr ' ' "$nl" \
671cf503b78Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672cf503b78Smrg    | sed -e 's/$/ :/' >> "$depfile"
67315fb4814Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67415fb4814Smrg  ;;
67515fb4814Smrg
67615fb4814Smrgcpp)
67715fb4814Smrg  # Important note: in order to support this mode, a compiler *must*
67815fb4814Smrg  # always write the preprocessed file to stdout.
67915fb4814Smrg  "$@" || exit $?
68015fb4814Smrg
68115fb4814Smrg  # Remove the call to Libtool.
68215fb4814Smrg  if test "$libtool" = yes; then
683b4d38c65Smrg    while test "X$1" != 'X--mode=compile'; do
68415fb4814Smrg      shift
68515fb4814Smrg    done
68615fb4814Smrg    shift
68715fb4814Smrg  fi
68815fb4814Smrg
689cf503b78Smrg  # Remove '-o $object'.
69015fb4814Smrg  IFS=" "
69115fb4814Smrg  for arg
69215fb4814Smrg  do
69315fb4814Smrg    case $arg in
69415fb4814Smrg    -o)
69515fb4814Smrg      shift
69615fb4814Smrg      ;;
69715fb4814Smrg    $object)
69815fb4814Smrg      shift
69915fb4814Smrg      ;;
70015fb4814Smrg    *)
70115fb4814Smrg      set fnord "$@" "$arg"
70215fb4814Smrg      shift # fnord
70315fb4814Smrg      shift # $arg
70415fb4814Smrg      ;;
70515fb4814Smrg    esac
70615fb4814Smrg  done
70715fb4814Smrg
708cf503b78Smrg  "$@" -E \
709cf503b78Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710cf503b78Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711cf503b78Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
71215fb4814Smrg  rm -f "$depfile"
71315fb4814Smrg  echo "$object : \\" > "$depfile"
71415fb4814Smrg  cat < "$tmpdepfile" >> "$depfile"
71515fb4814Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71615fb4814Smrg  rm -f "$tmpdepfile"
71715fb4814Smrg  ;;
71815fb4814Smrg
71915fb4814Smrgmsvisualcpp)
72015fb4814Smrg  # Important note: in order to support this mode, a compiler *must*
721b4d38c65Smrg  # always write the preprocessed file to stdout.
72215fb4814Smrg  "$@" || exit $?
723b4d38c65Smrg
724b4d38c65Smrg  # Remove the call to Libtool.
725b4d38c65Smrg  if test "$libtool" = yes; then
726b4d38c65Smrg    while test "X$1" != 'X--mode=compile'; do
727b4d38c65Smrg      shift
728b4d38c65Smrg    done
729b4d38c65Smrg    shift
730b4d38c65Smrg  fi
731b4d38c65Smrg
73215fb4814Smrg  IFS=" "
73315fb4814Smrg  for arg
73415fb4814Smrg  do
73515fb4814Smrg    case "$arg" in
736b4d38c65Smrg    -o)
737b4d38c65Smrg      shift
738b4d38c65Smrg      ;;
739b4d38c65Smrg    $object)
740b4d38c65Smrg      shift
741b4d38c65Smrg      ;;
74215fb4814Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743cf503b78Smrg        set fnord "$@"
744cf503b78Smrg        shift
745cf503b78Smrg        shift
746cf503b78Smrg        ;;
74715fb4814Smrg    *)
748cf503b78Smrg        set fnord "$@" "$arg"
749cf503b78Smrg        shift
750cf503b78Smrg        shift
751cf503b78Smrg        ;;
75215fb4814Smrg    esac
75315fb4814Smrg  done
754b4d38c65Smrg  "$@" -E 2>/dev/null |
755b4d38c65Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75615fb4814Smrg  rm -f "$depfile"
75715fb4814Smrg  echo "$object : \\" > "$depfile"
758cf503b78Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759cf503b78Smrg  echo "$tab" >> "$depfile"
760b4d38c65Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76115fb4814Smrg  rm -f "$tmpdepfile"
76215fb4814Smrg  ;;
76315fb4814Smrg
764b4d38c65Smrgmsvcmsys)
765b4d38c65Smrg  # This case exists only to let depend.m4 do its work.  It works by
766b4d38c65Smrg  # looking at the text of this script.  This case will never be run,
767b4d38c65Smrg  # since it is checked for above.
768b4d38c65Smrg  exit 1
769b4d38c65Smrg  ;;
770b4d38c65Smrg
77115fb4814Smrgnone)
77215fb4814Smrg  exec "$@"
77315fb4814Smrg  ;;
77415fb4814Smrg
77515fb4814Smrg*)
77615fb4814Smrg  echo "Unknown depmode $depmode" 1>&2
77715fb4814Smrg  exit 1
77815fb4814Smrg  ;;
77915fb4814Smrgesac
78015fb4814Smrg
78115fb4814Smrgexit 0
78215fb4814Smrg
78315fb4814Smrg# Local Variables:
78415fb4814Smrg# mode: shell-script
78515fb4814Smrg# sh-indentation: 2
786f010a93dSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
78715fb4814Smrg# time-stamp-start: "scriptversion="
78815fb4814Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789f010a93dSmrg# time-stamp-time-zone: "UTC0"
790b4d38c65Smrg# time-stamp-end: "; # UTC"
79115fb4814Smrg# End:
792