18108eb18Smrg#! /bin/sh
28108eb18Smrg# depcomp - compile a program generating dependencies as side-effects
31a650d1eSmrg
499c4c48aSmrgscriptversion=2018-03-07.03; # UTC
51a650d1eSmrg
699c4c48aSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
78108eb18Smrg
88108eb18Smrg# This program is free software; you can redistribute it and/or modify
98108eb18Smrg# it under the terms of the GNU General Public License as published by
108108eb18Smrg# the Free Software Foundation; either version 2, or (at your option)
118108eb18Smrg# any later version.
128108eb18Smrg
138108eb18Smrg# This program is distributed in the hope that it will be useful,
148108eb18Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
158108eb18Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
168108eb18Smrg# GNU General Public License for more details.
178108eb18Smrg
188108eb18Smrg# You should have received a copy of the GNU General Public License
1999c4c48aSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
208108eb18Smrg
218108eb18Smrg# As a special exception to the GNU General Public License, if you
228108eb18Smrg# distribute this file as part of a program that contains a
238108eb18Smrg# configuration script generated by Autoconf, you may include it under
248108eb18Smrg# the same distribution terms that you use for the rest of that program.
258108eb18Smrg
268108eb18Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
278108eb18Smrg
281a650d1eSmrgcase $1 in
291a650d1eSmrg  '')
308a355152Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
318a355152Smrg    exit 1;
328a355152Smrg    ;;
331a650d1eSmrg  -h | --h*)
341a650d1eSmrg    cat <<\EOF
351a650d1eSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
361a650d1eSmrg
371a650d1eSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
381a650d1eSmrgas side-effects.
391a650d1eSmrg
401a650d1eSmrgEnvironment variables:
411a650d1eSmrg  depmode     Dependency tracking mode.
428a355152Smrg  source      Source file read by 'PROGRAMS ARGS'.
438a355152Smrg  object      Object file output by 'PROGRAMS ARGS'.
441a650d1eSmrg  DEPDIR      directory where to store dependencies.
451a650d1eSmrg  depfile     Dependency file to output.
465977a007Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
471a650d1eSmrg  libtool     Whether libtool is used (yes/no).
481a650d1eSmrg
491a650d1eSmrgReport bugs to <bug-automake@gnu.org>.
501a650d1eSmrgEOF
511a650d1eSmrg    exit $?
521a650d1eSmrg    ;;
531a650d1eSmrg  -v | --v*)
541a650d1eSmrg    echo "depcomp $scriptversion"
551a650d1eSmrg    exit $?
561a650d1eSmrg    ;;
571a650d1eSmrgesac
581a650d1eSmrg
598a355152Smrg# Get the directory component of the given path, and save it in the
608a355152Smrg# global variables '$dir'.  Note that this directory component will
618a355152Smrg# be either empty or ending with a '/' character.  This is deliberate.
628a355152Smrgset_dir_from ()
638a355152Smrg{
648a355152Smrg  case $1 in
658a355152Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
668a355152Smrg      *) dir=;;
678a355152Smrg  esac
688a355152Smrg}
698a355152Smrg
708a355152Smrg# Get the suffix-stripped basename of the given path, and save it the
718a355152Smrg# global variable '$base'.
728a355152Smrgset_base_from ()
738a355152Smrg{
748a355152Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
758a355152Smrg}
768a355152Smrg
778a355152Smrg# If no dependency file was actually created by the compiler invocation,
788a355152Smrg# we still have to create a dummy depfile, to avoid errors with the
798a355152Smrg# Makefile "include basename.Plo" scheme.
808a355152Smrgmake_dummy_depfile ()
818a355152Smrg{
828a355152Smrg  echo "#dummy" > "$depfile"
838a355152Smrg}
848a355152Smrg
858a355152Smrg# Factor out some common post-processing of the generated depfile.
868a355152Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
878a355152Smrgaix_post_process_depfile ()
888a355152Smrg{
898a355152Smrg  # If the compiler actually managed to produce a dependency file,
908a355152Smrg  # post-process it.
918a355152Smrg  if test -f "$tmpdepfile"; then
928a355152Smrg    # Each line is of the form 'foo.o: dependency.h'.
938a355152Smrg    # Do two passes, one to just change these to
948a355152Smrg    #   $object: dependency.h
958a355152Smrg    # and one to simply output
968a355152Smrg    #   dependency.h:
978a355152Smrg    # which is needed to avoid the deleted-header problem.
988a355152Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
998a355152Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1008a355152Smrg    } > "$depfile"
1018a355152Smrg    rm -f "$tmpdepfile"
1028a355152Smrg  else
1038a355152Smrg    make_dummy_depfile
1048a355152Smrg  fi
1058a355152Smrg}
1068a355152Smrg
1078a355152Smrg# A tabulation character.
1088a355152Smrgtab='	'
1098a355152Smrg# A newline character.
1108a355152Smrgnl='
1118a355152Smrg'
1128a355152Smrg# Character ranges might be problematic outside the C locale.
1138a355152Smrg# These definitions help.
1148a355152Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1158a355152Smrglower=abcdefghijklmnopqrstuvwxyz
1168a355152Smrgdigits=0123456789
1178a355152Smrgalpha=${upper}${lower}
1188a355152Smrg
1198108eb18Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1208108eb18Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1218108eb18Smrg  exit 1
1228108eb18Smrgfi
1238108eb18Smrg
1241a650d1eSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1251a650d1eSmrgdepfile=${depfile-`echo "$object" |
1261a650d1eSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1278108eb18Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1288108eb18Smrg
1298108eb18Smrgrm -f "$tmpdepfile"
1308108eb18Smrg
1318a355152Smrg# Avoid interferences from the environment.
1328a355152Smrggccflag= dashmflag=
1338a355152Smrg
1348108eb18Smrg# Some modes work just like other modes, but use different flags.  We
1358108eb18Smrg# parameterize here, but still list the modes in the big case below,
1368108eb18Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1378108eb18Smrg# here, because this file can only contain one case statement.
1388108eb18Smrgif test "$depmode" = hp; then
1398108eb18Smrg  # HP compiler uses -M and no extra arg.
1408108eb18Smrg  gccflag=-M
1418108eb18Smrg  depmode=gcc
1428108eb18Smrgfi
1438108eb18Smrg
1448108eb18Smrgif test "$depmode" = dashXmstdout; then
1458a355152Smrg  # This is just like dashmstdout with a different argument.
1468a355152Smrg  dashmflag=-xM
1478a355152Smrg  depmode=dashmstdout
1488108eb18Smrgfi
1498108eb18Smrg
1501a650d1eSmrgcygpath_u="cygpath -u -f -"
1511a650d1eSmrgif test "$depmode" = msvcmsys; then
1528a355152Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1538a355152Smrg  # Just convert the backslash-escaped backslashes to single forward
1548a355152Smrg  # slashes to satisfy depend.m4
1558a355152Smrg  cygpath_u='sed s,\\\\,/,g'
1568a355152Smrg  depmode=msvisualcpp
1571a650d1eSmrgfi
1581a650d1eSmrg
1595977a007Smrgif test "$depmode" = msvc7msys; then
1608a355152Smrg  # This is just like msvc7 but w/o cygpath translation.
1618a355152Smrg  # Just convert the backslash-escaped backslashes to single forward
1628a355152Smrg  # slashes to satisfy depend.m4
1638a355152Smrg  cygpath_u='sed s,\\\\,/,g'
1648a355152Smrg  depmode=msvc7
1658a355152Smrgfi
1668a355152Smrg
1678a355152Smrgif test "$depmode" = xlc; then
1688a355152Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1698a355152Smrg  gccflag=-qmakedep=gcc,-MF
1708a355152Smrg  depmode=gcc
1715977a007Smrgfi
1725977a007Smrg
1738108eb18Smrgcase "$depmode" in
1748108eb18Smrggcc3)
1758108eb18Smrg## gcc 3 implements dependency tracking that does exactly what
1768108eb18Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1778108eb18Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1781a650d1eSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1791a650d1eSmrg## the command line argument order; so add the flags where they
1801a650d1eSmrg## appear in depend2.am.  Note that the slowdown incurred here
1811a650d1eSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1821a650d1eSmrg  for arg
1831a650d1eSmrg  do
1841a650d1eSmrg    case $arg in
1851a650d1eSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1861a650d1eSmrg    *)  set fnord "$@" "$arg" ;;
1871a650d1eSmrg    esac
1881a650d1eSmrg    shift # fnord
1891a650d1eSmrg    shift # $arg
1901a650d1eSmrg  done
1911a650d1eSmrg  "$@"
1928108eb18Smrg  stat=$?
1938a355152Smrg  if test $stat -ne 0; then
1948108eb18Smrg    rm -f "$tmpdepfile"
1958108eb18Smrg    exit $stat
1968108eb18Smrg  fi
1978108eb18Smrg  mv "$tmpdepfile" "$depfile"
1988108eb18Smrg  ;;
1998108eb18Smrg
2008108eb18Smrggcc)
2018a355152Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2028a355152Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2038a355152Smrg## (see the conditional assignment to $gccflag above).
2048108eb18Smrg## There are various ways to get dependency output from gcc.  Here's
2058108eb18Smrg## why we pick this rather obscure method:
2068108eb18Smrg## - Don't want to use -MD because we'd like the dependencies to end
2078108eb18Smrg##   up in a subdir.  Having to rename by hand is ugly.
2088108eb18Smrg##   (We might end up doing this anyway to support other compilers.)
2098108eb18Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2108a355152Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2118a355152Smrg##   supported by the other compilers which use the 'gcc' depmode.
2128108eb18Smrg## - Using -M directly means running the compiler twice (even worse
2138108eb18Smrg##   than renaming).
2148108eb18Smrg  if test -z "$gccflag"; then
2158108eb18Smrg    gccflag=-MD,
2168108eb18Smrg  fi
2178108eb18Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
2188108eb18Smrg  stat=$?
2198a355152Smrg  if test $stat -ne 0; then
2208108eb18Smrg    rm -f "$tmpdepfile"
2218108eb18Smrg    exit $stat
2228108eb18Smrg  fi
2238108eb18Smrg  rm -f "$depfile"
2248108eb18Smrg  echo "$object : \\" > "$depfile"
2258a355152Smrg  # The second -e expression handles DOS-style file names with drive
2268a355152Smrg  # letters.
2278108eb18Smrg  sed -e 's/^[^:]*: / /' \
2288108eb18Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2298a355152Smrg## This next piece of magic avoids the "deleted header file" problem.
2308108eb18Smrg## The problem is that when a header file which appears in a .P file
2318108eb18Smrg## is deleted, the dependency causes make to die (because there is
2328108eb18Smrg## typically no way to rebuild the header).  We avoid this by adding
2338108eb18Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2348108eb18Smrg## this for us directly.
2358a355152Smrg## Some versions of gcc put a space before the ':'.  On the theory
2368108eb18Smrg## that the space means something, we add a space to the output as
2375977a007Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2385977a007Smrg## to the object.  Take care to not repeat it in the output.
2398108eb18Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
2408108eb18Smrg## correctly.  Breaking it into two sed invocations is a workaround.
2418a355152Smrg  tr ' ' "$nl" < "$tmpdepfile" \
2428a355152Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2438a355152Smrg    | sed -e 's/$/ :/' >> "$depfile"
2448108eb18Smrg  rm -f "$tmpdepfile"
2458108eb18Smrg  ;;
2468108eb18Smrg
2478108eb18Smrghp)
2488108eb18Smrg  # This case exists only to let depend.m4 do its work.  It works by
2498108eb18Smrg  # looking at the text of this script.  This case will never be run,
2508108eb18Smrg  # since it is checked for above.
2518108eb18Smrg  exit 1
2528108eb18Smrg  ;;
2538108eb18Smrg
2548108eb18Smrgsgi)
2558108eb18Smrg  if test "$libtool" = yes; then
2568108eb18Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2578108eb18Smrg  else
2588108eb18Smrg    "$@" -MDupdate "$tmpdepfile"
2598108eb18Smrg  fi
2608108eb18Smrg  stat=$?
2618a355152Smrg  if test $stat -ne 0; then
2628108eb18Smrg    rm -f "$tmpdepfile"
2638108eb18Smrg    exit $stat
2648108eb18Smrg  fi
2658108eb18Smrg  rm -f "$depfile"
2668108eb18Smrg
2678108eb18Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2688108eb18Smrg    echo "$object : \\" > "$depfile"
2698108eb18Smrg    # Clip off the initial element (the dependent).  Don't try to be
2708108eb18Smrg    # clever and replace this with sed code, as IRIX sed won't handle
2718108eb18Smrg    # lines with more than a fixed number of characters (4096 in
2728108eb18Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2738a355152Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
2748108eb18Smrg    # dependency line.
2758a355152Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2768a355152Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2778a355152Smrg      | tr "$nl" ' ' >> "$depfile"
2781a650d1eSmrg    echo >> "$depfile"
2798108eb18Smrg    # The second pass generates a dummy entry for each header file.
2808a355152Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2818a355152Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2828a355152Smrg      >> "$depfile"
2838108eb18Smrg  else
2848a355152Smrg    make_dummy_depfile
2858108eb18Smrg  fi
2868108eb18Smrg  rm -f "$tmpdepfile"
2878108eb18Smrg  ;;
2888108eb18Smrg
2898a355152Smrgxlc)
2908a355152Smrg  # This case exists only to let depend.m4 do its work.  It works by
2918a355152Smrg  # looking at the text of this script.  This case will never be run,
2928a355152Smrg  # since it is checked for above.
2938a355152Smrg  exit 1
2948a355152Smrg  ;;
2958a355152Smrg
2968108eb18Smrgaix)
2978108eb18Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2988108eb18Smrg  # in a .u file.  In older versions, this file always lives in the
2998a355152Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3008108eb18Smrg  # start of each line; $object doesn't have directory information.
3018108eb18Smrg  # Version 6 uses the directory in both cases.
3028a355152Smrg  set_dir_from "$object"
3038a355152Smrg  set_base_from "$object"
3048108eb18Smrg  if test "$libtool" = yes; then
3051a650d1eSmrg    tmpdepfile1=$dir$base.u
3061a650d1eSmrg    tmpdepfile2=$base.u
3071a650d1eSmrg    tmpdepfile3=$dir.libs/$base.u
3088108eb18Smrg    "$@" -Wc,-M
3098108eb18Smrg  else
3101a650d1eSmrg    tmpdepfile1=$dir$base.u
3111a650d1eSmrg    tmpdepfile2=$dir$base.u
3121a650d1eSmrg    tmpdepfile3=$dir$base.u
3138108eb18Smrg    "$@" -M
3148108eb18Smrg  fi
3158108eb18Smrg  stat=$?
3168a355152Smrg  if test $stat -ne 0; then
3171a650d1eSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3188108eb18Smrg    exit $stat
3198108eb18Smrg  fi
3208108eb18Smrg
3211a650d1eSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3221a650d1eSmrg  do
3231a650d1eSmrg    test -f "$tmpdepfile" && break
3241a650d1eSmrg  done
3258a355152Smrg  aix_post_process_depfile
3268a355152Smrg  ;;
3278a355152Smrg
3288a355152Smrgtcc)
3298a355152Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3308a355152Smrg  # FIXME: That version still under development at the moment of writing.
3318a355152Smrg  #        Make that this statement remains true also for stable, released
3328a355152Smrg  #        versions.
3338a355152Smrg  # It will wrap lines (doesn't matter whether long or short) with a
3348a355152Smrg  # trailing '\', as in:
3358a355152Smrg  #
3368a355152Smrg  #   foo.o : \
3378a355152Smrg  #    foo.c \
3388a355152Smrg  #    foo.h \
3398a355152Smrg  #
3408a355152Smrg  # It will put a trailing '\' even on the last line, and will use leading
3418a355152Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3428a355152Smrg  # "Emit spaces for -MD").
3438a355152Smrg  "$@" -MD -MF "$tmpdepfile"
3448a355152Smrg  stat=$?
3458a355152Smrg  if test $stat -ne 0; then
3468a355152Smrg    rm -f "$tmpdepfile"
3478a355152Smrg    exit $stat
3488108eb18Smrg  fi
3498a355152Smrg  rm -f "$depfile"
3508a355152Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3518a355152Smrg  # We have to change lines of the first kind to '$object: \'.
3528a355152Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3538a355152Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3548a355152Smrg  # dummy dependency, to avoid the deleted-header problem.
3558a355152Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3568108eb18Smrg  rm -f "$tmpdepfile"
3578108eb18Smrg  ;;
3588108eb18Smrg
3598a355152Smrg## The order of this option in the case statement is important, since the
3608a355152Smrg## shell code in configure will try each of these formats in the order
3618a355152Smrg## listed in this file.  A plain '-MD' option would be understood by many
3628a355152Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3638a355152Smrgpgcc)
3648a355152Smrg  # Portland's C compiler understands '-MD'.
3658a355152Smrg  # Will always output deps to 'file.d' where file is the root name of the
3668a355152Smrg  # source file under compilation, even if file resides in a subdirectory.
3678a355152Smrg  # The object file name does not affect the name of the '.d' file.
3688a355152Smrg  # pgcc 10.2 will output
3698108eb18Smrg  #    foo.o: sub/foo.c sub/foo.h
3708a355152Smrg  # and will wrap long lines using '\' :
3718108eb18Smrg  #    foo.o: sub/foo.c ... \
3728108eb18Smrg  #     sub/foo.h ... \
3738108eb18Smrg  #     ...
3748a355152Smrg  set_dir_from "$object"
3758a355152Smrg  # Use the source, not the object, to determine the base name, since
3768a355152Smrg  # that's sadly what pgcc will do too.
3778a355152Smrg  set_base_from "$source"
3788a355152Smrg  tmpdepfile=$base.d
3798a355152Smrg
3808a355152Smrg  # For projects that build the same source file twice into different object
3818a355152Smrg  # files, the pgcc approach of using the *source* file root name can cause
3828a355152Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3838a355152Smrg  # the same $tmpdepfile.
3848a355152Smrg  lockdir=$base.d-lock
3858a355152Smrg  trap "
3868a355152Smrg    echo '$0: caught signal, cleaning up...' >&2
3878a355152Smrg    rmdir '$lockdir'
3888a355152Smrg    exit 1
3898a355152Smrg  " 1 2 13 15
3908a355152Smrg  numtries=100
3918a355152Smrg  i=$numtries
3928a355152Smrg  while test $i -gt 0; do
3938a355152Smrg    # mkdir is a portable test-and-set.
3948a355152Smrg    if mkdir "$lockdir" 2>/dev/null; then
3958a355152Smrg      # This process acquired the lock.
3968a355152Smrg      "$@" -MD
3978a355152Smrg      stat=$?
3988a355152Smrg      # Release the lock.
3998a355152Smrg      rmdir "$lockdir"
4008a355152Smrg      break
4018a355152Smrg    else
4028a355152Smrg      # If the lock is being held by a different process, wait
4038a355152Smrg      # until the winning process is done or we timeout.
4048a355152Smrg      while test -d "$lockdir" && test $i -gt 0; do
4058a355152Smrg        sleep 1
4068a355152Smrg        i=`expr $i - 1`
4078a355152Smrg      done
4088a355152Smrg    fi
4098a355152Smrg    i=`expr $i - 1`
4108a355152Smrg  done
4118a355152Smrg  trap - 1 2 13 15
4128a355152Smrg  if test $i -le 0; then
4138a355152Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4148a355152Smrg    echo "$0: check lockdir '$lockdir'" >&2
4158a355152Smrg    exit 1
4168a355152Smrg  fi
4178108eb18Smrg
4188a355152Smrg  if test $stat -ne 0; then
4198108eb18Smrg    rm -f "$tmpdepfile"
4208108eb18Smrg    exit $stat
4218108eb18Smrg  fi
4228108eb18Smrg  rm -f "$depfile"
4238108eb18Smrg  # Each line is of the form `foo.o: dependent.h',
4248108eb18Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4258108eb18Smrg  # Do two passes, one to just change these to
4268108eb18Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4278108eb18Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4288108eb18Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4298108eb18Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
4308a355152Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4318a355152Smrg    | sed -e 's/$/ :/' >> "$depfile"
4328108eb18Smrg  rm -f "$tmpdepfile"
4338108eb18Smrg  ;;
4348108eb18Smrg
4351a650d1eSmrghp2)
4361a650d1eSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4371a650d1eSmrg  # compilers, which have integrated preprocessors.  The correct option
4381a650d1eSmrg  # to use with these is +Maked; it writes dependencies to a file named
4391a650d1eSmrg  # 'foo.d', which lands next to the object file, wherever that
4401a650d1eSmrg  # happens to be.
4411a650d1eSmrg  # Much of this is similar to the tru64 case; see comments there.
4428a355152Smrg  set_dir_from  "$object"
4438a355152Smrg  set_base_from "$object"
4441a650d1eSmrg  if test "$libtool" = yes; then
4451a650d1eSmrg    tmpdepfile1=$dir$base.d
4461a650d1eSmrg    tmpdepfile2=$dir.libs/$base.d
4471a650d1eSmrg    "$@" -Wc,+Maked
4481a650d1eSmrg  else
4491a650d1eSmrg    tmpdepfile1=$dir$base.d
4501a650d1eSmrg    tmpdepfile2=$dir$base.d
4511a650d1eSmrg    "$@" +Maked
4521a650d1eSmrg  fi
4531a650d1eSmrg  stat=$?
4548a355152Smrg  if test $stat -ne 0; then
4551a650d1eSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4561a650d1eSmrg     exit $stat
4571a650d1eSmrg  fi
4581a650d1eSmrg
4591a650d1eSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4601a650d1eSmrg  do
4611a650d1eSmrg    test -f "$tmpdepfile" && break
4621a650d1eSmrg  done
4631a650d1eSmrg  if test -f "$tmpdepfile"; then
4648a355152Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4658a355152Smrg    # Add 'dependent.h:' lines.
4661a650d1eSmrg    sed -ne '2,${
4678a355152Smrg               s/^ *//
4688a355152Smrg               s/ \\*$//
4698a355152Smrg               s/$/:/
4708a355152Smrg               p
4718a355152Smrg             }' "$tmpdepfile" >> "$depfile"
4721a650d1eSmrg  else
4738a355152Smrg    make_dummy_depfile
4741a650d1eSmrg  fi
4751a650d1eSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4761a650d1eSmrg  ;;
4771a650d1eSmrg
4788108eb18Smrgtru64)
4798a355152Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4808a355152Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4818a355152Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4828a355152Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4838a355152Smrg  # Subdirectories are respected.
4848a355152Smrg  set_dir_from  "$object"
4858a355152Smrg  set_base_from "$object"
4868a355152Smrg
4878a355152Smrg  if test "$libtool" = yes; then
4888a355152Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4898a355152Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4908a355152Smrg    # in $dir$base.o.d.  We have to check for both files, because
4918a355152Smrg    # one of the two compilations can be disabled.  We should prefer
4928a355152Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4938a355152Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4948a355152Smrg    # the former would cause a distcleancheck panic.
4958a355152Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4968a355152Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4978a355152Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4988a355152Smrg    "$@" -Wc,-MD
4998a355152Smrg  else
5008a355152Smrg    tmpdepfile1=$dir$base.d
5018a355152Smrg    tmpdepfile2=$dir$base.d
5028a355152Smrg    tmpdepfile3=$dir$base.d
5038a355152Smrg    "$@" -MD
5048a355152Smrg  fi
5058a355152Smrg
5068a355152Smrg  stat=$?
5078a355152Smrg  if test $stat -ne 0; then
5088a355152Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5098a355152Smrg    exit $stat
5108a355152Smrg  fi
5118a355152Smrg
5128a355152Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5138a355152Smrg  do
5148a355152Smrg    test -f "$tmpdepfile" && break
5158a355152Smrg  done
5168a355152Smrg  # Same post-processing that is required for AIX mode.
5178a355152Smrg  aix_post_process_depfile
5188a355152Smrg  ;;
5198108eb18Smrg
5205977a007Smrgmsvc7)
5215977a007Smrg  if test "$libtool" = yes; then
5225977a007Smrg    showIncludes=-Wc,-showIncludes
5235977a007Smrg  else
5245977a007Smrg    showIncludes=-showIncludes
5255977a007Smrg  fi
5265977a007Smrg  "$@" $showIncludes > "$tmpdepfile"
5275977a007Smrg  stat=$?
5285977a007Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5298a355152Smrg  if test $stat -ne 0; then
5305977a007Smrg    rm -f "$tmpdepfile"
5315977a007Smrg    exit $stat
5325977a007Smrg  fi
5335977a007Smrg  rm -f "$depfile"
5345977a007Smrg  echo "$object : \\" > "$depfile"
5355977a007Smrg  # The first sed program below extracts the file names and escapes
5365977a007Smrg  # backslashes for cygpath.  The second sed program outputs the file
5375977a007Smrg  # name when reading, but also accumulates all include files in the
5385977a007Smrg  # hold buffer in order to output them again at the end.  This only
5395977a007Smrg  # works with sed implementations that can handle large buffers.
5405977a007Smrg  sed < "$tmpdepfile" -n '
5415977a007Smrg/^Note: including file:  *\(.*\)/ {
5425977a007Smrg  s//\1/
5435977a007Smrg  s/\\/\\\\/g
5445977a007Smrg  p
5455977a007Smrg}' | $cygpath_u | sort -u | sed -n '
5465977a007Smrgs/ /\\ /g
5478a355152Smrgs/\(.*\)/'"$tab"'\1 \\/p
5485977a007Smrgs/.\(.*\) \\/\1:/
5495977a007SmrgH
5505977a007Smrg$ {
5518a355152Smrg  s/.*/'"$tab"'/
5525977a007Smrg  G
5535977a007Smrg  p
5545977a007Smrg}' >> "$depfile"
5558a355152Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5565977a007Smrg  rm -f "$tmpdepfile"
5575977a007Smrg  ;;
5585977a007Smrg
5595977a007Smrgmsvc7msys)
5605977a007Smrg  # This case exists only to let depend.m4 do its work.  It works by
5615977a007Smrg  # looking at the text of this script.  This case will never be run,
5625977a007Smrg  # since it is checked for above.
5635977a007Smrg  exit 1
5645977a007Smrg  ;;
5655977a007Smrg
5668108eb18Smrg#nosideeffect)
5678108eb18Smrg  # This comment above is used by automake to tell side-effect
5688108eb18Smrg  # dependency tracking mechanisms from slower ones.
5698108eb18Smrg
5708108eb18Smrgdashmstdout)
5718108eb18Smrg  # Important note: in order to support this mode, a compiler *must*
5728108eb18Smrg  # always write the preprocessed file to stdout, regardless of -o.
5738108eb18Smrg  "$@" || exit $?
5748108eb18Smrg
5758108eb18Smrg  # Remove the call to Libtool.
5768108eb18Smrg  if test "$libtool" = yes; then
5771a650d1eSmrg    while test "X$1" != 'X--mode=compile'; do
5788108eb18Smrg      shift
5798108eb18Smrg    done
5808108eb18Smrg    shift
5818108eb18Smrg  fi
5828108eb18Smrg
5838a355152Smrg  # Remove '-o $object'.
5848108eb18Smrg  IFS=" "
5858108eb18Smrg  for arg
5868108eb18Smrg  do
5878108eb18Smrg    case $arg in
5888108eb18Smrg    -o)
5898108eb18Smrg      shift
5908108eb18Smrg      ;;
5918108eb18Smrg    $object)
5928108eb18Smrg      shift
5938108eb18Smrg      ;;
5948108eb18Smrg    *)
5958108eb18Smrg      set fnord "$@" "$arg"
5968108eb18Smrg      shift # fnord
5978108eb18Smrg      shift # $arg
5988108eb18Smrg      ;;
5998108eb18Smrg    esac
6008108eb18Smrg  done
6018108eb18Smrg
6028108eb18Smrg  test -z "$dashmflag" && dashmflag=-M
6038a355152Smrg  # Require at least two characters before searching for ':'
6048108eb18Smrg  # in the target name.  This is to cope with DOS-style filenames:
6058a355152Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6068108eb18Smrg  "$@" $dashmflag |
6078a355152Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6088108eb18Smrg  rm -f "$depfile"
6098108eb18Smrg  cat < "$tmpdepfile" > "$depfile"
6108a355152Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6118a355152Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6128a355152Smrg  tr ' ' "$nl" < "$tmpdepfile" \
6138a355152Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6148a355152Smrg    | sed -e 's/$/ :/' >> "$depfile"
6158108eb18Smrg  rm -f "$tmpdepfile"
6168108eb18Smrg  ;;
6178108eb18Smrg
6188108eb18SmrgdashXmstdout)
6198108eb18Smrg  # This case only exists to satisfy depend.m4.  It is never actually
6208108eb18Smrg  # run, as this mode is specially recognized in the preamble.
6218108eb18Smrg  exit 1
6228108eb18Smrg  ;;
6238108eb18Smrg
6248108eb18Smrgmakedepend)
6258108eb18Smrg  "$@" || exit $?
6268108eb18Smrg  # Remove any Libtool call
6278108eb18Smrg  if test "$libtool" = yes; then
6281a650d1eSmrg    while test "X$1" != 'X--mode=compile'; do
6298108eb18Smrg      shift
6308108eb18Smrg    done
6318108eb18Smrg    shift
6328108eb18Smrg  fi
6338108eb18Smrg  # X makedepend
6348108eb18Smrg  shift
6351a650d1eSmrg  cleared=no eat=no
6361a650d1eSmrg  for arg
6371a650d1eSmrg  do
6388108eb18Smrg    case $cleared in
6398108eb18Smrg    no)
6408108eb18Smrg      set ""; shift
6418108eb18Smrg      cleared=yes ;;
6428108eb18Smrg    esac
6431a650d1eSmrg    if test $eat = yes; then
6441a650d1eSmrg      eat=no
6451a650d1eSmrg      continue
6461a650d1eSmrg    fi
6478108eb18Smrg    case "$arg" in
6488108eb18Smrg    -D*|-I*)
6498108eb18Smrg      set fnord "$@" "$arg"; shift ;;
6508108eb18Smrg    # Strip any option that makedepend may not understand.  Remove
6518108eb18Smrg    # the object too, otherwise makedepend will parse it as a source file.
6521a650d1eSmrg    -arch)
6531a650d1eSmrg      eat=yes ;;
6548108eb18Smrg    -*|$object)
6558108eb18Smrg      ;;
6568108eb18Smrg    *)
6578108eb18Smrg      set fnord "$@" "$arg"; shift ;;
6588108eb18Smrg    esac
6598108eb18Smrg  done
6601a650d1eSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6618108eb18Smrg  touch "$tmpdepfile"
6628108eb18Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6638108eb18Smrg  rm -f "$depfile"
6645977a007Smrg  # makedepend may prepend the VPATH from the source file name to the object.
6655977a007Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6665977a007Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6678a355152Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6688a355152Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6698a355152Smrg  sed '1,2d' "$tmpdepfile" \
6708a355152Smrg    | tr ' ' "$nl" \
6718a355152Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6728a355152Smrg    | sed -e 's/$/ :/' >> "$depfile"
6738108eb18Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6748108eb18Smrg  ;;
6758108eb18Smrg
6768108eb18Smrgcpp)
6778108eb18Smrg  # Important note: in order to support this mode, a compiler *must*
6788108eb18Smrg  # always write the preprocessed file to stdout.
6798108eb18Smrg  "$@" || exit $?
6808108eb18Smrg
6818108eb18Smrg  # Remove the call to Libtool.
6828108eb18Smrg  if test "$libtool" = yes; then
6831a650d1eSmrg    while test "X$1" != 'X--mode=compile'; do
6848108eb18Smrg      shift
6858108eb18Smrg    done
6868108eb18Smrg    shift
6878108eb18Smrg  fi
6888108eb18Smrg
6898a355152Smrg  # Remove '-o $object'.
6908108eb18Smrg  IFS=" "
6918108eb18Smrg  for arg
6928108eb18Smrg  do
6938108eb18Smrg    case $arg in
6948108eb18Smrg    -o)
6958108eb18Smrg      shift
6968108eb18Smrg      ;;
6978108eb18Smrg    $object)
6988108eb18Smrg      shift
6998108eb18Smrg      ;;
7008108eb18Smrg    *)
7018108eb18Smrg      set fnord "$@" "$arg"
7028108eb18Smrg      shift # fnord
7038108eb18Smrg      shift # $arg
7048108eb18Smrg      ;;
7058108eb18Smrg    esac
7068108eb18Smrg  done
7078108eb18Smrg
7088a355152Smrg  "$@" -E \
7098a355152Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7108a355152Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7118a355152Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
7128108eb18Smrg  rm -f "$depfile"
7138108eb18Smrg  echo "$object : \\" > "$depfile"
7148108eb18Smrg  cat < "$tmpdepfile" >> "$depfile"
7158108eb18Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7168108eb18Smrg  rm -f "$tmpdepfile"
7178108eb18Smrg  ;;
7188108eb18Smrg
7198108eb18Smrgmsvisualcpp)
7208108eb18Smrg  # Important note: in order to support this mode, a compiler *must*
7211a650d1eSmrg  # always write the preprocessed file to stdout.
7228108eb18Smrg  "$@" || exit $?
7231a650d1eSmrg
7241a650d1eSmrg  # Remove the call to Libtool.
7251a650d1eSmrg  if test "$libtool" = yes; then
7261a650d1eSmrg    while test "X$1" != 'X--mode=compile'; do
7271a650d1eSmrg      shift
7281a650d1eSmrg    done
7291a650d1eSmrg    shift
7301a650d1eSmrg  fi
7311a650d1eSmrg
7328108eb18Smrg  IFS=" "
7338108eb18Smrg  for arg
7348108eb18Smrg  do
7358108eb18Smrg    case "$arg" in
7361a650d1eSmrg    -o)
7371a650d1eSmrg      shift
7381a650d1eSmrg      ;;
7391a650d1eSmrg    $object)
7401a650d1eSmrg      shift
7411a650d1eSmrg      ;;
7428108eb18Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7438a355152Smrg        set fnord "$@"
7448a355152Smrg        shift
7458a355152Smrg        shift
7468a355152Smrg        ;;
7478108eb18Smrg    *)
7488a355152Smrg        set fnord "$@" "$arg"
7498a355152Smrg        shift
7508a355152Smrg        shift
7518a355152Smrg        ;;
7528108eb18Smrg    esac
7538108eb18Smrg  done
7541a650d1eSmrg  "$@" -E 2>/dev/null |
7551a650d1eSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7568108eb18Smrg  rm -f "$depfile"
7578108eb18Smrg  echo "$object : \\" > "$depfile"
7588a355152Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7598a355152Smrg  echo "$tab" >> "$depfile"
7601a650d1eSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7618108eb18Smrg  rm -f "$tmpdepfile"
7628108eb18Smrg  ;;
7638108eb18Smrg
7641a650d1eSmrgmsvcmsys)
7651a650d1eSmrg  # This case exists only to let depend.m4 do its work.  It works by
7661a650d1eSmrg  # looking at the text of this script.  This case will never be run,
7671a650d1eSmrg  # since it is checked for above.
7681a650d1eSmrg  exit 1
7691a650d1eSmrg  ;;
7701a650d1eSmrg
7718108eb18Smrgnone)
7728108eb18Smrg  exec "$@"
7738108eb18Smrg  ;;
7748108eb18Smrg
7758108eb18Smrg*)
7768108eb18Smrg  echo "Unknown depmode $depmode" 1>&2
7778108eb18Smrg  exit 1
7788108eb18Smrg  ;;
7798108eb18Smrgesac
7808108eb18Smrg
7818108eb18Smrgexit 0
7821a650d1eSmrg
7831a650d1eSmrg# Local Variables:
7841a650d1eSmrg# mode: shell-script
7851a650d1eSmrg# sh-indentation: 2
78699c4c48aSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
7871a650d1eSmrg# time-stamp-start: "scriptversion="
7881a650d1eSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
78999c4c48aSmrg# time-stamp-time-zone: "UTC0"
7901a650d1eSmrg# time-stamp-end: "; # UTC"
7911a650d1eSmrg# End:
792