depcomp revision 576bbdfc
1fc89c0fbSmrg#! /bin/sh
2fc89c0fbSmrg# depcomp - compile a program generating dependencies as side-effects
3fc89c0fbSmrg
4576bbdfcSmrgscriptversion=2013-05-30.07; # UTC
5fc89c0fbSmrg
6576bbdfcSmrg# Copyright (C) 1999-2013 Free Software Foundation, Inc.
7fc89c0fbSmrg
8fc89c0fbSmrg# This program is free software; you can redistribute it and/or modify
9fc89c0fbSmrg# it under the terms of the GNU General Public License as published by
10fc89c0fbSmrg# the Free Software Foundation; either version 2, or (at your option)
11fc89c0fbSmrg# any later version.
12fc89c0fbSmrg
13fc89c0fbSmrg# This program is distributed in the hope that it will be useful,
14fc89c0fbSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15fc89c0fbSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16fc89c0fbSmrg# GNU General Public License for more details.
17fc89c0fbSmrg
18fc89c0fbSmrg# You should have received a copy of the GNU General Public License
1991ec45ceSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20fc89c0fbSmrg
21fc89c0fbSmrg# As a special exception to the GNU General Public License, if you
22fc89c0fbSmrg# distribute this file as part of a program that contains a
23fc89c0fbSmrg# configuration script generated by Autoconf, you may include it under
24fc89c0fbSmrg# the same distribution terms that you use for the rest of that program.
25fc89c0fbSmrg
26fc89c0fbSmrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27fc89c0fbSmrg
28fc89c0fbSmrgcase $1 in
29fc89c0fbSmrg  '')
30576bbdfcSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31576bbdfcSmrg    exit 1;
32576bbdfcSmrg    ;;
33fc89c0fbSmrg  -h | --h*)
34fc89c0fbSmrg    cat <<\EOF
35fc89c0fbSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36fc89c0fbSmrg
37fc89c0fbSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38fc89c0fbSmrgas side-effects.
39fc89c0fbSmrg
40fc89c0fbSmrgEnvironment variables:
41fc89c0fbSmrg  depmode     Dependency tracking mode.
42576bbdfcSmrg  source      Source file read by 'PROGRAMS ARGS'.
43576bbdfcSmrg  object      Object file output by 'PROGRAMS ARGS'.
44fc89c0fbSmrg  DEPDIR      directory where to store dependencies.
45fc89c0fbSmrg  depfile     Dependency file to output.
46576bbdfcSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
47fc89c0fbSmrg  libtool     Whether libtool is used (yes/no).
48fc89c0fbSmrg
49fc89c0fbSmrgReport bugs to <bug-automake@gnu.org>.
50fc89c0fbSmrgEOF
51fc89c0fbSmrg    exit $?
52fc89c0fbSmrg    ;;
53fc89c0fbSmrg  -v | --v*)
54fc89c0fbSmrg    echo "depcomp $scriptversion"
55fc89c0fbSmrg    exit $?
56fc89c0fbSmrg    ;;
57fc89c0fbSmrgesac
58fc89c0fbSmrg
59576bbdfcSmrg# Get the directory component of the given path, and save it in the
60576bbdfcSmrg# global variables '$dir'.  Note that this directory component will
61576bbdfcSmrg# be either empty or ending with a '/' character.  This is deliberate.
62576bbdfcSmrgset_dir_from ()
63576bbdfcSmrg{
64576bbdfcSmrg  case $1 in
65576bbdfcSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66576bbdfcSmrg      *) dir=;;
67576bbdfcSmrg  esac
68576bbdfcSmrg}
69576bbdfcSmrg
70576bbdfcSmrg# Get the suffix-stripped basename of the given path, and save it the
71576bbdfcSmrg# global variable '$base'.
72576bbdfcSmrgset_base_from ()
73576bbdfcSmrg{
74576bbdfcSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75576bbdfcSmrg}
76576bbdfcSmrg
77576bbdfcSmrg# If no dependency file was actually created by the compiler invocation,
78576bbdfcSmrg# we still have to create a dummy depfile, to avoid errors with the
79576bbdfcSmrg# Makefile "include basename.Plo" scheme.
80576bbdfcSmrgmake_dummy_depfile ()
81576bbdfcSmrg{
82576bbdfcSmrg  echo "#dummy" > "$depfile"
83576bbdfcSmrg}
84576bbdfcSmrg
85576bbdfcSmrg# Factor out some common post-processing of the generated depfile.
86576bbdfcSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87576bbdfcSmrgaix_post_process_depfile ()
88576bbdfcSmrg{
89576bbdfcSmrg  # If the compiler actually managed to produce a dependency file,
90576bbdfcSmrg  # post-process it.
91576bbdfcSmrg  if test -f "$tmpdepfile"; then
92576bbdfcSmrg    # Each line is of the form 'foo.o: dependency.h'.
93576bbdfcSmrg    # Do two passes, one to just change these to
94576bbdfcSmrg    #   $object: dependency.h
95576bbdfcSmrg    # and one to simply output
96576bbdfcSmrg    #   dependency.h:
97576bbdfcSmrg    # which is needed to avoid the deleted-header problem.
98576bbdfcSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99576bbdfcSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100576bbdfcSmrg    } > "$depfile"
101576bbdfcSmrg    rm -f "$tmpdepfile"
102576bbdfcSmrg  else
103576bbdfcSmrg    make_dummy_depfile
104576bbdfcSmrg  fi
105576bbdfcSmrg}
106576bbdfcSmrg
107576bbdfcSmrg# A tabulation character.
108576bbdfcSmrgtab='	'
109576bbdfcSmrg# A newline character.
110576bbdfcSmrgnl='
111576bbdfcSmrg'
112576bbdfcSmrg# Character ranges might be problematic outside the C locale.
113576bbdfcSmrg# These definitions help.
114576bbdfcSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115576bbdfcSmrglower=abcdefghijklmnopqrstuvwxyz
116576bbdfcSmrgdigits=0123456789
117576bbdfcSmrgalpha=${upper}${lower}
118576bbdfcSmrg
119fc89c0fbSmrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120fc89c0fbSmrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121fc89c0fbSmrg  exit 1
122fc89c0fbSmrgfi
123fc89c0fbSmrg
124fc89c0fbSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125fc89c0fbSmrgdepfile=${depfile-`echo "$object" |
126fc89c0fbSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127fc89c0fbSmrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128fc89c0fbSmrg
129fc89c0fbSmrgrm -f "$tmpdepfile"
130fc89c0fbSmrg
131576bbdfcSmrg# Avoid interferences from the environment.
132576bbdfcSmrggccflag= dashmflag=
133576bbdfcSmrg
134fc89c0fbSmrg# Some modes work just like other modes, but use different flags.  We
135fc89c0fbSmrg# parameterize here, but still list the modes in the big case below,
136fc89c0fbSmrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137fc89c0fbSmrg# here, because this file can only contain one case statement.
138fc89c0fbSmrgif test "$depmode" = hp; then
139fc89c0fbSmrg  # HP compiler uses -M and no extra arg.
140fc89c0fbSmrg  gccflag=-M
141fc89c0fbSmrg  depmode=gcc
142fc89c0fbSmrgfi
143fc89c0fbSmrg
144fc89c0fbSmrgif test "$depmode" = dashXmstdout; then
145576bbdfcSmrg  # This is just like dashmstdout with a different argument.
146576bbdfcSmrg  dashmflag=-xM
147576bbdfcSmrg  depmode=dashmstdout
148fc89c0fbSmrgfi
149fc89c0fbSmrg
15091ec45ceSmrgcygpath_u="cygpath -u -f -"
15191ec45ceSmrgif test "$depmode" = msvcmsys; then
152576bbdfcSmrg  # This is just like msvisualcpp but w/o cygpath translation.
153576bbdfcSmrg  # Just convert the backslash-escaped backslashes to single forward
154576bbdfcSmrg  # slashes to satisfy depend.m4
155576bbdfcSmrg  cygpath_u='sed s,\\\\,/,g'
156576bbdfcSmrg  depmode=msvisualcpp
157576bbdfcSmrgfi
158576bbdfcSmrg
159576bbdfcSmrgif test "$depmode" = msvc7msys; then
160576bbdfcSmrg  # This is just like msvc7 but w/o cygpath translation.
161576bbdfcSmrg  # Just convert the backslash-escaped backslashes to single forward
162576bbdfcSmrg  # slashes to satisfy depend.m4
163576bbdfcSmrg  cygpath_u='sed s,\\\\,/,g'
164576bbdfcSmrg  depmode=msvc7
165576bbdfcSmrgfi
166576bbdfcSmrg
167576bbdfcSmrgif test "$depmode" = xlc; then
168576bbdfcSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169576bbdfcSmrg  gccflag=-qmakedep=gcc,-MF
170576bbdfcSmrg  depmode=gcc
17191ec45ceSmrgfi
17291ec45ceSmrg
173fc89c0fbSmrgcase "$depmode" in
174fc89c0fbSmrggcc3)
175fc89c0fbSmrg## gcc 3 implements dependency tracking that does exactly what
176fc89c0fbSmrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177fc89c0fbSmrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178fc89c0fbSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179fc89c0fbSmrg## the command line argument order; so add the flags where they
180fc89c0fbSmrg## appear in depend2.am.  Note that the slowdown incurred here
181fc89c0fbSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182fc89c0fbSmrg  for arg
183fc89c0fbSmrg  do
184fc89c0fbSmrg    case $arg in
185fc89c0fbSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186fc89c0fbSmrg    *)  set fnord "$@" "$arg" ;;
187fc89c0fbSmrg    esac
188fc89c0fbSmrg    shift # fnord
189fc89c0fbSmrg    shift # $arg
190fc89c0fbSmrg  done
191fc89c0fbSmrg  "$@"
192fc89c0fbSmrg  stat=$?
193576bbdfcSmrg  if test $stat -ne 0; then
194fc89c0fbSmrg    rm -f "$tmpdepfile"
195fc89c0fbSmrg    exit $stat
196fc89c0fbSmrg  fi
197fc89c0fbSmrg  mv "$tmpdepfile" "$depfile"
198fc89c0fbSmrg  ;;
199fc89c0fbSmrg
200fc89c0fbSmrggcc)
201576bbdfcSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202576bbdfcSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203576bbdfcSmrg## (see the conditional assignment to $gccflag above).
204fc89c0fbSmrg## There are various ways to get dependency output from gcc.  Here's
205fc89c0fbSmrg## why we pick this rather obscure method:
206fc89c0fbSmrg## - Don't want to use -MD because we'd like the dependencies to end
207fc89c0fbSmrg##   up in a subdir.  Having to rename by hand is ugly.
208fc89c0fbSmrg##   (We might end up doing this anyway to support other compilers.)
209fc89c0fbSmrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210576bbdfcSmrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211576bbdfcSmrg##   supported by the other compilers which use the 'gcc' depmode.
212fc89c0fbSmrg## - Using -M directly means running the compiler twice (even worse
213fc89c0fbSmrg##   than renaming).
214fc89c0fbSmrg  if test -z "$gccflag"; then
215fc89c0fbSmrg    gccflag=-MD,
216fc89c0fbSmrg  fi
217fc89c0fbSmrg  "$@" -Wp,"$gccflag$tmpdepfile"
218fc89c0fbSmrg  stat=$?
219576bbdfcSmrg  if test $stat -ne 0; then
220fc89c0fbSmrg    rm -f "$tmpdepfile"
221fc89c0fbSmrg    exit $stat
222fc89c0fbSmrg  fi
223fc89c0fbSmrg  rm -f "$depfile"
224fc89c0fbSmrg  echo "$object : \\" > "$depfile"
225576bbdfcSmrg  # The second -e expression handles DOS-style file names with drive
226576bbdfcSmrg  # letters.
227fc89c0fbSmrg  sed -e 's/^[^:]*: / /' \
228fc89c0fbSmrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229576bbdfcSmrg## This next piece of magic avoids the "deleted header file" problem.
230fc89c0fbSmrg## The problem is that when a header file which appears in a .P file
231fc89c0fbSmrg## is deleted, the dependency causes make to die (because there is
232fc89c0fbSmrg## typically no way to rebuild the header).  We avoid this by adding
233fc89c0fbSmrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234fc89c0fbSmrg## this for us directly.
235576bbdfcSmrg## Some versions of gcc put a space before the ':'.  On the theory
236fc89c0fbSmrg## that the space means something, we add a space to the output as
237576bbdfcSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238576bbdfcSmrg## to the object.  Take care to not repeat it in the output.
239fc89c0fbSmrg## Some versions of the HPUX 10.20 sed can't process this invocation
240fc89c0fbSmrg## correctly.  Breaking it into two sed invocations is a workaround.
241576bbdfcSmrg  tr ' ' "$nl" < "$tmpdepfile" \
242576bbdfcSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243576bbdfcSmrg    | sed -e 's/$/ :/' >> "$depfile"
244fc89c0fbSmrg  rm -f "$tmpdepfile"
245fc89c0fbSmrg  ;;
246fc89c0fbSmrg
247fc89c0fbSmrghp)
248fc89c0fbSmrg  # This case exists only to let depend.m4 do its work.  It works by
249fc89c0fbSmrg  # looking at the text of this script.  This case will never be run,
250fc89c0fbSmrg  # since it is checked for above.
251fc89c0fbSmrg  exit 1
252fc89c0fbSmrg  ;;
253fc89c0fbSmrg
254fc89c0fbSmrgsgi)
255fc89c0fbSmrg  if test "$libtool" = yes; then
256fc89c0fbSmrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257fc89c0fbSmrg  else
258fc89c0fbSmrg    "$@" -MDupdate "$tmpdepfile"
259fc89c0fbSmrg  fi
260fc89c0fbSmrg  stat=$?
261576bbdfcSmrg  if test $stat -ne 0; then
262fc89c0fbSmrg    rm -f "$tmpdepfile"
263fc89c0fbSmrg    exit $stat
264fc89c0fbSmrg  fi
265fc89c0fbSmrg  rm -f "$depfile"
266fc89c0fbSmrg
267fc89c0fbSmrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268fc89c0fbSmrg    echo "$object : \\" > "$depfile"
269fc89c0fbSmrg    # Clip off the initial element (the dependent).  Don't try to be
270fc89c0fbSmrg    # clever and replace this with sed code, as IRIX sed won't handle
271fc89c0fbSmrg    # lines with more than a fixed number of characters (4096 in
272fc89c0fbSmrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273576bbdfcSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
274fc89c0fbSmrg    # dependency line.
275576bbdfcSmrg    tr ' ' "$nl" < "$tmpdepfile" \
276576bbdfcSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277576bbdfcSmrg      | tr "$nl" ' ' >> "$depfile"
27891ec45ceSmrg    echo >> "$depfile"
279fc89c0fbSmrg    # The second pass generates a dummy entry for each header file.
280576bbdfcSmrg    tr ' ' "$nl" < "$tmpdepfile" \
281576bbdfcSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282576bbdfcSmrg      >> "$depfile"
283fc89c0fbSmrg  else
284576bbdfcSmrg    make_dummy_depfile
285fc89c0fbSmrg  fi
286fc89c0fbSmrg  rm -f "$tmpdepfile"
287fc89c0fbSmrg  ;;
288fc89c0fbSmrg
289576bbdfcSmrgxlc)
290576bbdfcSmrg  # This case exists only to let depend.m4 do its work.  It works by
291576bbdfcSmrg  # looking at the text of this script.  This case will never be run,
292576bbdfcSmrg  # since it is checked for above.
293576bbdfcSmrg  exit 1
294576bbdfcSmrg  ;;
295576bbdfcSmrg
296fc89c0fbSmrgaix)
297fc89c0fbSmrg  # The C for AIX Compiler uses -M and outputs the dependencies
298fc89c0fbSmrg  # in a .u file.  In older versions, this file always lives in the
299576bbdfcSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300fc89c0fbSmrg  # start of each line; $object doesn't have directory information.
301fc89c0fbSmrg  # Version 6 uses the directory in both cases.
302576bbdfcSmrg  set_dir_from "$object"
303576bbdfcSmrg  set_base_from "$object"
304fc89c0fbSmrg  if test "$libtool" = yes; then
30591ec45ceSmrg    tmpdepfile1=$dir$base.u
30691ec45ceSmrg    tmpdepfile2=$base.u
30791ec45ceSmrg    tmpdepfile3=$dir.libs/$base.u
308fc89c0fbSmrg    "$@" -Wc,-M
309fc89c0fbSmrg  else
31091ec45ceSmrg    tmpdepfile1=$dir$base.u
31191ec45ceSmrg    tmpdepfile2=$dir$base.u
31291ec45ceSmrg    tmpdepfile3=$dir$base.u
313fc89c0fbSmrg    "$@" -M
314fc89c0fbSmrg  fi
315fc89c0fbSmrg  stat=$?
316576bbdfcSmrg  if test $stat -ne 0; then
31791ec45ceSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318fc89c0fbSmrg    exit $stat
319fc89c0fbSmrg  fi
320fc89c0fbSmrg
32191ec45ceSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
32291ec45ceSmrg  do
32391ec45ceSmrg    test -f "$tmpdepfile" && break
32491ec45ceSmrg  done
325576bbdfcSmrg  aix_post_process_depfile
326576bbdfcSmrg  ;;
327576bbdfcSmrg
328576bbdfcSmrgtcc)
329576bbdfcSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330576bbdfcSmrg  # FIXME: That version still under development at the moment of writing.
331576bbdfcSmrg  #        Make that this statement remains true also for stable, released
332576bbdfcSmrg  #        versions.
333576bbdfcSmrg  # It will wrap lines (doesn't matter whether long or short) with a
334576bbdfcSmrg  # trailing '\', as in:
335576bbdfcSmrg  #
336576bbdfcSmrg  #   foo.o : \
337576bbdfcSmrg  #    foo.c \
338576bbdfcSmrg  #    foo.h \
339576bbdfcSmrg  #
340576bbdfcSmrg  # It will put a trailing '\' even on the last line, and will use leading
341576bbdfcSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342576bbdfcSmrg  # "Emit spaces for -MD").
343576bbdfcSmrg  "$@" -MD -MF "$tmpdepfile"
344576bbdfcSmrg  stat=$?
345576bbdfcSmrg  if test $stat -ne 0; then
346576bbdfcSmrg    rm -f "$tmpdepfile"
347576bbdfcSmrg    exit $stat
348fc89c0fbSmrg  fi
349576bbdfcSmrg  rm -f "$depfile"
350576bbdfcSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351576bbdfcSmrg  # We have to change lines of the first kind to '$object: \'.
352576bbdfcSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353576bbdfcSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354576bbdfcSmrg  # dummy dependency, to avoid the deleted-header problem.
355576bbdfcSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356fc89c0fbSmrg  rm -f "$tmpdepfile"
357fc89c0fbSmrg  ;;
358fc89c0fbSmrg
359576bbdfcSmrg## The order of this option in the case statement is important, since the
360576bbdfcSmrg## shell code in configure will try each of these formats in the order
361576bbdfcSmrg## listed in this file.  A plain '-MD' option would be understood by many
362576bbdfcSmrg## compilers, so we must ensure this comes after the gcc and icc options.
363576bbdfcSmrgpgcc)
364576bbdfcSmrg  # Portland's C compiler understands '-MD'.
365576bbdfcSmrg  # Will always output deps to 'file.d' where file is the root name of the
366576bbdfcSmrg  # source file under compilation, even if file resides in a subdirectory.
367576bbdfcSmrg  # The object file name does not affect the name of the '.d' file.
368576bbdfcSmrg  # pgcc 10.2 will output
369fc89c0fbSmrg  #    foo.o: sub/foo.c sub/foo.h
370576bbdfcSmrg  # and will wrap long lines using '\' :
371fc89c0fbSmrg  #    foo.o: sub/foo.c ... \
372fc89c0fbSmrg  #     sub/foo.h ... \
373fc89c0fbSmrg  #     ...
374576bbdfcSmrg  set_dir_from "$object"
375576bbdfcSmrg  # Use the source, not the object, to determine the base name, since
376576bbdfcSmrg  # that's sadly what pgcc will do too.
377576bbdfcSmrg  set_base_from "$source"
378576bbdfcSmrg  tmpdepfile=$base.d
379576bbdfcSmrg
380576bbdfcSmrg  # For projects that build the same source file twice into different object
381576bbdfcSmrg  # files, the pgcc approach of using the *source* file root name can cause
382576bbdfcSmrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383576bbdfcSmrg  # the same $tmpdepfile.
384576bbdfcSmrg  lockdir=$base.d-lock
385576bbdfcSmrg  trap "
386576bbdfcSmrg    echo '$0: caught signal, cleaning up...' >&2
387576bbdfcSmrg    rmdir '$lockdir'
388576bbdfcSmrg    exit 1
389576bbdfcSmrg  " 1 2 13 15
390576bbdfcSmrg  numtries=100
391576bbdfcSmrg  i=$numtries
392576bbdfcSmrg  while test $i -gt 0; do
393576bbdfcSmrg    # mkdir is a portable test-and-set.
394576bbdfcSmrg    if mkdir "$lockdir" 2>/dev/null; then
395576bbdfcSmrg      # This process acquired the lock.
396576bbdfcSmrg      "$@" -MD
397576bbdfcSmrg      stat=$?
398576bbdfcSmrg      # Release the lock.
399576bbdfcSmrg      rmdir "$lockdir"
400576bbdfcSmrg      break
401576bbdfcSmrg    else
402576bbdfcSmrg      # If the lock is being held by a different process, wait
403576bbdfcSmrg      # until the winning process is done or we timeout.
404576bbdfcSmrg      while test -d "$lockdir" && test $i -gt 0; do
405576bbdfcSmrg        sleep 1
406576bbdfcSmrg        i=`expr $i - 1`
407576bbdfcSmrg      done
408576bbdfcSmrg    fi
409576bbdfcSmrg    i=`expr $i - 1`
410576bbdfcSmrg  done
411576bbdfcSmrg  trap - 1 2 13 15
412576bbdfcSmrg  if test $i -le 0; then
413576bbdfcSmrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414576bbdfcSmrg    echo "$0: check lockdir '$lockdir'" >&2
415576bbdfcSmrg    exit 1
416576bbdfcSmrg  fi
417fc89c0fbSmrg
418576bbdfcSmrg  if test $stat -ne 0; then
419fc89c0fbSmrg    rm -f "$tmpdepfile"
420fc89c0fbSmrg    exit $stat
421fc89c0fbSmrg  fi
422fc89c0fbSmrg  rm -f "$depfile"
423fc89c0fbSmrg  # Each line is of the form `foo.o: dependent.h',
424fc89c0fbSmrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425fc89c0fbSmrg  # Do two passes, one to just change these to
426fc89c0fbSmrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427fc89c0fbSmrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428fc89c0fbSmrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429fc89c0fbSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
430576bbdfcSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431576bbdfcSmrg    | sed -e 's/$/ :/' >> "$depfile"
432fc89c0fbSmrg  rm -f "$tmpdepfile"
433fc89c0fbSmrg  ;;
434fc89c0fbSmrg
435fc89c0fbSmrghp2)
436fc89c0fbSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437fc89c0fbSmrg  # compilers, which have integrated preprocessors.  The correct option
438fc89c0fbSmrg  # to use with these is +Maked; it writes dependencies to a file named
439fc89c0fbSmrg  # 'foo.d', which lands next to the object file, wherever that
440fc89c0fbSmrg  # happens to be.
441fc89c0fbSmrg  # Much of this is similar to the tru64 case; see comments there.
442576bbdfcSmrg  set_dir_from  "$object"
443576bbdfcSmrg  set_base_from "$object"
444fc89c0fbSmrg  if test "$libtool" = yes; then
445fc89c0fbSmrg    tmpdepfile1=$dir$base.d
446fc89c0fbSmrg    tmpdepfile2=$dir.libs/$base.d
447fc89c0fbSmrg    "$@" -Wc,+Maked
448fc89c0fbSmrg  else
449fc89c0fbSmrg    tmpdepfile1=$dir$base.d
450fc89c0fbSmrg    tmpdepfile2=$dir$base.d
451fc89c0fbSmrg    "$@" +Maked
452fc89c0fbSmrg  fi
453fc89c0fbSmrg  stat=$?
454576bbdfcSmrg  if test $stat -ne 0; then
455fc89c0fbSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456fc89c0fbSmrg     exit $stat
457fc89c0fbSmrg  fi
458fc89c0fbSmrg
459fc89c0fbSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460fc89c0fbSmrg  do
461fc89c0fbSmrg    test -f "$tmpdepfile" && break
462fc89c0fbSmrg  done
463fc89c0fbSmrg  if test -f "$tmpdepfile"; then
464576bbdfcSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465576bbdfcSmrg    # Add 'dependent.h:' lines.
46691ec45ceSmrg    sed -ne '2,${
467576bbdfcSmrg               s/^ *//
468576bbdfcSmrg               s/ \\*$//
469576bbdfcSmrg               s/$/:/
470576bbdfcSmrg               p
471576bbdfcSmrg             }' "$tmpdepfile" >> "$depfile"
472fc89c0fbSmrg  else
473576bbdfcSmrg    make_dummy_depfile
474fc89c0fbSmrg  fi
475fc89c0fbSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476fc89c0fbSmrg  ;;
477fc89c0fbSmrg
478fc89c0fbSmrgtru64)
479576bbdfcSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480576bbdfcSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481576bbdfcSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482576bbdfcSmrg  # dependencies in 'foo.d' instead, so we check for that too.
483576bbdfcSmrg  # Subdirectories are respected.
484576bbdfcSmrg  set_dir_from  "$object"
485576bbdfcSmrg  set_base_from "$object"
486576bbdfcSmrg
487576bbdfcSmrg  if test "$libtool" = yes; then
488576bbdfcSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489576bbdfcSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490576bbdfcSmrg    # in $dir$base.o.d.  We have to check for both files, because
491576bbdfcSmrg    # one of the two compilations can be disabled.  We should prefer
492576bbdfcSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493576bbdfcSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
494576bbdfcSmrg    # the former would cause a distcleancheck panic.
495576bbdfcSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496576bbdfcSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497576bbdfcSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498576bbdfcSmrg    "$@" -Wc,-MD
499576bbdfcSmrg  else
500576bbdfcSmrg    tmpdepfile1=$dir$base.d
501576bbdfcSmrg    tmpdepfile2=$dir$base.d
502576bbdfcSmrg    tmpdepfile3=$dir$base.d
503576bbdfcSmrg    "$@" -MD
504576bbdfcSmrg  fi
505576bbdfcSmrg
506576bbdfcSmrg  stat=$?
507576bbdfcSmrg  if test $stat -ne 0; then
508576bbdfcSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509576bbdfcSmrg    exit $stat
510576bbdfcSmrg  fi
511576bbdfcSmrg
512576bbdfcSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513576bbdfcSmrg  do
514576bbdfcSmrg    test -f "$tmpdepfile" && break
515576bbdfcSmrg  done
516576bbdfcSmrg  # Same post-processing that is required for AIX mode.
517576bbdfcSmrg  aix_post_process_depfile
518576bbdfcSmrg  ;;
519576bbdfcSmrg
520576bbdfcSmrgmsvc7)
521576bbdfcSmrg  if test "$libtool" = yes; then
522576bbdfcSmrg    showIncludes=-Wc,-showIncludes
523576bbdfcSmrg  else
524576bbdfcSmrg    showIncludes=-showIncludes
525576bbdfcSmrg  fi
526576bbdfcSmrg  "$@" $showIncludes > "$tmpdepfile"
527576bbdfcSmrg  stat=$?
528576bbdfcSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
529576bbdfcSmrg  if test $stat -ne 0; then
530576bbdfcSmrg    rm -f "$tmpdepfile"
531576bbdfcSmrg    exit $stat
532576bbdfcSmrg  fi
533576bbdfcSmrg  rm -f "$depfile"
534576bbdfcSmrg  echo "$object : \\" > "$depfile"
535576bbdfcSmrg  # The first sed program below extracts the file names and escapes
536576bbdfcSmrg  # backslashes for cygpath.  The second sed program outputs the file
537576bbdfcSmrg  # name when reading, but also accumulates all include files in the
538576bbdfcSmrg  # hold buffer in order to output them again at the end.  This only
539576bbdfcSmrg  # works with sed implementations that can handle large buffers.
540576bbdfcSmrg  sed < "$tmpdepfile" -n '
541576bbdfcSmrg/^Note: including file:  *\(.*\)/ {
542576bbdfcSmrg  s//\1/
543576bbdfcSmrg  s/\\/\\\\/g
544576bbdfcSmrg  p
545576bbdfcSmrg}' | $cygpath_u | sort -u | sed -n '
546576bbdfcSmrgs/ /\\ /g
547576bbdfcSmrgs/\(.*\)/'"$tab"'\1 \\/p
548576bbdfcSmrgs/.\(.*\) \\/\1:/
549576bbdfcSmrgH
550576bbdfcSmrg$ {
551576bbdfcSmrg  s/.*/'"$tab"'/
552576bbdfcSmrg  G
553576bbdfcSmrg  p
554576bbdfcSmrg}' >> "$depfile"
555576bbdfcSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556576bbdfcSmrg  rm -f "$tmpdepfile"
557576bbdfcSmrg  ;;
558576bbdfcSmrg
559576bbdfcSmrgmsvc7msys)
560576bbdfcSmrg  # This case exists only to let depend.m4 do its work.  It works by
561576bbdfcSmrg  # looking at the text of this script.  This case will never be run,
562576bbdfcSmrg  # since it is checked for above.
563576bbdfcSmrg  exit 1
564576bbdfcSmrg  ;;
565fc89c0fbSmrg
566fc89c0fbSmrg#nosideeffect)
567fc89c0fbSmrg  # This comment above is used by automake to tell side-effect
568fc89c0fbSmrg  # dependency tracking mechanisms from slower ones.
569fc89c0fbSmrg
570fc89c0fbSmrgdashmstdout)
571fc89c0fbSmrg  # Important note: in order to support this mode, a compiler *must*
572fc89c0fbSmrg  # always write the preprocessed file to stdout, regardless of -o.
573fc89c0fbSmrg  "$@" || exit $?
574fc89c0fbSmrg
575fc89c0fbSmrg  # Remove the call to Libtool.
576fc89c0fbSmrg  if test "$libtool" = yes; then
57791ec45ceSmrg    while test "X$1" != 'X--mode=compile'; do
578fc89c0fbSmrg      shift
579fc89c0fbSmrg    done
580fc89c0fbSmrg    shift
581fc89c0fbSmrg  fi
582fc89c0fbSmrg
583576bbdfcSmrg  # Remove '-o $object'.
584fc89c0fbSmrg  IFS=" "
585fc89c0fbSmrg  for arg
586fc89c0fbSmrg  do
587fc89c0fbSmrg    case $arg in
588fc89c0fbSmrg    -o)
589fc89c0fbSmrg      shift
590fc89c0fbSmrg      ;;
591fc89c0fbSmrg    $object)
592fc89c0fbSmrg      shift
593fc89c0fbSmrg      ;;
594fc89c0fbSmrg    *)
595fc89c0fbSmrg      set fnord "$@" "$arg"
596fc89c0fbSmrg      shift # fnord
597fc89c0fbSmrg      shift # $arg
598fc89c0fbSmrg      ;;
599fc89c0fbSmrg    esac
600fc89c0fbSmrg  done
601fc89c0fbSmrg
602fc89c0fbSmrg  test -z "$dashmflag" && dashmflag=-M
603576bbdfcSmrg  # Require at least two characters before searching for ':'
604fc89c0fbSmrg  # in the target name.  This is to cope with DOS-style filenames:
605576bbdfcSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606fc89c0fbSmrg  "$@" $dashmflag |
607576bbdfcSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608fc89c0fbSmrg  rm -f "$depfile"
609fc89c0fbSmrg  cat < "$tmpdepfile" > "$depfile"
610576bbdfcSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611576bbdfcSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
612576bbdfcSmrg  tr ' ' "$nl" < "$tmpdepfile" \
613576bbdfcSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614576bbdfcSmrg    | sed -e 's/$/ :/' >> "$depfile"
615fc89c0fbSmrg  rm -f "$tmpdepfile"
616fc89c0fbSmrg  ;;
617fc89c0fbSmrg
618fc89c0fbSmrgdashXmstdout)
619fc89c0fbSmrg  # This case only exists to satisfy depend.m4.  It is never actually
620fc89c0fbSmrg  # run, as this mode is specially recognized in the preamble.
621fc89c0fbSmrg  exit 1
622fc89c0fbSmrg  ;;
623fc89c0fbSmrg
624fc89c0fbSmrgmakedepend)
625fc89c0fbSmrg  "$@" || exit $?
626fc89c0fbSmrg  # Remove any Libtool call
627fc89c0fbSmrg  if test "$libtool" = yes; then
62891ec45ceSmrg    while test "X$1" != 'X--mode=compile'; do
629fc89c0fbSmrg      shift
630fc89c0fbSmrg    done
631fc89c0fbSmrg    shift
632fc89c0fbSmrg  fi
633fc89c0fbSmrg  # X makedepend
634fc89c0fbSmrg  shift
63591ec45ceSmrg  cleared=no eat=no
63691ec45ceSmrg  for arg
63791ec45ceSmrg  do
638fc89c0fbSmrg    case $cleared in
639fc89c0fbSmrg    no)
640fc89c0fbSmrg      set ""; shift
641fc89c0fbSmrg      cleared=yes ;;
642fc89c0fbSmrg    esac
64391ec45ceSmrg    if test $eat = yes; then
64491ec45ceSmrg      eat=no
64591ec45ceSmrg      continue
64691ec45ceSmrg    fi
647fc89c0fbSmrg    case "$arg" in
648fc89c0fbSmrg    -D*|-I*)
649fc89c0fbSmrg      set fnord "$@" "$arg"; shift ;;
650fc89c0fbSmrg    # Strip any option that makedepend may not understand.  Remove
651fc89c0fbSmrg    # the object too, otherwise makedepend will parse it as a source file.
65291ec45ceSmrg    -arch)
65391ec45ceSmrg      eat=yes ;;
654fc89c0fbSmrg    -*|$object)
655fc89c0fbSmrg      ;;
656fc89c0fbSmrg    *)
657fc89c0fbSmrg      set fnord "$@" "$arg"; shift ;;
658fc89c0fbSmrg    esac
659fc89c0fbSmrg  done
66091ec45ceSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661fc89c0fbSmrg  touch "$tmpdepfile"
662fc89c0fbSmrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663fc89c0fbSmrg  rm -f "$depfile"
664576bbdfcSmrg  # makedepend may prepend the VPATH from the source file name to the object.
665576bbdfcSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666576bbdfcSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667576bbdfcSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668576bbdfcSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
669576bbdfcSmrg  sed '1,2d' "$tmpdepfile" \
670576bbdfcSmrg    | tr ' ' "$nl" \
671576bbdfcSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672576bbdfcSmrg    | sed -e 's/$/ :/' >> "$depfile"
673fc89c0fbSmrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674fc89c0fbSmrg  ;;
675fc89c0fbSmrg
676fc89c0fbSmrgcpp)
677fc89c0fbSmrg  # Important note: in order to support this mode, a compiler *must*
678fc89c0fbSmrg  # always write the preprocessed file to stdout.
679fc89c0fbSmrg  "$@" || exit $?
680fc89c0fbSmrg
681fc89c0fbSmrg  # Remove the call to Libtool.
682fc89c0fbSmrg  if test "$libtool" = yes; then
68391ec45ceSmrg    while test "X$1" != 'X--mode=compile'; do
684fc89c0fbSmrg      shift
685fc89c0fbSmrg    done
686fc89c0fbSmrg    shift
687fc89c0fbSmrg  fi
688fc89c0fbSmrg
689576bbdfcSmrg  # Remove '-o $object'.
690fc89c0fbSmrg  IFS=" "
691fc89c0fbSmrg  for arg
692fc89c0fbSmrg  do
693fc89c0fbSmrg    case $arg in
694fc89c0fbSmrg    -o)
695fc89c0fbSmrg      shift
696fc89c0fbSmrg      ;;
697fc89c0fbSmrg    $object)
698fc89c0fbSmrg      shift
699fc89c0fbSmrg      ;;
700fc89c0fbSmrg    *)
701fc89c0fbSmrg      set fnord "$@" "$arg"
702fc89c0fbSmrg      shift # fnord
703fc89c0fbSmrg      shift # $arg
704fc89c0fbSmrg      ;;
705fc89c0fbSmrg    esac
706fc89c0fbSmrg  done
707fc89c0fbSmrg
708576bbdfcSmrg  "$@" -E \
709576bbdfcSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710576bbdfcSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711576bbdfcSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
712fc89c0fbSmrg  rm -f "$depfile"
713fc89c0fbSmrg  echo "$object : \\" > "$depfile"
714fc89c0fbSmrg  cat < "$tmpdepfile" >> "$depfile"
715fc89c0fbSmrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716fc89c0fbSmrg  rm -f "$tmpdepfile"
717fc89c0fbSmrg  ;;
718fc89c0fbSmrg
719fc89c0fbSmrgmsvisualcpp)
720fc89c0fbSmrg  # Important note: in order to support this mode, a compiler *must*
72191ec45ceSmrg  # always write the preprocessed file to stdout.
722fc89c0fbSmrg  "$@" || exit $?
72391ec45ceSmrg
72491ec45ceSmrg  # Remove the call to Libtool.
72591ec45ceSmrg  if test "$libtool" = yes; then
72691ec45ceSmrg    while test "X$1" != 'X--mode=compile'; do
72791ec45ceSmrg      shift
72891ec45ceSmrg    done
72991ec45ceSmrg    shift
73091ec45ceSmrg  fi
73191ec45ceSmrg
732fc89c0fbSmrg  IFS=" "
733fc89c0fbSmrg  for arg
734fc89c0fbSmrg  do
735fc89c0fbSmrg    case "$arg" in
73691ec45ceSmrg    -o)
73791ec45ceSmrg      shift
73891ec45ceSmrg      ;;
73991ec45ceSmrg    $object)
74091ec45ceSmrg      shift
74191ec45ceSmrg      ;;
742fc89c0fbSmrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743576bbdfcSmrg        set fnord "$@"
744576bbdfcSmrg        shift
745576bbdfcSmrg        shift
746576bbdfcSmrg        ;;
747fc89c0fbSmrg    *)
748576bbdfcSmrg        set fnord "$@" "$arg"
749576bbdfcSmrg        shift
750576bbdfcSmrg        shift
751576bbdfcSmrg        ;;
752fc89c0fbSmrg    esac
753fc89c0fbSmrg  done
75491ec45ceSmrg  "$@" -E 2>/dev/null |
75591ec45ceSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756fc89c0fbSmrg  rm -f "$depfile"
757fc89c0fbSmrg  echo "$object : \\" > "$depfile"
758576bbdfcSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759576bbdfcSmrg  echo "$tab" >> "$depfile"
76091ec45ceSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761fc89c0fbSmrg  rm -f "$tmpdepfile"
762fc89c0fbSmrg  ;;
763fc89c0fbSmrg
76491ec45ceSmrgmsvcmsys)
76591ec45ceSmrg  # This case exists only to let depend.m4 do its work.  It works by
76691ec45ceSmrg  # looking at the text of this script.  This case will never be run,
76791ec45ceSmrg  # since it is checked for above.
76891ec45ceSmrg  exit 1
76991ec45ceSmrg  ;;
77091ec45ceSmrg
771fc89c0fbSmrgnone)
772fc89c0fbSmrg  exec "$@"
773fc89c0fbSmrg  ;;
774fc89c0fbSmrg
775fc89c0fbSmrg*)
776fc89c0fbSmrg  echo "Unknown depmode $depmode" 1>&2
777fc89c0fbSmrg  exit 1
778fc89c0fbSmrg  ;;
779fc89c0fbSmrgesac
780fc89c0fbSmrg
781fc89c0fbSmrgexit 0
782fc89c0fbSmrg
783fc89c0fbSmrg# Local Variables:
784fc89c0fbSmrg# mode: shell-script
785fc89c0fbSmrg# sh-indentation: 2
786fc89c0fbSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
787fc89c0fbSmrg# time-stamp-start: "scriptversion="
788fc89c0fbSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
78991ec45ceSmrg# time-stamp-time-zone: "UTC"
79091ec45ceSmrg# time-stamp-end: "; # UTC"
791fc89c0fbSmrg# End:
792