xref: /netbsd-src/external/lgpl3/mpc/dist/depcomp (revision 062d2d48d34d3e4901797f81befe658ca0cf6792)
18fa80f29Smrg#!/bin/sh
28fa80f29Smrg# depcomp - compile a program generating dependencies as side-effects
38fa80f29Smrg
4*062d2d48Smrgscriptversion=2013-05-30.07; # UTC
58fa80f29Smrg
6*062d2d48Smrg# Copyright (C) 1999-2014 Free Software Foundation, Inc.
78fa80f29Smrg
88fa80f29Smrg# This program is free software; you can redistribute it and/or modify
98fa80f29Smrg# it under the terms of the GNU General Public License as published by
108fa80f29Smrg# the Free Software Foundation; either version 2, or (at your option)
118fa80f29Smrg# any later version.
128fa80f29Smrg
138fa80f29Smrg# This program is distributed in the hope that it will be useful,
148fa80f29Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
158fa80f29Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
168fa80f29Smrg# GNU General Public License for more details.
178fa80f29Smrg
188fa80f29Smrg# You should have received a copy of the GNU General Public License
198fa80f29Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
208fa80f29Smrg
218fa80f29Smrg# As a special exception to the GNU General Public License, if you
228fa80f29Smrg# distribute this file as part of a program that contains a
238fa80f29Smrg# configuration script generated by Autoconf, you may include it under
248fa80f29Smrg# the same distribution terms that you use for the rest of that program.
258fa80f29Smrg
268fa80f29Smrg# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
278fa80f29Smrg
288fa80f29Smrgcase $1 in
298fa80f29Smrg  '')
308fa80f29Smrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
318fa80f29Smrg    exit 1;
328fa80f29Smrg    ;;
338fa80f29Smrg  -h | --h*)
348fa80f29Smrg    cat <<\EOF
358fa80f29SmrgUsage: depcomp [--help] [--version] PROGRAM [ARGS]
368fa80f29Smrg
378fa80f29SmrgRun PROGRAMS ARGS to compile a file, generating dependencies
388fa80f29Smrgas side-effects.
398fa80f29Smrg
408fa80f29SmrgEnvironment variables:
418fa80f29Smrg  depmode     Dependency tracking mode.
428fa80f29Smrg  source      Source file read by 'PROGRAMS ARGS'.
438fa80f29Smrg  object      Object file output by 'PROGRAMS ARGS'.
448fa80f29Smrg  DEPDIR      directory where to store dependencies.
458fa80f29Smrg  depfile     Dependency file to output.
468fa80f29Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
478fa80f29Smrg  libtool     Whether libtool is used (yes/no).
488fa80f29Smrg
498fa80f29SmrgReport bugs to <bug-automake@gnu.org>.
508fa80f29SmrgEOF
518fa80f29Smrg    exit $?
528fa80f29Smrg    ;;
538fa80f29Smrg  -v | --v*)
548fa80f29Smrg    echo "depcomp $scriptversion"
558fa80f29Smrg    exit $?
568fa80f29Smrg    ;;
578fa80f29Smrgesac
588fa80f29Smrg
59*062d2d48Smrg# Get the directory component of the given path, and save it in the
60*062d2d48Smrg# global variables '$dir'.  Note that this directory component will
61*062d2d48Smrg# be either empty or ending with a '/' character.  This is deliberate.
62*062d2d48Smrgset_dir_from ()
63*062d2d48Smrg{
64*062d2d48Smrg  case $1 in
65*062d2d48Smrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
66*062d2d48Smrg      *) dir=;;
67*062d2d48Smrg  esac
68*062d2d48Smrg}
69*062d2d48Smrg
70*062d2d48Smrg# Get the suffix-stripped basename of the given path, and save it the
71*062d2d48Smrg# global variable '$base'.
72*062d2d48Smrgset_base_from ()
73*062d2d48Smrg{
74*062d2d48Smrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
75*062d2d48Smrg}
76*062d2d48Smrg
77*062d2d48Smrg# If no dependency file was actually created by the compiler invocation,
78*062d2d48Smrg# we still have to create a dummy depfile, to avoid errors with the
79*062d2d48Smrg# Makefile "include basename.Plo" scheme.
80*062d2d48Smrgmake_dummy_depfile ()
81*062d2d48Smrg{
82*062d2d48Smrg  echo "#dummy" > "$depfile"
83*062d2d48Smrg}
84*062d2d48Smrg
85*062d2d48Smrg# Factor out some common post-processing of the generated depfile.
86*062d2d48Smrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
87*062d2d48Smrgaix_post_process_depfile ()
88*062d2d48Smrg{
89*062d2d48Smrg  # If the compiler actually managed to produce a dependency file,
90*062d2d48Smrg  # post-process it.
91*062d2d48Smrg  if test -f "$tmpdepfile"; then
92*062d2d48Smrg    # Each line is of the form 'foo.o: dependency.h'.
93*062d2d48Smrg    # Do two passes, one to just change these to
94*062d2d48Smrg    #   $object: dependency.h
95*062d2d48Smrg    # and one to simply output
96*062d2d48Smrg    #   dependency.h:
97*062d2d48Smrg    # which is needed to avoid the deleted-header problem.
98*062d2d48Smrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
99*062d2d48Smrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
100*062d2d48Smrg    } > "$depfile"
101*062d2d48Smrg    rm -f "$tmpdepfile"
102*062d2d48Smrg  else
103*062d2d48Smrg    make_dummy_depfile
104*062d2d48Smrg  fi
105*062d2d48Smrg}
106*062d2d48Smrg
1078fa80f29Smrg# A tabulation character.
1088fa80f29Smrgtab='	'
1098fa80f29Smrg# A newline character.
1108fa80f29Smrgnl='
1118fa80f29Smrg'
112*062d2d48Smrg# Character ranges might be problematic outside the C locale.
113*062d2d48Smrg# These definitions help.
114*062d2d48Smrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
115*062d2d48Smrglower=abcdefghijklmnopqrstuvwxyz
116*062d2d48Smrgdigits=0123456789
117*062d2d48Smrgalpha=${upper}${lower}
1188fa80f29Smrg
1198fa80f29Smrgif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1208fa80f29Smrg  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1218fa80f29Smrg  exit 1
1228fa80f29Smrgfi
1238fa80f29Smrg
1248fa80f29Smrg# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1258fa80f29Smrgdepfile=${depfile-`echo "$object" |
1268fa80f29Smrg  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1278fa80f29Smrgtmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1288fa80f29Smrg
1298fa80f29Smrgrm -f "$tmpdepfile"
1308fa80f29Smrg
131*062d2d48Smrg# Avoid interferences from the environment.
132*062d2d48Smrggccflag= dashmflag=
133*062d2d48Smrg
1348fa80f29Smrg# Some modes work just like other modes, but use different flags.  We
1358fa80f29Smrg# parameterize here, but still list the modes in the big case below,
1368fa80f29Smrg# to make depend.m4 easier to write.  Note that we *cannot* use a case
1378fa80f29Smrg# here, because this file can only contain one case statement.
1388fa80f29Smrgif test "$depmode" = hp; then
1398fa80f29Smrg  # HP compiler uses -M and no extra arg.
1408fa80f29Smrg  gccflag=-M
1418fa80f29Smrg  depmode=gcc
1428fa80f29Smrgfi
1438fa80f29Smrg
1448fa80f29Smrgif test "$depmode" = dashXmstdout; then
1458fa80f29Smrg  # This is just like dashmstdout with a different argument.
1468fa80f29Smrg  dashmflag=-xM
1478fa80f29Smrg  depmode=dashmstdout
1488fa80f29Smrgfi
1498fa80f29Smrg
1508fa80f29Smrgcygpath_u="cygpath -u -f -"
1518fa80f29Smrgif test "$depmode" = msvcmsys; then
1528fa80f29Smrg  # This is just like msvisualcpp but w/o cygpath translation.
1538fa80f29Smrg  # Just convert the backslash-escaped backslashes to single forward
1548fa80f29Smrg  # slashes to satisfy depend.m4
1558fa80f29Smrg  cygpath_u='sed s,\\\\,/,g'
1568fa80f29Smrg  depmode=msvisualcpp
1578fa80f29Smrgfi
1588fa80f29Smrg
1598fa80f29Smrgif test "$depmode" = msvc7msys; then
1608fa80f29Smrg  # This is just like msvc7 but w/o cygpath translation.
1618fa80f29Smrg  # Just convert the backslash-escaped backslashes to single forward
1628fa80f29Smrg  # slashes to satisfy depend.m4
1638fa80f29Smrg  cygpath_u='sed s,\\\\,/,g'
1648fa80f29Smrg  depmode=msvc7
1658fa80f29Smrgfi
1668fa80f29Smrg
1678fa80f29Smrgif test "$depmode" = xlc; then
168*062d2d48Smrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1698fa80f29Smrg  gccflag=-qmakedep=gcc,-MF
1708fa80f29Smrg  depmode=gcc
1718fa80f29Smrgfi
1728fa80f29Smrg
1738fa80f29Smrgcase "$depmode" in
1748fa80f29Smrggcc3)
1758fa80f29Smrg## gcc 3 implements dependency tracking that does exactly what
1768fa80f29Smrg## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1778fa80f29Smrg## it if -MD -MP comes after the -MF stuff.  Hmm.
1788fa80f29Smrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
1798fa80f29Smrg## the command line argument order; so add the flags where they
1808fa80f29Smrg## appear in depend2.am.  Note that the slowdown incurred here
1818fa80f29Smrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
1828fa80f29Smrg  for arg
1838fa80f29Smrg  do
1848fa80f29Smrg    case $arg in
1858fa80f29Smrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
1868fa80f29Smrg    *)  set fnord "$@" "$arg" ;;
1878fa80f29Smrg    esac
1888fa80f29Smrg    shift # fnord
1898fa80f29Smrg    shift # $arg
1908fa80f29Smrg  done
1918fa80f29Smrg  "$@"
1928fa80f29Smrg  stat=$?
193*062d2d48Smrg  if test $stat -ne 0; then
1948fa80f29Smrg    rm -f "$tmpdepfile"
1958fa80f29Smrg    exit $stat
1968fa80f29Smrg  fi
1978fa80f29Smrg  mv "$tmpdepfile" "$depfile"
1988fa80f29Smrg  ;;
1998fa80f29Smrg
2008fa80f29Smrggcc)
201*062d2d48Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202*062d2d48Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203*062d2d48Smrg## (see the conditional assignment to $gccflag above).
2048fa80f29Smrg## There are various ways to get dependency output from gcc.  Here's
2058fa80f29Smrg## why we pick this rather obscure method:
2068fa80f29Smrg## - Don't want to use -MD because we'd like the dependencies to end
2078fa80f29Smrg##   up in a subdir.  Having to rename by hand is ugly.
2088fa80f29Smrg##   (We might end up doing this anyway to support other compilers.)
2098fa80f29Smrg## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210*062d2d48Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211*062d2d48Smrg##   supported by the other compilers which use the 'gcc' depmode.
2128fa80f29Smrg## - Using -M directly means running the compiler twice (even worse
2138fa80f29Smrg##   than renaming).
2148fa80f29Smrg  if test -z "$gccflag"; then
2158fa80f29Smrg    gccflag=-MD,
2168fa80f29Smrg  fi
2178fa80f29Smrg  "$@" -Wp,"$gccflag$tmpdepfile"
2188fa80f29Smrg  stat=$?
219*062d2d48Smrg  if test $stat -ne 0; then
2208fa80f29Smrg    rm -f "$tmpdepfile"
2218fa80f29Smrg    exit $stat
2228fa80f29Smrg  fi
2238fa80f29Smrg  rm -f "$depfile"
2248fa80f29Smrg  echo "$object : \\" > "$depfile"
225*062d2d48Smrg  # The second -e expression handles DOS-style file names with drive
226*062d2d48Smrg  # letters.
2278fa80f29Smrg  sed -e 's/^[^:]*: / /' \
2288fa80f29Smrg      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2298fa80f29Smrg## This next piece of magic avoids the "deleted header file" problem.
2308fa80f29Smrg## The problem is that when a header file which appears in a .P file
2318fa80f29Smrg## is deleted, the dependency causes make to die (because there is
2328fa80f29Smrg## typically no way to rebuild the header).  We avoid this by adding
2338fa80f29Smrg## dummy dependencies for each header file.  Too bad gcc doesn't do
2348fa80f29Smrg## this for us directly.
2358fa80f29Smrg## Some versions of gcc put a space before the ':'.  On the theory
2368fa80f29Smrg## that the space means something, we add a space to the output as
2378fa80f29Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
2388fa80f29Smrg## to the object.  Take care to not repeat it in the output.
2398fa80f29Smrg## Some versions of the HPUX 10.20 sed can't process this invocation
2408fa80f29Smrg## correctly.  Breaking it into two sed invocations is a workaround.
241*062d2d48Smrg  tr ' ' "$nl" < "$tmpdepfile" \
242*062d2d48Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2438fa80f29Smrg    | sed -e 's/$/ :/' >> "$depfile"
2448fa80f29Smrg  rm -f "$tmpdepfile"
2458fa80f29Smrg  ;;
2468fa80f29Smrg
2478fa80f29Smrghp)
2488fa80f29Smrg  # This case exists only to let depend.m4 do its work.  It works by
2498fa80f29Smrg  # looking at the text of this script.  This case will never be run,
2508fa80f29Smrg  # since it is checked for above.
2518fa80f29Smrg  exit 1
2528fa80f29Smrg  ;;
2538fa80f29Smrg
2548fa80f29Smrgsgi)
2558fa80f29Smrg  if test "$libtool" = yes; then
2568fa80f29Smrg    "$@" "-Wp,-MDupdate,$tmpdepfile"
2578fa80f29Smrg  else
2588fa80f29Smrg    "$@" -MDupdate "$tmpdepfile"
2598fa80f29Smrg  fi
2608fa80f29Smrg  stat=$?
261*062d2d48Smrg  if test $stat -ne 0; then
2628fa80f29Smrg    rm -f "$tmpdepfile"
2638fa80f29Smrg    exit $stat
2648fa80f29Smrg  fi
2658fa80f29Smrg  rm -f "$depfile"
2668fa80f29Smrg
2678fa80f29Smrg  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2688fa80f29Smrg    echo "$object : \\" > "$depfile"
2698fa80f29Smrg    # Clip off the initial element (the dependent).  Don't try to be
2708fa80f29Smrg    # clever and replace this with sed code, as IRIX sed won't handle
2718fa80f29Smrg    # lines with more than a fixed number of characters (4096 in
2728fa80f29Smrg    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2738fa80f29Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
2748fa80f29Smrg    # dependency line.
2758fa80f29Smrg    tr ' ' "$nl" < "$tmpdepfile" \
276*062d2d48Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
277*062d2d48Smrg      | tr "$nl" ' ' >> "$depfile"
2788fa80f29Smrg    echo >> "$depfile"
2798fa80f29Smrg    # The second pass generates a dummy entry for each header file.
2808fa80f29Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2818fa80f29Smrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2828fa80f29Smrg      >> "$depfile"
2838fa80f29Smrg  else
284*062d2d48Smrg    make_dummy_depfile
2858fa80f29Smrg  fi
2868fa80f29Smrg  rm -f "$tmpdepfile"
2878fa80f29Smrg  ;;
2888fa80f29Smrg
2898fa80f29Smrgxlc)
2908fa80f29Smrg  # This case exists only to let depend.m4 do its work.  It works by
2918fa80f29Smrg  # looking at the text of this script.  This case will never be run,
2928fa80f29Smrg  # since it is checked for above.
2938fa80f29Smrg  exit 1
2948fa80f29Smrg  ;;
2958fa80f29Smrg
2968fa80f29Smrgaix)
2978fa80f29Smrg  # The C for AIX Compiler uses -M and outputs the dependencies
2988fa80f29Smrg  # in a .u file.  In older versions, this file always lives in the
2998fa80f29Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3008fa80f29Smrg  # start of each line; $object doesn't have directory information.
3018fa80f29Smrg  # Version 6 uses the directory in both cases.
302*062d2d48Smrg  set_dir_from "$object"
303*062d2d48Smrg  set_base_from "$object"
3048fa80f29Smrg  if test "$libtool" = yes; then
3058fa80f29Smrg    tmpdepfile1=$dir$base.u
3068fa80f29Smrg    tmpdepfile2=$base.u
3078fa80f29Smrg    tmpdepfile3=$dir.libs/$base.u
3088fa80f29Smrg    "$@" -Wc,-M
3098fa80f29Smrg  else
3108fa80f29Smrg    tmpdepfile1=$dir$base.u
3118fa80f29Smrg    tmpdepfile2=$dir$base.u
3128fa80f29Smrg    tmpdepfile3=$dir$base.u
3138fa80f29Smrg    "$@" -M
3148fa80f29Smrg  fi
3158fa80f29Smrg  stat=$?
316*062d2d48Smrg  if test $stat -ne 0; then
3178fa80f29Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3188fa80f29Smrg    exit $stat
3198fa80f29Smrg  fi
3208fa80f29Smrg
3218fa80f29Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3228fa80f29Smrg  do
3238fa80f29Smrg    test -f "$tmpdepfile" && break
3248fa80f29Smrg  done
325*062d2d48Smrg  aix_post_process_depfile
326*062d2d48Smrg  ;;
327*062d2d48Smrg
328*062d2d48Smrgtcc)
329*062d2d48Smrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
330*062d2d48Smrg  # FIXME: That version still under development at the moment of writing.
331*062d2d48Smrg  #        Make that this statement remains true also for stable, released
332*062d2d48Smrg  #        versions.
333*062d2d48Smrg  # It will wrap lines (doesn't matter whether long or short) with a
334*062d2d48Smrg  # trailing '\', as in:
335*062d2d48Smrg  #
336*062d2d48Smrg  #   foo.o : \
337*062d2d48Smrg  #    foo.c \
338*062d2d48Smrg  #    foo.h \
339*062d2d48Smrg  #
340*062d2d48Smrg  # It will put a trailing '\' even on the last line, and will use leading
341*062d2d48Smrg  # spaces rather than leading tabs (at least since its commit 0394caf7
342*062d2d48Smrg  # "Emit spaces for -MD").
343*062d2d48Smrg  "$@" -MD -MF "$tmpdepfile"
344*062d2d48Smrg  stat=$?
345*062d2d48Smrg  if test $stat -ne 0; then
346*062d2d48Smrg    rm -f "$tmpdepfile"
347*062d2d48Smrg    exit $stat
3488fa80f29Smrg  fi
349*062d2d48Smrg  rm -f "$depfile"
350*062d2d48Smrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
351*062d2d48Smrg  # We have to change lines of the first kind to '$object: \'.
352*062d2d48Smrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
353*062d2d48Smrg  # And for each line of the second kind, we have to emit a 'dep.h:'
354*062d2d48Smrg  # dummy dependency, to avoid the deleted-header problem.
355*062d2d48Smrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
3568fa80f29Smrg  rm -f "$tmpdepfile"
3578fa80f29Smrg  ;;
3588fa80f29Smrg
359*062d2d48Smrg## The order of this option in the case statement is important, since the
360*062d2d48Smrg## shell code in configure will try each of these formats in the order
361*062d2d48Smrg## listed in this file.  A plain '-MD' option would be understood by many
362*062d2d48Smrg## compilers, so we must ensure this comes after the gcc and icc options.
363*062d2d48Smrgpgcc)
364*062d2d48Smrg  # Portland's C compiler understands '-MD'.
365*062d2d48Smrg  # Will always output deps to 'file.d' where file is the root name of the
366*062d2d48Smrg  # source file under compilation, even if file resides in a subdirectory.
367*062d2d48Smrg  # The object file name does not affect the name of the '.d' file.
368*062d2d48Smrg  # pgcc 10.2 will output
3698fa80f29Smrg  #    foo.o: sub/foo.c sub/foo.h
3708fa80f29Smrg  # and will wrap long lines using '\' :
3718fa80f29Smrg  #    foo.o: sub/foo.c ... \
3728fa80f29Smrg  #     sub/foo.h ... \
3738fa80f29Smrg  #     ...
374*062d2d48Smrg  set_dir_from "$object"
375*062d2d48Smrg  # Use the source, not the object, to determine the base name, since
376*062d2d48Smrg  # that's sadly what pgcc will do too.
377*062d2d48Smrg  set_base_from "$source"
378*062d2d48Smrg  tmpdepfile=$base.d
379*062d2d48Smrg
380*062d2d48Smrg  # For projects that build the same source file twice into different object
381*062d2d48Smrg  # files, the pgcc approach of using the *source* file root name can cause
382*062d2d48Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383*062d2d48Smrg  # the same $tmpdepfile.
384*062d2d48Smrg  lockdir=$base.d-lock
385*062d2d48Smrg  trap "
386*062d2d48Smrg    echo '$0: caught signal, cleaning up...' >&2
387*062d2d48Smrg    rmdir '$lockdir'
388*062d2d48Smrg    exit 1
389*062d2d48Smrg  " 1 2 13 15
390*062d2d48Smrg  numtries=100
391*062d2d48Smrg  i=$numtries
392*062d2d48Smrg  while test $i -gt 0; do
393*062d2d48Smrg    # mkdir is a portable test-and-set.
394*062d2d48Smrg    if mkdir "$lockdir" 2>/dev/null; then
395*062d2d48Smrg      # This process acquired the lock.
396*062d2d48Smrg      "$@" -MD
3978fa80f29Smrg      stat=$?
398*062d2d48Smrg      # Release the lock.
399*062d2d48Smrg      rmdir "$lockdir"
400*062d2d48Smrg      break
4018fa80f29Smrg    else
402*062d2d48Smrg      # If the lock is being held by a different process, wait
403*062d2d48Smrg      # until the winning process is done or we timeout.
404*062d2d48Smrg      while test -d "$lockdir" && test $i -gt 0; do
405*062d2d48Smrg        sleep 1
406*062d2d48Smrg        i=`expr $i - 1`
407*062d2d48Smrg      done
408*062d2d48Smrg    fi
409*062d2d48Smrg    i=`expr $i - 1`
410*062d2d48Smrg  done
411*062d2d48Smrg  trap - 1 2 13 15
412*062d2d48Smrg  if test $i -le 0; then
413*062d2d48Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414*062d2d48Smrg    echo "$0: check lockdir '$lockdir'" >&2
415*062d2d48Smrg    exit 1
416*062d2d48Smrg  fi
417*062d2d48Smrg
418*062d2d48Smrg  if test $stat -ne 0; then
4198fa80f29Smrg    rm -f "$tmpdepfile"
4208fa80f29Smrg    exit $stat
4218fa80f29Smrg  fi
4228fa80f29Smrg  rm -f "$depfile"
423*062d2d48Smrg  # Each line is of the form `foo.o: dependent.h',
424*062d2d48Smrg  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4258fa80f29Smrg  # Do two passes, one to just change these to
426*062d2d48Smrg  # `$object: dependent.h' and one to simply `dependent.h:'.
427*062d2d48Smrg  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
428*062d2d48Smrg  # Some versions of the HPUX 10.20 sed can't process this invocation
429*062d2d48Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
430*062d2d48Smrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
431*062d2d48Smrg    | sed -e 's/$/ :/' >> "$depfile"
4328fa80f29Smrg  rm -f "$tmpdepfile"
4338fa80f29Smrg  ;;
4348fa80f29Smrg
4358fa80f29Smrghp2)
4368fa80f29Smrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
4378fa80f29Smrg  # compilers, which have integrated preprocessors.  The correct option
4388fa80f29Smrg  # to use with these is +Maked; it writes dependencies to a file named
4398fa80f29Smrg  # 'foo.d', which lands next to the object file, wherever that
4408fa80f29Smrg  # happens to be.
4418fa80f29Smrg  # Much of this is similar to the tru64 case; see comments there.
442*062d2d48Smrg  set_dir_from  "$object"
443*062d2d48Smrg  set_base_from "$object"
4448fa80f29Smrg  if test "$libtool" = yes; then
4458fa80f29Smrg    tmpdepfile1=$dir$base.d
4468fa80f29Smrg    tmpdepfile2=$dir.libs/$base.d
4478fa80f29Smrg    "$@" -Wc,+Maked
4488fa80f29Smrg  else
4498fa80f29Smrg    tmpdepfile1=$dir$base.d
4508fa80f29Smrg    tmpdepfile2=$dir$base.d
4518fa80f29Smrg    "$@" +Maked
4528fa80f29Smrg  fi
4538fa80f29Smrg  stat=$?
454*062d2d48Smrg  if test $stat -ne 0; then
4558fa80f29Smrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
4568fa80f29Smrg     exit $stat
4578fa80f29Smrg  fi
4588fa80f29Smrg
4598fa80f29Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
4608fa80f29Smrg  do
4618fa80f29Smrg    test -f "$tmpdepfile" && break
4628fa80f29Smrg  done
4638fa80f29Smrg  if test -f "$tmpdepfile"; then
464*062d2d48Smrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4658fa80f29Smrg    # Add 'dependent.h:' lines.
4668fa80f29Smrg    sed -ne '2,${
4678fa80f29Smrg               s/^ *//
4688fa80f29Smrg               s/ \\*$//
4698fa80f29Smrg               s/$/:/
4708fa80f29Smrg               p
4718fa80f29Smrg             }' "$tmpdepfile" >> "$depfile"
4728fa80f29Smrg  else
473*062d2d48Smrg    make_dummy_depfile
4748fa80f29Smrg  fi
4758fa80f29Smrg  rm -f "$tmpdepfile" "$tmpdepfile2"
4768fa80f29Smrg  ;;
4778fa80f29Smrg
4788fa80f29Smrgtru64)
4798fa80f29Smrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4808fa80f29Smrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4818fa80f29Smrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4828fa80f29Smrg  # dependencies in 'foo.d' instead, so we check for that too.
4838fa80f29Smrg  # Subdirectories are respected.
484*062d2d48Smrg  set_dir_from  "$object"
485*062d2d48Smrg  set_base_from "$object"
4868fa80f29Smrg
4878fa80f29Smrg  if test "$libtool" = yes; then
488*062d2d48Smrg    # Libtool generates 2 separate objects for the 2 libraries.  These
489*062d2d48Smrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4908fa80f29Smrg    # in $dir$base.o.d.  We have to check for both files, because
4918fa80f29Smrg    # one of the two compilations can be disabled.  We should prefer
4928fa80f29Smrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4938fa80f29Smrg    # automatically cleaned when .libs/ is deleted, while ignoring
4948fa80f29Smrg    # the former would cause a distcleancheck panic.
495*062d2d48Smrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
496*062d2d48Smrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
497*062d2d48Smrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4988fa80f29Smrg    "$@" -Wc,-MD
4998fa80f29Smrg  else
500*062d2d48Smrg    tmpdepfile1=$dir$base.d
5018fa80f29Smrg    tmpdepfile2=$dir$base.d
5028fa80f29Smrg    tmpdepfile3=$dir$base.d
5038fa80f29Smrg    "$@" -MD
5048fa80f29Smrg  fi
5058fa80f29Smrg
5068fa80f29Smrg  stat=$?
507*062d2d48Smrg  if test $stat -ne 0; then
508*062d2d48Smrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5098fa80f29Smrg    exit $stat
5108fa80f29Smrg  fi
5118fa80f29Smrg
512*062d2d48Smrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5138fa80f29Smrg  do
5148fa80f29Smrg    test -f "$tmpdepfile" && break
5158fa80f29Smrg  done
516*062d2d48Smrg  # Same post-processing that is required for AIX mode.
517*062d2d48Smrg  aix_post_process_depfile
5188fa80f29Smrg  ;;
5198fa80f29Smrg
5208fa80f29Smrgmsvc7)
5218fa80f29Smrg  if test "$libtool" = yes; then
5228fa80f29Smrg    showIncludes=-Wc,-showIncludes
5238fa80f29Smrg  else
5248fa80f29Smrg    showIncludes=-showIncludes
5258fa80f29Smrg  fi
5268fa80f29Smrg  "$@" $showIncludes > "$tmpdepfile"
5278fa80f29Smrg  stat=$?
5288fa80f29Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
529*062d2d48Smrg  if test $stat -ne 0; then
5308fa80f29Smrg    rm -f "$tmpdepfile"
5318fa80f29Smrg    exit $stat
5328fa80f29Smrg  fi
5338fa80f29Smrg  rm -f "$depfile"
5348fa80f29Smrg  echo "$object : \\" > "$depfile"
5358fa80f29Smrg  # The first sed program below extracts the file names and escapes
5368fa80f29Smrg  # backslashes for cygpath.  The second sed program outputs the file
5378fa80f29Smrg  # name when reading, but also accumulates all include files in the
5388fa80f29Smrg  # hold buffer in order to output them again at the end.  This only
5398fa80f29Smrg  # works with sed implementations that can handle large buffers.
5408fa80f29Smrg  sed < "$tmpdepfile" -n '
5418fa80f29Smrg/^Note: including file:  *\(.*\)/ {
5428fa80f29Smrg  s//\1/
5438fa80f29Smrg  s/\\/\\\\/g
5448fa80f29Smrg  p
5458fa80f29Smrg}' | $cygpath_u | sort -u | sed -n '
5468fa80f29Smrgs/ /\\ /g
5478fa80f29Smrgs/\(.*\)/'"$tab"'\1 \\/p
5488fa80f29Smrgs/.\(.*\) \\/\1:/
5498fa80f29SmrgH
5508fa80f29Smrg$ {
5518fa80f29Smrg  s/.*/'"$tab"'/
5528fa80f29Smrg  G
5538fa80f29Smrg  p
5548fa80f29Smrg}' >> "$depfile"
555*062d2d48Smrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5568fa80f29Smrg  rm -f "$tmpdepfile"
5578fa80f29Smrg  ;;
5588fa80f29Smrg
5598fa80f29Smrgmsvc7msys)
5608fa80f29Smrg  # This case exists only to let depend.m4 do its work.  It works by
5618fa80f29Smrg  # looking at the text of this script.  This case will never be run,
5628fa80f29Smrg  # since it is checked for above.
5638fa80f29Smrg  exit 1
5648fa80f29Smrg  ;;
5658fa80f29Smrg
5668fa80f29Smrg#nosideeffect)
5678fa80f29Smrg  # This comment above is used by automake to tell side-effect
5688fa80f29Smrg  # dependency tracking mechanisms from slower ones.
5698fa80f29Smrg
5708fa80f29Smrgdashmstdout)
5718fa80f29Smrg  # Important note: in order to support this mode, a compiler *must*
5728fa80f29Smrg  # always write the preprocessed file to stdout, regardless of -o.
5738fa80f29Smrg  "$@" || exit $?
5748fa80f29Smrg
5758fa80f29Smrg  # Remove the call to Libtool.
5768fa80f29Smrg  if test "$libtool" = yes; then
5778fa80f29Smrg    while test "X$1" != 'X--mode=compile'; do
5788fa80f29Smrg      shift
5798fa80f29Smrg    done
5808fa80f29Smrg    shift
5818fa80f29Smrg  fi
5828fa80f29Smrg
5838fa80f29Smrg  # Remove '-o $object'.
5848fa80f29Smrg  IFS=" "
5858fa80f29Smrg  for arg
5868fa80f29Smrg  do
5878fa80f29Smrg    case $arg in
5888fa80f29Smrg    -o)
5898fa80f29Smrg      shift
5908fa80f29Smrg      ;;
5918fa80f29Smrg    $object)
5928fa80f29Smrg      shift
5938fa80f29Smrg      ;;
5948fa80f29Smrg    *)
5958fa80f29Smrg      set fnord "$@" "$arg"
5968fa80f29Smrg      shift # fnord
5978fa80f29Smrg      shift # $arg
5988fa80f29Smrg      ;;
5998fa80f29Smrg    esac
6008fa80f29Smrg  done
6018fa80f29Smrg
6028fa80f29Smrg  test -z "$dashmflag" && dashmflag=-M
6038fa80f29Smrg  # Require at least two characters before searching for ':'
6048fa80f29Smrg  # in the target name.  This is to cope with DOS-style filenames:
6058fa80f29Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6068fa80f29Smrg  "$@" $dashmflag |
607*062d2d48Smrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6088fa80f29Smrg  rm -f "$depfile"
6098fa80f29Smrg  cat < "$tmpdepfile" > "$depfile"
610*062d2d48Smrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
611*062d2d48Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
612*062d2d48Smrg  tr ' ' "$nl" < "$tmpdepfile" \
613*062d2d48Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
614*062d2d48Smrg    | sed -e 's/$/ :/' >> "$depfile"
6158fa80f29Smrg  rm -f "$tmpdepfile"
6168fa80f29Smrg  ;;
6178fa80f29Smrg
6188fa80f29SmrgdashXmstdout)
6198fa80f29Smrg  # This case only exists to satisfy depend.m4.  It is never actually
6208fa80f29Smrg  # run, as this mode is specially recognized in the preamble.
6218fa80f29Smrg  exit 1
6228fa80f29Smrg  ;;
6238fa80f29Smrg
6248fa80f29Smrgmakedepend)
6258fa80f29Smrg  "$@" || exit $?
6268fa80f29Smrg  # Remove any Libtool call
6278fa80f29Smrg  if test "$libtool" = yes; then
6288fa80f29Smrg    while test "X$1" != 'X--mode=compile'; do
6298fa80f29Smrg      shift
6308fa80f29Smrg    done
6318fa80f29Smrg    shift
6328fa80f29Smrg  fi
6338fa80f29Smrg  # X makedepend
6348fa80f29Smrg  shift
6358fa80f29Smrg  cleared=no eat=no
6368fa80f29Smrg  for arg
6378fa80f29Smrg  do
6388fa80f29Smrg    case $cleared in
6398fa80f29Smrg    no)
6408fa80f29Smrg      set ""; shift
6418fa80f29Smrg      cleared=yes ;;
6428fa80f29Smrg    esac
6438fa80f29Smrg    if test $eat = yes; then
6448fa80f29Smrg      eat=no
6458fa80f29Smrg      continue
6468fa80f29Smrg    fi
6478fa80f29Smrg    case "$arg" in
6488fa80f29Smrg    -D*|-I*)
6498fa80f29Smrg      set fnord "$@" "$arg"; shift ;;
6508fa80f29Smrg    # Strip any option that makedepend may not understand.  Remove
6518fa80f29Smrg    # the object too, otherwise makedepend will parse it as a source file.
6528fa80f29Smrg    -arch)
6538fa80f29Smrg      eat=yes ;;
6548fa80f29Smrg    -*|$object)
6558fa80f29Smrg      ;;
6568fa80f29Smrg    *)
6578fa80f29Smrg      set fnord "$@" "$arg"; shift ;;
6588fa80f29Smrg    esac
6598fa80f29Smrg  done
6608fa80f29Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6618fa80f29Smrg  touch "$tmpdepfile"
6628fa80f29Smrg  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6638fa80f29Smrg  rm -f "$depfile"
6648fa80f29Smrg  # makedepend may prepend the VPATH from the source file name to the object.
6658fa80f29Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
6668fa80f29Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
667*062d2d48Smrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
668*062d2d48Smrg  # correctly.  Breaking it into two sed invocations is a workaround.
669*062d2d48Smrg  sed '1,2d' "$tmpdepfile" \
670*062d2d48Smrg    | tr ' ' "$nl" \
671*062d2d48Smrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
672*062d2d48Smrg    | sed -e 's/$/ :/' >> "$depfile"
6738fa80f29Smrg  rm -f "$tmpdepfile" "$tmpdepfile".bak
6748fa80f29Smrg  ;;
6758fa80f29Smrg
6768fa80f29Smrgcpp)
6778fa80f29Smrg  # Important note: in order to support this mode, a compiler *must*
6788fa80f29Smrg  # always write the preprocessed file to stdout.
6798fa80f29Smrg  "$@" || exit $?
6808fa80f29Smrg
6818fa80f29Smrg  # Remove the call to Libtool.
6828fa80f29Smrg  if test "$libtool" = yes; then
6838fa80f29Smrg    while test "X$1" != 'X--mode=compile'; do
6848fa80f29Smrg      shift
6858fa80f29Smrg    done
6868fa80f29Smrg    shift
6878fa80f29Smrg  fi
6888fa80f29Smrg
6898fa80f29Smrg  # Remove '-o $object'.
6908fa80f29Smrg  IFS=" "
6918fa80f29Smrg  for arg
6928fa80f29Smrg  do
6938fa80f29Smrg    case $arg in
6948fa80f29Smrg    -o)
6958fa80f29Smrg      shift
6968fa80f29Smrg      ;;
6978fa80f29Smrg    $object)
6988fa80f29Smrg      shift
6998fa80f29Smrg      ;;
7008fa80f29Smrg    *)
7018fa80f29Smrg      set fnord "$@" "$arg"
7028fa80f29Smrg      shift # fnord
7038fa80f29Smrg      shift # $arg
7048fa80f29Smrg      ;;
7058fa80f29Smrg    esac
7068fa80f29Smrg  done
7078fa80f29Smrg
708*062d2d48Smrg  "$@" -E \
709*062d2d48Smrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710*062d2d48Smrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
711*062d2d48Smrg    | sed '$ s: \\$::' > "$tmpdepfile"
7128fa80f29Smrg  rm -f "$depfile"
7138fa80f29Smrg  echo "$object : \\" > "$depfile"
7148fa80f29Smrg  cat < "$tmpdepfile" >> "$depfile"
7158fa80f29Smrg  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7168fa80f29Smrg  rm -f "$tmpdepfile"
7178fa80f29Smrg  ;;
7188fa80f29Smrg
7198fa80f29Smrgmsvisualcpp)
7208fa80f29Smrg  # Important note: in order to support this mode, a compiler *must*
7218fa80f29Smrg  # always write the preprocessed file to stdout.
7228fa80f29Smrg  "$@" || exit $?
7238fa80f29Smrg
7248fa80f29Smrg  # Remove the call to Libtool.
7258fa80f29Smrg  if test "$libtool" = yes; then
7268fa80f29Smrg    while test "X$1" != 'X--mode=compile'; do
7278fa80f29Smrg      shift
7288fa80f29Smrg    done
7298fa80f29Smrg    shift
7308fa80f29Smrg  fi
7318fa80f29Smrg
7328fa80f29Smrg  IFS=" "
7338fa80f29Smrg  for arg
7348fa80f29Smrg  do
7358fa80f29Smrg    case "$arg" in
7368fa80f29Smrg    -o)
7378fa80f29Smrg      shift
7388fa80f29Smrg      ;;
7398fa80f29Smrg    $object)
7408fa80f29Smrg      shift
7418fa80f29Smrg      ;;
7428fa80f29Smrg    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7438fa80f29Smrg        set fnord "$@"
7448fa80f29Smrg        shift
7458fa80f29Smrg        shift
7468fa80f29Smrg        ;;
7478fa80f29Smrg    *)
7488fa80f29Smrg        set fnord "$@" "$arg"
7498fa80f29Smrg        shift
7508fa80f29Smrg        shift
7518fa80f29Smrg        ;;
7528fa80f29Smrg    esac
7538fa80f29Smrg  done
7548fa80f29Smrg  "$@" -E 2>/dev/null |
7558fa80f29Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7568fa80f29Smrg  rm -f "$depfile"
7578fa80f29Smrg  echo "$object : \\" > "$depfile"
7588fa80f29Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7598fa80f29Smrg  echo "$tab" >> "$depfile"
7608fa80f29Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7618fa80f29Smrg  rm -f "$tmpdepfile"
7628fa80f29Smrg  ;;
7638fa80f29Smrg
7648fa80f29Smrgmsvcmsys)
7658fa80f29Smrg  # This case exists only to let depend.m4 do its work.  It works by
7668fa80f29Smrg  # looking at the text of this script.  This case will never be run,
7678fa80f29Smrg  # since it is checked for above.
7688fa80f29Smrg  exit 1
7698fa80f29Smrg  ;;
7708fa80f29Smrg
7718fa80f29Smrgnone)
7728fa80f29Smrg  exec "$@"
7738fa80f29Smrg  ;;
7748fa80f29Smrg
7758fa80f29Smrg*)
7768fa80f29Smrg  echo "Unknown depmode $depmode" 1>&2
7778fa80f29Smrg  exit 1
7788fa80f29Smrg  ;;
7798fa80f29Smrgesac
7808fa80f29Smrg
7818fa80f29Smrgexit 0
7828fa80f29Smrg
7838fa80f29Smrg# Local Variables:
7848fa80f29Smrg# mode: shell-script
7858fa80f29Smrg# sh-indentation: 2
7868fa80f29Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
7878fa80f29Smrg# time-stamp-start: "scriptversion="
7888fa80f29Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
7898fa80f29Smrg# time-stamp-time-zone: "UTC"
7908fa80f29Smrg# time-stamp-end: "; # UTC"
7918fa80f29Smrg# End:
792