133c89af1Smrg#! /bin/sh
233c89af1Smrg# depcomp - compile a program generating dependencies as side-effects
333c89af1Smrg
4352bf44eSmrgscriptversion=2018-03-07.03; # UTC
533c89af1Smrg
6352bf44eSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
733c89af1Smrg
833c89af1Smrg# This program is free software; you can redistribute it and/or modify
933c89af1Smrg# it under the terms of the GNU General Public License as published by
1033c89af1Smrg# the Free Software Foundation; either version 2, or (at your option)
1133c89af1Smrg# any later version.
1233c89af1Smrg
1333c89af1Smrg# This program is distributed in the hope that it will be useful,
1433c89af1Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1533c89af1Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1633c89af1Smrg# GNU General Public License for more details.
1733c89af1Smrg
1833c89af1Smrg# You should have received a copy of the GNU General Public License
19352bf44eSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2033c89af1Smrg
2133c89af1Smrg# As a special exception to the GNU General Public License, if you
2233c89af1Smrg# distribute this file as part of a program that contains a
2333c89af1Smrg# configuration script generated by Autoconf, you may include it under
2433c89af1Smrg# the same distribution terms that you use for the rest of that program.
2533c89af1Smrg
2633c89af1Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2733c89af1Smrg
2833c89af1Smrgcase $1 in
2933c89af1Smrg  '')
30ad47b356Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31ad47b356Smrg    exit 1;
32ad47b356Smrg    ;;
3333c89af1Smrg  -h | --h*)
3433c89af1Smrg    cat <<\EOF
3533c89af1SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3633c89af1Smrg
3733c89af1SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3833c89af1Smrgas side-effects.
3933c89af1Smrg
4033c89af1SmrgEnvironment variables:
4133c89af1Smrg  depmode     Dependency tracking mode.
42ad47b356Smrg  source      Source file read by 'PROGRAMS ARGS'.
43ad47b356Smrg  object      Object file output by 'PROGRAMS ARGS'.
4433c89af1Smrg  DEPDIR      directory where to store dependencies.
4533c89af1Smrg  depfile     Dependency file to output.
46988795beSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
4733c89af1Smrg  libtool     Whether libtool is used (yes/no).
4833c89af1Smrg
4933c89af1SmrgReport bugs to <bug-automake@gnu.org>.
5033c89af1SmrgEOF
5133c89af1Smrg    exit $?
5233c89af1Smrg    ;;
5333c89af1Smrg  -v | --v*)
5433c89af1Smrg    echo "depcomp $scriptversion"
5533c89af1Smrg    exit $?
5633c89af1Smrg    ;;
5733c89af1Smrgesac
5833c89af1Smrg
59ad47b356Smrg# Get the directory component of the given path, and save it in the
60ad47b356Smrg# global variables '$dir'.  Note that this directory component will
61ad47b356Smrg# be either empty or ending with a '/' character.  This is deliberate.
62ad47b356Smrgset_dir_from ()
63ad47b356Smrg{
64ad47b356Smrg  case $1 in
65ad47b356Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66ad47b356Smrg      *) dir=;;
67ad47b356Smrg  esac
68ad47b356Smrg}
69ad47b356Smrg
70ad47b356Smrg# Get the suffix-stripped basename of the given path, and save it the
71ad47b356Smrg# global variable '$base'.
72ad47b356Smrgset_base_from ()
73ad47b356Smrg{
74ad47b356Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75ad47b356Smrg}
76ad47b356Smrg
77ad47b356Smrg# If no dependency file was actually created by the compiler invocation,
78ad47b356Smrg# we still have to create a dummy depfile, to avoid errors with the
79ad47b356Smrg# Makefile "include basename.Plo" scheme.
80ad47b356Smrgmake_dummy_depfile ()
81ad47b356Smrg{
82ad47b356Smrg  echo "#dummy" > "$depfile"
83ad47b356Smrg}
84ad47b356Smrg
85ad47b356Smrg# Factor out some common post-processing of the generated depfile.
86ad47b356Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87ad47b356Smrgaix_post_process_depfile ()
88ad47b356Smrg{
89ad47b356Smrg  # If the compiler actually managed to produce a dependency file,
90ad47b356Smrg  # post-process it.
91ad47b356Smrg  if test -f "$tmpdepfile"; then
92ad47b356Smrg    # Each line is of the form 'foo.o: dependency.h'.
93ad47b356Smrg    # Do two passes, one to just change these to
94ad47b356Smrg    #   $object: dependency.h
95ad47b356Smrg    # and one to simply output
96ad47b356Smrg    #   dependency.h:
97ad47b356Smrg    # which is needed to avoid the deleted-header problem.
98ad47b356Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99ad47b356Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100ad47b356Smrg    } > "$depfile"
101ad47b356Smrg    rm -f "$tmpdepfile"
102ad47b356Smrg  else
103ad47b356Smrg    make_dummy_depfile
104ad47b356Smrg  fi
105ad47b356Smrg}
106ad47b356Smrg
107ad47b356Smrg# A tabulation character.
108ad47b356Smrgtab='	'
109ad47b356Smrg# A newline character.
110ad47b356Smrgnl='
111ad47b356Smrg'
112ad47b356Smrg# Character ranges might be problematic outside the C locale.
113ad47b356Smrg# These definitions help.
114ad47b356Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115ad47b356Smrglower=abcdefghijklmnopqrstuvwxyz
116ad47b356Smrgdigits=0123456789
117ad47b356Smrgalpha=${upper}${lower}
118ad47b356Smrg
11933c89af1Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12033c89af1Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12133c89af1Smrg  exit 1
12233c89af1Smrgfi
12333c89af1Smrg
12433c89af1Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12533c89af1Smrgdepfile=${depfile-`echo "$object" |
12633c89af1Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12733c89af1Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12833c89af1Smrg
12933c89af1Smrgrm -f "$tmpdepfile"
13033c89af1Smrg
131ad47b356Smrg# Avoid interferences from the environment.
132ad47b356Smrggccflag= dashmflag=
133ad47b356Smrg
13433c89af1Smrg# Some modes work just like other modes, but use different flags.  We
13533c89af1Smrg# parameterize here, but still list the modes in the big case below,
13633c89af1Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13733c89af1Smrg# here, because this file can only contain one case statement.
13833c89af1Smrgif test "$depmode" = hp; then
13933c89af1Smrg  # HP compiler uses -M and no extra arg.
14033c89af1Smrg  gccflag=-M
14133c89af1Smrg  depmode=gcc
14233c89af1Smrgfi
14333c89af1Smrg
14433c89af1Smrgif test "$depmode" = dashXmstdout; then
145ad47b356Smrg  # This is just like dashmstdout with a different argument.
146ad47b356Smrg  dashmflag=-xM
147ad47b356Smrg  depmode=dashmstdout
14833c89af1Smrgfi
14933c89af1Smrg
150278eca22Smrgcygpath_u="cygpath -u -f -"
151278eca22Smrgif test "$depmode" = msvcmsys; then
152ad47b356Smrg  # This is just like msvisualcpp but w/o cygpath translation.
153ad47b356Smrg  # Just convert the backslash-escaped backslashes to single forward
154ad47b356Smrg  # slashes to satisfy depend.m4
155ad47b356Smrg  cygpath_u='sed s,\\\\,/,g'
156ad47b356Smrg  depmode=msvisualcpp
157278eca22Smrgfi
158278eca22Smrg
159988795beSmrgif test "$depmode" = msvc7msys; then
160ad47b356Smrg  # This is just like msvc7 but w/o cygpath translation.
161ad47b356Smrg  # Just convert the backslash-escaped backslashes to single forward
162ad47b356Smrg  # slashes to satisfy depend.m4
163ad47b356Smrg  cygpath_u='sed s,\\\\,/,g'
164ad47b356Smrg  depmode=msvc7
165ad47b356Smrgfi
166ad47b356Smrg
167ad47b356Smrgif test "$depmode" = xlc; then
168ad47b356Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169ad47b356Smrg  gccflag=-qmakedep=gcc,-MF
170ad47b356Smrg  depmode=gcc
171988795beSmrgfi
172988795beSmrg
17333c89af1Smrgcase "$depmode" in
17433c89af1Smrggcc3)
17533c89af1Smrg## gcc 3 implements dependency tracking that does exactly what
17633c89af1Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17733c89af1Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178278eca22Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179278eca22Smrg## the command line argument order; so add the flags where they
180278eca22Smrg## appear in depend2.am.  Note that the slowdown incurred here
181278eca22Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182278eca22Smrg  for arg
183278eca22Smrg  do
184278eca22Smrg    case $arg in
185278eca22Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186278eca22Smrg    *)  set fnord "$@" "$arg" ;;
187278eca22Smrg    esac
188278eca22Smrg    shift # fnord
189278eca22Smrg    shift # $arg
190278eca22Smrg  done
191278eca22Smrg  "$@"
19233c89af1Smrg  stat=$?
193ad47b356Smrg  if test $stat -ne 0; then
19433c89af1Smrg    rm -f "$tmpdepfile"
19533c89af1Smrg    exit $stat
19633c89af1Smrg  fi
19733c89af1Smrg  mv "$tmpdepfile" "$depfile"
19833c89af1Smrg  ;;
19933c89af1Smrg
20033c89af1Smrggcc)
201ad47b356Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202ad47b356Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203ad47b356Smrg## (see the conditional assignment to $gccflag above).
20433c89af1Smrg## There are various ways to get dependency output from gcc.  Here's
20533c89af1Smrg## why we pick this rather obscure method:
20633c89af1Smrg## - Don't want to use -MD because we'd like the dependencies to end
20733c89af1Smrg##   up in a subdir.  Having to rename by hand is ugly.
20833c89af1Smrg##   (We might end up doing this anyway to support other compilers.)
20933c89af1Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210ad47b356Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211ad47b356Smrg##   supported by the other compilers which use the 'gcc' depmode.
21233c89af1Smrg## - Using -M directly means running the compiler twice (even worse
21333c89af1Smrg##   than renaming).
21433c89af1Smrg  if test -z "$gccflag"; then
21533c89af1Smrg    gccflag=-MD,
21633c89af1Smrg  fi
21733c89af1Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
21833c89af1Smrg  stat=$?
219ad47b356Smrg  if test $stat -ne 0; then
22033c89af1Smrg    rm -f "$tmpdepfile"
22133c89af1Smrg    exit $stat
22233c89af1Smrg  fi
22333c89af1Smrg  rm -f "$depfile"
22433c89af1Smrg  echo "$object : \\" > "$depfile"
225ad47b356Smrg  # The second -e expression handles DOS-style file names with drive
226ad47b356Smrg  # letters.
22733c89af1Smrg  sed -e 's/^[^:]*: / /' \
22833c89af1Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229ad47b356Smrg## This next piece of magic avoids the "deleted header file" problem.
23033c89af1Smrg## The problem is that when a header file which appears in a .P file
23133c89af1Smrg## is deleted, the dependency causes make to die (because there is
23233c89af1Smrg## typically no way to rebuild the header).  We avoid this by adding
23333c89af1Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23433c89af1Smrg## this for us directly.
235ad47b356Smrg## Some versions of gcc put a space before the ':'.  On the theory
23633c89af1Smrg## that the space means something, we add a space to the output as
237988795beSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238988795beSmrg## to the object.  Take care to not repeat it in the output.
23933c89af1Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
24033c89af1Smrg## correctly.  Breaking it into two sed invocations is a workaround.
241ad47b356Smrg  tr ' ' "$nl" < "$tmpdepfile" \
242ad47b356Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243ad47b356Smrg    | sed -e 's/$/ :/' >> "$depfile"
24433c89af1Smrg  rm -f "$tmpdepfile"
24533c89af1Smrg  ;;
24633c89af1Smrg
24733c89af1Smrghp)
24833c89af1Smrg  # This case exists only to let depend.m4 do its work.  It works by
24933c89af1Smrg  # looking at the text of this script.  This case will never be run,
25033c89af1Smrg  # since it is checked for above.
25133c89af1Smrg  exit 1
25233c89af1Smrg  ;;
25333c89af1Smrg
25433c89af1Smrgsgi)
25533c89af1Smrg  if test "$libtool" = yes; then
25633c89af1Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25733c89af1Smrg  else
25833c89af1Smrg    "$@" -MDupdate "$tmpdepfile"
25933c89af1Smrg  fi
26033c89af1Smrg  stat=$?
261ad47b356Smrg  if test $stat -ne 0; then
26233c89af1Smrg    rm -f "$tmpdepfile"
26333c89af1Smrg    exit $stat
26433c89af1Smrg  fi
26533c89af1Smrg  rm -f "$depfile"
26633c89af1Smrg
26733c89af1Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26833c89af1Smrg    echo "$object : \\" > "$depfile"
26933c89af1Smrg    # Clip off the initial element (the dependent).  Don't try to be
27033c89af1Smrg    # clever and replace this with sed code, as IRIX sed won't handle
27133c89af1Smrg    # lines with more than a fixed number of characters (4096 in
27233c89af1Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273ad47b356Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
27433c89af1Smrg    # dependency line.
275ad47b356Smrg    tr ' ' "$nl" < "$tmpdepfile" \
276ad47b356Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277ad47b356Smrg      | tr "$nl" ' ' >> "$depfile"
278278eca22Smrg    echo >> "$depfile"
27933c89af1Smrg    # The second pass generates a dummy entry for each header file.
280ad47b356Smrg    tr ' ' "$nl" < "$tmpdepfile" \
281ad47b356Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282ad47b356Smrg      >> "$depfile"
28333c89af1Smrg  else
284ad47b356Smrg    make_dummy_depfile
28533c89af1Smrg  fi
28633c89af1Smrg  rm -f "$tmpdepfile"
28733c89af1Smrg  ;;
28833c89af1Smrg
289ad47b356Smrgxlc)
290ad47b356Smrg  # This case exists only to let depend.m4 do its work.  It works by
291ad47b356Smrg  # looking at the text of this script.  This case will never be run,
292ad47b356Smrg  # since it is checked for above.
293ad47b356Smrg  exit 1
294ad47b356Smrg  ;;
295ad47b356Smrg
29633c89af1Smrgaix)
29733c89af1Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
29833c89af1Smrg  # in a .u file.  In older versions, this file always lives in the
299ad47b356Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30033c89af1Smrg  # start of each line; $object doesn't have directory information.
30133c89af1Smrg  # Version 6 uses the directory in both cases.
302ad47b356Smrg  set_dir_from "$object"
303ad47b356Smrg  set_base_from "$object"
30433c89af1Smrg  if test "$libtool" = yes; then
305278eca22Smrg    tmpdepfile1=$dir$base.u
306278eca22Smrg    tmpdepfile2=$base.u
307278eca22Smrg    tmpdepfile3=$dir.libs/$base.u
30833c89af1Smrg    "$@" -Wc,-M
30933c89af1Smrg  else
310278eca22Smrg    tmpdepfile1=$dir$base.u
311278eca22Smrg    tmpdepfile2=$dir$base.u
312278eca22Smrg    tmpdepfile3=$dir$base.u
31333c89af1Smrg    "$@" -M
31433c89af1Smrg  fi
31533c89af1Smrg  stat=$?
316ad47b356Smrg  if test $stat -ne 0; then
317278eca22Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31833c89af1Smrg    exit $stat
31933c89af1Smrg  fi
32033c89af1Smrg
321278eca22Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322278eca22Smrg  do
323278eca22Smrg    test -f "$tmpdepfile" && break
324278eca22Smrg  done
325ad47b356Smrg  aix_post_process_depfile
326ad47b356Smrg  ;;
327ad47b356Smrg
328ad47b356Smrgtcc)
329ad47b356Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330ad47b356Smrg  # FIXME: That version still under development at the moment of writing.
331ad47b356Smrg  #        Make that this statement remains true also for stable, released
332ad47b356Smrg  #        versions.
333ad47b356Smrg  # It will wrap lines (doesn't matter whether long or short) with a
334ad47b356Smrg  # trailing '\', as in:
335ad47b356Smrg  #
336ad47b356Smrg  #   foo.o : \
337ad47b356Smrg  #    foo.c \
338ad47b356Smrg  #    foo.h \
339ad47b356Smrg  #
340ad47b356Smrg  # It will put a trailing '\' even on the last line, and will use leading
341ad47b356Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342ad47b356Smrg  # "Emit spaces for -MD").
343ad47b356Smrg  "$@" -MD -MF "$tmpdepfile"
344ad47b356Smrg  stat=$?
345ad47b356Smrg  if test $stat -ne 0; then
346ad47b356Smrg    rm -f "$tmpdepfile"
347ad47b356Smrg    exit $stat
34833c89af1Smrg  fi
349ad47b356Smrg  rm -f "$depfile"
350ad47b356Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351ad47b356Smrg  # We have to change lines of the first kind to '$object: \'.
352ad47b356Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353ad47b356Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354ad47b356Smrg  # dummy dependency, to avoid the deleted-header problem.
355ad47b356Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35633c89af1Smrg  rm -f "$tmpdepfile"
35733c89af1Smrg  ;;
35833c89af1Smrg
359ad47b356Smrg## The order of this option in the case statement is important, since the
360ad47b356Smrg## shell code in configure will try each of these formats in the order
361ad47b356Smrg## listed in this file.  A plain '-MD' option would be understood by many
362ad47b356Smrg## compilers, so we must ensure this comes after the gcc and icc options.
363ad47b356Smrgpgcc)
364ad47b356Smrg  # Portland's C compiler understands '-MD'.
365ad47b356Smrg  # Will always output deps to 'file.d' where file is the root name of the
366ad47b356Smrg  # source file under compilation, even if file resides in a subdirectory.
367ad47b356Smrg  # The object file name does not affect the name of the '.d' file.
368ad47b356Smrg  # pgcc 10.2 will output
36933c89af1Smrg  #    foo.o: sub/foo.c sub/foo.h
370ad47b356Smrg  # and will wrap long lines using '\' :
37133c89af1Smrg  #    foo.o: sub/foo.c ... \
37233c89af1Smrg  #     sub/foo.h ... \
37333c89af1Smrg  #     ...
374ad47b356Smrg  set_dir_from "$object"
375ad47b356Smrg  # Use the source, not the object, to determine the base name, since
376ad47b356Smrg  # that's sadly what pgcc will do too.
377ad47b356Smrg  set_base_from "$source"
378ad47b356Smrg  tmpdepfile=$base.d
379ad47b356Smrg
380ad47b356Smrg  # For projects that build the same source file twice into different object
381ad47b356Smrg  # files, the pgcc approach of using the *source* file root name can cause
382ad47b356Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383ad47b356Smrg  # the same $tmpdepfile.
384ad47b356Smrg  lockdir=$base.d-lock
385ad47b356Smrg  trap "
386ad47b356Smrg    echo '$0: caught signal, cleaning up...' >&2
387ad47b356Smrg    rmdir '$lockdir'
388ad47b356Smrg    exit 1
389ad47b356Smrg  " 1 2 13 15
390ad47b356Smrg  numtries=100
391ad47b356Smrg  i=$numtries
392ad47b356Smrg  while test $i -gt 0; do
393ad47b356Smrg    # mkdir is a portable test-and-set.
394ad47b356Smrg    if mkdir "$lockdir" 2>/dev/null; then
395ad47b356Smrg      # This process acquired the lock.
396ad47b356Smrg      "$@" -MD
397ad47b356Smrg      stat=$?
398ad47b356Smrg      # Release the lock.
399ad47b356Smrg      rmdir "$lockdir"
400ad47b356Smrg      break
401ad47b356Smrg    else
402ad47b356Smrg      # If the lock is being held by a different process, wait
403ad47b356Smrg      # until the winning process is done or we timeout.
404ad47b356Smrg      while test -d "$lockdir" && test $i -gt 0; do
405ad47b356Smrg        sleep 1
406ad47b356Smrg        i=`expr $i - 1`
407ad47b356Smrg      done
408ad47b356Smrg    fi
409ad47b356Smrg    i=`expr $i - 1`
410ad47b356Smrg  done
411ad47b356Smrg  trap - 1 2 13 15
412ad47b356Smrg  if test $i -le 0; then
413ad47b356Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414ad47b356Smrg    echo "$0: check lockdir '$lockdir'" >&2
415ad47b356Smrg    exit 1
416ad47b356Smrg  fi
41733c89af1Smrg
418ad47b356Smrg  if test $stat -ne 0; then
41933c89af1Smrg    rm -f "$tmpdepfile"
42033c89af1Smrg    exit $stat
42133c89af1Smrg  fi
42233c89af1Smrg  rm -f "$depfile"
42333c89af1Smrg  # Each line is of the form `foo.o: dependent.h',
42433c89af1Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42533c89af1Smrg  # Do two passes, one to just change these to
42633c89af1Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42733c89af1Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42833c89af1Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
42933c89af1Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
430ad47b356Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431ad47b356Smrg    | sed -e 's/$/ :/' >> "$depfile"
43233c89af1Smrg  rm -f "$tmpdepfile"
43333c89af1Smrg  ;;
43433c89af1Smrg
435278eca22Smrghp2)
436278eca22Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437278eca22Smrg  # compilers, which have integrated preprocessors.  The correct option
438278eca22Smrg  # to use with these is +Maked; it writes dependencies to a file named
439278eca22Smrg  # 'foo.d', which lands next to the object file, wherever that
440278eca22Smrg  # happens to be.
441278eca22Smrg  # Much of this is similar to the tru64 case; see comments there.
442ad47b356Smrg  set_dir_from  "$object"
443ad47b356Smrg  set_base_from "$object"
444278eca22Smrg  if test "$libtool" = yes; then
445278eca22Smrg    tmpdepfile1=$dir$base.d
446278eca22Smrg    tmpdepfile2=$dir.libs/$base.d
447278eca22Smrg    "$@" -Wc,+Maked
448278eca22Smrg  else
449278eca22Smrg    tmpdepfile1=$dir$base.d
450278eca22Smrg    tmpdepfile2=$dir$base.d
451278eca22Smrg    "$@" +Maked
452278eca22Smrg  fi
453278eca22Smrg  stat=$?
454ad47b356Smrg  if test $stat -ne 0; then
455278eca22Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456278eca22Smrg     exit $stat
457278eca22Smrg  fi
458278eca22Smrg
459278eca22Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460278eca22Smrg  do
461278eca22Smrg    test -f "$tmpdepfile" && break
462278eca22Smrg  done
463278eca22Smrg  if test -f "$tmpdepfile"; then
464ad47b356Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465ad47b356Smrg    # Add 'dependent.h:' lines.
466278eca22Smrg    sed -ne '2,${
467ad47b356Smrg               s/^ *//
468ad47b356Smrg               s/ \\*$//
469ad47b356Smrg               s/$/:/
470ad47b356Smrg               p
471ad47b356Smrg             }' "$tmpdepfile" >> "$depfile"
472278eca22Smrg  else
473ad47b356Smrg    make_dummy_depfile
474278eca22Smrg  fi
475278eca22Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476278eca22Smrg  ;;
477278eca22Smrg
47833c89af1Smrgtru64)
479ad47b356Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480ad47b356Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481ad47b356Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482ad47b356Smrg  # dependencies in 'foo.d' instead, so we check for that too.
483ad47b356Smrg  # Subdirectories are respected.
484ad47b356Smrg  set_dir_from  "$object"
485ad47b356Smrg  set_base_from "$object"
486ad47b356Smrg
487ad47b356Smrg  if test "$libtool" = yes; then
488ad47b356Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489ad47b356Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490ad47b356Smrg    # in $dir$base.o.d.  We have to check for both files, because
491ad47b356Smrg    # one of the two compilations can be disabled.  We should prefer
492ad47b356Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493ad47b356Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
494ad47b356Smrg    # the former would cause a distcleancheck panic.
495ad47b356Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496ad47b356Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497ad47b356Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498ad47b356Smrg    "$@" -Wc,-MD
499ad47b356Smrg  else
500ad47b356Smrg    tmpdepfile1=$dir$base.d
501ad47b356Smrg    tmpdepfile2=$dir$base.d
502ad47b356Smrg    tmpdepfile3=$dir$base.d
503ad47b356Smrg    "$@" -MD
504ad47b356Smrg  fi
505ad47b356Smrg
506ad47b356Smrg  stat=$?
507ad47b356Smrg  if test $stat -ne 0; then
508ad47b356Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509ad47b356Smrg    exit $stat
510ad47b356Smrg  fi
511ad47b356Smrg
512ad47b356Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513ad47b356Smrg  do
514ad47b356Smrg    test -f "$tmpdepfile" && break
515ad47b356Smrg  done
516ad47b356Smrg  # Same post-processing that is required for AIX mode.
517ad47b356Smrg  aix_post_process_depfile
518ad47b356Smrg  ;;
51933c89af1Smrg
520988795beSmrgmsvc7)
521988795beSmrg  if test "$libtool" = yes; then
522988795beSmrg    showIncludes=-Wc,-showIncludes
523988795beSmrg  else
524988795beSmrg    showIncludes=-showIncludes
525988795beSmrg  fi
526988795beSmrg  "$@" $showIncludes > "$tmpdepfile"
527988795beSmrg  stat=$?
528988795beSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
529ad47b356Smrg  if test $stat -ne 0; then
530988795beSmrg    rm -f "$tmpdepfile"
531988795beSmrg    exit $stat
532988795beSmrg  fi
533988795beSmrg  rm -f "$depfile"
534988795beSmrg  echo "$object : \\" > "$depfile"
535988795beSmrg  # The first sed program below extracts the file names and escapes
536988795beSmrg  # backslashes for cygpath.  The second sed program outputs the file
537988795beSmrg  # name when reading, but also accumulates all include files in the
538988795beSmrg  # hold buffer in order to output them again at the end.  This only
539988795beSmrg  # works with sed implementations that can handle large buffers.
540988795beSmrg  sed < "$tmpdepfile" -n '
541988795beSmrg/^Note: including file:  *\(.*\)/ {
542988795beSmrg  s//\1/
543988795beSmrg  s/\\/\\\\/g
544988795beSmrg  p
545988795beSmrg}' | $cygpath_u | sort -u | sed -n '
546988795beSmrgs/ /\\ /g
547ad47b356Smrgs/\(.*\)/'"$tab"'\1 \\/p
548988795beSmrgs/.\(.*\) \\/\1:/
549988795beSmrgH
550988795beSmrg$ {
551ad47b356Smrg  s/.*/'"$tab"'/
552988795beSmrg  G
553988795beSmrg  p
554988795beSmrg}' >> "$depfile"
555ad47b356Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556988795beSmrg  rm -f "$tmpdepfile"
557988795beSmrg  ;;
558988795beSmrg
559988795beSmrgmsvc7msys)
560988795beSmrg  # This case exists only to let depend.m4 do its work.  It works by
561988795beSmrg  # looking at the text of this script.  This case will never be run,
562988795beSmrg  # since it is checked for above.
563988795beSmrg  exit 1
564988795beSmrg  ;;
565988795beSmrg
56633c89af1Smrg#nosideeffect)
56733c89af1Smrg  # This comment above is used by automake to tell side-effect
56833c89af1Smrg  # dependency tracking mechanisms from slower ones.
56933c89af1Smrg
57033c89af1Smrgdashmstdout)
57133c89af1Smrg  # Important note: in order to support this mode, a compiler *must*
57233c89af1Smrg  # always write the preprocessed file to stdout, regardless of -o.
57333c89af1Smrg  "$@" || exit $?
57433c89af1Smrg
57533c89af1Smrg  # Remove the call to Libtool.
57633c89af1Smrg  if test "$libtool" = yes; then
577278eca22Smrg    while test "X$1" != 'X--mode=compile'; do
57833c89af1Smrg      shift
57933c89af1Smrg    done
58033c89af1Smrg    shift
58133c89af1Smrg  fi
58233c89af1Smrg
583ad47b356Smrg  # Remove '-o $object'.
58433c89af1Smrg  IFS=" "
58533c89af1Smrg  for arg
58633c89af1Smrg  do
58733c89af1Smrg    case $arg in
58833c89af1Smrg    -o)
58933c89af1Smrg      shift
59033c89af1Smrg      ;;
59133c89af1Smrg    $object)
59233c89af1Smrg      shift
59333c89af1Smrg      ;;
59433c89af1Smrg    *)
59533c89af1Smrg      set fnord "$@" "$arg"
59633c89af1Smrg      shift # fnord
59733c89af1Smrg      shift # $arg
59833c89af1Smrg      ;;
59933c89af1Smrg    esac
60033c89af1Smrg  done
60133c89af1Smrg
60233c89af1Smrg  test -z "$dashmflag" && dashmflag=-M
603ad47b356Smrg  # Require at least two characters before searching for ':'
60433c89af1Smrg  # in the target name.  This is to cope with DOS-style filenames:
605ad47b356Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60633c89af1Smrg  "$@" $dashmflag |
607ad47b356Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60833c89af1Smrg  rm -f "$depfile"
60933c89af1Smrg  cat < "$tmpdepfile" > "$depfile"
610ad47b356Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611ad47b356Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
612ad47b356Smrg  tr ' ' "$nl" < "$tmpdepfile" \
613ad47b356Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614ad47b356Smrg    | sed -e 's/$/ :/' >> "$depfile"
61533c89af1Smrg  rm -f "$tmpdepfile"
61633c89af1Smrg  ;;
61733c89af1Smrg
61833c89af1SmrgdashXmstdout)
61933c89af1Smrg  # This case only exists to satisfy depend.m4.  It is never actually
62033c89af1Smrg  # run, as this mode is specially recognized in the preamble.
62133c89af1Smrg  exit 1
62233c89af1Smrg  ;;
62333c89af1Smrg
62433c89af1Smrgmakedepend)
62533c89af1Smrg  "$@" || exit $?
62633c89af1Smrg  # Remove any Libtool call
62733c89af1Smrg  if test "$libtool" = yes; then
628278eca22Smrg    while test "X$1" != 'X--mode=compile'; do
62933c89af1Smrg      shift
63033c89af1Smrg    done
63133c89af1Smrg    shift
63233c89af1Smrg  fi
63333c89af1Smrg  # X makedepend
63433c89af1Smrg  shift
635278eca22Smrg  cleared=no eat=no
636278eca22Smrg  for arg
637278eca22Smrg  do
63833c89af1Smrg    case $cleared in
63933c89af1Smrg    no)
64033c89af1Smrg      set ""; shift
64133c89af1Smrg      cleared=yes ;;
64233c89af1Smrg    esac
643278eca22Smrg    if test $eat = yes; then
644278eca22Smrg      eat=no
645278eca22Smrg      continue
646278eca22Smrg    fi
64733c89af1Smrg    case "$arg" in
64833c89af1Smrg    -D*|-I*)
64933c89af1Smrg      set fnord "$@" "$arg"; shift ;;
65033c89af1Smrg    # Strip any option that makedepend may not understand.  Remove
65133c89af1Smrg    # the object too, otherwise makedepend will parse it as a source file.
652278eca22Smrg    -arch)
653278eca22Smrg      eat=yes ;;
65433c89af1Smrg    -*|$object)
65533c89af1Smrg      ;;
65633c89af1Smrg    *)
65733c89af1Smrg      set fnord "$@" "$arg"; shift ;;
65833c89af1Smrg    esac
65933c89af1Smrg  done
660278eca22Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66133c89af1Smrg  touch "$tmpdepfile"
66233c89af1Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66333c89af1Smrg  rm -f "$depfile"
664988795beSmrg  # makedepend may prepend the VPATH from the source file name to the object.
665988795beSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666988795beSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667ad47b356Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668ad47b356Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
669ad47b356Smrg  sed '1,2d' "$tmpdepfile" \
670ad47b356Smrg    | tr ' ' "$nl" \
671ad47b356Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672ad47b356Smrg    | sed -e 's/$/ :/' >> "$depfile"
67333c89af1Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67433c89af1Smrg  ;;
67533c89af1Smrg
67633c89af1Smrgcpp)
67733c89af1Smrg  # Important note: in order to support this mode, a compiler *must*
67833c89af1Smrg  # always write the preprocessed file to stdout.
67933c89af1Smrg  "$@" || exit $?
68033c89af1Smrg
68133c89af1Smrg  # Remove the call to Libtool.
68233c89af1Smrg  if test "$libtool" = yes; then
683278eca22Smrg    while test "X$1" != 'X--mode=compile'; do
68433c89af1Smrg      shift
68533c89af1Smrg    done
68633c89af1Smrg    shift
68733c89af1Smrg  fi
68833c89af1Smrg
689ad47b356Smrg  # Remove '-o $object'.
69033c89af1Smrg  IFS=" "
69133c89af1Smrg  for arg
69233c89af1Smrg  do
69333c89af1Smrg    case $arg in
69433c89af1Smrg    -o)
69533c89af1Smrg      shift
69633c89af1Smrg      ;;
69733c89af1Smrg    $object)
69833c89af1Smrg      shift
69933c89af1Smrg      ;;
70033c89af1Smrg    *)
70133c89af1Smrg      set fnord "$@" "$arg"
70233c89af1Smrg      shift # fnord
70333c89af1Smrg      shift # $arg
70433c89af1Smrg      ;;
70533c89af1Smrg    esac
70633c89af1Smrg  done
70733c89af1Smrg
708ad47b356Smrg  "$@" -E \
709ad47b356Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710ad47b356Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711ad47b356Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
71233c89af1Smrg  rm -f "$depfile"
71333c89af1Smrg  echo "$object : \\" > "$depfile"
71433c89af1Smrg  cat < "$tmpdepfile" >> "$depfile"
71533c89af1Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71633c89af1Smrg  rm -f "$tmpdepfile"
71733c89af1Smrg  ;;
71833c89af1Smrg
71933c89af1Smrgmsvisualcpp)
72033c89af1Smrg  # Important note: in order to support this mode, a compiler *must*
721278eca22Smrg  # always write the preprocessed file to stdout.
72233c89af1Smrg  "$@" || exit $?
723278eca22Smrg
724278eca22Smrg  # Remove the call to Libtool.
725278eca22Smrg  if test "$libtool" = yes; then
726278eca22Smrg    while test "X$1" != 'X--mode=compile'; do
727278eca22Smrg      shift
728278eca22Smrg    done
729278eca22Smrg    shift
730278eca22Smrg  fi
731278eca22Smrg
73233c89af1Smrg  IFS=" "
73333c89af1Smrg  for arg
73433c89af1Smrg  do
73533c89af1Smrg    case "$arg" in
736278eca22Smrg    -o)
737278eca22Smrg      shift
738278eca22Smrg      ;;
739278eca22Smrg    $object)
740278eca22Smrg      shift
741278eca22Smrg      ;;
74233c89af1Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743ad47b356Smrg        set fnord "$@"
744ad47b356Smrg        shift
745ad47b356Smrg        shift
746ad47b356Smrg        ;;
74733c89af1Smrg    *)
748ad47b356Smrg        set fnord "$@" "$arg"
749ad47b356Smrg        shift
750ad47b356Smrg        shift
751ad47b356Smrg        ;;
75233c89af1Smrg    esac
75333c89af1Smrg  done
754278eca22Smrg  "$@" -E 2>/dev/null |
755278eca22Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75633c89af1Smrg  rm -f "$depfile"
75733c89af1Smrg  echo "$object : \\" > "$depfile"
758ad47b356Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759ad47b356Smrg  echo "$tab" >> "$depfile"
760278eca22Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76133c89af1Smrg  rm -f "$tmpdepfile"
76233c89af1Smrg  ;;
76333c89af1Smrg
764278eca22Smrgmsvcmsys)
765278eca22Smrg  # This case exists only to let depend.m4 do its work.  It works by
766278eca22Smrg  # looking at the text of this script.  This case will never be run,
767278eca22Smrg  # since it is checked for above.
768278eca22Smrg  exit 1
769278eca22Smrg  ;;
770278eca22Smrg
77133c89af1Smrgnone)
77233c89af1Smrg  exec "$@"
77333c89af1Smrg  ;;
77433c89af1Smrg
77533c89af1Smrg*)
77633c89af1Smrg  echo "Unknown depmode $depmode" 1>&2
77733c89af1Smrg  exit 1
77833c89af1Smrg  ;;
77933c89af1Smrgesac
78033c89af1Smrg
78133c89af1Smrgexit 0
78233c89af1Smrg
78333c89af1Smrg# Local Variables:
78433c89af1Smrg# mode: shell-script
78533c89af1Smrg# sh-indentation: 2
786352bf44eSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
78733c89af1Smrg# time-stamp-start: "scriptversion="
78833c89af1Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789352bf44eSmrg# time-stamp-time-zone: "UTC0"
790278eca22Smrg# time-stamp-end: "; # UTC"
79133c89af1Smrg# End:
792