176910425Smrg#! /bin/sh
276910425Smrg# depcomp - compile a program generating dependencies as side-effects
376910425Smrg
48bfe6addSmrgscriptversion=2024-06-19.01; # UTC
576910425Smrg
68bfe6addSmrg# Copyright (C) 1999-2024 Free Software Foundation, Inc.
776910425Smrg
876910425Smrg# This program is free software; you can redistribute it and/or modify
976910425Smrg# it under the terms of the GNU General Public License as published by
1076910425Smrg# the Free Software Foundation; either version 2, or (at your option)
1176910425Smrg# any later version.
1276910425Smrg
1376910425Smrg# This program is distributed in the hope that it will be useful,
1476910425Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1576910425Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1676910425Smrg# GNU General Public License for more details.
1776910425Smrg
1876910425Smrg# You should have received a copy of the GNU General Public License
19a67f45c3Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2076910425Smrg
2176910425Smrg# As a special exception to the GNU General Public License, if you
2276910425Smrg# distribute this file as part of a program that contains a
2376910425Smrg# configuration script generated by Autoconf, you may include it under
2476910425Smrg# the same distribution terms that you use for the rest of that program.
2576910425Smrg
2676910425Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2776910425Smrg
2876910425Smrgcase $1 in
2976910425Smrg  '')
309ff100acSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
319ff100acSmrg    exit 1;
329ff100acSmrg    ;;
3376910425Smrg  -h | --h*)
3476910425Smrg    cat <<\EOF
3576910425SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3676910425Smrg
3776910425SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3876910425Smrgas side-effects.
3976910425Smrg
4076910425SmrgEnvironment variables:
4176910425Smrg  depmode     Dependency tracking mode.
429ff100acSmrg  source      Source file read by 'PROGRAMS ARGS'.
439ff100acSmrg  object      Object file output by 'PROGRAMS ARGS'.
4476910425Smrg  DEPDIR      directory where to store dependencies.
4576910425Smrg  depfile     Dependency file to output.
469ff100acSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
4776910425Smrg  libtool     Whether libtool is used (yes/no).
4876910425Smrg
4976910425SmrgReport bugs to <bug-automake@gnu.org>.
508bfe6addSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
518bfe6addSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>.
5276910425SmrgEOF
5376910425Smrg    exit $?
5476910425Smrg    ;;
5576910425Smrg  -v | --v*)
568bfe6addSmrg    echo "depcomp (GNU Automake) $scriptversion"
5776910425Smrg    exit $?
5876910425Smrg    ;;
5976910425Smrgesac
6076910425Smrg
619ff100acSmrg# Get the directory component of the given path, and save it in the
629ff100acSmrg# global variables '$dir'.  Note that this directory component will
639ff100acSmrg# be either empty or ending with a '/' character.  This is deliberate.
649ff100acSmrgset_dir_from ()
659ff100acSmrg{
669ff100acSmrg  case $1 in
679ff100acSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
689ff100acSmrg      *) dir=;;
699ff100acSmrg  esac
709ff100acSmrg}
719ff100acSmrg
729ff100acSmrg# Get the suffix-stripped basename of the given path, and save it the
739ff100acSmrg# global variable '$base'.
749ff100acSmrgset_base_from ()
759ff100acSmrg{
769ff100acSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
779ff100acSmrg}
789ff100acSmrg
799ff100acSmrg# If no dependency file was actually created by the compiler invocation,
809ff100acSmrg# we still have to create a dummy depfile, to avoid errors with the
819ff100acSmrg# Makefile "include basename.Plo" scheme.
829ff100acSmrgmake_dummy_depfile ()
839ff100acSmrg{
849ff100acSmrg  echo "#dummy" > "$depfile"
859ff100acSmrg}
869ff100acSmrg
879ff100acSmrg# Factor out some common post-processing of the generated depfile.
889ff100acSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
899ff100acSmrgaix_post_process_depfile ()
909ff100acSmrg{
919ff100acSmrg  # If the compiler actually managed to produce a dependency file,
929ff100acSmrg  # post-process it.
939ff100acSmrg  if test -f "$tmpdepfile"; then
949ff100acSmrg    # Each line is of the form 'foo.o: dependency.h'.
959ff100acSmrg    # Do two passes, one to just change these to
969ff100acSmrg    #   $object: dependency.h
979ff100acSmrg    # and one to simply output
989ff100acSmrg    #   dependency.h:
999ff100acSmrg    # which is needed to avoid the deleted-header problem.
1009ff100acSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
1019ff100acSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1029ff100acSmrg    } > "$depfile"
1039ff100acSmrg    rm -f "$tmpdepfile"
1049ff100acSmrg  else
1059ff100acSmrg    make_dummy_depfile
1069ff100acSmrg  fi
1079ff100acSmrg}
1089ff100acSmrg
1099ff100acSmrg# A tabulation character.
1109ff100acSmrgtab='	'
1119ff100acSmrg# A newline character.
1129ff100acSmrgnl='
1139ff100acSmrg'
1149ff100acSmrg# Character ranges might be problematic outside the C locale.
1159ff100acSmrg# These definitions help.
1169ff100acSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1179ff100acSmrglower=abcdefghijklmnopqrstuvwxyz
1189ff100acSmrgalpha=${upper}${lower}
1199ff100acSmrg
12076910425Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12176910425Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12276910425Smrg  exit 1
12376910425Smrgfi
12476910425Smrg
12576910425Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12676910425Smrgdepfile=${depfile-`echo "$object" |
12776910425Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12876910425Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12976910425Smrg
13076910425Smrgrm -f "$tmpdepfile"
13176910425Smrg
1328bfe6addSmrg# Avoid interference from the environment.
1339ff100acSmrggccflag= dashmflag=
1349ff100acSmrg
13576910425Smrg# Some modes work just like other modes, but use different flags.  We
13676910425Smrg# parameterize here, but still list the modes in the big case below,
13776910425Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13876910425Smrg# here, because this file can only contain one case statement.
13976910425Smrgif test "$depmode" = hp; then
14076910425Smrg  # HP compiler uses -M and no extra arg.
14176910425Smrg  gccflag=-M
14276910425Smrg  depmode=gcc
14376910425Smrgfi
14476910425Smrg
14576910425Smrgif test "$depmode" = dashXmstdout; then
1469ff100acSmrg  # This is just like dashmstdout with a different argument.
1479ff100acSmrg  dashmflag=-xM
1489ff100acSmrg  depmode=dashmstdout
14976910425Smrgfi
15076910425Smrg
151db17cd6dSmrgcygpath_u="cygpath -u -f -"
152db17cd6dSmrgif test "$depmode" = msvcmsys; then
1539ff100acSmrg  # This is just like msvisualcpp but w/o cygpath translation.
1549ff100acSmrg  # Just convert the backslash-escaped backslashes to single forward
1559ff100acSmrg  # slashes to satisfy depend.m4
1569ff100acSmrg  cygpath_u='sed s,\\\\,/,g'
1579ff100acSmrg  depmode=msvisualcpp
1589ff100acSmrgfi
1599ff100acSmrg
1609ff100acSmrgif test "$depmode" = msvc7msys; then
1619ff100acSmrg  # This is just like msvc7 but w/o cygpath translation.
1629ff100acSmrg  # Just convert the backslash-escaped backslashes to single forward
1639ff100acSmrg  # slashes to satisfy depend.m4
1649ff100acSmrg  cygpath_u='sed s,\\\\,/,g'
1659ff100acSmrg  depmode=msvc7
1669ff100acSmrgfi
1679ff100acSmrg
1689ff100acSmrgif test "$depmode" = xlc; then
1699ff100acSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1709ff100acSmrg  gccflag=-qmakedep=gcc,-MF
1719ff100acSmrg  depmode=gcc
172db17cd6dSmrgfi
173db17cd6dSmrg
17476910425Smrgcase "$depmode" in
17576910425Smrggcc3)
17676910425Smrg## gcc 3 implements dependency tracking that does exactly what
17776910425Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17876910425Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
179db17cd6dSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
180db17cd6dSmrg## the command line argument order; so add the flags where they
181db17cd6dSmrg## appear in depend2.am.  Note that the slowdown incurred here
182db17cd6dSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
183db17cd6dSmrg  for arg
184db17cd6dSmrg  do
185db17cd6dSmrg    case $arg in
186db17cd6dSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
187db17cd6dSmrg    *)  set fnord "$@" "$arg" ;;
188db17cd6dSmrg    esac
189db17cd6dSmrg    shift # fnord
190db17cd6dSmrg    shift # $arg
191db17cd6dSmrg  done
192db17cd6dSmrg  "$@"
19376910425Smrg  stat=$?
1949ff100acSmrg  if test $stat -ne 0; then
19576910425Smrg    rm -f "$tmpdepfile"
19676910425Smrg    exit $stat
19776910425Smrg  fi
19876910425Smrg  mv "$tmpdepfile" "$depfile"
19976910425Smrg  ;;
20076910425Smrg
20176910425Smrggcc)
2028bfe6addSmrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers.
2038bfe6addSmrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler.
2049ff100acSmrg## (see the conditional assignment to $gccflag above).
20576910425Smrg## There are various ways to get dependency output from gcc.  Here's
20676910425Smrg## why we pick this rather obscure method:
20776910425Smrg## - Don't want to use -MD because we'd like the dependencies to end
20876910425Smrg##   up in a subdir.  Having to rename by hand is ugly.
20976910425Smrg##   (We might end up doing this anyway to support other compilers.)
21076910425Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2119ff100acSmrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2129ff100acSmrg##   supported by the other compilers which use the 'gcc' depmode.
21376910425Smrg## - Using -M directly means running the compiler twice (even worse
21476910425Smrg##   than renaming).
21576910425Smrg  if test -z "$gccflag"; then
21676910425Smrg    gccflag=-MD,
21776910425Smrg  fi
21876910425Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
21976910425Smrg  stat=$?
2209ff100acSmrg  if test $stat -ne 0; then
22176910425Smrg    rm -f "$tmpdepfile"
22276910425Smrg    exit $stat
22376910425Smrg  fi
22476910425Smrg  rm -f "$depfile"
22576910425Smrg  echo "$object : \\" > "$depfile"
2269ff100acSmrg  # The second -e expression handles DOS-style file names with drive
2279ff100acSmrg  # letters.
22876910425Smrg  sed -e 's/^[^:]*: / /' \
22976910425Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2309ff100acSmrg## This next piece of magic avoids the "deleted header file" problem.
23176910425Smrg## The problem is that when a header file which appears in a .P file
23276910425Smrg## is deleted, the dependency causes make to die (because there is
23376910425Smrg## typically no way to rebuild the header).  We avoid this by adding
23476910425Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23576910425Smrg## this for us directly.
2369ff100acSmrg## Some versions of gcc put a space before the ':'.  On the theory
23776910425Smrg## that the space means something, we add a space to the output as
2389ff100acSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2399ff100acSmrg## to the object.  Take care to not repeat it in the output.
24076910425Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
24176910425Smrg## correctly.  Breaking it into two sed invocations is a workaround.
2429ff100acSmrg  tr ' ' "$nl" < "$tmpdepfile" \
2439ff100acSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2449ff100acSmrg    | sed -e 's/$/ :/' >> "$depfile"
24576910425Smrg  rm -f "$tmpdepfile"
24676910425Smrg  ;;
24776910425Smrg
24876910425Smrghp)
24976910425Smrg  # This case exists only to let depend.m4 do its work.  It works by
25076910425Smrg  # looking at the text of this script.  This case will never be run,
25176910425Smrg  # since it is checked for above.
25276910425Smrg  exit 1
25376910425Smrg  ;;
25476910425Smrg
25576910425Smrgsgi)
25676910425Smrg  if test "$libtool" = yes; then
25776910425Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25876910425Smrg  else
25976910425Smrg    "$@" -MDupdate "$tmpdepfile"
26076910425Smrg  fi
26176910425Smrg  stat=$?
2629ff100acSmrg  if test $stat -ne 0; then
26376910425Smrg    rm -f "$tmpdepfile"
26476910425Smrg    exit $stat
26576910425Smrg  fi
26676910425Smrg  rm -f "$depfile"
26776910425Smrg
26876910425Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26976910425Smrg    echo "$object : \\" > "$depfile"
27076910425Smrg    # Clip off the initial element (the dependent).  Don't try to be
27176910425Smrg    # clever and replace this with sed code, as IRIX sed won't handle
27276910425Smrg    # lines with more than a fixed number of characters (4096 in
27376910425Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2749ff100acSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
27576910425Smrg    # dependency line.
2769ff100acSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2779ff100acSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2789ff100acSmrg      | tr "$nl" ' ' >> "$depfile"
279db17cd6dSmrg    echo >> "$depfile"
28076910425Smrg    # The second pass generates a dummy entry for each header file.
2819ff100acSmrg    tr ' ' "$nl" < "$tmpdepfile" \
2829ff100acSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2839ff100acSmrg      >> "$depfile"
28476910425Smrg  else
2859ff100acSmrg    make_dummy_depfile
28676910425Smrg  fi
28776910425Smrg  rm -f "$tmpdepfile"
28876910425Smrg  ;;
28976910425Smrg
2909ff100acSmrgxlc)
2919ff100acSmrg  # This case exists only to let depend.m4 do its work.  It works by
2929ff100acSmrg  # looking at the text of this script.  This case will never be run,
2939ff100acSmrg  # since it is checked for above.
2949ff100acSmrg  exit 1
2959ff100acSmrg  ;;
2969ff100acSmrg
29776910425Smrgaix)
29876910425Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
29976910425Smrg  # in a .u file.  In older versions, this file always lives in the
3009ff100acSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30176910425Smrg  # start of each line; $object doesn't have directory information.
30276910425Smrg  # Version 6 uses the directory in both cases.
3039ff100acSmrg  set_dir_from "$object"
3049ff100acSmrg  set_base_from "$object"
30576910425Smrg  if test "$libtool" = yes; then
306db17cd6dSmrg    tmpdepfile1=$dir$base.u
307db17cd6dSmrg    tmpdepfile2=$base.u
308db17cd6dSmrg    tmpdepfile3=$dir.libs/$base.u
30976910425Smrg    "$@" -Wc,-M
31076910425Smrg  else
311db17cd6dSmrg    tmpdepfile1=$dir$base.u
312db17cd6dSmrg    tmpdepfile2=$dir$base.u
313db17cd6dSmrg    tmpdepfile3=$dir$base.u
31476910425Smrg    "$@" -M
31576910425Smrg  fi
31676910425Smrg  stat=$?
3179ff100acSmrg  if test $stat -ne 0; then
318db17cd6dSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31976910425Smrg    exit $stat
32076910425Smrg  fi
32176910425Smrg
322db17cd6dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
323db17cd6dSmrg  do
324db17cd6dSmrg    test -f "$tmpdepfile" && break
325db17cd6dSmrg  done
3269ff100acSmrg  aix_post_process_depfile
3279ff100acSmrg  ;;
3289ff100acSmrg
3299ff100acSmrgtcc)
3309ff100acSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3319ff100acSmrg  # FIXME: That version still under development at the moment of writing.
3329ff100acSmrg  #        Make that this statement remains true also for stable, released
3339ff100acSmrg  #        versions.
3349ff100acSmrg  # It will wrap lines (doesn't matter whether long or short) with a
3359ff100acSmrg  # trailing '\', as in:
3369ff100acSmrg  #
3379ff100acSmrg  #   foo.o : \
3389ff100acSmrg  #    foo.c \
3399ff100acSmrg  #    foo.h \
3409ff100acSmrg  #
3419ff100acSmrg  # It will put a trailing '\' even on the last line, and will use leading
3429ff100acSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3439ff100acSmrg  # "Emit spaces for -MD").
3449ff100acSmrg  "$@" -MD -MF "$tmpdepfile"
3459ff100acSmrg  stat=$?
3469ff100acSmrg  if test $stat -ne 0; then
3479ff100acSmrg    rm -f "$tmpdepfile"
3489ff100acSmrg    exit $stat
34976910425Smrg  fi
3509ff100acSmrg  rm -f "$depfile"
3519ff100acSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3529ff100acSmrg  # We have to change lines of the first kind to '$object: \'.
3539ff100acSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3549ff100acSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3559ff100acSmrg  # dummy dependency, to avoid the deleted-header problem.
3569ff100acSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35776910425Smrg  rm -f "$tmpdepfile"
35876910425Smrg  ;;
35976910425Smrg
3609ff100acSmrg## The order of this option in the case statement is important, since the
3619ff100acSmrg## shell code in configure will try each of these formats in the order
3629ff100acSmrg## listed in this file.  A plain '-MD' option would be understood by many
3639ff100acSmrg## compilers, so we must ensure this comes after the gcc and icc options.
3649ff100acSmrgpgcc)
3659ff100acSmrg  # Portland's C compiler understands '-MD'.
3669ff100acSmrg  # Will always output deps to 'file.d' where file is the root name of the
3679ff100acSmrg  # source file under compilation, even if file resides in a subdirectory.
3689ff100acSmrg  # The object file name does not affect the name of the '.d' file.
3699ff100acSmrg  # pgcc 10.2 will output
37076910425Smrg  #    foo.o: sub/foo.c sub/foo.h
3719ff100acSmrg  # and will wrap long lines using '\' :
37276910425Smrg  #    foo.o: sub/foo.c ... \
37376910425Smrg  #     sub/foo.h ... \
37476910425Smrg  #     ...
3759ff100acSmrg  set_dir_from "$object"
3769ff100acSmrg  # Use the source, not the object, to determine the base name, since
3779ff100acSmrg  # that's sadly what pgcc will do too.
3789ff100acSmrg  set_base_from "$source"
3799ff100acSmrg  tmpdepfile=$base.d
3809ff100acSmrg
3819ff100acSmrg  # For projects that build the same source file twice into different object
3829ff100acSmrg  # files, the pgcc approach of using the *source* file root name can cause
3839ff100acSmrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3849ff100acSmrg  # the same $tmpdepfile.
3859ff100acSmrg  lockdir=$base.d-lock
3869ff100acSmrg  trap "
3879ff100acSmrg    echo '$0: caught signal, cleaning up...' >&2
3889ff100acSmrg    rmdir '$lockdir'
3899ff100acSmrg    exit 1
3909ff100acSmrg  " 1 2 13 15
3919ff100acSmrg  numtries=100
3929ff100acSmrg  i=$numtries
3939ff100acSmrg  while test $i -gt 0; do
3949ff100acSmrg    # mkdir is a portable test-and-set.
3959ff100acSmrg    if mkdir "$lockdir" 2>/dev/null; then
3969ff100acSmrg      # This process acquired the lock.
3979ff100acSmrg      "$@" -MD
3989ff100acSmrg      stat=$?
3999ff100acSmrg      # Release the lock.
4009ff100acSmrg      rmdir "$lockdir"
4019ff100acSmrg      break
4029ff100acSmrg    else
4039ff100acSmrg      # If the lock is being held by a different process, wait
4049ff100acSmrg      # until the winning process is done or we timeout.
4059ff100acSmrg      while test -d "$lockdir" && test $i -gt 0; do
4069ff100acSmrg        sleep 1
4079ff100acSmrg        i=`expr $i - 1`
4089ff100acSmrg      done
4099ff100acSmrg    fi
4109ff100acSmrg    i=`expr $i - 1`
4119ff100acSmrg  done
4129ff100acSmrg  trap - 1 2 13 15
4139ff100acSmrg  if test $i -le 0; then
4149ff100acSmrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4159ff100acSmrg    echo "$0: check lockdir '$lockdir'" >&2
4169ff100acSmrg    exit 1
4179ff100acSmrg  fi
41876910425Smrg
4199ff100acSmrg  if test $stat -ne 0; then
42076910425Smrg    rm -f "$tmpdepfile"
42176910425Smrg    exit $stat
42276910425Smrg  fi
42376910425Smrg  rm -f "$depfile"
42476910425Smrg  # Each line is of the form `foo.o: dependent.h',
42576910425Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42676910425Smrg  # Do two passes, one to just change these to
42776910425Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42876910425Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42976910425Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
43076910425Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
4319ff100acSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4329ff100acSmrg    | sed -e 's/$/ :/' >> "$depfile"
43376910425Smrg  rm -f "$tmpdepfile"
43476910425Smrg  ;;
43576910425Smrg
436db17cd6dSmrghp2)
437db17cd6dSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
438db17cd6dSmrg  # compilers, which have integrated preprocessors.  The correct option
439db17cd6dSmrg  # to use with these is +Maked; it writes dependencies to a file named
440db17cd6dSmrg  # 'foo.d', which lands next to the object file, wherever that
441db17cd6dSmrg  # happens to be.
442db17cd6dSmrg  # Much of this is similar to the tru64 case; see comments there.
4439ff100acSmrg  set_dir_from  "$object"
4449ff100acSmrg  set_base_from "$object"
445db17cd6dSmrg  if test "$libtool" = yes; then
446db17cd6dSmrg    tmpdepfile1=$dir$base.d
447db17cd6dSmrg    tmpdepfile2=$dir.libs/$base.d
448db17cd6dSmrg    "$@" -Wc,+Maked
449db17cd6dSmrg  else
450db17cd6dSmrg    tmpdepfile1=$dir$base.d
451db17cd6dSmrg    tmpdepfile2=$dir$base.d
452db17cd6dSmrg    "$@" +Maked
453db17cd6dSmrg  fi
454db17cd6dSmrg  stat=$?
4559ff100acSmrg  if test $stat -ne 0; then
456db17cd6dSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
457db17cd6dSmrg     exit $stat
458db17cd6dSmrg  fi
459db17cd6dSmrg
460db17cd6dSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
461db17cd6dSmrg  do
462db17cd6dSmrg    test -f "$tmpdepfile" && break
463db17cd6dSmrg  done
464db17cd6dSmrg  if test -f "$tmpdepfile"; then
4659ff100acSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4669ff100acSmrg    # Add 'dependent.h:' lines.
467db17cd6dSmrg    sed -ne '2,${
4689ff100acSmrg               s/^ *//
4699ff100acSmrg               s/ \\*$//
4709ff100acSmrg               s/$/:/
4719ff100acSmrg               p
4729ff100acSmrg             }' "$tmpdepfile" >> "$depfile"
473db17cd6dSmrg  else
4749ff100acSmrg    make_dummy_depfile
475db17cd6dSmrg  fi
476db17cd6dSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
477db17cd6dSmrg  ;;
478db17cd6dSmrg
47976910425Smrgtru64)
4809ff100acSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4819ff100acSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4829ff100acSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4839ff100acSmrg  # dependencies in 'foo.d' instead, so we check for that too.
4849ff100acSmrg  # Subdirectories are respected.
4859ff100acSmrg  set_dir_from  "$object"
4869ff100acSmrg  set_base_from "$object"
4879ff100acSmrg
4889ff100acSmrg  if test "$libtool" = yes; then
4899ff100acSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4909ff100acSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4919ff100acSmrg    # in $dir$base.o.d.  We have to check for both files, because
4929ff100acSmrg    # one of the two compilations can be disabled.  We should prefer
4939ff100acSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4949ff100acSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
4959ff100acSmrg    # the former would cause a distcleancheck panic.
4969ff100acSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4979ff100acSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4989ff100acSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4999ff100acSmrg    "$@" -Wc,-MD
5009ff100acSmrg  else
5019ff100acSmrg    tmpdepfile1=$dir$base.d
5029ff100acSmrg    tmpdepfile2=$dir$base.d
5039ff100acSmrg    tmpdepfile3=$dir$base.d
5049ff100acSmrg    "$@" -MD
5059ff100acSmrg  fi
5069ff100acSmrg
5079ff100acSmrg  stat=$?
5089ff100acSmrg  if test $stat -ne 0; then
5099ff100acSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5109ff100acSmrg    exit $stat
5119ff100acSmrg  fi
5129ff100acSmrg
5139ff100acSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5149ff100acSmrg  do
5159ff100acSmrg    test -f "$tmpdepfile" && break
5169ff100acSmrg  done
5179ff100acSmrg  # Same post-processing that is required for AIX mode.
5189ff100acSmrg  aix_post_process_depfile
5199ff100acSmrg  ;;
5209ff100acSmrg
5219ff100acSmrgmsvc7)
5229ff100acSmrg  if test "$libtool" = yes; then
5239ff100acSmrg    showIncludes=-Wc,-showIncludes
5249ff100acSmrg  else
5259ff100acSmrg    showIncludes=-showIncludes
5269ff100acSmrg  fi
5279ff100acSmrg  "$@" $showIncludes > "$tmpdepfile"
5289ff100acSmrg  stat=$?
5299ff100acSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
5309ff100acSmrg  if test $stat -ne 0; then
5319ff100acSmrg    rm -f "$tmpdepfile"
5329ff100acSmrg    exit $stat
5339ff100acSmrg  fi
5349ff100acSmrg  rm -f "$depfile"
5359ff100acSmrg  echo "$object : \\" > "$depfile"
5369ff100acSmrg  # The first sed program below extracts the file names and escapes
5379ff100acSmrg  # backslashes for cygpath.  The second sed program outputs the file
5389ff100acSmrg  # name when reading, but also accumulates all include files in the
5399ff100acSmrg  # hold buffer in order to output them again at the end.  This only
5409ff100acSmrg  # works with sed implementations that can handle large buffers.
5419ff100acSmrg  sed < "$tmpdepfile" -n '
5429ff100acSmrg/^Note: including file:  *\(.*\)/ {
5439ff100acSmrg  s//\1/
5449ff100acSmrg  s/\\/\\\\/g
5459ff100acSmrg  p
5469ff100acSmrg}' | $cygpath_u | sort -u | sed -n '
5479ff100acSmrgs/ /\\ /g
5489ff100acSmrgs/\(.*\)/'"$tab"'\1 \\/p
5499ff100acSmrgs/.\(.*\) \\/\1:/
5509ff100acSmrgH
5519ff100acSmrg$ {
5529ff100acSmrg  s/.*/'"$tab"'/
5539ff100acSmrg  G
5549ff100acSmrg  p
5559ff100acSmrg}' >> "$depfile"
5569ff100acSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5579ff100acSmrg  rm -f "$tmpdepfile"
5589ff100acSmrg  ;;
5599ff100acSmrg
5609ff100acSmrgmsvc7msys)
5619ff100acSmrg  # This case exists only to let depend.m4 do its work.  It works by
5629ff100acSmrg  # looking at the text of this script.  This case will never be run,
5639ff100acSmrg  # since it is checked for above.
5649ff100acSmrg  exit 1
5659ff100acSmrg  ;;
56676910425Smrg
56776910425Smrg#nosideeffect)
56876910425Smrg  # This comment above is used by automake to tell side-effect
56976910425Smrg  # dependency tracking mechanisms from slower ones.
57076910425Smrg
57176910425Smrgdashmstdout)
57276910425Smrg  # Important note: in order to support this mode, a compiler *must*
57376910425Smrg  # always write the preprocessed file to stdout, regardless of -o.
57476910425Smrg  "$@" || exit $?
57576910425Smrg
57676910425Smrg  # Remove the call to Libtool.
57776910425Smrg  if test "$libtool" = yes; then
578db17cd6dSmrg    while test "X$1" != 'X--mode=compile'; do
57976910425Smrg      shift
58076910425Smrg    done
58176910425Smrg    shift
58276910425Smrg  fi
58376910425Smrg
5849ff100acSmrg  # Remove '-o $object'.
58576910425Smrg  IFS=" "
58676910425Smrg  for arg
58776910425Smrg  do
58876910425Smrg    case $arg in
58976910425Smrg    -o)
59076910425Smrg      shift
59176910425Smrg      ;;
59276910425Smrg    $object)
59376910425Smrg      shift
59476910425Smrg      ;;
59576910425Smrg    *)
59676910425Smrg      set fnord "$@" "$arg"
59776910425Smrg      shift # fnord
59876910425Smrg      shift # $arg
59976910425Smrg      ;;
60076910425Smrg    esac
60176910425Smrg  done
60276910425Smrg
60376910425Smrg  test -z "$dashmflag" && dashmflag=-M
6049ff100acSmrg  # Require at least two characters before searching for ':'
60576910425Smrg  # in the target name.  This is to cope with DOS-style filenames:
6069ff100acSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60776910425Smrg  "$@" $dashmflag |
6089ff100acSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60976910425Smrg  rm -f "$depfile"
61076910425Smrg  cat < "$tmpdepfile" > "$depfile"
6119ff100acSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6129ff100acSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6139ff100acSmrg  tr ' ' "$nl" < "$tmpdepfile" \
6149ff100acSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6159ff100acSmrg    | sed -e 's/$/ :/' >> "$depfile"
61676910425Smrg  rm -f "$tmpdepfile"
61776910425Smrg  ;;
61876910425Smrg
61976910425SmrgdashXmstdout)
62076910425Smrg  # This case only exists to satisfy depend.m4.  It is never actually
62176910425Smrg  # run, as this mode is specially recognized in the preamble.
62276910425Smrg  exit 1
62376910425Smrg  ;;
62476910425Smrg
62576910425Smrgmakedepend)
62676910425Smrg  "$@" || exit $?
62776910425Smrg  # Remove any Libtool call
62876910425Smrg  if test "$libtool" = yes; then
629db17cd6dSmrg    while test "X$1" != 'X--mode=compile'; do
63076910425Smrg      shift
63176910425Smrg    done
63276910425Smrg    shift
63376910425Smrg  fi
63476910425Smrg  # X makedepend
63576910425Smrg  shift
636db17cd6dSmrg  cleared=no eat=no
637db17cd6dSmrg  for arg
638db17cd6dSmrg  do
63976910425Smrg    case $cleared in
64076910425Smrg    no)
64176910425Smrg      set ""; shift
64276910425Smrg      cleared=yes ;;
64376910425Smrg    esac
644db17cd6dSmrg    if test $eat = yes; then
645db17cd6dSmrg      eat=no
646db17cd6dSmrg      continue
647db17cd6dSmrg    fi
64876910425Smrg    case "$arg" in
64976910425Smrg    -D*|-I*)
65076910425Smrg      set fnord "$@" "$arg"; shift ;;
65176910425Smrg    # Strip any option that makedepend may not understand.  Remove
65276910425Smrg    # the object too, otherwise makedepend will parse it as a source file.
653db17cd6dSmrg    -arch)
654db17cd6dSmrg      eat=yes ;;
65576910425Smrg    -*|$object)
65676910425Smrg      ;;
65776910425Smrg    *)
65876910425Smrg      set fnord "$@" "$arg"; shift ;;
65976910425Smrg    esac
66076910425Smrg  done
661db17cd6dSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66276910425Smrg  touch "$tmpdepfile"
66376910425Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66476910425Smrg  rm -f "$depfile"
6659ff100acSmrg  # makedepend may prepend the VPATH from the source file name to the object.
6669ff100acSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6679ff100acSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6689ff100acSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6699ff100acSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6709ff100acSmrg  sed '1,2d' "$tmpdepfile" \
6719ff100acSmrg    | tr ' ' "$nl" \
6729ff100acSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6739ff100acSmrg    | sed -e 's/$/ :/' >> "$depfile"
67476910425Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67576910425Smrg  ;;
67676910425Smrg
67776910425Smrgcpp)
67876910425Smrg  # Important note: in order to support this mode, a compiler *must*
67976910425Smrg  # always write the preprocessed file to stdout.
68076910425Smrg  "$@" || exit $?
68176910425Smrg
68276910425Smrg  # Remove the call to Libtool.
68376910425Smrg  if test "$libtool" = yes; then
684db17cd6dSmrg    while test "X$1" != 'X--mode=compile'; do
68576910425Smrg      shift
68676910425Smrg    done
68776910425Smrg    shift
68876910425Smrg  fi
68976910425Smrg
6909ff100acSmrg  # Remove '-o $object'.
69176910425Smrg  IFS=" "
69276910425Smrg  for arg
69376910425Smrg  do
69476910425Smrg    case $arg in
69576910425Smrg    -o)
69676910425Smrg      shift
69776910425Smrg      ;;
69876910425Smrg    $object)
69976910425Smrg      shift
70076910425Smrg      ;;
70176910425Smrg    *)
70276910425Smrg      set fnord "$@" "$arg"
70376910425Smrg      shift # fnord
70476910425Smrg      shift # $arg
70576910425Smrg      ;;
70676910425Smrg    esac
70776910425Smrg  done
70876910425Smrg
7099ff100acSmrg  "$@" -E \
7109ff100acSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7119ff100acSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7129ff100acSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
71376910425Smrg  rm -f "$depfile"
71476910425Smrg  echo "$object : \\" > "$depfile"
71576910425Smrg  cat < "$tmpdepfile" >> "$depfile"
71676910425Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71776910425Smrg  rm -f "$tmpdepfile"
71876910425Smrg  ;;
71976910425Smrg
72076910425Smrgmsvisualcpp)
72176910425Smrg  # Important note: in order to support this mode, a compiler *must*
722db17cd6dSmrg  # always write the preprocessed file to stdout.
72376910425Smrg  "$@" || exit $?
724db17cd6dSmrg
725db17cd6dSmrg  # Remove the call to Libtool.
726db17cd6dSmrg  if test "$libtool" = yes; then
727db17cd6dSmrg    while test "X$1" != 'X--mode=compile'; do
728db17cd6dSmrg      shift
729db17cd6dSmrg    done
730db17cd6dSmrg    shift
731db17cd6dSmrg  fi
732db17cd6dSmrg
73376910425Smrg  IFS=" "
73476910425Smrg  for arg
73576910425Smrg  do
73676910425Smrg    case "$arg" in
737db17cd6dSmrg    -o)
738db17cd6dSmrg      shift
739db17cd6dSmrg      ;;
740db17cd6dSmrg    $object)
741db17cd6dSmrg      shift
742db17cd6dSmrg      ;;
74376910425Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7449ff100acSmrg        set fnord "$@"
7459ff100acSmrg        shift
7469ff100acSmrg        shift
7479ff100acSmrg        ;;
74876910425Smrg    *)
7499ff100acSmrg        set fnord "$@" "$arg"
7509ff100acSmrg        shift
7519ff100acSmrg        shift
7529ff100acSmrg        ;;
75376910425Smrg    esac
75476910425Smrg  done
755db17cd6dSmrg  "$@" -E 2>/dev/null |
756db17cd6dSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75776910425Smrg  rm -f "$depfile"
75876910425Smrg  echo "$object : \\" > "$depfile"
7599ff100acSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7609ff100acSmrg  echo "$tab" >> "$depfile"
761db17cd6dSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76276910425Smrg  rm -f "$tmpdepfile"
76376910425Smrg  ;;
76476910425Smrg
765db17cd6dSmrgmsvcmsys)
766db17cd6dSmrg  # This case exists only to let depend.m4 do its work.  It works by
767db17cd6dSmrg  # looking at the text of this script.  This case will never be run,
768db17cd6dSmrg  # since it is checked for above.
769db17cd6dSmrg  exit 1
770db17cd6dSmrg  ;;
771db17cd6dSmrg
77276910425Smrgnone)
77376910425Smrg  exec "$@"
77476910425Smrg  ;;
77576910425Smrg
77676910425Smrg*)
77776910425Smrg  echo "Unknown depmode $depmode" 1>&2
77876910425Smrg  exit 1
77976910425Smrg  ;;
78076910425Smrgesac
78176910425Smrg
78276910425Smrgexit 0
78376910425Smrg
78476910425Smrg# Local Variables:
78576910425Smrg# mode: shell-script
78676910425Smrg# sh-indentation: 2
787a67f45c3Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
78876910425Smrg# time-stamp-start: "scriptversion="
78976910425Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
790a67f45c3Smrg# time-stamp-time-zone: "UTC0"
791db17cd6dSmrg# time-stamp-end: "; # UTC"
79276910425Smrg# End:
793