1f7ec340bSmacallan#! /bin/sh
2f7ec340bSmacallan# depcomp - compile a program generating dependencies as side-effects
3f7ec340bSmacallan
466ab3337Smrgscriptversion=2018-03-07.03; # UTC
5f7ec340bSmacallan
666ab3337Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
7f7ec340bSmacallan
8f7ec340bSmacallan# This program is free software; you can redistribute it and/or modify
9f7ec340bSmacallan# it under the terms of the GNU General Public License as published by
10f7ec340bSmacallan# the Free Software Foundation; either version 2, or (at your option)
11f7ec340bSmacallan# any later version.
12f7ec340bSmacallan
13f7ec340bSmacallan# This program is distributed in the hope that it will be useful,
14f7ec340bSmacallan# but WITHOUT ANY WARRANTY; without even the implied warranty of
15f7ec340bSmacallan# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16f7ec340bSmacallan# GNU General Public License for more details.
17f7ec340bSmacallan
18f7ec340bSmacallan# You should have received a copy of the GNU General Public License
1966ab3337Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20f7ec340bSmacallan
21f7ec340bSmacallan# As a special exception to the GNU General Public License, if you
22f7ec340bSmacallan# distribute this file as part of a program that contains a
23f7ec340bSmacallan# configuration script generated by Autoconf, you may include it under
24f7ec340bSmacallan# the same distribution terms that you use for the rest of that program.
25f7ec340bSmacallan
26f7ec340bSmacallan# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27f7ec340bSmacallan
28f7ec340bSmacallancase $1 in
29f7ec340bSmacallan  '')
3066ab3337Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
3166ab3337Smrg    exit 1;
3266ab3337Smrg    ;;
33f7ec340bSmacallan  -h | --h*)
34f7ec340bSmacallan    cat <<\EOF
35f7ec340bSmacallanUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36f7ec340bSmacallan
37f7ec340bSmacallanRun PROGRAMS ARGS to compile a file, generating dependencies
38f7ec340bSmacallanas side-effects.
39f7ec340bSmacallan
40f7ec340bSmacallanEnvironment variables:
41f7ec340bSmacallan  depmode     Dependency tracking mode.
422a75d1c4Smrg  source      Source file read by 'PROGRAMS ARGS'.
432a75d1c4Smrg  object      Object file output by 'PROGRAMS ARGS'.
44f7ec340bSmacallan  DEPDIR      directory where to store dependencies.
45f7ec340bSmacallan  depfile     Dependency file to output.
462a75d1c4Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
47f7ec340bSmacallan  libtool     Whether libtool is used (yes/no).
48f7ec340bSmacallan
49f7ec340bSmacallanReport bugs to <bug-automake@gnu.org>.
50f7ec340bSmacallanEOF
51f7ec340bSmacallan    exit $?
52f7ec340bSmacallan    ;;
53f7ec340bSmacallan  -v | --v*)
54f7ec340bSmacallan    echo "depcomp $scriptversion"
55f7ec340bSmacallan    exit $?
56f7ec340bSmacallan    ;;
57f7ec340bSmacallanesac
58f7ec340bSmacallan
5966ab3337Smrg# Get the directory component of the given path, and save it in the
6066ab3337Smrg# global variables '$dir'.  Note that this directory component will
6166ab3337Smrg# be either empty or ending with a '/' character.  This is deliberate.
6266ab3337Smrgset_dir_from ()
6366ab3337Smrg{
6466ab3337Smrg  case $1 in
6566ab3337Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
6666ab3337Smrg      *) dir=;;
6766ab3337Smrg  esac
6866ab3337Smrg}
6966ab3337Smrg
7066ab3337Smrg# Get the suffix-stripped basename of the given path, and save it the
7166ab3337Smrg# global variable '$base'.
7266ab3337Smrgset_base_from ()
7366ab3337Smrg{
7466ab3337Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
7566ab3337Smrg}
7666ab3337Smrg
7766ab3337Smrg# If no dependency file was actually created by the compiler invocation,
7866ab3337Smrg# we still have to create a dummy depfile, to avoid errors with the
7966ab3337Smrg# Makefile "include basename.Plo" scheme.
8066ab3337Smrgmake_dummy_depfile ()
8166ab3337Smrg{
8266ab3337Smrg  echo "#dummy" > "$depfile"
8366ab3337Smrg}
8466ab3337Smrg
8566ab3337Smrg# Factor out some common post-processing of the generated depfile.
8666ab3337Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
8766ab3337Smrgaix_post_process_depfile ()
8866ab3337Smrg{
8966ab3337Smrg  # If the compiler actually managed to produce a dependency file,
9066ab3337Smrg  # post-process it.
9166ab3337Smrg  if test -f "$tmpdepfile"; then
9266ab3337Smrg    # Each line is of the form 'foo.o: dependency.h'.
9366ab3337Smrg    # Do two passes, one to just change these to
9466ab3337Smrg    #   $object: dependency.h
9566ab3337Smrg    # and one to simply output
9666ab3337Smrg    #   dependency.h:
9766ab3337Smrg    # which is needed to avoid the deleted-header problem.
9866ab3337Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
9966ab3337Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
10066ab3337Smrg    } > "$depfile"
10166ab3337Smrg    rm -f "$tmpdepfile"
10266ab3337Smrg  else
10366ab3337Smrg    make_dummy_depfile
10466ab3337Smrg  fi
10566ab3337Smrg}
10666ab3337Smrg
1072a75d1c4Smrg# A tabulation character.
1082a75d1c4Smrgtab='	'
1092a75d1c4Smrg# A newline character.
1102a75d1c4Smrgnl='
1112a75d1c4Smrg'
11266ab3337Smrg# Character ranges might be problematic outside the C locale.
11366ab3337Smrg# These definitions help.
11466ab3337Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
11566ab3337Smrglower=abcdefghijklmnopqrstuvwxyz
11666ab3337Smrgdigits=0123456789
11766ab3337Smrgalpha=${upper}${lower}
1182a75d1c4Smrg
119f7ec340bSmacallanif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120f7ec340bSmacallan  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121f7ec340bSmacallan  exit 1
122f7ec340bSmacallanfi
123f7ec340bSmacallan
124f7ec340bSmacallan# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125f7ec340bSmacallandepfile=${depfile-`echo "$object" |
126f7ec340bSmacallan  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127f7ec340bSmacallantmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128f7ec340bSmacallan
129f7ec340bSmacallanrm -f "$tmpdepfile"
130f7ec340bSmacallan
1312a75d1c4Smrg# Avoid interferences from the environment.
1322a75d1c4Smrggccflag= dashmflag=
1332a75d1c4Smrg
134f7ec340bSmacallan# Some modes work just like other modes, but use different flags.  We
135f7ec340bSmacallan# parameterize here, but still list the modes in the big case below,
136f7ec340bSmacallan# to make depend.m4 easier to write.  Note that we *cannot* use a case
137f7ec340bSmacallan# here, because this file can only contain one case statement.
138f7ec340bSmacallanif test "$depmode" = hp; then
139f7ec340bSmacallan  # HP compiler uses -M and no extra arg.
140f7ec340bSmacallan  gccflag=-M
141f7ec340bSmacallan  depmode=gcc
142f7ec340bSmacallanfi
143f7ec340bSmacallan
144f7ec340bSmacallanif test "$depmode" = dashXmstdout; then
14566ab3337Smrg  # This is just like dashmstdout with a different argument.
14666ab3337Smrg  dashmflag=-xM
14766ab3337Smrg  depmode=dashmstdout
148f7ec340bSmacallanfi
149f7ec340bSmacallan
1502a75d1c4Smrgcygpath_u="cygpath -u -f -"
1512a75d1c4Smrgif test "$depmode" = msvcmsys; then
15266ab3337Smrg  # This is just like msvisualcpp but w/o cygpath translation.
15366ab3337Smrg  # Just convert the backslash-escaped backslashes to single forward
15466ab3337Smrg  # slashes to satisfy depend.m4
15566ab3337Smrg  cygpath_u='sed s,\\\\,/,g'
15666ab3337Smrg  depmode=msvisualcpp
1572a75d1c4Smrgfi
1582a75d1c4Smrg
1592a75d1c4Smrgif test "$depmode" = msvc7msys; then
16066ab3337Smrg  # This is just like msvc7 but w/o cygpath translation.
16166ab3337Smrg  # Just convert the backslash-escaped backslashes to single forward
16266ab3337Smrg  # slashes to satisfy depend.m4
16366ab3337Smrg  cygpath_u='sed s,\\\\,/,g'
16466ab3337Smrg  depmode=msvc7
1652a75d1c4Smrgfi
1662a75d1c4Smrg
1672a75d1c4Smrgif test "$depmode" = xlc; then
16866ab3337Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
16966ab3337Smrg  gccflag=-qmakedep=gcc,-MF
17066ab3337Smrg  depmode=gcc
1712a75d1c4Smrgfi
1722a75d1c4Smrg
173f7ec340bSmacallancase "$depmode" in
174f7ec340bSmacallangcc3)
175f7ec340bSmacallan## gcc 3 implements dependency tracking that does exactly what
176f7ec340bSmacallan## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177f7ec340bSmacallan## it if -MD -MP comes after the -MF stuff.  Hmm.
1787ce7e03cSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1797ce7e03cSmrg## the command line argument order; so add the flags where they
1807ce7e03cSmrg## appear in depend2.am.  Note that the slowdown incurred here
1817ce7e03cSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1827ce7e03cSmrg  for arg
1837ce7e03cSmrg  do
1847ce7e03cSmrg    case $arg in
1857ce7e03cSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1867ce7e03cSmrg    *)  set fnord "$@" "$arg" ;;
1877ce7e03cSmrg    esac
1887ce7e03cSmrg    shift # fnord
1897ce7e03cSmrg    shift # $arg
1907ce7e03cSmrg  done
1917ce7e03cSmrg  "$@"
192f7ec340bSmacallan  stat=$?
19366ab3337Smrg  if test $stat -ne 0; then
194f7ec340bSmacallan    rm -f "$tmpdepfile"
195f7ec340bSmacallan    exit $stat
196f7ec340bSmacallan  fi
197f7ec340bSmacallan  mv "$tmpdepfile" "$depfile"
198f7ec340bSmacallan  ;;
199f7ec340bSmacallan
200f7ec340bSmacallangcc)
2012a75d1c4Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2022a75d1c4Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2032a75d1c4Smrg## (see the conditional assignment to $gccflag above).
204f7ec340bSmacallan## There are various ways to get dependency output from gcc.  Here's
205f7ec340bSmacallan## why we pick this rather obscure method:
206f7ec340bSmacallan## - Don't want to use -MD because we'd like the dependencies to end
207f7ec340bSmacallan##   up in a subdir.  Having to rename by hand is ugly.
208f7ec340bSmacallan##   (We might end up doing this anyway to support other compilers.)
209f7ec340bSmacallan## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2102a75d1c4Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2112a75d1c4Smrg##   supported by the other compilers which use the 'gcc' depmode.
212f7ec340bSmacallan## - Using -M directly means running the compiler twice (even worse
213f7ec340bSmacallan##   than renaming).
214f7ec340bSmacallan  if test -z "$gccflag"; then
215f7ec340bSmacallan    gccflag=-MD,
216f7ec340bSmacallan  fi
217f7ec340bSmacallan  "$@" -Wp,"$gccflag$tmpdepfile"
218f7ec340bSmacallan  stat=$?
21966ab3337Smrg  if test $stat -ne 0; then
220f7ec340bSmacallan    rm -f "$tmpdepfile"
221f7ec340bSmacallan    exit $stat
222f7ec340bSmacallan  fi
223f7ec340bSmacallan  rm -f "$depfile"
224f7ec340bSmacallan  echo "$object : \\" > "$depfile"
22566ab3337Smrg  # The second -e expression handles DOS-style file names with drive
22666ab3337Smrg  # letters.
227f7ec340bSmacallan  sed -e 's/^[^:]*: / /' \
228f7ec340bSmacallan      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2292a75d1c4Smrg## This next piece of magic avoids the "deleted header file" problem.
230f7ec340bSmacallan## The problem is that when a header file which appears in a .P file
231f7ec340bSmacallan## is deleted, the dependency causes make to die (because there is
232f7ec340bSmacallan## typically no way to rebuild the header).  We avoid this by adding
233f7ec340bSmacallan## dummy dependencies for each header file.  Too bad gcc doesn't do
234f7ec340bSmacallan## this for us directly.
2352a75d1c4Smrg## Some versions of gcc put a space before the ':'.  On the theory
236f7ec340bSmacallan## that the space means something, we add a space to the output as
2372a75d1c4Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2382a75d1c4Smrg## to the object.  Take care to not repeat it in the output.
239f7ec340bSmacallan## Some versions of the HPUX 10.20 sed can't process this invocation
240f7ec340bSmacallan## correctly.  Breaking it into two sed invocations is a workaround.
24166ab3337Smrg  tr ' ' "$nl" < "$tmpdepfile" \
24266ab3337Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
24366ab3337Smrg    | sed -e 's/$/ :/' >> "$depfile"
244f7ec340bSmacallan  rm -f "$tmpdepfile"
245f7ec340bSmacallan  ;;
246f7ec340bSmacallan
247f7ec340bSmacallanhp)
248f7ec340bSmacallan  # This case exists only to let depend.m4 do its work.  It works by
249f7ec340bSmacallan  # looking at the text of this script.  This case will never be run,
250f7ec340bSmacallan  # since it is checked for above.
251f7ec340bSmacallan  exit 1
252f7ec340bSmacallan  ;;
253f7ec340bSmacallan
254f7ec340bSmacallansgi)
255f7ec340bSmacallan  if test "$libtool" = yes; then
256f7ec340bSmacallan    "$@" "-Wp,-MDupdate,$tmpdepfile"
257f7ec340bSmacallan  else
258f7ec340bSmacallan    "$@" -MDupdate "$tmpdepfile"
259f7ec340bSmacallan  fi
260f7ec340bSmacallan  stat=$?
26166ab3337Smrg  if test $stat -ne 0; then
262f7ec340bSmacallan    rm -f "$tmpdepfile"
263f7ec340bSmacallan    exit $stat
264f7ec340bSmacallan  fi
265f7ec340bSmacallan  rm -f "$depfile"
266f7ec340bSmacallan
267f7ec340bSmacallan  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268f7ec340bSmacallan    echo "$object : \\" > "$depfile"
269f7ec340bSmacallan    # Clip off the initial element (the dependent).  Don't try to be
270f7ec340bSmacallan    # clever and replace this with sed code, as IRIX sed won't handle
271f7ec340bSmacallan    # lines with more than a fixed number of characters (4096 in
272f7ec340bSmacallan    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2732a75d1c4Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
274f7ec340bSmacallan    # dependency line.
2752a75d1c4Smrg    tr ' ' "$nl" < "$tmpdepfile" \
27666ab3337Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
27766ab3337Smrg      | tr "$nl" ' ' >> "$depfile"
2782a75d1c4Smrg    echo >> "$depfile"
279f7ec340bSmacallan    # The second pass generates a dummy entry for each header file.
2802a75d1c4Smrg    tr ' ' "$nl" < "$tmpdepfile" \
28166ab3337Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
28266ab3337Smrg      >> "$depfile"
283f7ec340bSmacallan  else
28466ab3337Smrg    make_dummy_depfile
285f7ec340bSmacallan  fi
286f7ec340bSmacallan  rm -f "$tmpdepfile"
287f7ec340bSmacallan  ;;
288f7ec340bSmacallan
2892a75d1c4Smrgxlc)
2902a75d1c4Smrg  # This case exists only to let depend.m4 do its work.  It works by
2912a75d1c4Smrg  # looking at the text of this script.  This case will never be run,
2922a75d1c4Smrg  # since it is checked for above.
2932a75d1c4Smrg  exit 1
2942a75d1c4Smrg  ;;
2952a75d1c4Smrg
296f7ec340bSmacallanaix)
297f7ec340bSmacallan  # The C for AIX Compiler uses -M and outputs the dependencies
298f7ec340bSmacallan  # in a .u file.  In older versions, this file always lives in the
2992a75d1c4Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300f7ec340bSmacallan  # start of each line; $object doesn't have directory information.
301f7ec340bSmacallan  # Version 6 uses the directory in both cases.
30266ab3337Smrg  set_dir_from "$object"
30366ab3337Smrg  set_base_from "$object"
304f7ec340bSmacallan  if test "$libtool" = yes; then
3057ce7e03cSmrg    tmpdepfile1=$dir$base.u
3067ce7e03cSmrg    tmpdepfile2=$base.u
3077ce7e03cSmrg    tmpdepfile3=$dir.libs/$base.u
308f7ec340bSmacallan    "$@" -Wc,-M
309f7ec340bSmacallan  else
3107ce7e03cSmrg    tmpdepfile1=$dir$base.u
3117ce7e03cSmrg    tmpdepfile2=$dir$base.u
3127ce7e03cSmrg    tmpdepfile3=$dir$base.u
313f7ec340bSmacallan    "$@" -M
314f7ec340bSmacallan  fi
315f7ec340bSmacallan  stat=$?
31666ab3337Smrg  if test $stat -ne 0; then
3177ce7e03cSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318f7ec340bSmacallan    exit $stat
319f7ec340bSmacallan  fi
320f7ec340bSmacallan
3217ce7e03cSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3227ce7e03cSmrg  do
3237ce7e03cSmrg    test -f "$tmpdepfile" && break
3247ce7e03cSmrg  done
32566ab3337Smrg  aix_post_process_depfile
326f7ec340bSmacallan  ;;
327f7ec340bSmacallan
32866ab3337Smrgtcc)
32966ab3337Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
33066ab3337Smrg  # FIXME: That version still under development at the moment of writing.
33166ab3337Smrg  #        Make that this statement remains true also for stable, released
33266ab3337Smrg  #        versions.
33366ab3337Smrg  # It will wrap lines (doesn't matter whether long or short) with a
33466ab3337Smrg  # trailing '\', as in:
33566ab3337Smrg  #
33666ab3337Smrg  #   foo.o : \
33766ab3337Smrg  #    foo.c \
33866ab3337Smrg  #    foo.h \
33966ab3337Smrg  #
34066ab3337Smrg  # It will put a trailing '\' even on the last line, and will use leading
34166ab3337Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
34266ab3337Smrg  # "Emit spaces for -MD").
343f7ec340bSmacallan  "$@" -MD -MF "$tmpdepfile"
344f7ec340bSmacallan  stat=$?
34566ab3337Smrg  if test $stat -ne 0; then
346f7ec340bSmacallan    rm -f "$tmpdepfile"
347f7ec340bSmacallan    exit $stat
348f7ec340bSmacallan  fi
349f7ec340bSmacallan  rm -f "$depfile"
35066ab3337Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
35166ab3337Smrg  # We have to change lines of the first kind to '$object: \'.
35266ab3337Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
35366ab3337Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
35466ab3337Smrg  # dummy dependency, to avoid the deleted-header problem.
35566ab3337Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3562a75d1c4Smrg  rm -f "$tmpdepfile"
3572a75d1c4Smrg  ;;
3582a75d1c4Smrg
3592a75d1c4Smrg## The order of this option in the case statement is important, since the
3602a75d1c4Smrg## shell code in configure will try each of these formats in the order
3612a75d1c4Smrg## listed in this file.  A plain '-MD' option would be understood by many
3622a75d1c4Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3632a75d1c4Smrgpgcc)
3642a75d1c4Smrg  # Portland's C compiler understands '-MD'.
3652a75d1c4Smrg  # Will always output deps to 'file.d' where file is the root name of the
3662a75d1c4Smrg  # source file under compilation, even if file resides in a subdirectory.
3672a75d1c4Smrg  # The object file name does not affect the name of the '.d' file.
3682a75d1c4Smrg  # pgcc 10.2 will output
3692a75d1c4Smrg  #    foo.o: sub/foo.c sub/foo.h
3702a75d1c4Smrg  # and will wrap long lines using '\' :
3712a75d1c4Smrg  #    foo.o: sub/foo.c ... \
3722a75d1c4Smrg  #     sub/foo.h ... \
3732a75d1c4Smrg  #     ...
37466ab3337Smrg  set_dir_from "$object"
3752a75d1c4Smrg  # Use the source, not the object, to determine the base name, since
3762a75d1c4Smrg  # that's sadly what pgcc will do too.
37766ab3337Smrg  set_base_from "$source"
37866ab3337Smrg  tmpdepfile=$base.d
3792a75d1c4Smrg
3802a75d1c4Smrg  # For projects that build the same source file twice into different object
3812a75d1c4Smrg  # files, the pgcc approach of using the *source* file root name can cause
3822a75d1c4Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3832a75d1c4Smrg  # the same $tmpdepfile.
38466ab3337Smrg  lockdir=$base.d-lock
38566ab3337Smrg  trap "
38666ab3337Smrg    echo '$0: caught signal, cleaning up...' >&2
38766ab3337Smrg    rmdir '$lockdir'
38866ab3337Smrg    exit 1
38966ab3337Smrg  " 1 2 13 15
3902a75d1c4Smrg  numtries=100
3912a75d1c4Smrg  i=$numtries
39266ab3337Smrg  while test $i -gt 0; do
3932a75d1c4Smrg    # mkdir is a portable test-and-set.
39466ab3337Smrg    if mkdir "$lockdir" 2>/dev/null; then
3952a75d1c4Smrg      # This process acquired the lock.
3962a75d1c4Smrg      "$@" -MD
3972a75d1c4Smrg      stat=$?
3982a75d1c4Smrg      # Release the lock.
39966ab3337Smrg      rmdir "$lockdir"
4002a75d1c4Smrg      break
4012a75d1c4Smrg    else
40266ab3337Smrg      # If the lock is being held by a different process, wait
40366ab3337Smrg      # until the winning process is done or we timeout.
40466ab3337Smrg      while test -d "$lockdir" && test $i -gt 0; do
4052a75d1c4Smrg        sleep 1
4062a75d1c4Smrg        i=`expr $i - 1`
4072a75d1c4Smrg      done
4082a75d1c4Smrg    fi
4092a75d1c4Smrg    i=`expr $i - 1`
4102a75d1c4Smrg  done
4112a75d1c4Smrg  trap - 1 2 13 15
4122a75d1c4Smrg  if test $i -le 0; then
4132a75d1c4Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4142a75d1c4Smrg    echo "$0: check lockdir '$lockdir'" >&2
4152a75d1c4Smrg    exit 1
4162a75d1c4Smrg  fi
4172a75d1c4Smrg
4182a75d1c4Smrg  if test $stat -ne 0; then
4192a75d1c4Smrg    rm -f "$tmpdepfile"
4202a75d1c4Smrg    exit $stat
4212a75d1c4Smrg  fi
4222a75d1c4Smrg  rm -f "$depfile"
423f7ec340bSmacallan  # Each line is of the form `foo.o: dependent.h',
424f7ec340bSmacallan  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425f7ec340bSmacallan  # Do two passes, one to just change these to
426f7ec340bSmacallan  # `$object: dependent.h' and one to simply `dependent.h:'.
427f7ec340bSmacallan  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428f7ec340bSmacallan  # Some versions of the HPUX 10.20 sed can't process this invocation
429f7ec340bSmacallan  # correctly.  Breaking it into two sed invocations is a workaround.
43066ab3337Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
43166ab3337Smrg    | sed -e 's/$/ :/' >> "$depfile"
432f7ec340bSmacallan  rm -f "$tmpdepfile"
433f7ec340bSmacallan  ;;
434f7ec340bSmacallan
4357ce7e03cSmrghp2)
4367ce7e03cSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4377ce7e03cSmrg  # compilers, which have integrated preprocessors.  The correct option
4387ce7e03cSmrg  # to use with these is +Maked; it writes dependencies to a file named
4397ce7e03cSmrg  # 'foo.d', which lands next to the object file, wherever that
4407ce7e03cSmrg  # happens to be.
4417ce7e03cSmrg  # Much of this is similar to the tru64 case; see comments there.
44266ab3337Smrg  set_dir_from  "$object"
44366ab3337Smrg  set_base_from "$object"
4447ce7e03cSmrg  if test "$libtool" = yes; then
4457ce7e03cSmrg    tmpdepfile1=$dir$base.d
4467ce7e03cSmrg    tmpdepfile2=$dir.libs/$base.d
4477ce7e03cSmrg    "$@" -Wc,+Maked
4487ce7e03cSmrg  else
4497ce7e03cSmrg    tmpdepfile1=$dir$base.d
4507ce7e03cSmrg    tmpdepfile2=$dir$base.d
4517ce7e03cSmrg    "$@" +Maked
4527ce7e03cSmrg  fi
4537ce7e03cSmrg  stat=$?
45466ab3337Smrg  if test $stat -ne 0; then
4557ce7e03cSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4567ce7e03cSmrg     exit $stat
4577ce7e03cSmrg  fi
4587ce7e03cSmrg
4597ce7e03cSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4607ce7e03cSmrg  do
4617ce7e03cSmrg    test -f "$tmpdepfile" && break
4627ce7e03cSmrg  done
4637ce7e03cSmrg  if test -f "$tmpdepfile"; then
46466ab3337Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4652a75d1c4Smrg    # Add 'dependent.h:' lines.
4662a75d1c4Smrg    sed -ne '2,${
46766ab3337Smrg               s/^ *//
46866ab3337Smrg               s/ \\*$//
46966ab3337Smrg               s/$/:/
47066ab3337Smrg               p
47166ab3337Smrg             }' "$tmpdepfile" >> "$depfile"
4727ce7e03cSmrg  else
47366ab3337Smrg    make_dummy_depfile
4747ce7e03cSmrg  fi
4757ce7e03cSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4767ce7e03cSmrg  ;;
4777ce7e03cSmrg
478f7ec340bSmacallantru64)
47966ab3337Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
48066ab3337Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
48166ab3337Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
48266ab3337Smrg  # dependencies in 'foo.d' instead, so we check for that too.
48366ab3337Smrg  # Subdirectories are respected.
48466ab3337Smrg  set_dir_from  "$object"
48566ab3337Smrg  set_base_from "$object"
48666ab3337Smrg
48766ab3337Smrg  if test "$libtool" = yes; then
48866ab3337Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
48966ab3337Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
49066ab3337Smrg    # in $dir$base.o.d.  We have to check for both files, because
49166ab3337Smrg    # one of the two compilations can be disabled.  We should prefer
49266ab3337Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
49366ab3337Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
49466ab3337Smrg    # the former would cause a distcleancheck panic.
49566ab3337Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
49666ab3337Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
49766ab3337Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
49866ab3337Smrg    "$@" -Wc,-MD
49966ab3337Smrg  else
50066ab3337Smrg    tmpdepfile1=$dir$base.d
50166ab3337Smrg    tmpdepfile2=$dir$base.d
50266ab3337Smrg    tmpdepfile3=$dir$base.d
50366ab3337Smrg    "$@" -MD
50466ab3337Smrg  fi
50566ab3337Smrg
50666ab3337Smrg  stat=$?
50766ab3337Smrg  if test $stat -ne 0; then
50866ab3337Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
50966ab3337Smrg    exit $stat
51066ab3337Smrg  fi
51166ab3337Smrg
51266ab3337Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
51366ab3337Smrg  do
51466ab3337Smrg    test -f "$tmpdepfile" && break
51566ab3337Smrg  done
51666ab3337Smrg  # Same post-processing that is required for AIX mode.
51766ab3337Smrg  aix_post_process_depfile
51866ab3337Smrg  ;;
519f7ec340bSmacallan
5202a75d1c4Smrgmsvc7)
5212a75d1c4Smrg  if test "$libtool" = yes; then
5222a75d1c4Smrg    showIncludes=-Wc,-showIncludes
5232a75d1c4Smrg  else
5242a75d1c4Smrg    showIncludes=-showIncludes
5252a75d1c4Smrg  fi
5262a75d1c4Smrg  "$@" $showIncludes > "$tmpdepfile"
5272a75d1c4Smrg  stat=$?
5282a75d1c4Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
52966ab3337Smrg  if test $stat -ne 0; then
5302a75d1c4Smrg    rm -f "$tmpdepfile"
5312a75d1c4Smrg    exit $stat
5322a75d1c4Smrg  fi
5332a75d1c4Smrg  rm -f "$depfile"
5342a75d1c4Smrg  echo "$object : \\" > "$depfile"
5352a75d1c4Smrg  # The first sed program below extracts the file names and escapes
5362a75d1c4Smrg  # backslashes for cygpath.  The second sed program outputs the file
5372a75d1c4Smrg  # name when reading, but also accumulates all include files in the
5382a75d1c4Smrg  # hold buffer in order to output them again at the end.  This only
5392a75d1c4Smrg  # works with sed implementations that can handle large buffers.
5402a75d1c4Smrg  sed < "$tmpdepfile" -n '
5412a75d1c4Smrg/^Note: including file:  *\(.*\)/ {
5422a75d1c4Smrg  s//\1/
5432a75d1c4Smrg  s/\\/\\\\/g
5442a75d1c4Smrg  p
5452a75d1c4Smrg}' | $cygpath_u | sort -u | sed -n '
5462a75d1c4Smrgs/ /\\ /g
5472a75d1c4Smrgs/\(.*\)/'"$tab"'\1 \\/p
5482a75d1c4Smrgs/.\(.*\) \\/\1:/
5492a75d1c4SmrgH
5502a75d1c4Smrg$ {
5512a75d1c4Smrg  s/.*/'"$tab"'/
5522a75d1c4Smrg  G
5532a75d1c4Smrg  p
5542a75d1c4Smrg}' >> "$depfile"
55566ab3337Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5562a75d1c4Smrg  rm -f "$tmpdepfile"
5572a75d1c4Smrg  ;;
5582a75d1c4Smrg
5592a75d1c4Smrgmsvc7msys)
5602a75d1c4Smrg  # This case exists only to let depend.m4 do its work.  It works by
5612a75d1c4Smrg  # looking at the text of this script.  This case will never be run,
5622a75d1c4Smrg  # since it is checked for above.
5632a75d1c4Smrg  exit 1
5642a75d1c4Smrg  ;;
5652a75d1c4Smrg
566f7ec340bSmacallan#nosideeffect)
567f7ec340bSmacallan  # This comment above is used by automake to tell side-effect
568f7ec340bSmacallan  # dependency tracking mechanisms from slower ones.
569f7ec340bSmacallan
570f7ec340bSmacallandashmstdout)
571f7ec340bSmacallan  # Important note: in order to support this mode, a compiler *must*
572f7ec340bSmacallan  # always write the preprocessed file to stdout, regardless of -o.
573f7ec340bSmacallan  "$@" || exit $?
574f7ec340bSmacallan
575f7ec340bSmacallan  # Remove the call to Libtool.
576f7ec340bSmacallan  if test "$libtool" = yes; then
5772a75d1c4Smrg    while test "X$1" != 'X--mode=compile'; do
578f7ec340bSmacallan      shift
579f7ec340bSmacallan    done
580f7ec340bSmacallan    shift
581f7ec340bSmacallan  fi
582f7ec340bSmacallan
5832a75d1c4Smrg  # Remove '-o $object'.
584f7ec340bSmacallan  IFS=" "
585f7ec340bSmacallan  for arg
586f7ec340bSmacallan  do
587f7ec340bSmacallan    case $arg in
588f7ec340bSmacallan    -o)
589f7ec340bSmacallan      shift
590f7ec340bSmacallan      ;;
591f7ec340bSmacallan    $object)
592f7ec340bSmacallan      shift
593f7ec340bSmacallan      ;;
594f7ec340bSmacallan    *)
595f7ec340bSmacallan      set fnord "$@" "$arg"
596f7ec340bSmacallan      shift # fnord
597f7ec340bSmacallan      shift # $arg
598f7ec340bSmacallan      ;;
599f7ec340bSmacallan    esac
600f7ec340bSmacallan  done
601f7ec340bSmacallan
602f7ec340bSmacallan  test -z "$dashmflag" && dashmflag=-M
6032a75d1c4Smrg  # Require at least two characters before searching for ':'
604f7ec340bSmacallan  # in the target name.  This is to cope with DOS-style filenames:
6052a75d1c4Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606f7ec340bSmacallan  "$@" $dashmflag |
60766ab3337Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608f7ec340bSmacallan  rm -f "$depfile"
609f7ec340bSmacallan  cat < "$tmpdepfile" > "$depfile"
61066ab3337Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
61166ab3337Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
61266ab3337Smrg  tr ' ' "$nl" < "$tmpdepfile" \
61366ab3337Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
61466ab3337Smrg    | sed -e 's/$/ :/' >> "$depfile"
615f7ec340bSmacallan  rm -f "$tmpdepfile"
616f7ec340bSmacallan  ;;
617f7ec340bSmacallan
618f7ec340bSmacallandashXmstdout)
619f7ec340bSmacallan  # This case only exists to satisfy depend.m4.  It is never actually
620f7ec340bSmacallan  # run, as this mode is specially recognized in the preamble.
621f7ec340bSmacallan  exit 1
622f7ec340bSmacallan  ;;
623f7ec340bSmacallan
624f7ec340bSmacallanmakedepend)
625f7ec340bSmacallan  "$@" || exit $?
626f7ec340bSmacallan  # Remove any Libtool call
627f7ec340bSmacallan  if test "$libtool" = yes; then
6282a75d1c4Smrg    while test "X$1" != 'X--mode=compile'; do
629f7ec340bSmacallan      shift
630f7ec340bSmacallan    done
631f7ec340bSmacallan    shift
632f7ec340bSmacallan  fi
633f7ec340bSmacallan  # X makedepend
634f7ec340bSmacallan  shift
6352a75d1c4Smrg  cleared=no eat=no
6362a75d1c4Smrg  for arg
6372a75d1c4Smrg  do
638f7ec340bSmacallan    case $cleared in
639f7ec340bSmacallan    no)
640f7ec340bSmacallan      set ""; shift
641f7ec340bSmacallan      cleared=yes ;;
642f7ec340bSmacallan    esac
6432a75d1c4Smrg    if test $eat = yes; then
6442a75d1c4Smrg      eat=no
6452a75d1c4Smrg      continue
6462a75d1c4Smrg    fi
647f7ec340bSmacallan    case "$arg" in
648f7ec340bSmacallan    -D*|-I*)
649f7ec340bSmacallan      set fnord "$@" "$arg"; shift ;;
650f7ec340bSmacallan    # Strip any option that makedepend may not understand.  Remove
651f7ec340bSmacallan    # the object too, otherwise makedepend will parse it as a source file.
6522a75d1c4Smrg    -arch)
6532a75d1c4Smrg      eat=yes ;;
654f7ec340bSmacallan    -*|$object)
655f7ec340bSmacallan      ;;
656f7ec340bSmacallan    *)
657f7ec340bSmacallan      set fnord "$@" "$arg"; shift ;;
658f7ec340bSmacallan    esac
659f7ec340bSmacallan  done
6602a75d1c4Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661f7ec340bSmacallan  touch "$tmpdepfile"
662f7ec340bSmacallan  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663f7ec340bSmacallan  rm -f "$depfile"
6642a75d1c4Smrg  # makedepend may prepend the VPATH from the source file name to the object.
6652a75d1c4Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6662a75d1c4Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
66766ab3337Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
66866ab3337Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
66966ab3337Smrg  sed '1,2d' "$tmpdepfile" \
67066ab3337Smrg    | tr ' ' "$nl" \
67166ab3337Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
67266ab3337Smrg    | sed -e 's/$/ :/' >> "$depfile"
673f7ec340bSmacallan  rm -f "$tmpdepfile" "$tmpdepfile".bak
674f7ec340bSmacallan  ;;
675f7ec340bSmacallan
676f7ec340bSmacallancpp)
677f7ec340bSmacallan  # Important note: in order to support this mode, a compiler *must*
678f7ec340bSmacallan  # always write the preprocessed file to stdout.
679f7ec340bSmacallan  "$@" || exit $?
680f7ec340bSmacallan
681f7ec340bSmacallan  # Remove the call to Libtool.
682f7ec340bSmacallan  if test "$libtool" = yes; then
6832a75d1c4Smrg    while test "X$1" != 'X--mode=compile'; do
684f7ec340bSmacallan      shift
685f7ec340bSmacallan    done
686f7ec340bSmacallan    shift
687f7ec340bSmacallan  fi
688f7ec340bSmacallan
6892a75d1c4Smrg  # Remove '-o $object'.
690f7ec340bSmacallan  IFS=" "
691f7ec340bSmacallan  for arg
692f7ec340bSmacallan  do
693f7ec340bSmacallan    case $arg in
694f7ec340bSmacallan    -o)
695f7ec340bSmacallan      shift
696f7ec340bSmacallan      ;;
697f7ec340bSmacallan    $object)
698f7ec340bSmacallan      shift
699f7ec340bSmacallan      ;;
700f7ec340bSmacallan    *)
701f7ec340bSmacallan      set fnord "$@" "$arg"
702f7ec340bSmacallan      shift # fnord
703f7ec340bSmacallan      shift # $arg
704f7ec340bSmacallan      ;;
705f7ec340bSmacallan    esac
706f7ec340bSmacallan  done
707f7ec340bSmacallan
70866ab3337Smrg  "$@" -E \
70966ab3337Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71066ab3337Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71166ab3337Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
712f7ec340bSmacallan  rm -f "$depfile"
713f7ec340bSmacallan  echo "$object : \\" > "$depfile"
714f7ec340bSmacallan  cat < "$tmpdepfile" >> "$depfile"
715f7ec340bSmacallan  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716f7ec340bSmacallan  rm -f "$tmpdepfile"
717f7ec340bSmacallan  ;;
718f7ec340bSmacallan
719f7ec340bSmacallanmsvisualcpp)
720f7ec340bSmacallan  # Important note: in order to support this mode, a compiler *must*
7212a75d1c4Smrg  # always write the preprocessed file to stdout.
722f7ec340bSmacallan  "$@" || exit $?
7232a75d1c4Smrg
7242a75d1c4Smrg  # Remove the call to Libtool.
7252a75d1c4Smrg  if test "$libtool" = yes; then
7262a75d1c4Smrg    while test "X$1" != 'X--mode=compile'; do
7272a75d1c4Smrg      shift
7282a75d1c4Smrg    done
7292a75d1c4Smrg    shift
7302a75d1c4Smrg  fi
7312a75d1c4Smrg
732f7ec340bSmacallan  IFS=" "
733f7ec340bSmacallan  for arg
734f7ec340bSmacallan  do
735f7ec340bSmacallan    case "$arg" in
7362a75d1c4Smrg    -o)
7372a75d1c4Smrg      shift
7382a75d1c4Smrg      ;;
7392a75d1c4Smrg    $object)
7402a75d1c4Smrg      shift
7412a75d1c4Smrg      ;;
742f7ec340bSmacallan    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
74366ab3337Smrg        set fnord "$@"
74466ab3337Smrg        shift
74566ab3337Smrg        shift
74666ab3337Smrg        ;;
747f7ec340bSmacallan    *)
74866ab3337Smrg        set fnord "$@" "$arg"
74966ab3337Smrg        shift
75066ab3337Smrg        shift
75166ab3337Smrg        ;;
752f7ec340bSmacallan    esac
753f7ec340bSmacallan  done
7542a75d1c4Smrg  "$@" -E 2>/dev/null |
7552a75d1c4Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756f7ec340bSmacallan  rm -f "$depfile"
757f7ec340bSmacallan  echo "$object : \\" > "$depfile"
7582a75d1c4Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7592a75d1c4Smrg  echo "$tab" >> "$depfile"
7602a75d1c4Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761f7ec340bSmacallan  rm -f "$tmpdepfile"
762f7ec340bSmacallan  ;;
763f7ec340bSmacallan
7642a75d1c4Smrgmsvcmsys)
7652a75d1c4Smrg  # This case exists only to let depend.m4 do its work.  It works by
7662a75d1c4Smrg  # looking at the text of this script.  This case will never be run,
7672a75d1c4Smrg  # since it is checked for above.
7682a75d1c4Smrg  exit 1
7692a75d1c4Smrg  ;;
7702a75d1c4Smrg
771f7ec340bSmacallannone)
772f7ec340bSmacallan  exec "$@"
773f7ec340bSmacallan  ;;
774f7ec340bSmacallan
775f7ec340bSmacallan*)
776f7ec340bSmacallan  echo "Unknown depmode $depmode" 1>&2
777f7ec340bSmacallan  exit 1
778f7ec340bSmacallan  ;;
779f7ec340bSmacallanesac
780f7ec340bSmacallan
781f7ec340bSmacallanexit 0
782f7ec340bSmacallan
783f7ec340bSmacallan# Local Variables:
784f7ec340bSmacallan# mode: shell-script
785f7ec340bSmacallan# sh-indentation: 2
78666ab3337Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
787f7ec340bSmacallan# time-stamp-start: "scriptversion="
788f7ec340bSmacallan# time-stamp-format: "%:y-%02m-%02d.%02H"
78966ab3337Smrg# time-stamp-time-zone: "UTC0"
7902a75d1c4Smrg# time-stamp-end: "; # UTC"
791f7ec340bSmacallan# End:
792