129459361Smrg#! /bin/sh
229459361Smrg# depcomp - compile a program generating dependencies as side-effects
329459361Smrg
4eb323118Smrgscriptversion=2024-06-19.01; # UTC
529459361Smrg
6eb323118Smrg# Copyright (C) 1999-2024 Free Software Foundation, Inc.
729459361Smrg
829459361Smrg# This program is free software; you can redistribute it and/or modify
929459361Smrg# it under the terms of the GNU General Public License as published by
1029459361Smrg# the Free Software Foundation; either version 2, or (at your option)
1129459361Smrg# any later version.
1229459361Smrg
1329459361Smrg# This program is distributed in the hope that it will be useful,
1429459361Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1529459361Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1629459361Smrg# GNU General Public License for more details.
1729459361Smrg
1829459361Smrg# You should have received a copy of the GNU General Public License
19e24f450bSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2029459361Smrg
2129459361Smrg# As a special exception to the GNU General Public License, if you
2229459361Smrg# distribute this file as part of a program that contains a
2329459361Smrg# configuration script generated by Autoconf, you may include it under
2429459361Smrg# the same distribution terms that you use for the rest of that program.
2529459361Smrg
2629459361Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2729459361Smrg
2829459361Smrgcase $1 in
2929459361Smrg  '')
30fb4ebca8Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31fb4ebca8Smrg    exit 1;
32fb4ebca8Smrg    ;;
3329459361Smrg  -h | --h*)
3429459361Smrg    cat <<\EOF
3529459361SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3629459361Smrg
3729459361SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3829459361Smrgas side-effects.
3929459361Smrg
4029459361SmrgEnvironment variables:
4129459361Smrg  depmode     Dependency tracking mode.
42fb4ebca8Smrg  source      Source file read by 'PROGRAMS ARGS'.
43fb4ebca8Smrg  object      Object file output by 'PROGRAMS ARGS'.
4429459361Smrg  DEPDIR      directory where to store dependencies.
4529459361Smrg  depfile     Dependency file to output.
465dd2154eSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
4729459361Smrg  libtool     Whether libtool is used (yes/no).
4829459361Smrg
4929459361SmrgReport bugs to <bug-automake@gnu.org>.
50eb323118SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
51eb323118SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>.
5229459361SmrgEOF
5329459361Smrg    exit $?
5429459361Smrg    ;;
5529459361Smrg  -v | --v*)
56eb323118Smrg    echo "depcomp (GNU Automake) $scriptversion"
5729459361Smrg    exit $?
5829459361Smrg    ;;
5929459361Smrgesac
6029459361Smrg
61fb4ebca8Smrg# Get the directory component of the given path, and save it in the
62fb4ebca8Smrg# global variables '$dir'.  Note that this directory component will
63fb4ebca8Smrg# be either empty or ending with a '/' character.  This is deliberate.
64fb4ebca8Smrgset_dir_from ()
65fb4ebca8Smrg{
66fb4ebca8Smrg  case $1 in
67fb4ebca8Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
68fb4ebca8Smrg      *) dir=;;
69fb4ebca8Smrg  esac
70fb4ebca8Smrg}
71fb4ebca8Smrg
72fb4ebca8Smrg# Get the suffix-stripped basename of the given path, and save it the
73fb4ebca8Smrg# global variable '$base'.
74fb4ebca8Smrgset_base_from ()
75fb4ebca8Smrg{
76fb4ebca8Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
77fb4ebca8Smrg}
78fb4ebca8Smrg
79fb4ebca8Smrg# If no dependency file was actually created by the compiler invocation,
80fb4ebca8Smrg# we still have to create a dummy depfile, to avoid errors with the
81fb4ebca8Smrg# Makefile "include basename.Plo" scheme.
82fb4ebca8Smrgmake_dummy_depfile ()
83fb4ebca8Smrg{
84fb4ebca8Smrg  echo "#dummy" > "$depfile"
85fb4ebca8Smrg}
86fb4ebca8Smrg
87fb4ebca8Smrg# Factor out some common post-processing of the generated depfile.
88fb4ebca8Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
89fb4ebca8Smrgaix_post_process_depfile ()
90fb4ebca8Smrg{
91fb4ebca8Smrg  # If the compiler actually managed to produce a dependency file,
92fb4ebca8Smrg  # post-process it.
93fb4ebca8Smrg  if test -f "$tmpdepfile"; then
94fb4ebca8Smrg    # Each line is of the form 'foo.o: dependency.h'.
95fb4ebca8Smrg    # Do two passes, one to just change these to
96fb4ebca8Smrg    #   $object: dependency.h
97fb4ebca8Smrg    # and one to simply output
98fb4ebca8Smrg    #   dependency.h:
99fb4ebca8Smrg    # which is needed to avoid the deleted-header problem.
100fb4ebca8Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
101fb4ebca8Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
102fb4ebca8Smrg    } > "$depfile"
103fb4ebca8Smrg    rm -f "$tmpdepfile"
104fb4ebca8Smrg  else
105fb4ebca8Smrg    make_dummy_depfile
106fb4ebca8Smrg  fi
107fb4ebca8Smrg}
108fb4ebca8Smrg
109fb4ebca8Smrg# A tabulation character.
110fb4ebca8Smrgtab='	'
111fb4ebca8Smrg# A newline character.
112fb4ebca8Smrgnl='
113fb4ebca8Smrg'
114fb4ebca8Smrg# Character ranges might be problematic outside the C locale.
115fb4ebca8Smrg# These definitions help.
116fb4ebca8Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
117fb4ebca8Smrglower=abcdefghijklmnopqrstuvwxyz
118fb4ebca8Smrgalpha=${upper}${lower}
119fb4ebca8Smrg
12029459361Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12129459361Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12229459361Smrg  exit 1
12329459361Smrgfi
12429459361Smrg
12529459361Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12629459361Smrgdepfile=${depfile-`echo "$object" |
12729459361Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12829459361Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12929459361Smrg
13029459361Smrgrm -f "$tmpdepfile"
13129459361Smrg
132eb323118Smrg# Avoid interference from the environment.
133fb4ebca8Smrggccflag= dashmflag=
134fb4ebca8Smrg
13529459361Smrg# Some modes work just like other modes, but use different flags.  We
13629459361Smrg# parameterize here, but still list the modes in the big case below,
13729459361Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13829459361Smrg# here, because this file can only contain one case statement.
13929459361Smrgif test "$depmode" = hp; then
14029459361Smrg  # HP compiler uses -M and no extra arg.
14129459361Smrg  gccflag=-M
14229459361Smrg  depmode=gcc
14329459361Smrgfi
14429459361Smrg
14529459361Smrgif test "$depmode" = dashXmstdout; then
146fb4ebca8Smrg  # This is just like dashmstdout with a different argument.
147fb4ebca8Smrg  dashmflag=-xM
148fb4ebca8Smrg  depmode=dashmstdout
14929459361Smrgfi
15029459361Smrg
15147202d7bSmrgcygpath_u="cygpath -u -f -"
15247202d7bSmrgif test "$depmode" = msvcmsys; then
153fb4ebca8Smrg  # This is just like msvisualcpp but w/o cygpath translation.
154fb4ebca8Smrg  # Just convert the backslash-escaped backslashes to single forward
155fb4ebca8Smrg  # slashes to satisfy depend.m4
156fb4ebca8Smrg  cygpath_u='sed s,\\\\,/,g'
157fb4ebca8Smrg  depmode=msvisualcpp
15847202d7bSmrgfi
15947202d7bSmrg
1605dd2154eSmrgif test "$depmode" = msvc7msys; then
161fb4ebca8Smrg  # This is just like msvc7 but w/o cygpath translation.
162fb4ebca8Smrg  # Just convert the backslash-escaped backslashes to single forward
163fb4ebca8Smrg  # slashes to satisfy depend.m4
164fb4ebca8Smrg  cygpath_u='sed s,\\\\,/,g'
165fb4ebca8Smrg  depmode=msvc7
166fb4ebca8Smrgfi
167fb4ebca8Smrg
168fb4ebca8Smrgif test "$depmode" = xlc; then
169fb4ebca8Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
170fb4ebca8Smrg  gccflag=-qmakedep=gcc,-MF
171fb4ebca8Smrg  depmode=gcc
1725dd2154eSmrgfi
1735dd2154eSmrg
17429459361Smrgcase "$depmode" in
17529459361Smrggcc3)
17629459361Smrg## gcc 3 implements dependency tracking that does exactly what
17729459361Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17829459361Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
17947202d7bSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
18047202d7bSmrg## the command line argument order; so add the flags where they
18147202d7bSmrg## appear in depend2.am.  Note that the slowdown incurred here
18247202d7bSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
18347202d7bSmrg  for arg
18447202d7bSmrg  do
18547202d7bSmrg    case $arg in
18647202d7bSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
18747202d7bSmrg    *)  set fnord "$@" "$arg" ;;
18847202d7bSmrg    esac
18947202d7bSmrg    shift # fnord
19047202d7bSmrg    shift # $arg
19147202d7bSmrg  done
19247202d7bSmrg  "$@"
19329459361Smrg  stat=$?
194fb4ebca8Smrg  if test $stat -ne 0; then
19529459361Smrg    rm -f "$tmpdepfile"
19629459361Smrg    exit $stat
19729459361Smrg  fi
19829459361Smrg  mv "$tmpdepfile" "$depfile"
19929459361Smrg  ;;
20029459361Smrg
20129459361Smrggcc)
202eb323118Smrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers.
203eb323118Smrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler.
204fb4ebca8Smrg## (see the conditional assignment to $gccflag above).
20529459361Smrg## There are various ways to get dependency output from gcc.  Here's
20629459361Smrg## why we pick this rather obscure method:
20729459361Smrg## - Don't want to use -MD because we'd like the dependencies to end
20829459361Smrg##   up in a subdir.  Having to rename by hand is ugly.
20929459361Smrg##   (We might end up doing this anyway to support other compilers.)
21029459361Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
211fb4ebca8Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
212fb4ebca8Smrg##   supported by the other compilers which use the 'gcc' depmode.
21329459361Smrg## - Using -M directly means running the compiler twice (even worse
21429459361Smrg##   than renaming).
21529459361Smrg  if test -z "$gccflag"; then
21629459361Smrg    gccflag=-MD,
21729459361Smrg  fi
21829459361Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
21929459361Smrg  stat=$?
220fb4ebca8Smrg  if test $stat -ne 0; then
22129459361Smrg    rm -f "$tmpdepfile"
22229459361Smrg    exit $stat
22329459361Smrg  fi
22429459361Smrg  rm -f "$depfile"
22529459361Smrg  echo "$object : \\" > "$depfile"
226fb4ebca8Smrg  # The second -e expression handles DOS-style file names with drive
227fb4ebca8Smrg  # letters.
22829459361Smrg  sed -e 's/^[^:]*: / /' \
22929459361Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
230fb4ebca8Smrg## This next piece of magic avoids the "deleted header file" problem.
23129459361Smrg## The problem is that when a header file which appears in a .P file
23229459361Smrg## is deleted, the dependency causes make to die (because there is
23329459361Smrg## typically no way to rebuild the header).  We avoid this by adding
23429459361Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23529459361Smrg## this for us directly.
236fb4ebca8Smrg## Some versions of gcc put a space before the ':'.  On the theory
23729459361Smrg## that the space means something, we add a space to the output as
2385dd2154eSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2395dd2154eSmrg## to the object.  Take care to not repeat it in the output.
24029459361Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
24129459361Smrg## correctly.  Breaking it into two sed invocations is a workaround.
242fb4ebca8Smrg  tr ' ' "$nl" < "$tmpdepfile" \
243fb4ebca8Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
244fb4ebca8Smrg    | sed -e 's/$/ :/' >> "$depfile"
24529459361Smrg  rm -f "$tmpdepfile"
24629459361Smrg  ;;
24729459361Smrg
24829459361Smrghp)
24929459361Smrg  # This case exists only to let depend.m4 do its work.  It works by
25029459361Smrg  # looking at the text of this script.  This case will never be run,
25129459361Smrg  # since it is checked for above.
25229459361Smrg  exit 1
25329459361Smrg  ;;
25429459361Smrg
25529459361Smrgsgi)
25629459361Smrg  if test "$libtool" = yes; then
25729459361Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25829459361Smrg  else
25929459361Smrg    "$@" -MDupdate "$tmpdepfile"
26029459361Smrg  fi
26129459361Smrg  stat=$?
262fb4ebca8Smrg  if test $stat -ne 0; then
26329459361Smrg    rm -f "$tmpdepfile"
26429459361Smrg    exit $stat
26529459361Smrg  fi
26629459361Smrg  rm -f "$depfile"
26729459361Smrg
26829459361Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26929459361Smrg    echo "$object : \\" > "$depfile"
27029459361Smrg    # Clip off the initial element (the dependent).  Don't try to be
27129459361Smrg    # clever and replace this with sed code, as IRIX sed won't handle
27229459361Smrg    # lines with more than a fixed number of characters (4096 in
27329459361Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
274fb4ebca8Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
27529459361Smrg    # dependency line.
276fb4ebca8Smrg    tr ' ' "$nl" < "$tmpdepfile" \
277fb4ebca8Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
278fb4ebca8Smrg      | tr "$nl" ' ' >> "$depfile"
27947202d7bSmrg    echo >> "$depfile"
28029459361Smrg    # The second pass generates a dummy entry for each header file.
281fb4ebca8Smrg    tr ' ' "$nl" < "$tmpdepfile" \
282fb4ebca8Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
283fb4ebca8Smrg      >> "$depfile"
28429459361Smrg  else
285fb4ebca8Smrg    make_dummy_depfile
28629459361Smrg  fi
28729459361Smrg  rm -f "$tmpdepfile"
28829459361Smrg  ;;
28929459361Smrg
290fb4ebca8Smrgxlc)
291fb4ebca8Smrg  # This case exists only to let depend.m4 do its work.  It works by
292fb4ebca8Smrg  # looking at the text of this script.  This case will never be run,
293fb4ebca8Smrg  # since it is checked for above.
294fb4ebca8Smrg  exit 1
295fb4ebca8Smrg  ;;
296fb4ebca8Smrg
29729459361Smrgaix)
29829459361Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
29929459361Smrg  # in a .u file.  In older versions, this file always lives in the
300fb4ebca8Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30129459361Smrg  # start of each line; $object doesn't have directory information.
30229459361Smrg  # Version 6 uses the directory in both cases.
303fb4ebca8Smrg  set_dir_from "$object"
304fb4ebca8Smrg  set_base_from "$object"
30529459361Smrg  if test "$libtool" = yes; then
30647202d7bSmrg    tmpdepfile1=$dir$base.u
30747202d7bSmrg    tmpdepfile2=$base.u
30847202d7bSmrg    tmpdepfile3=$dir.libs/$base.u
30929459361Smrg    "$@" -Wc,-M
31029459361Smrg  else
31147202d7bSmrg    tmpdepfile1=$dir$base.u
31247202d7bSmrg    tmpdepfile2=$dir$base.u
31347202d7bSmrg    tmpdepfile3=$dir$base.u
31429459361Smrg    "$@" -M
31529459361Smrg  fi
31629459361Smrg  stat=$?
317fb4ebca8Smrg  if test $stat -ne 0; then
31847202d7bSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31929459361Smrg    exit $stat
32029459361Smrg  fi
32129459361Smrg
32247202d7bSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
32347202d7bSmrg  do
32447202d7bSmrg    test -f "$tmpdepfile" && break
32547202d7bSmrg  done
326fb4ebca8Smrg  aix_post_process_depfile
327fb4ebca8Smrg  ;;
328fb4ebca8Smrg
329fb4ebca8Smrgtcc)
330fb4ebca8Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
331fb4ebca8Smrg  # FIXME: That version still under development at the moment of writing.
332fb4ebca8Smrg  #        Make that this statement remains true also for stable, released
333fb4ebca8Smrg  #        versions.
334fb4ebca8Smrg  # It will wrap lines (doesn't matter whether long or short) with a
335fb4ebca8Smrg  # trailing '\', as in:
336fb4ebca8Smrg  #
337fb4ebca8Smrg  #   foo.o : \
338fb4ebca8Smrg  #    foo.c \
339fb4ebca8Smrg  #    foo.h \
340fb4ebca8Smrg  #
341fb4ebca8Smrg  # It will put a trailing '\' even on the last line, and will use leading
342fb4ebca8Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
343fb4ebca8Smrg  # "Emit spaces for -MD").
344fb4ebca8Smrg  "$@" -MD -MF "$tmpdepfile"
345fb4ebca8Smrg  stat=$?
346fb4ebca8Smrg  if test $stat -ne 0; then
347fb4ebca8Smrg    rm -f "$tmpdepfile"
348fb4ebca8Smrg    exit $stat
34929459361Smrg  fi
350fb4ebca8Smrg  rm -f "$depfile"
351fb4ebca8Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
352fb4ebca8Smrg  # We have to change lines of the first kind to '$object: \'.
353fb4ebca8Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
354fb4ebca8Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
355fb4ebca8Smrg  # dummy dependency, to avoid the deleted-header problem.
356fb4ebca8Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35729459361Smrg  rm -f "$tmpdepfile"
35829459361Smrg  ;;
35929459361Smrg
360fb4ebca8Smrg## The order of this option in the case statement is important, since the
361fb4ebca8Smrg## shell code in configure will try each of these formats in the order
362fb4ebca8Smrg## listed in this file.  A plain '-MD' option would be understood by many
363fb4ebca8Smrg## compilers, so we must ensure this comes after the gcc and icc options.
364fb4ebca8Smrgpgcc)
365fb4ebca8Smrg  # Portland's C compiler understands '-MD'.
366fb4ebca8Smrg  # Will always output deps to 'file.d' where file is the root name of the
367fb4ebca8Smrg  # source file under compilation, even if file resides in a subdirectory.
368fb4ebca8Smrg  # The object file name does not affect the name of the '.d' file.
369fb4ebca8Smrg  # pgcc 10.2 will output
37029459361Smrg  #    foo.o: sub/foo.c sub/foo.h
371fb4ebca8Smrg  # and will wrap long lines using '\' :
37229459361Smrg  #    foo.o: sub/foo.c ... \
37329459361Smrg  #     sub/foo.h ... \
37429459361Smrg  #     ...
375fb4ebca8Smrg  set_dir_from "$object"
376fb4ebca8Smrg  # Use the source, not the object, to determine the base name, since
377fb4ebca8Smrg  # that's sadly what pgcc will do too.
378fb4ebca8Smrg  set_base_from "$source"
379fb4ebca8Smrg  tmpdepfile=$base.d
380fb4ebca8Smrg
381fb4ebca8Smrg  # For projects that build the same source file twice into different object
382fb4ebca8Smrg  # files, the pgcc approach of using the *source* file root name can cause
383fb4ebca8Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
384fb4ebca8Smrg  # the same $tmpdepfile.
385fb4ebca8Smrg  lockdir=$base.d-lock
386fb4ebca8Smrg  trap "
387fb4ebca8Smrg    echo '$0: caught signal, cleaning up...' >&2
388fb4ebca8Smrg    rmdir '$lockdir'
389fb4ebca8Smrg    exit 1
390fb4ebca8Smrg  " 1 2 13 15
391fb4ebca8Smrg  numtries=100
392fb4ebca8Smrg  i=$numtries
393fb4ebca8Smrg  while test $i -gt 0; do
394fb4ebca8Smrg    # mkdir is a portable test-and-set.
395fb4ebca8Smrg    if mkdir "$lockdir" 2>/dev/null; then
396fb4ebca8Smrg      # This process acquired the lock.
397fb4ebca8Smrg      "$@" -MD
398fb4ebca8Smrg      stat=$?
399fb4ebca8Smrg      # Release the lock.
400fb4ebca8Smrg      rmdir "$lockdir"
401fb4ebca8Smrg      break
402fb4ebca8Smrg    else
403fb4ebca8Smrg      # If the lock is being held by a different process, wait
404fb4ebca8Smrg      # until the winning process is done or we timeout.
405fb4ebca8Smrg      while test -d "$lockdir" && test $i -gt 0; do
406fb4ebca8Smrg        sleep 1
407fb4ebca8Smrg        i=`expr $i - 1`
408fb4ebca8Smrg      done
409fb4ebca8Smrg    fi
410fb4ebca8Smrg    i=`expr $i - 1`
411fb4ebca8Smrg  done
412fb4ebca8Smrg  trap - 1 2 13 15
413fb4ebca8Smrg  if test $i -le 0; then
414fb4ebca8Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
415fb4ebca8Smrg    echo "$0: check lockdir '$lockdir'" >&2
416fb4ebca8Smrg    exit 1
417fb4ebca8Smrg  fi
41829459361Smrg
419fb4ebca8Smrg  if test $stat -ne 0; then
42029459361Smrg    rm -f "$tmpdepfile"
42129459361Smrg    exit $stat
42229459361Smrg  fi
42329459361Smrg  rm -f "$depfile"
42429459361Smrg  # Each line is of the form `foo.o: dependent.h',
42529459361Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42629459361Smrg  # Do two passes, one to just change these to
42729459361Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42829459361Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42929459361Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
43029459361Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
431fb4ebca8Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
432fb4ebca8Smrg    | sed -e 's/$/ :/' >> "$depfile"
43329459361Smrg  rm -f "$tmpdepfile"
43429459361Smrg  ;;
43529459361Smrg
43647202d7bSmrghp2)
43747202d7bSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
43847202d7bSmrg  # compilers, which have integrated preprocessors.  The correct option
43947202d7bSmrg  # to use with these is +Maked; it writes dependencies to a file named
44047202d7bSmrg  # 'foo.d', which lands next to the object file, wherever that
44147202d7bSmrg  # happens to be.
44247202d7bSmrg  # Much of this is similar to the tru64 case; see comments there.
443fb4ebca8Smrg  set_dir_from  "$object"
444fb4ebca8Smrg  set_base_from "$object"
44547202d7bSmrg  if test "$libtool" = yes; then
44647202d7bSmrg    tmpdepfile1=$dir$base.d
44747202d7bSmrg    tmpdepfile2=$dir.libs/$base.d
44847202d7bSmrg    "$@" -Wc,+Maked
44947202d7bSmrg  else
45047202d7bSmrg    tmpdepfile1=$dir$base.d
45147202d7bSmrg    tmpdepfile2=$dir$base.d
45247202d7bSmrg    "$@" +Maked
45347202d7bSmrg  fi
45447202d7bSmrg  stat=$?
455fb4ebca8Smrg  if test $stat -ne 0; then
45647202d7bSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
45747202d7bSmrg     exit $stat
45847202d7bSmrg  fi
45947202d7bSmrg
46047202d7bSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
46147202d7bSmrg  do
46247202d7bSmrg    test -f "$tmpdepfile" && break
46347202d7bSmrg  done
46447202d7bSmrg  if test -f "$tmpdepfile"; then
465fb4ebca8Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
466fb4ebca8Smrg    # Add 'dependent.h:' lines.
46747202d7bSmrg    sed -ne '2,${
468fb4ebca8Smrg               s/^ *//
469fb4ebca8Smrg               s/ \\*$//
470fb4ebca8Smrg               s/$/:/
471fb4ebca8Smrg               p
472fb4ebca8Smrg             }' "$tmpdepfile" >> "$depfile"
47347202d7bSmrg  else
474fb4ebca8Smrg    make_dummy_depfile
47547202d7bSmrg  fi
47647202d7bSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
47747202d7bSmrg  ;;
47847202d7bSmrg
47929459361Smrgtru64)
480fb4ebca8Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
481fb4ebca8Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
482fb4ebca8Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
483fb4ebca8Smrg  # dependencies in 'foo.d' instead, so we check for that too.
484fb4ebca8Smrg  # Subdirectories are respected.
485fb4ebca8Smrg  set_dir_from  "$object"
486fb4ebca8Smrg  set_base_from "$object"
487fb4ebca8Smrg
488fb4ebca8Smrg  if test "$libtool" = yes; then
489fb4ebca8Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
490fb4ebca8Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
491fb4ebca8Smrg    # in $dir$base.o.d.  We have to check for both files, because
492fb4ebca8Smrg    # one of the two compilations can be disabled.  We should prefer
493fb4ebca8Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
494fb4ebca8Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
495fb4ebca8Smrg    # the former would cause a distcleancheck panic.
496fb4ebca8Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
497fb4ebca8Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
498fb4ebca8Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
499fb4ebca8Smrg    "$@" -Wc,-MD
500fb4ebca8Smrg  else
501fb4ebca8Smrg    tmpdepfile1=$dir$base.d
502fb4ebca8Smrg    tmpdepfile2=$dir$base.d
503fb4ebca8Smrg    tmpdepfile3=$dir$base.d
504fb4ebca8Smrg    "$@" -MD
505fb4ebca8Smrg  fi
506fb4ebca8Smrg
507fb4ebca8Smrg  stat=$?
508fb4ebca8Smrg  if test $stat -ne 0; then
509fb4ebca8Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
510fb4ebca8Smrg    exit $stat
511fb4ebca8Smrg  fi
512fb4ebca8Smrg
513fb4ebca8Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
514fb4ebca8Smrg  do
515fb4ebca8Smrg    test -f "$tmpdepfile" && break
516fb4ebca8Smrg  done
517fb4ebca8Smrg  # Same post-processing that is required for AIX mode.
518fb4ebca8Smrg  aix_post_process_depfile
519fb4ebca8Smrg  ;;
52029459361Smrg
5215dd2154eSmrgmsvc7)
5225dd2154eSmrg  if test "$libtool" = yes; then
5235dd2154eSmrg    showIncludes=-Wc,-showIncludes
5245dd2154eSmrg  else
5255dd2154eSmrg    showIncludes=-showIncludes
5265dd2154eSmrg  fi
5275dd2154eSmrg  "$@" $showIncludes > "$tmpdepfile"
5285dd2154eSmrg  stat=$?
5295dd2154eSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
530fb4ebca8Smrg  if test $stat -ne 0; then
5315dd2154eSmrg    rm -f "$tmpdepfile"
5325dd2154eSmrg    exit $stat
5335dd2154eSmrg  fi
5345dd2154eSmrg  rm -f "$depfile"
5355dd2154eSmrg  echo "$object : \\" > "$depfile"
5365dd2154eSmrg  # The first sed program below extracts the file names and escapes
5375dd2154eSmrg  # backslashes for cygpath.  The second sed program outputs the file
5385dd2154eSmrg  # name when reading, but also accumulates all include files in the
5395dd2154eSmrg  # hold buffer in order to output them again at the end.  This only
5405dd2154eSmrg  # works with sed implementations that can handle large buffers.
5415dd2154eSmrg  sed < "$tmpdepfile" -n '
5425dd2154eSmrg/^Note: including file:  *\(.*\)/ {
5435dd2154eSmrg  s//\1/
5445dd2154eSmrg  s/\\/\\\\/g
5455dd2154eSmrg  p
5465dd2154eSmrg}' | $cygpath_u | sort -u | sed -n '
5475dd2154eSmrgs/ /\\ /g
548fb4ebca8Smrgs/\(.*\)/'"$tab"'\1 \\/p
5495dd2154eSmrgs/.\(.*\) \\/\1:/
5505dd2154eSmrgH
5515dd2154eSmrg$ {
552fb4ebca8Smrg  s/.*/'"$tab"'/
5535dd2154eSmrg  G
5545dd2154eSmrg  p
5555dd2154eSmrg}' >> "$depfile"
556fb4ebca8Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5575dd2154eSmrg  rm -f "$tmpdepfile"
5585dd2154eSmrg  ;;
5595dd2154eSmrg
5605dd2154eSmrgmsvc7msys)
5615dd2154eSmrg  # This case exists only to let depend.m4 do its work.  It works by
5625dd2154eSmrg  # looking at the text of this script.  This case will never be run,
5635dd2154eSmrg  # since it is checked for above.
5645dd2154eSmrg  exit 1
5655dd2154eSmrg  ;;
5665dd2154eSmrg
56729459361Smrg#nosideeffect)
56829459361Smrg  # This comment above is used by automake to tell side-effect
56929459361Smrg  # dependency tracking mechanisms from slower ones.
57029459361Smrg
57129459361Smrgdashmstdout)
57229459361Smrg  # Important note: in order to support this mode, a compiler *must*
57329459361Smrg  # always write the preprocessed file to stdout, regardless of -o.
57429459361Smrg  "$@" || exit $?
57529459361Smrg
57629459361Smrg  # Remove the call to Libtool.
57729459361Smrg  if test "$libtool" = yes; then
57847202d7bSmrg    while test "X$1" != 'X--mode=compile'; do
57929459361Smrg      shift
58029459361Smrg    done
58129459361Smrg    shift
58229459361Smrg  fi
58329459361Smrg
584fb4ebca8Smrg  # Remove '-o $object'.
58529459361Smrg  IFS=" "
58629459361Smrg  for arg
58729459361Smrg  do
58829459361Smrg    case $arg in
58929459361Smrg    -o)
59029459361Smrg      shift
59129459361Smrg      ;;
59229459361Smrg    $object)
59329459361Smrg      shift
59429459361Smrg      ;;
59529459361Smrg    *)
59629459361Smrg      set fnord "$@" "$arg"
59729459361Smrg      shift # fnord
59829459361Smrg      shift # $arg
59929459361Smrg      ;;
60029459361Smrg    esac
60129459361Smrg  done
60229459361Smrg
60329459361Smrg  test -z "$dashmflag" && dashmflag=-M
604fb4ebca8Smrg  # Require at least two characters before searching for ':'
60529459361Smrg  # in the target name.  This is to cope with DOS-style filenames:
606fb4ebca8Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60729459361Smrg  "$@" $dashmflag |
608fb4ebca8Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60929459361Smrg  rm -f "$depfile"
61029459361Smrg  cat < "$tmpdepfile" > "$depfile"
611fb4ebca8Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
612fb4ebca8Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
613fb4ebca8Smrg  tr ' ' "$nl" < "$tmpdepfile" \
614fb4ebca8Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
615fb4ebca8Smrg    | sed -e 's/$/ :/' >> "$depfile"
61629459361Smrg  rm -f "$tmpdepfile"
61729459361Smrg  ;;
61829459361Smrg
61929459361SmrgdashXmstdout)
62029459361Smrg  # This case only exists to satisfy depend.m4.  It is never actually
62129459361Smrg  # run, as this mode is specially recognized in the preamble.
62229459361Smrg  exit 1
62329459361Smrg  ;;
62429459361Smrg
62529459361Smrgmakedepend)
62629459361Smrg  "$@" || exit $?
62729459361Smrg  # Remove any Libtool call
62829459361Smrg  if test "$libtool" = yes; then
62947202d7bSmrg    while test "X$1" != 'X--mode=compile'; do
63029459361Smrg      shift
63129459361Smrg    done
63229459361Smrg    shift
63329459361Smrg  fi
63429459361Smrg  # X makedepend
63529459361Smrg  shift
63647202d7bSmrg  cleared=no eat=no
63747202d7bSmrg  for arg
63847202d7bSmrg  do
63929459361Smrg    case $cleared in
64029459361Smrg    no)
64129459361Smrg      set ""; shift
64229459361Smrg      cleared=yes ;;
64329459361Smrg    esac
64447202d7bSmrg    if test $eat = yes; then
64547202d7bSmrg      eat=no
64647202d7bSmrg      continue
64747202d7bSmrg    fi
64829459361Smrg    case "$arg" in
64929459361Smrg    -D*|-I*)
65029459361Smrg      set fnord "$@" "$arg"; shift ;;
65129459361Smrg    # Strip any option that makedepend may not understand.  Remove
65229459361Smrg    # the object too, otherwise makedepend will parse it as a source file.
65347202d7bSmrg    -arch)
65447202d7bSmrg      eat=yes ;;
65529459361Smrg    -*|$object)
65629459361Smrg      ;;
65729459361Smrg    *)
65829459361Smrg      set fnord "$@" "$arg"; shift ;;
65929459361Smrg    esac
66029459361Smrg  done
66147202d7bSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66229459361Smrg  touch "$tmpdepfile"
66329459361Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66429459361Smrg  rm -f "$depfile"
6655dd2154eSmrg  # makedepend may prepend the VPATH from the source file name to the object.
6665dd2154eSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6675dd2154eSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
668fb4ebca8Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
669fb4ebca8Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
670fb4ebca8Smrg  sed '1,2d' "$tmpdepfile" \
671fb4ebca8Smrg    | tr ' ' "$nl" \
672fb4ebca8Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
673fb4ebca8Smrg    | sed -e 's/$/ :/' >> "$depfile"
67429459361Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67529459361Smrg  ;;
67629459361Smrg
67729459361Smrgcpp)
67829459361Smrg  # Important note: in order to support this mode, a compiler *must*
67929459361Smrg  # always write the preprocessed file to stdout.
68029459361Smrg  "$@" || exit $?
68129459361Smrg
68229459361Smrg  # Remove the call to Libtool.
68329459361Smrg  if test "$libtool" = yes; then
68447202d7bSmrg    while test "X$1" != 'X--mode=compile'; do
68529459361Smrg      shift
68629459361Smrg    done
68729459361Smrg    shift
68829459361Smrg  fi
68929459361Smrg
690fb4ebca8Smrg  # Remove '-o $object'.
69129459361Smrg  IFS=" "
69229459361Smrg  for arg
69329459361Smrg  do
69429459361Smrg    case $arg in
69529459361Smrg    -o)
69629459361Smrg      shift
69729459361Smrg      ;;
69829459361Smrg    $object)
69929459361Smrg      shift
70029459361Smrg      ;;
70129459361Smrg    *)
70229459361Smrg      set fnord "$@" "$arg"
70329459361Smrg      shift # fnord
70429459361Smrg      shift # $arg
70529459361Smrg      ;;
70629459361Smrg    esac
70729459361Smrg  done
70829459361Smrg
709fb4ebca8Smrg  "$@" -E \
710fb4ebca8Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711fb4ebca8Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
712fb4ebca8Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
71329459361Smrg  rm -f "$depfile"
71429459361Smrg  echo "$object : \\" > "$depfile"
71529459361Smrg  cat < "$tmpdepfile" >> "$depfile"
71629459361Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71729459361Smrg  rm -f "$tmpdepfile"
71829459361Smrg  ;;
71929459361Smrg
72029459361Smrgmsvisualcpp)
72129459361Smrg  # Important note: in order to support this mode, a compiler *must*
72247202d7bSmrg  # always write the preprocessed file to stdout.
72329459361Smrg  "$@" || exit $?
72447202d7bSmrg
72547202d7bSmrg  # Remove the call to Libtool.
72647202d7bSmrg  if test "$libtool" = yes; then
72747202d7bSmrg    while test "X$1" != 'X--mode=compile'; do
72847202d7bSmrg      shift
72947202d7bSmrg    done
73047202d7bSmrg    shift
73147202d7bSmrg  fi
73247202d7bSmrg
73329459361Smrg  IFS=" "
73429459361Smrg  for arg
73529459361Smrg  do
73629459361Smrg    case "$arg" in
73747202d7bSmrg    -o)
73847202d7bSmrg      shift
73947202d7bSmrg      ;;
74047202d7bSmrg    $object)
74147202d7bSmrg      shift
74247202d7bSmrg      ;;
74329459361Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
744fb4ebca8Smrg        set fnord "$@"
745fb4ebca8Smrg        shift
746fb4ebca8Smrg        shift
747fb4ebca8Smrg        ;;
74829459361Smrg    *)
749fb4ebca8Smrg        set fnord "$@" "$arg"
750fb4ebca8Smrg        shift
751fb4ebca8Smrg        shift
752fb4ebca8Smrg        ;;
75329459361Smrg    esac
75429459361Smrg  done
75547202d7bSmrg  "$@" -E 2>/dev/null |
75647202d7bSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75729459361Smrg  rm -f "$depfile"
75829459361Smrg  echo "$object : \\" > "$depfile"
759fb4ebca8Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
760fb4ebca8Smrg  echo "$tab" >> "$depfile"
76147202d7bSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76229459361Smrg  rm -f "$tmpdepfile"
76329459361Smrg  ;;
76429459361Smrg
76547202d7bSmrgmsvcmsys)
76647202d7bSmrg  # This case exists only to let depend.m4 do its work.  It works by
76747202d7bSmrg  # looking at the text of this script.  This case will never be run,
76847202d7bSmrg  # since it is checked for above.
76947202d7bSmrg  exit 1
77047202d7bSmrg  ;;
77147202d7bSmrg
77229459361Smrgnone)
77329459361Smrg  exec "$@"
77429459361Smrg  ;;
77529459361Smrg
77629459361Smrg*)
77729459361Smrg  echo "Unknown depmode $depmode" 1>&2
77829459361Smrg  exit 1
77929459361Smrg  ;;
78029459361Smrgesac
78129459361Smrg
78229459361Smrgexit 0
78329459361Smrg
78429459361Smrg# Local Variables:
78529459361Smrg# mode: shell-script
78629459361Smrg# sh-indentation: 2
787e24f450bSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
78829459361Smrg# time-stamp-start: "scriptversion="
78929459361Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
790fa2b3b63Smrg# time-stamp-time-zone: "UTC0"
79147202d7bSmrg# time-stamp-end: "; # UTC"
79229459361Smrg# End:
793