14fb28925Smrg#! /bin/sh
24fb28925Smrg# depcomp - compile a program generating dependencies as side-effects
3b66d1acbSmrg
41c145c9fSmrgscriptversion=2018-03-07.03; # UTC
5b66d1acbSmrg
61c145c9fSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
74fb28925Smrg
84fb28925Smrg# This program is free software; you can redistribute it and/or modify
94fb28925Smrg# it under the terms of the GNU General Public License as published by
104fb28925Smrg# the Free Software Foundation; either version 2, or (at your option)
114fb28925Smrg# any later version.
124fb28925Smrg
134fb28925Smrg# This program is distributed in the hope that it will be useful,
144fb28925Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
154fb28925Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
164fb28925Smrg# GNU General Public License for more details.
174fb28925Smrg
184fb28925Smrg# You should have received a copy of the GNU General Public License
191c145c9fSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
204fb28925Smrg
214fb28925Smrg# As a special exception to the GNU General Public License, if you
224fb28925Smrg# distribute this file as part of a program that contains a
234fb28925Smrg# configuration script generated by Autoconf, you may include it under
244fb28925Smrg# the same distribution terms that you use for the rest of that program.
254fb28925Smrg
264fb28925Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
274fb28925Smrg
28b66d1acbSmrgcase $1 in
29b66d1acbSmrg  '')
30df58931aSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31df58931aSmrg    exit 1;
32df58931aSmrg    ;;
33b66d1acbSmrg  -h | --h*)
34b66d1acbSmrg    cat <<\EOF
35b66d1acbSmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36b66d1acbSmrg
37b66d1acbSmrgRun PROGRAMS ARGS to compile a file, generating dependencies
38b66d1acbSmrgas side-effects.
39b66d1acbSmrg
40b66d1acbSmrgEnvironment variables:
41b66d1acbSmrg  depmode     Dependency tracking mode.
42df58931aSmrg  source      Source file read by 'PROGRAMS ARGS'.
43df58931aSmrg  object      Object file output by 'PROGRAMS ARGS'.
44b66d1acbSmrg  DEPDIR      directory where to store dependencies.
45b66d1acbSmrg  depfile     Dependency file to output.
46df58931aSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
47b66d1acbSmrg  libtool     Whether libtool is used (yes/no).
48b66d1acbSmrg
49b66d1acbSmrgReport bugs to <bug-automake@gnu.org>.
50b66d1acbSmrgEOF
51b66d1acbSmrg    exit $?
52b66d1acbSmrg    ;;
53b66d1acbSmrg  -v | --v*)
54b66d1acbSmrg    echo "depcomp $scriptversion"
55b66d1acbSmrg    exit $?
56b66d1acbSmrg    ;;
57b66d1acbSmrgesac
58b66d1acbSmrg
59df58931aSmrg# Get the directory component of the given path, and save it in the
60df58931aSmrg# global variables '$dir'.  Note that this directory component will
61df58931aSmrg# be either empty or ending with a '/' character.  This is deliberate.
62df58931aSmrgset_dir_from ()
63df58931aSmrg{
64df58931aSmrg  case $1 in
65df58931aSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66df58931aSmrg      *) dir=;;
67df58931aSmrg  esac
68df58931aSmrg}
69df58931aSmrg
70df58931aSmrg# Get the suffix-stripped basename of the given path, and save it the
71df58931aSmrg# global variable '$base'.
72df58931aSmrgset_base_from ()
73df58931aSmrg{
74df58931aSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75df58931aSmrg}
76df58931aSmrg
77df58931aSmrg# If no dependency file was actually created by the compiler invocation,
78df58931aSmrg# we still have to create a dummy depfile, to avoid errors with the
79df58931aSmrg# Makefile "include basename.Plo" scheme.
80df58931aSmrgmake_dummy_depfile ()
81df58931aSmrg{
82df58931aSmrg  echo "#dummy" > "$depfile"
83df58931aSmrg}
84df58931aSmrg
85df58931aSmrg# Factor out some common post-processing of the generated depfile.
86df58931aSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87df58931aSmrgaix_post_process_depfile ()
88df58931aSmrg{
89df58931aSmrg  # If the compiler actually managed to produce a dependency file,
90df58931aSmrg  # post-process it.
91df58931aSmrg  if test -f "$tmpdepfile"; then
92df58931aSmrg    # Each line is of the form 'foo.o: dependency.h'.
93df58931aSmrg    # Do two passes, one to just change these to
94df58931aSmrg    #   $object: dependency.h
95df58931aSmrg    # and one to simply output
96df58931aSmrg    #   dependency.h:
97df58931aSmrg    # which is needed to avoid the deleted-header problem.
98df58931aSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99df58931aSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100df58931aSmrg    } > "$depfile"
101df58931aSmrg    rm -f "$tmpdepfile"
102df58931aSmrg  else
103df58931aSmrg    make_dummy_depfile
104df58931aSmrg  fi
105df58931aSmrg}
106df58931aSmrg
107df58931aSmrg# A tabulation character.
108df58931aSmrgtab='	'
109df58931aSmrg# A newline character.
110df58931aSmrgnl='
111df58931aSmrg'
112df58931aSmrg# Character ranges might be problematic outside the C locale.
113df58931aSmrg# These definitions help.
114df58931aSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115df58931aSmrglower=abcdefghijklmnopqrstuvwxyz
116df58931aSmrgdigits=0123456789
117df58931aSmrgalpha=${upper}${lower}
118df58931aSmrg
1194fb28925Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1204fb28925Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1214fb28925Smrg  exit 1
1224fb28925Smrgfi
1234fb28925Smrg
124b66d1acbSmrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125b66d1acbSmrgdepfile=${depfile-`echo "$object" |
126b66d1acbSmrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1274fb28925Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1284fb28925Smrg
1294fb28925Smrgrm -f "$tmpdepfile"
1304fb28925Smrg
131df58931aSmrg# Avoid interferences from the environment.
132df58931aSmrggccflag= dashmflag=
133df58931aSmrg
1344fb28925Smrg# Some modes work just like other modes, but use different flags.  We
1354fb28925Smrg# parameterize here, but still list the modes in the big case below,
1364fb28925Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1374fb28925Smrg# here, because this file can only contain one case statement.
1384fb28925Smrgif test "$depmode" = hp; then
1394fb28925Smrg  # HP compiler uses -M and no extra arg.
1404fb28925Smrg  gccflag=-M
1414fb28925Smrg  depmode=gcc
1424fb28925Smrgfi
1434fb28925Smrg
1444fb28925Smrgif test "$depmode" = dashXmstdout; then
145df58931aSmrg  # This is just like dashmstdout with a different argument.
146df58931aSmrg  dashmflag=-xM
147df58931aSmrg  depmode=dashmstdout
1484fb28925Smrgfi
1494fb28925Smrg
150b66d1acbSmrgcygpath_u="cygpath -u -f -"
151b66d1acbSmrgif test "$depmode" = msvcmsys; then
152df58931aSmrg  # This is just like msvisualcpp but w/o cygpath translation.
153df58931aSmrg  # Just convert the backslash-escaped backslashes to single forward
154df58931aSmrg  # slashes to satisfy depend.m4
155df58931aSmrg  cygpath_u='sed s,\\\\,/,g'
156df58931aSmrg  depmode=msvisualcpp
157df58931aSmrgfi
158df58931aSmrg
159df58931aSmrgif test "$depmode" = msvc7msys; then
160df58931aSmrg  # This is just like msvc7 but w/o cygpath translation.
161df58931aSmrg  # Just convert the backslash-escaped backslashes to single forward
162df58931aSmrg  # slashes to satisfy depend.m4
163df58931aSmrg  cygpath_u='sed s,\\\\,/,g'
164df58931aSmrg  depmode=msvc7
165df58931aSmrgfi
166df58931aSmrg
167df58931aSmrgif test "$depmode" = xlc; then
168df58931aSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169df58931aSmrg  gccflag=-qmakedep=gcc,-MF
170df58931aSmrg  depmode=gcc
171b66d1acbSmrgfi
172b66d1acbSmrg
1734fb28925Smrgcase "$depmode" in
1744fb28925Smrggcc3)
1754fb28925Smrg## gcc 3 implements dependency tracking that does exactly what
1764fb28925Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1774fb28925Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
178b66d1acbSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179b66d1acbSmrg## the command line argument order; so add the flags where they
180b66d1acbSmrg## appear in depend2.am.  Note that the slowdown incurred here
181b66d1acbSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182b66d1acbSmrg  for arg
183b66d1acbSmrg  do
184b66d1acbSmrg    case $arg in
185b66d1acbSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186b66d1acbSmrg    *)  set fnord "$@" "$arg" ;;
187b66d1acbSmrg    esac
188b66d1acbSmrg    shift # fnord
189b66d1acbSmrg    shift # $arg
190b66d1acbSmrg  done
191b66d1acbSmrg  "$@"
1924fb28925Smrg  stat=$?
193df58931aSmrg  if test $stat -ne 0; then
1944fb28925Smrg    rm -f "$tmpdepfile"
1954fb28925Smrg    exit $stat
1964fb28925Smrg  fi
1974fb28925Smrg  mv "$tmpdepfile" "$depfile"
1984fb28925Smrg  ;;
1994fb28925Smrg
2004fb28925Smrggcc)
201df58931aSmrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202df58931aSmrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203df58931aSmrg## (see the conditional assignment to $gccflag above).
2044fb28925Smrg## There are various ways to get dependency output from gcc.  Here's
2054fb28925Smrg## why we pick this rather obscure method:
2064fb28925Smrg## - Don't want to use -MD because we'd like the dependencies to end
2074fb28925Smrg##   up in a subdir.  Having to rename by hand is ugly.
2084fb28925Smrg##   (We might end up doing this anyway to support other compilers.)
2094fb28925Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210df58931aSmrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211df58931aSmrg##   supported by the other compilers which use the 'gcc' depmode.
2124fb28925Smrg## - Using -M directly means running the compiler twice (even worse
2134fb28925Smrg##   than renaming).
2144fb28925Smrg  if test -z "$gccflag"; then
2154fb28925Smrg    gccflag=-MD,
2164fb28925Smrg  fi
2174fb28925Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
2184fb28925Smrg  stat=$?
219df58931aSmrg  if test $stat -ne 0; then
2204fb28925Smrg    rm -f "$tmpdepfile"
2214fb28925Smrg    exit $stat
2224fb28925Smrg  fi
2234fb28925Smrg  rm -f "$depfile"
2244fb28925Smrg  echo "$object : \\" > "$depfile"
225df58931aSmrg  # The second -e expression handles DOS-style file names with drive
226df58931aSmrg  # letters.
2274fb28925Smrg  sed -e 's/^[^:]*: / /' \
2284fb28925Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229df58931aSmrg## This next piece of magic avoids the "deleted header file" problem.
2304fb28925Smrg## The problem is that when a header file which appears in a .P file
2314fb28925Smrg## is deleted, the dependency causes make to die (because there is
2324fb28925Smrg## typically no way to rebuild the header).  We avoid this by adding
2334fb28925Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2344fb28925Smrg## this for us directly.
235df58931aSmrg## Some versions of gcc put a space before the ':'.  On the theory
2364fb28925Smrg## that the space means something, we add a space to the output as
237df58931aSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238df58931aSmrg## to the object.  Take care to not repeat it in the output.
2394fb28925Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
2404fb28925Smrg## correctly.  Breaking it into two sed invocations is a workaround.
241df58931aSmrg  tr ' ' "$nl" < "$tmpdepfile" \
242df58931aSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243df58931aSmrg    | sed -e 's/$/ :/' >> "$depfile"
2444fb28925Smrg  rm -f "$tmpdepfile"
2454fb28925Smrg  ;;
2464fb28925Smrg
2474fb28925Smrghp)
2484fb28925Smrg  # This case exists only to let depend.m4 do its work.  It works by
2494fb28925Smrg  # looking at the text of this script.  This case will never be run,
2504fb28925Smrg  # since it is checked for above.
2514fb28925Smrg  exit 1
2524fb28925Smrg  ;;
2534fb28925Smrg
2544fb28925Smrgsgi)
2554fb28925Smrg  if test "$libtool" = yes; then
2564fb28925Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2574fb28925Smrg  else
2584fb28925Smrg    "$@" -MDupdate "$tmpdepfile"
2594fb28925Smrg  fi
2604fb28925Smrg  stat=$?
261df58931aSmrg  if test $stat -ne 0; then
2624fb28925Smrg    rm -f "$tmpdepfile"
2634fb28925Smrg    exit $stat
2644fb28925Smrg  fi
2654fb28925Smrg  rm -f "$depfile"
2664fb28925Smrg
2674fb28925Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2684fb28925Smrg    echo "$object : \\" > "$depfile"
2694fb28925Smrg    # Clip off the initial element (the dependent).  Don't try to be
2704fb28925Smrg    # clever and replace this with sed code, as IRIX sed won't handle
2714fb28925Smrg    # lines with more than a fixed number of characters (4096 in
2724fb28925Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273df58931aSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
2744fb28925Smrg    # dependency line.
275df58931aSmrg    tr ' ' "$nl" < "$tmpdepfile" \
276df58931aSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277df58931aSmrg      | tr "$nl" ' ' >> "$depfile"
278b66d1acbSmrg    echo >> "$depfile"
2794fb28925Smrg    # The second pass generates a dummy entry for each header file.
280df58931aSmrg    tr ' ' "$nl" < "$tmpdepfile" \
281df58931aSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282df58931aSmrg      >> "$depfile"
2834fb28925Smrg  else
284df58931aSmrg    make_dummy_depfile
2854fb28925Smrg  fi
2864fb28925Smrg  rm -f "$tmpdepfile"
2874fb28925Smrg  ;;
2884fb28925Smrg
289df58931aSmrgxlc)
290df58931aSmrg  # This case exists only to let depend.m4 do its work.  It works by
291df58931aSmrg  # looking at the text of this script.  This case will never be run,
292df58931aSmrg  # since it is checked for above.
293df58931aSmrg  exit 1
294df58931aSmrg  ;;
295df58931aSmrg
2964fb28925Smrgaix)
2974fb28925Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2984fb28925Smrg  # in a .u file.  In older versions, this file always lives in the
299df58931aSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3004fb28925Smrg  # start of each line; $object doesn't have directory information.
3014fb28925Smrg  # Version 6 uses the directory in both cases.
302df58931aSmrg  set_dir_from "$object"
303df58931aSmrg  set_base_from "$object"
3044fb28925Smrg  if test "$libtool" = yes; then
305b66d1acbSmrg    tmpdepfile1=$dir$base.u
306b66d1acbSmrg    tmpdepfile2=$base.u
307b66d1acbSmrg    tmpdepfile3=$dir.libs/$base.u
3084fb28925Smrg    "$@" -Wc,-M
3094fb28925Smrg  else
310b66d1acbSmrg    tmpdepfile1=$dir$base.u
311b66d1acbSmrg    tmpdepfile2=$dir$base.u
312b66d1acbSmrg    tmpdepfile3=$dir$base.u
3134fb28925Smrg    "$@" -M
3144fb28925Smrg  fi
3154fb28925Smrg  stat=$?
316df58931aSmrg  if test $stat -ne 0; then
317b66d1acbSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3184fb28925Smrg    exit $stat
3194fb28925Smrg  fi
3204fb28925Smrg
321b66d1acbSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322b66d1acbSmrg  do
323b66d1acbSmrg    test -f "$tmpdepfile" && break
324b66d1acbSmrg  done
325df58931aSmrg  aix_post_process_depfile
326df58931aSmrg  ;;
327df58931aSmrg
328df58931aSmrgtcc)
329df58931aSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330df58931aSmrg  # FIXME: That version still under development at the moment of writing.
331df58931aSmrg  #        Make that this statement remains true also for stable, released
332df58931aSmrg  #        versions.
333df58931aSmrg  # It will wrap lines (doesn't matter whether long or short) with a
334df58931aSmrg  # trailing '\', as in:
335df58931aSmrg  #
336df58931aSmrg  #   foo.o : \
337df58931aSmrg  #    foo.c \
338df58931aSmrg  #    foo.h \
339df58931aSmrg  #
340df58931aSmrg  # It will put a trailing '\' even on the last line, and will use leading
341df58931aSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342df58931aSmrg  # "Emit spaces for -MD").
343df58931aSmrg  "$@" -MD -MF "$tmpdepfile"
344df58931aSmrg  stat=$?
345df58931aSmrg  if test $stat -ne 0; then
346df58931aSmrg    rm -f "$tmpdepfile"
347df58931aSmrg    exit $stat
3484fb28925Smrg  fi
349df58931aSmrg  rm -f "$depfile"
350df58931aSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351df58931aSmrg  # We have to change lines of the first kind to '$object: \'.
352df58931aSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353df58931aSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354df58931aSmrg  # dummy dependency, to avoid the deleted-header problem.
355df58931aSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3564fb28925Smrg  rm -f "$tmpdepfile"
3574fb28925Smrg  ;;
3584fb28925Smrg
359df58931aSmrg## The order of this option in the case statement is important, since the
360df58931aSmrg## shell code in configure will try each of these formats in the order
361df58931aSmrg## listed in this file.  A plain '-MD' option would be understood by many
362df58931aSmrg## compilers, so we must ensure this comes after the gcc and icc options.
363df58931aSmrgpgcc)
364df58931aSmrg  # Portland's C compiler understands '-MD'.
365df58931aSmrg  # Will always output deps to 'file.d' where file is the root name of the
366df58931aSmrg  # source file under compilation, even if file resides in a subdirectory.
367df58931aSmrg  # The object file name does not affect the name of the '.d' file.
368df58931aSmrg  # pgcc 10.2 will output
3694fb28925Smrg  #    foo.o: sub/foo.c sub/foo.h
370df58931aSmrg  # and will wrap long lines using '\' :
3714fb28925Smrg  #    foo.o: sub/foo.c ... \
3724fb28925Smrg  #     sub/foo.h ... \
3734fb28925Smrg  #     ...
374df58931aSmrg  set_dir_from "$object"
375df58931aSmrg  # Use the source, not the object, to determine the base name, since
376df58931aSmrg  # that's sadly what pgcc will do too.
377df58931aSmrg  set_base_from "$source"
378df58931aSmrg  tmpdepfile=$base.d
379df58931aSmrg
380df58931aSmrg  # For projects that build the same source file twice into different object
381df58931aSmrg  # files, the pgcc approach of using the *source* file root name can cause
382df58931aSmrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383df58931aSmrg  # the same $tmpdepfile.
384df58931aSmrg  lockdir=$base.d-lock
385df58931aSmrg  trap "
386df58931aSmrg    echo '$0: caught signal, cleaning up...' >&2
387df58931aSmrg    rmdir '$lockdir'
388df58931aSmrg    exit 1
389df58931aSmrg  " 1 2 13 15
390df58931aSmrg  numtries=100
391df58931aSmrg  i=$numtries
392df58931aSmrg  while test $i -gt 0; do
393df58931aSmrg    # mkdir is a portable test-and-set.
394df58931aSmrg    if mkdir "$lockdir" 2>/dev/null; then
395df58931aSmrg      # This process acquired the lock.
396df58931aSmrg      "$@" -MD
397df58931aSmrg      stat=$?
398df58931aSmrg      # Release the lock.
399df58931aSmrg      rmdir "$lockdir"
400df58931aSmrg      break
401df58931aSmrg    else
402df58931aSmrg      # If the lock is being held by a different process, wait
403df58931aSmrg      # until the winning process is done or we timeout.
404df58931aSmrg      while test -d "$lockdir" && test $i -gt 0; do
405df58931aSmrg        sleep 1
406df58931aSmrg        i=`expr $i - 1`
407df58931aSmrg      done
408df58931aSmrg    fi
409df58931aSmrg    i=`expr $i - 1`
410df58931aSmrg  done
411df58931aSmrg  trap - 1 2 13 15
412df58931aSmrg  if test $i -le 0; then
413df58931aSmrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414df58931aSmrg    echo "$0: check lockdir '$lockdir'" >&2
415df58931aSmrg    exit 1
416df58931aSmrg  fi
4174fb28925Smrg
418df58931aSmrg  if test $stat -ne 0; then
4194fb28925Smrg    rm -f "$tmpdepfile"
4204fb28925Smrg    exit $stat
4214fb28925Smrg  fi
4224fb28925Smrg  rm -f "$depfile"
4234fb28925Smrg  # Each line is of the form `foo.o: dependent.h',
4244fb28925Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4254fb28925Smrg  # Do two passes, one to just change these to
4264fb28925Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
4274fb28925Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4284fb28925Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
4294fb28925Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
430df58931aSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431df58931aSmrg    | sed -e 's/$/ :/' >> "$depfile"
4324fb28925Smrg  rm -f "$tmpdepfile"
4334fb28925Smrg  ;;
4344fb28925Smrg
435b66d1acbSmrghp2)
436b66d1acbSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437b66d1acbSmrg  # compilers, which have integrated preprocessors.  The correct option
438b66d1acbSmrg  # to use with these is +Maked; it writes dependencies to a file named
439b66d1acbSmrg  # 'foo.d', which lands next to the object file, wherever that
440b66d1acbSmrg  # happens to be.
441b66d1acbSmrg  # Much of this is similar to the tru64 case; see comments there.
442df58931aSmrg  set_dir_from  "$object"
443df58931aSmrg  set_base_from "$object"
444b66d1acbSmrg  if test "$libtool" = yes; then
445b66d1acbSmrg    tmpdepfile1=$dir$base.d
446b66d1acbSmrg    tmpdepfile2=$dir.libs/$base.d
447b66d1acbSmrg    "$@" -Wc,+Maked
448b66d1acbSmrg  else
449b66d1acbSmrg    tmpdepfile1=$dir$base.d
450b66d1acbSmrg    tmpdepfile2=$dir$base.d
451b66d1acbSmrg    "$@" +Maked
452b66d1acbSmrg  fi
453b66d1acbSmrg  stat=$?
454df58931aSmrg  if test $stat -ne 0; then
455b66d1acbSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
456b66d1acbSmrg     exit $stat
457b66d1acbSmrg  fi
458b66d1acbSmrg
459b66d1acbSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460b66d1acbSmrg  do
461b66d1acbSmrg    test -f "$tmpdepfile" && break
462b66d1acbSmrg  done
463b66d1acbSmrg  if test -f "$tmpdepfile"; then
464df58931aSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465df58931aSmrg    # Add 'dependent.h:' lines.
466b66d1acbSmrg    sed -ne '2,${
467df58931aSmrg               s/^ *//
468df58931aSmrg               s/ \\*$//
469df58931aSmrg               s/$/:/
470df58931aSmrg               p
471df58931aSmrg             }' "$tmpdepfile" >> "$depfile"
472b66d1acbSmrg  else
473df58931aSmrg    make_dummy_depfile
474b66d1acbSmrg  fi
475b66d1acbSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
476b66d1acbSmrg  ;;
477b66d1acbSmrg
4784fb28925Smrgtru64)
479df58931aSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
480df58931aSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481df58931aSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482df58931aSmrg  # dependencies in 'foo.d' instead, so we check for that too.
483df58931aSmrg  # Subdirectories are respected.
484df58931aSmrg  set_dir_from  "$object"
485df58931aSmrg  set_base_from "$object"
486df58931aSmrg
487df58931aSmrg  if test "$libtool" = yes; then
488df58931aSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489df58931aSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
490df58931aSmrg    # in $dir$base.o.d.  We have to check for both files, because
491df58931aSmrg    # one of the two compilations can be disabled.  We should prefer
492df58931aSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493df58931aSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
494df58931aSmrg    # the former would cause a distcleancheck panic.
495df58931aSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496df58931aSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497df58931aSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498df58931aSmrg    "$@" -Wc,-MD
499df58931aSmrg  else
500df58931aSmrg    tmpdepfile1=$dir$base.d
501df58931aSmrg    tmpdepfile2=$dir$base.d
502df58931aSmrg    tmpdepfile3=$dir$base.d
503df58931aSmrg    "$@" -MD
504df58931aSmrg  fi
505df58931aSmrg
506df58931aSmrg  stat=$?
507df58931aSmrg  if test $stat -ne 0; then
508df58931aSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509df58931aSmrg    exit $stat
510df58931aSmrg  fi
511df58931aSmrg
512df58931aSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513df58931aSmrg  do
514df58931aSmrg    test -f "$tmpdepfile" && break
515df58931aSmrg  done
516df58931aSmrg  # Same post-processing that is required for AIX mode.
517df58931aSmrg  aix_post_process_depfile
518df58931aSmrg  ;;
519df58931aSmrg
520df58931aSmrgmsvc7)
521df58931aSmrg  if test "$libtool" = yes; then
522df58931aSmrg    showIncludes=-Wc,-showIncludes
523df58931aSmrg  else
524df58931aSmrg    showIncludes=-showIncludes
525df58931aSmrg  fi
526df58931aSmrg  "$@" $showIncludes > "$tmpdepfile"
527df58931aSmrg  stat=$?
528df58931aSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
529df58931aSmrg  if test $stat -ne 0; then
530df58931aSmrg    rm -f "$tmpdepfile"
531df58931aSmrg    exit $stat
532df58931aSmrg  fi
533df58931aSmrg  rm -f "$depfile"
534df58931aSmrg  echo "$object : \\" > "$depfile"
535df58931aSmrg  # The first sed program below extracts the file names and escapes
536df58931aSmrg  # backslashes for cygpath.  The second sed program outputs the file
537df58931aSmrg  # name when reading, but also accumulates all include files in the
538df58931aSmrg  # hold buffer in order to output them again at the end.  This only
539df58931aSmrg  # works with sed implementations that can handle large buffers.
540df58931aSmrg  sed < "$tmpdepfile" -n '
541df58931aSmrg/^Note: including file:  *\(.*\)/ {
542df58931aSmrg  s//\1/
543df58931aSmrg  s/\\/\\\\/g
544df58931aSmrg  p
545df58931aSmrg}' | $cygpath_u | sort -u | sed -n '
546df58931aSmrgs/ /\\ /g
547df58931aSmrgs/\(.*\)/'"$tab"'\1 \\/p
548df58931aSmrgs/.\(.*\) \\/\1:/
549df58931aSmrgH
550df58931aSmrg$ {
551df58931aSmrg  s/.*/'"$tab"'/
552df58931aSmrg  G
553df58931aSmrg  p
554df58931aSmrg}' >> "$depfile"
555df58931aSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556df58931aSmrg  rm -f "$tmpdepfile"
557df58931aSmrg  ;;
558df58931aSmrg
559df58931aSmrgmsvc7msys)
560df58931aSmrg  # This case exists only to let depend.m4 do its work.  It works by
561df58931aSmrg  # looking at the text of this script.  This case will never be run,
562df58931aSmrg  # since it is checked for above.
563df58931aSmrg  exit 1
564df58931aSmrg  ;;
5654fb28925Smrg
5664fb28925Smrg#nosideeffect)
5674fb28925Smrg  # This comment above is used by automake to tell side-effect
5684fb28925Smrg  # dependency tracking mechanisms from slower ones.
5694fb28925Smrg
5704fb28925Smrgdashmstdout)
5714fb28925Smrg  # Important note: in order to support this mode, a compiler *must*
5724fb28925Smrg  # always write the preprocessed file to stdout, regardless of -o.
5734fb28925Smrg  "$@" || exit $?
5744fb28925Smrg
5754fb28925Smrg  # Remove the call to Libtool.
5764fb28925Smrg  if test "$libtool" = yes; then
577b66d1acbSmrg    while test "X$1" != 'X--mode=compile'; do
5784fb28925Smrg      shift
5794fb28925Smrg    done
5804fb28925Smrg    shift
5814fb28925Smrg  fi
5824fb28925Smrg
583df58931aSmrg  # Remove '-o $object'.
5844fb28925Smrg  IFS=" "
5854fb28925Smrg  for arg
5864fb28925Smrg  do
5874fb28925Smrg    case $arg in
5884fb28925Smrg    -o)
5894fb28925Smrg      shift
5904fb28925Smrg      ;;
5914fb28925Smrg    $object)
5924fb28925Smrg      shift
5934fb28925Smrg      ;;
5944fb28925Smrg    *)
5954fb28925Smrg      set fnord "$@" "$arg"
5964fb28925Smrg      shift # fnord
5974fb28925Smrg      shift # $arg
5984fb28925Smrg      ;;
5994fb28925Smrg    esac
6004fb28925Smrg  done
6014fb28925Smrg
6024fb28925Smrg  test -z "$dashmflag" && dashmflag=-M
603df58931aSmrg  # Require at least two characters before searching for ':'
6044fb28925Smrg  # in the target name.  This is to cope with DOS-style filenames:
605df58931aSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6064fb28925Smrg  "$@" $dashmflag |
607df58931aSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6084fb28925Smrg  rm -f "$depfile"
6094fb28925Smrg  cat < "$tmpdepfile" > "$depfile"
610df58931aSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611df58931aSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
612df58931aSmrg  tr ' ' "$nl" < "$tmpdepfile" \
613df58931aSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614df58931aSmrg    | sed -e 's/$/ :/' >> "$depfile"
6154fb28925Smrg  rm -f "$tmpdepfile"
6164fb28925Smrg  ;;
6174fb28925Smrg
6184fb28925SmrgdashXmstdout)
6194fb28925Smrg  # This case only exists to satisfy depend.m4.  It is never actually
6204fb28925Smrg  # run, as this mode is specially recognized in the preamble.
6214fb28925Smrg  exit 1
6224fb28925Smrg  ;;
6234fb28925Smrg
6244fb28925Smrgmakedepend)
6254fb28925Smrg  "$@" || exit $?
6264fb28925Smrg  # Remove any Libtool call
6274fb28925Smrg  if test "$libtool" = yes; then
628b66d1acbSmrg    while test "X$1" != 'X--mode=compile'; do
6294fb28925Smrg      shift
6304fb28925Smrg    done
6314fb28925Smrg    shift
6324fb28925Smrg  fi
6334fb28925Smrg  # X makedepend
6344fb28925Smrg  shift
635b66d1acbSmrg  cleared=no eat=no
636b66d1acbSmrg  for arg
637b66d1acbSmrg  do
6384fb28925Smrg    case $cleared in
6394fb28925Smrg    no)
6404fb28925Smrg      set ""; shift
6414fb28925Smrg      cleared=yes ;;
6424fb28925Smrg    esac
643b66d1acbSmrg    if test $eat = yes; then
644b66d1acbSmrg      eat=no
645b66d1acbSmrg      continue
646b66d1acbSmrg    fi
6474fb28925Smrg    case "$arg" in
6484fb28925Smrg    -D*|-I*)
6494fb28925Smrg      set fnord "$@" "$arg"; shift ;;
6504fb28925Smrg    # Strip any option that makedepend may not understand.  Remove
6514fb28925Smrg    # the object too, otherwise makedepend will parse it as a source file.
652b66d1acbSmrg    -arch)
653b66d1acbSmrg      eat=yes ;;
6544fb28925Smrg    -*|$object)
6554fb28925Smrg      ;;
6564fb28925Smrg    *)
6574fb28925Smrg      set fnord "$@" "$arg"; shift ;;
6584fb28925Smrg    esac
6594fb28925Smrg  done
660b66d1acbSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6614fb28925Smrg  touch "$tmpdepfile"
6624fb28925Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6634fb28925Smrg  rm -f "$depfile"
664df58931aSmrg  # makedepend may prepend the VPATH from the source file name to the object.
665df58931aSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666df58931aSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667df58931aSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668df58931aSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
669df58931aSmrg  sed '1,2d' "$tmpdepfile" \
670df58931aSmrg    | tr ' ' "$nl" \
671df58931aSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672df58931aSmrg    | sed -e 's/$/ :/' >> "$depfile"
6734fb28925Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6744fb28925Smrg  ;;
6754fb28925Smrg
6764fb28925Smrgcpp)
6774fb28925Smrg  # Important note: in order to support this mode, a compiler *must*
6784fb28925Smrg  # always write the preprocessed file to stdout.
6794fb28925Smrg  "$@" || exit $?
6804fb28925Smrg
6814fb28925Smrg  # Remove the call to Libtool.
6824fb28925Smrg  if test "$libtool" = yes; then
683b66d1acbSmrg    while test "X$1" != 'X--mode=compile'; do
6844fb28925Smrg      shift
6854fb28925Smrg    done
6864fb28925Smrg    shift
6874fb28925Smrg  fi
6884fb28925Smrg
689df58931aSmrg  # Remove '-o $object'.
6904fb28925Smrg  IFS=" "
6914fb28925Smrg  for arg
6924fb28925Smrg  do
6934fb28925Smrg    case $arg in
6944fb28925Smrg    -o)
6954fb28925Smrg      shift
6964fb28925Smrg      ;;
6974fb28925Smrg    $object)
6984fb28925Smrg      shift
6994fb28925Smrg      ;;
7004fb28925Smrg    *)
7014fb28925Smrg      set fnord "$@" "$arg"
7024fb28925Smrg      shift # fnord
7034fb28925Smrg      shift # $arg
7044fb28925Smrg      ;;
7054fb28925Smrg    esac
7064fb28925Smrg  done
7074fb28925Smrg
708df58931aSmrg  "$@" -E \
709df58931aSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710df58931aSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711df58931aSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
7124fb28925Smrg  rm -f "$depfile"
7134fb28925Smrg  echo "$object : \\" > "$depfile"
7144fb28925Smrg  cat < "$tmpdepfile" >> "$depfile"
7154fb28925Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7164fb28925Smrg  rm -f "$tmpdepfile"
7174fb28925Smrg  ;;
7184fb28925Smrg
7194fb28925Smrgmsvisualcpp)
7204fb28925Smrg  # Important note: in order to support this mode, a compiler *must*
721b66d1acbSmrg  # always write the preprocessed file to stdout.
7224fb28925Smrg  "$@" || exit $?
723b66d1acbSmrg
724b66d1acbSmrg  # Remove the call to Libtool.
725b66d1acbSmrg  if test "$libtool" = yes; then
726b66d1acbSmrg    while test "X$1" != 'X--mode=compile'; do
727b66d1acbSmrg      shift
728b66d1acbSmrg    done
729b66d1acbSmrg    shift
730b66d1acbSmrg  fi
731b66d1acbSmrg
7324fb28925Smrg  IFS=" "
7334fb28925Smrg  for arg
7344fb28925Smrg  do
7354fb28925Smrg    case "$arg" in
736b66d1acbSmrg    -o)
737b66d1acbSmrg      shift
738b66d1acbSmrg      ;;
739b66d1acbSmrg    $object)
740b66d1acbSmrg      shift
741b66d1acbSmrg      ;;
7424fb28925Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743df58931aSmrg        set fnord "$@"
744df58931aSmrg        shift
745df58931aSmrg        shift
746df58931aSmrg        ;;
7474fb28925Smrg    *)
748df58931aSmrg        set fnord "$@" "$arg"
749df58931aSmrg        shift
750df58931aSmrg        shift
751df58931aSmrg        ;;
7524fb28925Smrg    esac
7534fb28925Smrg  done
754b66d1acbSmrg  "$@" -E 2>/dev/null |
755b66d1acbSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7564fb28925Smrg  rm -f "$depfile"
7574fb28925Smrg  echo "$object : \\" > "$depfile"
758df58931aSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759df58931aSmrg  echo "$tab" >> "$depfile"
760b66d1acbSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7614fb28925Smrg  rm -f "$tmpdepfile"
7624fb28925Smrg  ;;
7634fb28925Smrg
764b66d1acbSmrgmsvcmsys)
765b66d1acbSmrg  # This case exists only to let depend.m4 do its work.  It works by
766b66d1acbSmrg  # looking at the text of this script.  This case will never be run,
767b66d1acbSmrg  # since it is checked for above.
768b66d1acbSmrg  exit 1
769b66d1acbSmrg  ;;
770b66d1acbSmrg
7714fb28925Smrgnone)
7724fb28925Smrg  exec "$@"
7734fb28925Smrg  ;;
7744fb28925Smrg
7754fb28925Smrg*)
7764fb28925Smrg  echo "Unknown depmode $depmode" 1>&2
7774fb28925Smrg  exit 1
7784fb28925Smrg  ;;
7794fb28925Smrgesac
7804fb28925Smrg
7814fb28925Smrgexit 0
782b66d1acbSmrg
783b66d1acbSmrg# Local Variables:
784b66d1acbSmrg# mode: shell-script
785b66d1acbSmrg# sh-indentation: 2
7861c145c9fSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
787b66d1acbSmrg# time-stamp-start: "scriptversion="
788b66d1acbSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7891c145c9fSmrg# time-stamp-time-zone: "UTC0"
790b66d1acbSmrg# time-stamp-end: "; # UTC"
791b66d1acbSmrg# End:
792