109885543Smrg#! /bin/sh
209885543Smrg# depcomp - compile a program generating dependencies as side-effects
309885543Smrg
4beef1b22Smrgscriptversion=2018-03-07.03; # UTC
509885543Smrg
6beef1b22Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
709885543Smrg
809885543Smrg# This program is free software; you can redistribute it and/or modify
909885543Smrg# it under the terms of the GNU General Public License as published by
1009885543Smrg# the Free Software Foundation; either version 2, or (at your option)
1109885543Smrg# any later version.
1209885543Smrg
1309885543Smrg# This program is distributed in the hope that it will be useful,
1409885543Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1509885543Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1609885543Smrg# GNU General Public License for more details.
1709885543Smrg
1809885543Smrg# You should have received a copy of the GNU General Public License
19beef1b22Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2009885543Smrg
2109885543Smrg# As a special exception to the GNU General Public License, if you
2209885543Smrg# distribute this file as part of a program that contains a
2309885543Smrg# configuration script generated by Autoconf, you may include it under
2409885543Smrg# the same distribution terms that you use for the rest of that program.
2509885543Smrg
2609885543Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2709885543Smrg
2809885543Smrgcase $1 in
2909885543Smrg  '')
30df9ffc95Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31df9ffc95Smrg    exit 1;
32df9ffc95Smrg    ;;
3309885543Smrg  -h | --h*)
3409885543Smrg    cat <<\EOF
3509885543SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3609885543Smrg
3709885543SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3809885543Smrgas side-effects.
3909885543Smrg
4009885543SmrgEnvironment variables:
4109885543Smrg  depmode     Dependency tracking mode.
42df9ffc95Smrg  source      Source file read by 'PROGRAMS ARGS'.
43df9ffc95Smrg  object      Object file output by 'PROGRAMS ARGS'.
4409885543Smrg  DEPDIR      directory where to store dependencies.
4509885543Smrg  depfile     Dependency file to output.
46b12e5c03Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
4709885543Smrg  libtool     Whether libtool is used (yes/no).
4809885543Smrg
4909885543SmrgReport bugs to <bug-automake@gnu.org>.
5009885543SmrgEOF
5109885543Smrg    exit $?
5209885543Smrg    ;;
5309885543Smrg  -v | --v*)
5409885543Smrg    echo "depcomp $scriptversion"
5509885543Smrg    exit $?
5609885543Smrg    ;;
5709885543Smrgesac
5809885543Smrg
59df9ffc95Smrg# Get the directory component of the given path, and save it in the
60df9ffc95Smrg# global variables '$dir'.  Note that this directory component will
61df9ffc95Smrg# be either empty or ending with a '/' character.  This is deliberate.
62df9ffc95Smrgset_dir_from ()
63df9ffc95Smrg{
64df9ffc95Smrg  case $1 in
65df9ffc95Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66df9ffc95Smrg      *) dir=;;
67df9ffc95Smrg  esac
68df9ffc95Smrg}
69df9ffc95Smrg
70df9ffc95Smrg# Get the suffix-stripped basename of the given path, and save it the
71df9ffc95Smrg# global variable '$base'.
72df9ffc95Smrgset_base_from ()
73df9ffc95Smrg{
74df9ffc95Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75df9ffc95Smrg}
76df9ffc95Smrg
77df9ffc95Smrg# If no dependency file was actually created by the compiler invocation,
78df9ffc95Smrg# we still have to create a dummy depfile, to avoid errors with the
79df9ffc95Smrg# Makefile "include basename.Plo" scheme.
80df9ffc95Smrgmake_dummy_depfile ()
81df9ffc95Smrg{
82df9ffc95Smrg  echo "#dummy" > "$depfile"
83df9ffc95Smrg}
84df9ffc95Smrg
85df9ffc95Smrg# Factor out some common post-processing of the generated depfile.
86df9ffc95Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87df9ffc95Smrgaix_post_process_depfile ()
88df9ffc95Smrg{
89df9ffc95Smrg  # If the compiler actually managed to produce a dependency file,
90df9ffc95Smrg  # post-process it.
91df9ffc95Smrg  if test -f "$tmpdepfile"; then
92df9ffc95Smrg    # Each line is of the form 'foo.o: dependency.h'.
93df9ffc95Smrg    # Do two passes, one to just change these to
94df9ffc95Smrg    #   $object: dependency.h
95df9ffc95Smrg    # and one to simply output
96df9ffc95Smrg    #   dependency.h:
97df9ffc95Smrg    # which is needed to avoid the deleted-header problem.
98df9ffc95Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99df9ffc95Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100df9ffc95Smrg    } > "$depfile"
101df9ffc95Smrg    rm -f "$tmpdepfile"
102df9ffc95Smrg  else
103df9ffc95Smrg    make_dummy_depfile
104df9ffc95Smrg  fi
105df9ffc95Smrg}
106df9ffc95Smrg
107df9ffc95Smrg# A tabulation character.
108df9ffc95Smrgtab='	'
109df9ffc95Smrg# A newline character.
110df9ffc95Smrgnl='
111df9ffc95Smrg'
112df9ffc95Smrg# Character ranges might be problematic outside the C locale.
113df9ffc95Smrg# These definitions help.
114df9ffc95Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115df9ffc95Smrglower=abcdefghijklmnopqrstuvwxyz
116df9ffc95Smrgdigits=0123456789
117df9ffc95Smrgalpha=${upper}${lower}
118df9ffc95Smrg
11909885543Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12009885543Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12109885543Smrg  exit 1
12209885543Smrgfi
12309885543Smrg
12409885543Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12509885543Smrgdepfile=${depfile-`echo "$object" |
12609885543Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12709885543Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12809885543Smrg
12909885543Smrgrm -f "$tmpdepfile"
13009885543Smrg
131df9ffc95Smrg# Avoid interferences from the environment.
132df9ffc95Smrggccflag= dashmflag=
133df9ffc95Smrg
13409885543Smrg# Some modes work just like other modes, but use different flags.  We
13509885543Smrg# parameterize here, but still list the modes in the big case below,
13609885543Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13709885543Smrg# here, because this file can only contain one case statement.
13809885543Smrgif test "$depmode" = hp; then
13909885543Smrg  # HP compiler uses -M and no extra arg.
14009885543Smrg  gccflag=-M
14109885543Smrg  depmode=gcc
14209885543Smrgfi
14309885543Smrg
14409885543Smrgif test "$depmode" = dashXmstdout; then
145df9ffc95Smrg  # This is just like dashmstdout with a different argument.
146df9ffc95Smrg  dashmflag=-xM
147df9ffc95Smrg  depmode=dashmstdout
14809885543Smrgfi
14909885543Smrg
150b698ba48Smrgcygpath_u="cygpath -u -f -"
151b698ba48Smrgif test "$depmode" = msvcmsys; then
152df9ffc95Smrg  # This is just like msvisualcpp but w/o cygpath translation.
153df9ffc95Smrg  # Just convert the backslash-escaped backslashes to single forward
154df9ffc95Smrg  # slashes to satisfy depend.m4
155df9ffc95Smrg  cygpath_u='sed s,\\\\,/,g'
156df9ffc95Smrg  depmode=msvisualcpp
157b698ba48Smrgfi
158b698ba48Smrg
159b12e5c03Smrgif test "$depmode" = msvc7msys; then
160df9ffc95Smrg  # This is just like msvc7 but w/o cygpath translation.
161df9ffc95Smrg  # Just convert the backslash-escaped backslashes to single forward
162df9ffc95Smrg  # slashes to satisfy depend.m4
163df9ffc95Smrg  cygpath_u='sed s,\\\\,/,g'
164df9ffc95Smrg  depmode=msvc7
165df9ffc95Smrgfi
166df9ffc95Smrg
167df9ffc95Smrgif test "$depmode" = xlc; then
168df9ffc95Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169df9ffc95Smrg  gccflag=-qmakedep=gcc,-MF
170df9ffc95Smrg  depmode=gcc
171b12e5c03Smrgfi
172b12e5c03Smrg
17309885543Smrgcase "$depmode" in
17409885543Smrggcc3)
17509885543Smrg## gcc 3 implements dependency tracking that does exactly what
17609885543Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17709885543Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1787104f784Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1797104f784Smrg## the command line argument order; so add the flags where they
1807104f784Smrg## appear in depend2.am.  Note that the slowdown incurred here
1817104f784Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1827104f784Smrg  for arg
1837104f784Smrg  do
1847104f784Smrg    case $arg in
1857104f784Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1867104f784Smrg    *)  set fnord "$@" "$arg" ;;
1877104f784Smrg    esac
1887104f784Smrg    shift # fnord
1897104f784Smrg    shift # $arg
1907104f784Smrg  done
1917104f784Smrg  "$@"
19209885543Smrg  stat=$?
193df9ffc95Smrg  if test $stat -ne 0; then
19409885543Smrg    rm -f "$tmpdepfile"
19509885543Smrg    exit $stat
19609885543Smrg  fi
19709885543Smrg  mv "$tmpdepfile" "$depfile"
19809885543Smrg  ;;
19909885543Smrg
20009885543Smrggcc)
201df9ffc95Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202df9ffc95Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203df9ffc95Smrg## (see the conditional assignment to $gccflag above).
20409885543Smrg## There are various ways to get dependency output from gcc.  Here's
20509885543Smrg## why we pick this rather obscure method:
20609885543Smrg## - Don't want to use -MD because we'd like the dependencies to end
20709885543Smrg##   up in a subdir.  Having to rename by hand is ugly.
20809885543Smrg##   (We might end up doing this anyway to support other compilers.)
20909885543Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210df9ffc95Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211df9ffc95Smrg##   supported by the other compilers which use the 'gcc' depmode.
21209885543Smrg## - Using -M directly means running the compiler twice (even worse
21309885543Smrg##   than renaming).
21409885543Smrg  if test -z "$gccflag"; then
21509885543Smrg    gccflag=-MD,
21609885543Smrg  fi
21709885543Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
21809885543Smrg  stat=$?
219df9ffc95Smrg  if test $stat -ne 0; then
22009885543Smrg    rm -f "$tmpdepfile"
22109885543Smrg    exit $stat
22209885543Smrg  fi
22309885543Smrg  rm -f "$depfile"
22409885543Smrg  echo "$object : \\" > "$depfile"
225df9ffc95Smrg  # The second -e expression handles DOS-style file names with drive
226df9ffc95Smrg  # letters.
22709885543Smrg  sed -e 's/^[^:]*: / /' \
22809885543Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229df9ffc95Smrg## This next piece of magic avoids the "deleted header file" problem.
23009885543Smrg## The problem is that when a header file which appears in a .P file
23109885543Smrg## is deleted, the dependency causes make to die (because there is
23209885543Smrg## typically no way to rebuild the header).  We avoid this by adding
23309885543Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23409885543Smrg## this for us directly.
235df9ffc95Smrg## Some versions of gcc put a space before the ':'.  On the theory
23609885543Smrg## that the space means something, we add a space to the output as
237b12e5c03Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238b12e5c03Smrg## to the object.  Take care to not repeat it in the output.
23909885543Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
24009885543Smrg## correctly.  Breaking it into two sed invocations is a workaround.
241df9ffc95Smrg  tr ' ' "$nl" < "$tmpdepfile" \
242df9ffc95Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243df9ffc95Smrg    | sed -e 's/$/ :/' >> "$depfile"
24409885543Smrg  rm -f "$tmpdepfile"
24509885543Smrg  ;;
24609885543Smrg
24709885543Smrghp)
24809885543Smrg  # This case exists only to let depend.m4 do its work.  It works by
24909885543Smrg  # looking at the text of this script.  This case will never be run,
25009885543Smrg  # since it is checked for above.
25109885543Smrg  exit 1
25209885543Smrg  ;;
25309885543Smrg
25409885543Smrgsgi)
25509885543Smrg  if test "$libtool" = yes; then
25609885543Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25709885543Smrg  else
25809885543Smrg    "$@" -MDupdate "$tmpdepfile"
25909885543Smrg  fi
26009885543Smrg  stat=$?
261df9ffc95Smrg  if test $stat -ne 0; then
26209885543Smrg    rm -f "$tmpdepfile"
26309885543Smrg    exit $stat
26409885543Smrg  fi
26509885543Smrg  rm -f "$depfile"
26609885543Smrg
26709885543Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26809885543Smrg    echo "$object : \\" > "$depfile"
26909885543Smrg    # Clip off the initial element (the dependent).  Don't try to be
27009885543Smrg    # clever and replace this with sed code, as IRIX sed won't handle
27109885543Smrg    # lines with more than a fixed number of characters (4096 in
27209885543Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273df9ffc95Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
27409885543Smrg    # dependency line.
275df9ffc95Smrg    tr ' ' "$nl" < "$tmpdepfile" \
276df9ffc95Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277df9ffc95Smrg      | tr "$nl" ' ' >> "$depfile"
278b698ba48Smrg    echo >> "$depfile"
27909885543Smrg    # The second pass generates a dummy entry for each header file.
280df9ffc95Smrg    tr ' ' "$nl" < "$tmpdepfile" \
281df9ffc95Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282df9ffc95Smrg      >> "$depfile"
28309885543Smrg  else
284df9ffc95Smrg    make_dummy_depfile
28509885543Smrg  fi
28609885543Smrg  rm -f "$tmpdepfile"
28709885543Smrg  ;;
28809885543Smrg
289df9ffc95Smrgxlc)
290df9ffc95Smrg  # This case exists only to let depend.m4 do its work.  It works by
291df9ffc95Smrg  # looking at the text of this script.  This case will never be run,
292df9ffc95Smrg  # since it is checked for above.
293df9ffc95Smrg  exit 1
294df9ffc95Smrg  ;;
295df9ffc95Smrg
29609885543Smrgaix)
29709885543Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
29809885543Smrg  # in a .u file.  In older versions, this file always lives in the
299df9ffc95Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30009885543Smrg  # start of each line; $object doesn't have directory information.
30109885543Smrg  # Version 6 uses the directory in both cases.
302df9ffc95Smrg  set_dir_from "$object"
303df9ffc95Smrg  set_base_from "$object"
30409885543Smrg  if test "$libtool" = yes; then
3057104f784Smrg    tmpdepfile1=$dir$base.u
3067104f784Smrg    tmpdepfile2=$base.u
3077104f784Smrg    tmpdepfile3=$dir.libs/$base.u
30809885543Smrg    "$@" -Wc,-M
30909885543Smrg  else
3107104f784Smrg    tmpdepfile1=$dir$base.u
3117104f784Smrg    tmpdepfile2=$dir$base.u
3127104f784Smrg    tmpdepfile3=$dir$base.u
31309885543Smrg    "$@" -M
31409885543Smrg  fi
31509885543Smrg  stat=$?
316df9ffc95Smrg  if test $stat -ne 0; then
3177104f784Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31809885543Smrg    exit $stat
31909885543Smrg  fi
32009885543Smrg
3217104f784Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3227104f784Smrg  do
3237104f784Smrg    test -f "$tmpdepfile" && break
3247104f784Smrg  done
325df9ffc95Smrg  aix_post_process_depfile
326df9ffc95Smrg  ;;
327df9ffc95Smrg
328df9ffc95Smrgtcc)
329df9ffc95Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330df9ffc95Smrg  # FIXME: That version still under development at the moment of writing.
331df9ffc95Smrg  #        Make that this statement remains true also for stable, released
332df9ffc95Smrg  #        versions.
333df9ffc95Smrg  # It will wrap lines (doesn't matter whether long or short) with a
334df9ffc95Smrg  # trailing '\', as in:
335df9ffc95Smrg  #
336df9ffc95Smrg  #   foo.o : \
337df9ffc95Smrg  #    foo.c \
338df9ffc95Smrg  #    foo.h \
339df9ffc95Smrg  #
340df9ffc95Smrg  # It will put a trailing '\' even on the last line, and will use leading
341df9ffc95Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342df9ffc95Smrg  # "Emit spaces for -MD").
343df9ffc95Smrg  "$@" -MD -MF "$tmpdepfile"
344df9ffc95Smrg  stat=$?
345df9ffc95Smrg  if test $stat -ne 0; then
346df9ffc95Smrg    rm -f "$tmpdepfile"
347df9ffc95Smrg    exit $stat
34809885543Smrg  fi
349df9ffc95Smrg  rm -f "$depfile"
350df9ffc95Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351df9ffc95Smrg  # We have to change lines of the first kind to '$object: \'.
352df9ffc95Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353df9ffc95Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354df9ffc95Smrg  # dummy dependency, to avoid the deleted-header problem.
355df9ffc95Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35609885543Smrg  rm -f "$tmpdepfile"
35709885543Smrg  ;;
35809885543Smrg
359df9ffc95Smrg## The order of this option in the case statement is important, since the
360df9ffc95Smrg## shell code in configure will try each of these formats in the order
361df9ffc95Smrg## listed in this file.  A plain '-MD' option would be understood by many
362df9ffc95Smrg## compilers, so we must ensure this comes after the gcc and icc options.
363df9ffc95Smrgpgcc)
364df9ffc95Smrg  # Portland's C compiler understands '-MD'.
365df9ffc95Smrg  # Will always output deps to 'file.d' where file is the root name of the
366df9ffc95Smrg  # source file under compilation, even if file resides in a subdirectory.
367df9ffc95Smrg  # The object file name does not affect the name of the '.d' file.
368df9ffc95Smrg  # pgcc 10.2 will output
36909885543Smrg  #    foo.o: sub/foo.c sub/foo.h
370df9ffc95Smrg  # and will wrap long lines using '\' :
37109885543Smrg  #    foo.o: sub/foo.c ... \
37209885543Smrg  #     sub/foo.h ... \
37309885543Smrg  #     ...
374df9ffc95Smrg  set_dir_from "$object"
375df9ffc95Smrg  # Use the source, not the object, to determine the base name, since
376df9ffc95Smrg  # that's sadly what pgcc will do too.
377df9ffc95Smrg  set_base_from "$source"
378df9ffc95Smrg  tmpdepfile=$base.d
379df9ffc95Smrg
380df9ffc95Smrg  # For projects that build the same source file twice into different object
381df9ffc95Smrg  # files, the pgcc approach of using the *source* file root name can cause
382df9ffc95Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383df9ffc95Smrg  # the same $tmpdepfile.
384df9ffc95Smrg  lockdir=$base.d-lock
385df9ffc95Smrg  trap "
386df9ffc95Smrg    echo '$0: caught signal, cleaning up...' >&2
387df9ffc95Smrg    rmdir '$lockdir'
388df9ffc95Smrg    exit 1
389df9ffc95Smrg  " 1 2 13 15
390df9ffc95Smrg  numtries=100
391df9ffc95Smrg  i=$numtries
392df9ffc95Smrg  while test $i -gt 0; do
393df9ffc95Smrg    # mkdir is a portable test-and-set.
394df9ffc95Smrg    if mkdir "$lockdir" 2>/dev/null; then
395df9ffc95Smrg      # This process acquired the lock.
396df9ffc95Smrg      "$@" -MD
397df9ffc95Smrg      stat=$?
398df9ffc95Smrg      # Release the lock.
399df9ffc95Smrg      rmdir "$lockdir"
400df9ffc95Smrg      break
401df9ffc95Smrg    else
402df9ffc95Smrg      # If the lock is being held by a different process, wait
403df9ffc95Smrg      # until the winning process is done or we timeout.
404df9ffc95Smrg      while test -d "$lockdir" && test $i -gt 0; do
405df9ffc95Smrg        sleep 1
406df9ffc95Smrg        i=`expr $i - 1`
407df9ffc95Smrg      done
408df9ffc95Smrg    fi
409df9ffc95Smrg    i=`expr $i - 1`
410df9ffc95Smrg  done
411df9ffc95Smrg  trap - 1 2 13 15
412df9ffc95Smrg  if test $i -le 0; then
413df9ffc95Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414df9ffc95Smrg    echo "$0: check lockdir '$lockdir'" >&2
415df9ffc95Smrg    exit 1
416df9ffc95Smrg  fi
41709885543Smrg
418df9ffc95Smrg  if test $stat -ne 0; then
41909885543Smrg    rm -f "$tmpdepfile"
42009885543Smrg    exit $stat
42109885543Smrg  fi
42209885543Smrg  rm -f "$depfile"
42309885543Smrg  # Each line is of the form `foo.o: dependent.h',
42409885543Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42509885543Smrg  # Do two passes, one to just change these to
42609885543Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42709885543Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42809885543Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
42909885543Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
430df9ffc95Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431df9ffc95Smrg    | sed -e 's/$/ :/' >> "$depfile"
43209885543Smrg  rm -f "$tmpdepfile"
43309885543Smrg  ;;
43409885543Smrg
4357104f784Smrghp2)
4367104f784Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4377104f784Smrg  # compilers, which have integrated preprocessors.  The correct option
4387104f784Smrg  # to use with these is +Maked; it writes dependencies to a file named
4397104f784Smrg  # 'foo.d', which lands next to the object file, wherever that
4407104f784Smrg  # happens to be.
4417104f784Smrg  # Much of this is similar to the tru64 case; see comments there.
442df9ffc95Smrg  set_dir_from  "$object"
443df9ffc95Smrg  set_base_from "$object"
4447104f784Smrg  if test "$libtool" = yes; then
4457104f784Smrg    tmpdepfile1=$dir$base.d
4467104f784Smrg    tmpdepfile2=$dir.libs/$base.d
4477104f784Smrg    "$@" -Wc,+Maked
4487104f784Smrg  else
4497104f784Smrg    tmpdepfile1=$dir$base.d
4507104f784Smrg    tmpdepfile2=$dir$base.d
4517104f784Smrg    "$@" +Maked
4527104f784Smrg  fi
4537104f784Smrg  stat=$?
454df9ffc95Smrg  if test $stat -ne 0; then
4557104f784Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4567104f784Smrg     exit $stat
4577104f784Smrg  fi
4587104f784Smrg
4597104f784Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4607104f784Smrg  do
4617104f784Smrg    test -f "$tmpdepfile" && break
4627104f784Smrg  done
4637104f784Smrg  if test -f "$tmpdepfile"; then
464df9ffc95Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465df9ffc95Smrg    # Add 'dependent.h:' lines.
466b698ba48Smrg    sed -ne '2,${
467df9ffc95Smrg               s/^ *//
468df9ffc95Smrg               s/ \\*$//
469df9ffc95Smrg               s/$/:/
470df9ffc95Smrg               p
471df9ffc95Smrg             }' "$tmpdepfile" >> "$depfile"
4727104f784Smrg  else
473df9ffc95Smrg    make_dummy_depfile
4747104f784Smrg  fi
4757104f784Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4767104f784Smrg  ;;
4777104f784Smrg
47809885543Smrgtru64)
479df9ffc95Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480df9ffc95Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481df9ffc95Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482df9ffc95Smrg  # dependencies in 'foo.d' instead, so we check for that too.
483df9ffc95Smrg  # Subdirectories are respected.
484df9ffc95Smrg  set_dir_from  "$object"
485df9ffc95Smrg  set_base_from "$object"
486df9ffc95Smrg
487df9ffc95Smrg  if test "$libtool" = yes; then
488df9ffc95Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489df9ffc95Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490df9ffc95Smrg    # in $dir$base.o.d.  We have to check for both files, because
491df9ffc95Smrg    # one of the two compilations can be disabled.  We should prefer
492df9ffc95Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493df9ffc95Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
494df9ffc95Smrg    # the former would cause a distcleancheck panic.
495df9ffc95Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496df9ffc95Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497df9ffc95Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498df9ffc95Smrg    "$@" -Wc,-MD
499df9ffc95Smrg  else
500df9ffc95Smrg    tmpdepfile1=$dir$base.d
501df9ffc95Smrg    tmpdepfile2=$dir$base.d
502df9ffc95Smrg    tmpdepfile3=$dir$base.d
503df9ffc95Smrg    "$@" -MD
504df9ffc95Smrg  fi
505df9ffc95Smrg
506df9ffc95Smrg  stat=$?
507df9ffc95Smrg  if test $stat -ne 0; then
508df9ffc95Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509df9ffc95Smrg    exit $stat
510df9ffc95Smrg  fi
511df9ffc95Smrg
512df9ffc95Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513df9ffc95Smrg  do
514df9ffc95Smrg    test -f "$tmpdepfile" && break
515df9ffc95Smrg  done
516df9ffc95Smrg  # Same post-processing that is required for AIX mode.
517df9ffc95Smrg  aix_post_process_depfile
518df9ffc95Smrg  ;;
51909885543Smrg
520b12e5c03Smrgmsvc7)
521b12e5c03Smrg  if test "$libtool" = yes; then
522b12e5c03Smrg    showIncludes=-Wc,-showIncludes
523b12e5c03Smrg  else
524b12e5c03Smrg    showIncludes=-showIncludes
525b12e5c03Smrg  fi
526b12e5c03Smrg  "$@" $showIncludes > "$tmpdepfile"
527b12e5c03Smrg  stat=$?
528b12e5c03Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
529df9ffc95Smrg  if test $stat -ne 0; then
530b12e5c03Smrg    rm -f "$tmpdepfile"
531b12e5c03Smrg    exit $stat
532b12e5c03Smrg  fi
533b12e5c03Smrg  rm -f "$depfile"
534b12e5c03Smrg  echo "$object : \\" > "$depfile"
535b12e5c03Smrg  # The first sed program below extracts the file names and escapes
536b12e5c03Smrg  # backslashes for cygpath.  The second sed program outputs the file
537b12e5c03Smrg  # name when reading, but also accumulates all include files in the
538b12e5c03Smrg  # hold buffer in order to output them again at the end.  This only
539b12e5c03Smrg  # works with sed implementations that can handle large buffers.
540b12e5c03Smrg  sed < "$tmpdepfile" -n '
541b12e5c03Smrg/^Note: including file:  *\(.*\)/ {
542b12e5c03Smrg  s//\1/
543b12e5c03Smrg  s/\\/\\\\/g
544b12e5c03Smrg  p
545b12e5c03Smrg}' | $cygpath_u | sort -u | sed -n '
546b12e5c03Smrgs/ /\\ /g
547df9ffc95Smrgs/\(.*\)/'"$tab"'\1 \\/p
548b12e5c03Smrgs/.\(.*\) \\/\1:/
549b12e5c03SmrgH
550b12e5c03Smrg$ {
551df9ffc95Smrg  s/.*/'"$tab"'/
552b12e5c03Smrg  G
553b12e5c03Smrg  p
554b12e5c03Smrg}' >> "$depfile"
555df9ffc95Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556b12e5c03Smrg  rm -f "$tmpdepfile"
557b12e5c03Smrg  ;;
558b12e5c03Smrg
559b12e5c03Smrgmsvc7msys)
560b12e5c03Smrg  # This case exists only to let depend.m4 do its work.  It works by
561b12e5c03Smrg  # looking at the text of this script.  This case will never be run,
562b12e5c03Smrg  # since it is checked for above.
563b12e5c03Smrg  exit 1
564b12e5c03Smrg  ;;
565b12e5c03Smrg
56609885543Smrg#nosideeffect)
56709885543Smrg  # This comment above is used by automake to tell side-effect
56809885543Smrg  # dependency tracking mechanisms from slower ones.
56909885543Smrg
57009885543Smrgdashmstdout)
57109885543Smrg  # Important note: in order to support this mode, a compiler *must*
57209885543Smrg  # always write the preprocessed file to stdout, regardless of -o.
57309885543Smrg  "$@" || exit $?
57409885543Smrg
57509885543Smrg  # Remove the call to Libtool.
57609885543Smrg  if test "$libtool" = yes; then
577b698ba48Smrg    while test "X$1" != 'X--mode=compile'; do
57809885543Smrg      shift
57909885543Smrg    done
58009885543Smrg    shift
58109885543Smrg  fi
58209885543Smrg
583df9ffc95Smrg  # Remove '-o $object'.
58409885543Smrg  IFS=" "
58509885543Smrg  for arg
58609885543Smrg  do
58709885543Smrg    case $arg in
58809885543Smrg    -o)
58909885543Smrg      shift
59009885543Smrg      ;;
59109885543Smrg    $object)
59209885543Smrg      shift
59309885543Smrg      ;;
59409885543Smrg    *)
59509885543Smrg      set fnord "$@" "$arg"
59609885543Smrg      shift # fnord
59709885543Smrg      shift # $arg
59809885543Smrg      ;;
59909885543Smrg    esac
60009885543Smrg  done
60109885543Smrg
60209885543Smrg  test -z "$dashmflag" && dashmflag=-M
603df9ffc95Smrg  # Require at least two characters before searching for ':'
60409885543Smrg  # in the target name.  This is to cope with DOS-style filenames:
605df9ffc95Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60609885543Smrg  "$@" $dashmflag |
607df9ffc95Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60809885543Smrg  rm -f "$depfile"
60909885543Smrg  cat < "$tmpdepfile" > "$depfile"
610df9ffc95Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611df9ffc95Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
612df9ffc95Smrg  tr ' ' "$nl" < "$tmpdepfile" \
613df9ffc95Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614df9ffc95Smrg    | sed -e 's/$/ :/' >> "$depfile"
61509885543Smrg  rm -f "$tmpdepfile"
61609885543Smrg  ;;
61709885543Smrg
61809885543SmrgdashXmstdout)
61909885543Smrg  # This case only exists to satisfy depend.m4.  It is never actually
62009885543Smrg  # run, as this mode is specially recognized in the preamble.
62109885543Smrg  exit 1
62209885543Smrg  ;;
62309885543Smrg
62409885543Smrgmakedepend)
62509885543Smrg  "$@" || exit $?
62609885543Smrg  # Remove any Libtool call
62709885543Smrg  if test "$libtool" = yes; then
628b698ba48Smrg    while test "X$1" != 'X--mode=compile'; do
62909885543Smrg      shift
63009885543Smrg    done
63109885543Smrg    shift
63209885543Smrg  fi
63309885543Smrg  # X makedepend
63409885543Smrg  shift
635b698ba48Smrg  cleared=no eat=no
636b698ba48Smrg  for arg
637b698ba48Smrg  do
63809885543Smrg    case $cleared in
63909885543Smrg    no)
64009885543Smrg      set ""; shift
64109885543Smrg      cleared=yes ;;
64209885543Smrg    esac
643b698ba48Smrg    if test $eat = yes; then
644b698ba48Smrg      eat=no
645b698ba48Smrg      continue
646b698ba48Smrg    fi
64709885543Smrg    case "$arg" in
64809885543Smrg    -D*|-I*)
64909885543Smrg      set fnord "$@" "$arg"; shift ;;
65009885543Smrg    # Strip any option that makedepend may not understand.  Remove
65109885543Smrg    # the object too, otherwise makedepend will parse it as a source file.
652b698ba48Smrg    -arch)
653b698ba48Smrg      eat=yes ;;
65409885543Smrg    -*|$object)
65509885543Smrg      ;;
65609885543Smrg    *)
65709885543Smrg      set fnord "$@" "$arg"; shift ;;
65809885543Smrg    esac
65909885543Smrg  done
660b698ba48Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66109885543Smrg  touch "$tmpdepfile"
66209885543Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66309885543Smrg  rm -f "$depfile"
664b12e5c03Smrg  # makedepend may prepend the VPATH from the source file name to the object.
665b12e5c03Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666b12e5c03Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667df9ffc95Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668df9ffc95Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
669df9ffc95Smrg  sed '1,2d' "$tmpdepfile" \
670df9ffc95Smrg    | tr ' ' "$nl" \
671df9ffc95Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672df9ffc95Smrg    | sed -e 's/$/ :/' >> "$depfile"
67309885543Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67409885543Smrg  ;;
67509885543Smrg
67609885543Smrgcpp)
67709885543Smrg  # Important note: in order to support this mode, a compiler *must*
67809885543Smrg  # always write the preprocessed file to stdout.
67909885543Smrg  "$@" || exit $?
68009885543Smrg
68109885543Smrg  # Remove the call to Libtool.
68209885543Smrg  if test "$libtool" = yes; then
683b698ba48Smrg    while test "X$1" != 'X--mode=compile'; do
68409885543Smrg      shift
68509885543Smrg    done
68609885543Smrg    shift
68709885543Smrg  fi
68809885543Smrg
689df9ffc95Smrg  # Remove '-o $object'.
69009885543Smrg  IFS=" "
69109885543Smrg  for arg
69209885543Smrg  do
69309885543Smrg    case $arg in
69409885543Smrg    -o)
69509885543Smrg      shift
69609885543Smrg      ;;
69709885543Smrg    $object)
69809885543Smrg      shift
69909885543Smrg      ;;
70009885543Smrg    *)
70109885543Smrg      set fnord "$@" "$arg"
70209885543Smrg      shift # fnord
70309885543Smrg      shift # $arg
70409885543Smrg      ;;
70509885543Smrg    esac
70609885543Smrg  done
70709885543Smrg
708df9ffc95Smrg  "$@" -E \
709df9ffc95Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710df9ffc95Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711df9ffc95Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
71209885543Smrg  rm -f "$depfile"
71309885543Smrg  echo "$object : \\" > "$depfile"
71409885543Smrg  cat < "$tmpdepfile" >> "$depfile"
71509885543Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71609885543Smrg  rm -f "$tmpdepfile"
71709885543Smrg  ;;
71809885543Smrg
71909885543Smrgmsvisualcpp)
72009885543Smrg  # Important note: in order to support this mode, a compiler *must*
721b698ba48Smrg  # always write the preprocessed file to stdout.
72209885543Smrg  "$@" || exit $?
723b698ba48Smrg
724b698ba48Smrg  # Remove the call to Libtool.
725b698ba48Smrg  if test "$libtool" = yes; then
726b698ba48Smrg    while test "X$1" != 'X--mode=compile'; do
727b698ba48Smrg      shift
728b698ba48Smrg    done
729b698ba48Smrg    shift
730b698ba48Smrg  fi
731b698ba48Smrg
73209885543Smrg  IFS=" "
73309885543Smrg  for arg
73409885543Smrg  do
73509885543Smrg    case "$arg" in
736b698ba48Smrg    -o)
737b698ba48Smrg      shift
738b698ba48Smrg      ;;
739b698ba48Smrg    $object)
740b698ba48Smrg      shift
741b698ba48Smrg      ;;
74209885543Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743df9ffc95Smrg        set fnord "$@"
744df9ffc95Smrg        shift
745df9ffc95Smrg        shift
746df9ffc95Smrg        ;;
74709885543Smrg    *)
748df9ffc95Smrg        set fnord "$@" "$arg"
749df9ffc95Smrg        shift
750df9ffc95Smrg        shift
751df9ffc95Smrg        ;;
75209885543Smrg    esac
75309885543Smrg  done
754b698ba48Smrg  "$@" -E 2>/dev/null |
755b698ba48Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75609885543Smrg  rm -f "$depfile"
75709885543Smrg  echo "$object : \\" > "$depfile"
758df9ffc95Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759df9ffc95Smrg  echo "$tab" >> "$depfile"
760b698ba48Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76109885543Smrg  rm -f "$tmpdepfile"
76209885543Smrg  ;;
76309885543Smrg
764b698ba48Smrgmsvcmsys)
765b698ba48Smrg  # This case exists only to let depend.m4 do its work.  It works by
766b698ba48Smrg  # looking at the text of this script.  This case will never be run,
767b698ba48Smrg  # since it is checked for above.
768b698ba48Smrg  exit 1
769b698ba48Smrg  ;;
770b698ba48Smrg
77109885543Smrgnone)
77209885543Smrg  exec "$@"
77309885543Smrg  ;;
77409885543Smrg
77509885543Smrg*)
77609885543Smrg  echo "Unknown depmode $depmode" 1>&2
77709885543Smrg  exit 1
77809885543Smrg  ;;
77909885543Smrgesac
78009885543Smrg
78109885543Smrgexit 0
78209885543Smrg
78309885543Smrg# Local Variables:
78409885543Smrg# mode: shell-script
78509885543Smrg# sh-indentation: 2
786beef1b22Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
78709885543Smrg# time-stamp-start: "scriptversion="
78809885543Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789beef1b22Smrg# time-stamp-time-zone: "UTC0"
790b698ba48Smrg# time-stamp-end: "; # UTC"
79109885543Smrg# End:
792