19fe995a9Smrg#! /bin/sh
29fe995a9Smrg# depcomp - compile a program generating dependencies as side-effects
39fe995a9Smrg
4c048b52eSmrgscriptversion=2018-03-07.03; # UTC
59fe995a9Smrg
6c048b52eSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
79fe995a9Smrg
89fe995a9Smrg# This program is free software; you can redistribute it and/or modify
99fe995a9Smrg# it under the terms of the GNU General Public License as published by
109fe995a9Smrg# the Free Software Foundation; either version 2, or (at your option)
119fe995a9Smrg# any later version.
129fe995a9Smrg
139fe995a9Smrg# This program is distributed in the hope that it will be useful,
149fe995a9Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
159fe995a9Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
169fe995a9Smrg# GNU General Public License for more details.
179fe995a9Smrg
189fe995a9Smrg# You should have received a copy of the GNU General Public License
19c048b52eSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
209fe995a9Smrg
219fe995a9Smrg# As a special exception to the GNU General Public License, if you
229fe995a9Smrg# distribute this file as part of a program that contains a
239fe995a9Smrg# configuration script generated by Autoconf, you may include it under
249fe995a9Smrg# the same distribution terms that you use for the rest of that program.
259fe995a9Smrg
269fe995a9Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
279fe995a9Smrg
289fe995a9Smrgcase $1 in
299fe995a9Smrg  '')
309d794632Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
319d794632Smrg    exit 1;
329d794632Smrg    ;;
339fe995a9Smrg  -h | --h*)
349fe995a9Smrg    cat <<\EOF
359fe995a9SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
369fe995a9Smrg
379fe995a9SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
389fe995a9Smrgas side-effects.
399fe995a9Smrg
409fe995a9SmrgEnvironment variables:
419fe995a9Smrg  depmode     Dependency tracking mode.
429d794632Smrg  source      Source file read by 'PROGRAMS ARGS'.
439d794632Smrg  object      Object file output by 'PROGRAMS ARGS'.
449fe995a9Smrg  DEPDIR      directory where to store dependencies.
459fe995a9Smrg  depfile     Dependency file to output.
469d794632Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
479fe995a9Smrg  libtool     Whether libtool is used (yes/no).
489fe995a9Smrg
499fe995a9SmrgReport bugs to <bug-automake@gnu.org>.
509fe995a9SmrgEOF
519fe995a9Smrg    exit $?
529fe995a9Smrg    ;;
539fe995a9Smrg  -v | --v*)
549fe995a9Smrg    echo "depcomp $scriptversion"
559fe995a9Smrg    exit $?
569fe995a9Smrg    ;;
579fe995a9Smrgesac
589fe995a9Smrg
599d794632Smrg# Get the directory component of the given path, and save it in the
609d794632Smrg# global variables '$dir'.  Note that this directory component will
619d794632Smrg# be either empty or ending with a '/' character.  This is deliberate.
629d794632Smrgset_dir_from ()
639d794632Smrg{
649d794632Smrg  case $1 in
659d794632Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
669d794632Smrg      *) dir=;;
679d794632Smrg  esac
689d794632Smrg}
699d794632Smrg
709d794632Smrg# Get the suffix-stripped basename of the given path, and save it the
719d794632Smrg# global variable '$base'.
729d794632Smrgset_base_from ()
739d794632Smrg{
749d794632Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
759d794632Smrg}
769d794632Smrg
779d794632Smrg# If no dependency file was actually created by the compiler invocation,
789d794632Smrg# we still have to create a dummy depfile, to avoid errors with the
799d794632Smrg# Makefile "include basename.Plo" scheme.
809d794632Smrgmake_dummy_depfile ()
819d794632Smrg{
829d794632Smrg  echo "#dummy" > "$depfile"
839d794632Smrg}
849d794632Smrg
859d794632Smrg# Factor out some common post-processing of the generated depfile.
869d794632Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
879d794632Smrgaix_post_process_depfile ()
889d794632Smrg{
899d794632Smrg  # If the compiler actually managed to produce a dependency file,
909d794632Smrg  # post-process it.
919d794632Smrg  if test -f "$tmpdepfile"; then
929d794632Smrg    # Each line is of the form 'foo.o: dependency.h'.
939d794632Smrg    # Do two passes, one to just change these to
949d794632Smrg    #   $object: dependency.h
959d794632Smrg    # and one to simply output
969d794632Smrg    #   dependency.h:
979d794632Smrg    # which is needed to avoid the deleted-header problem.
989d794632Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
999d794632Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1009d794632Smrg    } > "$depfile"
1019d794632Smrg    rm -f "$tmpdepfile"
1029d794632Smrg  else
1039d794632Smrg    make_dummy_depfile
1049d794632Smrg  fi
1059d794632Smrg}
1069d794632Smrg
1079d794632Smrg# A tabulation character.
1089d794632Smrgtab='	'
1099d794632Smrg# A newline character.
1109d794632Smrgnl='
1119d794632Smrg'
1129d794632Smrg# Character ranges might be problematic outside the C locale.
1139d794632Smrg# These definitions help.
1149d794632Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1159d794632Smrglower=abcdefghijklmnopqrstuvwxyz
1169d794632Smrgdigits=0123456789
1179d794632Smrgalpha=${upper}${lower}
1189d794632Smrg
1199fe995a9Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1209fe995a9Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1219fe995a9Smrg  exit 1
1229fe995a9Smrgfi
1239fe995a9Smrg
1249fe995a9Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1259fe995a9Smrgdepfile=${depfile-`echo "$object" |
1269fe995a9Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1279fe995a9Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1289fe995a9Smrg
1299fe995a9Smrgrm -f "$tmpdepfile"
1309fe995a9Smrg
1319d794632Smrg# Avoid interferences from the environment.
1329d794632Smrggccflag= dashmflag=
1339d794632Smrg
1349fe995a9Smrg# Some modes work just like other modes, but use different flags.  We
1359fe995a9Smrg# parameterize here, but still list the modes in the big case below,
1369fe995a9Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1379fe995a9Smrg# here, because this file can only contain one case statement.
1389fe995a9Smrgif test "$depmode" = hp; then
1399fe995a9Smrg  # HP compiler uses -M and no extra arg.
1409fe995a9Smrg  gccflag=-M
1419fe995a9Smrg  depmode=gcc
1429fe995a9Smrgfi
1439fe995a9Smrg
1449fe995a9Smrgif test "$depmode" = dashXmstdout; then
1459d794632Smrg  # This is just like dashmstdout with a different argument.
1469d794632Smrg  dashmflag=-xM
1479d794632Smrg  depmode=dashmstdout
1489fe995a9Smrgfi
1499fe995a9Smrg
150b62cc08cSmrgcygpath_u="cygpath -u -f -"
151b62cc08cSmrgif test "$depmode" = msvcmsys; then
1529d794632Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1539d794632Smrg  # Just convert the backslash-escaped backslashes to single forward
1549d794632Smrg  # slashes to satisfy depend.m4
1559d794632Smrg  cygpath_u='sed s,\\\\,/,g'
1569d794632Smrg  depmode=msvisualcpp
1579d794632Smrgfi
1589d794632Smrg
1599d794632Smrgif test "$depmode" = msvc7msys; then
1609d794632Smrg  # This is just like msvc7 but w/o cygpath translation.
1619d794632Smrg  # Just convert the backslash-escaped backslashes to single forward
1629d794632Smrg  # slashes to satisfy depend.m4
1639d794632Smrg  cygpath_u='sed s,\\\\,/,g'
1649d794632Smrg  depmode=msvc7
1659d794632Smrgfi
1669d794632Smrg
1679d794632Smrgif test "$depmode" = xlc; then
1689d794632Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1699d794632Smrg  gccflag=-qmakedep=gcc,-MF
1709d794632Smrg  depmode=gcc
171b62cc08cSmrgfi
172b62cc08cSmrg
1739fe995a9Smrgcase "$depmode" in
1749fe995a9Smrggcc3)
1759fe995a9Smrg## gcc 3 implements dependency tracking that does exactly what
1769fe995a9Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1779fe995a9Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1789fe995a9Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1799fe995a9Smrg## the command line argument order; so add the flags where they
1809fe995a9Smrg## appear in depend2.am.  Note that the slowdown incurred here
1819fe995a9Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1829fe995a9Smrg  for arg
1839fe995a9Smrg  do
1849fe995a9Smrg    case $arg in
1859fe995a9Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1869fe995a9Smrg    *)  set fnord "$@" "$arg" ;;
1879fe995a9Smrg    esac
1889fe995a9Smrg    shift # fnord
1899fe995a9Smrg    shift # $arg
1909fe995a9Smrg  done
1919fe995a9Smrg  "$@"
1929fe995a9Smrg  stat=$?
1939d794632Smrg  if test $stat -ne 0; then
1949fe995a9Smrg    rm -f "$tmpdepfile"
1959fe995a9Smrg    exit $stat
1969fe995a9Smrg  fi
1979fe995a9Smrg  mv "$tmpdepfile" "$depfile"
1989fe995a9Smrg  ;;
1999fe995a9Smrg
2009fe995a9Smrggcc)
2019d794632Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2029d794632Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2039d794632Smrg## (see the conditional assignment to $gccflag above).
2049fe995a9Smrg## There are various ways to get dependency output from gcc.  Here's
2059fe995a9Smrg## why we pick this rather obscure method:
2069fe995a9Smrg## - Don't want to use -MD because we'd like the dependencies to end
2079fe995a9Smrg##   up in a subdir.  Having to rename by hand is ugly.
2089fe995a9Smrg##   (We might end up doing this anyway to support other compilers.)
2099fe995a9Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2109d794632Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2119d794632Smrg##   supported by the other compilers which use the 'gcc' depmode.
2129fe995a9Smrg## - Using -M directly means running the compiler twice (even worse
2139fe995a9Smrg##   than renaming).
2149fe995a9Smrg  if test -z "$gccflag"; then
2159fe995a9Smrg    gccflag=-MD,
2169fe995a9Smrg  fi
2179fe995a9Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
2189fe995a9Smrg  stat=$?
2199d794632Smrg  if test $stat -ne 0; then
2209fe995a9Smrg    rm -f "$tmpdepfile"
2219fe995a9Smrg    exit $stat
2229fe995a9Smrg  fi
2239fe995a9Smrg  rm -f "$depfile"
2249fe995a9Smrg  echo "$object : \\" > "$depfile"
2259d794632Smrg  # The second -e expression handles DOS-style file names with drive
2269d794632Smrg  # letters.
2279fe995a9Smrg  sed -e 's/^[^:]*: / /' \
2289fe995a9Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2299d794632Smrg## This next piece of magic avoids the "deleted header file" problem.
2309fe995a9Smrg## The problem is that when a header file which appears in a .P file
2319fe995a9Smrg## is deleted, the dependency causes make to die (because there is
2329fe995a9Smrg## typically no way to rebuild the header).  We avoid this by adding
2339fe995a9Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2349fe995a9Smrg## this for us directly.
2359d794632Smrg## Some versions of gcc put a space before the ':'.  On the theory
2369fe995a9Smrg## that the space means something, we add a space to the output as
2379d794632Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2389d794632Smrg## to the object.  Take care to not repeat it in the output.
2399fe995a9Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
2409fe995a9Smrg## correctly.  Breaking it into two sed invocations is a workaround.
2419d794632Smrg  tr ' ' "$nl" < "$tmpdepfile" \
2429d794632Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2439d794632Smrg    | sed -e 's/$/ :/' >> "$depfile"
2449fe995a9Smrg  rm -f "$tmpdepfile"
2459fe995a9Smrg  ;;
2469fe995a9Smrg
2479fe995a9Smrghp)
2489fe995a9Smrg  # This case exists only to let depend.m4 do its work.  It works by
2499fe995a9Smrg  # looking at the text of this script.  This case will never be run,
2509fe995a9Smrg  # since it is checked for above.
2519fe995a9Smrg  exit 1
2529fe995a9Smrg  ;;
2539fe995a9Smrg
2549fe995a9Smrgsgi)
2559fe995a9Smrg  if test "$libtool" = yes; then
2569fe995a9Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2579fe995a9Smrg  else
2589fe995a9Smrg    "$@" -MDupdate "$tmpdepfile"
2599fe995a9Smrg  fi
2609fe995a9Smrg  stat=$?
2619d794632Smrg  if test $stat -ne 0; then
2629fe995a9Smrg    rm -f "$tmpdepfile"
2639fe995a9Smrg    exit $stat
2649fe995a9Smrg  fi
2659fe995a9Smrg  rm -f "$depfile"
2669fe995a9Smrg
2679fe995a9Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2689fe995a9Smrg    echo "$object : \\" > "$depfile"
2699fe995a9Smrg    # Clip off the initial element (the dependent).  Don't try to be
2709fe995a9Smrg    # clever and replace this with sed code, as IRIX sed won't handle
2719fe995a9Smrg    # lines with more than a fixed number of characters (4096 in
2729fe995a9Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2739d794632Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
2749fe995a9Smrg    # dependency line.
2759d794632Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2769d794632Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2779d794632Smrg      | tr "$nl" ' ' >> "$depfile"
278b62cc08cSmrg    echo >> "$depfile"
2799fe995a9Smrg    # The second pass generates a dummy entry for each header file.
2809d794632Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2819d794632Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2829d794632Smrg      >> "$depfile"
2839fe995a9Smrg  else
2849d794632Smrg    make_dummy_depfile
2859fe995a9Smrg  fi
2869fe995a9Smrg  rm -f "$tmpdepfile"
2879fe995a9Smrg  ;;
2889fe995a9Smrg
2899d794632Smrgxlc)
2909d794632Smrg  # This case exists only to let depend.m4 do its work.  It works by
2919d794632Smrg  # looking at the text of this script.  This case will never be run,
2929d794632Smrg  # since it is checked for above.
2939d794632Smrg  exit 1
2949d794632Smrg  ;;
2959d794632Smrg
2969fe995a9Smrgaix)
2979fe995a9Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2989fe995a9Smrg  # in a .u file.  In older versions, this file always lives in the
2999d794632Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3009fe995a9Smrg  # start of each line; $object doesn't have directory information.
3019fe995a9Smrg  # Version 6 uses the directory in both cases.
3029d794632Smrg  set_dir_from "$object"
3039d794632Smrg  set_base_from "$object"
3049fe995a9Smrg  if test "$libtool" = yes; then
305b62cc08cSmrg    tmpdepfile1=$dir$base.u
306b62cc08cSmrg    tmpdepfile2=$base.u
307b62cc08cSmrg    tmpdepfile3=$dir.libs/$base.u
3089fe995a9Smrg    "$@" -Wc,-M
3099fe995a9Smrg  else
310b62cc08cSmrg    tmpdepfile1=$dir$base.u
311b62cc08cSmrg    tmpdepfile2=$dir$base.u
312b62cc08cSmrg    tmpdepfile3=$dir$base.u
3139fe995a9Smrg    "$@" -M
3149fe995a9Smrg  fi
3159fe995a9Smrg  stat=$?
3169d794632Smrg  if test $stat -ne 0; then
317b62cc08cSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3189fe995a9Smrg    exit $stat
3199fe995a9Smrg  fi
3209fe995a9Smrg
321b62cc08cSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322b62cc08cSmrg  do
323b62cc08cSmrg    test -f "$tmpdepfile" && break
324b62cc08cSmrg  done
3259d794632Smrg  aix_post_process_depfile
3269d794632Smrg  ;;
3279d794632Smrg
3289d794632Smrgtcc)
3299d794632Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3309d794632Smrg  # FIXME: That version still under development at the moment of writing.
3319d794632Smrg  #        Make that this statement remains true also for stable, released
3329d794632Smrg  #        versions.
3339d794632Smrg  # It will wrap lines (doesn't matter whether long or short) with a
3349d794632Smrg  # trailing '\', as in:
3359d794632Smrg  #
3369d794632Smrg  #   foo.o : \
3379d794632Smrg  #    foo.c \
3389d794632Smrg  #    foo.h \
3399d794632Smrg  #
3409d794632Smrg  # It will put a trailing '\' even on the last line, and will use leading
3419d794632Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3429d794632Smrg  # "Emit spaces for -MD").
3439d794632Smrg  "$@" -MD -MF "$tmpdepfile"
3449d794632Smrg  stat=$?
3459d794632Smrg  if test $stat -ne 0; then
3469d794632Smrg    rm -f "$tmpdepfile"
3479d794632Smrg    exit $stat
3489fe995a9Smrg  fi
3499d794632Smrg  rm -f "$depfile"
3509d794632Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3519d794632Smrg  # We have to change lines of the first kind to '$object: \'.
3529d794632Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3539d794632Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3549d794632Smrg  # dummy dependency, to avoid the deleted-header problem.
3559d794632Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3569fe995a9Smrg  rm -f "$tmpdepfile"
3579fe995a9Smrg  ;;
3589fe995a9Smrg
3599d794632Smrg## The order of this option in the case statement is important, since the
3609d794632Smrg## shell code in configure will try each of these formats in the order
3619d794632Smrg## listed in this file.  A plain '-MD' option would be understood by many
3629d794632Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3639d794632Smrgpgcc)
3649d794632Smrg  # Portland's C compiler understands '-MD'.
3659d794632Smrg  # Will always output deps to 'file.d' where file is the root name of the
3669d794632Smrg  # source file under compilation, even if file resides in a subdirectory.
3679d794632Smrg  # The object file name does not affect the name of the '.d' file.
3689d794632Smrg  # pgcc 10.2 will output
3699fe995a9Smrg  #    foo.o: sub/foo.c sub/foo.h
3709d794632Smrg  # and will wrap long lines using '\' :
3719fe995a9Smrg  #    foo.o: sub/foo.c ... \
3729fe995a9Smrg  #     sub/foo.h ... \
3739fe995a9Smrg  #     ...
3749d794632Smrg  set_dir_from "$object"
3759d794632Smrg  # Use the source, not the object, to determine the base name, since
3769d794632Smrg  # that's sadly what pgcc will do too.
3779d794632Smrg  set_base_from "$source"
3789d794632Smrg  tmpdepfile=$base.d
3799d794632Smrg
3809d794632Smrg  # For projects that build the same source file twice into different object
3819d794632Smrg  # files, the pgcc approach of using the *source* file root name can cause
3829d794632Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3839d794632Smrg  # the same $tmpdepfile.
3849d794632Smrg  lockdir=$base.d-lock
3859d794632Smrg  trap "
3869d794632Smrg    echo '$0: caught signal, cleaning up...' >&2
3879d794632Smrg    rmdir '$lockdir'
3889d794632Smrg    exit 1
3899d794632Smrg  " 1 2 13 15
3909d794632Smrg  numtries=100
3919d794632Smrg  i=$numtries
3929d794632Smrg  while test $i -gt 0; do
3939d794632Smrg    # mkdir is a portable test-and-set.
3949d794632Smrg    if mkdir "$lockdir" 2>/dev/null; then
3959d794632Smrg      # This process acquired the lock.
3969d794632Smrg      "$@" -MD
3979d794632Smrg      stat=$?
3989d794632Smrg      # Release the lock.
3999d794632Smrg      rmdir "$lockdir"
4009d794632Smrg      break
4019d794632Smrg    else
4029d794632Smrg      # If the lock is being held by a different process, wait
4039d794632Smrg      # until the winning process is done or we timeout.
4049d794632Smrg      while test -d "$lockdir" && test $i -gt 0; do
4059d794632Smrg        sleep 1
4069d794632Smrg        i=`expr $i - 1`
4079d794632Smrg      done
4089d794632Smrg    fi
4099d794632Smrg    i=`expr $i - 1`
4109d794632Smrg  done
4119d794632Smrg  trap - 1 2 13 15
4129d794632Smrg  if test $i -le 0; then
4139d794632Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4149d794632Smrg    echo "$0: check lockdir '$lockdir'" >&2
4159d794632Smrg    exit 1
4169d794632Smrg  fi
4179fe995a9Smrg
4189d794632Smrg  if test $stat -ne 0; then
4199fe995a9Smrg    rm -f "$tmpdepfile"
4209fe995a9Smrg    exit $stat
4219fe995a9Smrg  fi
4229fe995a9Smrg  rm -f "$depfile"
4239fe995a9Smrg  # Each line is of the form `foo.o: dependent.h',
4249fe995a9Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4259fe995a9Smrg  # Do two passes, one to just change these to
4269fe995a9Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4279fe995a9Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4289fe995a9Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4299fe995a9Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
4309d794632Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4319d794632Smrg    | sed -e 's/$/ :/' >> "$depfile"
4329fe995a9Smrg  rm -f "$tmpdepfile"
4339fe995a9Smrg  ;;
4349fe995a9Smrg
4359fe995a9Smrghp2)
4369fe995a9Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4379fe995a9Smrg  # compilers, which have integrated preprocessors.  The correct option
4389fe995a9Smrg  # to use with these is +Maked; it writes dependencies to a file named
4399fe995a9Smrg  # 'foo.d', which lands next to the object file, wherever that
4409fe995a9Smrg  # happens to be.
4419fe995a9Smrg  # Much of this is similar to the tru64 case; see comments there.
4429d794632Smrg  set_dir_from  "$object"
4439d794632Smrg  set_base_from "$object"
4449fe995a9Smrg  if test "$libtool" = yes; then
4459fe995a9Smrg    tmpdepfile1=$dir$base.d
4469fe995a9Smrg    tmpdepfile2=$dir.libs/$base.d
4479fe995a9Smrg    "$@" -Wc,+Maked
4489fe995a9Smrg  else
4499fe995a9Smrg    tmpdepfile1=$dir$base.d
4509fe995a9Smrg    tmpdepfile2=$dir$base.d
4519fe995a9Smrg    "$@" +Maked
4529fe995a9Smrg  fi
4539fe995a9Smrg  stat=$?
4549d794632Smrg  if test $stat -ne 0; then
4559fe995a9Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4569fe995a9Smrg     exit $stat
4579fe995a9Smrg  fi
4589fe995a9Smrg
4599fe995a9Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4609fe995a9Smrg  do
4619fe995a9Smrg    test -f "$tmpdepfile" && break
4629fe995a9Smrg  done
4639fe995a9Smrg  if test -f "$tmpdepfile"; then
4649d794632Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4659d794632Smrg    # Add 'dependent.h:' lines.
466b62cc08cSmrg    sed -ne '2,${
4679d794632Smrg               s/^ *//
4689d794632Smrg               s/ \\*$//
4699d794632Smrg               s/$/:/
4709d794632Smrg               p
4719d794632Smrg             }' "$tmpdepfile" >> "$depfile"
4729fe995a9Smrg  else
4739d794632Smrg    make_dummy_depfile
4749fe995a9Smrg  fi
4759fe995a9Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4769fe995a9Smrg  ;;
4779fe995a9Smrg
4789fe995a9Smrgtru64)
4799d794632Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4809d794632Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4819d794632Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4829d794632Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4839d794632Smrg  # Subdirectories are respected.
4849d794632Smrg  set_dir_from  "$object"
4859d794632Smrg  set_base_from "$object"
4869d794632Smrg
4879d794632Smrg  if test "$libtool" = yes; then
4889d794632Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4899d794632Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4909d794632Smrg    # in $dir$base.o.d.  We have to check for both files, because
4919d794632Smrg    # one of the two compilations can be disabled.  We should prefer
4929d794632Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4939d794632Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4949d794632Smrg    # the former would cause a distcleancheck panic.
4959d794632Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4969d794632Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4979d794632Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4989d794632Smrg    "$@" -Wc,-MD
4999d794632Smrg  else
5009d794632Smrg    tmpdepfile1=$dir$base.d
5019d794632Smrg    tmpdepfile2=$dir$base.d
5029d794632Smrg    tmpdepfile3=$dir$base.d
5039d794632Smrg    "$@" -MD
5049d794632Smrg  fi
5059d794632Smrg
5069d794632Smrg  stat=$?
5079d794632Smrg  if test $stat -ne 0; then
5089d794632Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5099d794632Smrg    exit $stat
5109d794632Smrg  fi
5119d794632Smrg
5129d794632Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5139d794632Smrg  do
5149d794632Smrg    test -f "$tmpdepfile" && break
5159d794632Smrg  done
5169d794632Smrg  # Same post-processing that is required for AIX mode.
5179d794632Smrg  aix_post_process_depfile
5189d794632Smrg  ;;
5199d794632Smrg
5209d794632Smrgmsvc7)
5219d794632Smrg  if test "$libtool" = yes; then
5229d794632Smrg    showIncludes=-Wc,-showIncludes
5239d794632Smrg  else
5249d794632Smrg    showIncludes=-showIncludes
5259d794632Smrg  fi
5269d794632Smrg  "$@" $showIncludes > "$tmpdepfile"
5279d794632Smrg  stat=$?
5289d794632Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5299d794632Smrg  if test $stat -ne 0; then
5309d794632Smrg    rm -f "$tmpdepfile"
5319d794632Smrg    exit $stat
5329d794632Smrg  fi
5339d794632Smrg  rm -f "$depfile"
5349d794632Smrg  echo "$object : \\" > "$depfile"
5359d794632Smrg  # The first sed program below extracts the file names and escapes
5369d794632Smrg  # backslashes for cygpath.  The second sed program outputs the file
5379d794632Smrg  # name when reading, but also accumulates all include files in the
5389d794632Smrg  # hold buffer in order to output them again at the end.  This only
5399d794632Smrg  # works with sed implementations that can handle large buffers.
5409d794632Smrg  sed < "$tmpdepfile" -n '
5419d794632Smrg/^Note: including file:  *\(.*\)/ {
5429d794632Smrg  s//\1/
5439d794632Smrg  s/\\/\\\\/g
5449d794632Smrg  p
5459d794632Smrg}' | $cygpath_u | sort -u | sed -n '
5469d794632Smrgs/ /\\ /g
5479d794632Smrgs/\(.*\)/'"$tab"'\1 \\/p
5489d794632Smrgs/.\(.*\) \\/\1:/
5499d794632SmrgH
5509d794632Smrg$ {
5519d794632Smrg  s/.*/'"$tab"'/
5529d794632Smrg  G
5539d794632Smrg  p
5549d794632Smrg}' >> "$depfile"
5559d794632Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5569d794632Smrg  rm -f "$tmpdepfile"
5579d794632Smrg  ;;
5589d794632Smrg
5599d794632Smrgmsvc7msys)
5609d794632Smrg  # This case exists only to let depend.m4 do its work.  It works by
5619d794632Smrg  # looking at the text of this script.  This case will never be run,
5629d794632Smrg  # since it is checked for above.
5639d794632Smrg  exit 1
5649d794632Smrg  ;;
5659fe995a9Smrg
5669fe995a9Smrg#nosideeffect)
5679fe995a9Smrg  # This comment above is used by automake to tell side-effect
5689fe995a9Smrg  # dependency tracking mechanisms from slower ones.
5699fe995a9Smrg
5709fe995a9Smrgdashmstdout)
5719fe995a9Smrg  # Important note: in order to support this mode, a compiler *must*
5729fe995a9Smrg  # always write the preprocessed file to stdout, regardless of -o.
5739fe995a9Smrg  "$@" || exit $?
5749fe995a9Smrg
5759fe995a9Smrg  # Remove the call to Libtool.
5769fe995a9Smrg  if test "$libtool" = yes; then
577b62cc08cSmrg    while test "X$1" != 'X--mode=compile'; do
5789fe995a9Smrg      shift
5799fe995a9Smrg    done
5809fe995a9Smrg    shift
5819fe995a9Smrg  fi
5829fe995a9Smrg
5839d794632Smrg  # Remove '-o $object'.
5849fe995a9Smrg  IFS=" "
5859fe995a9Smrg  for arg
5869fe995a9Smrg  do
5879fe995a9Smrg    case $arg in
5889fe995a9Smrg    -o)
5899fe995a9Smrg      shift
5909fe995a9Smrg      ;;
5919fe995a9Smrg    $object)
5929fe995a9Smrg      shift
5939fe995a9Smrg      ;;
5949fe995a9Smrg    *)
5959fe995a9Smrg      set fnord "$@" "$arg"
5969fe995a9Smrg      shift # fnord
5979fe995a9Smrg      shift # $arg
5989fe995a9Smrg      ;;
5999fe995a9Smrg    esac
6009fe995a9Smrg  done
6019fe995a9Smrg
6029fe995a9Smrg  test -z "$dashmflag" && dashmflag=-M
6039d794632Smrg  # Require at least two characters before searching for ':'
6049fe995a9Smrg  # in the target name.  This is to cope with DOS-style filenames:
6059d794632Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6069fe995a9Smrg  "$@" $dashmflag |
6079d794632Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6089fe995a9Smrg  rm -f "$depfile"
6099fe995a9Smrg  cat < "$tmpdepfile" > "$depfile"
6109d794632Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6119d794632Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6129d794632Smrg  tr ' ' "$nl" < "$tmpdepfile" \
6139d794632Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6149d794632Smrg    | sed -e 's/$/ :/' >> "$depfile"
6159fe995a9Smrg  rm -f "$tmpdepfile"
6169fe995a9Smrg  ;;
6179fe995a9Smrg
6189fe995a9SmrgdashXmstdout)
6199fe995a9Smrg  # This case only exists to satisfy depend.m4.  It is never actually
6209fe995a9Smrg  # run, as this mode is specially recognized in the preamble.
6219fe995a9Smrg  exit 1
6229fe995a9Smrg  ;;
6239fe995a9Smrg
6249fe995a9Smrgmakedepend)
6259fe995a9Smrg  "$@" || exit $?
6269fe995a9Smrg  # Remove any Libtool call
6279fe995a9Smrg  if test "$libtool" = yes; then
628b62cc08cSmrg    while test "X$1" != 'X--mode=compile'; do
6299fe995a9Smrg      shift
6309fe995a9Smrg    done
6319fe995a9Smrg    shift
6329fe995a9Smrg  fi
6339fe995a9Smrg  # X makedepend
6349fe995a9Smrg  shift
635b62cc08cSmrg  cleared=no eat=no
636b62cc08cSmrg  for arg
637b62cc08cSmrg  do
6389fe995a9Smrg    case $cleared in
6399fe995a9Smrg    no)
6409fe995a9Smrg      set ""; shift
6419fe995a9Smrg      cleared=yes ;;
6429fe995a9Smrg    esac
643b62cc08cSmrg    if test $eat = yes; then
644b62cc08cSmrg      eat=no
645b62cc08cSmrg      continue
646b62cc08cSmrg    fi
6479fe995a9Smrg    case "$arg" in
6489fe995a9Smrg    -D*|-I*)
6499fe995a9Smrg      set fnord "$@" "$arg"; shift ;;
6509fe995a9Smrg    # Strip any option that makedepend may not understand.  Remove
6519fe995a9Smrg    # the object too, otherwise makedepend will parse it as a source file.
652b62cc08cSmrg    -arch)
653b62cc08cSmrg      eat=yes ;;
6549fe995a9Smrg    -*|$object)
6559fe995a9Smrg      ;;
6569fe995a9Smrg    *)
6579fe995a9Smrg      set fnord "$@" "$arg"; shift ;;
6589fe995a9Smrg    esac
6599fe995a9Smrg  done
660b62cc08cSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6619fe995a9Smrg  touch "$tmpdepfile"
6629fe995a9Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6639fe995a9Smrg  rm -f "$depfile"
6649d794632Smrg  # makedepend may prepend the VPATH from the source file name to the object.
6659d794632Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6669d794632Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6679d794632Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6689d794632Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6699d794632Smrg  sed '1,2d' "$tmpdepfile" \
6709d794632Smrg    | tr ' ' "$nl" \
6719d794632Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6729d794632Smrg    | sed -e 's/$/ :/' >> "$depfile"
6739fe995a9Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6749fe995a9Smrg  ;;
6759fe995a9Smrg
6769fe995a9Smrgcpp)
6779fe995a9Smrg  # Important note: in order to support this mode, a compiler *must*
6789fe995a9Smrg  # always write the preprocessed file to stdout.
6799fe995a9Smrg  "$@" || exit $?
6809fe995a9Smrg
6819fe995a9Smrg  # Remove the call to Libtool.
6829fe995a9Smrg  if test "$libtool" = yes; then
683b62cc08cSmrg    while test "X$1" != 'X--mode=compile'; do
6849fe995a9Smrg      shift
6859fe995a9Smrg    done
6869fe995a9Smrg    shift
6879fe995a9Smrg  fi
6889fe995a9Smrg
6899d794632Smrg  # Remove '-o $object'.
6909fe995a9Smrg  IFS=" "
6919fe995a9Smrg  for arg
6929fe995a9Smrg  do
6939fe995a9Smrg    case $arg in
6949fe995a9Smrg    -o)
6959fe995a9Smrg      shift
6969fe995a9Smrg      ;;
6979fe995a9Smrg    $object)
6989fe995a9Smrg      shift
6999fe995a9Smrg      ;;
7009fe995a9Smrg    *)
7019fe995a9Smrg      set fnord "$@" "$arg"
7029fe995a9Smrg      shift # fnord
7039fe995a9Smrg      shift # $arg
7049fe995a9Smrg      ;;
7059fe995a9Smrg    esac
7069fe995a9Smrg  done
7079fe995a9Smrg
7089d794632Smrg  "$@" -E \
7099d794632Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7109d794632Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7119d794632Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
7129fe995a9Smrg  rm -f "$depfile"
7139fe995a9Smrg  echo "$object : \\" > "$depfile"
7149fe995a9Smrg  cat < "$tmpdepfile" >> "$depfile"
7159fe995a9Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7169fe995a9Smrg  rm -f "$tmpdepfile"
7179fe995a9Smrg  ;;
7189fe995a9Smrg
7199fe995a9Smrgmsvisualcpp)
7209fe995a9Smrg  # Important note: in order to support this mode, a compiler *must*
721b62cc08cSmrg  # always write the preprocessed file to stdout.
7229fe995a9Smrg  "$@" || exit $?
723b62cc08cSmrg
724b62cc08cSmrg  # Remove the call to Libtool.
725b62cc08cSmrg  if test "$libtool" = yes; then
726b62cc08cSmrg    while test "X$1" != 'X--mode=compile'; do
727b62cc08cSmrg      shift
728b62cc08cSmrg    done
729b62cc08cSmrg    shift
730b62cc08cSmrg  fi
731b62cc08cSmrg
7329fe995a9Smrg  IFS=" "
7339fe995a9Smrg  for arg
7349fe995a9Smrg  do
7359fe995a9Smrg    case "$arg" in
736b62cc08cSmrg    -o)
737b62cc08cSmrg      shift
738b62cc08cSmrg      ;;
739b62cc08cSmrg    $object)
740b62cc08cSmrg      shift
741b62cc08cSmrg      ;;
7429fe995a9Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7439d794632Smrg        set fnord "$@"
7449d794632Smrg        shift
7459d794632Smrg        shift
7469d794632Smrg        ;;
7479fe995a9Smrg    *)
7489d794632Smrg        set fnord "$@" "$arg"
7499d794632Smrg        shift
7509d794632Smrg        shift
7519d794632Smrg        ;;
7529fe995a9Smrg    esac
7539fe995a9Smrg  done
754b62cc08cSmrg  "$@" -E 2>/dev/null |
755b62cc08cSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7569fe995a9Smrg  rm -f "$depfile"
7579fe995a9Smrg  echo "$object : \\" > "$depfile"
7589d794632Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7599d794632Smrg  echo "$tab" >> "$depfile"
760b62cc08cSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7619fe995a9Smrg  rm -f "$tmpdepfile"
7629fe995a9Smrg  ;;
7639fe995a9Smrg
764b62cc08cSmrgmsvcmsys)
765b62cc08cSmrg  # This case exists only to let depend.m4 do its work.  It works by
766b62cc08cSmrg  # looking at the text of this script.  This case will never be run,
767b62cc08cSmrg  # since it is checked for above.
768b62cc08cSmrg  exit 1
769b62cc08cSmrg  ;;
770b62cc08cSmrg
7719fe995a9Smrgnone)
7729fe995a9Smrg  exec "$@"
7739fe995a9Smrg  ;;
7749fe995a9Smrg
7759fe995a9Smrg*)
7769fe995a9Smrg  echo "Unknown depmode $depmode" 1>&2
7779fe995a9Smrg  exit 1
7789fe995a9Smrg  ;;
7799fe995a9Smrgesac
7809fe995a9Smrg
7819fe995a9Smrgexit 0
7829fe995a9Smrg
7839fe995a9Smrg# Local Variables:
7849fe995a9Smrg# mode: shell-script
7859fe995a9Smrg# sh-indentation: 2
786c048b52eSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
7879fe995a9Smrg# time-stamp-start: "scriptversion="
7889fe995a9Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789c048b52eSmrg# time-stamp-time-zone: "UTC0"
790b62cc08cSmrg# time-stamp-end: "; # UTC"
7919fe995a9Smrg# End:
792