depcomp revision fe12f63c
11016ad83Smrg#! /bin/sh
21016ad83Smrg# depcomp - compile a program generating dependencies as side-effects
31016ad83Smrg
4fe12f63cSmrgscriptversion=2018-03-07.03; # UTC
51016ad83Smrg
6fe12f63cSmrg# Copyright (C) 1999-2018 Free Software Foundation, Inc.
71016ad83Smrg
81016ad83Smrg# This program is free software; you can redistribute it and/or modify
91016ad83Smrg# it under the terms of the GNU General Public License as published by
101016ad83Smrg# the Free Software Foundation; either version 2, or (at your option)
111016ad83Smrg# any later version.
121016ad83Smrg
131016ad83Smrg# This program is distributed in the hope that it will be useful,
141016ad83Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
151016ad83Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161016ad83Smrg# GNU General Public License for more details.
171016ad83Smrg
181016ad83Smrg# You should have received a copy of the GNU General Public License
19fe12f63cSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
201016ad83Smrg
211016ad83Smrg# As a special exception to the GNU General Public License, if you
221016ad83Smrg# distribute this file as part of a program that contains a
231016ad83Smrg# configuration script generated by Autoconf, you may include it under
241016ad83Smrg# the same distribution terms that you use for the rest of that program.
251016ad83Smrg
261016ad83Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
271016ad83Smrg
281016ad83Smrgcase $1 in
291016ad83Smrg  '')
301016ad83Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
311016ad83Smrg    exit 1;
321016ad83Smrg    ;;
331016ad83Smrg  -h | --h*)
341016ad83Smrg    cat <<\EOF
351016ad83SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
361016ad83Smrg
371016ad83SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
381016ad83Smrgas side-effects.
391016ad83Smrg
401016ad83SmrgEnvironment variables:
411016ad83Smrg  depmode     Dependency tracking mode.
421016ad83Smrg  source      Source file read by 'PROGRAMS ARGS'.
431016ad83Smrg  object      Object file output by 'PROGRAMS ARGS'.
441016ad83Smrg  DEPDIR      directory where to store dependencies.
451016ad83Smrg  depfile     Dependency file to output.
461016ad83Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
471016ad83Smrg  libtool     Whether libtool is used (yes/no).
481016ad83Smrg
491016ad83SmrgReport bugs to <bug-automake@gnu.org>.
501016ad83SmrgEOF
511016ad83Smrg    exit $?
521016ad83Smrg    ;;
531016ad83Smrg  -v | --v*)
541016ad83Smrg    echo "depcomp $scriptversion"
551016ad83Smrg    exit $?
561016ad83Smrg    ;;
571016ad83Smrgesac
581016ad83Smrg
591016ad83Smrg# Get the directory component of the given path, and save it in the
601016ad83Smrg# global variables '$dir'.  Note that this directory component will
611016ad83Smrg# be either empty or ending with a '/' character.  This is deliberate.
621016ad83Smrgset_dir_from ()
631016ad83Smrg{
641016ad83Smrg  case $1 in
651016ad83Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
661016ad83Smrg      *) dir=;;
671016ad83Smrg  esac
681016ad83Smrg}
691016ad83Smrg
701016ad83Smrg# Get the suffix-stripped basename of the given path, and save it the
711016ad83Smrg# global variable '$base'.
721016ad83Smrgset_base_from ()
731016ad83Smrg{
741016ad83Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
751016ad83Smrg}
761016ad83Smrg
771016ad83Smrg# If no dependency file was actually created by the compiler invocation,
781016ad83Smrg# we still have to create a dummy depfile, to avoid errors with the
791016ad83Smrg# Makefile "include basename.Plo" scheme.
801016ad83Smrgmake_dummy_depfile ()
811016ad83Smrg{
821016ad83Smrg  echo "#dummy" > "$depfile"
831016ad83Smrg}
841016ad83Smrg
851016ad83Smrg# Factor out some common post-processing of the generated depfile.
861016ad83Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
871016ad83Smrgaix_post_process_depfile ()
881016ad83Smrg{
891016ad83Smrg  # If the compiler actually managed to produce a dependency file,
901016ad83Smrg  # post-process it.
911016ad83Smrg  if test -f "$tmpdepfile"; then
921016ad83Smrg    # Each line is of the form 'foo.o: dependency.h'.
931016ad83Smrg    # Do two passes, one to just change these to
941016ad83Smrg    #   $object: dependency.h
951016ad83Smrg    # and one to simply output
961016ad83Smrg    #   dependency.h:
971016ad83Smrg    # which is needed to avoid the deleted-header problem.
981016ad83Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
991016ad83Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1001016ad83Smrg    } > "$depfile"
1011016ad83Smrg    rm -f "$tmpdepfile"
1021016ad83Smrg  else
1031016ad83Smrg    make_dummy_depfile
1041016ad83Smrg  fi
1051016ad83Smrg}
1061016ad83Smrg
1071016ad83Smrg# A tabulation character.
1081016ad83Smrgtab='	'
1091016ad83Smrg# A newline character.
1101016ad83Smrgnl='
1111016ad83Smrg'
1121016ad83Smrg# Character ranges might be problematic outside the C locale.
1131016ad83Smrg# These definitions help.
1141016ad83Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1151016ad83Smrglower=abcdefghijklmnopqrstuvwxyz
1161016ad83Smrgdigits=0123456789
1171016ad83Smrgalpha=${upper}${lower}
1181016ad83Smrg
1191016ad83Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1201016ad83Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1211016ad83Smrg  exit 1
1221016ad83Smrgfi
1231016ad83Smrg
1241016ad83Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1251016ad83Smrgdepfile=${depfile-`echo "$object" |
1261016ad83Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1271016ad83Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1281016ad83Smrg
1291016ad83Smrgrm -f "$tmpdepfile"
1301016ad83Smrg
1311016ad83Smrg# Avoid interferences from the environment.
1321016ad83Smrggccflag= dashmflag=
1331016ad83Smrg
1341016ad83Smrg# Some modes work just like other modes, but use different flags.  We
1351016ad83Smrg# parameterize here, but still list the modes in the big case below,
1361016ad83Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1371016ad83Smrg# here, because this file can only contain one case statement.
1381016ad83Smrgif test "$depmode" = hp; then
1391016ad83Smrg  # HP compiler uses -M and no extra arg.
1401016ad83Smrg  gccflag=-M
1411016ad83Smrg  depmode=gcc
1421016ad83Smrgfi
1431016ad83Smrg
1441016ad83Smrgif test "$depmode" = dashXmstdout; then
1451016ad83Smrg  # This is just like dashmstdout with a different argument.
1461016ad83Smrg  dashmflag=-xM
1471016ad83Smrg  depmode=dashmstdout
1481016ad83Smrgfi
1491016ad83Smrg
1501016ad83Smrgcygpath_u="cygpath -u -f -"
1511016ad83Smrgif test "$depmode" = msvcmsys; then
1521016ad83Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1531016ad83Smrg  # Just convert the backslash-escaped backslashes to single forward
1541016ad83Smrg  # slashes to satisfy depend.m4
1551016ad83Smrg  cygpath_u='sed s,\\\\,/,g'
1561016ad83Smrg  depmode=msvisualcpp
1571016ad83Smrgfi
1581016ad83Smrg
1591016ad83Smrgif test "$depmode" = msvc7msys; then
1601016ad83Smrg  # This is just like msvc7 but w/o cygpath translation.
1611016ad83Smrg  # Just convert the backslash-escaped backslashes to single forward
1621016ad83Smrg  # slashes to satisfy depend.m4
1631016ad83Smrg  cygpath_u='sed s,\\\\,/,g'
1641016ad83Smrg  depmode=msvc7
1651016ad83Smrgfi
1661016ad83Smrg
1671016ad83Smrgif test "$depmode" = xlc; then
1681016ad83Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1691016ad83Smrg  gccflag=-qmakedep=gcc,-MF
1701016ad83Smrg  depmode=gcc
1711016ad83Smrgfi
1721016ad83Smrg
1731016ad83Smrgcase "$depmode" in
1741016ad83Smrggcc3)
1751016ad83Smrg## gcc 3 implements dependency tracking that does exactly what
1761016ad83Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1771016ad83Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1781016ad83Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1791016ad83Smrg## the command line argument order; so add the flags where they
1801016ad83Smrg## appear in depend2.am.  Note that the slowdown incurred here
1811016ad83Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1821016ad83Smrg  for arg
1831016ad83Smrg  do
1841016ad83Smrg    case $arg in
1851016ad83Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1861016ad83Smrg    *)  set fnord "$@" "$arg" ;;
1871016ad83Smrg    esac
1881016ad83Smrg    shift # fnord
1891016ad83Smrg    shift # $arg
1901016ad83Smrg  done
1911016ad83Smrg  "$@"
1921016ad83Smrg  stat=$?
1931016ad83Smrg  if test $stat -ne 0; then
1941016ad83Smrg    rm -f "$tmpdepfile"
1951016ad83Smrg    exit $stat
1961016ad83Smrg  fi
1971016ad83Smrg  mv "$tmpdepfile" "$depfile"
1981016ad83Smrg  ;;
1991016ad83Smrg
2001016ad83Smrggcc)
2011016ad83Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2021016ad83Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2031016ad83Smrg## (see the conditional assignment to $gccflag above).
2041016ad83Smrg## There are various ways to get dependency output from gcc.  Here's
2051016ad83Smrg## why we pick this rather obscure method:
2061016ad83Smrg## - Don't want to use -MD because we'd like the dependencies to end
2071016ad83Smrg##   up in a subdir.  Having to rename by hand is ugly.
2081016ad83Smrg##   (We might end up doing this anyway to support other compilers.)
2091016ad83Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2101016ad83Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
2111016ad83Smrg##   supported by the other compilers which use the 'gcc' depmode.
2121016ad83Smrg## - Using -M directly means running the compiler twice (even worse
2131016ad83Smrg##   than renaming).
2141016ad83Smrg  if test -z "$gccflag"; then
2151016ad83Smrg    gccflag=-MD,
2161016ad83Smrg  fi
2171016ad83Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
2181016ad83Smrg  stat=$?
2191016ad83Smrg  if test $stat -ne 0; then
2201016ad83Smrg    rm -f "$tmpdepfile"
2211016ad83Smrg    exit $stat
2221016ad83Smrg  fi
2231016ad83Smrg  rm -f "$depfile"
2241016ad83Smrg  echo "$object : \\" > "$depfile"
2251016ad83Smrg  # The second -e expression handles DOS-style file names with drive
2261016ad83Smrg  # letters.
2271016ad83Smrg  sed -e 's/^[^:]*: / /' \
2281016ad83Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2291016ad83Smrg## This next piece of magic avoids the "deleted header file" problem.
2301016ad83Smrg## The problem is that when a header file which appears in a .P file
2311016ad83Smrg## is deleted, the dependency causes make to die (because there is
2321016ad83Smrg## typically no way to rebuild the header).  We avoid this by adding
2331016ad83Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2341016ad83Smrg## this for us directly.
2351016ad83Smrg## Some versions of gcc put a space before the ':'.  On the theory
2361016ad83Smrg## that the space means something, we add a space to the output as
2371016ad83Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2381016ad83Smrg## to the object.  Take care to not repeat it in the output.
2391016ad83Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
2401016ad83Smrg## correctly.  Breaking it into two sed invocations is a workaround.
2411016ad83Smrg  tr ' ' "$nl" < "$tmpdepfile" \
2421016ad83Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2431016ad83Smrg    | sed -e 's/$/ :/' >> "$depfile"
2441016ad83Smrg  rm -f "$tmpdepfile"
2451016ad83Smrg  ;;
2461016ad83Smrg
2471016ad83Smrghp)
2481016ad83Smrg  # This case exists only to let depend.m4 do its work.  It works by
2491016ad83Smrg  # looking at the text of this script.  This case will never be run,
2501016ad83Smrg  # since it is checked for above.
2511016ad83Smrg  exit 1
2521016ad83Smrg  ;;
2531016ad83Smrg
2541016ad83Smrgsgi)
2551016ad83Smrg  if test "$libtool" = yes; then
2561016ad83Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2571016ad83Smrg  else
2581016ad83Smrg    "$@" -MDupdate "$tmpdepfile"
2591016ad83Smrg  fi
2601016ad83Smrg  stat=$?
2611016ad83Smrg  if test $stat -ne 0; then
2621016ad83Smrg    rm -f "$tmpdepfile"
2631016ad83Smrg    exit $stat
2641016ad83Smrg  fi
2651016ad83Smrg  rm -f "$depfile"
2661016ad83Smrg
2671016ad83Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2681016ad83Smrg    echo "$object : \\" > "$depfile"
2691016ad83Smrg    # Clip off the initial element (the dependent).  Don't try to be
2701016ad83Smrg    # clever and replace this with sed code, as IRIX sed won't handle
2711016ad83Smrg    # lines with more than a fixed number of characters (4096 in
2721016ad83Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2731016ad83Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
2741016ad83Smrg    # dependency line.
2751016ad83Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2761016ad83Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2771016ad83Smrg      | tr "$nl" ' ' >> "$depfile"
2781016ad83Smrg    echo >> "$depfile"
2791016ad83Smrg    # The second pass generates a dummy entry for each header file.
2801016ad83Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2811016ad83Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2821016ad83Smrg      >> "$depfile"
2831016ad83Smrg  else
2841016ad83Smrg    make_dummy_depfile
2851016ad83Smrg  fi
2861016ad83Smrg  rm -f "$tmpdepfile"
2871016ad83Smrg  ;;
2881016ad83Smrg
2891016ad83Smrgxlc)
2901016ad83Smrg  # This case exists only to let depend.m4 do its work.  It works by
2911016ad83Smrg  # looking at the text of this script.  This case will never be run,
2921016ad83Smrg  # since it is checked for above.
2931016ad83Smrg  exit 1
2941016ad83Smrg  ;;
2951016ad83Smrg
2961016ad83Smrgaix)
2971016ad83Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2981016ad83Smrg  # in a .u file.  In older versions, this file always lives in the
2991016ad83Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3001016ad83Smrg  # start of each line; $object doesn't have directory information.
3011016ad83Smrg  # Version 6 uses the directory in both cases.
3021016ad83Smrg  set_dir_from "$object"
3031016ad83Smrg  set_base_from "$object"
3041016ad83Smrg  if test "$libtool" = yes; then
3051016ad83Smrg    tmpdepfile1=$dir$base.u
3061016ad83Smrg    tmpdepfile2=$base.u
3071016ad83Smrg    tmpdepfile3=$dir.libs/$base.u
3081016ad83Smrg    "$@" -Wc,-M
3091016ad83Smrg  else
3101016ad83Smrg    tmpdepfile1=$dir$base.u
3111016ad83Smrg    tmpdepfile2=$dir$base.u
3121016ad83Smrg    tmpdepfile3=$dir$base.u
3131016ad83Smrg    "$@" -M
3141016ad83Smrg  fi
3151016ad83Smrg  stat=$?
3161016ad83Smrg  if test $stat -ne 0; then
3171016ad83Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3181016ad83Smrg    exit $stat
3191016ad83Smrg  fi
3201016ad83Smrg
3211016ad83Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3221016ad83Smrg  do
3231016ad83Smrg    test -f "$tmpdepfile" && break
3241016ad83Smrg  done
3251016ad83Smrg  aix_post_process_depfile
3261016ad83Smrg  ;;
3271016ad83Smrg
3281016ad83Smrgtcc)
3291016ad83Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3301016ad83Smrg  # FIXME: That version still under development at the moment of writing.
3311016ad83Smrg  #        Make that this statement remains true also for stable, released
3321016ad83Smrg  #        versions.
3331016ad83Smrg  # It will wrap lines (doesn't matter whether long or short) with a
3341016ad83Smrg  # trailing '\', as in:
3351016ad83Smrg  #
3361016ad83Smrg  #   foo.o : \
3371016ad83Smrg  #    foo.c \
3381016ad83Smrg  #    foo.h \
3391016ad83Smrg  #
3401016ad83Smrg  # It will put a trailing '\' even on the last line, and will use leading
3411016ad83Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3421016ad83Smrg  # "Emit spaces for -MD").
3431016ad83Smrg  "$@" -MD -MF "$tmpdepfile"
3441016ad83Smrg  stat=$?
3451016ad83Smrg  if test $stat -ne 0; then
3461016ad83Smrg    rm -f "$tmpdepfile"
3471016ad83Smrg    exit $stat
3481016ad83Smrg  fi
3491016ad83Smrg  rm -f "$depfile"
3501016ad83Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3511016ad83Smrg  # We have to change lines of the first kind to '$object: \'.
3521016ad83Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3531016ad83Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3541016ad83Smrg  # dummy dependency, to avoid the deleted-header problem.
3551016ad83Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3561016ad83Smrg  rm -f "$tmpdepfile"
3571016ad83Smrg  ;;
3581016ad83Smrg
3591016ad83Smrg## The order of this option in the case statement is important, since the
3601016ad83Smrg## shell code in configure will try each of these formats in the order
3611016ad83Smrg## listed in this file.  A plain '-MD' option would be understood by many
3621016ad83Smrg## compilers, so we must ensure this comes after the gcc and icc options.
3631016ad83Smrgpgcc)
3641016ad83Smrg  # Portland's C compiler understands '-MD'.
3651016ad83Smrg  # Will always output deps to 'file.d' where file is the root name of the
3661016ad83Smrg  # source file under compilation, even if file resides in a subdirectory.
3671016ad83Smrg  # The object file name does not affect the name of the '.d' file.
3681016ad83Smrg  # pgcc 10.2 will output
3691016ad83Smrg  #    foo.o: sub/foo.c sub/foo.h
3701016ad83Smrg  # and will wrap long lines using '\' :
3711016ad83Smrg  #    foo.o: sub/foo.c ... \
3721016ad83Smrg  #     sub/foo.h ... \
3731016ad83Smrg  #     ...
3741016ad83Smrg  set_dir_from "$object"
3751016ad83Smrg  # Use the source, not the object, to determine the base name, since
3761016ad83Smrg  # that's sadly what pgcc will do too.
3771016ad83Smrg  set_base_from "$source"
3781016ad83Smrg  tmpdepfile=$base.d
3791016ad83Smrg
3801016ad83Smrg  # For projects that build the same source file twice into different object
3811016ad83Smrg  # files, the pgcc approach of using the *source* file root name can cause
3821016ad83Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3831016ad83Smrg  # the same $tmpdepfile.
3841016ad83Smrg  lockdir=$base.d-lock
3851016ad83Smrg  trap "
3861016ad83Smrg    echo '$0: caught signal, cleaning up...' >&2
3871016ad83Smrg    rmdir '$lockdir'
3881016ad83Smrg    exit 1
3891016ad83Smrg  " 1 2 13 15
3901016ad83Smrg  numtries=100
3911016ad83Smrg  i=$numtries
3921016ad83Smrg  while test $i -gt 0; do
3931016ad83Smrg    # mkdir is a portable test-and-set.
3941016ad83Smrg    if mkdir "$lockdir" 2>/dev/null; then
3951016ad83Smrg      # This process acquired the lock.
3961016ad83Smrg      "$@" -MD
3971016ad83Smrg      stat=$?
3981016ad83Smrg      # Release the lock.
3991016ad83Smrg      rmdir "$lockdir"
4001016ad83Smrg      break
4011016ad83Smrg    else
4021016ad83Smrg      # If the lock is being held by a different process, wait
4031016ad83Smrg      # until the winning process is done or we timeout.
4041016ad83Smrg      while test -d "$lockdir" && test $i -gt 0; do
4051016ad83Smrg        sleep 1
4061016ad83Smrg        i=`expr $i - 1`
4071016ad83Smrg      done
4081016ad83Smrg    fi
4091016ad83Smrg    i=`expr $i - 1`
4101016ad83Smrg  done
4111016ad83Smrg  trap - 1 2 13 15
4121016ad83Smrg  if test $i -le 0; then
4131016ad83Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
4141016ad83Smrg    echo "$0: check lockdir '$lockdir'" >&2
4151016ad83Smrg    exit 1
4161016ad83Smrg  fi
4171016ad83Smrg
4181016ad83Smrg  if test $stat -ne 0; then
4191016ad83Smrg    rm -f "$tmpdepfile"
4201016ad83Smrg    exit $stat
4211016ad83Smrg  fi
4221016ad83Smrg  rm -f "$depfile"
4231016ad83Smrg  # Each line is of the form `foo.o: dependent.h',
4241016ad83Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4251016ad83Smrg  # Do two passes, one to just change these to
4261016ad83Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4271016ad83Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4281016ad83Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4291016ad83Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
4301016ad83Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4311016ad83Smrg    | sed -e 's/$/ :/' >> "$depfile"
4321016ad83Smrg  rm -f "$tmpdepfile"
4331016ad83Smrg  ;;
4341016ad83Smrg
4351016ad83Smrghp2)
4361016ad83Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4371016ad83Smrg  # compilers, which have integrated preprocessors.  The correct option
4381016ad83Smrg  # to use with these is +Maked; it writes dependencies to a file named
4391016ad83Smrg  # 'foo.d', which lands next to the object file, wherever that
4401016ad83Smrg  # happens to be.
4411016ad83Smrg  # Much of this is similar to the tru64 case; see comments there.
4421016ad83Smrg  set_dir_from  "$object"
4431016ad83Smrg  set_base_from "$object"
4441016ad83Smrg  if test "$libtool" = yes; then
4451016ad83Smrg    tmpdepfile1=$dir$base.d
4461016ad83Smrg    tmpdepfile2=$dir.libs/$base.d
4471016ad83Smrg    "$@" -Wc,+Maked
4481016ad83Smrg  else
4491016ad83Smrg    tmpdepfile1=$dir$base.d
4501016ad83Smrg    tmpdepfile2=$dir$base.d
4511016ad83Smrg    "$@" +Maked
4521016ad83Smrg  fi
4531016ad83Smrg  stat=$?
4541016ad83Smrg  if test $stat -ne 0; then
4551016ad83Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4561016ad83Smrg     exit $stat
4571016ad83Smrg  fi
4581016ad83Smrg
4591016ad83Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4601016ad83Smrg  do
4611016ad83Smrg    test -f "$tmpdepfile" && break
4621016ad83Smrg  done
4631016ad83Smrg  if test -f "$tmpdepfile"; then
4641016ad83Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4651016ad83Smrg    # Add 'dependent.h:' lines.
4661016ad83Smrg    sed -ne '2,${
4671016ad83Smrg               s/^ *//
4681016ad83Smrg               s/ \\*$//
4691016ad83Smrg               s/$/:/
4701016ad83Smrg               p
4711016ad83Smrg             }' "$tmpdepfile" >> "$depfile"
4721016ad83Smrg  else
4731016ad83Smrg    make_dummy_depfile
4741016ad83Smrg  fi
4751016ad83Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4761016ad83Smrg  ;;
4771016ad83Smrg
4781016ad83Smrgtru64)
4791016ad83Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4801016ad83Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4811016ad83Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4821016ad83Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4831016ad83Smrg  # Subdirectories are respected.
4841016ad83Smrg  set_dir_from  "$object"
4851016ad83Smrg  set_base_from "$object"
4861016ad83Smrg
4871016ad83Smrg  if test "$libtool" = yes; then
4881016ad83Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4891016ad83Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4901016ad83Smrg    # in $dir$base.o.d.  We have to check for both files, because
4911016ad83Smrg    # one of the two compilations can be disabled.  We should prefer
4921016ad83Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4931016ad83Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4941016ad83Smrg    # the former would cause a distcleancheck panic.
4951016ad83Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4961016ad83Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4971016ad83Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4981016ad83Smrg    "$@" -Wc,-MD
4991016ad83Smrg  else
5001016ad83Smrg    tmpdepfile1=$dir$base.d
5011016ad83Smrg    tmpdepfile2=$dir$base.d
5021016ad83Smrg    tmpdepfile3=$dir$base.d
5031016ad83Smrg    "$@" -MD
5041016ad83Smrg  fi
5051016ad83Smrg
5061016ad83Smrg  stat=$?
5071016ad83Smrg  if test $stat -ne 0; then
5081016ad83Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5091016ad83Smrg    exit $stat
5101016ad83Smrg  fi
5111016ad83Smrg
5121016ad83Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5131016ad83Smrg  do
5141016ad83Smrg    test -f "$tmpdepfile" && break
5151016ad83Smrg  done
5161016ad83Smrg  # Same post-processing that is required for AIX mode.
5171016ad83Smrg  aix_post_process_depfile
5181016ad83Smrg  ;;
5191016ad83Smrg
5201016ad83Smrgmsvc7)
5211016ad83Smrg  if test "$libtool" = yes; then
5221016ad83Smrg    showIncludes=-Wc,-showIncludes
5231016ad83Smrg  else
5241016ad83Smrg    showIncludes=-showIncludes
5251016ad83Smrg  fi
5261016ad83Smrg  "$@" $showIncludes > "$tmpdepfile"
5271016ad83Smrg  stat=$?
5281016ad83Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5291016ad83Smrg  if test $stat -ne 0; then
5301016ad83Smrg    rm -f "$tmpdepfile"
5311016ad83Smrg    exit $stat
5321016ad83Smrg  fi
5331016ad83Smrg  rm -f "$depfile"
5341016ad83Smrg  echo "$object : \\" > "$depfile"
5351016ad83Smrg  # The first sed program below extracts the file names and escapes
5361016ad83Smrg  # backslashes for cygpath.  The second sed program outputs the file
5371016ad83Smrg  # name when reading, but also accumulates all include files in the
5381016ad83Smrg  # hold buffer in order to output them again at the end.  This only
5391016ad83Smrg  # works with sed implementations that can handle large buffers.
5401016ad83Smrg  sed < "$tmpdepfile" -n '
5411016ad83Smrg/^Note: including file:  *\(.*\)/ {
5421016ad83Smrg  s//\1/
5431016ad83Smrg  s/\\/\\\\/g
5441016ad83Smrg  p
5451016ad83Smrg}' | $cygpath_u | sort -u | sed -n '
5461016ad83Smrgs/ /\\ /g
5471016ad83Smrgs/\(.*\)/'"$tab"'\1 \\/p
5481016ad83Smrgs/.\(.*\) \\/\1:/
5491016ad83SmrgH
5501016ad83Smrg$ {
5511016ad83Smrg  s/.*/'"$tab"'/
5521016ad83Smrg  G
5531016ad83Smrg  p
5541016ad83Smrg}' >> "$depfile"
5551016ad83Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5561016ad83Smrg  rm -f "$tmpdepfile"
5571016ad83Smrg  ;;
5581016ad83Smrg
5591016ad83Smrgmsvc7msys)
5601016ad83Smrg  # This case exists only to let depend.m4 do its work.  It works by
5611016ad83Smrg  # looking at the text of this script.  This case will never be run,
5621016ad83Smrg  # since it is checked for above.
5631016ad83Smrg  exit 1
5641016ad83Smrg  ;;
5651016ad83Smrg
5661016ad83Smrg#nosideeffect)
5671016ad83Smrg  # This comment above is used by automake to tell side-effect
5681016ad83Smrg  # dependency tracking mechanisms from slower ones.
5691016ad83Smrg
5701016ad83Smrgdashmstdout)
5711016ad83Smrg  # Important note: in order to support this mode, a compiler *must*
5721016ad83Smrg  # always write the preprocessed file to stdout, regardless of -o.
5731016ad83Smrg  "$@" || exit $?
5741016ad83Smrg
5751016ad83Smrg  # Remove the call to Libtool.
5761016ad83Smrg  if test "$libtool" = yes; then
5771016ad83Smrg    while test "X$1" != 'X--mode=compile'; do
5781016ad83Smrg      shift
5791016ad83Smrg    done
5801016ad83Smrg    shift
5811016ad83Smrg  fi
5821016ad83Smrg
5831016ad83Smrg  # Remove '-o $object'.
5841016ad83Smrg  IFS=" "
5851016ad83Smrg  for arg
5861016ad83Smrg  do
5871016ad83Smrg    case $arg in
5881016ad83Smrg    -o)
5891016ad83Smrg      shift
5901016ad83Smrg      ;;
5911016ad83Smrg    $object)
5921016ad83Smrg      shift
5931016ad83Smrg      ;;
5941016ad83Smrg    *)
5951016ad83Smrg      set fnord "$@" "$arg"
5961016ad83Smrg      shift # fnord
5971016ad83Smrg      shift # $arg
5981016ad83Smrg      ;;
5991016ad83Smrg    esac
6001016ad83Smrg  done
6011016ad83Smrg
6021016ad83Smrg  test -z "$dashmflag" && dashmflag=-M
6031016ad83Smrg  # Require at least two characters before searching for ':'
6041016ad83Smrg  # in the target name.  This is to cope with DOS-style filenames:
6051016ad83Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6061016ad83Smrg  "$@" $dashmflag |
6071016ad83Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6081016ad83Smrg  rm -f "$depfile"
6091016ad83Smrg  cat < "$tmpdepfile" > "$depfile"
6101016ad83Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6111016ad83Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6121016ad83Smrg  tr ' ' "$nl" < "$tmpdepfile" \
6131016ad83Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6141016ad83Smrg    | sed -e 's/$/ :/' >> "$depfile"
6151016ad83Smrg  rm -f "$tmpdepfile"
6161016ad83Smrg  ;;
6171016ad83Smrg
6181016ad83SmrgdashXmstdout)
6191016ad83Smrg  # This case only exists to satisfy depend.m4.  It is never actually
6201016ad83Smrg  # run, as this mode is specially recognized in the preamble.
6211016ad83Smrg  exit 1
6221016ad83Smrg  ;;
6231016ad83Smrg
6241016ad83Smrgmakedepend)
6251016ad83Smrg  "$@" || exit $?
6261016ad83Smrg  # Remove any Libtool call
6271016ad83Smrg  if test "$libtool" = yes; then
6281016ad83Smrg    while test "X$1" != 'X--mode=compile'; do
6291016ad83Smrg      shift
6301016ad83Smrg    done
6311016ad83Smrg    shift
6321016ad83Smrg  fi
6331016ad83Smrg  # X makedepend
6341016ad83Smrg  shift
6351016ad83Smrg  cleared=no eat=no
6361016ad83Smrg  for arg
6371016ad83Smrg  do
6381016ad83Smrg    case $cleared in
6391016ad83Smrg    no)
6401016ad83Smrg      set ""; shift
6411016ad83Smrg      cleared=yes ;;
6421016ad83Smrg    esac
6431016ad83Smrg    if test $eat = yes; then
6441016ad83Smrg      eat=no
6451016ad83Smrg      continue
6461016ad83Smrg    fi
6471016ad83Smrg    case "$arg" in
6481016ad83Smrg    -D*|-I*)
6491016ad83Smrg      set fnord "$@" "$arg"; shift ;;
6501016ad83Smrg    # Strip any option that makedepend may not understand.  Remove
6511016ad83Smrg    # the object too, otherwise makedepend will parse it as a source file.
6521016ad83Smrg    -arch)
6531016ad83Smrg      eat=yes ;;
6541016ad83Smrg    -*|$object)
6551016ad83Smrg      ;;
6561016ad83Smrg    *)
6571016ad83Smrg      set fnord "$@" "$arg"; shift ;;
6581016ad83Smrg    esac
6591016ad83Smrg  done
6601016ad83Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6611016ad83Smrg  touch "$tmpdepfile"
6621016ad83Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6631016ad83Smrg  rm -f "$depfile"
6641016ad83Smrg  # makedepend may prepend the VPATH from the source file name to the object.
6651016ad83Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6661016ad83Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6671016ad83Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6681016ad83Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
6691016ad83Smrg  sed '1,2d' "$tmpdepfile" \
6701016ad83Smrg    | tr ' ' "$nl" \
6711016ad83Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6721016ad83Smrg    | sed -e 's/$/ :/' >> "$depfile"
6731016ad83Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6741016ad83Smrg  ;;
6751016ad83Smrg
6761016ad83Smrgcpp)
6771016ad83Smrg  # Important note: in order to support this mode, a compiler *must*
6781016ad83Smrg  # always write the preprocessed file to stdout.
6791016ad83Smrg  "$@" || exit $?
6801016ad83Smrg
6811016ad83Smrg  # Remove the call to Libtool.
6821016ad83Smrg  if test "$libtool" = yes; then
6831016ad83Smrg    while test "X$1" != 'X--mode=compile'; do
6841016ad83Smrg      shift
6851016ad83Smrg    done
6861016ad83Smrg    shift
6871016ad83Smrg  fi
6881016ad83Smrg
6891016ad83Smrg  # Remove '-o $object'.
6901016ad83Smrg  IFS=" "
6911016ad83Smrg  for arg
6921016ad83Smrg  do
6931016ad83Smrg    case $arg in
6941016ad83Smrg    -o)
6951016ad83Smrg      shift
6961016ad83Smrg      ;;
6971016ad83Smrg    $object)
6981016ad83Smrg      shift
6991016ad83Smrg      ;;
7001016ad83Smrg    *)
7011016ad83Smrg      set fnord "$@" "$arg"
7021016ad83Smrg      shift # fnord
7031016ad83Smrg      shift # $arg
7041016ad83Smrg      ;;
7051016ad83Smrg    esac
7061016ad83Smrg  done
7071016ad83Smrg
7081016ad83Smrg  "$@" -E \
7091016ad83Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7101016ad83Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7111016ad83Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
7121016ad83Smrg  rm -f "$depfile"
7131016ad83Smrg  echo "$object : \\" > "$depfile"
7141016ad83Smrg  cat < "$tmpdepfile" >> "$depfile"
7151016ad83Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7161016ad83Smrg  rm -f "$tmpdepfile"
7171016ad83Smrg  ;;
7181016ad83Smrg
7191016ad83Smrgmsvisualcpp)
7201016ad83Smrg  # Important note: in order to support this mode, a compiler *must*
7211016ad83Smrg  # always write the preprocessed file to stdout.
7221016ad83Smrg  "$@" || exit $?
7231016ad83Smrg
7241016ad83Smrg  # Remove the call to Libtool.
7251016ad83Smrg  if test "$libtool" = yes; then
7261016ad83Smrg    while test "X$1" != 'X--mode=compile'; do
7271016ad83Smrg      shift
7281016ad83Smrg    done
7291016ad83Smrg    shift
7301016ad83Smrg  fi
7311016ad83Smrg
7321016ad83Smrg  IFS=" "
7331016ad83Smrg  for arg
7341016ad83Smrg  do
7351016ad83Smrg    case "$arg" in
7361016ad83Smrg    -o)
7371016ad83Smrg      shift
7381016ad83Smrg      ;;
7391016ad83Smrg    $object)
7401016ad83Smrg      shift
7411016ad83Smrg      ;;
7421016ad83Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7431016ad83Smrg        set fnord "$@"
7441016ad83Smrg        shift
7451016ad83Smrg        shift
7461016ad83Smrg        ;;
7471016ad83Smrg    *)
7481016ad83Smrg        set fnord "$@" "$arg"
7491016ad83Smrg        shift
7501016ad83Smrg        shift
7511016ad83Smrg        ;;
7521016ad83Smrg    esac
7531016ad83Smrg  done
7541016ad83Smrg  "$@" -E 2>/dev/null |
7551016ad83Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7561016ad83Smrg  rm -f "$depfile"
7571016ad83Smrg  echo "$object : \\" > "$depfile"
7581016ad83Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7591016ad83Smrg  echo "$tab" >> "$depfile"
7601016ad83Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7611016ad83Smrg  rm -f "$tmpdepfile"
7621016ad83Smrg  ;;
7631016ad83Smrg
7641016ad83Smrgmsvcmsys)
7651016ad83Smrg  # This case exists only to let depend.m4 do its work.  It works by
7661016ad83Smrg  # looking at the text of this script.  This case will never be run,
7671016ad83Smrg  # since it is checked for above.
7681016ad83Smrg  exit 1
7691016ad83Smrg  ;;
7701016ad83Smrg
7711016ad83Smrgnone)
7721016ad83Smrg  exec "$@"
7731016ad83Smrg  ;;
7741016ad83Smrg
7751016ad83Smrg*)
7761016ad83Smrg  echo "Unknown depmode $depmode" 1>&2
7771016ad83Smrg  exit 1
7781016ad83Smrg  ;;
7791016ad83Smrgesac
7801016ad83Smrg
7811016ad83Smrgexit 0
7821016ad83Smrg
7831016ad83Smrg# Local Variables:
7841016ad83Smrg# mode: shell-script
7851016ad83Smrg# sh-indentation: 2
786fe12f63cSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
7871016ad83Smrg# time-stamp-start: "scriptversion="
7881016ad83Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789245c37e9Smrg# time-stamp-time-zone: "UTC0"
7901016ad83Smrg# time-stamp-end: "; # UTC"
7911016ad83Smrg# End:
792