127702724Smrg#! /bin/sh
227702724Smrg# depcomp - compile a program generating dependencies as side-effects
327702724Smrg
4ae545d91Smrgscriptversion=2024-06-19.01; # UTC
527702724Smrg
6ae545d91Smrg# Copyright (C) 1999-2024 Free Software Foundation, Inc.
727702724Smrg
827702724Smrg# This program is free software; you can redistribute it and/or modify
927702724Smrg# it under the terms of the GNU General Public License as published by
1027702724Smrg# the Free Software Foundation; either version 2, or (at your option)
1127702724Smrg# any later version.
1227702724Smrg
1327702724Smrg# This program is distributed in the hope that it will be useful,
1427702724Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1527702724Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1627702724Smrg# GNU General Public License for more details.
1727702724Smrg
1827702724Smrg# You should have received a copy of the GNU General Public License
1995b7a5c8Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2027702724Smrg
2127702724Smrg# As a special exception to the GNU General Public License, if you
2227702724Smrg# distribute this file as part of a program that contains a
2327702724Smrg# configuration script generated by Autoconf, you may include it under
2427702724Smrg# the same distribution terms that you use for the rest of that program.
2527702724Smrg
2627702724Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2727702724Smrg
2827702724Smrgcase $1 in
2927702724Smrg  '')
30313a12fdSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31313a12fdSmrg    exit 1;
32313a12fdSmrg    ;;
3327702724Smrg  -h | --h*)
3427702724Smrg    cat <<\EOF
3527702724SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3627702724Smrg
3727702724SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
3827702724Smrgas side-effects.
3927702724Smrg
4027702724SmrgEnvironment variables:
4127702724Smrg  depmode     Dependency tracking mode.
42313a12fdSmrg  source      Source file read by 'PROGRAMS ARGS'.
43313a12fdSmrg  object      Object file output by 'PROGRAMS ARGS'.
4427702724Smrg  DEPDIR      directory where to store dependencies.
4527702724Smrg  depfile     Dependency file to output.
46313a12fdSmrg  tmpdepfile  Temporary file to use when outputting dependencies.
4727702724Smrg  libtool     Whether libtool is used (yes/no).
4827702724Smrg
4927702724SmrgReport bugs to <bug-automake@gnu.org>.
50ae545d91SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
51ae545d91SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>.
5227702724SmrgEOF
5327702724Smrg    exit $?
5427702724Smrg    ;;
5527702724Smrg  -v | --v*)
56ae545d91Smrg    echo "depcomp (GNU Automake) $scriptversion"
5727702724Smrg    exit $?
5827702724Smrg    ;;
5927702724Smrgesac
6027702724Smrg
61313a12fdSmrg# Get the directory component of the given path, and save it in the
62313a12fdSmrg# global variables '$dir'.  Note that this directory component will
63313a12fdSmrg# be either empty or ending with a '/' character.  This is deliberate.
64313a12fdSmrgset_dir_from ()
65313a12fdSmrg{
66313a12fdSmrg  case $1 in
67313a12fdSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
68313a12fdSmrg      *) dir=;;
69313a12fdSmrg  esac
70313a12fdSmrg}
71313a12fdSmrg
72313a12fdSmrg# Get the suffix-stripped basename of the given path, and save it the
73313a12fdSmrg# global variable '$base'.
74313a12fdSmrgset_base_from ()
75313a12fdSmrg{
76313a12fdSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
77313a12fdSmrg}
78313a12fdSmrg
79313a12fdSmrg# If no dependency file was actually created by the compiler invocation,
80313a12fdSmrg# we still have to create a dummy depfile, to avoid errors with the
81313a12fdSmrg# Makefile "include basename.Plo" scheme.
82313a12fdSmrgmake_dummy_depfile ()
83313a12fdSmrg{
84313a12fdSmrg  echo "#dummy" > "$depfile"
85313a12fdSmrg}
86313a12fdSmrg
87313a12fdSmrg# Factor out some common post-processing of the generated depfile.
88313a12fdSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
89313a12fdSmrgaix_post_process_depfile ()
90313a12fdSmrg{
91313a12fdSmrg  # If the compiler actually managed to produce a dependency file,
92313a12fdSmrg  # post-process it.
93313a12fdSmrg  if test -f "$tmpdepfile"; then
94313a12fdSmrg    # Each line is of the form 'foo.o: dependency.h'.
95313a12fdSmrg    # Do two passes, one to just change these to
96313a12fdSmrg    #   $object: dependency.h
97313a12fdSmrg    # and one to simply output
98313a12fdSmrg    #   dependency.h:
99313a12fdSmrg    # which is needed to avoid the deleted-header problem.
100313a12fdSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
101313a12fdSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
102313a12fdSmrg    } > "$depfile"
103313a12fdSmrg    rm -f "$tmpdepfile"
104313a12fdSmrg  else
105313a12fdSmrg    make_dummy_depfile
106313a12fdSmrg  fi
107313a12fdSmrg}
108313a12fdSmrg
109313a12fdSmrg# A tabulation character.
110313a12fdSmrgtab='	'
111313a12fdSmrg# A newline character.
112313a12fdSmrgnl='
113313a12fdSmrg'
114313a12fdSmrg# Character ranges might be problematic outside the C locale.
115313a12fdSmrg# These definitions help.
116313a12fdSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
117313a12fdSmrglower=abcdefghijklmnopqrstuvwxyz
118313a12fdSmrgalpha=${upper}${lower}
119313a12fdSmrg
12027702724Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12127702724Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12227702724Smrg  exit 1
12327702724Smrgfi
12427702724Smrg
12527702724Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12627702724Smrgdepfile=${depfile-`echo "$object" |
12727702724Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12827702724Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12927702724Smrg
13027702724Smrgrm -f "$tmpdepfile"
13127702724Smrg
132ae545d91Smrg# Avoid interference from the environment.
133313a12fdSmrggccflag= dashmflag=
134313a12fdSmrg
13527702724Smrg# Some modes work just like other modes, but use different flags.  We
13627702724Smrg# parameterize here, but still list the modes in the big case below,
13727702724Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
13827702724Smrg# here, because this file can only contain one case statement.
13927702724Smrgif test "$depmode" = hp; then
14027702724Smrg  # HP compiler uses -M and no extra arg.
14127702724Smrg  gccflag=-M
14227702724Smrg  depmode=gcc
14327702724Smrgfi
14427702724Smrg
14527702724Smrgif test "$depmode" = dashXmstdout; then
146313a12fdSmrg  # This is just like dashmstdout with a different argument.
147313a12fdSmrg  dashmflag=-xM
148313a12fdSmrg  depmode=dashmstdout
14927702724Smrgfi
15027702724Smrg
15100084f2cSmrgcygpath_u="cygpath -u -f -"
15200084f2cSmrgif test "$depmode" = msvcmsys; then
153313a12fdSmrg  # This is just like msvisualcpp but w/o cygpath translation.
154313a12fdSmrg  # Just convert the backslash-escaped backslashes to single forward
155313a12fdSmrg  # slashes to satisfy depend.m4
156313a12fdSmrg  cygpath_u='sed s,\\\\,/,g'
157313a12fdSmrg  depmode=msvisualcpp
158313a12fdSmrgfi
159313a12fdSmrg
160313a12fdSmrgif test "$depmode" = msvc7msys; then
161313a12fdSmrg  # This is just like msvc7 but w/o cygpath translation.
162313a12fdSmrg  # Just convert the backslash-escaped backslashes to single forward
163313a12fdSmrg  # slashes to satisfy depend.m4
164313a12fdSmrg  cygpath_u='sed s,\\\\,/,g'
165313a12fdSmrg  depmode=msvc7
166313a12fdSmrgfi
167313a12fdSmrg
168313a12fdSmrgif test "$depmode" = xlc; then
169313a12fdSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
170313a12fdSmrg  gccflag=-qmakedep=gcc,-MF
171313a12fdSmrg  depmode=gcc
17200084f2cSmrgfi
17300084f2cSmrg
17427702724Smrgcase "$depmode" in
17527702724Smrggcc3)
17627702724Smrg## gcc 3 implements dependency tracking that does exactly what
17727702724Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17827702724Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
179e19dfac4Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
180e19dfac4Smrg## the command line argument order; so add the flags where they
181e19dfac4Smrg## appear in depend2.am.  Note that the slowdown incurred here
182e19dfac4Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
183e19dfac4Smrg  for arg
184e19dfac4Smrg  do
185e19dfac4Smrg    case $arg in
186e19dfac4Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
187e19dfac4Smrg    *)  set fnord "$@" "$arg" ;;
188e19dfac4Smrg    esac
189e19dfac4Smrg    shift # fnord
190e19dfac4Smrg    shift # $arg
191e19dfac4Smrg  done
192e19dfac4Smrg  "$@"
19327702724Smrg  stat=$?
194313a12fdSmrg  if test $stat -ne 0; then
19527702724Smrg    rm -f "$tmpdepfile"
19627702724Smrg    exit $stat
19727702724Smrg  fi
19827702724Smrg  mv "$tmpdepfile" "$depfile"
19927702724Smrg  ;;
20027702724Smrg
20127702724Smrggcc)
202ae545d91Smrg## Note that this doesn't just cater to obsolete pre-3.x GCC compilers.
203ae545d91Smrg## but also to in-use compilers like IBM xlc/xlC and the HP C compiler.
204313a12fdSmrg## (see the conditional assignment to $gccflag above).
20527702724Smrg## There are various ways to get dependency output from gcc.  Here's
20627702724Smrg## why we pick this rather obscure method:
20727702724Smrg## - Don't want to use -MD because we'd like the dependencies to end
20827702724Smrg##   up in a subdir.  Having to rename by hand is ugly.
20927702724Smrg##   (We might end up doing this anyway to support other compilers.)
21027702724Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
211313a12fdSmrg##   -MM, not -M (despite what the docs say).  Also, it might not be
212313a12fdSmrg##   supported by the other compilers which use the 'gcc' depmode.
21327702724Smrg## - Using -M directly means running the compiler twice (even worse
21427702724Smrg##   than renaming).
21527702724Smrg  if test -z "$gccflag"; then
21627702724Smrg    gccflag=-MD,
21727702724Smrg  fi
21827702724Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
21927702724Smrg  stat=$?
220313a12fdSmrg  if test $stat -ne 0; then
22127702724Smrg    rm -f "$tmpdepfile"
22227702724Smrg    exit $stat
22327702724Smrg  fi
22427702724Smrg  rm -f "$depfile"
22527702724Smrg  echo "$object : \\" > "$depfile"
226313a12fdSmrg  # The second -e expression handles DOS-style file names with drive
227313a12fdSmrg  # letters.
22827702724Smrg  sed -e 's/^[^:]*: / /' \
22927702724Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
230313a12fdSmrg## This next piece of magic avoids the "deleted header file" problem.
23127702724Smrg## The problem is that when a header file which appears in a .P file
23227702724Smrg## is deleted, the dependency causes make to die (because there is
23327702724Smrg## typically no way to rebuild the header).  We avoid this by adding
23427702724Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
23527702724Smrg## this for us directly.
236313a12fdSmrg## Some versions of gcc put a space before the ':'.  On the theory
23727702724Smrg## that the space means something, we add a space to the output as
238313a12fdSmrg## well.  hp depmode also adds that space, but also prefixes the VPATH
239313a12fdSmrg## to the object.  Take care to not repeat it in the output.
24027702724Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
24127702724Smrg## correctly.  Breaking it into two sed invocations is a workaround.
242313a12fdSmrg  tr ' ' "$nl" < "$tmpdepfile" \
243313a12fdSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
244313a12fdSmrg    | sed -e 's/$/ :/' >> "$depfile"
24527702724Smrg  rm -f "$tmpdepfile"
24627702724Smrg  ;;
24727702724Smrg
24827702724Smrghp)
24927702724Smrg  # This case exists only to let depend.m4 do its work.  It works by
25027702724Smrg  # looking at the text of this script.  This case will never be run,
25127702724Smrg  # since it is checked for above.
25227702724Smrg  exit 1
25327702724Smrg  ;;
25427702724Smrg
25527702724Smrgsgi)
25627702724Smrg  if test "$libtool" = yes; then
25727702724Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
25827702724Smrg  else
25927702724Smrg    "$@" -MDupdate "$tmpdepfile"
26027702724Smrg  fi
26127702724Smrg  stat=$?
262313a12fdSmrg  if test $stat -ne 0; then
26327702724Smrg    rm -f "$tmpdepfile"
26427702724Smrg    exit $stat
26527702724Smrg  fi
26627702724Smrg  rm -f "$depfile"
26727702724Smrg
26827702724Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26927702724Smrg    echo "$object : \\" > "$depfile"
27027702724Smrg    # Clip off the initial element (the dependent).  Don't try to be
27127702724Smrg    # clever and replace this with sed code, as IRIX sed won't handle
27227702724Smrg    # lines with more than a fixed number of characters (4096 in
27327702724Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
274313a12fdSmrg    # the IRIX cc adds comments like '#:fec' to the end of the
27527702724Smrg    # dependency line.
276313a12fdSmrg    tr ' ' "$nl" < "$tmpdepfile" \
277313a12fdSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
278313a12fdSmrg      | tr "$nl" ' ' >> "$depfile"
27900084f2cSmrg    echo >> "$depfile"
28027702724Smrg    # The second pass generates a dummy entry for each header file.
281313a12fdSmrg    tr ' ' "$nl" < "$tmpdepfile" \
282313a12fdSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
283313a12fdSmrg      >> "$depfile"
28427702724Smrg  else
285313a12fdSmrg    make_dummy_depfile
28627702724Smrg  fi
28727702724Smrg  rm -f "$tmpdepfile"
28827702724Smrg  ;;
28927702724Smrg
290313a12fdSmrgxlc)
291313a12fdSmrg  # This case exists only to let depend.m4 do its work.  It works by
292313a12fdSmrg  # looking at the text of this script.  This case will never be run,
293313a12fdSmrg  # since it is checked for above.
294313a12fdSmrg  exit 1
295313a12fdSmrg  ;;
296313a12fdSmrg
29727702724Smrgaix)
29827702724Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
29927702724Smrg  # in a .u file.  In older versions, this file always lives in the
300313a12fdSmrg  # current directory.  Also, the AIX compiler puts '$object:' at the
30127702724Smrg  # start of each line; $object doesn't have directory information.
30227702724Smrg  # Version 6 uses the directory in both cases.
303313a12fdSmrg  set_dir_from "$object"
304313a12fdSmrg  set_base_from "$object"
30527702724Smrg  if test "$libtool" = yes; then
306e19dfac4Smrg    tmpdepfile1=$dir$base.u
307e19dfac4Smrg    tmpdepfile2=$base.u
308e19dfac4Smrg    tmpdepfile3=$dir.libs/$base.u
30927702724Smrg    "$@" -Wc,-M
31027702724Smrg  else
311e19dfac4Smrg    tmpdepfile1=$dir$base.u
312e19dfac4Smrg    tmpdepfile2=$dir$base.u
313e19dfac4Smrg    tmpdepfile3=$dir$base.u
31427702724Smrg    "$@" -M
31527702724Smrg  fi
31627702724Smrg  stat=$?
317313a12fdSmrg  if test $stat -ne 0; then
318e19dfac4Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31927702724Smrg    exit $stat
32027702724Smrg  fi
32127702724Smrg
322e19dfac4Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
323e19dfac4Smrg  do
324e19dfac4Smrg    test -f "$tmpdepfile" && break
325e19dfac4Smrg  done
326313a12fdSmrg  aix_post_process_depfile
327313a12fdSmrg  ;;
328313a12fdSmrg
329313a12fdSmrgtcc)
330313a12fdSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
331313a12fdSmrg  # FIXME: That version still under development at the moment of writing.
332313a12fdSmrg  #        Make that this statement remains true also for stable, released
333313a12fdSmrg  #        versions.
334313a12fdSmrg  # It will wrap lines (doesn't matter whether long or short) with a
335313a12fdSmrg  # trailing '\', as in:
336313a12fdSmrg  #
337313a12fdSmrg  #   foo.o : \
338313a12fdSmrg  #    foo.c \
339313a12fdSmrg  #    foo.h \
340313a12fdSmrg  #
341313a12fdSmrg  # It will put a trailing '\' even on the last line, and will use leading
342313a12fdSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
343313a12fdSmrg  # "Emit spaces for -MD").
344313a12fdSmrg  "$@" -MD -MF "$tmpdepfile"
345313a12fdSmrg  stat=$?
346313a12fdSmrg  if test $stat -ne 0; then
347313a12fdSmrg    rm -f "$tmpdepfile"
348313a12fdSmrg    exit $stat
34927702724Smrg  fi
350313a12fdSmrg  rm -f "$depfile"
351313a12fdSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
352313a12fdSmrg  # We have to change lines of the first kind to '$object: \'.
353313a12fdSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
354313a12fdSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
355313a12fdSmrg  # dummy dependency, to avoid the deleted-header problem.
356313a12fdSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35727702724Smrg  rm -f "$tmpdepfile"
35827702724Smrg  ;;
35927702724Smrg
360313a12fdSmrg## The order of this option in the case statement is important, since the
361313a12fdSmrg## shell code in configure will try each of these formats in the order
362313a12fdSmrg## listed in this file.  A plain '-MD' option would be understood by many
363313a12fdSmrg## compilers, so we must ensure this comes after the gcc and icc options.
364313a12fdSmrgpgcc)
365313a12fdSmrg  # Portland's C compiler understands '-MD'.
366313a12fdSmrg  # Will always output deps to 'file.d' where file is the root name of the
367313a12fdSmrg  # source file under compilation, even if file resides in a subdirectory.
368313a12fdSmrg  # The object file name does not affect the name of the '.d' file.
369313a12fdSmrg  # pgcc 10.2 will output
37027702724Smrg  #    foo.o: sub/foo.c sub/foo.h
371313a12fdSmrg  # and will wrap long lines using '\' :
37227702724Smrg  #    foo.o: sub/foo.c ... \
37327702724Smrg  #     sub/foo.h ... \
37427702724Smrg  #     ...
375313a12fdSmrg  set_dir_from "$object"
376313a12fdSmrg  # Use the source, not the object, to determine the base name, since
377313a12fdSmrg  # that's sadly what pgcc will do too.
378313a12fdSmrg  set_base_from "$source"
379313a12fdSmrg  tmpdepfile=$base.d
380313a12fdSmrg
381313a12fdSmrg  # For projects that build the same source file twice into different object
382313a12fdSmrg  # files, the pgcc approach of using the *source* file root name can cause
383313a12fdSmrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
384313a12fdSmrg  # the same $tmpdepfile.
385313a12fdSmrg  lockdir=$base.d-lock
386313a12fdSmrg  trap "
387313a12fdSmrg    echo '$0: caught signal, cleaning up...' >&2
388313a12fdSmrg    rmdir '$lockdir'
389313a12fdSmrg    exit 1
390313a12fdSmrg  " 1 2 13 15
391313a12fdSmrg  numtries=100
392313a12fdSmrg  i=$numtries
393313a12fdSmrg  while test $i -gt 0; do
394313a12fdSmrg    # mkdir is a portable test-and-set.
395313a12fdSmrg    if mkdir "$lockdir" 2>/dev/null; then
396313a12fdSmrg      # This process acquired the lock.
397313a12fdSmrg      "$@" -MD
398313a12fdSmrg      stat=$?
399313a12fdSmrg      # Release the lock.
400313a12fdSmrg      rmdir "$lockdir"
401313a12fdSmrg      break
402313a12fdSmrg    else
403313a12fdSmrg      # If the lock is being held by a different process, wait
404313a12fdSmrg      # until the winning process is done or we timeout.
405313a12fdSmrg      while test -d "$lockdir" && test $i -gt 0; do
406313a12fdSmrg        sleep 1
407313a12fdSmrg        i=`expr $i - 1`
408313a12fdSmrg      done
409313a12fdSmrg    fi
410313a12fdSmrg    i=`expr $i - 1`
411313a12fdSmrg  done
412313a12fdSmrg  trap - 1 2 13 15
413313a12fdSmrg  if test $i -le 0; then
414313a12fdSmrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
415313a12fdSmrg    echo "$0: check lockdir '$lockdir'" >&2
416313a12fdSmrg    exit 1
417313a12fdSmrg  fi
41827702724Smrg
419313a12fdSmrg  if test $stat -ne 0; then
42027702724Smrg    rm -f "$tmpdepfile"
42127702724Smrg    exit $stat
42227702724Smrg  fi
42327702724Smrg  rm -f "$depfile"
42427702724Smrg  # Each line is of the form `foo.o: dependent.h',
42527702724Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42627702724Smrg  # Do two passes, one to just change these to
42727702724Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
42827702724Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42927702724Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
43027702724Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
431313a12fdSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
432313a12fdSmrg    | sed -e 's/$/ :/' >> "$depfile"
43327702724Smrg  rm -f "$tmpdepfile"
43427702724Smrg  ;;
43527702724Smrg
436e19dfac4Smrghp2)
437e19dfac4Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
438e19dfac4Smrg  # compilers, which have integrated preprocessors.  The correct option
439e19dfac4Smrg  # to use with these is +Maked; it writes dependencies to a file named
440e19dfac4Smrg  # 'foo.d', which lands next to the object file, wherever that
441e19dfac4Smrg  # happens to be.
442e19dfac4Smrg  # Much of this is similar to the tru64 case; see comments there.
443313a12fdSmrg  set_dir_from  "$object"
444313a12fdSmrg  set_base_from "$object"
445e19dfac4Smrg  if test "$libtool" = yes; then
446e19dfac4Smrg    tmpdepfile1=$dir$base.d
447e19dfac4Smrg    tmpdepfile2=$dir.libs/$base.d
448e19dfac4Smrg    "$@" -Wc,+Maked
449e19dfac4Smrg  else
450e19dfac4Smrg    tmpdepfile1=$dir$base.d
451e19dfac4Smrg    tmpdepfile2=$dir$base.d
452e19dfac4Smrg    "$@" +Maked
453e19dfac4Smrg  fi
454e19dfac4Smrg  stat=$?
455313a12fdSmrg  if test $stat -ne 0; then
456e19dfac4Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
457e19dfac4Smrg     exit $stat
458e19dfac4Smrg  fi
459e19dfac4Smrg
460e19dfac4Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
461e19dfac4Smrg  do
462e19dfac4Smrg    test -f "$tmpdepfile" && break
463e19dfac4Smrg  done
464e19dfac4Smrg  if test -f "$tmpdepfile"; then
465313a12fdSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
466313a12fdSmrg    # Add 'dependent.h:' lines.
46700084f2cSmrg    sed -ne '2,${
468313a12fdSmrg               s/^ *//
469313a12fdSmrg               s/ \\*$//
470313a12fdSmrg               s/$/:/
471313a12fdSmrg               p
472313a12fdSmrg             }' "$tmpdepfile" >> "$depfile"
473e19dfac4Smrg  else
474313a12fdSmrg    make_dummy_depfile
475e19dfac4Smrg  fi
476e19dfac4Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
477e19dfac4Smrg  ;;
478e19dfac4Smrg
47927702724Smrgtru64)
480313a12fdSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
481313a12fdSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
482313a12fdSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
483313a12fdSmrg  # dependencies in 'foo.d' instead, so we check for that too.
484313a12fdSmrg  # Subdirectories are respected.
485313a12fdSmrg  set_dir_from  "$object"
486313a12fdSmrg  set_base_from "$object"
487313a12fdSmrg
488313a12fdSmrg  if test "$libtool" = yes; then
489313a12fdSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
490313a12fdSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
491313a12fdSmrg    # in $dir$base.o.d.  We have to check for both files, because
492313a12fdSmrg    # one of the two compilations can be disabled.  We should prefer
493313a12fdSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
494313a12fdSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
495313a12fdSmrg    # the former would cause a distcleancheck panic.
496313a12fdSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
497313a12fdSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
498313a12fdSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
499313a12fdSmrg    "$@" -Wc,-MD
500313a12fdSmrg  else
501313a12fdSmrg    tmpdepfile1=$dir$base.d
502313a12fdSmrg    tmpdepfile2=$dir$base.d
503313a12fdSmrg    tmpdepfile3=$dir$base.d
504313a12fdSmrg    "$@" -MD
505313a12fdSmrg  fi
506313a12fdSmrg
507313a12fdSmrg  stat=$?
508313a12fdSmrg  if test $stat -ne 0; then
509313a12fdSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
510313a12fdSmrg    exit $stat
511313a12fdSmrg  fi
512313a12fdSmrg
513313a12fdSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
514313a12fdSmrg  do
515313a12fdSmrg    test -f "$tmpdepfile" && break
516313a12fdSmrg  done
517313a12fdSmrg  # Same post-processing that is required for AIX mode.
518313a12fdSmrg  aix_post_process_depfile
519313a12fdSmrg  ;;
520313a12fdSmrg
521313a12fdSmrgmsvc7)
522313a12fdSmrg  if test "$libtool" = yes; then
523313a12fdSmrg    showIncludes=-Wc,-showIncludes
524313a12fdSmrg  else
525313a12fdSmrg    showIncludes=-showIncludes
526313a12fdSmrg  fi
527313a12fdSmrg  "$@" $showIncludes > "$tmpdepfile"
528313a12fdSmrg  stat=$?
529313a12fdSmrg  grep -v '^Note: including file: ' "$tmpdepfile"
530313a12fdSmrg  if test $stat -ne 0; then
531313a12fdSmrg    rm -f "$tmpdepfile"
532313a12fdSmrg    exit $stat
533313a12fdSmrg  fi
534313a12fdSmrg  rm -f "$depfile"
535313a12fdSmrg  echo "$object : \\" > "$depfile"
536313a12fdSmrg  # The first sed program below extracts the file names and escapes
537313a12fdSmrg  # backslashes for cygpath.  The second sed program outputs the file
538313a12fdSmrg  # name when reading, but also accumulates all include files in the
539313a12fdSmrg  # hold buffer in order to output them again at the end.  This only
540313a12fdSmrg  # works with sed implementations that can handle large buffers.
541313a12fdSmrg  sed < "$tmpdepfile" -n '
542313a12fdSmrg/^Note: including file:  *\(.*\)/ {
543313a12fdSmrg  s//\1/
544313a12fdSmrg  s/\\/\\\\/g
545313a12fdSmrg  p
546313a12fdSmrg}' | $cygpath_u | sort -u | sed -n '
547313a12fdSmrgs/ /\\ /g
548313a12fdSmrgs/\(.*\)/'"$tab"'\1 \\/p
549313a12fdSmrgs/.\(.*\) \\/\1:/
550313a12fdSmrgH
551313a12fdSmrg$ {
552313a12fdSmrg  s/.*/'"$tab"'/
553313a12fdSmrg  G
554313a12fdSmrg  p
555313a12fdSmrg}' >> "$depfile"
5567cea3689Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
557313a12fdSmrg  rm -f "$tmpdepfile"
558313a12fdSmrg  ;;
559313a12fdSmrg
560313a12fdSmrgmsvc7msys)
561313a12fdSmrg  # This case exists only to let depend.m4 do its work.  It works by
562313a12fdSmrg  # looking at the text of this script.  This case will never be run,
563313a12fdSmrg  # since it is checked for above.
564313a12fdSmrg  exit 1
565313a12fdSmrg  ;;
56627702724Smrg
56727702724Smrg#nosideeffect)
56827702724Smrg  # This comment above is used by automake to tell side-effect
56927702724Smrg  # dependency tracking mechanisms from slower ones.
57027702724Smrg
57127702724Smrgdashmstdout)
57227702724Smrg  # Important note: in order to support this mode, a compiler *must*
57327702724Smrg  # always write the preprocessed file to stdout, regardless of -o.
57427702724Smrg  "$@" || exit $?
57527702724Smrg
57627702724Smrg  # Remove the call to Libtool.
57727702724Smrg  if test "$libtool" = yes; then
57800084f2cSmrg    while test "X$1" != 'X--mode=compile'; do
57927702724Smrg      shift
58027702724Smrg    done
58127702724Smrg    shift
58227702724Smrg  fi
58327702724Smrg
584313a12fdSmrg  # Remove '-o $object'.
58527702724Smrg  IFS=" "
58627702724Smrg  for arg
58727702724Smrg  do
58827702724Smrg    case $arg in
58927702724Smrg    -o)
59027702724Smrg      shift
59127702724Smrg      ;;
59227702724Smrg    $object)
59327702724Smrg      shift
59427702724Smrg      ;;
59527702724Smrg    *)
59627702724Smrg      set fnord "$@" "$arg"
59727702724Smrg      shift # fnord
59827702724Smrg      shift # $arg
59927702724Smrg      ;;
60027702724Smrg    esac
60127702724Smrg  done
60227702724Smrg
60327702724Smrg  test -z "$dashmflag" && dashmflag=-M
604313a12fdSmrg  # Require at least two characters before searching for ':'
60527702724Smrg  # in the target name.  This is to cope with DOS-style filenames:
606313a12fdSmrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60727702724Smrg  "$@" $dashmflag |
608313a12fdSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60927702724Smrg  rm -f "$depfile"
61027702724Smrg  cat < "$tmpdepfile" > "$depfile"
611313a12fdSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
612313a12fdSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
613313a12fdSmrg  tr ' ' "$nl" < "$tmpdepfile" \
614313a12fdSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
615313a12fdSmrg    | sed -e 's/$/ :/' >> "$depfile"
61627702724Smrg  rm -f "$tmpdepfile"
61727702724Smrg  ;;
61827702724Smrg
61927702724SmrgdashXmstdout)
62027702724Smrg  # This case only exists to satisfy depend.m4.  It is never actually
62127702724Smrg  # run, as this mode is specially recognized in the preamble.
62227702724Smrg  exit 1
62327702724Smrg  ;;
62427702724Smrg
62527702724Smrgmakedepend)
62627702724Smrg  "$@" || exit $?
62727702724Smrg  # Remove any Libtool call
62827702724Smrg  if test "$libtool" = yes; then
62900084f2cSmrg    while test "X$1" != 'X--mode=compile'; do
63027702724Smrg      shift
63127702724Smrg    done
63227702724Smrg    shift
63327702724Smrg  fi
63427702724Smrg  # X makedepend
63527702724Smrg  shift
63600084f2cSmrg  cleared=no eat=no
63700084f2cSmrg  for arg
63800084f2cSmrg  do
63927702724Smrg    case $cleared in
64027702724Smrg    no)
64127702724Smrg      set ""; shift
64227702724Smrg      cleared=yes ;;
64327702724Smrg    esac
64400084f2cSmrg    if test $eat = yes; then
64500084f2cSmrg      eat=no
64600084f2cSmrg      continue
64700084f2cSmrg    fi
64827702724Smrg    case "$arg" in
64927702724Smrg    -D*|-I*)
65027702724Smrg      set fnord "$@" "$arg"; shift ;;
65127702724Smrg    # Strip any option that makedepend may not understand.  Remove
65227702724Smrg    # the object too, otherwise makedepend will parse it as a source file.
65300084f2cSmrg    -arch)
65400084f2cSmrg      eat=yes ;;
65527702724Smrg    -*|$object)
65627702724Smrg      ;;
65727702724Smrg    *)
65827702724Smrg      set fnord "$@" "$arg"; shift ;;
65927702724Smrg    esac
66027702724Smrg  done
66100084f2cSmrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66227702724Smrg  touch "$tmpdepfile"
66327702724Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66427702724Smrg  rm -f "$depfile"
665313a12fdSmrg  # makedepend may prepend the VPATH from the source file name to the object.
666313a12fdSmrg  # No need to regex-escape $object, excess matching of '.' is harmless.
667313a12fdSmrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
668313a12fdSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
669313a12fdSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
670313a12fdSmrg  sed '1,2d' "$tmpdepfile" \
671313a12fdSmrg    | tr ' ' "$nl" \
672313a12fdSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
673313a12fdSmrg    | sed -e 's/$/ :/' >> "$depfile"
67427702724Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
67527702724Smrg  ;;
67627702724Smrg
67727702724Smrgcpp)
67827702724Smrg  # Important note: in order to support this mode, a compiler *must*
67927702724Smrg  # always write the preprocessed file to stdout.
68027702724Smrg  "$@" || exit $?
68127702724Smrg
68227702724Smrg  # Remove the call to Libtool.
68327702724Smrg  if test "$libtool" = yes; then
68400084f2cSmrg    while test "X$1" != 'X--mode=compile'; do
68527702724Smrg      shift
68627702724Smrg    done
68727702724Smrg    shift
68827702724Smrg  fi
68927702724Smrg
690313a12fdSmrg  # Remove '-o $object'.
69127702724Smrg  IFS=" "
69227702724Smrg  for arg
69327702724Smrg  do
69427702724Smrg    case $arg in
69527702724Smrg    -o)
69627702724Smrg      shift
69727702724Smrg      ;;
69827702724Smrg    $object)
69927702724Smrg      shift
70027702724Smrg      ;;
70127702724Smrg    *)
70227702724Smrg      set fnord "$@" "$arg"
70327702724Smrg      shift # fnord
70427702724Smrg      shift # $arg
70527702724Smrg      ;;
70627702724Smrg    esac
70727702724Smrg  done
70827702724Smrg
709313a12fdSmrg  "$@" -E \
710313a12fdSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711313a12fdSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
712313a12fdSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
71327702724Smrg  rm -f "$depfile"
71427702724Smrg  echo "$object : \\" > "$depfile"
71527702724Smrg  cat < "$tmpdepfile" >> "$depfile"
71627702724Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71727702724Smrg  rm -f "$tmpdepfile"
71827702724Smrg  ;;
71927702724Smrg
72027702724Smrgmsvisualcpp)
72127702724Smrg  # Important note: in order to support this mode, a compiler *must*
72200084f2cSmrg  # always write the preprocessed file to stdout.
72327702724Smrg  "$@" || exit $?
72400084f2cSmrg
72500084f2cSmrg  # Remove the call to Libtool.
72600084f2cSmrg  if test "$libtool" = yes; then
72700084f2cSmrg    while test "X$1" != 'X--mode=compile'; do
72800084f2cSmrg      shift
72900084f2cSmrg    done
73000084f2cSmrg    shift
73100084f2cSmrg  fi
73200084f2cSmrg
73327702724Smrg  IFS=" "
73427702724Smrg  for arg
73527702724Smrg  do
73627702724Smrg    case "$arg" in
73700084f2cSmrg    -o)
73800084f2cSmrg      shift
73900084f2cSmrg      ;;
74000084f2cSmrg    $object)
74100084f2cSmrg      shift
74200084f2cSmrg      ;;
74327702724Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
744313a12fdSmrg        set fnord "$@"
745313a12fdSmrg        shift
746313a12fdSmrg        shift
747313a12fdSmrg        ;;
74827702724Smrg    *)
749313a12fdSmrg        set fnord "$@" "$arg"
750313a12fdSmrg        shift
751313a12fdSmrg        shift
752313a12fdSmrg        ;;
75327702724Smrg    esac
75427702724Smrg  done
75500084f2cSmrg  "$@" -E 2>/dev/null |
75600084f2cSmrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75727702724Smrg  rm -f "$depfile"
75827702724Smrg  echo "$object : \\" > "$depfile"
759313a12fdSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
760313a12fdSmrg  echo "$tab" >> "$depfile"
76100084f2cSmrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76227702724Smrg  rm -f "$tmpdepfile"
76327702724Smrg  ;;
76427702724Smrg
76500084f2cSmrgmsvcmsys)
76600084f2cSmrg  # This case exists only to let depend.m4 do its work.  It works by
76700084f2cSmrg  # looking at the text of this script.  This case will never be run,
76800084f2cSmrg  # since it is checked for above.
76900084f2cSmrg  exit 1
77000084f2cSmrg  ;;
77100084f2cSmrg
77227702724Smrgnone)
77327702724Smrg  exec "$@"
77427702724Smrg  ;;
77527702724Smrg
77627702724Smrg*)
77727702724Smrg  echo "Unknown depmode $depmode" 1>&2
77827702724Smrg  exit 1
77927702724Smrg  ;;
78027702724Smrgesac
78127702724Smrg
78227702724Smrgexit 0
78327702724Smrg
78427702724Smrg# Local Variables:
78527702724Smrg# mode: shell-script
78627702724Smrg# sh-indentation: 2
78795b7a5c8Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
78827702724Smrg# time-stamp-start: "scriptversion="
78927702724Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
79095b7a5c8Smrg# time-stamp-time-zone: "UTC0"
79100084f2cSmrg# time-stamp-end: "; # UTC"
79227702724Smrg# End:
793