132001f49Smrg#! /bin/sh
232001f49Smrg# depcomp - compile a program generating dependencies as side-effects
332001f49Smrg
47ec3b29aSmrgscriptversion=2016-01-11.22; # UTC
532001f49Smrg
67ec3b29aSmrg# Copyright (C) 1999-2017 Free Software Foundation, Inc.
732001f49Smrg
832001f49Smrg# This program is free software; you can redistribute it and/or modify
932001f49Smrg# it under the terms of the GNU General Public License as published by
1032001f49Smrg# the Free Software Foundation; either version 2, or (at your option)
1132001f49Smrg# any later version.
1232001f49Smrg
1332001f49Smrg# This program is distributed in the hope that it will be useful,
1432001f49Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1532001f49Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1632001f49Smrg# GNU General Public License for more details.
1732001f49Smrg
1832001f49Smrg# You should have received a copy of the GNU General Public License
1932001f49Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2032001f49Smrg
2132001f49Smrg# As a special exception to the GNU General Public License, if you
2232001f49Smrg# distribute this file as part of a program that contains a
2332001f49Smrg# configuration script generated by Autoconf, you may include it under
2432001f49Smrg# the same distribution terms that you use for the rest of that program.
2532001f49Smrg
2632001f49Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2732001f49Smrg
2832001f49Smrgcase $1 in
2932001f49Smrg  '')
3032001f49Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
3132001f49Smrg    exit 1;
3232001f49Smrg    ;;
3332001f49Smrg  -h | --h*)
3432001f49Smrg    cat <<\EOF
3532001f49SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3632001f49Smrg
3732001f49SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3832001f49Smrgas side-effects.
3932001f49Smrg
4032001f49SmrgEnvironment variables:
4132001f49Smrg  depmode     Dependency tracking mode.
4232001f49Smrg  source      Source file read by 'PROGRAMS ARGS'.
4332001f49Smrg  object      Object file output by 'PROGRAMS ARGS'.
4432001f49Smrg  DEPDIR      directory where to store dependencies.
4532001f49Smrg  depfile     Dependency file to output.
4632001f49Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
4732001f49Smrg  libtool     Whether libtool is used (yes/no).
4832001f49Smrg
4932001f49SmrgReport bugs to <bug-automake@gnu.org>.
5032001f49SmrgEOF
5132001f49Smrg    exit $?
5232001f49Smrg    ;;
5332001f49Smrg  -v | --v*)
5432001f49Smrg    echo "depcomp $scriptversion"
5532001f49Smrg    exit $?
5632001f49Smrg    ;;
5732001f49Smrgesac
5832001f49Smrg
5932001f49Smrg# Get the directory component of the given path, and save it in the
6032001f49Smrg# global variables '$dir'.  Note that this directory component will
6132001f49Smrg# be either empty or ending with a '/' character.  This is deliberate.
6232001f49Smrgset_dir_from ()
6332001f49Smrg{
6432001f49Smrg  case $1 in
6532001f49Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
6632001f49Smrg      *) dir=;;
6732001f49Smrg  esac
6832001f49Smrg}
6932001f49Smrg
7032001f49Smrg# Get the suffix-stripped basename of the given path, and save it the
7132001f49Smrg# global variable '$base'.
7232001f49Smrgset_base_from ()
7332001f49Smrg{
7432001f49Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
7532001f49Smrg}
7632001f49Smrg
7732001f49Smrg# If no dependency file was actually created by the compiler invocation,
7832001f49Smrg# we still have to create a dummy depfile, to avoid errors with the
7932001f49Smrg# Makefile "include basename.Plo" scheme.
8032001f49Smrgmake_dummy_depfile ()
8132001f49Smrg{
8232001f49Smrg  echo "#dummy" > "$depfile"
8332001f49Smrg}
8432001f49Smrg
8532001f49Smrg# Factor out some common post-processing of the generated depfile.
8632001f49Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
8732001f49Smrgaix_post_process_depfile ()
8832001f49Smrg{
8932001f49Smrg  # If the compiler actually managed to produce a dependency file,
9032001f49Smrg  # post-process it.
9132001f49Smrg  if test -f "$tmpdepfile"; then
9232001f49Smrg    # Each line is of the form 'foo.o: dependency.h'.
9332001f49Smrg    # Do two passes, one to just change these to
9432001f49Smrg    #   $object: dependency.h
9532001f49Smrg    # and one to simply output
9632001f49Smrg    #   dependency.h:
9732001f49Smrg    # which is needed to avoid the deleted-header problem.
9832001f49Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
9932001f49Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
10032001f49Smrg    } > "$depfile"
10132001f49Smrg    rm -f "$tmpdepfile"
10232001f49Smrg  else
10332001f49Smrg    make_dummy_depfile
10432001f49Smrg  fi
10532001f49Smrg}
10632001f49Smrg
10732001f49Smrg# A tabulation character.
10832001f49Smrgtab='	'
10932001f49Smrg# A newline character.
11032001f49Smrgnl='
11132001f49Smrg'
11232001f49Smrg# Character ranges might be problematic outside the C locale.
11332001f49Smrg# These definitions help.
11432001f49Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
11532001f49Smrglower=abcdefghijklmnopqrstuvwxyz
11632001f49Smrgdigits=0123456789
11732001f49Smrgalpha=${upper}${lower}
11832001f49Smrg
11932001f49Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12032001f49Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12132001f49Smrg  exit 1
12232001f49Smrgfi
12332001f49Smrg
12432001f49Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12532001f49Smrgdepfile=${depfile-`echo "$object" |
12632001f49Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12732001f49Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12832001f49Smrg
12932001f49Smrgrm -f "$tmpdepfile"
13032001f49Smrg
13132001f49Smrg# Avoid interferences from the environment.
13232001f49Smrggccflag= dashmflag=
13332001f49Smrg
13432001f49Smrg# Some modes work just like other modes, but use different flags.  We
13532001f49Smrg# parameterize here, but still list the modes in the big case below,
13632001f49Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13732001f49Smrg# here, because this file can only contain one case statement.
13832001f49Smrgif test "$depmode" = hp; then
13932001f49Smrg  # HP compiler uses -M and no extra arg.
14032001f49Smrg  gccflag=-M
14132001f49Smrg  depmode=gcc
14232001f49Smrgfi
14332001f49Smrg
14432001f49Smrgif test "$depmode" = dashXmstdout; then
14532001f49Smrg  # This is just like dashmstdout with a different argument.
14632001f49Smrg  dashmflag=-xM
14732001f49Smrg  depmode=dashmstdout
14832001f49Smrgfi
14932001f49Smrg
15032001f49Smrgcygpath_u="cygpath -u -f -"
15132001f49Smrgif test "$depmode" = msvcmsys; then
15232001f49Smrg  # This is just like msvisualcpp but w/o cygpath translation.
15332001f49Smrg  # Just convert the backslash-escaped backslashes to single forward
15432001f49Smrg  # slashes to satisfy depend.m4
15532001f49Smrg  cygpath_u='sed s,\\\\,/,g'
15632001f49Smrg  depmode=msvisualcpp
15732001f49Smrgfi
15832001f49Smrg
15932001f49Smrgif test "$depmode" = msvc7msys; then
16032001f49Smrg  # This is just like msvc7 but w/o cygpath translation.
16132001f49Smrg  # Just convert the backslash-escaped backslashes to single forward
16232001f49Smrg  # slashes to satisfy depend.m4
16332001f49Smrg  cygpath_u='sed s,\\\\,/,g'
16432001f49Smrg  depmode=msvc7
16532001f49Smrgfi
16632001f49Smrg
16732001f49Smrgif test "$depmode" = xlc; then
16832001f49Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
16932001f49Smrg  gccflag=-qmakedep=gcc,-MF
17032001f49Smrg  depmode=gcc
17132001f49Smrgfi
17232001f49Smrg
17332001f49Smrgcase "$depmode" in
17432001f49Smrggcc3)
17532001f49Smrg## gcc 3 implements dependency tracking that does exactly what
17632001f49Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17732001f49Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
17832001f49Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
17932001f49Smrg## the command line argument order; so add the flags where they
18032001f49Smrg## appear in depend2.am.  Note that the slowdown incurred here
18132001f49Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
18232001f49Smrg  for arg
18332001f49Smrg  do
18432001f49Smrg    case $arg in
18532001f49Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
18632001f49Smrg    *)  set fnord "$@" "$arg" ;;
18732001f49Smrg    esac
18832001f49Smrg    shift # fnord
18932001f49Smrg    shift # $arg
19032001f49Smrg  done
19132001f49Smrg  "$@"
19232001f49Smrg  stat=$?
19332001f49Smrg  if test $stat -ne 0; then
19432001f49Smrg    rm -f "$tmpdepfile"
19532001f49Smrg    exit $stat
19632001f49Smrg  fi
19732001f49Smrg  mv "$tmpdepfile" "$depfile"
19832001f49Smrg  ;;
19932001f49Smrg
20032001f49Smrggcc)
20132001f49Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
20232001f49Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
20332001f49Smrg## (see the conditional assignment to $gccflag above).
20432001f49Smrg## There are various ways to get dependency output from gcc.  Here's
20532001f49Smrg## why we pick this rather obscure method:
20632001f49Smrg## - Don't want to use -MD because we'd like the dependencies to end
20732001f49Smrg##   up in a subdir.  Having to rename by hand is ugly.
20832001f49Smrg##   (We might end up doing this anyway to support other compilers.)
20932001f49Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
21032001f49Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
21132001f49Smrg##   supported by the other compilers which use the 'gcc' depmode.
21232001f49Smrg## - Using -M directly means running the compiler twice (even worse
21332001f49Smrg##   than renaming).
21432001f49Smrg  if test -z "$gccflag"; then
21532001f49Smrg    gccflag=-MD,
21632001f49Smrg  fi
21732001f49Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
21832001f49Smrg  stat=$?
21932001f49Smrg  if test $stat -ne 0; then
22032001f49Smrg    rm -f "$tmpdepfile"
22132001f49Smrg    exit $stat
22232001f49Smrg  fi
22332001f49Smrg  rm -f "$depfile"
22432001f49Smrg  echo "$object : \\" > "$depfile"
22532001f49Smrg  # The second -e expression handles DOS-style file names with drive
22632001f49Smrg  # letters.
22732001f49Smrg  sed -e 's/^[^:]*: / /' \
22832001f49Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
22932001f49Smrg## This next piece of magic avoids the "deleted header file" problem.
23032001f49Smrg## The problem is that when a header file which appears in a .P file
23132001f49Smrg## is deleted, the dependency causes make to die (because there is
23232001f49Smrg## typically no way to rebuild the header).  We avoid this by adding
23332001f49Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23432001f49Smrg## this for us directly.
23532001f49Smrg## Some versions of gcc put a space before the ':'.  On the theory
23632001f49Smrg## that the space means something, we add a space to the output as
23732001f49Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
23832001f49Smrg## to the object.  Take care to not repeat it in the output.
23932001f49Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
24032001f49Smrg## correctly.  Breaking it into two sed invocations is a workaround.
24132001f49Smrg  tr ' ' "$nl" < "$tmpdepfile" \
24232001f49Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
24332001f49Smrg    | sed -e 's/$/ :/' >> "$depfile"
24432001f49Smrg  rm -f "$tmpdepfile"
24532001f49Smrg  ;;
24632001f49Smrg
24732001f49Smrghp)
24832001f49Smrg  # This case exists only to let depend.m4 do its work.  It works by
24932001f49Smrg  # looking at the text of this script.  This case will never be run,
25032001f49Smrg  # since it is checked for above.
25132001f49Smrg  exit 1
25232001f49Smrg  ;;
25332001f49Smrg
25432001f49Smrgsgi)
25532001f49Smrg  if test "$libtool" = yes; then
25632001f49Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25732001f49Smrg  else
25832001f49Smrg    "$@" -MDupdate "$tmpdepfile"
25932001f49Smrg  fi
26032001f49Smrg  stat=$?
26132001f49Smrg  if test $stat -ne 0; then
26232001f49Smrg    rm -f "$tmpdepfile"
26332001f49Smrg    exit $stat
26432001f49Smrg  fi
26532001f49Smrg  rm -f "$depfile"
26632001f49Smrg
26732001f49Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26832001f49Smrg    echo "$object : \\" > "$depfile"
26932001f49Smrg    # Clip off the initial element (the dependent).  Don't try to be
27032001f49Smrg    # clever and replace this with sed code, as IRIX sed won't handle
27132001f49Smrg    # lines with more than a fixed number of characters (4096 in
27232001f49Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
27332001f49Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
27432001f49Smrg    # dependency line.
27532001f49Smrg    tr ' ' "$nl" < "$tmpdepfile" \
27632001f49Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
27732001f49Smrg      | tr "$nl" ' ' >> "$depfile"
27832001f49Smrg    echo >> "$depfile"
27932001f49Smrg    # The second pass generates a dummy entry for each header file.
28032001f49Smrg    tr ' ' "$nl" < "$tmpdepfile" \
28132001f49Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
28232001f49Smrg      >> "$depfile"
28332001f49Smrg  else
28432001f49Smrg    make_dummy_depfile
28532001f49Smrg  fi
28632001f49Smrg  rm -f "$tmpdepfile"
28732001f49Smrg  ;;
28832001f49Smrg
28932001f49Smrgxlc)
29032001f49Smrg  # This case exists only to let depend.m4 do its work.  It works by
29132001f49Smrg  # looking at the text of this script.  This case will never be run,
29232001f49Smrg  # since it is checked for above.
29332001f49Smrg  exit 1
29432001f49Smrg  ;;
29532001f49Smrg
29632001f49Smrgaix)
29732001f49Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
29832001f49Smrg  # in a .u file.  In older versions, this file always lives in the
29932001f49Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30032001f49Smrg  # start of each line; $object doesn't have directory information.
30132001f49Smrg  # Version 6 uses the directory in both cases.
30232001f49Smrg  set_dir_from "$object"
30332001f49Smrg  set_base_from "$object"
30432001f49Smrg  if test "$libtool" = yes; then
30532001f49Smrg    tmpdepfile1=$dir$base.u
30632001f49Smrg    tmpdepfile2=$base.u
30732001f49Smrg    tmpdepfile3=$dir.libs/$base.u
30832001f49Smrg    "$@" -Wc,-M
30932001f49Smrg  else
31032001f49Smrg    tmpdepfile1=$dir$base.u
31132001f49Smrg    tmpdepfile2=$dir$base.u
31232001f49Smrg    tmpdepfile3=$dir$base.u
31332001f49Smrg    "$@" -M
31432001f49Smrg  fi
31532001f49Smrg  stat=$?
31632001f49Smrg  if test $stat -ne 0; then
31732001f49Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31832001f49Smrg    exit $stat
31932001f49Smrg  fi
32032001f49Smrg
32132001f49Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
32232001f49Smrg  do
32332001f49Smrg    test -f "$tmpdepfile" && break
32432001f49Smrg  done
32532001f49Smrg  aix_post_process_depfile
32632001f49Smrg  ;;
32732001f49Smrg
32832001f49Smrgtcc)
32932001f49Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
33032001f49Smrg  # FIXME: That version still under development at the moment of writing.
33132001f49Smrg  #        Make that this statement remains true also for stable, released
33232001f49Smrg  #        versions.
33332001f49Smrg  # It will wrap lines (doesn't matter whether long or short) with a
33432001f49Smrg  # trailing '\', as in:
33532001f49Smrg  #
33632001f49Smrg  #   foo.o : \
33732001f49Smrg  #    foo.c \
33832001f49Smrg  #    foo.h \
33932001f49Smrg  #
34032001f49Smrg  # It will put a trailing '\' even on the last line, and will use leading
34132001f49Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
34232001f49Smrg  # "Emit spaces for -MD").
34332001f49Smrg  "$@" -MD -MF "$tmpdepfile"
34432001f49Smrg  stat=$?
34532001f49Smrg  if test $stat -ne 0; then
34632001f49Smrg    rm -f "$tmpdepfile"
34732001f49Smrg    exit $stat
34832001f49Smrg  fi
34932001f49Smrg  rm -f "$depfile"
35032001f49Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
35132001f49Smrg  # We have to change lines of the first kind to '$object: \'.
35232001f49Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
35332001f49Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
35432001f49Smrg  # dummy dependency, to avoid the deleted-header problem.
35532001f49Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35632001f49Smrg  rm -f "$tmpdepfile"
35732001f49Smrg  ;;
35832001f49Smrg
35932001f49Smrg## The order of this option in the case statement is important, since the
36032001f49Smrg## shell code in configure will try each of these formats in the order
36132001f49Smrg## listed in this file.  A plain '-MD' option would be understood by many
36232001f49Smrg## compilers, so we must ensure this comes after the gcc and icc options.
36332001f49Smrgpgcc)
36432001f49Smrg  # Portland's C compiler understands '-MD'.
36532001f49Smrg  # Will always output deps to 'file.d' where file is the root name of the
36632001f49Smrg  # source file under compilation, even if file resides in a subdirectory.
36732001f49Smrg  # The object file name does not affect the name of the '.d' file.
36832001f49Smrg  # pgcc 10.2 will output
36932001f49Smrg  #    foo.o: sub/foo.c sub/foo.h
37032001f49Smrg  # and will wrap long lines using '\' :
37132001f49Smrg  #    foo.o: sub/foo.c ... \
37232001f49Smrg  #     sub/foo.h ... \
37332001f49Smrg  #     ...
37432001f49Smrg  set_dir_from "$object"
37532001f49Smrg  # Use the source, not the object, to determine the base name, since
37632001f49Smrg  # that's sadly what pgcc will do too.
37732001f49Smrg  set_base_from "$source"
37832001f49Smrg  tmpdepfile=$base.d
37932001f49Smrg
38032001f49Smrg  # For projects that build the same source file twice into different object
38132001f49Smrg  # files, the pgcc approach of using the *source* file root name can cause
38232001f49Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
38332001f49Smrg  # the same $tmpdepfile.
38432001f49Smrg  lockdir=$base.d-lock
38532001f49Smrg  trap "
38632001f49Smrg    echo '$0: caught signal, cleaning up...' >&2
38732001f49Smrg    rmdir '$lockdir'
38832001f49Smrg    exit 1
38932001f49Smrg  " 1 2 13 15
39032001f49Smrg  numtries=100
39132001f49Smrg  i=$numtries
39232001f49Smrg  while test $i -gt 0; do
39332001f49Smrg    # mkdir is a portable test-and-set.
39432001f49Smrg    if mkdir "$lockdir" 2>/dev/null; then
39532001f49Smrg      # This process acquired the lock.
39632001f49Smrg      "$@" -MD
39732001f49Smrg      stat=$?
39832001f49Smrg      # Release the lock.
39932001f49Smrg      rmdir "$lockdir"
40032001f49Smrg      break
40132001f49Smrg    else
40232001f49Smrg      # If the lock is being held by a different process, wait
40332001f49Smrg      # until the winning process is done or we timeout.
40432001f49Smrg      while test -d "$lockdir" && test $i -gt 0; do
40532001f49Smrg        sleep 1
40632001f49Smrg        i=`expr $i - 1`
40732001f49Smrg      done
40832001f49Smrg    fi
40932001f49Smrg    i=`expr $i - 1`
41032001f49Smrg  done
41132001f49Smrg  trap - 1 2 13 15
41232001f49Smrg  if test $i -le 0; then
41332001f49Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
41432001f49Smrg    echo "$0: check lockdir '$lockdir'" >&2
41532001f49Smrg    exit 1
41632001f49Smrg  fi
41732001f49Smrg
41832001f49Smrg  if test $stat -ne 0; then
41932001f49Smrg    rm -f "$tmpdepfile"
42032001f49Smrg    exit $stat
42132001f49Smrg  fi
42232001f49Smrg  rm -f "$depfile"
42332001f49Smrg  # Each line is of the form `foo.o: dependent.h',
42432001f49Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42532001f49Smrg  # Do two passes, one to just change these to
42632001f49Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42732001f49Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42832001f49Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
42932001f49Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
43032001f49Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
43132001f49Smrg    | sed -e 's/$/ :/' >> "$depfile"
43232001f49Smrg  rm -f "$tmpdepfile"
43332001f49Smrg  ;;
43432001f49Smrg
43532001f49Smrghp2)
43632001f49Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
43732001f49Smrg  # compilers, which have integrated preprocessors.  The correct option
43832001f49Smrg  # to use with these is +Maked; it writes dependencies to a file named
43932001f49Smrg  # 'foo.d', which lands next to the object file, wherever that
44032001f49Smrg  # happens to be.
44132001f49Smrg  # Much of this is similar to the tru64 case; see comments there.
44232001f49Smrg  set_dir_from  "$object"
44332001f49Smrg  set_base_from "$object"
44432001f49Smrg  if test "$libtool" = yes; then
44532001f49Smrg    tmpdepfile1=$dir$base.d
44632001f49Smrg    tmpdepfile2=$dir.libs/$base.d
44732001f49Smrg    "$@" -Wc,+Maked
44832001f49Smrg  else
44932001f49Smrg    tmpdepfile1=$dir$base.d
45032001f49Smrg    tmpdepfile2=$dir$base.d
45132001f49Smrg    "$@" +Maked
45232001f49Smrg  fi
45332001f49Smrg  stat=$?
45432001f49Smrg  if test $stat -ne 0; then
45532001f49Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
45632001f49Smrg     exit $stat
45732001f49Smrg  fi
45832001f49Smrg
45932001f49Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
46032001f49Smrg  do
46132001f49Smrg    test -f "$tmpdepfile" && break
46232001f49Smrg  done
46332001f49Smrg  if test -f "$tmpdepfile"; then
46432001f49Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
46532001f49Smrg    # Add 'dependent.h:' lines.
46632001f49Smrg    sed -ne '2,${
46732001f49Smrg               s/^ *//
46832001f49Smrg               s/ \\*$//
46932001f49Smrg               s/$/:/
47032001f49Smrg               p
47132001f49Smrg             }' "$tmpdepfile" >> "$depfile"
47232001f49Smrg  else
47332001f49Smrg    make_dummy_depfile
47432001f49Smrg  fi
47532001f49Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
47632001f49Smrg  ;;
47732001f49Smrg
47832001f49Smrgtru64)
47932001f49Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
48032001f49Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
48132001f49Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
48232001f49Smrg  # dependencies in 'foo.d' instead, so we check for that too.
48332001f49Smrg  # Subdirectories are respected.
48432001f49Smrg  set_dir_from  "$object"
48532001f49Smrg  set_base_from "$object"
48632001f49Smrg
48732001f49Smrg  if test "$libtool" = yes; then
48832001f49Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
48932001f49Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
49032001f49Smrg    # in $dir$base.o.d.  We have to check for both files, because
49132001f49Smrg    # one of the two compilations can be disabled.  We should prefer
49232001f49Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
49332001f49Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
49432001f49Smrg    # the former would cause a distcleancheck panic.
49532001f49Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
49632001f49Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
49732001f49Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
49832001f49Smrg    "$@" -Wc,-MD
49932001f49Smrg  else
50032001f49Smrg    tmpdepfile1=$dir$base.d
50132001f49Smrg    tmpdepfile2=$dir$base.d
50232001f49Smrg    tmpdepfile3=$dir$base.d
50332001f49Smrg    "$@" -MD
50432001f49Smrg  fi
50532001f49Smrg
50632001f49Smrg  stat=$?
50732001f49Smrg  if test $stat -ne 0; then
50832001f49Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
50932001f49Smrg    exit $stat
51032001f49Smrg  fi
51132001f49Smrg
51232001f49Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
51332001f49Smrg  do
51432001f49Smrg    test -f "$tmpdepfile" && break
51532001f49Smrg  done
51632001f49Smrg  # Same post-processing that is required for AIX mode.
51732001f49Smrg  aix_post_process_depfile
51832001f49Smrg  ;;
51932001f49Smrg
52032001f49Smrgmsvc7)
52132001f49Smrg  if test "$libtool" = yes; then
52232001f49Smrg    showIncludes=-Wc,-showIncludes
52332001f49Smrg  else
52432001f49Smrg    showIncludes=-showIncludes
52532001f49Smrg  fi
52632001f49Smrg  "$@" $showIncludes > "$tmpdepfile"
52732001f49Smrg  stat=$?
52832001f49Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
52932001f49Smrg  if test $stat -ne 0; then
53032001f49Smrg    rm -f "$tmpdepfile"
53132001f49Smrg    exit $stat
53232001f49Smrg  fi
53332001f49Smrg  rm -f "$depfile"
53432001f49Smrg  echo "$object : \\" > "$depfile"
53532001f49Smrg  # The first sed program below extracts the file names and escapes
53632001f49Smrg  # backslashes for cygpath.  The second sed program outputs the file
53732001f49Smrg  # name when reading, but also accumulates all include files in the
53832001f49Smrg  # hold buffer in order to output them again at the end.  This only
53932001f49Smrg  # works with sed implementations that can handle large buffers.
54032001f49Smrg  sed < "$tmpdepfile" -n '
54132001f49Smrg/^Note: including file:  *\(.*\)/ {
54232001f49Smrg  s//\1/
54332001f49Smrg  s/\\/\\\\/g
54432001f49Smrg  p
54532001f49Smrg}' | $cygpath_u | sort -u | sed -n '
54632001f49Smrgs/ /\\ /g
54732001f49Smrgs/\(.*\)/'"$tab"'\1 \\/p
54832001f49Smrgs/.\(.*\) \\/\1:/
54932001f49SmrgH
55032001f49Smrg$ {
55132001f49Smrg  s/.*/'"$tab"'/
55232001f49Smrg  G
55332001f49Smrg  p
55432001f49Smrg}' >> "$depfile"
55532001f49Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
55632001f49Smrg  rm -f "$tmpdepfile"
55732001f49Smrg  ;;
55832001f49Smrg
55932001f49Smrgmsvc7msys)
56032001f49Smrg  # This case exists only to let depend.m4 do its work.  It works by
56132001f49Smrg  # looking at the text of this script.  This case will never be run,
56232001f49Smrg  # since it is checked for above.
56332001f49Smrg  exit 1
56432001f49Smrg  ;;
56532001f49Smrg
56632001f49Smrg#nosideeffect)
56732001f49Smrg  # This comment above is used by automake to tell side-effect
56832001f49Smrg  # dependency tracking mechanisms from slower ones.
56932001f49Smrg
57032001f49Smrgdashmstdout)
57132001f49Smrg  # Important note: in order to support this mode, a compiler *must*
57232001f49Smrg  # always write the preprocessed file to stdout, regardless of -o.
57332001f49Smrg  "$@" || exit $?
57432001f49Smrg
57532001f49Smrg  # Remove the call to Libtool.
57632001f49Smrg  if test "$libtool" = yes; then
57732001f49Smrg    while test "X$1" != 'X--mode=compile'; do
57832001f49Smrg      shift
57932001f49Smrg    done
58032001f49Smrg    shift
58132001f49Smrg  fi
58232001f49Smrg
58332001f49Smrg  # Remove '-o $object'.
58432001f49Smrg  IFS=" "
58532001f49Smrg  for arg
58632001f49Smrg  do
58732001f49Smrg    case $arg in
58832001f49Smrg    -o)
58932001f49Smrg      shift
59032001f49Smrg      ;;
59132001f49Smrg    $object)
59232001f49Smrg      shift
59332001f49Smrg      ;;
59432001f49Smrg    *)
59532001f49Smrg      set fnord "$@" "$arg"
59632001f49Smrg      shift # fnord
59732001f49Smrg      shift # $arg
59832001f49Smrg      ;;
59932001f49Smrg    esac
60032001f49Smrg  done
60132001f49Smrg
60232001f49Smrg  test -z "$dashmflag" && dashmflag=-M
60332001f49Smrg  # Require at least two characters before searching for ':'
60432001f49Smrg  # in the target name.  This is to cope with DOS-style filenames:
60532001f49Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60632001f49Smrg  "$@" $dashmflag |
60732001f49Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60832001f49Smrg  rm -f "$depfile"
60932001f49Smrg  cat < "$tmpdepfile" > "$depfile"
61032001f49Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
61132001f49Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
61232001f49Smrg  tr ' ' "$nl" < "$tmpdepfile" \
61332001f49Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
61432001f49Smrg    | sed -e 's/$/ :/' >> "$depfile"
61532001f49Smrg  rm -f "$tmpdepfile"
61632001f49Smrg  ;;
61732001f49Smrg
61832001f49SmrgdashXmstdout)
61932001f49Smrg  # This case only exists to satisfy depend.m4.  It is never actually
62032001f49Smrg  # run, as this mode is specially recognized in the preamble.
62132001f49Smrg  exit 1
62232001f49Smrg  ;;
62332001f49Smrg
62432001f49Smrgmakedepend)
62532001f49Smrg  "$@" || exit $?
62632001f49Smrg  # Remove any Libtool call
62732001f49Smrg  if test "$libtool" = yes; then
62832001f49Smrg    while test "X$1" != 'X--mode=compile'; do
62932001f49Smrg      shift
63032001f49Smrg    done
63132001f49Smrg    shift
63232001f49Smrg  fi
63332001f49Smrg  # X makedepend
63432001f49Smrg  shift
63532001f49Smrg  cleared=no eat=no
63632001f49Smrg  for arg
63732001f49Smrg  do
63832001f49Smrg    case $cleared in
63932001f49Smrg    no)
64032001f49Smrg      set ""; shift
64132001f49Smrg      cleared=yes ;;
64232001f49Smrg    esac
64332001f49Smrg    if test $eat = yes; then
64432001f49Smrg      eat=no
64532001f49Smrg      continue
64632001f49Smrg    fi
64732001f49Smrg    case "$arg" in
64832001f49Smrg    -D*|-I*)
64932001f49Smrg      set fnord "$@" "$arg"; shift ;;
65032001f49Smrg    # Strip any option that makedepend may not understand.  Remove
65132001f49Smrg    # the object too, otherwise makedepend will parse it as a source file.
65232001f49Smrg    -arch)
65332001f49Smrg      eat=yes ;;
65432001f49Smrg    -*|$object)
65532001f49Smrg      ;;
65632001f49Smrg    *)
65732001f49Smrg      set fnord "$@" "$arg"; shift ;;
65832001f49Smrg    esac
65932001f49Smrg  done
66032001f49Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66132001f49Smrg  touch "$tmpdepfile"
66232001f49Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66332001f49Smrg  rm -f "$depfile"
66432001f49Smrg  # makedepend may prepend the VPATH from the source file name to the object.
66532001f49Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
66632001f49Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
66732001f49Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
66832001f49Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
66932001f49Smrg  sed '1,2d' "$tmpdepfile" \
67032001f49Smrg    | tr ' ' "$nl" \
67132001f49Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
67232001f49Smrg    | sed -e 's/$/ :/' >> "$depfile"
67332001f49Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67432001f49Smrg  ;;
67532001f49Smrg
67632001f49Smrgcpp)
67732001f49Smrg  # Important note: in order to support this mode, a compiler *must*
67832001f49Smrg  # always write the preprocessed file to stdout.
67932001f49Smrg  "$@" || exit $?
68032001f49Smrg
68132001f49Smrg  # Remove the call to Libtool.
68232001f49Smrg  if test "$libtool" = yes; then
68332001f49Smrg    while test "X$1" != 'X--mode=compile'; do
68432001f49Smrg      shift
68532001f49Smrg    done
68632001f49Smrg    shift
68732001f49Smrg  fi
68832001f49Smrg
68932001f49Smrg  # Remove '-o $object'.
69032001f49Smrg  IFS=" "
69132001f49Smrg  for arg
69232001f49Smrg  do
69332001f49Smrg    case $arg in
69432001f49Smrg    -o)
69532001f49Smrg      shift
69632001f49Smrg      ;;
69732001f49Smrg    $object)
69832001f49Smrg      shift
69932001f49Smrg      ;;
70032001f49Smrg    *)
70132001f49Smrg      set fnord "$@" "$arg"
70232001f49Smrg      shift # fnord
70332001f49Smrg      shift # $arg
70432001f49Smrg      ;;
70532001f49Smrg    esac
70632001f49Smrg  done
70732001f49Smrg
70832001f49Smrg  "$@" -E \
70932001f49Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71032001f49Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71132001f49Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
71232001f49Smrg  rm -f "$depfile"
71332001f49Smrg  echo "$object : \\" > "$depfile"
71432001f49Smrg  cat < "$tmpdepfile" >> "$depfile"
71532001f49Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71632001f49Smrg  rm -f "$tmpdepfile"
71732001f49Smrg  ;;
71832001f49Smrg
71932001f49Smrgmsvisualcpp)
72032001f49Smrg  # Important note: in order to support this mode, a compiler *must*
72132001f49Smrg  # always write the preprocessed file to stdout.
72232001f49Smrg  "$@" || exit $?
72332001f49Smrg
72432001f49Smrg  # Remove the call to Libtool.
72532001f49Smrg  if test "$libtool" = yes; then
72632001f49Smrg    while test "X$1" != 'X--mode=compile'; do
72732001f49Smrg      shift
72832001f49Smrg    done
72932001f49Smrg    shift
73032001f49Smrg  fi
73132001f49Smrg
73232001f49Smrg  IFS=" "
73332001f49Smrg  for arg
73432001f49Smrg  do
73532001f49Smrg    case "$arg" in
73632001f49Smrg    -o)
73732001f49Smrg      shift
73832001f49Smrg      ;;
73932001f49Smrg    $object)
74032001f49Smrg      shift
74132001f49Smrg      ;;
74232001f49Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
74332001f49Smrg        set fnord "$@"
74432001f49Smrg        shift
74532001f49Smrg        shift
74632001f49Smrg        ;;
74732001f49Smrg    *)
74832001f49Smrg        set fnord "$@" "$arg"
74932001f49Smrg        shift
75032001f49Smrg        shift
75132001f49Smrg        ;;
75232001f49Smrg    esac
75332001f49Smrg  done
75432001f49Smrg  "$@" -E 2>/dev/null |
75532001f49Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75632001f49Smrg  rm -f "$depfile"
75732001f49Smrg  echo "$object : \\" > "$depfile"
75832001f49Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
75932001f49Smrg  echo "$tab" >> "$depfile"
76032001f49Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76132001f49Smrg  rm -f "$tmpdepfile"
76232001f49Smrg  ;;
76332001f49Smrg
76432001f49Smrgmsvcmsys)
76532001f49Smrg  # This case exists only to let depend.m4 do its work.  It works by
76632001f49Smrg  # looking at the text of this script.  This case will never be run,
76732001f49Smrg  # since it is checked for above.
76832001f49Smrg  exit 1
76932001f49Smrg  ;;
77032001f49Smrg
77132001f49Smrgnone)
77232001f49Smrg  exec "$@"
77332001f49Smrg  ;;
77432001f49Smrg
77532001f49Smrg*)
77632001f49Smrg  echo "Unknown depmode $depmode" 1>&2
77732001f49Smrg  exit 1
77832001f49Smrg  ;;
77932001f49Smrgesac
78032001f49Smrg
78132001f49Smrgexit 0
78232001f49Smrg
78332001f49Smrg# Local Variables:
78432001f49Smrg# mode: shell-script
78532001f49Smrg# sh-indentation: 2
78632001f49Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
78732001f49Smrg# time-stamp-start: "scriptversion="
78832001f49Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7897ec3b29aSmrg# time-stamp-time-zone: "UTC0"
79032001f49Smrg# time-stamp-end: "; # UTC"
79132001f49Smrg# End:
792