1267843Sdelphij#! /bin/sh
2267843Sdelphij# depcomp - compile a program generating dependencies as side-effects
3267843Sdelphij
4267843Sdelphijscriptversion=2013-05-30.07; # UTC
5267843Sdelphij
6267843Sdelphij# Copyright (C) 1999-2013 Free Software Foundation, Inc.
7267843Sdelphij
8267843Sdelphij# This program is free software; you can redistribute it and/or modify
9267843Sdelphij# it under the terms of the GNU General Public License as published by
10267843Sdelphij# the Free Software Foundation; either version 2, or (at your option)
11267843Sdelphij# any later version.
12267843Sdelphij
13267843Sdelphij# This program is distributed in the hope that it will be useful,
14267843Sdelphij# but WITHOUT ANY WARRANTY; without even the implied warranty of
15267843Sdelphij# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16267843Sdelphij# GNU General Public License for more details.
17267843Sdelphij
18267843Sdelphij# You should have received a copy of the GNU General Public License
19267843Sdelphij# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20267843Sdelphij
21267843Sdelphij# As a special exception to the GNU General Public License, if you
22267843Sdelphij# distribute this file as part of a program that contains a
23267843Sdelphij# configuration script generated by Autoconf, you may include it under
24267843Sdelphij# the same distribution terms that you use for the rest of that program.
25267843Sdelphij
26267843Sdelphij# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27267843Sdelphij
28267843Sdelphijcase $1 in
29267843Sdelphij  '')
30267843Sdelphij    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
31267843Sdelphij    exit 1;
32267843Sdelphij    ;;
33267843Sdelphij  -h | --h*)
34267843Sdelphij    cat <<\EOF
35267843SdelphijUsage: depcomp [--help] [--version] PROGRAM [ARGS]
36267843Sdelphij
37267843SdelphijRun PROGRAMS ARGS to compile a file, generating dependencies
38267843Sdelphijas side-effects.
39267843Sdelphij
40267843SdelphijEnvironment variables:
41267843Sdelphij  depmode     Dependency tracking mode.
42267843Sdelphij  source      Source file read by 'PROGRAMS ARGS'.
43267843Sdelphij  object      Object file output by 'PROGRAMS ARGS'.
44267843Sdelphij  DEPDIR      directory where to store dependencies.
45267843Sdelphij  depfile     Dependency file to output.
46267843Sdelphij  tmpdepfile  Temporary file to use when outputting dependencies.
47267843Sdelphij  libtool     Whether libtool is used (yes/no).
48267843Sdelphij
49267843SdelphijReport bugs to <bug-automake@gnu.org>.
50267843SdelphijEOF
51267843Sdelphij    exit $?
52267843Sdelphij    ;;
53267843Sdelphij  -v | --v*)
54267843Sdelphij    echo "depcomp $scriptversion"
55267843Sdelphij    exit $?
56267843Sdelphij    ;;
57267843Sdelphijesac
58267843Sdelphij
59267843Sdelphij# Get the directory component of the given path, and save it in the
60267843Sdelphij# global variables '$dir'.  Note that this directory component will
61267843Sdelphij# be either empty or ending with a '/' character.  This is deliberate.
62267843Sdelphijset_dir_from ()
63267843Sdelphij{
64267843Sdelphij  case $1 in
65267843Sdelphij    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66267843Sdelphij      *) dir=;;
67267843Sdelphij  esac
68267843Sdelphij}
69267843Sdelphij
70267843Sdelphij# Get the suffix-stripped basename of the given path, and save it the
71267843Sdelphij# global variable '$base'.
72267843Sdelphijset_base_from ()
73267843Sdelphij{
74267843Sdelphij  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75267843Sdelphij}
76267843Sdelphij
77267843Sdelphij# If no dependency file was actually created by the compiler invocation,
78267843Sdelphij# we still have to create a dummy depfile, to avoid errors with the
79267843Sdelphij# Makefile "include basename.Plo" scheme.
80267843Sdelphijmake_dummy_depfile ()
81267843Sdelphij{
82267843Sdelphij  echo "#dummy" > "$depfile"
83267843Sdelphij}
84267843Sdelphij
85267843Sdelphij# Factor out some common post-processing of the generated depfile.
86267843Sdelphij# Requires the auxiliary global variable '$tmpdepfile' to be set.
87267843Sdelphijaix_post_process_depfile ()
88267843Sdelphij{
89267843Sdelphij  # If the compiler actually managed to produce a dependency file,
90267843Sdelphij  # post-process it.
91267843Sdelphij  if test -f "$tmpdepfile"; then
92267843Sdelphij    # Each line is of the form 'foo.o: dependency.h'.
93267843Sdelphij    # Do two passes, one to just change these to
94267843Sdelphij    #   $object: dependency.h
95267843Sdelphij    # and one to simply output
96267843Sdelphij    #   dependency.h:
97267843Sdelphij    # which is needed to avoid the deleted-header problem.
98267843Sdelphij    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99267843Sdelphij      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100267843Sdelphij    } > "$depfile"
101267843Sdelphij    rm -f "$tmpdepfile"
102267843Sdelphij  else
103267843Sdelphij    make_dummy_depfile
104267843Sdelphij  fi
105267843Sdelphij}
106267843Sdelphij
107267843Sdelphij# A tabulation character.
108267843Sdelphijtab='	'
109267843Sdelphij# A newline character.
110267843Sdelphijnl='
111267843Sdelphij'
112267843Sdelphij# Character ranges might be problematic outside the C locale.
113267843Sdelphij# These definitions help.
114267843Sdelphijupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115267843Sdelphijlower=abcdefghijklmnopqrstuvwxyz
116267843Sdelphijdigits=0123456789
117267843Sdelphijalpha=${upper}${lower}
118267843Sdelphij
119267843Sdelphijif test -z "$depmode" || test -z "$source" || test -z "$object"; then
120267843Sdelphij  echo "depcomp: Variables source, object and depmode must be set" 1>&2
121267843Sdelphij  exit 1
122267843Sdelphijfi
123267843Sdelphij
124267843Sdelphij# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
125267843Sdelphijdepfile=${depfile-`echo "$object" |
126267843Sdelphij  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
127267843Sdelphijtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
128267843Sdelphij
129267843Sdelphijrm -f "$tmpdepfile"
130267843Sdelphij
131267843Sdelphij# Avoid interferences from the environment.
132267843Sdelphijgccflag= dashmflag=
133267843Sdelphij
134267843Sdelphij# Some modes work just like other modes, but use different flags.  We
135267843Sdelphij# parameterize here, but still list the modes in the big case below,
136267843Sdelphij# to make depend.m4 easier to write.  Note that we *cannot* use a case
137267843Sdelphij# here, because this file can only contain one case statement.
138267843Sdelphijif test "$depmode" = hp; then
139267843Sdelphij  # HP compiler uses -M and no extra arg.
140267843Sdelphij  gccflag=-M
141267843Sdelphij  depmode=gcc
142267843Sdelphijfi
143267843Sdelphij
144267843Sdelphijif test "$depmode" = dashXmstdout; then
145267843Sdelphij  # This is just like dashmstdout with a different argument.
146267843Sdelphij  dashmflag=-xM
147267843Sdelphij  depmode=dashmstdout
148267843Sdelphijfi
149267843Sdelphij
150267843Sdelphijcygpath_u="cygpath -u -f -"
151267843Sdelphijif test "$depmode" = msvcmsys; then
152267843Sdelphij  # This is just like msvisualcpp but w/o cygpath translation.
153267843Sdelphij  # Just convert the backslash-escaped backslashes to single forward
154267843Sdelphij  # slashes to satisfy depend.m4
155267843Sdelphij  cygpath_u='sed s,\\\\,/,g'
156267843Sdelphij  depmode=msvisualcpp
157267843Sdelphijfi
158267843Sdelphij
159267843Sdelphijif test "$depmode" = msvc7msys; then
160267843Sdelphij  # This is just like msvc7 but w/o cygpath translation.
161267843Sdelphij  # Just convert the backslash-escaped backslashes to single forward
162267843Sdelphij  # slashes to satisfy depend.m4
163267843Sdelphij  cygpath_u='sed s,\\\\,/,g'
164267843Sdelphij  depmode=msvc7
165267843Sdelphijfi
166267843Sdelphij
167267843Sdelphijif test "$depmode" = xlc; then
168267843Sdelphij  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
169267843Sdelphij  gccflag=-qmakedep=gcc,-MF
170267843Sdelphij  depmode=gcc
171267843Sdelphijfi
172267843Sdelphij
173267843Sdelphijcase "$depmode" in
174267843Sdelphijgcc3)
175267843Sdelphij## gcc 3 implements dependency tracking that does exactly what
176267843Sdelphij## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
177267843Sdelphij## it if -MD -MP comes after the -MF stuff.  Hmm.
178267843Sdelphij## Unfortunately, FreeBSD c89 acceptance of flags depends upon
179267843Sdelphij## the command line argument order; so add the flags where they
180267843Sdelphij## appear in depend2.am.  Note that the slowdown incurred here
181267843Sdelphij## affects only configure: in makefiles, %FASTDEP% shortcuts this.
182267843Sdelphij  for arg
183267843Sdelphij  do
184267843Sdelphij    case $arg in
185267843Sdelphij    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
186267843Sdelphij    *)  set fnord "$@" "$arg" ;;
187267843Sdelphij    esac
188267843Sdelphij    shift # fnord
189267843Sdelphij    shift # $arg
190267843Sdelphij  done
191267843Sdelphij  "$@"
192267843Sdelphij  stat=$?
193267843Sdelphij  if test $stat -ne 0; then
194267843Sdelphij    rm -f "$tmpdepfile"
195267843Sdelphij    exit $stat
196267843Sdelphij  fi
197267843Sdelphij  mv "$tmpdepfile" "$depfile"
198267843Sdelphij  ;;
199267843Sdelphij
200267843Sdelphijgcc)
201267843Sdelphij## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202267843Sdelphij## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203267843Sdelphij## (see the conditional assignment to $gccflag above).
204267843Sdelphij## There are various ways to get dependency output from gcc.  Here's
205267843Sdelphij## why we pick this rather obscure method:
206267843Sdelphij## - Don't want to use -MD because we'd like the dependencies to end
207267843Sdelphij##   up in a subdir.  Having to rename by hand is ugly.
208267843Sdelphij##   (We might end up doing this anyway to support other compilers.)
209267843Sdelphij## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210267843Sdelphij##   -MM, not -M (despite what the docs say).  Also, it might not be
211267843Sdelphij##   supported by the other compilers which use the 'gcc' depmode.
212267843Sdelphij## - Using -M directly means running the compiler twice (even worse
213267843Sdelphij##   than renaming).
214267843Sdelphij  if test -z "$gccflag"; then
215267843Sdelphij    gccflag=-MD,
216267843Sdelphij  fi
217267843Sdelphij  "$@" -Wp,"$gccflag$tmpdepfile"
218267843Sdelphij  stat=$?
219267843Sdelphij  if test $stat -ne 0; then
220267843Sdelphij    rm -f "$tmpdepfile"
221267843Sdelphij    exit $stat
222267843Sdelphij  fi
223267843Sdelphij  rm -f "$depfile"
224267843Sdelphij  echo "$object : \\" > "$depfile"
225267843Sdelphij  # The second -e expression handles DOS-style file names with drive
226267843Sdelphij  # letters.
227267843Sdelphij  sed -e 's/^[^:]*: / /' \
228267843Sdelphij      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229267843Sdelphij## This next piece of magic avoids the "deleted header file" problem.
230267843Sdelphij## The problem is that when a header file which appears in a .P file
231267843Sdelphij## is deleted, the dependency causes make to die (because there is
232267843Sdelphij## typically no way to rebuild the header).  We avoid this by adding
233267843Sdelphij## dummy dependencies for each header file.  Too bad gcc doesn't do
234267843Sdelphij## this for us directly.
235267843Sdelphij## Some versions of gcc put a space before the ':'.  On the theory
236267843Sdelphij## that the space means something, we add a space to the output as
237267843Sdelphij## well.  hp depmode also adds that space, but also prefixes the VPATH
238267843Sdelphij## to the object.  Take care to not repeat it in the output.
239267843Sdelphij## Some versions of the HPUX 10.20 sed can't process this invocation
240267843Sdelphij## correctly.  Breaking it into two sed invocations is a workaround.
241267843Sdelphij  tr ' ' "$nl" < "$tmpdepfile" \
242267843Sdelphij    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
243267843Sdelphij    | sed -e 's/$/ :/' >> "$depfile"
244267843Sdelphij  rm -f "$tmpdepfile"
245267843Sdelphij  ;;
246267843Sdelphij
247267843Sdelphijhp)
248267843Sdelphij  # This case exists only to let depend.m4 do its work.  It works by
249267843Sdelphij  # looking at the text of this script.  This case will never be run,
250267843Sdelphij  # since it is checked for above.
251267843Sdelphij  exit 1
252267843Sdelphij  ;;
253267843Sdelphij
254267843Sdelphijsgi)
255267843Sdelphij  if test "$libtool" = yes; then
256267843Sdelphij    "$@" "-Wp,-MDupdate,$tmpdepfile"
257267843Sdelphij  else
258267843Sdelphij    "$@" -MDupdate "$tmpdepfile"
259267843Sdelphij  fi
260267843Sdelphij  stat=$?
261267843Sdelphij  if test $stat -ne 0; then
262267843Sdelphij    rm -f "$tmpdepfile"
263267843Sdelphij    exit $stat
264267843Sdelphij  fi
265267843Sdelphij  rm -f "$depfile"
266267843Sdelphij
267267843Sdelphij  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
268267843Sdelphij    echo "$object : \\" > "$depfile"
269267843Sdelphij    # Clip off the initial element (the dependent).  Don't try to be
270267843Sdelphij    # clever and replace this with sed code, as IRIX sed won't handle
271267843Sdelphij    # lines with more than a fixed number of characters (4096 in
272267843Sdelphij    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273267843Sdelphij    # the IRIX cc adds comments like '#:fec' to the end of the
274267843Sdelphij    # dependency line.
275267843Sdelphij    tr ' ' "$nl" < "$tmpdepfile" \
276267843Sdelphij      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277267843Sdelphij      | tr "$nl" ' ' >> "$depfile"
278267843Sdelphij    echo >> "$depfile"
279267843Sdelphij    # The second pass generates a dummy entry for each header file.
280267843Sdelphij    tr ' ' "$nl" < "$tmpdepfile" \
281267843Sdelphij      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
282267843Sdelphij      >> "$depfile"
283267843Sdelphij  else
284267843Sdelphij    make_dummy_depfile
285267843Sdelphij  fi
286267843Sdelphij  rm -f "$tmpdepfile"
287267843Sdelphij  ;;
288267843Sdelphij
289267843Sdelphijxlc)
290267843Sdelphij  # This case exists only to let depend.m4 do its work.  It works by
291267843Sdelphij  # looking at the text of this script.  This case will never be run,
292267843Sdelphij  # since it is checked for above.
293267843Sdelphij  exit 1
294267843Sdelphij  ;;
295267843Sdelphij
296267843Sdelphijaix)
297267843Sdelphij  # The C for AIX Compiler uses -M and outputs the dependencies
298267843Sdelphij  # in a .u file.  In older versions, this file always lives in the
299267843Sdelphij  # current directory.  Also, the AIX compiler puts '$object:' at the
300267843Sdelphij  # start of each line; $object doesn't have directory information.
301267843Sdelphij  # Version 6 uses the directory in both cases.
302267843Sdelphij  set_dir_from "$object"
303267843Sdelphij  set_base_from "$object"
304267843Sdelphij  if test "$libtool" = yes; then
305267843Sdelphij    tmpdepfile1=$dir$base.u
306267843Sdelphij    tmpdepfile2=$base.u
307267843Sdelphij    tmpdepfile3=$dir.libs/$base.u
308267843Sdelphij    "$@" -Wc,-M
309267843Sdelphij  else
310267843Sdelphij    tmpdepfile1=$dir$base.u
311267843Sdelphij    tmpdepfile2=$dir$base.u
312267843Sdelphij    tmpdepfile3=$dir$base.u
313267843Sdelphij    "$@" -M
314267843Sdelphij  fi
315267843Sdelphij  stat=$?
316267843Sdelphij  if test $stat -ne 0; then
317267843Sdelphij    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
318267843Sdelphij    exit $stat
319267843Sdelphij  fi
320267843Sdelphij
321267843Sdelphij  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
322267843Sdelphij  do
323267843Sdelphij    test -f "$tmpdepfile" && break
324267843Sdelphij  done
325267843Sdelphij  aix_post_process_depfile
326267843Sdelphij  ;;
327267843Sdelphij
328267843Sdelphijtcc)
329267843Sdelphij  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330267843Sdelphij  # FIXME: That version still under development at the moment of writing.
331267843Sdelphij  #        Make that this statement remains true also for stable, released
332267843Sdelphij  #        versions.
333267843Sdelphij  # It will wrap lines (doesn't matter whether long or short) with a
334267843Sdelphij  # trailing '\', as in:
335267843Sdelphij  #
336267843Sdelphij  #   foo.o : \
337267843Sdelphij  #    foo.c \
338267843Sdelphij  #    foo.h \
339267843Sdelphij  #
340267843Sdelphij  # It will put a trailing '\' even on the last line, and will use leading
341267843Sdelphij  # spaces rather than leading tabs (at least since its commit 0394caf7
342267843Sdelphij  # "Emit spaces for -MD").
343267843Sdelphij  "$@" -MD -MF "$tmpdepfile"
344267843Sdelphij  stat=$?
345267843Sdelphij  if test $stat -ne 0; then
346267843Sdelphij    rm -f "$tmpdepfile"
347267843Sdelphij    exit $stat
348267843Sdelphij  fi
349267843Sdelphij  rm -f "$depfile"
350267843Sdelphij  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351267843Sdelphij  # We have to change lines of the first kind to '$object: \'.
352267843Sdelphij  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353267843Sdelphij  # And for each line of the second kind, we have to emit a 'dep.h:'
354267843Sdelphij  # dummy dependency, to avoid the deleted-header problem.
355267843Sdelphij  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356267843Sdelphij  rm -f "$tmpdepfile"
357267843Sdelphij  ;;
358267843Sdelphij
359267843Sdelphij## The order of this option in the case statement is important, since the
360267843Sdelphij## shell code in configure will try each of these formats in the order
361267843Sdelphij## listed in this file.  A plain '-MD' option would be understood by many
362267843Sdelphij## compilers, so we must ensure this comes after the gcc and icc options.
363267843Sdelphijpgcc)
364267843Sdelphij  # Portland's C compiler understands '-MD'.
365267843Sdelphij  # Will always output deps to 'file.d' where file is the root name of the
366267843Sdelphij  # source file under compilation, even if file resides in a subdirectory.
367267843Sdelphij  # The object file name does not affect the name of the '.d' file.
368267843Sdelphij  # pgcc 10.2 will output
369267843Sdelphij  #    foo.o: sub/foo.c sub/foo.h
370267843Sdelphij  # and will wrap long lines using '\' :
371267843Sdelphij  #    foo.o: sub/foo.c ... \
372267843Sdelphij  #     sub/foo.h ... \
373267843Sdelphij  #     ...
374267843Sdelphij  set_dir_from "$object"
375267843Sdelphij  # Use the source, not the object, to determine the base name, since
376267843Sdelphij  # that's sadly what pgcc will do too.
377267843Sdelphij  set_base_from "$source"
378267843Sdelphij  tmpdepfile=$base.d
379267843Sdelphij
380267843Sdelphij  # For projects that build the same source file twice into different object
381267843Sdelphij  # files, the pgcc approach of using the *source* file root name can cause
382267843Sdelphij  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383267843Sdelphij  # the same $tmpdepfile.
384267843Sdelphij  lockdir=$base.d-lock
385267843Sdelphij  trap "
386267843Sdelphij    echo '$0: caught signal, cleaning up...' >&2
387267843Sdelphij    rmdir '$lockdir'
388267843Sdelphij    exit 1
389267843Sdelphij  " 1 2 13 15
390267843Sdelphij  numtries=100
391267843Sdelphij  i=$numtries
392267843Sdelphij  while test $i -gt 0; do
393267843Sdelphij    # mkdir is a portable test-and-set.
394267843Sdelphij    if mkdir "$lockdir" 2>/dev/null; then
395267843Sdelphij      # This process acquired the lock.
396267843Sdelphij      "$@" -MD
397267843Sdelphij      stat=$?
398267843Sdelphij      # Release the lock.
399267843Sdelphij      rmdir "$lockdir"
400267843Sdelphij      break
401267843Sdelphij    else
402267843Sdelphij      # If the lock is being held by a different process, wait
403267843Sdelphij      # until the winning process is done or we timeout.
404267843Sdelphij      while test -d "$lockdir" && test $i -gt 0; do
405267843Sdelphij        sleep 1
406267843Sdelphij        i=`expr $i - 1`
407267843Sdelphij      done
408267843Sdelphij    fi
409267843Sdelphij    i=`expr $i - 1`
410267843Sdelphij  done
411267843Sdelphij  trap - 1 2 13 15
412267843Sdelphij  if test $i -le 0; then
413267843Sdelphij    echo "$0: failed to acquire lock after $numtries attempts" >&2
414267843Sdelphij    echo "$0: check lockdir '$lockdir'" >&2
415267843Sdelphij    exit 1
416267843Sdelphij  fi
417267843Sdelphij
418267843Sdelphij  if test $stat -ne 0; then
419267843Sdelphij    rm -f "$tmpdepfile"
420267843Sdelphij    exit $stat
421267843Sdelphij  fi
422267843Sdelphij  rm -f "$depfile"
423267843Sdelphij  # Each line is of the form `foo.o: dependent.h',
424267843Sdelphij  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
425267843Sdelphij  # Do two passes, one to just change these to
426267843Sdelphij  # `$object: dependent.h' and one to simply `dependent.h:'.
427267843Sdelphij  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428267843Sdelphij  # Some versions of the HPUX 10.20 sed can't process this invocation
429267843Sdelphij  # correctly.  Breaking it into two sed invocations is a workaround.
430267843Sdelphij  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431267843Sdelphij    | sed -e 's/$/ :/' >> "$depfile"
432267843Sdelphij  rm -f "$tmpdepfile"
433267843Sdelphij  ;;
434267843Sdelphij
435267843Sdelphijhp2)
436267843Sdelphij  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
437267843Sdelphij  # compilers, which have integrated preprocessors.  The correct option
438267843Sdelphij  # to use with these is +Maked; it writes dependencies to a file named
439267843Sdelphij  # 'foo.d', which lands next to the object file, wherever that
440267843Sdelphij  # happens to be.
441267843Sdelphij  # Much of this is similar to the tru64 case; see comments there.
442267843Sdelphij  set_dir_from  "$object"
443267843Sdelphij  set_base_from "$object"
444267843Sdelphij  if test "$libtool" = yes; then
445267843Sdelphij    tmpdepfile1=$dir$base.d
446267843Sdelphij    tmpdepfile2=$dir.libs/$base.d
447267843Sdelphij    "$@" -Wc,+Maked
448267843Sdelphij  else
449267843Sdelphij    tmpdepfile1=$dir$base.d
450267843Sdelphij    tmpdepfile2=$dir$base.d
451267843Sdelphij    "$@" +Maked
452267843Sdelphij  fi
453267843Sdelphij  stat=$?
454267843Sdelphij  if test $stat -ne 0; then
455267843Sdelphij     rm -f "$tmpdepfile1" "$tmpdepfile2"
456267843Sdelphij     exit $stat
457267843Sdelphij  fi
458267843Sdelphij
459267843Sdelphij  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
460267843Sdelphij  do
461267843Sdelphij    test -f "$tmpdepfile" && break
462267843Sdelphij  done
463267843Sdelphij  if test -f "$tmpdepfile"; then
464267843Sdelphij    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465267843Sdelphij    # Add 'dependent.h:' lines.
466267843Sdelphij    sed -ne '2,${
467267843Sdelphij               s/^ *//
468267843Sdelphij               s/ \\*$//
469267843Sdelphij               s/$/:/
470267843Sdelphij               p
471267843Sdelphij             }' "$tmpdepfile" >> "$depfile"
472267843Sdelphij  else
473267843Sdelphij    make_dummy_depfile
474267843Sdelphij  fi
475267843Sdelphij  rm -f "$tmpdepfile" "$tmpdepfile2"
476267843Sdelphij  ;;
477267843Sdelphij
478267843Sdelphijtru64)
479267843Sdelphij  # The Tru64 compiler uses -MD to generate dependencies as a side
480267843Sdelphij  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
481267843Sdelphij  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
482267843Sdelphij  # dependencies in 'foo.d' instead, so we check for that too.
483267843Sdelphij  # Subdirectories are respected.
484267843Sdelphij  set_dir_from  "$object"
485267843Sdelphij  set_base_from "$object"
486267843Sdelphij
487267843Sdelphij  if test "$libtool" = yes; then
488267843Sdelphij    # Libtool generates 2 separate objects for the 2 libraries.  These
489267843Sdelphij    # two compilations output dependencies in $dir.libs/$base.o.d and
490267843Sdelphij    # in $dir$base.o.d.  We have to check for both files, because
491267843Sdelphij    # one of the two compilations can be disabled.  We should prefer
492267843Sdelphij    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
493267843Sdelphij    # automatically cleaned when .libs/ is deleted, while ignoring
494267843Sdelphij    # the former would cause a distcleancheck panic.
495267843Sdelphij    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496267843Sdelphij    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497267843Sdelphij    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
498267843Sdelphij    "$@" -Wc,-MD
499267843Sdelphij  else
500267843Sdelphij    tmpdepfile1=$dir$base.d
501267843Sdelphij    tmpdepfile2=$dir$base.d
502267843Sdelphij    tmpdepfile3=$dir$base.d
503267843Sdelphij    "$@" -MD
504267843Sdelphij  fi
505267843Sdelphij
506267843Sdelphij  stat=$?
507267843Sdelphij  if test $stat -ne 0; then
508267843Sdelphij    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
509267843Sdelphij    exit $stat
510267843Sdelphij  fi
511267843Sdelphij
512267843Sdelphij  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
513267843Sdelphij  do
514267843Sdelphij    test -f "$tmpdepfile" && break
515267843Sdelphij  done
516267843Sdelphij  # Same post-processing that is required for AIX mode.
517267843Sdelphij  aix_post_process_depfile
518267843Sdelphij  ;;
519267843Sdelphij
520267843Sdelphijmsvc7)
521267843Sdelphij  if test "$libtool" = yes; then
522267843Sdelphij    showIncludes=-Wc,-showIncludes
523267843Sdelphij  else
524267843Sdelphij    showIncludes=-showIncludes
525267843Sdelphij  fi
526267843Sdelphij  "$@" $showIncludes > "$tmpdepfile"
527267843Sdelphij  stat=$?
528267843Sdelphij  grep -v '^Note: including file: ' "$tmpdepfile"
529267843Sdelphij  if test $stat -ne 0; then
530267843Sdelphij    rm -f "$tmpdepfile"
531267843Sdelphij    exit $stat
532267843Sdelphij  fi
533267843Sdelphij  rm -f "$depfile"
534267843Sdelphij  echo "$object : \\" > "$depfile"
535267843Sdelphij  # The first sed program below extracts the file names and escapes
536267843Sdelphij  # backslashes for cygpath.  The second sed program outputs the file
537267843Sdelphij  # name when reading, but also accumulates all include files in the
538267843Sdelphij  # hold buffer in order to output them again at the end.  This only
539267843Sdelphij  # works with sed implementations that can handle large buffers.
540267843Sdelphij  sed < "$tmpdepfile" -n '
541267843Sdelphij/^Note: including file:  *\(.*\)/ {
542267843Sdelphij  s//\1/
543267843Sdelphij  s/\\/\\\\/g
544267843Sdelphij  p
545267843Sdelphij}' | $cygpath_u | sort -u | sed -n '
546267843Sdelphijs/ /\\ /g
547267843Sdelphijs/\(.*\)/'"$tab"'\1 \\/p
548267843Sdelphijs/.\(.*\) \\/\1:/
549267843SdelphijH
550267843Sdelphij$ {
551267843Sdelphij  s/.*/'"$tab"'/
552267843Sdelphij  G
553267843Sdelphij  p
554267843Sdelphij}' >> "$depfile"
555267843Sdelphij  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556267843Sdelphij  rm -f "$tmpdepfile"
557267843Sdelphij  ;;
558267843Sdelphij
559267843Sdelphijmsvc7msys)
560267843Sdelphij  # This case exists only to let depend.m4 do its work.  It works by
561267843Sdelphij  # looking at the text of this script.  This case will never be run,
562267843Sdelphij  # since it is checked for above.
563267843Sdelphij  exit 1
564267843Sdelphij  ;;
565267843Sdelphij
566267843Sdelphij#nosideeffect)
567267843Sdelphij  # This comment above is used by automake to tell side-effect
568267843Sdelphij  # dependency tracking mechanisms from slower ones.
569267843Sdelphij
570267843Sdelphijdashmstdout)
571267843Sdelphij  # Important note: in order to support this mode, a compiler *must*
572267843Sdelphij  # always write the preprocessed file to stdout, regardless of -o.
573267843Sdelphij  "$@" || exit $?
574267843Sdelphij
575267843Sdelphij  # Remove the call to Libtool.
576267843Sdelphij  if test "$libtool" = yes; then
577267843Sdelphij    while test "X$1" != 'X--mode=compile'; do
578267843Sdelphij      shift
579267843Sdelphij    done
580267843Sdelphij    shift
581267843Sdelphij  fi
582267843Sdelphij
583267843Sdelphij  # Remove '-o $object'.
584267843Sdelphij  IFS=" "
585267843Sdelphij  for arg
586267843Sdelphij  do
587267843Sdelphij    case $arg in
588267843Sdelphij    -o)
589267843Sdelphij      shift
590267843Sdelphij      ;;
591267843Sdelphij    $object)
592267843Sdelphij      shift
593267843Sdelphij      ;;
594267843Sdelphij    *)
595267843Sdelphij      set fnord "$@" "$arg"
596267843Sdelphij      shift # fnord
597267843Sdelphij      shift # $arg
598267843Sdelphij      ;;
599267843Sdelphij    esac
600267843Sdelphij  done
601267843Sdelphij
602267843Sdelphij  test -z "$dashmflag" && dashmflag=-M
603267843Sdelphij  # Require at least two characters before searching for ':'
604267843Sdelphij  # in the target name.  This is to cope with DOS-style filenames:
605267843Sdelphij  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
606267843Sdelphij  "$@" $dashmflag |
607267843Sdelphij    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
608267843Sdelphij  rm -f "$depfile"
609267843Sdelphij  cat < "$tmpdepfile" > "$depfile"
610267843Sdelphij  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611267843Sdelphij  # correctly.  Breaking it into two sed invocations is a workaround.
612267843Sdelphij  tr ' ' "$nl" < "$tmpdepfile" \
613267843Sdelphij    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614267843Sdelphij    | sed -e 's/$/ :/' >> "$depfile"
615267843Sdelphij  rm -f "$tmpdepfile"
616267843Sdelphij  ;;
617267843Sdelphij
618267843SdelphijdashXmstdout)
619267843Sdelphij  # This case only exists to satisfy depend.m4.  It is never actually
620267843Sdelphij  # run, as this mode is specially recognized in the preamble.
621267843Sdelphij  exit 1
622267843Sdelphij  ;;
623267843Sdelphij
624267843Sdelphijmakedepend)
625267843Sdelphij  "$@" || exit $?
626267843Sdelphij  # Remove any Libtool call
627267843Sdelphij  if test "$libtool" = yes; then
628267843Sdelphij    while test "X$1" != 'X--mode=compile'; do
629267843Sdelphij      shift
630267843Sdelphij    done
631267843Sdelphij    shift
632267843Sdelphij  fi
633267843Sdelphij  # X makedepend
634267843Sdelphij  shift
635267843Sdelphij  cleared=no eat=no
636267843Sdelphij  for arg
637267843Sdelphij  do
638267843Sdelphij    case $cleared in
639267843Sdelphij    no)
640267843Sdelphij      set ""; shift
641267843Sdelphij      cleared=yes ;;
642267843Sdelphij    esac
643267843Sdelphij    if test $eat = yes; then
644267843Sdelphij      eat=no
645267843Sdelphij      continue
646267843Sdelphij    fi
647267843Sdelphij    case "$arg" in
648267843Sdelphij    -D*|-I*)
649267843Sdelphij      set fnord "$@" "$arg"; shift ;;
650267843Sdelphij    # Strip any option that makedepend may not understand.  Remove
651267843Sdelphij    # the object too, otherwise makedepend will parse it as a source file.
652267843Sdelphij    -arch)
653267843Sdelphij      eat=yes ;;
654267843Sdelphij    -*|$object)
655267843Sdelphij      ;;
656267843Sdelphij    *)
657267843Sdelphij      set fnord "$@" "$arg"; shift ;;
658267843Sdelphij    esac
659267843Sdelphij  done
660267843Sdelphij  obj_suffix=`echo "$object" | sed 's/^.*\././'`
661267843Sdelphij  touch "$tmpdepfile"
662267843Sdelphij  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
663267843Sdelphij  rm -f "$depfile"
664267843Sdelphij  # makedepend may prepend the VPATH from the source file name to the object.
665267843Sdelphij  # No need to regex-escape $object, excess matching of '.' is harmless.
666267843Sdelphij  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667267843Sdelphij  # Some versions of the HPUX 10.20 sed can't process the last invocation
668267843Sdelphij  # correctly.  Breaking it into two sed invocations is a workaround.
669267843Sdelphij  sed '1,2d' "$tmpdepfile" \
670267843Sdelphij    | tr ' ' "$nl" \
671267843Sdelphij    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672267843Sdelphij    | sed -e 's/$/ :/' >> "$depfile"
673267843Sdelphij  rm -f "$tmpdepfile" "$tmpdepfile".bak
674267843Sdelphij  ;;
675267843Sdelphij
676267843Sdelphijcpp)
677267843Sdelphij  # Important note: in order to support this mode, a compiler *must*
678267843Sdelphij  # always write the preprocessed file to stdout.
679267843Sdelphij  "$@" || exit $?
680267843Sdelphij
681267843Sdelphij  # Remove the call to Libtool.
682267843Sdelphij  if test "$libtool" = yes; then
683267843Sdelphij    while test "X$1" != 'X--mode=compile'; do
684267843Sdelphij      shift
685267843Sdelphij    done
686267843Sdelphij    shift
687267843Sdelphij  fi
688267843Sdelphij
689267843Sdelphij  # Remove '-o $object'.
690267843Sdelphij  IFS=" "
691267843Sdelphij  for arg
692267843Sdelphij  do
693267843Sdelphij    case $arg in
694267843Sdelphij    -o)
695267843Sdelphij      shift
696267843Sdelphij      ;;
697267843Sdelphij    $object)
698267843Sdelphij      shift
699267843Sdelphij      ;;
700267843Sdelphij    *)
701267843Sdelphij      set fnord "$@" "$arg"
702267843Sdelphij      shift # fnord
703267843Sdelphij      shift # $arg
704267843Sdelphij      ;;
705267843Sdelphij    esac
706267843Sdelphij  done
707267843Sdelphij
708267843Sdelphij  "$@" -E \
709267843Sdelphij    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710267843Sdelphij             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711267843Sdelphij    | sed '$ s: \\$::' > "$tmpdepfile"
712267843Sdelphij  rm -f "$depfile"
713267843Sdelphij  echo "$object : \\" > "$depfile"
714267843Sdelphij  cat < "$tmpdepfile" >> "$depfile"
715267843Sdelphij  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
716267843Sdelphij  rm -f "$tmpdepfile"
717267843Sdelphij  ;;
718267843Sdelphij
719267843Sdelphijmsvisualcpp)
720267843Sdelphij  # Important note: in order to support this mode, a compiler *must*
721267843Sdelphij  # always write the preprocessed file to stdout.
722267843Sdelphij  "$@" || exit $?
723267843Sdelphij
724267843Sdelphij  # Remove the call to Libtool.
725267843Sdelphij  if test "$libtool" = yes; then
726267843Sdelphij    while test "X$1" != 'X--mode=compile'; do
727267843Sdelphij      shift
728267843Sdelphij    done
729267843Sdelphij    shift
730267843Sdelphij  fi
731267843Sdelphij
732267843Sdelphij  IFS=" "
733267843Sdelphij  for arg
734267843Sdelphij  do
735267843Sdelphij    case "$arg" in
736267843Sdelphij    -o)
737267843Sdelphij      shift
738267843Sdelphij      ;;
739267843Sdelphij    $object)
740267843Sdelphij      shift
741267843Sdelphij      ;;
742267843Sdelphij    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
743267843Sdelphij        set fnord "$@"
744267843Sdelphij        shift
745267843Sdelphij        shift
746267843Sdelphij        ;;
747267843Sdelphij    *)
748267843Sdelphij        set fnord "$@" "$arg"
749267843Sdelphij        shift
750267843Sdelphij        shift
751267843Sdelphij        ;;
752267843Sdelphij    esac
753267843Sdelphij  done
754267843Sdelphij  "$@" -E 2>/dev/null |
755267843Sdelphij  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
756267843Sdelphij  rm -f "$depfile"
757267843Sdelphij  echo "$object : \\" > "$depfile"
758267843Sdelphij  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759267843Sdelphij  echo "$tab" >> "$depfile"
760267843Sdelphij  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
761267843Sdelphij  rm -f "$tmpdepfile"
762267843Sdelphij  ;;
763267843Sdelphij
764267843Sdelphijmsvcmsys)
765267843Sdelphij  # This case exists only to let depend.m4 do its work.  It works by
766267843Sdelphij  # looking at the text of this script.  This case will never be run,
767267843Sdelphij  # since it is checked for above.
768267843Sdelphij  exit 1
769267843Sdelphij  ;;
770267843Sdelphij
771267843Sdelphijnone)
772267843Sdelphij  exec "$@"
773267843Sdelphij  ;;
774267843Sdelphij
775267843Sdelphij*)
776267843Sdelphij  echo "Unknown depmode $depmode" 1>&2
777267843Sdelphij  exit 1
778267843Sdelphij  ;;
779267843Sdelphijesac
780267843Sdelphij
781267843Sdelphijexit 0
782267843Sdelphij
783267843Sdelphij# Local Variables:
784267843Sdelphij# mode: shell-script
785267843Sdelphij# sh-indentation: 2
786267843Sdelphij# eval: (add-hook 'write-file-hooks 'time-stamp)
787267843Sdelphij# time-stamp-start: "scriptversion="
788267843Sdelphij# time-stamp-format: "%:y-%02m-%02d.%02H"
789267843Sdelphij# time-stamp-time-zone: "UTC"
790267843Sdelphij# time-stamp-end: "; # UTC"
791267843Sdelphij# End:
792