depcomp revision ac92798b
1a966c04fSmrg#! /bin/sh
2a966c04fSmrg# depcomp - compile a program generating dependencies as side-effects
3a966c04fSmrg
4ac92798bSmrgscriptversion=2013-05-30.07; # UTC
5a966c04fSmrg
6ac92798bSmrg# Copyright (C) 1999-2013 Free Software Foundation, Inc.
7a966c04fSmrg
8a966c04fSmrg# This program is free software; you can redistribute it and/or modify
9a966c04fSmrg# it under the terms of the GNU General Public License as published by
10a966c04fSmrg# the Free Software Foundation; either version 2, or (at your option)
11a966c04fSmrg# any later version.
12a966c04fSmrg
13a966c04fSmrg# This program is distributed in the hope that it will be useful,
14a966c04fSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15a966c04fSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16a966c04fSmrg# GNU General Public License for more details.
17a966c04fSmrg
18a966c04fSmrg# You should have received a copy of the GNU General Public License
192e2dd055Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20a966c04fSmrg
21a966c04fSmrg# As a special exception to the GNU General Public License, if you
22a966c04fSmrg# distribute this file as part of a program that contains a
23a966c04fSmrg# configuration script generated by Autoconf, you may include it under
24a966c04fSmrg# the same distribution terms that you use for the rest of that program.
25a966c04fSmrg
26a966c04fSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27a966c04fSmrg
28a966c04fSmrgcase $1 in
29a966c04fSmrg  '')
30ac92798bSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31ac92798bSmrg    exit 1;
32ac92798bSmrg    ;;
33a966c04fSmrg  -h | --h*)
34a966c04fSmrg    cat <<\EOF
35a966c04fSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36a966c04fSmrg
37a966c04fSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38a966c04fSmrgas side-effects.
39a966c04fSmrg
40a966c04fSmrgEnvironment variables:
41a966c04fSmrg  depmode     Dependency tracking mode.
42ac92798bSmrg  source      Source file read by 'PROGRAMS ARGS'.
43ac92798bSmrg  object      Object file output by 'PROGRAMS ARGS'.
44a966c04fSmrg  DEPDIR      directory where to store dependencies.
45a966c04fSmrg  depfile     Dependency file to output.
46ac92798bSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
47a966c04fSmrg  libtool     Whether libtool is used (yes/no).
48a966c04fSmrg
49a966c04fSmrgReport bugs to <bug-automake@gnu.org>.
50a966c04fSmrgEOF
51a966c04fSmrg    exit $?
52a966c04fSmrg    ;;
53a966c04fSmrg  -v | --v*)
54a966c04fSmrg    echo "depcomp $scriptversion"
55a966c04fSmrg    exit $?
56a966c04fSmrg    ;;
57a966c04fSmrgesac
58a966c04fSmrg
59ac92798bSmrg# Get the directory component of the given path, and save it in the
60ac92798bSmrg# global variables '$dir'.  Note that this directory component will
61ac92798bSmrg# be either empty or ending with a '/' character.  This is deliberate.
62ac92798bSmrgset_dir_from ()
63ac92798bSmrg{
64ac92798bSmrg  case $1 in
65ac92798bSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66ac92798bSmrg      *) dir=;;
67ac92798bSmrg  esac
68ac92798bSmrg}
69ac92798bSmrg
70ac92798bSmrg# Get the suffix-stripped basename of the given path, and save it the
71ac92798bSmrg# global variable '$base'.
72ac92798bSmrgset_base_from ()
73ac92798bSmrg{
74ac92798bSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75ac92798bSmrg}
76ac92798bSmrg
77ac92798bSmrg# If no dependency file was actually created by the compiler invocation,
78ac92798bSmrg# we still have to create a dummy depfile, to avoid errors with the
79ac92798bSmrg# Makefile "include basename.Plo" scheme.
80ac92798bSmrgmake_dummy_depfile ()
81ac92798bSmrg{
82ac92798bSmrg  echo "#dummy" > "$depfile"
83ac92798bSmrg}
84ac92798bSmrg
85ac92798bSmrg# Factor out some common post-processing of the generated depfile.
86ac92798bSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87ac92798bSmrgaix_post_process_depfile ()
88ac92798bSmrg{
89ac92798bSmrg  # If the compiler actually managed to produce a dependency file,
90ac92798bSmrg  # post-process it.
91ac92798bSmrg  if test -f "$tmpdepfile"; then
92ac92798bSmrg    # Each line is of the form 'foo.o: dependency.h'.
93ac92798bSmrg    # Do two passes, one to just change these to
94ac92798bSmrg    #   $object: dependency.h
95ac92798bSmrg    # and one to simply output
96ac92798bSmrg    #   dependency.h:
97ac92798bSmrg    # which is needed to avoid the deleted-header problem.
98ac92798bSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99ac92798bSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100ac92798bSmrg    } > "$depfile"
101ac92798bSmrg    rm -f "$tmpdepfile"
102ac92798bSmrg  else
103ac92798bSmrg    make_dummy_depfile
104ac92798bSmrg  fi
105ac92798bSmrg}
106ac92798bSmrg
107ac92798bSmrg# A tabulation character.
108ac92798bSmrgtab='	'
109ac92798bSmrg# A newline character.
110ac92798bSmrgnl='
111ac92798bSmrg'
112ac92798bSmrg# Character ranges might be problematic outside the C locale.
113ac92798bSmrg# These definitions help.
114ac92798bSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115ac92798bSmrglower=abcdefghijklmnopqrstuvwxyz
116ac92798bSmrgdigits=0123456789
117ac92798bSmrgalpha=${upper}${lower}
118ac92798bSmrg
119a966c04fSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120a966c04fSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121a966c04fSmrg  exit 1
122a966c04fSmrgfi
123a966c04fSmrg
124a966c04fSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125a966c04fSmrgdepfile=${depfile-`echo "$object" |
126a966c04fSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127a966c04fSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128a966c04fSmrg
129a966c04fSmrgrm -f "$tmpdepfile"
130a966c04fSmrg
131ac92798bSmrg# Avoid interferences from the environment.
132ac92798bSmrggccflag= dashmflag=
133ac92798bSmrg
134a966c04fSmrg# Some modes work just like other modes, but use different flags.  We
135a966c04fSmrg# parameterize here, but still list the modes in the big case below,
136a966c04fSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137a966c04fSmrg# here, because this file can only contain one case statement.
138a966c04fSmrgif test "$depmode" = hp; then
139a966c04fSmrg  # HP compiler uses -M and no extra arg.
140a966c04fSmrg  gccflag=-M
141a966c04fSmrg  depmode=gcc
142a966c04fSmrgfi
143a966c04fSmrg
144a966c04fSmrgif test "$depmode" = dashXmstdout; then
145ac92798bSmrg  # This is just like dashmstdout with a different argument.
146ac92798bSmrg  dashmflag=-xM
147ac92798bSmrg  depmode=dashmstdout
148a966c04fSmrgfi
149a966c04fSmrg
1502e2dd055Smrgcygpath_u="cygpath -u -f -"
1512e2dd055Smrgif test "$depmode" = msvcmsys; then
152ac92798bSmrg  # This is just like msvisualcpp but w/o cygpath translation.
153ac92798bSmrg  # Just convert the backslash-escaped backslashes to single forward
154ac92798bSmrg  # slashes to satisfy depend.m4
155ac92798bSmrg  cygpath_u='sed s,\\\\,/,g'
156ac92798bSmrg  depmode=msvisualcpp
157ac92798bSmrgfi
158ac92798bSmrg
159ac92798bSmrgif test "$depmode" = msvc7msys; then
160ac92798bSmrg  # This is just like msvc7 but w/o cygpath translation.
161ac92798bSmrg  # Just convert the backslash-escaped backslashes to single forward
162ac92798bSmrg  # slashes to satisfy depend.m4
163ac92798bSmrg  cygpath_u='sed s,\\\\,/,g'
164ac92798bSmrg  depmode=msvc7
165ac92798bSmrgfi
166ac92798bSmrg
167ac92798bSmrgif test "$depmode" = xlc; then
168ac92798bSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169ac92798bSmrg  gccflag=-qmakedep=gcc,-MF
170ac92798bSmrg  depmode=gcc
1712e2dd055Smrgfi
1722e2dd055Smrg
173a966c04fSmrgcase "$depmode" in
174a966c04fSmrggcc3)
175a966c04fSmrg## gcc 3 implements dependency tracking that does exactly what
176a966c04fSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177a966c04fSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178a966c04fSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179a966c04fSmrg## the command line argument order; so add the flags where they
180a966c04fSmrg## appear in depend2.am.  Note that the slowdown incurred here
181a966c04fSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182a966c04fSmrg  for arg
183a966c04fSmrg  do
184a966c04fSmrg    case $arg in
185a966c04fSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186a966c04fSmrg    *)  set fnord "$@" "$arg" ;;
187a966c04fSmrg    esac
188a966c04fSmrg    shift # fnord
189a966c04fSmrg    shift # $arg
190a966c04fSmrg  done
191a966c04fSmrg  "$@"
192a966c04fSmrg  stat=$?
193ac92798bSmrg  if test $stat -ne 0; then
194a966c04fSmrg    rm -f "$tmpdepfile"
195a966c04fSmrg    exit $stat
196a966c04fSmrg  fi
197a966c04fSmrg  mv "$tmpdepfile" "$depfile"
198a966c04fSmrg  ;;
199a966c04fSmrg
200a966c04fSmrggcc)
201ac92798bSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202ac92798bSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203ac92798bSmrg## (see the conditional assignment to $gccflag above).
204a966c04fSmrg## There are various ways to get dependency output from gcc.  Here's
205a966c04fSmrg## why we pick this rather obscure method:
206a966c04fSmrg## - Don't want to use -MD because we'd like the dependencies to end
207a966c04fSmrg##   up in a subdir.  Having to rename by hand is ugly.
208a966c04fSmrg##   (We might end up doing this anyway to support other compilers.)
209a966c04fSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210ac92798bSmrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211ac92798bSmrg##   supported by the other compilers which use the 'gcc' depmode.
212a966c04fSmrg## - Using -M directly means running the compiler twice (even worse
213a966c04fSmrg##   than renaming).
214a966c04fSmrg  if test -z "$gccflag"; then
215a966c04fSmrg    gccflag=-MD,
216a966c04fSmrg  fi
217a966c04fSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
218a966c04fSmrg  stat=$?
219ac92798bSmrg  if test $stat -ne 0; then
220a966c04fSmrg    rm -f "$tmpdepfile"
221a966c04fSmrg    exit $stat
222a966c04fSmrg  fi
223a966c04fSmrg  rm -f "$depfile"
224a966c04fSmrg  echo "$object : \\" > "$depfile"
225ac92798bSmrg  # The second -e expression handles DOS-style file names with drive
226ac92798bSmrg  # letters.
227a966c04fSmrg  sed -e 's/^[^:]*: / /' \
228a966c04fSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229ac92798bSmrg## This next piece of magic avoids the "deleted header file" problem.
230a966c04fSmrg## The problem is that when a header file which appears in a .P file
231a966c04fSmrg## is deleted, the dependency causes make to die (because there is
232a966c04fSmrg## typically no way to rebuild the header).  We avoid this by adding
233a966c04fSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234a966c04fSmrg## this for us directly.
235ac92798bSmrg## Some versions of gcc put a space before the ':'.  On the theory
236a966c04fSmrg## that the space means something, we add a space to the output as
237ac92798bSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238ac92798bSmrg## to the object.  Take care to not repeat it in the output.
239a966c04fSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
240a966c04fSmrg## correctly.  Breaking it into two sed invocations is a workaround.
241ac92798bSmrg  tr ' ' "$nl" < "$tmpdepfile" \
242ac92798bSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243ac92798bSmrg    | sed -e 's/$/ :/' >> "$depfile"
244a966c04fSmrg  rm -f "$tmpdepfile"
245a966c04fSmrg  ;;
246a966c04fSmrg
247a966c04fSmrghp)
248a966c04fSmrg  # This case exists only to let depend.m4 do its work.  It works by
249a966c04fSmrg  # looking at the text of this script.  This case will never be run,
250a966c04fSmrg  # since it is checked for above.
251a966c04fSmrg  exit 1
252a966c04fSmrg  ;;
253a966c04fSmrg
254a966c04fSmrgsgi)
255a966c04fSmrg  if test "$libtool" = yes; then
256a966c04fSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257a966c04fSmrg  else
258a966c04fSmrg    "$@" -MDupdate "$tmpdepfile"
259a966c04fSmrg  fi
260a966c04fSmrg  stat=$?
261ac92798bSmrg  if test $stat -ne 0; then
262a966c04fSmrg    rm -f "$tmpdepfile"
263a966c04fSmrg    exit $stat
264a966c04fSmrg  fi
265a966c04fSmrg  rm -f "$depfile"
266a966c04fSmrg
267a966c04fSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268a966c04fSmrg    echo "$object : \\" > "$depfile"
269a966c04fSmrg    # Clip off the initial element (the dependent).  Don't try to be
270a966c04fSmrg    # clever and replace this with sed code, as IRIX sed won't handle
271a966c04fSmrg    # lines with more than a fixed number of characters (4096 in
272a966c04fSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273ac92798bSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
274a966c04fSmrg    # dependency line.
275ac92798bSmrg    tr ' ' "$nl" < "$tmpdepfile" \
276ac92798bSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277ac92798bSmrg      | tr "$nl" ' ' >> "$depfile"
2782e2dd055Smrg    echo >> "$depfile"
279a966c04fSmrg    # The second pass generates a dummy entry for each header file.
280ac92798bSmrg    tr ' ' "$nl" < "$tmpdepfile" \
281ac92798bSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282ac92798bSmrg      >> "$depfile"
283a966c04fSmrg  else
284ac92798bSmrg    make_dummy_depfile
285a966c04fSmrg  fi
286a966c04fSmrg  rm -f "$tmpdepfile"
287a966c04fSmrg  ;;
288a966c04fSmrg
289ac92798bSmrgxlc)
290ac92798bSmrg  # This case exists only to let depend.m4 do its work.  It works by
291ac92798bSmrg  # looking at the text of this script.  This case will never be run,
292ac92798bSmrg  # since it is checked for above.
293ac92798bSmrg  exit 1
294ac92798bSmrg  ;;
295ac92798bSmrg
296a966c04fSmrgaix)
297a966c04fSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
298a966c04fSmrg  # in a .u file.  In older versions, this file always lives in the
299ac92798bSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300a966c04fSmrg  # start of each line; $object doesn't have directory information.
301a966c04fSmrg  # Version 6 uses the directory in both cases.
302ac92798bSmrg  set_dir_from "$object"
303ac92798bSmrg  set_base_from "$object"
304a966c04fSmrg  if test "$libtool" = yes; then
3052e2dd055Smrg    tmpdepfile1=$dir$base.u
3062e2dd055Smrg    tmpdepfile2=$base.u
3072e2dd055Smrg    tmpdepfile3=$dir.libs/$base.u
308a966c04fSmrg    "$@" -Wc,-M
309a966c04fSmrg  else
3102e2dd055Smrg    tmpdepfile1=$dir$base.u
3112e2dd055Smrg    tmpdepfile2=$dir$base.u
3122e2dd055Smrg    tmpdepfile3=$dir$base.u
313a966c04fSmrg    "$@" -M
314a966c04fSmrg  fi
315a966c04fSmrg  stat=$?
316ac92798bSmrg  if test $stat -ne 0; then
3172e2dd055Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318a966c04fSmrg    exit $stat
319a966c04fSmrg  fi
320a966c04fSmrg
3212e2dd055Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3222e2dd055Smrg  do
3232e2dd055Smrg    test -f "$tmpdepfile" && break
3242e2dd055Smrg  done
325ac92798bSmrg  aix_post_process_depfile
326ac92798bSmrg  ;;
327ac92798bSmrg
328ac92798bSmrgtcc)
329ac92798bSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330ac92798bSmrg  # FIXME: That version still under development at the moment of writing.
331ac92798bSmrg  #        Make that this statement remains true also for stable, released
332ac92798bSmrg  #        versions.
333ac92798bSmrg  # It will wrap lines (doesn't matter whether long or short) with a
334ac92798bSmrg  # trailing '\', as in:
335ac92798bSmrg  #
336ac92798bSmrg  #   foo.o : \
337ac92798bSmrg  #    foo.c \
338ac92798bSmrg  #    foo.h \
339ac92798bSmrg  #
340ac92798bSmrg  # It will put a trailing '\' even on the last line, and will use leading
341ac92798bSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342ac92798bSmrg  # "Emit spaces for -MD").
343ac92798bSmrg  "$@" -MD -MF "$tmpdepfile"
344ac92798bSmrg  stat=$?
345ac92798bSmrg  if test $stat -ne 0; then
346ac92798bSmrg    rm -f "$tmpdepfile"
347ac92798bSmrg    exit $stat
348a966c04fSmrg  fi
349ac92798bSmrg  rm -f "$depfile"
350ac92798bSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351ac92798bSmrg  # We have to change lines of the first kind to '$object: \'.
352ac92798bSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353ac92798bSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354ac92798bSmrg  # dummy dependency, to avoid the deleted-header problem.
355ac92798bSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356a966c04fSmrg  rm -f "$tmpdepfile"
357a966c04fSmrg  ;;
358a966c04fSmrg
359ac92798bSmrg## The order of this option in the case statement is important, since the
360ac92798bSmrg## shell code in configure will try each of these formats in the order
361ac92798bSmrg## listed in this file.  A plain '-MD' option would be understood by many
362ac92798bSmrg## compilers, so we must ensure this comes after the gcc and icc options.
363ac92798bSmrgpgcc)
364ac92798bSmrg  # Portland's C compiler understands '-MD'.
365ac92798bSmrg  # Will always output deps to 'file.d' where file is the root name of the
366ac92798bSmrg  # source file under compilation, even if file resides in a subdirectory.
367ac92798bSmrg  # The object file name does not affect the name of the '.d' file.
368ac92798bSmrg  # pgcc 10.2 will output
369a966c04fSmrg  #    foo.o: sub/foo.c sub/foo.h
370ac92798bSmrg  # and will wrap long lines using '\' :
371a966c04fSmrg  #    foo.o: sub/foo.c ... \
372a966c04fSmrg  #     sub/foo.h ... \
373a966c04fSmrg  #     ...
374ac92798bSmrg  set_dir_from "$object"
375ac92798bSmrg  # Use the source, not the object, to determine the base name, since
376ac92798bSmrg  # that's sadly what pgcc will do too.
377ac92798bSmrg  set_base_from "$source"
378ac92798bSmrg  tmpdepfile=$base.d
379ac92798bSmrg
380ac92798bSmrg  # For projects that build the same source file twice into different object
381ac92798bSmrg  # files, the pgcc approach of using the *source* file root name can cause
382ac92798bSmrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383ac92798bSmrg  # the same $tmpdepfile.
384ac92798bSmrg  lockdir=$base.d-lock
385ac92798bSmrg  trap "
386ac92798bSmrg    echo '$0: caught signal, cleaning up...' >&2
387ac92798bSmrg    rmdir '$lockdir'
388ac92798bSmrg    exit 1
389ac92798bSmrg  " 1 2 13 15
390ac92798bSmrg  numtries=100
391ac92798bSmrg  i=$numtries
392ac92798bSmrg  while test $i -gt 0; do
393ac92798bSmrg    # mkdir is a portable test-and-set.
394ac92798bSmrg    if mkdir "$lockdir" 2>/dev/null; then
395ac92798bSmrg      # This process acquired the lock.
396ac92798bSmrg      "$@" -MD
397ac92798bSmrg      stat=$?
398ac92798bSmrg      # Release the lock.
399ac92798bSmrg      rmdir "$lockdir"
400ac92798bSmrg      break
401ac92798bSmrg    else
402ac92798bSmrg      # If the lock is being held by a different process, wait
403ac92798bSmrg      # until the winning process is done or we timeout.
404ac92798bSmrg      while test -d "$lockdir" && test $i -gt 0; do
405ac92798bSmrg        sleep 1
406ac92798bSmrg        i=`expr $i - 1`
407ac92798bSmrg      done
408ac92798bSmrg    fi
409ac92798bSmrg    i=`expr $i - 1`
410ac92798bSmrg  done
411ac92798bSmrg  trap - 1 2 13 15
412ac92798bSmrg  if test $i -le 0; then
413ac92798bSmrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414ac92798bSmrg    echo "$0: check lockdir '$lockdir'" >&2
415ac92798bSmrg    exit 1
416ac92798bSmrg  fi
417a966c04fSmrg
418ac92798bSmrg  if test $stat -ne 0; then
419a966c04fSmrg    rm -f "$tmpdepfile"
420a966c04fSmrg    exit $stat
421a966c04fSmrg  fi
422a966c04fSmrg  rm -f "$depfile"
423a966c04fSmrg  # Each line is of the form `foo.o: dependent.h',
424a966c04fSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425a966c04fSmrg  # Do two passes, one to just change these to
426a966c04fSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427a966c04fSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428a966c04fSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429a966c04fSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
430ac92798bSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431ac92798bSmrg    | sed -e 's/$/ :/' >> "$depfile"
432a966c04fSmrg  rm -f "$tmpdepfile"
433a966c04fSmrg  ;;
434a966c04fSmrg
435a966c04fSmrghp2)
436a966c04fSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437a966c04fSmrg  # compilers, which have integrated preprocessors.  The correct option
438a966c04fSmrg  # to use with these is +Maked; it writes dependencies to a file named
439a966c04fSmrg  # 'foo.d', which lands next to the object file, wherever that
440a966c04fSmrg  # happens to be.
441a966c04fSmrg  # Much of this is similar to the tru64 case; see comments there.
442ac92798bSmrg  set_dir_from  "$object"
443ac92798bSmrg  set_base_from "$object"
444a966c04fSmrg  if test "$libtool" = yes; then
445a966c04fSmrg    tmpdepfile1=$dir$base.d
446a966c04fSmrg    tmpdepfile2=$dir.libs/$base.d
447a966c04fSmrg    "$@" -Wc,+Maked
448a966c04fSmrg  else
449a966c04fSmrg    tmpdepfile1=$dir$base.d
450a966c04fSmrg    tmpdepfile2=$dir$base.d
451a966c04fSmrg    "$@" +Maked
452a966c04fSmrg  fi
453a966c04fSmrg  stat=$?
454ac92798bSmrg  if test $stat -ne 0; then
455a966c04fSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456a966c04fSmrg     exit $stat
457a966c04fSmrg  fi
458a966c04fSmrg
459a966c04fSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460a966c04fSmrg  do
461a966c04fSmrg    test -f "$tmpdepfile" && break
462a966c04fSmrg  done
463a966c04fSmrg  if test -f "$tmpdepfile"; then
464ac92798bSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465ac92798bSmrg    # Add 'dependent.h:' lines.
4662e2dd055Smrg    sed -ne '2,${
467ac92798bSmrg               s/^ *//
468ac92798bSmrg               s/ \\*$//
469ac92798bSmrg               s/$/:/
470ac92798bSmrg               p
471ac92798bSmrg             }' "$tmpdepfile" >> "$depfile"
472a966c04fSmrg  else
473ac92798bSmrg    make_dummy_depfile
474a966c04fSmrg  fi
475a966c04fSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476a966c04fSmrg  ;;
477a966c04fSmrg
478a966c04fSmrgtru64)
479ac92798bSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480ac92798bSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481ac92798bSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482ac92798bSmrg  # dependencies in 'foo.d' instead, so we check for that too.
483ac92798bSmrg  # Subdirectories are respected.
484ac92798bSmrg  set_dir_from  "$object"
485ac92798bSmrg  set_base_from "$object"
486ac92798bSmrg
487ac92798bSmrg  if test "$libtool" = yes; then
488ac92798bSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489ac92798bSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490ac92798bSmrg    # in $dir$base.o.d.  We have to check for both files, because
491ac92798bSmrg    # one of the two compilations can be disabled.  We should prefer
492ac92798bSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493ac92798bSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
494ac92798bSmrg    # the former would cause a distcleancheck panic.
495ac92798bSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496ac92798bSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497ac92798bSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498ac92798bSmrg    "$@" -Wc,-MD
499ac92798bSmrg  else
500ac92798bSmrg    tmpdepfile1=$dir$base.d
501ac92798bSmrg    tmpdepfile2=$dir$base.d
502ac92798bSmrg    tmpdepfile3=$dir$base.d
503ac92798bSmrg    "$@" -MD
504ac92798bSmrg  fi
505ac92798bSmrg
506ac92798bSmrg  stat=$?
507ac92798bSmrg  if test $stat -ne 0; then
508ac92798bSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509ac92798bSmrg    exit $stat
510ac92798bSmrg  fi
511ac92798bSmrg
512ac92798bSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513ac92798bSmrg  do
514ac92798bSmrg    test -f "$tmpdepfile" && break
515ac92798bSmrg  done
516ac92798bSmrg  # Same post-processing that is required for AIX mode.
517ac92798bSmrg  aix_post_process_depfile
518ac92798bSmrg  ;;
519ac92798bSmrg
520ac92798bSmrgmsvc7)
521ac92798bSmrg  if test "$libtool" = yes; then
522ac92798bSmrg    showIncludes=-Wc,-showIncludes
523ac92798bSmrg  else
524ac92798bSmrg    showIncludes=-showIncludes
525ac92798bSmrg  fi
526ac92798bSmrg  "$@" $showIncludes > "$tmpdepfile"
527ac92798bSmrg  stat=$?
528ac92798bSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
529ac92798bSmrg  if test $stat -ne 0; then
530ac92798bSmrg    rm -f "$tmpdepfile"
531ac92798bSmrg    exit $stat
532ac92798bSmrg  fi
533ac92798bSmrg  rm -f "$depfile"
534ac92798bSmrg  echo "$object : \\" > "$depfile"
535ac92798bSmrg  # The first sed program below extracts the file names and escapes
536ac92798bSmrg  # backslashes for cygpath.  The second sed program outputs the file
537ac92798bSmrg  # name when reading, but also accumulates all include files in the
538ac92798bSmrg  # hold buffer in order to output them again at the end.  This only
539ac92798bSmrg  # works with sed implementations that can handle large buffers.
540ac92798bSmrg  sed < "$tmpdepfile" -n '
541ac92798bSmrg/^Note: including file:  *\(.*\)/ {
542ac92798bSmrg  s//\1/
543ac92798bSmrg  s/\\/\\\\/g
544ac92798bSmrg  p
545ac92798bSmrg}' | $cygpath_u | sort -u | sed -n '
546ac92798bSmrgs/ /\\ /g
547ac92798bSmrgs/\(.*\)/'"$tab"'\1 \\/p
548ac92798bSmrgs/.\(.*\) \\/\1:/
549ac92798bSmrgH
550ac92798bSmrg$ {
551ac92798bSmrg  s/.*/'"$tab"'/
552ac92798bSmrg  G
553ac92798bSmrg  p
554ac92798bSmrg}' >> "$depfile"
555ac92798bSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556ac92798bSmrg  rm -f "$tmpdepfile"
557ac92798bSmrg  ;;
558ac92798bSmrg
559ac92798bSmrgmsvc7msys)
560ac92798bSmrg  # This case exists only to let depend.m4 do its work.  It works by
561ac92798bSmrg  # looking at the text of this script.  This case will never be run,
562ac92798bSmrg  # since it is checked for above.
563ac92798bSmrg  exit 1
564ac92798bSmrg  ;;
565a966c04fSmrg
566a966c04fSmrg#nosideeffect)
567a966c04fSmrg  # This comment above is used by automake to tell side-effect
568a966c04fSmrg  # dependency tracking mechanisms from slower ones.
569a966c04fSmrg
570a966c04fSmrgdashmstdout)
571a966c04fSmrg  # Important note: in order to support this mode, a compiler *must*
572a966c04fSmrg  # always write the preprocessed file to stdout, regardless of -o.
573a966c04fSmrg  "$@" || exit $?
574a966c04fSmrg
575a966c04fSmrg  # Remove the call to Libtool.
576a966c04fSmrg  if test "$libtool" = yes; then
5772e2dd055Smrg    while test "X$1" != 'X--mode=compile'; do
578a966c04fSmrg      shift
579a966c04fSmrg    done
580a966c04fSmrg    shift
581a966c04fSmrg  fi
582a966c04fSmrg
583ac92798bSmrg  # Remove '-o $object'.
584a966c04fSmrg  IFS=" "
585a966c04fSmrg  for arg
586a966c04fSmrg  do
587a966c04fSmrg    case $arg in
588a966c04fSmrg    -o)
589a966c04fSmrg      shift
590a966c04fSmrg      ;;
591a966c04fSmrg    $object)
592a966c04fSmrg      shift
593a966c04fSmrg      ;;
594a966c04fSmrg    *)
595a966c04fSmrg      set fnord "$@" "$arg"
596a966c04fSmrg      shift # fnord
597a966c04fSmrg      shift # $arg
598a966c04fSmrg      ;;
599a966c04fSmrg    esac
600a966c04fSmrg  done
601a966c04fSmrg
602a966c04fSmrg  test -z "$dashmflag" && dashmflag=-M
603ac92798bSmrg  # Require at least two characters before searching for ':'
604a966c04fSmrg  # in the target name.  This is to cope with DOS-style filenames:
605ac92798bSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606a966c04fSmrg  "$@" $dashmflag |
607ac92798bSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608a966c04fSmrg  rm -f "$depfile"
609a966c04fSmrg  cat < "$tmpdepfile" > "$depfile"
610ac92798bSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611ac92798bSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
612ac92798bSmrg  tr ' ' "$nl" < "$tmpdepfile" \
613ac92798bSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614ac92798bSmrg    | sed -e 's/$/ :/' >> "$depfile"
615a966c04fSmrg  rm -f "$tmpdepfile"
616a966c04fSmrg  ;;
617a966c04fSmrg
618a966c04fSmrgdashXmstdout)
619a966c04fSmrg  # This case only exists to satisfy depend.m4.  It is never actually
620a966c04fSmrg  # run, as this mode is specially recognized in the preamble.
621a966c04fSmrg  exit 1
622a966c04fSmrg  ;;
623a966c04fSmrg
624a966c04fSmrgmakedepend)
625a966c04fSmrg  "$@" || exit $?
626a966c04fSmrg  # Remove any Libtool call
627a966c04fSmrg  if test "$libtool" = yes; then
6282e2dd055Smrg    while test "X$1" != 'X--mode=compile'; do
629a966c04fSmrg      shift
630a966c04fSmrg    done
631a966c04fSmrg    shift
632a966c04fSmrg  fi
633a966c04fSmrg  # X makedepend
634a966c04fSmrg  shift
6352e2dd055Smrg  cleared=no eat=no
6362e2dd055Smrg  for arg
6372e2dd055Smrg  do
638a966c04fSmrg    case $cleared in
639a966c04fSmrg    no)
640a966c04fSmrg      set ""; shift
641a966c04fSmrg      cleared=yes ;;
642a966c04fSmrg    esac
6432e2dd055Smrg    if test $eat = yes; then
6442e2dd055Smrg      eat=no
6452e2dd055Smrg      continue
6462e2dd055Smrg    fi
647a966c04fSmrg    case "$arg" in
648a966c04fSmrg    -D*|-I*)
649a966c04fSmrg      set fnord "$@" "$arg"; shift ;;
650a966c04fSmrg    # Strip any option that makedepend may not understand.  Remove
651a966c04fSmrg    # the object too, otherwise makedepend will parse it as a source file.
6522e2dd055Smrg    -arch)
6532e2dd055Smrg      eat=yes ;;
654a966c04fSmrg    -*|$object)
655a966c04fSmrg      ;;
656a966c04fSmrg    *)
657a966c04fSmrg      set fnord "$@" "$arg"; shift ;;
658a966c04fSmrg    esac
659a966c04fSmrg  done
6602e2dd055Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661a966c04fSmrg  touch "$tmpdepfile"
662a966c04fSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663a966c04fSmrg  rm -f "$depfile"
664ac92798bSmrg  # makedepend may prepend the VPATH from the source file name to the object.
665ac92798bSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666ac92798bSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667ac92798bSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668ac92798bSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
669ac92798bSmrg  sed '1,2d' "$tmpdepfile" \
670ac92798bSmrg    | tr ' ' "$nl" \
671ac92798bSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672ac92798bSmrg    | sed -e 's/$/ :/' >> "$depfile"
673a966c04fSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674a966c04fSmrg  ;;
675a966c04fSmrg
676a966c04fSmrgcpp)
677a966c04fSmrg  # Important note: in order to support this mode, a compiler *must*
678a966c04fSmrg  # always write the preprocessed file to stdout.
679a966c04fSmrg  "$@" || exit $?
680a966c04fSmrg
681a966c04fSmrg  # Remove the call to Libtool.
682a966c04fSmrg  if test "$libtool" = yes; then
6832e2dd055Smrg    while test "X$1" != 'X--mode=compile'; do
684a966c04fSmrg      shift
685a966c04fSmrg    done
686a966c04fSmrg    shift
687a966c04fSmrg  fi
688a966c04fSmrg
689ac92798bSmrg  # Remove '-o $object'.
690a966c04fSmrg  IFS=" "
691a966c04fSmrg  for arg
692a966c04fSmrg  do
693a966c04fSmrg    case $arg in
694a966c04fSmrg    -o)
695a966c04fSmrg      shift
696a966c04fSmrg      ;;
697a966c04fSmrg    $object)
698a966c04fSmrg      shift
699a966c04fSmrg      ;;
700a966c04fSmrg    *)
701a966c04fSmrg      set fnord "$@" "$arg"
702a966c04fSmrg      shift # fnord
703a966c04fSmrg      shift # $arg
704a966c04fSmrg      ;;
705a966c04fSmrg    esac
706a966c04fSmrg  done
707a966c04fSmrg
708ac92798bSmrg  "$@" -E \
709ac92798bSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710ac92798bSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711ac92798bSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
712a966c04fSmrg  rm -f "$depfile"
713a966c04fSmrg  echo "$object : \\" > "$depfile"
714a966c04fSmrg  cat < "$tmpdepfile" >> "$depfile"
715a966c04fSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716a966c04fSmrg  rm -f "$tmpdepfile"
717a966c04fSmrg  ;;
718a966c04fSmrg
719a966c04fSmrgmsvisualcpp)
720a966c04fSmrg  # Important note: in order to support this mode, a compiler *must*
7212e2dd055Smrg  # always write the preprocessed file to stdout.
722a966c04fSmrg  "$@" || exit $?
7232e2dd055Smrg
7242e2dd055Smrg  # Remove the call to Libtool.
7252e2dd055Smrg  if test "$libtool" = yes; then
7262e2dd055Smrg    while test "X$1" != 'X--mode=compile'; do
7272e2dd055Smrg      shift
7282e2dd055Smrg    done
7292e2dd055Smrg    shift
7302e2dd055Smrg  fi
7312e2dd055Smrg
732a966c04fSmrg  IFS=" "
733a966c04fSmrg  for arg
734a966c04fSmrg  do
735a966c04fSmrg    case "$arg" in
7362e2dd055Smrg    -o)
7372e2dd055Smrg      shift
7382e2dd055Smrg      ;;
7392e2dd055Smrg    $object)
7402e2dd055Smrg      shift
7412e2dd055Smrg      ;;
742a966c04fSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743ac92798bSmrg        set fnord "$@"
744ac92798bSmrg        shift
745ac92798bSmrg        shift
746ac92798bSmrg        ;;
747a966c04fSmrg    *)
748ac92798bSmrg        set fnord "$@" "$arg"
749ac92798bSmrg        shift
750ac92798bSmrg        shift
751ac92798bSmrg        ;;
752a966c04fSmrg    esac
753a966c04fSmrg  done
7542e2dd055Smrg  "$@" -E 2>/dev/null |
7552e2dd055Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756a966c04fSmrg  rm -f "$depfile"
757a966c04fSmrg  echo "$object : \\" > "$depfile"
758ac92798bSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759ac92798bSmrg  echo "$tab" >> "$depfile"
7602e2dd055Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761a966c04fSmrg  rm -f "$tmpdepfile"
762a966c04fSmrg  ;;
763a966c04fSmrg
7642e2dd055Smrgmsvcmsys)
7652e2dd055Smrg  # This case exists only to let depend.m4 do its work.  It works by
7662e2dd055Smrg  # looking at the text of this script.  This case will never be run,
7672e2dd055Smrg  # since it is checked for above.
7682e2dd055Smrg  exit 1
7692e2dd055Smrg  ;;
7702e2dd055Smrg
771a966c04fSmrgnone)
772a966c04fSmrg  exec "$@"
773a966c04fSmrg  ;;
774a966c04fSmrg
775a966c04fSmrg*)
776a966c04fSmrg  echo "Unknown depmode $depmode" 1>&2
777a966c04fSmrg  exit 1
778a966c04fSmrg  ;;
779a966c04fSmrgesac
780a966c04fSmrg
781a966c04fSmrgexit 0
782a966c04fSmrg
783a966c04fSmrg# Local Variables:
784a966c04fSmrg# mode: shell-script
785a966c04fSmrg# sh-indentation: 2
786a966c04fSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
787a966c04fSmrg# time-stamp-start: "scriptversion="
788a966c04fSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7892e2dd055Smrg# time-stamp-time-zone: "UTC"
7902e2dd055Smrg# time-stamp-end: "; # UTC"
791a966c04fSmrg# End:
792