1100ae103Smrg#! /bin/sh
2100ae103Smrg# depcomp - compile a program generating dependencies as side-effects
3100ae103Smrg
40103645bSmrgscriptversion=2018-03-07.03; # UTC
5100ae103Smrg
60103645bSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
7100ae103Smrg
8100ae103Smrg# This program is free software; you can redistribute it and/or modify
9100ae103Smrg# it under the terms of the GNU General Public License as published by
10100ae103Smrg# the Free Software Foundation; either version 2, or (at your option)
11100ae103Smrg# any later version.
12100ae103Smrg
13100ae103Smrg# This program is distributed in the hope that it will be useful,
14100ae103Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15100ae103Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16100ae103Smrg# GNU General Public License for more details.
17100ae103Smrg
18100ae103Smrg# You should have received a copy of the GNU General Public License
190103645bSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20100ae103Smrg
21100ae103Smrg# As a special exception to the GNU General Public License, if you
22100ae103Smrg# distribute this file as part of a program that contains a
23100ae103Smrg# configuration script generated by Autoconf, you may include it under
24100ae103Smrg# the same distribution terms that you use for the rest of that program.
25100ae103Smrg
26100ae103Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27100ae103Smrg
28100ae103Smrgcase $1 in
29100ae103Smrg  '')
3095cf0c00Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
3195cf0c00Smrg    exit 1;
3295cf0c00Smrg    ;;
33100ae103Smrg  -h | --h*)
34100ae103Smrg    cat <<\EOF
35100ae103SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36100ae103Smrg
37100ae103SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38100ae103Smrgas side-effects.
39100ae103Smrg
40100ae103SmrgEnvironment variables:
41100ae103Smrg  depmode     Dependency tracking mode.
4295cf0c00Smrg  source      Source file read by 'PROGRAMS ARGS'.
4395cf0c00Smrg  object      Object file output by 'PROGRAMS ARGS'.
44100ae103Smrg  DEPDIR      directory where to store dependencies.
45100ae103Smrg  depfile     Dependency file to output.
468831d3fbSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
47100ae103Smrg  libtool     Whether libtool is used (yes/no).
48100ae103Smrg
49100ae103SmrgReport bugs to <bug-automake@gnu.org>.
50100ae103SmrgEOF
51100ae103Smrg    exit $?
52100ae103Smrg    ;;
53100ae103Smrg  -v | --v*)
54100ae103Smrg    echo "depcomp $scriptversion"
55100ae103Smrg    exit $?
56100ae103Smrg    ;;
57100ae103Smrgesac
58100ae103Smrg
5995cf0c00Smrg# Get the directory component of the given path, and save it in the
6095cf0c00Smrg# global variables '$dir'.  Note that this directory component will
6195cf0c00Smrg# be either empty or ending with a '/' character.  This is deliberate.
6295cf0c00Smrgset_dir_from ()
6395cf0c00Smrg{
6495cf0c00Smrg  case $1 in
6595cf0c00Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
6695cf0c00Smrg      *) dir=;;
6795cf0c00Smrg  esac
6895cf0c00Smrg}
6995cf0c00Smrg
7095cf0c00Smrg# Get the suffix-stripped basename of the given path, and save it the
7195cf0c00Smrg# global variable '$base'.
7295cf0c00Smrgset_base_from ()
7395cf0c00Smrg{
7495cf0c00Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
7595cf0c00Smrg}
7695cf0c00Smrg
7795cf0c00Smrg# If no dependency file was actually created by the compiler invocation,
7895cf0c00Smrg# we still have to create a dummy depfile, to avoid errors with the
7995cf0c00Smrg# Makefile "include basename.Plo" scheme.
8095cf0c00Smrgmake_dummy_depfile ()
8195cf0c00Smrg{
8295cf0c00Smrg  echo "#dummy" > "$depfile"
8395cf0c00Smrg}
8495cf0c00Smrg
8595cf0c00Smrg# Factor out some common post-processing of the generated depfile.
8695cf0c00Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
8795cf0c00Smrgaix_post_process_depfile ()
8895cf0c00Smrg{
8995cf0c00Smrg  # If the compiler actually managed to produce a dependency file,
9095cf0c00Smrg  # post-process it.
9195cf0c00Smrg  if test -f "$tmpdepfile"; then
9295cf0c00Smrg    # Each line is of the form 'foo.o: dependency.h'.
9395cf0c00Smrg    # Do two passes, one to just change these to
9495cf0c00Smrg    #   $object: dependency.h
9595cf0c00Smrg    # and one to simply output
9695cf0c00Smrg    #   dependency.h:
9795cf0c00Smrg    # which is needed to avoid the deleted-header problem.
9895cf0c00Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
9995cf0c00Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
10095cf0c00Smrg    } > "$depfile"
10195cf0c00Smrg    rm -f "$tmpdepfile"
10295cf0c00Smrg  else
10395cf0c00Smrg    make_dummy_depfile
10495cf0c00Smrg  fi
10595cf0c00Smrg}
10695cf0c00Smrg
10795cf0c00Smrg# A tabulation character.
10895cf0c00Smrgtab='	'
10995cf0c00Smrg# A newline character.
11095cf0c00Smrgnl='
11195cf0c00Smrg'
11295cf0c00Smrg# Character ranges might be problematic outside the C locale.
11395cf0c00Smrg# These definitions help.
11495cf0c00Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
11595cf0c00Smrglower=abcdefghijklmnopqrstuvwxyz
11695cf0c00Smrgdigits=0123456789
11795cf0c00Smrgalpha=${upper}${lower}
11895cf0c00Smrg
119100ae103Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120100ae103Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121100ae103Smrg  exit 1
122100ae103Smrgfi
123100ae103Smrg
124100ae103Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125100ae103Smrgdepfile=${depfile-`echo "$object" |
126100ae103Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127100ae103Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128100ae103Smrg
129100ae103Smrgrm -f "$tmpdepfile"
130100ae103Smrg
13195cf0c00Smrg# Avoid interferences from the environment.
13295cf0c00Smrggccflag= dashmflag=
13395cf0c00Smrg
134100ae103Smrg# Some modes work just like other modes, but use different flags.  We
135100ae103Smrg# parameterize here, but still list the modes in the big case below,
136100ae103Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137100ae103Smrg# here, because this file can only contain one case statement.
138100ae103Smrgif test "$depmode" = hp; then
139100ae103Smrg  # HP compiler uses -M and no extra arg.
140100ae103Smrg  gccflag=-M
141100ae103Smrg  depmode=gcc
142100ae103Smrgfi
143100ae103Smrg
144100ae103Smrgif test "$depmode" = dashXmstdout; then
14595cf0c00Smrg  # This is just like dashmstdout with a different argument.
14695cf0c00Smrg  dashmflag=-xM
14795cf0c00Smrg  depmode=dashmstdout
148100ae103Smrgfi
149100ae103Smrg
150165cb819Smrgcygpath_u="cygpath -u -f -"
151165cb819Smrgif test "$depmode" = msvcmsys; then
15295cf0c00Smrg  # This is just like msvisualcpp but w/o cygpath translation.
15395cf0c00Smrg  # Just convert the backslash-escaped backslashes to single forward
15495cf0c00Smrg  # slashes to satisfy depend.m4
15595cf0c00Smrg  cygpath_u='sed s,\\\\,/,g'
15695cf0c00Smrg  depmode=msvisualcpp
157165cb819Smrgfi
158165cb819Smrg
1598831d3fbSmrgif test "$depmode" = msvc7msys; then
16095cf0c00Smrg  # This is just like msvc7 but w/o cygpath translation.
16195cf0c00Smrg  # Just convert the backslash-escaped backslashes to single forward
16295cf0c00Smrg  # slashes to satisfy depend.m4
16395cf0c00Smrg  cygpath_u='sed s,\\\\,/,g'
16495cf0c00Smrg  depmode=msvc7
16595cf0c00Smrgfi
16695cf0c00Smrg
16795cf0c00Smrgif test "$depmode" = xlc; then
16895cf0c00Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
16995cf0c00Smrg  gccflag=-qmakedep=gcc,-MF
17095cf0c00Smrg  depmode=gcc
1718831d3fbSmrgfi
1728831d3fbSmrg
173100ae103Smrgcase "$depmode" in
174100ae103Smrggcc3)
175100ae103Smrg## gcc 3 implements dependency tracking that does exactly what
176100ae103Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177100ae103Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178165cb819Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179165cb819Smrg## the command line argument order; so add the flags where they
180165cb819Smrg## appear in depend2.am.  Note that the slowdown incurred here
181165cb819Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182165cb819Smrg  for arg
183165cb819Smrg  do
184165cb819Smrg    case $arg in
185165cb819Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186165cb819Smrg    *)  set fnord "$@" "$arg" ;;
187165cb819Smrg    esac
188165cb819Smrg    shift # fnord
189165cb819Smrg    shift # $arg
190165cb819Smrg  done
191165cb819Smrg  "$@"
192100ae103Smrg  stat=$?
19395cf0c00Smrg  if test $stat -ne 0; then
194100ae103Smrg    rm -f "$tmpdepfile"
195100ae103Smrg    exit $stat
196100ae103Smrg  fi
197100ae103Smrg  mv "$tmpdepfile" "$depfile"
198100ae103Smrg  ;;
199100ae103Smrg
200100ae103Smrggcc)
20195cf0c00Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
20295cf0c00Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
20395cf0c00Smrg## (see the conditional assignment to $gccflag above).
204100ae103Smrg## There are various ways to get dependency output from gcc.  Here's
205100ae103Smrg## why we pick this rather obscure method:
206100ae103Smrg## - Don't want to use -MD because we'd like the dependencies to end
207100ae103Smrg##   up in a subdir.  Having to rename by hand is ugly.
208100ae103Smrg##   (We might end up doing this anyway to support other compilers.)
209100ae103Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
21095cf0c00Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
21195cf0c00Smrg##   supported by the other compilers which use the 'gcc' depmode.
212100ae103Smrg## - Using -M directly means running the compiler twice (even worse
213100ae103Smrg##   than renaming).
214100ae103Smrg  if test -z "$gccflag"; then
215100ae103Smrg    gccflag=-MD,
216100ae103Smrg  fi
217100ae103Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
218100ae103Smrg  stat=$?
21995cf0c00Smrg  if test $stat -ne 0; then
220100ae103Smrg    rm -f "$tmpdepfile"
221100ae103Smrg    exit $stat
222100ae103Smrg  fi
223100ae103Smrg  rm -f "$depfile"
224100ae103Smrg  echo "$object : \\" > "$depfile"
22595cf0c00Smrg  # The second -e expression handles DOS-style file names with drive
22695cf0c00Smrg  # letters.
227100ae103Smrg  sed -e 's/^[^:]*: / /' \
228100ae103Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
22995cf0c00Smrg## This next piece of magic avoids the "deleted header file" problem.
230100ae103Smrg## The problem is that when a header file which appears in a .P file
231100ae103Smrg## is deleted, the dependency causes make to die (because there is
232100ae103Smrg## typically no way to rebuild the header).  We avoid this by adding
233100ae103Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234100ae103Smrg## this for us directly.
23595cf0c00Smrg## Some versions of gcc put a space before the ':'.  On the theory
236100ae103Smrg## that the space means something, we add a space to the output as
2378831d3fbSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2388831d3fbSmrg## to the object.  Take care to not repeat it in the output.
239100ae103Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
240100ae103Smrg## correctly.  Breaking it into two sed invocations is a workaround.
24195cf0c00Smrg  tr ' ' "$nl" < "$tmpdepfile" \
24295cf0c00Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
24395cf0c00Smrg    | sed -e 's/$/ :/' >> "$depfile"
244100ae103Smrg  rm -f "$tmpdepfile"
245100ae103Smrg  ;;
246100ae103Smrg
247100ae103Smrghp)
248100ae103Smrg  # This case exists only to let depend.m4 do its work.  It works by
249100ae103Smrg  # looking at the text of this script.  This case will never be run,
250100ae103Smrg  # since it is checked for above.
251100ae103Smrg  exit 1
252100ae103Smrg  ;;
253100ae103Smrg
254100ae103Smrgsgi)
255100ae103Smrg  if test "$libtool" = yes; then
256100ae103Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257100ae103Smrg  else
258100ae103Smrg    "$@" -MDupdate "$tmpdepfile"
259100ae103Smrg  fi
260100ae103Smrg  stat=$?
26195cf0c00Smrg  if test $stat -ne 0; then
262100ae103Smrg    rm -f "$tmpdepfile"
263100ae103Smrg    exit $stat
264100ae103Smrg  fi
265100ae103Smrg  rm -f "$depfile"
266100ae103Smrg
267100ae103Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268100ae103Smrg    echo "$object : \\" > "$depfile"
269100ae103Smrg    # Clip off the initial element (the dependent).  Don't try to be
270100ae103Smrg    # clever and replace this with sed code, as IRIX sed won't handle
271100ae103Smrg    # lines with more than a fixed number of characters (4096 in
272100ae103Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
27395cf0c00Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
274100ae103Smrg    # dependency line.
27595cf0c00Smrg    tr ' ' "$nl" < "$tmpdepfile" \
27695cf0c00Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
27795cf0c00Smrg      | tr "$nl" ' ' >> "$depfile"
278165cb819Smrg    echo >> "$depfile"
279100ae103Smrg    # The second pass generates a dummy entry for each header file.
28095cf0c00Smrg    tr ' ' "$nl" < "$tmpdepfile" \
28195cf0c00Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
28295cf0c00Smrg      >> "$depfile"
283100ae103Smrg  else
28495cf0c00Smrg    make_dummy_depfile
285100ae103Smrg  fi
286100ae103Smrg  rm -f "$tmpdepfile"
287100ae103Smrg  ;;
288100ae103Smrg
28995cf0c00Smrgxlc)
29095cf0c00Smrg  # This case exists only to let depend.m4 do its work.  It works by
29195cf0c00Smrg  # looking at the text of this script.  This case will never be run,
29295cf0c00Smrg  # since it is checked for above.
29395cf0c00Smrg  exit 1
29495cf0c00Smrg  ;;
29595cf0c00Smrg
296100ae103Smrgaix)
297100ae103Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
298100ae103Smrg  # in a .u file.  In older versions, this file always lives in the
29995cf0c00Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300100ae103Smrg  # start of each line; $object doesn't have directory information.
301100ae103Smrg  # Version 6 uses the directory in both cases.
30295cf0c00Smrg  set_dir_from "$object"
30395cf0c00Smrg  set_base_from "$object"
304100ae103Smrg  if test "$libtool" = yes; then
305165cb819Smrg    tmpdepfile1=$dir$base.u
306165cb819Smrg    tmpdepfile2=$base.u
307165cb819Smrg    tmpdepfile3=$dir.libs/$base.u
308100ae103Smrg    "$@" -Wc,-M
309100ae103Smrg  else
310165cb819Smrg    tmpdepfile1=$dir$base.u
311165cb819Smrg    tmpdepfile2=$dir$base.u
312165cb819Smrg    tmpdepfile3=$dir$base.u
313100ae103Smrg    "$@" -M
314100ae103Smrg  fi
315100ae103Smrg  stat=$?
31695cf0c00Smrg  if test $stat -ne 0; then
317165cb819Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318100ae103Smrg    exit $stat
319100ae103Smrg  fi
320100ae103Smrg
321165cb819Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322165cb819Smrg  do
323165cb819Smrg    test -f "$tmpdepfile" && break
324165cb819Smrg  done
32595cf0c00Smrg  aix_post_process_depfile
32695cf0c00Smrg  ;;
32795cf0c00Smrg
32895cf0c00Smrgtcc)
32995cf0c00Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
33095cf0c00Smrg  # FIXME: That version still under development at the moment of writing.
33195cf0c00Smrg  #        Make that this statement remains true also for stable, released
33295cf0c00Smrg  #        versions.
33395cf0c00Smrg  # It will wrap lines (doesn't matter whether long or short) with a
33495cf0c00Smrg  # trailing '\', as in:
33595cf0c00Smrg  #
33695cf0c00Smrg  #   foo.o : \
33795cf0c00Smrg  #    foo.c \
33895cf0c00Smrg  #    foo.h \
33995cf0c00Smrg  #
34095cf0c00Smrg  # It will put a trailing '\' even on the last line, and will use leading
34195cf0c00Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
34295cf0c00Smrg  # "Emit spaces for -MD").
34395cf0c00Smrg  "$@" -MD -MF "$tmpdepfile"
34495cf0c00Smrg  stat=$?
34595cf0c00Smrg  if test $stat -ne 0; then
34695cf0c00Smrg    rm -f "$tmpdepfile"
34795cf0c00Smrg    exit $stat
348100ae103Smrg  fi
34995cf0c00Smrg  rm -f "$depfile"
35095cf0c00Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
35195cf0c00Smrg  # We have to change lines of the first kind to '$object: \'.
35295cf0c00Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
35395cf0c00Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
35495cf0c00Smrg  # dummy dependency, to avoid the deleted-header problem.
35595cf0c00Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356100ae103Smrg  rm -f "$tmpdepfile"
357100ae103Smrg  ;;
358100ae103Smrg
35995cf0c00Smrg## The order of this option in the case statement is important, since the
36095cf0c00Smrg## shell code in configure will try each of these formats in the order
36195cf0c00Smrg## listed in this file.  A plain '-MD' option would be understood by many
36295cf0c00Smrg## compilers, so we must ensure this comes after the gcc and icc options.
36395cf0c00Smrgpgcc)
36495cf0c00Smrg  # Portland's C compiler understands '-MD'.
36595cf0c00Smrg  # Will always output deps to 'file.d' where file is the root name of the
36695cf0c00Smrg  # source file under compilation, even if file resides in a subdirectory.
36795cf0c00Smrg  # The object file name does not affect the name of the '.d' file.
36895cf0c00Smrg  # pgcc 10.2 will output
369100ae103Smrg  #    foo.o: sub/foo.c sub/foo.h
37095cf0c00Smrg  # and will wrap long lines using '\' :
371100ae103Smrg  #    foo.o: sub/foo.c ... \
372100ae103Smrg  #     sub/foo.h ... \
373100ae103Smrg  #     ...
37495cf0c00Smrg  set_dir_from "$object"
37595cf0c00Smrg  # Use the source, not the object, to determine the base name, since
37695cf0c00Smrg  # that's sadly what pgcc will do too.
37795cf0c00Smrg  set_base_from "$source"
37895cf0c00Smrg  tmpdepfile=$base.d
37995cf0c00Smrg
38095cf0c00Smrg  # For projects that build the same source file twice into different object
38195cf0c00Smrg  # files, the pgcc approach of using the *source* file root name can cause
38295cf0c00Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
38395cf0c00Smrg  # the same $tmpdepfile.
38495cf0c00Smrg  lockdir=$base.d-lock
38595cf0c00Smrg  trap "
38695cf0c00Smrg    echo '$0: caught signal, cleaning up...' >&2
38795cf0c00Smrg    rmdir '$lockdir'
38895cf0c00Smrg    exit 1
38995cf0c00Smrg  " 1 2 13 15
39095cf0c00Smrg  numtries=100
39195cf0c00Smrg  i=$numtries
39295cf0c00Smrg  while test $i -gt 0; do
39395cf0c00Smrg    # mkdir is a portable test-and-set.
39495cf0c00Smrg    if mkdir "$lockdir" 2>/dev/null; then
39595cf0c00Smrg      # This process acquired the lock.
39695cf0c00Smrg      "$@" -MD
39795cf0c00Smrg      stat=$?
39895cf0c00Smrg      # Release the lock.
39995cf0c00Smrg      rmdir "$lockdir"
40095cf0c00Smrg      break
40195cf0c00Smrg    else
40295cf0c00Smrg      # If the lock is being held by a different process, wait
40395cf0c00Smrg      # until the winning process is done or we timeout.
40495cf0c00Smrg      while test -d "$lockdir" && test $i -gt 0; do
40595cf0c00Smrg        sleep 1
40695cf0c00Smrg        i=`expr $i - 1`
40795cf0c00Smrg      done
40895cf0c00Smrg    fi
40995cf0c00Smrg    i=`expr $i - 1`
41095cf0c00Smrg  done
41195cf0c00Smrg  trap - 1 2 13 15
41295cf0c00Smrg  if test $i -le 0; then
41395cf0c00Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
41495cf0c00Smrg    echo "$0: check lockdir '$lockdir'" >&2
41595cf0c00Smrg    exit 1
41695cf0c00Smrg  fi
417100ae103Smrg
41895cf0c00Smrg  if test $stat -ne 0; then
419100ae103Smrg    rm -f "$tmpdepfile"
420100ae103Smrg    exit $stat
421100ae103Smrg  fi
422100ae103Smrg  rm -f "$depfile"
423100ae103Smrg  # Each line is of the form `foo.o: dependent.h',
424100ae103Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425100ae103Smrg  # Do two passes, one to just change these to
426100ae103Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427100ae103Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428100ae103Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429100ae103Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
43095cf0c00Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
43195cf0c00Smrg    | sed -e 's/$/ :/' >> "$depfile"
432100ae103Smrg  rm -f "$tmpdepfile"
433100ae103Smrg  ;;
434100ae103Smrg
435165cb819Smrghp2)
436165cb819Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437165cb819Smrg  # compilers, which have integrated preprocessors.  The correct option
438165cb819Smrg  # to use with these is +Maked; it writes dependencies to a file named
439165cb819Smrg  # 'foo.d', which lands next to the object file, wherever that
440165cb819Smrg  # happens to be.
441165cb819Smrg  # Much of this is similar to the tru64 case; see comments there.
44295cf0c00Smrg  set_dir_from  "$object"
44395cf0c00Smrg  set_base_from "$object"
444165cb819Smrg  if test "$libtool" = yes; then
445165cb819Smrg    tmpdepfile1=$dir$base.d
446165cb819Smrg    tmpdepfile2=$dir.libs/$base.d
447165cb819Smrg    "$@" -Wc,+Maked
448165cb819Smrg  else
449165cb819Smrg    tmpdepfile1=$dir$base.d
450165cb819Smrg    tmpdepfile2=$dir$base.d
451165cb819Smrg    "$@" +Maked
452165cb819Smrg  fi
453165cb819Smrg  stat=$?
45495cf0c00Smrg  if test $stat -ne 0; then
455165cb819Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456165cb819Smrg     exit $stat
457165cb819Smrg  fi
458165cb819Smrg
459165cb819Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460165cb819Smrg  do
461165cb819Smrg    test -f "$tmpdepfile" && break
462165cb819Smrg  done
463165cb819Smrg  if test -f "$tmpdepfile"; then
46495cf0c00Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
46595cf0c00Smrg    # Add 'dependent.h:' lines.
466165cb819Smrg    sed -ne '2,${
46795cf0c00Smrg               s/^ *//
46895cf0c00Smrg               s/ \\*$//
46995cf0c00Smrg               s/$/:/
47095cf0c00Smrg               p
47195cf0c00Smrg             }' "$tmpdepfile" >> "$depfile"
472165cb819Smrg  else
47395cf0c00Smrg    make_dummy_depfile
474165cb819Smrg  fi
475165cb819Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476165cb819Smrg  ;;
477165cb819Smrg
478100ae103Smrgtru64)
47995cf0c00Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
48095cf0c00Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
48195cf0c00Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
48295cf0c00Smrg  # dependencies in 'foo.d' instead, so we check for that too.
48395cf0c00Smrg  # Subdirectories are respected.
48495cf0c00Smrg  set_dir_from  "$object"
48595cf0c00Smrg  set_base_from "$object"
48695cf0c00Smrg
48795cf0c00Smrg  if test "$libtool" = yes; then
48895cf0c00Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
48995cf0c00Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
49095cf0c00Smrg    # in $dir$base.o.d.  We have to check for both files, because
49195cf0c00Smrg    # one of the two compilations can be disabled.  We should prefer
49295cf0c00Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
49395cf0c00Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
49495cf0c00Smrg    # the former would cause a distcleancheck panic.
49595cf0c00Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
49695cf0c00Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
49795cf0c00Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
49895cf0c00Smrg    "$@" -Wc,-MD
49995cf0c00Smrg  else
50095cf0c00Smrg    tmpdepfile1=$dir$base.d
50195cf0c00Smrg    tmpdepfile2=$dir$base.d
50295cf0c00Smrg    tmpdepfile3=$dir$base.d
50395cf0c00Smrg    "$@" -MD
50495cf0c00Smrg  fi
50595cf0c00Smrg
50695cf0c00Smrg  stat=$?
50795cf0c00Smrg  if test $stat -ne 0; then
50895cf0c00Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
50995cf0c00Smrg    exit $stat
51095cf0c00Smrg  fi
51195cf0c00Smrg
51295cf0c00Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
51395cf0c00Smrg  do
51495cf0c00Smrg    test -f "$tmpdepfile" && break
51595cf0c00Smrg  done
51695cf0c00Smrg  # Same post-processing that is required for AIX mode.
51795cf0c00Smrg  aix_post_process_depfile
51895cf0c00Smrg  ;;
519100ae103Smrg
5208831d3fbSmrgmsvc7)
5218831d3fbSmrg  if test "$libtool" = yes; then
5228831d3fbSmrg    showIncludes=-Wc,-showIncludes
5238831d3fbSmrg  else
5248831d3fbSmrg    showIncludes=-showIncludes
5258831d3fbSmrg  fi
5268831d3fbSmrg  "$@" $showIncludes > "$tmpdepfile"
5278831d3fbSmrg  stat=$?
5288831d3fbSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
52995cf0c00Smrg  if test $stat -ne 0; then
5308831d3fbSmrg    rm -f "$tmpdepfile"
5318831d3fbSmrg    exit $stat
5328831d3fbSmrg  fi
5338831d3fbSmrg  rm -f "$depfile"
5348831d3fbSmrg  echo "$object : \\" > "$depfile"
5358831d3fbSmrg  # The first sed program below extracts the file names and escapes
5368831d3fbSmrg  # backslashes for cygpath.  The second sed program outputs the file
5378831d3fbSmrg  # name when reading, but also accumulates all include files in the
5388831d3fbSmrg  # hold buffer in order to output them again at the end.  This only
5398831d3fbSmrg  # works with sed implementations that can handle large buffers.
5408831d3fbSmrg  sed < "$tmpdepfile" -n '
5418831d3fbSmrg/^Note: including file:  *\(.*\)/ {
5428831d3fbSmrg  s//\1/
5438831d3fbSmrg  s/\\/\\\\/g
5448831d3fbSmrg  p
5458831d3fbSmrg}' | $cygpath_u | sort -u | sed -n '
5468831d3fbSmrgs/ /\\ /g
54795cf0c00Smrgs/\(.*\)/'"$tab"'\1 \\/p
5488831d3fbSmrgs/.\(.*\) \\/\1:/
5498831d3fbSmrgH
5508831d3fbSmrg$ {
55195cf0c00Smrg  s/.*/'"$tab"'/
5528831d3fbSmrg  G
5538831d3fbSmrg  p
5548831d3fbSmrg}' >> "$depfile"
55595cf0c00Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5568831d3fbSmrg  rm -f "$tmpdepfile"
5578831d3fbSmrg  ;;
5588831d3fbSmrg
5598831d3fbSmrgmsvc7msys)
5608831d3fbSmrg  # This case exists only to let depend.m4 do its work.  It works by
5618831d3fbSmrg  # looking at the text of this script.  This case will never be run,
5628831d3fbSmrg  # since it is checked for above.
5638831d3fbSmrg  exit 1
5648831d3fbSmrg  ;;
5658831d3fbSmrg
566100ae103Smrg#nosideeffect)
567100ae103Smrg  # This comment above is used by automake to tell side-effect
568100ae103Smrg  # dependency tracking mechanisms from slower ones.
569100ae103Smrg
570100ae103Smrgdashmstdout)
571100ae103Smrg  # Important note: in order to support this mode, a compiler *must*
572100ae103Smrg  # always write the preprocessed file to stdout, regardless of -o.
573100ae103Smrg  "$@" || exit $?
574100ae103Smrg
575100ae103Smrg  # Remove the call to Libtool.
576100ae103Smrg  if test "$libtool" = yes; then
577165cb819Smrg    while test "X$1" != 'X--mode=compile'; do
578100ae103Smrg      shift
579100ae103Smrg    done
580100ae103Smrg    shift
581100ae103Smrg  fi
582100ae103Smrg
58395cf0c00Smrg  # Remove '-o $object'.
584100ae103Smrg  IFS=" "
585100ae103Smrg  for arg
586100ae103Smrg  do
587100ae103Smrg    case $arg in
588100ae103Smrg    -o)
589100ae103Smrg      shift
590100ae103Smrg      ;;
591100ae103Smrg    $object)
592100ae103Smrg      shift
593100ae103Smrg      ;;
594100ae103Smrg    *)
595100ae103Smrg      set fnord "$@" "$arg"
596100ae103Smrg      shift # fnord
597100ae103Smrg      shift # $arg
598100ae103Smrg      ;;
599100ae103Smrg    esac
600100ae103Smrg  done
601100ae103Smrg
602100ae103Smrg  test -z "$dashmflag" && dashmflag=-M
60395cf0c00Smrg  # Require at least two characters before searching for ':'
604100ae103Smrg  # in the target name.  This is to cope with DOS-style filenames:
60595cf0c00Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606100ae103Smrg  "$@" $dashmflag |
60795cf0c00Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608100ae103Smrg  rm -f "$depfile"
609100ae103Smrg  cat < "$tmpdepfile" > "$depfile"
61095cf0c00Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
61195cf0c00Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
61295cf0c00Smrg  tr ' ' "$nl" < "$tmpdepfile" \
61395cf0c00Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
61495cf0c00Smrg    | sed -e 's/$/ :/' >> "$depfile"
615100ae103Smrg  rm -f "$tmpdepfile"
616100ae103Smrg  ;;
617100ae103Smrg
618100ae103SmrgdashXmstdout)
619100ae103Smrg  # This case only exists to satisfy depend.m4.  It is never actually
620100ae103Smrg  # run, as this mode is specially recognized in the preamble.
621100ae103Smrg  exit 1
622100ae103Smrg  ;;
623100ae103Smrg
624100ae103Smrgmakedepend)
625100ae103Smrg  "$@" || exit $?
626100ae103Smrg  # Remove any Libtool call
627100ae103Smrg  if test "$libtool" = yes; then
628165cb819Smrg    while test "X$1" != 'X--mode=compile'; do
629100ae103Smrg      shift
630100ae103Smrg    done
631100ae103Smrg    shift
632100ae103Smrg  fi
633100ae103Smrg  # X makedepend
634100ae103Smrg  shift
635165cb819Smrg  cleared=no eat=no
636165cb819Smrg  for arg
637165cb819Smrg  do
638100ae103Smrg    case $cleared in
639100ae103Smrg    no)
640100ae103Smrg      set ""; shift
641100ae103Smrg      cleared=yes ;;
642100ae103Smrg    esac
643165cb819Smrg    if test $eat = yes; then
644165cb819Smrg      eat=no
645165cb819Smrg      continue
646165cb819Smrg    fi
647100ae103Smrg    case "$arg" in
648100ae103Smrg    -D*|-I*)
649100ae103Smrg      set fnord "$@" "$arg"; shift ;;
650100ae103Smrg    # Strip any option that makedepend may not understand.  Remove
651100ae103Smrg    # the object too, otherwise makedepend will parse it as a source file.
652165cb819Smrg    -arch)
653165cb819Smrg      eat=yes ;;
654100ae103Smrg    -*|$object)
655100ae103Smrg      ;;
656100ae103Smrg    *)
657100ae103Smrg      set fnord "$@" "$arg"; shift ;;
658100ae103Smrg    esac
659100ae103Smrg  done
660165cb819Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661100ae103Smrg  touch "$tmpdepfile"
662100ae103Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663100ae103Smrg  rm -f "$depfile"
6648831d3fbSmrg  # makedepend may prepend the VPATH from the source file name to the object.
6658831d3fbSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6668831d3fbSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
66795cf0c00Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
66895cf0c00Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
66995cf0c00Smrg  sed '1,2d' "$tmpdepfile" \
67095cf0c00Smrg    | tr ' ' "$nl" \
67195cf0c00Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
67295cf0c00Smrg    | sed -e 's/$/ :/' >> "$depfile"
673100ae103Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674100ae103Smrg  ;;
675100ae103Smrg
676100ae103Smrgcpp)
677100ae103Smrg  # Important note: in order to support this mode, a compiler *must*
678100ae103Smrg  # always write the preprocessed file to stdout.
679100ae103Smrg  "$@" || exit $?
680100ae103Smrg
681100ae103Smrg  # Remove the call to Libtool.
682100ae103Smrg  if test "$libtool" = yes; then
683165cb819Smrg    while test "X$1" != 'X--mode=compile'; do
684100ae103Smrg      shift
685100ae103Smrg    done
686100ae103Smrg    shift
687100ae103Smrg  fi
688100ae103Smrg
68995cf0c00Smrg  # Remove '-o $object'.
690100ae103Smrg  IFS=" "
691100ae103Smrg  for arg
692100ae103Smrg  do
693100ae103Smrg    case $arg in
694100ae103Smrg    -o)
695100ae103Smrg      shift
696100ae103Smrg      ;;
697100ae103Smrg    $object)
698100ae103Smrg      shift
699100ae103Smrg      ;;
700100ae103Smrg    *)
701100ae103Smrg      set fnord "$@" "$arg"
702100ae103Smrg      shift # fnord
703100ae103Smrg      shift # $arg
704100ae103Smrg      ;;
705100ae103Smrg    esac
706100ae103Smrg  done
707100ae103Smrg
70895cf0c00Smrg  "$@" -E \
70995cf0c00Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71095cf0c00Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71195cf0c00Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
712100ae103Smrg  rm -f "$depfile"
713100ae103Smrg  echo "$object : \\" > "$depfile"
714100ae103Smrg  cat < "$tmpdepfile" >> "$depfile"
715100ae103Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716100ae103Smrg  rm -f "$tmpdepfile"
717100ae103Smrg  ;;
718100ae103Smrg
719100ae103Smrgmsvisualcpp)
720100ae103Smrg  # Important note: in order to support this mode, a compiler *must*
721165cb819Smrg  # always write the preprocessed file to stdout.
722100ae103Smrg  "$@" || exit $?
723165cb819Smrg
724165cb819Smrg  # Remove the call to Libtool.
725165cb819Smrg  if test "$libtool" = yes; then
726165cb819Smrg    while test "X$1" != 'X--mode=compile'; do
727165cb819Smrg      shift
728165cb819Smrg    done
729165cb819Smrg    shift
730165cb819Smrg  fi
731165cb819Smrg
732100ae103Smrg  IFS=" "
733100ae103Smrg  for arg
734100ae103Smrg  do
735100ae103Smrg    case "$arg" in
736165cb819Smrg    -o)
737165cb819Smrg      shift
738165cb819Smrg      ;;
739165cb819Smrg    $object)
740165cb819Smrg      shift
741165cb819Smrg      ;;
742100ae103Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
74395cf0c00Smrg        set fnord "$@"
74495cf0c00Smrg        shift
74595cf0c00Smrg        shift
74695cf0c00Smrg        ;;
747100ae103Smrg    *)
74895cf0c00Smrg        set fnord "$@" "$arg"
74995cf0c00Smrg        shift
75095cf0c00Smrg        shift
75195cf0c00Smrg        ;;
752100ae103Smrg    esac
753100ae103Smrg  done
754165cb819Smrg  "$@" -E 2>/dev/null |
755165cb819Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756100ae103Smrg  rm -f "$depfile"
757100ae103Smrg  echo "$object : \\" > "$depfile"
75895cf0c00Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
75995cf0c00Smrg  echo "$tab" >> "$depfile"
760165cb819Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761100ae103Smrg  rm -f "$tmpdepfile"
762100ae103Smrg  ;;
763100ae103Smrg
764165cb819Smrgmsvcmsys)
765165cb819Smrg  # This case exists only to let depend.m4 do its work.  It works by
766165cb819Smrg  # looking at the text of this script.  This case will never be run,
767165cb819Smrg  # since it is checked for above.
768165cb819Smrg  exit 1
769165cb819Smrg  ;;
770165cb819Smrg
771100ae103Smrgnone)
772100ae103Smrg  exec "$@"
773100ae103Smrg  ;;
774100ae103Smrg
775100ae103Smrg*)
776100ae103Smrg  echo "Unknown depmode $depmode" 1>&2
777100ae103Smrg  exit 1
778100ae103Smrg  ;;
779100ae103Smrgesac
780100ae103Smrg
781100ae103Smrgexit 0
782100ae103Smrg
783100ae103Smrg# Local Variables:
784100ae103Smrg# mode: shell-script
785100ae103Smrg# sh-indentation: 2
7860103645bSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
787100ae103Smrg# time-stamp-start: "scriptversion="
788100ae103Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7890103645bSmrg# time-stamp-time-zone: "UTC0"
790165cb819Smrg# time-stamp-end: "; # UTC"
791100ae103Smrg# End:
792