1b1297603Smrg#! /bin/sh
2b1297603Smrg# depcomp - compile a program generating dependencies as side-effects
3b1297603Smrg
4a570218aSmrgscriptversion=2018-03-07.03; # UTC
5b1297603Smrg
620f5670eSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
7b1297603Smrg
8b1297603Smrg# This program is free software; you can redistribute it and/or modify
9b1297603Smrg# it under the terms of the GNU General Public License as published by
10b1297603Smrg# the Free Software Foundation; either version 2, or (at your option)
11b1297603Smrg# any later version.
12b1297603Smrg
13b1297603Smrg# This program is distributed in the hope that it will be useful,
14b1297603Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15b1297603Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16b1297603Smrg# GNU General Public License for more details.
17b1297603Smrg
18b1297603Smrg# You should have received a copy of the GNU General Public License
19a570218aSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20b1297603Smrg
21b1297603Smrg# As a special exception to the GNU General Public License, if you
22b1297603Smrg# distribute this file as part of a program that contains a
23b1297603Smrg# configuration script generated by Autoconf, you may include it under
24b1297603Smrg# the same distribution terms that you use for the rest of that program.
25b1297603Smrg
26b1297603Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27b1297603Smrg
28b1297603Smrgcase $1 in
29b1297603Smrg  '')
3033734831Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
3133734831Smrg    exit 1;
3233734831Smrg    ;;
33b1297603Smrg  -h | --h*)
34b1297603Smrg    cat <<\EOF
35b1297603SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36b1297603Smrg
37b1297603SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38b1297603Smrgas side-effects.
39b1297603Smrg
40b1297603SmrgEnvironment variables:
41b1297603Smrg  depmode     Dependency tracking mode.
4233734831Smrg  source      Source file read by 'PROGRAMS ARGS'.
4333734831Smrg  object      Object file output by 'PROGRAMS ARGS'.
44b1297603Smrg  DEPDIR      directory where to store dependencies.
45b1297603Smrg  depfile     Dependency file to output.
4633734831Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
47b1297603Smrg  libtool     Whether libtool is used (yes/no).
48b1297603Smrg
49b1297603SmrgReport bugs to <bug-automake@gnu.org>.
50b1297603SmrgEOF
51b1297603Smrg    exit $?
52b1297603Smrg    ;;
53b1297603Smrg  -v | --v*)
54b1297603Smrg    echo "depcomp $scriptversion"
55b1297603Smrg    exit $?
56b1297603Smrg    ;;
57b1297603Smrgesac
58b1297603Smrg
5933734831Smrg# Get the directory component of the given path, and save it in the
6033734831Smrg# global variables '$dir'.  Note that this directory component will
6133734831Smrg# be either empty or ending with a '/' character.  This is deliberate.
6233734831Smrgset_dir_from ()
6333734831Smrg{
6433734831Smrg  case $1 in
6533734831Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
6633734831Smrg      *) dir=;;
6733734831Smrg  esac
6833734831Smrg}
6933734831Smrg
7033734831Smrg# Get the suffix-stripped basename of the given path, and save it the
7133734831Smrg# global variable '$base'.
7233734831Smrgset_base_from ()
7333734831Smrg{
7433734831Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
7533734831Smrg}
7633734831Smrg
7733734831Smrg# If no dependency file was actually created by the compiler invocation,
7833734831Smrg# we still have to create a dummy depfile, to avoid errors with the
7933734831Smrg# Makefile "include basename.Plo" scheme.
8033734831Smrgmake_dummy_depfile ()
8133734831Smrg{
8233734831Smrg  echo "#dummy" > "$depfile"
8333734831Smrg}
8433734831Smrg
8533734831Smrg# Factor out some common post-processing of the generated depfile.
8633734831Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
8733734831Smrgaix_post_process_depfile ()
8833734831Smrg{
8933734831Smrg  # If the compiler actually managed to produce a dependency file,
9033734831Smrg  # post-process it.
9133734831Smrg  if test -f "$tmpdepfile"; then
9233734831Smrg    # Each line is of the form 'foo.o: dependency.h'.
9333734831Smrg    # Do two passes, one to just change these to
9433734831Smrg    #   $object: dependency.h
9533734831Smrg    # and one to simply output
9633734831Smrg    #   dependency.h:
9733734831Smrg    # which is needed to avoid the deleted-header problem.
9833734831Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
9933734831Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
10033734831Smrg    } > "$depfile"
10133734831Smrg    rm -f "$tmpdepfile"
10233734831Smrg  else
10333734831Smrg    make_dummy_depfile
10433734831Smrg  fi
10533734831Smrg}
10633734831Smrg
10733734831Smrg# A tabulation character.
10833734831Smrgtab='	'
10933734831Smrg# A newline character.
11033734831Smrgnl='
11133734831Smrg'
11233734831Smrg# Character ranges might be problematic outside the C locale.
11333734831Smrg# These definitions help.
11433734831Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
11533734831Smrglower=abcdefghijklmnopqrstuvwxyz
11633734831Smrgdigits=0123456789
11733734831Smrgalpha=${upper}${lower}
11833734831Smrg
119b1297603Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120b1297603Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121b1297603Smrg  exit 1
122b1297603Smrgfi
123b1297603Smrg
124b1297603Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125b1297603Smrgdepfile=${depfile-`echo "$object" |
126b1297603Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127b1297603Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128b1297603Smrg
129b1297603Smrgrm -f "$tmpdepfile"
130b1297603Smrg
13133734831Smrg# Avoid interferences from the environment.
13233734831Smrggccflag= dashmflag=
13333734831Smrg
134b1297603Smrg# Some modes work just like other modes, but use different flags.  We
135b1297603Smrg# parameterize here, but still list the modes in the big case below,
136b1297603Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
137b1297603Smrg# here, because this file can only contain one case statement.
138b1297603Smrgif test "$depmode" = hp; then
139b1297603Smrg  # HP compiler uses -M and no extra arg.
140b1297603Smrg  gccflag=-M
141b1297603Smrg  depmode=gcc
142b1297603Smrgfi
143b1297603Smrg
144b1297603Smrgif test "$depmode" = dashXmstdout; then
14533734831Smrg  # This is just like dashmstdout with a different argument.
14633734831Smrg  dashmflag=-xM
14733734831Smrg  depmode=dashmstdout
14833734831Smrgfi
14933734831Smrg
15033734831Smrgcygpath_u="cygpath -u -f -"
15133734831Smrgif test "$depmode" = msvcmsys; then
15233734831Smrg  # This is just like msvisualcpp but w/o cygpath translation.
15333734831Smrg  # Just convert the backslash-escaped backslashes to single forward
15433734831Smrg  # slashes to satisfy depend.m4
15533734831Smrg  cygpath_u='sed s,\\\\,/,g'
15633734831Smrg  depmode=msvisualcpp
15733734831Smrgfi
15833734831Smrg
15933734831Smrgif test "$depmode" = msvc7msys; then
16033734831Smrg  # This is just like msvc7 but w/o cygpath translation.
16133734831Smrg  # Just convert the backslash-escaped backslashes to single forward
16233734831Smrg  # slashes to satisfy depend.m4
16333734831Smrg  cygpath_u='sed s,\\\\,/,g'
16433734831Smrg  depmode=msvc7
16533734831Smrgfi
16633734831Smrg
16733734831Smrgif test "$depmode" = xlc; then
16833734831Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
16933734831Smrg  gccflag=-qmakedep=gcc,-MF
17033734831Smrg  depmode=gcc
171b1297603Smrgfi
172b1297603Smrg
173b1297603Smrgcase "$depmode" in
174b1297603Smrggcc3)
175b1297603Smrg## gcc 3 implements dependency tracking that does exactly what
176b1297603Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177b1297603Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1785b944e2aSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1795b944e2aSmrg## the command line argument order; so add the flags where they
1805b944e2aSmrg## appear in depend2.am.  Note that the slowdown incurred here
1815b944e2aSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1825b944e2aSmrg  for arg
1835b944e2aSmrg  do
1845b944e2aSmrg    case $arg in
1855b944e2aSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1865b944e2aSmrg    *)  set fnord "$@" "$arg" ;;
1875b944e2aSmrg    esac
1885b944e2aSmrg    shift # fnord
1895b944e2aSmrg    shift # $arg
1905b944e2aSmrg  done
1915b944e2aSmrg  "$@"
192b1297603Smrg  stat=$?
19333734831Smrg  if test $stat -ne 0; then
194b1297603Smrg    rm -f "$tmpdepfile"
195b1297603Smrg    exit $stat
196b1297603Smrg  fi
197b1297603Smrg  mv "$tmpdepfile" "$depfile"
198b1297603Smrg  ;;
199b1297603Smrg
200b1297603Smrggcc)
20133734831Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
20233734831Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
20333734831Smrg## (see the conditional assignment to $gccflag above).
204b1297603Smrg## There are various ways to get dependency output from gcc.  Here's
205b1297603Smrg## why we pick this rather obscure method:
206b1297603Smrg## - Don't want to use -MD because we'd like the dependencies to end
207b1297603Smrg##   up in a subdir.  Having to rename by hand is ugly.
208b1297603Smrg##   (We might end up doing this anyway to support other compilers.)
209b1297603Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
21033734831Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
21133734831Smrg##   supported by the other compilers which use the 'gcc' depmode.
212b1297603Smrg## - Using -M directly means running the compiler twice (even worse
213b1297603Smrg##   than renaming).
214b1297603Smrg  if test -z "$gccflag"; then
215b1297603Smrg    gccflag=-MD,
216b1297603Smrg  fi
217b1297603Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
218b1297603Smrg  stat=$?
21933734831Smrg  if test $stat -ne 0; then
220b1297603Smrg    rm -f "$tmpdepfile"
221b1297603Smrg    exit $stat
222b1297603Smrg  fi
223b1297603Smrg  rm -f "$depfile"
224b1297603Smrg  echo "$object : \\" > "$depfile"
22533734831Smrg  # The second -e expression handles DOS-style file names with drive
22633734831Smrg  # letters.
227b1297603Smrg  sed -e 's/^[^:]*: / /' \
228b1297603Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
22933734831Smrg## This next piece of magic avoids the "deleted header file" problem.
230b1297603Smrg## The problem is that when a header file which appears in a .P file
231b1297603Smrg## is deleted, the dependency causes make to die (because there is
232b1297603Smrg## typically no way to rebuild the header).  We avoid this by adding
233b1297603Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
234b1297603Smrg## this for us directly.
23533734831Smrg## Some versions of gcc put a space before the ':'.  On the theory
236b1297603Smrg## that the space means something, we add a space to the output as
23733734831Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
23833734831Smrg## to the object.  Take care to not repeat it in the output.
239b1297603Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
240b1297603Smrg## correctly.  Breaking it into two sed invocations is a workaround.
24133734831Smrg  tr ' ' "$nl" < "$tmpdepfile" \
24233734831Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
24333734831Smrg    | sed -e 's/$/ :/' >> "$depfile"
244b1297603Smrg  rm -f "$tmpdepfile"
245b1297603Smrg  ;;
246b1297603Smrg
247b1297603Smrghp)
248b1297603Smrg  # This case exists only to let depend.m4 do its work.  It works by
249b1297603Smrg  # looking at the text of this script.  This case will never be run,
250b1297603Smrg  # since it is checked for above.
251b1297603Smrg  exit 1
252b1297603Smrg  ;;
253b1297603Smrg
254b1297603Smrgsgi)
255b1297603Smrg  if test "$libtool" = yes; then
256b1297603Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
257b1297603Smrg  else
258b1297603Smrg    "$@" -MDupdate "$tmpdepfile"
259b1297603Smrg  fi
260b1297603Smrg  stat=$?
26133734831Smrg  if test $stat -ne 0; then
262b1297603Smrg    rm -f "$tmpdepfile"
263b1297603Smrg    exit $stat
264b1297603Smrg  fi
265b1297603Smrg  rm -f "$depfile"
266b1297603Smrg
267b1297603Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268b1297603Smrg    echo "$object : \\" > "$depfile"
269b1297603Smrg    # Clip off the initial element (the dependent).  Don't try to be
270b1297603Smrg    # clever and replace this with sed code, as IRIX sed won't handle
271b1297603Smrg    # lines with more than a fixed number of characters (4096 in
272b1297603Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
27333734831Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
274b1297603Smrg    # dependency line.
27533734831Smrg    tr ' ' "$nl" < "$tmpdepfile" \
27633734831Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
27733734831Smrg      | tr "$nl" ' ' >> "$depfile"
27833734831Smrg    echo >> "$depfile"
279b1297603Smrg    # The second pass generates a dummy entry for each header file.
28033734831Smrg    tr ' ' "$nl" < "$tmpdepfile" \
28133734831Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
28233734831Smrg      >> "$depfile"
283b1297603Smrg  else
28433734831Smrg    make_dummy_depfile
285b1297603Smrg  fi
286b1297603Smrg  rm -f "$tmpdepfile"
287b1297603Smrg  ;;
288b1297603Smrg
28933734831Smrgxlc)
29033734831Smrg  # This case exists only to let depend.m4 do its work.  It works by
29133734831Smrg  # looking at the text of this script.  This case will never be run,
29233734831Smrg  # since it is checked for above.
29333734831Smrg  exit 1
29433734831Smrg  ;;
29533734831Smrg
296b1297603Smrgaix)
297b1297603Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
298b1297603Smrg  # in a .u file.  In older versions, this file always lives in the
29933734831Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
300b1297603Smrg  # start of each line; $object doesn't have directory information.
301b1297603Smrg  # Version 6 uses the directory in both cases.
30233734831Smrg  set_dir_from "$object"
30333734831Smrg  set_base_from "$object"
304b1297603Smrg  if test "$libtool" = yes; then
30533734831Smrg    tmpdepfile1=$dir$base.u
30633734831Smrg    tmpdepfile2=$base.u
30733734831Smrg    tmpdepfile3=$dir.libs/$base.u
308b1297603Smrg    "$@" -Wc,-M
309b1297603Smrg  else
31033734831Smrg    tmpdepfile1=$dir$base.u
31133734831Smrg    tmpdepfile2=$dir$base.u
31233734831Smrg    tmpdepfile3=$dir$base.u
313b1297603Smrg    "$@" -M
314b1297603Smrg  fi
315b1297603Smrg  stat=$?
31633734831Smrg  if test $stat -ne 0; then
31733734831Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31833734831Smrg    exit $stat
319b1297603Smrg  fi
320b1297603Smrg
32133734831Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
32233734831Smrg  do
32333734831Smrg    test -f "$tmpdepfile" && break
32433734831Smrg  done
32533734831Smrg  aix_post_process_depfile
32633734831Smrg  ;;
32733734831Smrg
32833734831Smrgtcc)
32933734831Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
33033734831Smrg  # FIXME: That version still under development at the moment of writing.
33133734831Smrg  #        Make that this statement remains true also for stable, released
33233734831Smrg  #        versions.
33333734831Smrg  # It will wrap lines (doesn't matter whether long or short) with a
33433734831Smrg  # trailing '\', as in:
33533734831Smrg  #
33633734831Smrg  #   foo.o : \
33733734831Smrg  #    foo.c \
33833734831Smrg  #    foo.h \
33933734831Smrg  #
34033734831Smrg  # It will put a trailing '\' even on the last line, and will use leading
34133734831Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
34233734831Smrg  # "Emit spaces for -MD").
34333734831Smrg  "$@" -MD -MF "$tmpdepfile"
34433734831Smrg  stat=$?
34533734831Smrg  if test $stat -ne 0; then
346b1297603Smrg    rm -f "$tmpdepfile"
347b1297603Smrg    exit $stat
348b1297603Smrg  fi
34933734831Smrg  rm -f "$depfile"
35033734831Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
35133734831Smrg  # We have to change lines of the first kind to '$object: \'.
35233734831Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
35333734831Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
35433734831Smrg  # dummy dependency, to avoid the deleted-header problem.
35533734831Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356b1297603Smrg  rm -f "$tmpdepfile"
357b1297603Smrg  ;;
358b1297603Smrg
35933734831Smrg## The order of this option in the case statement is important, since the
36033734831Smrg## shell code in configure will try each of these formats in the order
36133734831Smrg## listed in this file.  A plain '-MD' option would be understood by many
36233734831Smrg## compilers, so we must ensure this comes after the gcc and icc options.
36333734831Smrgpgcc)
36433734831Smrg  # Portland's C compiler understands '-MD'.
36533734831Smrg  # Will always output deps to 'file.d' where file is the root name of the
36633734831Smrg  # source file under compilation, even if file resides in a subdirectory.
36733734831Smrg  # The object file name does not affect the name of the '.d' file.
36833734831Smrg  # pgcc 10.2 will output
369b1297603Smrg  #    foo.o: sub/foo.c sub/foo.h
37033734831Smrg  # and will wrap long lines using '\' :
371b1297603Smrg  #    foo.o: sub/foo.c ... \
372b1297603Smrg  #     sub/foo.h ... \
373b1297603Smrg  #     ...
37433734831Smrg  set_dir_from "$object"
37533734831Smrg  # Use the source, not the object, to determine the base name, since
37633734831Smrg  # that's sadly what pgcc will do too.
37733734831Smrg  set_base_from "$source"
37833734831Smrg  tmpdepfile=$base.d
37933734831Smrg
38033734831Smrg  # For projects that build the same source file twice into different object
38133734831Smrg  # files, the pgcc approach of using the *source* file root name can cause
38233734831Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
38333734831Smrg  # the same $tmpdepfile.
38433734831Smrg  lockdir=$base.d-lock
38533734831Smrg  trap "
38633734831Smrg    echo '$0: caught signal, cleaning up...' >&2
38733734831Smrg    rmdir '$lockdir'
38833734831Smrg    exit 1
38933734831Smrg  " 1 2 13 15
39033734831Smrg  numtries=100
39133734831Smrg  i=$numtries
39233734831Smrg  while test $i -gt 0; do
39333734831Smrg    # mkdir is a portable test-and-set.
39433734831Smrg    if mkdir "$lockdir" 2>/dev/null; then
39533734831Smrg      # This process acquired the lock.
39633734831Smrg      "$@" -MD
39733734831Smrg      stat=$?
39833734831Smrg      # Release the lock.
39933734831Smrg      rmdir "$lockdir"
40033734831Smrg      break
40133734831Smrg    else
40233734831Smrg      # If the lock is being held by a different process, wait
40333734831Smrg      # until the winning process is done or we timeout.
40433734831Smrg      while test -d "$lockdir" && test $i -gt 0; do
40533734831Smrg        sleep 1
40633734831Smrg        i=`expr $i - 1`
40733734831Smrg      done
40833734831Smrg    fi
40933734831Smrg    i=`expr $i - 1`
41033734831Smrg  done
41133734831Smrg  trap - 1 2 13 15
41233734831Smrg  if test $i -le 0; then
41333734831Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
41433734831Smrg    echo "$0: check lockdir '$lockdir'" >&2
41533734831Smrg    exit 1
41633734831Smrg  fi
417b1297603Smrg
41833734831Smrg  if test $stat -ne 0; then
419b1297603Smrg    rm -f "$tmpdepfile"
420b1297603Smrg    exit $stat
421b1297603Smrg  fi
422b1297603Smrg  rm -f "$depfile"
423b1297603Smrg  # Each line is of the form `foo.o: dependent.h',
424b1297603Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425b1297603Smrg  # Do two passes, one to just change these to
426b1297603Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427b1297603Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428b1297603Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429b1297603Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
43033734831Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
43133734831Smrg    | sed -e 's/$/ :/' >> "$depfile"
432b1297603Smrg  rm -f "$tmpdepfile"
433b1297603Smrg  ;;
434b1297603Smrg
4355b944e2aSmrghp2)
4365b944e2aSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4375b944e2aSmrg  # compilers, which have integrated preprocessors.  The correct option
4385b944e2aSmrg  # to use with these is +Maked; it writes dependencies to a file named
4395b944e2aSmrg  # 'foo.d', which lands next to the object file, wherever that
4405b944e2aSmrg  # happens to be.
4415b944e2aSmrg  # Much of this is similar to the tru64 case; see comments there.
44233734831Smrg  set_dir_from  "$object"
44333734831Smrg  set_base_from "$object"
4445b944e2aSmrg  if test "$libtool" = yes; then
4455b944e2aSmrg    tmpdepfile1=$dir$base.d
4465b944e2aSmrg    tmpdepfile2=$dir.libs/$base.d
4475b944e2aSmrg    "$@" -Wc,+Maked
4485b944e2aSmrg  else
4495b944e2aSmrg    tmpdepfile1=$dir$base.d
4505b944e2aSmrg    tmpdepfile2=$dir$base.d
4515b944e2aSmrg    "$@" +Maked
4525b944e2aSmrg  fi
4535b944e2aSmrg  stat=$?
45433734831Smrg  if test $stat -ne 0; then
4555b944e2aSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4565b944e2aSmrg     exit $stat
4575b944e2aSmrg  fi
4585b944e2aSmrg
4595b944e2aSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4605b944e2aSmrg  do
4615b944e2aSmrg    test -f "$tmpdepfile" && break
4625b944e2aSmrg  done
4635b944e2aSmrg  if test -f "$tmpdepfile"; then
46433734831Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
46533734831Smrg    # Add 'dependent.h:' lines.
46633734831Smrg    sed -ne '2,${
46733734831Smrg               s/^ *//
46833734831Smrg               s/ \\*$//
46933734831Smrg               s/$/:/
47033734831Smrg               p
47133734831Smrg             }' "$tmpdepfile" >> "$depfile"
4725b944e2aSmrg  else
47333734831Smrg    make_dummy_depfile
4745b944e2aSmrg  fi
4755b944e2aSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4765b944e2aSmrg  ;;
4775b944e2aSmrg
478b1297603Smrgtru64)
47933734831Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
48033734831Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
48133734831Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
48233734831Smrg  # dependencies in 'foo.d' instead, so we check for that too.
48333734831Smrg  # Subdirectories are respected.
48433734831Smrg  set_dir_from  "$object"
48533734831Smrg  set_base_from "$object"
48633734831Smrg
48733734831Smrg  if test "$libtool" = yes; then
48833734831Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
48933734831Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
49033734831Smrg    # in $dir$base.o.d.  We have to check for both files, because
49133734831Smrg    # one of the two compilations can be disabled.  We should prefer
49233734831Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
49333734831Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
49433734831Smrg    # the former would cause a distcleancheck panic.
49533734831Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
49633734831Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
49733734831Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
49833734831Smrg    "$@" -Wc,-MD
49933734831Smrg  else
50033734831Smrg    tmpdepfile1=$dir$base.d
50133734831Smrg    tmpdepfile2=$dir$base.d
50233734831Smrg    tmpdepfile3=$dir$base.d
50333734831Smrg    "$@" -MD
50433734831Smrg  fi
50533734831Smrg
50633734831Smrg  stat=$?
50733734831Smrg  if test $stat -ne 0; then
50833734831Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
50933734831Smrg    exit $stat
51033734831Smrg  fi
51133734831Smrg
51233734831Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
51333734831Smrg  do
51433734831Smrg    test -f "$tmpdepfile" && break
51533734831Smrg  done
51633734831Smrg  # Same post-processing that is required for AIX mode.
51733734831Smrg  aix_post_process_depfile
51833734831Smrg  ;;
51933734831Smrg
52033734831Smrgmsvc7)
52133734831Smrg  if test "$libtool" = yes; then
52233734831Smrg    showIncludes=-Wc,-showIncludes
52333734831Smrg  else
52433734831Smrg    showIncludes=-showIncludes
52533734831Smrg  fi
52633734831Smrg  "$@" $showIncludes > "$tmpdepfile"
52733734831Smrg  stat=$?
52833734831Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
52933734831Smrg  if test $stat -ne 0; then
53033734831Smrg    rm -f "$tmpdepfile"
53133734831Smrg    exit $stat
53233734831Smrg  fi
53333734831Smrg  rm -f "$depfile"
53433734831Smrg  echo "$object : \\" > "$depfile"
53533734831Smrg  # The first sed program below extracts the file names and escapes
53633734831Smrg  # backslashes for cygpath.  The second sed program outputs the file
53733734831Smrg  # name when reading, but also accumulates all include files in the
53833734831Smrg  # hold buffer in order to output them again at the end.  This only
53933734831Smrg  # works with sed implementations that can handle large buffers.
54033734831Smrg  sed < "$tmpdepfile" -n '
54133734831Smrg/^Note: including file:  *\(.*\)/ {
54233734831Smrg  s//\1/
54333734831Smrg  s/\\/\\\\/g
54433734831Smrg  p
54533734831Smrg}' | $cygpath_u | sort -u | sed -n '
54633734831Smrgs/ /\\ /g
54733734831Smrgs/\(.*\)/'"$tab"'\1 \\/p
54833734831Smrgs/.\(.*\) \\/\1:/
54933734831SmrgH
55033734831Smrg$ {
55133734831Smrg  s/.*/'"$tab"'/
55233734831Smrg  G
55333734831Smrg  p
55433734831Smrg}' >> "$depfile"
555a570218aSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
55633734831Smrg  rm -f "$tmpdepfile"
55733734831Smrg  ;;
55833734831Smrg
55933734831Smrgmsvc7msys)
56033734831Smrg  # This case exists only to let depend.m4 do its work.  It works by
56133734831Smrg  # looking at the text of this script.  This case will never be run,
56233734831Smrg  # since it is checked for above.
56333734831Smrg  exit 1
56433734831Smrg  ;;
565b1297603Smrg
566b1297603Smrg#nosideeffect)
567b1297603Smrg  # This comment above is used by automake to tell side-effect
568b1297603Smrg  # dependency tracking mechanisms from slower ones.
569b1297603Smrg
570b1297603Smrgdashmstdout)
571b1297603Smrg  # Important note: in order to support this mode, a compiler *must*
572b1297603Smrg  # always write the preprocessed file to stdout, regardless of -o.
573b1297603Smrg  "$@" || exit $?
574b1297603Smrg
575b1297603Smrg  # Remove the call to Libtool.
576b1297603Smrg  if test "$libtool" = yes; then
57733734831Smrg    while test "X$1" != 'X--mode=compile'; do
578b1297603Smrg      shift
579b1297603Smrg    done
580b1297603Smrg    shift
581b1297603Smrg  fi
582b1297603Smrg
58333734831Smrg  # Remove '-o $object'.
584b1297603Smrg  IFS=" "
585b1297603Smrg  for arg
586b1297603Smrg  do
587b1297603Smrg    case $arg in
588b1297603Smrg    -o)
589b1297603Smrg      shift
590b1297603Smrg      ;;
591b1297603Smrg    $object)
592b1297603Smrg      shift
593b1297603Smrg      ;;
594b1297603Smrg    *)
595b1297603Smrg      set fnord "$@" "$arg"
596b1297603Smrg      shift # fnord
597b1297603Smrg      shift # $arg
598b1297603Smrg      ;;
599b1297603Smrg    esac
600b1297603Smrg  done
601b1297603Smrg
602b1297603Smrg  test -z "$dashmflag" && dashmflag=-M
60333734831Smrg  # Require at least two characters before searching for ':'
604b1297603Smrg  # in the target name.  This is to cope with DOS-style filenames:
60533734831Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606b1297603Smrg  "$@" $dashmflag |
60733734831Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608b1297603Smrg  rm -f "$depfile"
609b1297603Smrg  cat < "$tmpdepfile" > "$depfile"
61033734831Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
61133734831Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
61233734831Smrg  tr ' ' "$nl" < "$tmpdepfile" \
61333734831Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
61433734831Smrg    | sed -e 's/$/ :/' >> "$depfile"
615b1297603Smrg  rm -f "$tmpdepfile"
616b1297603Smrg  ;;
617b1297603Smrg
618b1297603SmrgdashXmstdout)
619b1297603Smrg  # This case only exists to satisfy depend.m4.  It is never actually
620b1297603Smrg  # run, as this mode is specially recognized in the preamble.
621b1297603Smrg  exit 1
622b1297603Smrg  ;;
623b1297603Smrg
624b1297603Smrgmakedepend)
625b1297603Smrg  "$@" || exit $?
626b1297603Smrg  # Remove any Libtool call
627b1297603Smrg  if test "$libtool" = yes; then
62833734831Smrg    while test "X$1" != 'X--mode=compile'; do
629b1297603Smrg      shift
630b1297603Smrg    done
631b1297603Smrg    shift
632b1297603Smrg  fi
633b1297603Smrg  # X makedepend
634b1297603Smrg  shift
63533734831Smrg  cleared=no eat=no
63633734831Smrg  for arg
63733734831Smrg  do
638b1297603Smrg    case $cleared in
639b1297603Smrg    no)
640b1297603Smrg      set ""; shift
641b1297603Smrg      cleared=yes ;;
642b1297603Smrg    esac
64333734831Smrg    if test $eat = yes; then
64433734831Smrg      eat=no
64533734831Smrg      continue
64633734831Smrg    fi
647b1297603Smrg    case "$arg" in
648b1297603Smrg    -D*|-I*)
649b1297603Smrg      set fnord "$@" "$arg"; shift ;;
650b1297603Smrg    # Strip any option that makedepend may not understand.  Remove
651b1297603Smrg    # the object too, otherwise makedepend will parse it as a source file.
65233734831Smrg    -arch)
65333734831Smrg      eat=yes ;;
654b1297603Smrg    -*|$object)
655b1297603Smrg      ;;
656b1297603Smrg    *)
657b1297603Smrg      set fnord "$@" "$arg"; shift ;;
658b1297603Smrg    esac
659b1297603Smrg  done
66033734831Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661b1297603Smrg  touch "$tmpdepfile"
662b1297603Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663b1297603Smrg  rm -f "$depfile"
66433734831Smrg  # makedepend may prepend the VPATH from the source file name to the object.
66533734831Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
66633734831Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
66733734831Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
66833734831Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
66933734831Smrg  sed '1,2d' "$tmpdepfile" \
67033734831Smrg    | tr ' ' "$nl" \
67133734831Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
67233734831Smrg    | sed -e 's/$/ :/' >> "$depfile"
673b1297603Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
674b1297603Smrg  ;;
675b1297603Smrg
676b1297603Smrgcpp)
677b1297603Smrg  # Important note: in order to support this mode, a compiler *must*
678b1297603Smrg  # always write the preprocessed file to stdout.
679b1297603Smrg  "$@" || exit $?
680b1297603Smrg
681b1297603Smrg  # Remove the call to Libtool.
682b1297603Smrg  if test "$libtool" = yes; then
68333734831Smrg    while test "X$1" != 'X--mode=compile'; do
684b1297603Smrg      shift
685b1297603Smrg    done
686b1297603Smrg    shift
687b1297603Smrg  fi
688b1297603Smrg
68933734831Smrg  # Remove '-o $object'.
690b1297603Smrg  IFS=" "
691b1297603Smrg  for arg
692b1297603Smrg  do
693b1297603Smrg    case $arg in
694b1297603Smrg    -o)
695b1297603Smrg      shift
696b1297603Smrg      ;;
697b1297603Smrg    $object)
698b1297603Smrg      shift
699b1297603Smrg      ;;
700b1297603Smrg    *)
701b1297603Smrg      set fnord "$@" "$arg"
702b1297603Smrg      shift # fnord
703b1297603Smrg      shift # $arg
704b1297603Smrg      ;;
705b1297603Smrg    esac
706b1297603Smrg  done
707b1297603Smrg
70833734831Smrg  "$@" -E \
70933734831Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71033734831Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
71133734831Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
712b1297603Smrg  rm -f "$depfile"
713b1297603Smrg  echo "$object : \\" > "$depfile"
714b1297603Smrg  cat < "$tmpdepfile" >> "$depfile"
715b1297603Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716b1297603Smrg  rm -f "$tmpdepfile"
717b1297603Smrg  ;;
718b1297603Smrg
719b1297603Smrgmsvisualcpp)
720b1297603Smrg  # Important note: in order to support this mode, a compiler *must*
72133734831Smrg  # always write the preprocessed file to stdout.
722b1297603Smrg  "$@" || exit $?
72333734831Smrg
72433734831Smrg  # Remove the call to Libtool.
72533734831Smrg  if test "$libtool" = yes; then
72633734831Smrg    while test "X$1" != 'X--mode=compile'; do
72733734831Smrg      shift
72833734831Smrg    done
72933734831Smrg    shift
73033734831Smrg  fi
73133734831Smrg
732b1297603Smrg  IFS=" "
733b1297603Smrg  for arg
734b1297603Smrg  do
735b1297603Smrg    case "$arg" in
73633734831Smrg    -o)
73733734831Smrg      shift
73833734831Smrg      ;;
73933734831Smrg    $object)
74033734831Smrg      shift
74133734831Smrg      ;;
742b1297603Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
74333734831Smrg        set fnord "$@"
74433734831Smrg        shift
74533734831Smrg        shift
74633734831Smrg        ;;
747b1297603Smrg    *)
74833734831Smrg        set fnord "$@" "$arg"
74933734831Smrg        shift
75033734831Smrg        shift
75133734831Smrg        ;;
752b1297603Smrg    esac
753b1297603Smrg  done
75433734831Smrg  "$@" -E 2>/dev/null |
75533734831Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756b1297603Smrg  rm -f "$depfile"
757b1297603Smrg  echo "$object : \\" > "$depfile"
75833734831Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
75933734831Smrg  echo "$tab" >> "$depfile"
76033734831Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761b1297603Smrg  rm -f "$tmpdepfile"
762b1297603Smrg  ;;
763b1297603Smrg
76433734831Smrgmsvcmsys)
76533734831Smrg  # This case exists only to let depend.m4 do its work.  It works by
76633734831Smrg  # looking at the text of this script.  This case will never be run,
76733734831Smrg  # since it is checked for above.
76833734831Smrg  exit 1
76933734831Smrg  ;;
77033734831Smrg
771b1297603Smrgnone)
772b1297603Smrg  exec "$@"
773b1297603Smrg  ;;
774b1297603Smrg
775b1297603Smrg*)
776b1297603Smrg  echo "Unknown depmode $depmode" 1>&2
777b1297603Smrg  exit 1
778b1297603Smrg  ;;
779b1297603Smrgesac
780b1297603Smrg
781b1297603Smrgexit 0
782b1297603Smrg
783b1297603Smrg# Local Variables:
784b1297603Smrg# mode: shell-script
785b1297603Smrg# sh-indentation: 2
786a570218aSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
787b1297603Smrg# time-stamp-start: "scriptversion="
788b1297603Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
789a570218aSmrg# time-stamp-time-zone: "UTC0"
79033734831Smrg# time-stamp-end: "; # UTC"
791b1297603Smrg# End:
792