16ea72052Smrg#! /bin/sh
26ea72052Smrg# depcomp - compile a program generating dependencies as side-effects
3168023feSmrg
4e32e2dabSmrgscriptversion=2024-06-19.01; # UTC
5168023feSmrg
6e32e2dabSmrg# Copyright (C) 1999-2024 Free Software Foundation, Inc.
76ea72052Smrg
86ea72052Smrg# This program is free software; you can redistribute it and/or modify
96ea72052Smrg# it under the terms of the GNU General Public License as published by
106ea72052Smrg# the Free Software Foundation; either version 2, or (at your option)
116ea72052Smrg# any later version.
126ea72052Smrg
136ea72052Smrg# This program is distributed in the hope that it will be useful,
146ea72052Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
156ea72052Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
166ea72052Smrg# GNU General Public License for more details.
176ea72052Smrg
186ea72052Smrg# You should have received a copy of the GNU General Public License
19f3e6ffc5Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
206ea72052Smrg
216ea72052Smrg# As a special exception to the GNU General Public License, if you
226ea72052Smrg# distribute this file as part of a program that contains a
236ea72052Smrg# configuration script generated by Autoconf, you may include it under
246ea72052Smrg# the same distribution terms that you use for the rest of that program.
256ea72052Smrg
266ea72052Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
276ea72052Smrg
28168023feSmrgcase $1 in
29168023feSmrg  '')
30b0c24a08Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31b0c24a08Smrg    exit 1;
32b0c24a08Smrg    ;;
33168023feSmrg  -h | --h*)
34168023feSmrg    cat <<\EOF
35168023feSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36168023feSmrg
37168023feSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38168023feSmrgas side-effects.
39168023feSmrg
40168023feSmrgEnvironment variables:
41168023feSmrg  depmode     Dependency tracking mode.
42b0c24a08Smrg  source      Source file read by 'PROGRAMS ARGS'.
43b0c24a08Smrg  object      Object file output by 'PROGRAMS ARGS'.
44168023feSmrg  DEPDIR      directory where to store dependencies.
45168023feSmrg  depfile     Dependency file to output.
46b0c24a08Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
47168023feSmrg  libtool     Whether libtool is used (yes/no).
48168023feSmrg
49168023feSmrgReport bugs to <bug-automake@gnu.org>.
50e32e2dabSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
51e32e2dabSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>.
52168023feSmrgEOF
53168023feSmrg    exit $?
54168023feSmrg    ;;
55168023feSmrg  -v | --v*)
56e32e2dabSmrg    echo "depcomp (GNU Automake) $scriptversion"
57168023feSmrg    exit $?
58168023feSmrg    ;;
59168023feSmrgesac
60168023feSmrg
61b0c24a08Smrg# Get the directory component of the given path, and save it in the
62b0c24a08Smrg# global variables '$dir'.  Note that this directory component will
63b0c24a08Smrg# be either empty or ending with a '/' character.  This is deliberate.
64b0c24a08Smrgset_dir_from ()
65b0c24a08Smrg{
66b0c24a08Smrg  case $1 in
67b0c24a08Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
68b0c24a08Smrg      *) dir=;;
69b0c24a08Smrg  esac
70b0c24a08Smrg}
71b0c24a08Smrg
72b0c24a08Smrg# Get the suffix-stripped basename of the given path, and save it the
73b0c24a08Smrg# global variable '$base'.
74b0c24a08Smrgset_base_from ()
75b0c24a08Smrg{
76b0c24a08Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
77b0c24a08Smrg}
78b0c24a08Smrg
79b0c24a08Smrg# If no dependency file was actually created by the compiler invocation,
80b0c24a08Smrg# we still have to create a dummy depfile, to avoid errors with the
81b0c24a08Smrg# Makefile "include basename.Plo" scheme.
82b0c24a08Smrgmake_dummy_depfile ()
83b0c24a08Smrg{
84b0c24a08Smrg  echo "#dummy" > "$depfile"
85b0c24a08Smrg}
86b0c24a08Smrg
87b0c24a08Smrg# Factor out some common post-processing of the generated depfile.
88b0c24a08Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
89b0c24a08Smrgaix_post_process_depfile ()
90b0c24a08Smrg{
91b0c24a08Smrg  # If the compiler actually managed to produce a dependency file,
92b0c24a08Smrg  # post-process it.
93b0c24a08Smrg  if test -f "$tmpdepfile"; then
94b0c24a08Smrg    # Each line is of the form 'foo.o: dependency.h'.
95b0c24a08Smrg    # Do two passes, one to just change these to
96b0c24a08Smrg    #   $object: dependency.h
97b0c24a08Smrg    # and one to simply output
98b0c24a08Smrg    #   dependency.h:
99b0c24a08Smrg    # which is needed to avoid the deleted-header problem.
100b0c24a08Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
101b0c24a08Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
102b0c24a08Smrg    } > "$depfile"
103b0c24a08Smrg    rm -f "$tmpdepfile"
104b0c24a08Smrg  else
105b0c24a08Smrg    make_dummy_depfile
106b0c24a08Smrg  fi
107b0c24a08Smrg}
108b0c24a08Smrg
109b0c24a08Smrg# A tabulation character.
110b0c24a08Smrgtab='	'
111b0c24a08Smrg# A newline character.
112b0c24a08Smrgnl='
113b0c24a08Smrg'
114b0c24a08Smrg# Character ranges might be problematic outside the C locale.
115b0c24a08Smrg# These definitions help.
116b0c24a08Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
117b0c24a08Smrglower=abcdefghijklmnopqrstuvwxyz
118b0c24a08Smrgalpha=${upper}${lower}
119b0c24a08Smrg
1206ea72052Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1216ea72052Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1226ea72052Smrg  exit 1
1236ea72052Smrgfi
1246ea72052Smrg
125168023feSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
126168023feSmrgdepfile=${depfile-`echo "$object" |
127168023feSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1286ea72052Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1296ea72052Smrg
1306ea72052Smrgrm -f "$tmpdepfile"
1316ea72052Smrg
132e32e2dabSmrg# Avoid interference from the environment.
133b0c24a08Smrggccflag= dashmflag=
134b0c24a08Smrg
1356ea72052Smrg# Some modes work just like other modes, but use different flags.  We
1366ea72052Smrg# parameterize here, but still list the modes in the big case below,
1376ea72052Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1386ea72052Smrg# here, because this file can only contain one case statement.
1396ea72052Smrgif test "$depmode" = hp; then
1406ea72052Smrg  # HP compiler uses -M and no extra arg.
1416ea72052Smrg  gccflag=-M
1426ea72052Smrg  depmode=gcc
1436ea72052Smrgfi
1446ea72052Smrg
1456ea72052Smrgif test "$depmode" = dashXmstdout; then
146b0c24a08Smrg  # This is just like dashmstdout with a different argument.
147b0c24a08Smrg  dashmflag=-xM
148b0c24a08Smrg  depmode=dashmstdout
1496ea72052Smrgfi
1506ea72052Smrg
151168023feSmrgcygpath_u="cygpath -u -f -"
152168023feSmrgif test "$depmode" = msvcmsys; then
153b0c24a08Smrg  # This is just like msvisualcpp but w/o cygpath translation.
154b0c24a08Smrg  # Just convert the backslash-escaped backslashes to single forward
155b0c24a08Smrg  # slashes to satisfy depend.m4
156b0c24a08Smrg  cygpath_u='sed s,\\\\,/,g'
157b0c24a08Smrg  depmode=msvisualcpp
158b0c24a08Smrgfi
159b0c24a08Smrg
160b0c24a08Smrgif test "$depmode" = msvc7msys; then
161b0c24a08Smrg  # This is just like msvc7 but w/o cygpath translation.
162b0c24a08Smrg  # Just convert the backslash-escaped backslashes to single forward
163b0c24a08Smrg  # slashes to satisfy depend.m4
164b0c24a08Smrg  cygpath_u='sed s,\\\\,/,g'
165b0c24a08Smrg  depmode=msvc7
166b0c24a08Smrgfi
167b0c24a08Smrg
168b0c24a08Smrgif test "$depmode" = xlc; then
169b0c24a08Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
170b0c24a08Smrg  gccflag=-qmakedep=gcc,-MF
171b0c24a08Smrg  depmode=gcc
172168023feSmrgfi
173168023feSmrg
1746ea72052Smrgcase "$depmode" in
1756ea72052Smrggcc3)
1766ea72052Smrg## gcc 3 implements dependency tracking that does exactly what
1776ea72052Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1786ea72052Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
179168023feSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
180168023feSmrg## the command line argument order; so add the flags where they
181168023feSmrg## appear in depend2.am.  Note that the slowdown incurred here
182168023feSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
183168023feSmrg  for arg
184168023feSmrg  do
185168023feSmrg    case $arg in
186168023feSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
187168023feSmrg    *)  set fnord "$@" "$arg" ;;
188168023feSmrg    esac
189168023feSmrg    shift # fnord
190168023feSmrg    shift # $arg
191168023feSmrg  done
192168023feSmrg  "$@"
1936ea72052Smrg  stat=$?
194b0c24a08Smrg  if test $stat -ne 0; then
1956ea72052Smrg    rm -f "$tmpdepfile"
1966ea72052Smrg    exit $stat
1976ea72052Smrg  fi
1986ea72052Smrg  mv "$tmpdepfile" "$depfile"
1996ea72052Smrg  ;;
2006ea72052Smrg
2016ea72052Smrggcc)
202e32e2dabSmrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers.
203e32e2dabSmrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler.
204b0c24a08Smrg## (see the conditional assignment to $gccflag above).
2056ea72052Smrg## There are various ways to get dependency output from gcc.  Here's
2066ea72052Smrg## why we pick this rather obscure method:
2076ea72052Smrg## - Don't want to use -MD because we'd like the dependencies to end
2086ea72052Smrg##   up in a subdir.  Having to rename by hand is ugly.
2096ea72052Smrg##   (We might end up doing this anyway to support other compilers.)
2106ea72052Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
211b0c24a08Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
212b0c24a08Smrg##   supported by the other compilers which use the 'gcc' depmode.
2136ea72052Smrg## - Using -M directly means running the compiler twice (even worse
2146ea72052Smrg##   than renaming).
2156ea72052Smrg  if test -z "$gccflag"; then
2166ea72052Smrg    gccflag=-MD,
2176ea72052Smrg  fi
2186ea72052Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
2196ea72052Smrg  stat=$?
220b0c24a08Smrg  if test $stat -ne 0; then
2216ea72052Smrg    rm -f "$tmpdepfile"
2226ea72052Smrg    exit $stat
2236ea72052Smrg  fi
2246ea72052Smrg  rm -f "$depfile"
2256ea72052Smrg  echo "$object : \\" > "$depfile"
226b0c24a08Smrg  # The second -e expression handles DOS-style file names with drive
227b0c24a08Smrg  # letters.
2286ea72052Smrg  sed -e 's/^[^:]*: / /' \
2296ea72052Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
230b0c24a08Smrg## This next piece of magic avoids the "deleted header file" problem.
2316ea72052Smrg## The problem is that when a header file which appears in a .P file
2326ea72052Smrg## is deleted, the dependency causes make to die (because there is
2336ea72052Smrg## typically no way to rebuild the header).  We avoid this by adding
2346ea72052Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2356ea72052Smrg## this for us directly.
236b0c24a08Smrg## Some versions of gcc put a space before the ':'.  On the theory
2376ea72052Smrg## that the space means something, we add a space to the output as
238b0c24a08Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
239b0c24a08Smrg## to the object.  Take care to not repeat it in the output.
2406ea72052Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
2416ea72052Smrg## correctly.  Breaking it into two sed invocations is a workaround.
242b0c24a08Smrg  tr ' ' "$nl" < "$tmpdepfile" \
243b0c24a08Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
244b0c24a08Smrg    | sed -e 's/$/ :/' >> "$depfile"
2456ea72052Smrg  rm -f "$tmpdepfile"
2466ea72052Smrg  ;;
2476ea72052Smrg
2486ea72052Smrghp)
2496ea72052Smrg  # This case exists only to let depend.m4 do its work.  It works by
2506ea72052Smrg  # looking at the text of this script.  This case will never be run,
2516ea72052Smrg  # since it is checked for above.
2526ea72052Smrg  exit 1
2536ea72052Smrg  ;;
2546ea72052Smrg
2556ea72052Smrgsgi)
2566ea72052Smrg  if test "$libtool" = yes; then
2576ea72052Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2586ea72052Smrg  else
2596ea72052Smrg    "$@" -MDupdate "$tmpdepfile"
2606ea72052Smrg  fi
2616ea72052Smrg  stat=$?
262b0c24a08Smrg  if test $stat -ne 0; then
2636ea72052Smrg    rm -f "$tmpdepfile"
2646ea72052Smrg    exit $stat
2656ea72052Smrg  fi
2666ea72052Smrg  rm -f "$depfile"
2676ea72052Smrg
2686ea72052Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2696ea72052Smrg    echo "$object : \\" > "$depfile"
2706ea72052Smrg    # Clip off the initial element (the dependent).  Don't try to be
2716ea72052Smrg    # clever and replace this with sed code, as IRIX sed won't handle
2726ea72052Smrg    # lines with more than a fixed number of characters (4096 in
2736ea72052Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
274b0c24a08Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
2756ea72052Smrg    # dependency line.
276b0c24a08Smrg    tr ' ' "$nl" < "$tmpdepfile" \
277b0c24a08Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
278b0c24a08Smrg      | tr "$nl" ' ' >> "$depfile"
279168023feSmrg    echo >> "$depfile"
2806ea72052Smrg    # The second pass generates a dummy entry for each header file.
281b0c24a08Smrg    tr ' ' "$nl" < "$tmpdepfile" \
282b0c24a08Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
283b0c24a08Smrg      >> "$depfile"
2846ea72052Smrg  else
285b0c24a08Smrg    make_dummy_depfile
2866ea72052Smrg  fi
2876ea72052Smrg  rm -f "$tmpdepfile"
2886ea72052Smrg  ;;
2896ea72052Smrg
290b0c24a08Smrgxlc)
291b0c24a08Smrg  # This case exists only to let depend.m4 do its work.  It works by
292b0c24a08Smrg  # looking at the text of this script.  This case will never be run,
293b0c24a08Smrg  # since it is checked for above.
294b0c24a08Smrg  exit 1
295b0c24a08Smrg  ;;
296b0c24a08Smrg
2976ea72052Smrgaix)
2986ea72052Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2996ea72052Smrg  # in a .u file.  In older versions, this file always lives in the
300b0c24a08Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3016ea72052Smrg  # start of each line; $object doesn't have directory information.
3026ea72052Smrg  # Version 6 uses the directory in both cases.
303b0c24a08Smrg  set_dir_from "$object"
304b0c24a08Smrg  set_base_from "$object"
3056ea72052Smrg  if test "$libtool" = yes; then
306168023feSmrg    tmpdepfile1=$dir$base.u
307168023feSmrg    tmpdepfile2=$base.u
308168023feSmrg    tmpdepfile3=$dir.libs/$base.u
3096ea72052Smrg    "$@" -Wc,-M
3106ea72052Smrg  else
311168023feSmrg    tmpdepfile1=$dir$base.u
312168023feSmrg    tmpdepfile2=$dir$base.u
313168023feSmrg    tmpdepfile3=$dir$base.u
3146ea72052Smrg    "$@" -M
3156ea72052Smrg  fi
3166ea72052Smrg  stat=$?
317b0c24a08Smrg  if test $stat -ne 0; then
318168023feSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3196ea72052Smrg    exit $stat
3206ea72052Smrg  fi
3216ea72052Smrg
322168023feSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
323168023feSmrg  do
324168023feSmrg    test -f "$tmpdepfile" && break
325168023feSmrg  done
326b0c24a08Smrg  aix_post_process_depfile
327b0c24a08Smrg  ;;
328b0c24a08Smrg
329b0c24a08Smrgtcc)
330b0c24a08Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
331b0c24a08Smrg  # FIXME: That version still under development at the moment of writing.
332b0c24a08Smrg  #        Make that this statement remains true also for stable, released
333b0c24a08Smrg  #        versions.
334b0c24a08Smrg  # It will wrap lines (doesn't matter whether long or short) with a
335b0c24a08Smrg  # trailing '\', as in:
336b0c24a08Smrg  #
337b0c24a08Smrg  #   foo.o : \
338b0c24a08Smrg  #    foo.c \
339b0c24a08Smrg  #    foo.h \
340b0c24a08Smrg  #
341b0c24a08Smrg  # It will put a trailing '\' even on the last line, and will use leading
342b0c24a08Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
343b0c24a08Smrg  # "Emit spaces for -MD").
344b0c24a08Smrg  "$@" -MD -MF "$tmpdepfile"
345b0c24a08Smrg  stat=$?
346b0c24a08Smrg  if test $stat -ne 0; then
347b0c24a08Smrg    rm -f "$tmpdepfile"
348b0c24a08Smrg    exit $stat
3496ea72052Smrg  fi
350b0c24a08Smrg  rm -f "$depfile"
351b0c24a08Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
352b0c24a08Smrg  # We have to change lines of the first kind to '$object: \'.
353b0c24a08Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
354b0c24a08Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
355b0c24a08Smrg  # dummy dependency, to avoid the deleted-header problem.
356b0c24a08Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3576ea72052Smrg  rm -f "$tmpdepfile"
3586ea72052Smrg  ;;
3596ea72052Smrg
360b0c24a08Smrg## The order of this option in the case statement is important, since the
361b0c24a08Smrg## shell code in configure will try each of these formats in the order
362b0c24a08Smrg## listed in this file.  A plain '-MD' option would be understood by many
363b0c24a08Smrg## compilers, so we must ensure this comes after the gcc and icc options.
364b0c24a08Smrgpgcc)
365b0c24a08Smrg  # Portland's C compiler understands '-MD'.
366b0c24a08Smrg  # Will always output deps to 'file.d' where file is the root name of the
367b0c24a08Smrg  # source file under compilation, even if file resides in a subdirectory.
368b0c24a08Smrg  # The object file name does not affect the name of the '.d' file.
369b0c24a08Smrg  # pgcc 10.2 will output
3706ea72052Smrg  #    foo.o: sub/foo.c sub/foo.h
371b0c24a08Smrg  # and will wrap long lines using '\' :
3726ea72052Smrg  #    foo.o: sub/foo.c ... \
3736ea72052Smrg  #     sub/foo.h ... \
3746ea72052Smrg  #     ...
375b0c24a08Smrg  set_dir_from "$object"
376b0c24a08Smrg  # Use the source, not the object, to determine the base name, since
377b0c24a08Smrg  # that's sadly what pgcc will do too.
378b0c24a08Smrg  set_base_from "$source"
379b0c24a08Smrg  tmpdepfile=$base.d
380b0c24a08Smrg
381b0c24a08Smrg  # For projects that build the same source file twice into different object
382b0c24a08Smrg  # files, the pgcc approach of using the *source* file root name can cause
383b0c24a08Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
384b0c24a08Smrg  # the same $tmpdepfile.
385b0c24a08Smrg  lockdir=$base.d-lock
386b0c24a08Smrg  trap "
387b0c24a08Smrg    echo '$0: caught signal, cleaning up...' >&2
388b0c24a08Smrg    rmdir '$lockdir'
389b0c24a08Smrg    exit 1
390b0c24a08Smrg  " 1 2 13 15
391b0c24a08Smrg  numtries=100
392b0c24a08Smrg  i=$numtries
393b0c24a08Smrg  while test $i -gt 0; do
394b0c24a08Smrg    # mkdir is a portable test-and-set.
395b0c24a08Smrg    if mkdir "$lockdir" 2>/dev/null; then
396b0c24a08Smrg      # This process acquired the lock.
397b0c24a08Smrg      "$@" -MD
398b0c24a08Smrg      stat=$?
399b0c24a08Smrg      # Release the lock.
400b0c24a08Smrg      rmdir "$lockdir"
401b0c24a08Smrg      break
402b0c24a08Smrg    else
403b0c24a08Smrg      # If the lock is being held by a different process, wait
404b0c24a08Smrg      # until the winning process is done or we timeout.
405b0c24a08Smrg      while test -d "$lockdir" && test $i -gt 0; do
406b0c24a08Smrg        sleep 1
407b0c24a08Smrg        i=`expr $i - 1`
408b0c24a08Smrg      done
409b0c24a08Smrg    fi
410b0c24a08Smrg    i=`expr $i - 1`
411b0c24a08Smrg  done
412b0c24a08Smrg  trap - 1 2 13 15
413b0c24a08Smrg  if test $i -le 0; then
414b0c24a08Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
415b0c24a08Smrg    echo "$0: check lockdir '$lockdir'" >&2
416b0c24a08Smrg    exit 1
417b0c24a08Smrg  fi
4186ea72052Smrg
419b0c24a08Smrg  if test $stat -ne 0; then
4206ea72052Smrg    rm -f "$tmpdepfile"
4216ea72052Smrg    exit $stat
4226ea72052Smrg  fi
4236ea72052Smrg  rm -f "$depfile"
4246ea72052Smrg  # Each line is of the form `foo.o: dependent.h',
4256ea72052Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4266ea72052Smrg  # Do two passes, one to just change these to
4276ea72052Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4286ea72052Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4296ea72052Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4306ea72052Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
431b0c24a08Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
432b0c24a08Smrg    | sed -e 's/$/ :/' >> "$depfile"
4336ea72052Smrg  rm -f "$tmpdepfile"
4346ea72052Smrg  ;;
4356ea72052Smrg
436168023feSmrghp2)
437168023feSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
438168023feSmrg  # compilers, which have integrated preprocessors.  The correct option
439168023feSmrg  # to use with these is +Maked; it writes dependencies to a file named
440168023feSmrg  # 'foo.d', which lands next to the object file, wherever that
441168023feSmrg  # happens to be.
442168023feSmrg  # Much of this is similar to the tru64 case; see comments there.
443b0c24a08Smrg  set_dir_from  "$object"
444b0c24a08Smrg  set_base_from "$object"
445168023feSmrg  if test "$libtool" = yes; then
446168023feSmrg    tmpdepfile1=$dir$base.d
447168023feSmrg    tmpdepfile2=$dir.libs/$base.d
448168023feSmrg    "$@" -Wc,+Maked
449168023feSmrg  else
450168023feSmrg    tmpdepfile1=$dir$base.d
451168023feSmrg    tmpdepfile2=$dir$base.d
452168023feSmrg    "$@" +Maked
453168023feSmrg  fi
454168023feSmrg  stat=$?
455b0c24a08Smrg  if test $stat -ne 0; then
456168023feSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
457168023feSmrg     exit $stat
458168023feSmrg  fi
459168023feSmrg
460168023feSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
461168023feSmrg  do
462168023feSmrg    test -f "$tmpdepfile" && break
463168023feSmrg  done
464168023feSmrg  if test -f "$tmpdepfile"; then
465b0c24a08Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
466b0c24a08Smrg    # Add 'dependent.h:' lines.
467168023feSmrg    sed -ne '2,${
468b0c24a08Smrg               s/^ *//
469b0c24a08Smrg               s/ \\*$//
470b0c24a08Smrg               s/$/:/
471b0c24a08Smrg               p
472b0c24a08Smrg             }' "$tmpdepfile" >> "$depfile"
473168023feSmrg  else
474b0c24a08Smrg    make_dummy_depfile
475168023feSmrg  fi
476168023feSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
477168023feSmrg  ;;
478168023feSmrg
4796ea72052Smrgtru64)
480b0c24a08Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
481b0c24a08Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
482b0c24a08Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
483b0c24a08Smrg  # dependencies in 'foo.d' instead, so we check for that too.
484b0c24a08Smrg  # Subdirectories are respected.
485b0c24a08Smrg  set_dir_from  "$object"
486b0c24a08Smrg  set_base_from "$object"
487b0c24a08Smrg
488b0c24a08Smrg  if test "$libtool" = yes; then
489b0c24a08Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
490b0c24a08Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
491b0c24a08Smrg    # in $dir$base.o.d.  We have to check for both files, because
492b0c24a08Smrg    # one of the two compilations can be disabled.  We should prefer
493b0c24a08Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
494b0c24a08Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
495b0c24a08Smrg    # the former would cause a distcleancheck panic.
496b0c24a08Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
497b0c24a08Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
498b0c24a08Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
499b0c24a08Smrg    "$@" -Wc,-MD
500b0c24a08Smrg  else
501b0c24a08Smrg    tmpdepfile1=$dir$base.d
502b0c24a08Smrg    tmpdepfile2=$dir$base.d
503b0c24a08Smrg    tmpdepfile3=$dir$base.d
504b0c24a08Smrg    "$@" -MD
505b0c24a08Smrg  fi
506b0c24a08Smrg
507b0c24a08Smrg  stat=$?
508b0c24a08Smrg  if test $stat -ne 0; then
509b0c24a08Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
510b0c24a08Smrg    exit $stat
511b0c24a08Smrg  fi
512b0c24a08Smrg
513b0c24a08Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
514b0c24a08Smrg  do
515b0c24a08Smrg    test -f "$tmpdepfile" && break
516b0c24a08Smrg  done
517b0c24a08Smrg  # Same post-processing that is required for AIX mode.
518b0c24a08Smrg  aix_post_process_depfile
519b0c24a08Smrg  ;;
520b0c24a08Smrg
521b0c24a08Smrgmsvc7)
522b0c24a08Smrg  if test "$libtool" = yes; then
523b0c24a08Smrg    showIncludes=-Wc,-showIncludes
524b0c24a08Smrg  else
525b0c24a08Smrg    showIncludes=-showIncludes
526b0c24a08Smrg  fi
527b0c24a08Smrg  "$@" $showIncludes > "$tmpdepfile"
528b0c24a08Smrg  stat=$?
529b0c24a08Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
530b0c24a08Smrg  if test $stat -ne 0; then
531b0c24a08Smrg    rm -f "$tmpdepfile"
532b0c24a08Smrg    exit $stat
533b0c24a08Smrg  fi
534b0c24a08Smrg  rm -f "$depfile"
535b0c24a08Smrg  echo "$object : \\" > "$depfile"
536b0c24a08Smrg  # The first sed program below extracts the file names and escapes
537b0c24a08Smrg  # backslashes for cygpath.  The second sed program outputs the file
538b0c24a08Smrg  # name when reading, but also accumulates all include files in the
539b0c24a08Smrg  # hold buffer in order to output them again at the end.  This only
540b0c24a08Smrg  # works with sed implementations that can handle large buffers.
541b0c24a08Smrg  sed < "$tmpdepfile" -n '
542b0c24a08Smrg/^Note: including file:  *\(.*\)/ {
543b0c24a08Smrg  s//\1/
544b0c24a08Smrg  s/\\/\\\\/g
545b0c24a08Smrg  p
546b0c24a08Smrg}' | $cygpath_u | sort -u | sed -n '
547b0c24a08Smrgs/ /\\ /g
548b0c24a08Smrgs/\(.*\)/'"$tab"'\1 \\/p
549b0c24a08Smrgs/.\(.*\) \\/\1:/
550b0c24a08SmrgH
551b0c24a08Smrg$ {
552b0c24a08Smrg  s/.*/'"$tab"'/
553b0c24a08Smrg  G
554b0c24a08Smrg  p
555b0c24a08Smrg}' >> "$depfile"
556b0c24a08Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
557b0c24a08Smrg  rm -f "$tmpdepfile"
558b0c24a08Smrg  ;;
559b0c24a08Smrg
560b0c24a08Smrgmsvc7msys)
561b0c24a08Smrg  # This case exists only to let depend.m4 do its work.  It works by
562b0c24a08Smrg  # looking at the text of this script.  This case will never be run,
563b0c24a08Smrg  # since it is checked for above.
564b0c24a08Smrg  exit 1
565b0c24a08Smrg  ;;
5666ea72052Smrg
5676ea72052Smrg#nosideeffect)
5686ea72052Smrg  # This comment above is used by automake to tell side-effect
5696ea72052Smrg  # dependency tracking mechanisms from slower ones.
5706ea72052Smrg
5716ea72052Smrgdashmstdout)
5726ea72052Smrg  # Important note: in order to support this mode, a compiler *must*
5736ea72052Smrg  # always write the preprocessed file to stdout, regardless of -o.
5746ea72052Smrg  "$@" || exit $?
5756ea72052Smrg
5766ea72052Smrg  # Remove the call to Libtool.
5776ea72052Smrg  if test "$libtool" = yes; then
578168023feSmrg    while test "X$1" != 'X--mode=compile'; do
5796ea72052Smrg      shift
5806ea72052Smrg    done
5816ea72052Smrg    shift
5826ea72052Smrg  fi
5836ea72052Smrg
584b0c24a08Smrg  # Remove '-o $object'.
5856ea72052Smrg  IFS=" "
5866ea72052Smrg  for arg
5876ea72052Smrg  do
5886ea72052Smrg    case $arg in
5896ea72052Smrg    -o)
5906ea72052Smrg      shift
5916ea72052Smrg      ;;
5926ea72052Smrg    $object)
5936ea72052Smrg      shift
5946ea72052Smrg      ;;
5956ea72052Smrg    *)
5966ea72052Smrg      set fnord "$@" "$arg"
5976ea72052Smrg      shift # fnord
5986ea72052Smrg      shift # $arg
5996ea72052Smrg      ;;
6006ea72052Smrg    esac
6016ea72052Smrg  done
6026ea72052Smrg
6036ea72052Smrg  test -z "$dashmflag" && dashmflag=-M
604b0c24a08Smrg  # Require at least two characters before searching for ':'
6056ea72052Smrg  # in the target name.  This is to cope with DOS-style filenames:
606b0c24a08Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6076ea72052Smrg  "$@" $dashmflag |
608b0c24a08Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6096ea72052Smrg  rm -f "$depfile"
6106ea72052Smrg  cat < "$tmpdepfile" > "$depfile"
611b0c24a08Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
612b0c24a08Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
613b0c24a08Smrg  tr ' ' "$nl" < "$tmpdepfile" \
614b0c24a08Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
615b0c24a08Smrg    | sed -e 's/$/ :/' >> "$depfile"
6166ea72052Smrg  rm -f "$tmpdepfile"
6176ea72052Smrg  ;;
6186ea72052Smrg
6196ea72052SmrgdashXmstdout)
6206ea72052Smrg  # This case only exists to satisfy depend.m4.  It is never actually
6216ea72052Smrg  # run, as this mode is specially recognized in the preamble.
6226ea72052Smrg  exit 1
6236ea72052Smrg  ;;
6246ea72052Smrg
6256ea72052Smrgmakedepend)
6266ea72052Smrg  "$@" || exit $?
6276ea72052Smrg  # Remove any Libtool call
6286ea72052Smrg  if test "$libtool" = yes; then
629168023feSmrg    while test "X$1" != 'X--mode=compile'; do
6306ea72052Smrg      shift
6316ea72052Smrg    done
6326ea72052Smrg    shift
6336ea72052Smrg  fi
6346ea72052Smrg  # X makedepend
6356ea72052Smrg  shift
636168023feSmrg  cleared=no eat=no
637168023feSmrg  for arg
638168023feSmrg  do
6396ea72052Smrg    case $cleared in
6406ea72052Smrg    no)
6416ea72052Smrg      set ""; shift
6426ea72052Smrg      cleared=yes ;;
6436ea72052Smrg    esac
644168023feSmrg    if test $eat = yes; then
645168023feSmrg      eat=no
646168023feSmrg      continue
647168023feSmrg    fi
6486ea72052Smrg    case "$arg" in
6496ea72052Smrg    -D*|-I*)
6506ea72052Smrg      set fnord "$@" "$arg"; shift ;;
6516ea72052Smrg    # Strip any option that makedepend may not understand.  Remove
6526ea72052Smrg    # the object too, otherwise makedepend will parse it as a source file.
653168023feSmrg    -arch)
654168023feSmrg      eat=yes ;;
6556ea72052Smrg    -*|$object)
6566ea72052Smrg      ;;
6576ea72052Smrg    *)
6586ea72052Smrg      set fnord "$@" "$arg"; shift ;;
6596ea72052Smrg    esac
6606ea72052Smrg  done
661168023feSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6626ea72052Smrg  touch "$tmpdepfile"
6636ea72052Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6646ea72052Smrg  rm -f "$depfile"
665b0c24a08Smrg  # makedepend may prepend the VPATH from the source file name to the object.
666b0c24a08Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
667b0c24a08Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
668b0c24a08Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
669b0c24a08Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
670b0c24a08Smrg  sed '1,2d' "$tmpdepfile" \
671b0c24a08Smrg    | tr ' ' "$nl" \
672b0c24a08Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
673b0c24a08Smrg    | sed -e 's/$/ :/' >> "$depfile"
6746ea72052Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6756ea72052Smrg  ;;
6766ea72052Smrg
6776ea72052Smrgcpp)
6786ea72052Smrg  # Important note: in order to support this mode, a compiler *must*
6796ea72052Smrg  # always write the preprocessed file to stdout.
6806ea72052Smrg  "$@" || exit $?
6816ea72052Smrg
6826ea72052Smrg  # Remove the call to Libtool.
6836ea72052Smrg  if test "$libtool" = yes; then
684168023feSmrg    while test "X$1" != 'X--mode=compile'; do
6856ea72052Smrg      shift
6866ea72052Smrg    done
6876ea72052Smrg    shift
6886ea72052Smrg  fi
6896ea72052Smrg
690b0c24a08Smrg  # Remove '-o $object'.
6916ea72052Smrg  IFS=" "
6926ea72052Smrg  for arg
6936ea72052Smrg  do
6946ea72052Smrg    case $arg in
6956ea72052Smrg    -o)
6966ea72052Smrg      shift
6976ea72052Smrg      ;;
6986ea72052Smrg    $object)
6996ea72052Smrg      shift
7006ea72052Smrg      ;;
7016ea72052Smrg    *)
7026ea72052Smrg      set fnord "$@" "$arg"
7036ea72052Smrg      shift # fnord
7046ea72052Smrg      shift # $arg
7056ea72052Smrg      ;;
7066ea72052Smrg    esac
7076ea72052Smrg  done
7086ea72052Smrg
709b0c24a08Smrg  "$@" -E \
710b0c24a08Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711b0c24a08Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
712b0c24a08Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
7136ea72052Smrg  rm -f "$depfile"
7146ea72052Smrg  echo "$object : \\" > "$depfile"
7156ea72052Smrg  cat < "$tmpdepfile" >> "$depfile"
7166ea72052Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7176ea72052Smrg  rm -f "$tmpdepfile"
7186ea72052Smrg  ;;
7196ea72052Smrg
7206ea72052Smrgmsvisualcpp)
7216ea72052Smrg  # Important note: in order to support this mode, a compiler *must*
722168023feSmrg  # always write the preprocessed file to stdout.
7236ea72052Smrg  "$@" || exit $?
724168023feSmrg
725168023feSmrg  # Remove the call to Libtool.
726168023feSmrg  if test "$libtool" = yes; then
727168023feSmrg    while test "X$1" != 'X--mode=compile'; do
728168023feSmrg      shift
729168023feSmrg    done
730168023feSmrg    shift
731168023feSmrg  fi
732168023feSmrg
7336ea72052Smrg  IFS=" "
7346ea72052Smrg  for arg
7356ea72052Smrg  do
7366ea72052Smrg    case "$arg" in
737168023feSmrg    -o)
738168023feSmrg      shift
739168023feSmrg      ;;
740168023feSmrg    $object)
741168023feSmrg      shift
742168023feSmrg      ;;
7436ea72052Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
744b0c24a08Smrg        set fnord "$@"
745b0c24a08Smrg        shift
746b0c24a08Smrg        shift
747b0c24a08Smrg        ;;
7486ea72052Smrg    *)
749b0c24a08Smrg        set fnord "$@" "$arg"
750b0c24a08Smrg        shift
751b0c24a08Smrg        shift
752b0c24a08Smrg        ;;
7536ea72052Smrg    esac
7546ea72052Smrg  done
755168023feSmrg  "$@" -E 2>/dev/null |
756168023feSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7576ea72052Smrg  rm -f "$depfile"
7586ea72052Smrg  echo "$object : \\" > "$depfile"
759b0c24a08Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
760b0c24a08Smrg  echo "$tab" >> "$depfile"
761168023feSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7626ea72052Smrg  rm -f "$tmpdepfile"
7636ea72052Smrg  ;;
7646ea72052Smrg
765168023feSmrgmsvcmsys)
766168023feSmrg  # This case exists only to let depend.m4 do its work.  It works by
767168023feSmrg  # looking at the text of this script.  This case will never be run,
768168023feSmrg  # since it is checked for above.
769168023feSmrg  exit 1
770168023feSmrg  ;;
771168023feSmrg
7726ea72052Smrgnone)
7736ea72052Smrg  exec "$@"
7746ea72052Smrg  ;;
7756ea72052Smrg
7766ea72052Smrg*)
7776ea72052Smrg  echo "Unknown depmode $depmode" 1>&2
7786ea72052Smrg  exit 1
7796ea72052Smrg  ;;
7806ea72052Smrgesac
7816ea72052Smrg
7826ea72052Smrgexit 0
783168023feSmrg
784168023feSmrg# Local Variables:
785168023feSmrg# mode: shell-script
786168023feSmrg# sh-indentation: 2
787f3e6ffc5Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
788168023feSmrg# time-stamp-start: "scriptversion="
789168023feSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
790f3e6ffc5Smrg# time-stamp-time-zone: "UTC0"
791168023feSmrg# time-stamp-end: "; # UTC"
792168023feSmrg# End:
793