15eefee25Smacallan#! /bin/sh
25eefee25Smacallan# depcomp - compile a program generating dependencies as side-effects
35eefee25Smacallan
45c30ecadSmrgscriptversion=2018-03-07.03; # UTC
55eefee25Smacallan
65c30ecadSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
75eefee25Smacallan
85eefee25Smacallan# This program is free software; you can redistribute it and/or modify
95eefee25Smacallan# it under the terms of the GNU General Public License as published by
105eefee25Smacallan# the Free Software Foundation; either version 2, or (at your option)
115eefee25Smacallan# any later version.
125eefee25Smacallan
135eefee25Smacallan# This program is distributed in the hope that it will be useful,
145eefee25Smacallan# but WITHOUT ANY WARRANTY; without even the implied warranty of
155eefee25Smacallan# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
165eefee25Smacallan# GNU General Public License for more details.
175eefee25Smacallan
185eefee25Smacallan# You should have received a copy of the GNU General Public License
195c30ecadSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
205eefee25Smacallan
215eefee25Smacallan# As a special exception to the GNU General Public License, if you
225eefee25Smacallan# distribute this file as part of a program that contains a
235eefee25Smacallan# configuration script generated by Autoconf, you may include it under
245eefee25Smacallan# the same distribution terms that you use for the rest of that program.
255eefee25Smacallan
265eefee25Smacallan# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
275eefee25Smacallan
285eefee25Smacallancase $1 in
295eefee25Smacallan  '')
305c30ecadSmrg    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
315c30ecadSmrg    exit 1;
325c30ecadSmrg    ;;
335eefee25Smacallan  -h | --h*)
345eefee25Smacallan    cat <<\EOF
355eefee25SmacallanUsage: depcomp [--help] [--version] PROGRAM [ARGS]
365eefee25Smacallan
375eefee25SmacallanRun PROGRAMS ARGS to compile a file, generating dependencies
385eefee25Smacallanas side-effects.
395eefee25Smacallan
405eefee25SmacallanEnvironment variables:
415eefee25Smacallan  depmode     Dependency tracking mode.
42dc99b369Smrg  source      Source file read by 'PROGRAMS ARGS'.
43dc99b369Smrg  object      Object file output by 'PROGRAMS ARGS'.
445eefee25Smacallan  DEPDIR      directory where to store dependencies.
455eefee25Smacallan  depfile     Dependency file to output.
46dc99b369Smrg  tmpdepfile  Temporary file to use when outputting dependencies.
475eefee25Smacallan  libtool     Whether libtool is used (yes/no).
485eefee25Smacallan
495eefee25SmacallanReport bugs to <bug-automake@gnu.org>.
505eefee25SmacallanEOF
515eefee25Smacallan    exit $?
525eefee25Smacallan    ;;
535eefee25Smacallan  -v | --v*)
545eefee25Smacallan    echo "depcomp $scriptversion"
555eefee25Smacallan    exit $?
565eefee25Smacallan    ;;
575eefee25Smacallanesac
585eefee25Smacallan
595c30ecadSmrg# Get the directory component of the given path, and save it in the
605c30ecadSmrg# global variables '$dir'.  Note that this directory component will
615c30ecadSmrg# be either empty or ending with a '/' character.  This is deliberate.
625c30ecadSmrgset_dir_from ()
635c30ecadSmrg{
645c30ecadSmrg  case $1 in
655c30ecadSmrg    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
665c30ecadSmrg      *) dir=;;
675c30ecadSmrg  esac
685c30ecadSmrg}
695c30ecadSmrg
705c30ecadSmrg# Get the suffix-stripped basename of the given path, and save it the
715c30ecadSmrg# global variable '$base'.
725c30ecadSmrgset_base_from ()
735c30ecadSmrg{
745c30ecadSmrg  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
755c30ecadSmrg}
765c30ecadSmrg
775c30ecadSmrg# If no dependency file was actually created by the compiler invocation,
785c30ecadSmrg# we still have to create a dummy depfile, to avoid errors with the
795c30ecadSmrg# Makefile "include basename.Plo" scheme.
805c30ecadSmrgmake_dummy_depfile ()
815c30ecadSmrg{
825c30ecadSmrg  echo "#dummy" > "$depfile"
835c30ecadSmrg}
845c30ecadSmrg
855c30ecadSmrg# Factor out some common post-processing of the generated depfile.
865c30ecadSmrg# Requires the auxiliary global variable '$tmpdepfile' to be set.
875c30ecadSmrgaix_post_process_depfile ()
885c30ecadSmrg{
895c30ecadSmrg  # If the compiler actually managed to produce a dependency file,
905c30ecadSmrg  # post-process it.
915c30ecadSmrg  if test -f "$tmpdepfile"; then
925c30ecadSmrg    # Each line is of the form 'foo.o: dependency.h'.
935c30ecadSmrg    # Do two passes, one to just change these to
945c30ecadSmrg    #   $object: dependency.h
955c30ecadSmrg    # and one to simply output
965c30ecadSmrg    #   dependency.h:
975c30ecadSmrg    # which is needed to avoid the deleted-header problem.
985c30ecadSmrg    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
995c30ecadSmrg      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1005c30ecadSmrg    } > "$depfile"
1015c30ecadSmrg    rm -f "$tmpdepfile"
1025c30ecadSmrg  else
1035c30ecadSmrg    make_dummy_depfile
1045c30ecadSmrg  fi
1055c30ecadSmrg}
1065c30ecadSmrg
107dc99b369Smrg# A tabulation character.
108dc99b369Smrgtab='	'
109dc99b369Smrg# A newline character.
110dc99b369Smrgnl='
111dc99b369Smrg'
1125c30ecadSmrg# Character ranges might be problematic outside the C locale.
1135c30ecadSmrg# These definitions help.
1145c30ecadSmrgupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1155c30ecadSmrglower=abcdefghijklmnopqrstuvwxyz
1165c30ecadSmrgdigits=0123456789
1175c30ecadSmrgalpha=${upper}${lower}
118dc99b369Smrg
1195eefee25Smacallanif test -z "$depmode" || test -z "$source" || test -z "$object"; then
1205eefee25Smacallan  echo "depcomp: Variables source, object and depmode must be set" 1>&2
1215eefee25Smacallan  exit 1
1225eefee25Smacallanfi
1235eefee25Smacallan
1245eefee25Smacallan# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
1255eefee25Smacallandepfile=${depfile-`echo "$object" |
1265eefee25Smacallan  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
1275eefee25Smacallantmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
1285eefee25Smacallan
1295eefee25Smacallanrm -f "$tmpdepfile"
1305eefee25Smacallan
131dc99b369Smrg# Avoid interferences from the environment.
132dc99b369Smrggccflag= dashmflag=
133dc99b369Smrg
1345eefee25Smacallan# Some modes work just like other modes, but use different flags.  We
1355eefee25Smacallan# parameterize here, but still list the modes in the big case below,
1365eefee25Smacallan# to make depend.m4 easier to write.  Note that we *cannot* use a case
1375eefee25Smacallan# here, because this file can only contain one case statement.
1385eefee25Smacallanif test "$depmode" = hp; then
1395eefee25Smacallan  # HP compiler uses -M and no extra arg.
1405eefee25Smacallan  gccflag=-M
1415eefee25Smacallan  depmode=gcc
1425eefee25Smacallanfi
1435eefee25Smacallan
1445eefee25Smacallanif test "$depmode" = dashXmstdout; then
1455c30ecadSmrg  # This is just like dashmstdout with a different argument.
1465c30ecadSmrg  dashmflag=-xM
1475c30ecadSmrg  depmode=dashmstdout
1485eefee25Smacallanfi
1495eefee25Smacallan
150dc99b369Smrgcygpath_u="cygpath -u -f -"
151dc99b369Smrgif test "$depmode" = msvcmsys; then
1525c30ecadSmrg  # This is just like msvisualcpp but w/o cygpath translation.
1535c30ecadSmrg  # Just convert the backslash-escaped backslashes to single forward
1545c30ecadSmrg  # slashes to satisfy depend.m4
1555c30ecadSmrg  cygpath_u='sed s,\\\\,/,g'
1565c30ecadSmrg  depmode=msvisualcpp
157dc99b369Smrgfi
158dc99b369Smrg
159dc99b369Smrgif test "$depmode" = msvc7msys; then
1605c30ecadSmrg  # This is just like msvc7 but w/o cygpath translation.
1615c30ecadSmrg  # Just convert the backslash-escaped backslashes to single forward
1625c30ecadSmrg  # slashes to satisfy depend.m4
1635c30ecadSmrg  cygpath_u='sed s,\\\\,/,g'
1645c30ecadSmrg  depmode=msvc7
165dc99b369Smrgfi
166dc99b369Smrg
167dc99b369Smrgif test "$depmode" = xlc; then
1685c30ecadSmrg  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1695c30ecadSmrg  gccflag=-qmakedep=gcc,-MF
1705c30ecadSmrg  depmode=gcc
171dc99b369Smrgfi
172dc99b369Smrg
1735eefee25Smacallancase "$depmode" in
1745eefee25Smacallangcc3)
1755eefee25Smacallan## gcc 3 implements dependency tracking that does exactly what
1765eefee25Smacallan## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
1775eefee25Smacallan## it if -MD -MP comes after the -MF stuff.  Hmm.
17862ab96baSmrg## Unfortunately, FreeBSD c89 acceptance of flags depends upon
17962ab96baSmrg## the command line argument order; so add the flags where they
18062ab96baSmrg## appear in depend2.am.  Note that the slowdown incurred here
18162ab96baSmrg## affects only configure: in makefiles, %FASTDEP% shortcuts this.
18262ab96baSmrg  for arg
18362ab96baSmrg  do
18462ab96baSmrg    case $arg in
18562ab96baSmrg    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
18662ab96baSmrg    *)  set fnord "$@" "$arg" ;;
18762ab96baSmrg    esac
18862ab96baSmrg    shift # fnord
18962ab96baSmrg    shift # $arg
19062ab96baSmrg  done
19162ab96baSmrg  "$@"
1925eefee25Smacallan  stat=$?
1935c30ecadSmrg  if test $stat -ne 0; then
1945eefee25Smacallan    rm -f "$tmpdepfile"
1955eefee25Smacallan    exit $stat
1965eefee25Smacallan  fi
1975eefee25Smacallan  mv "$tmpdepfile" "$depfile"
1985eefee25Smacallan  ;;
1995eefee25Smacallan
2005eefee25Smacallangcc)
201dc99b369Smrg## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
202dc99b369Smrg## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
203dc99b369Smrg## (see the conditional assignment to $gccflag above).
2045eefee25Smacallan## There are various ways to get dependency output from gcc.  Here's
2055eefee25Smacallan## why we pick this rather obscure method:
2065eefee25Smacallan## - Don't want to use -MD because we'd like the dependencies to end
2075eefee25Smacallan##   up in a subdir.  Having to rename by hand is ugly.
2085eefee25Smacallan##   (We might end up doing this anyway to support other compilers.)
2095eefee25Smacallan## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
210dc99b369Smrg##   -MM, not -M (despite what the docs say).  Also, it might not be
211dc99b369Smrg##   supported by the other compilers which use the 'gcc' depmode.
2125eefee25Smacallan## - Using -M directly means running the compiler twice (even worse
2135eefee25Smacallan##   than renaming).
2145eefee25Smacallan  if test -z "$gccflag"; then
2155eefee25Smacallan    gccflag=-MD,
2165eefee25Smacallan  fi
2175eefee25Smacallan  "$@" -Wp,"$gccflag$tmpdepfile"
2185eefee25Smacallan  stat=$?
2195c30ecadSmrg  if test $stat -ne 0; then
2205eefee25Smacallan    rm -f "$tmpdepfile"
2215eefee25Smacallan    exit $stat
2225eefee25Smacallan  fi
2235eefee25Smacallan  rm -f "$depfile"
2245eefee25Smacallan  echo "$object : \\" > "$depfile"
2255c30ecadSmrg  # The second -e expression handles DOS-style file names with drive
2265c30ecadSmrg  # letters.
2275eefee25Smacallan  sed -e 's/^[^:]*: / /' \
2285eefee25Smacallan      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
229dc99b369Smrg## This next piece of magic avoids the "deleted header file" problem.
2305eefee25Smacallan## The problem is that when a header file which appears in a .P file
2315eefee25Smacallan## is deleted, the dependency causes make to die (because there is
2325eefee25Smacallan## typically no way to rebuild the header).  We avoid this by adding
2335eefee25Smacallan## dummy dependencies for each header file.  Too bad gcc doesn't do
2345eefee25Smacallan## this for us directly.
235dc99b369Smrg## Some versions of gcc put a space before the ':'.  On the theory
2365eefee25Smacallan## that the space means something, we add a space to the output as
237dc99b369Smrg## well.  hp depmode also adds that space, but also prefixes the VPATH
238dc99b369Smrg## to the object.  Take care to not repeat it in the output.
2395eefee25Smacallan## Some versions of the HPUX 10.20 sed can't process this invocation
2405eefee25Smacallan## correctly.  Breaking it into two sed invocations is a workaround.
2415c30ecadSmrg  tr ' ' "$nl" < "$tmpdepfile" \
2425c30ecadSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2435c30ecadSmrg    | sed -e 's/$/ :/' >> "$depfile"
2445eefee25Smacallan  rm -f "$tmpdepfile"
2455eefee25Smacallan  ;;
2465eefee25Smacallan
2475eefee25Smacallanhp)
2485eefee25Smacallan  # This case exists only to let depend.m4 do its work.  It works by
2495eefee25Smacallan  # looking at the text of this script.  This case will never be run,
2505eefee25Smacallan  # since it is checked for above.
2515eefee25Smacallan  exit 1
2525eefee25Smacallan  ;;
2535eefee25Smacallan
2545eefee25Smacallansgi)
2555eefee25Smacallan  if test "$libtool" = yes; then
2565eefee25Smacallan    "$@" "-Wp,-MDupdate,$tmpdepfile"
2575eefee25Smacallan  else
2585eefee25Smacallan    "$@" -MDupdate "$tmpdepfile"
2595eefee25Smacallan  fi
2605eefee25Smacallan  stat=$?
2615c30ecadSmrg  if test $stat -ne 0; then
2625eefee25Smacallan    rm -f "$tmpdepfile"
2635eefee25Smacallan    exit $stat
2645eefee25Smacallan  fi
2655eefee25Smacallan  rm -f "$depfile"
2665eefee25Smacallan
2675eefee25Smacallan  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
2685eefee25Smacallan    echo "$object : \\" > "$depfile"
2695eefee25Smacallan    # Clip off the initial element (the dependent).  Don't try to be
2705eefee25Smacallan    # clever and replace this with sed code, as IRIX sed won't handle
2715eefee25Smacallan    # lines with more than a fixed number of characters (4096 in
2725eefee25Smacallan    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
273dc99b369Smrg    # the IRIX cc adds comments like '#:fec' to the end of the
2745eefee25Smacallan    # dependency line.
275dc99b369Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2765c30ecadSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2775c30ecadSmrg      | tr "$nl" ' ' >> "$depfile"
278dc99b369Smrg    echo >> "$depfile"
2795eefee25Smacallan    # The second pass generates a dummy entry for each header file.
280dc99b369Smrg    tr ' ' "$nl" < "$tmpdepfile" \
2815c30ecadSmrg      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
2825c30ecadSmrg      >> "$depfile"
2835eefee25Smacallan  else
2845c30ecadSmrg    make_dummy_depfile
2855eefee25Smacallan  fi
2865eefee25Smacallan  rm -f "$tmpdepfile"
2875eefee25Smacallan  ;;
2885eefee25Smacallan
289dc99b369Smrgxlc)
290dc99b369Smrg  # This case exists only to let depend.m4 do its work.  It works by
291dc99b369Smrg  # looking at the text of this script.  This case will never be run,
292dc99b369Smrg  # since it is checked for above.
293dc99b369Smrg  exit 1
294dc99b369Smrg  ;;
295dc99b369Smrg
2965eefee25Smacallanaix)
2975eefee25Smacallan  # The C for AIX Compiler uses -M and outputs the dependencies
2985eefee25Smacallan  # in a .u file.  In older versions, this file always lives in the
299dc99b369Smrg  # current directory.  Also, the AIX compiler puts '$object:' at the
3005eefee25Smacallan  # start of each line; $object doesn't have directory information.
3015eefee25Smacallan  # Version 6 uses the directory in both cases.
3025c30ecadSmrg  set_dir_from "$object"
3035c30ecadSmrg  set_base_from "$object"
3045eefee25Smacallan  if test "$libtool" = yes; then
30562ab96baSmrg    tmpdepfile1=$dir$base.u
30662ab96baSmrg    tmpdepfile2=$base.u
30762ab96baSmrg    tmpdepfile3=$dir.libs/$base.u
3085eefee25Smacallan    "$@" -Wc,-M
3095eefee25Smacallan  else
31062ab96baSmrg    tmpdepfile1=$dir$base.u
31162ab96baSmrg    tmpdepfile2=$dir$base.u
31262ab96baSmrg    tmpdepfile3=$dir$base.u
3135eefee25Smacallan    "$@" -M
3145eefee25Smacallan  fi
3155eefee25Smacallan  stat=$?
3165c30ecadSmrg  if test $stat -ne 0; then
31762ab96baSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
3185eefee25Smacallan    exit $stat
3195eefee25Smacallan  fi
3205eefee25Smacallan
32162ab96baSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
32262ab96baSmrg  do
32362ab96baSmrg    test -f "$tmpdepfile" && break
32462ab96baSmrg  done
3255c30ecadSmrg  aix_post_process_depfile
3265eefee25Smacallan  ;;
3275eefee25Smacallan
3285c30ecadSmrgtcc)
3295c30ecadSmrg  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3305c30ecadSmrg  # FIXME: That version still under development at the moment of writing.
3315c30ecadSmrg  #        Make that this statement remains true also for stable, released
3325c30ecadSmrg  #        versions.
3335c30ecadSmrg  # It will wrap lines (doesn't matter whether long or short) with a
3345c30ecadSmrg  # trailing '\', as in:
3355c30ecadSmrg  #
3365c30ecadSmrg  #   foo.o : \
3375c30ecadSmrg  #    foo.c \
3385c30ecadSmrg  #    foo.h \
3395c30ecadSmrg  #
3405c30ecadSmrg  # It will put a trailing '\' even on the last line, and will use leading
3415c30ecadSmrg  # spaces rather than leading tabs (at least since its commit 0394caf7
3425c30ecadSmrg  # "Emit spaces for -MD").
3435eefee25Smacallan  "$@" -MD -MF "$tmpdepfile"
3445eefee25Smacallan  stat=$?
3455c30ecadSmrg  if test $stat -ne 0; then
3465eefee25Smacallan    rm -f "$tmpdepfile"
3475eefee25Smacallan    exit $stat
3485eefee25Smacallan  fi
3495eefee25Smacallan  rm -f "$depfile"
3505c30ecadSmrg  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3515c30ecadSmrg  # We have to change lines of the first kind to '$object: \'.
3525c30ecadSmrg  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3535c30ecadSmrg  # And for each line of the second kind, we have to emit a 'dep.h:'
3545c30ecadSmrg  # dummy dependency, to avoid the deleted-header problem.
3555c30ecadSmrg  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
356dc99b369Smrg  rm -f "$tmpdepfile"
357dc99b369Smrg  ;;
358dc99b369Smrg
359dc99b369Smrg## The order of this option in the case statement is important, since the
360dc99b369Smrg## shell code in configure will try each of these formats in the order
361dc99b369Smrg## listed in this file.  A plain '-MD' option would be understood by many
362dc99b369Smrg## compilers, so we must ensure this comes after the gcc and icc options.
363dc99b369Smrgpgcc)
364dc99b369Smrg  # Portland's C compiler understands '-MD'.
365dc99b369Smrg  # Will always output deps to 'file.d' where file is the root name of the
366dc99b369Smrg  # source file under compilation, even if file resides in a subdirectory.
367dc99b369Smrg  # The object file name does not affect the name of the '.d' file.
368dc99b369Smrg  # pgcc 10.2 will output
369dc99b369Smrg  #    foo.o: sub/foo.c sub/foo.h
370dc99b369Smrg  # and will wrap long lines using '\' :
371dc99b369Smrg  #    foo.o: sub/foo.c ... \
372dc99b369Smrg  #     sub/foo.h ... \
373dc99b369Smrg  #     ...
3745c30ecadSmrg  set_dir_from "$object"
375dc99b369Smrg  # Use the source, not the object, to determine the base name, since
376dc99b369Smrg  # that's sadly what pgcc will do too.
3775c30ecadSmrg  set_base_from "$source"
3785c30ecadSmrg  tmpdepfile=$base.d
379dc99b369Smrg
380dc99b369Smrg  # For projects that build the same source file twice into different object
381dc99b369Smrg  # files, the pgcc approach of using the *source* file root name can cause
382dc99b369Smrg  # problems in parallel builds.  Use a locking strategy to avoid stomping on
383dc99b369Smrg  # the same $tmpdepfile.
3845c30ecadSmrg  lockdir=$base.d-lock
3855c30ecadSmrg  trap "
3865c30ecadSmrg    echo '$0: caught signal, cleaning up...' >&2
3875c30ecadSmrg    rmdir '$lockdir'
3885c30ecadSmrg    exit 1
3895c30ecadSmrg  " 1 2 13 15
390dc99b369Smrg  numtries=100
391dc99b369Smrg  i=$numtries
3925c30ecadSmrg  while test $i -gt 0; do
393dc99b369Smrg    # mkdir is a portable test-and-set.
3945c30ecadSmrg    if mkdir "$lockdir" 2>/dev/null; then
395dc99b369Smrg      # This process acquired the lock.
396dc99b369Smrg      "$@" -MD
397dc99b369Smrg      stat=$?
398dc99b369Smrg      # Release the lock.
3995c30ecadSmrg      rmdir "$lockdir"
400dc99b369Smrg      break
401dc99b369Smrg    else
4025c30ecadSmrg      # If the lock is being held by a different process, wait
4035c30ecadSmrg      # until the winning process is done or we timeout.
4045c30ecadSmrg      while test -d "$lockdir" && test $i -gt 0; do
405dc99b369Smrg        sleep 1
406dc99b369Smrg        i=`expr $i - 1`
407dc99b369Smrg      done
408dc99b369Smrg    fi
409dc99b369Smrg    i=`expr $i - 1`
410dc99b369Smrg  done
411dc99b369Smrg  trap - 1 2 13 15
412dc99b369Smrg  if test $i -le 0; then
413dc99b369Smrg    echo "$0: failed to acquire lock after $numtries attempts" >&2
414dc99b369Smrg    echo "$0: check lockdir '$lockdir'" >&2
415dc99b369Smrg    exit 1
416dc99b369Smrg  fi
417dc99b369Smrg
418dc99b369Smrg  if test $stat -ne 0; then
419dc99b369Smrg    rm -f "$tmpdepfile"
420dc99b369Smrg    exit $stat
421dc99b369Smrg  fi
422dc99b369Smrg  rm -f "$depfile"
4235eefee25Smacallan  # Each line is of the form `foo.o: dependent.h',
4245eefee25Smacallan  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
4255eefee25Smacallan  # Do two passes, one to just change these to
4265eefee25Smacallan  # `$object: dependent.h' and one to simply `dependent.h:'.
4275eefee25Smacallan  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
4285eefee25Smacallan  # Some versions of the HPUX 10.20 sed can't process this invocation
4295eefee25Smacallan  # correctly.  Breaking it into two sed invocations is a workaround.
4305c30ecadSmrg  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4315c30ecadSmrg    | sed -e 's/$/ :/' >> "$depfile"
4325eefee25Smacallan  rm -f "$tmpdepfile"
4335eefee25Smacallan  ;;
4345eefee25Smacallan
43562ab96baSmrghp2)
43662ab96baSmrg  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
43762ab96baSmrg  # compilers, which have integrated preprocessors.  The correct option
43862ab96baSmrg  # to use with these is +Maked; it writes dependencies to a file named
43962ab96baSmrg  # 'foo.d', which lands next to the object file, wherever that
44062ab96baSmrg  # happens to be.
44162ab96baSmrg  # Much of this is similar to the tru64 case; see comments there.
4425c30ecadSmrg  set_dir_from  "$object"
4435c30ecadSmrg  set_base_from "$object"
44462ab96baSmrg  if test "$libtool" = yes; then
44562ab96baSmrg    tmpdepfile1=$dir$base.d
44662ab96baSmrg    tmpdepfile2=$dir.libs/$base.d
44762ab96baSmrg    "$@" -Wc,+Maked
44862ab96baSmrg  else
44962ab96baSmrg    tmpdepfile1=$dir$base.d
45062ab96baSmrg    tmpdepfile2=$dir$base.d
45162ab96baSmrg    "$@" +Maked
45262ab96baSmrg  fi
45362ab96baSmrg  stat=$?
4545c30ecadSmrg  if test $stat -ne 0; then
45562ab96baSmrg     rm -f "$tmpdepfile1" "$tmpdepfile2"
45662ab96baSmrg     exit $stat
45762ab96baSmrg  fi
45862ab96baSmrg
45962ab96baSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
46062ab96baSmrg  do
46162ab96baSmrg    test -f "$tmpdepfile" && break
46262ab96baSmrg  done
46362ab96baSmrg  if test -f "$tmpdepfile"; then
4645c30ecadSmrg    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
465dc99b369Smrg    # Add 'dependent.h:' lines.
466dc99b369Smrg    sed -ne '2,${
4675c30ecadSmrg               s/^ *//
4685c30ecadSmrg               s/ \\*$//
4695c30ecadSmrg               s/$/:/
4705c30ecadSmrg               p
4715c30ecadSmrg             }' "$tmpdepfile" >> "$depfile"
47262ab96baSmrg  else
4735c30ecadSmrg    make_dummy_depfile
47462ab96baSmrg  fi
47562ab96baSmrg  rm -f "$tmpdepfile" "$tmpdepfile2"
47662ab96baSmrg  ;;
47762ab96baSmrg
4785eefee25Smacallantru64)
4795c30ecadSmrg  # The Tru64 compiler uses -MD to generate dependencies as a side
4805c30ecadSmrg  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
4815c30ecadSmrg  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4825c30ecadSmrg  # dependencies in 'foo.d' instead, so we check for that too.
4835c30ecadSmrg  # Subdirectories are respected.
4845c30ecadSmrg  set_dir_from  "$object"
4855c30ecadSmrg  set_base_from "$object"
4865c30ecadSmrg
4875c30ecadSmrg  if test "$libtool" = yes; then
4885c30ecadSmrg    # Libtool generates 2 separate objects for the 2 libraries.  These
4895c30ecadSmrg    # two compilations output dependencies in $dir.libs/$base.o.d and
4905c30ecadSmrg    # in $dir$base.o.d.  We have to check for both files, because
4915c30ecadSmrg    # one of the two compilations can be disabled.  We should prefer
4925c30ecadSmrg    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
4935c30ecadSmrg    # automatically cleaned when .libs/ is deleted, while ignoring
4945c30ecadSmrg    # the former would cause a distcleancheck panic.
4955c30ecadSmrg    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4965c30ecadSmrg    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4975c30ecadSmrg    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
4985c30ecadSmrg    "$@" -Wc,-MD
4995c30ecadSmrg  else
5005c30ecadSmrg    tmpdepfile1=$dir$base.d
5015c30ecadSmrg    tmpdepfile2=$dir$base.d
5025c30ecadSmrg    tmpdepfile3=$dir$base.d
5035c30ecadSmrg    "$@" -MD
5045c30ecadSmrg  fi
5055c30ecadSmrg
5065c30ecadSmrg  stat=$?
5075c30ecadSmrg  if test $stat -ne 0; then
5085c30ecadSmrg    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5095c30ecadSmrg    exit $stat
5105c30ecadSmrg  fi
5115c30ecadSmrg
5125c30ecadSmrg  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
5135c30ecadSmrg  do
5145c30ecadSmrg    test -f "$tmpdepfile" && break
5155c30ecadSmrg  done
5165c30ecadSmrg  # Same post-processing that is required for AIX mode.
5175c30ecadSmrg  aix_post_process_depfile
5185c30ecadSmrg  ;;
5195eefee25Smacallan
520dc99b369Smrgmsvc7)
521dc99b369Smrg  if test "$libtool" = yes; then
522dc99b369Smrg    showIncludes=-Wc,-showIncludes
523dc99b369Smrg  else
524dc99b369Smrg    showIncludes=-showIncludes
525dc99b369Smrg  fi
526dc99b369Smrg  "$@" $showIncludes > "$tmpdepfile"
527dc99b369Smrg  stat=$?
528dc99b369Smrg  grep -v '^Note: including file: ' "$tmpdepfile"
5295c30ecadSmrg  if test $stat -ne 0; then
530dc99b369Smrg    rm -f "$tmpdepfile"
531dc99b369Smrg    exit $stat
532dc99b369Smrg  fi
533dc99b369Smrg  rm -f "$depfile"
534dc99b369Smrg  echo "$object : \\" > "$depfile"
535dc99b369Smrg  # The first sed program below extracts the file names and escapes
536dc99b369Smrg  # backslashes for cygpath.  The second sed program outputs the file
537dc99b369Smrg  # name when reading, but also accumulates all include files in the
538dc99b369Smrg  # hold buffer in order to output them again at the end.  This only
539dc99b369Smrg  # works with sed implementations that can handle large buffers.
540dc99b369Smrg  sed < "$tmpdepfile" -n '
541dc99b369Smrg/^Note: including file:  *\(.*\)/ {
542dc99b369Smrg  s//\1/
543dc99b369Smrg  s/\\/\\\\/g
544dc99b369Smrg  p
545dc99b369Smrg}' | $cygpath_u | sort -u | sed -n '
546dc99b369Smrgs/ /\\ /g
547dc99b369Smrgs/\(.*\)/'"$tab"'\1 \\/p
548dc99b369Smrgs/.\(.*\) \\/\1:/
549dc99b369SmrgH
550dc99b369Smrg$ {
551dc99b369Smrg  s/.*/'"$tab"'/
552dc99b369Smrg  G
553dc99b369Smrg  p
554dc99b369Smrg}' >> "$depfile"
5555c30ecadSmrg  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
556dc99b369Smrg  rm -f "$tmpdepfile"
557dc99b369Smrg  ;;
558dc99b369Smrg
559dc99b369Smrgmsvc7msys)
560dc99b369Smrg  # This case exists only to let depend.m4 do its work.  It works by
561dc99b369Smrg  # looking at the text of this script.  This case will never be run,
562dc99b369Smrg  # since it is checked for above.
563dc99b369Smrg  exit 1
564dc99b369Smrg  ;;
565dc99b369Smrg
5665eefee25Smacallan#nosideeffect)
5675eefee25Smacallan  # This comment above is used by automake to tell side-effect
5685eefee25Smacallan  # dependency tracking mechanisms from slower ones.
5695eefee25Smacallan
5705eefee25Smacallandashmstdout)
5715eefee25Smacallan  # Important note: in order to support this mode, a compiler *must*
5725eefee25Smacallan  # always write the preprocessed file to stdout, regardless of -o.
5735eefee25Smacallan  "$@" || exit $?
5745eefee25Smacallan
5755eefee25Smacallan  # Remove the call to Libtool.
5765eefee25Smacallan  if test "$libtool" = yes; then
577dc99b369Smrg    while test "X$1" != 'X--mode=compile'; do
5785eefee25Smacallan      shift
5795eefee25Smacallan    done
5805eefee25Smacallan    shift
5815eefee25Smacallan  fi
5825eefee25Smacallan
583dc99b369Smrg  # Remove '-o $object'.
5845eefee25Smacallan  IFS=" "
5855eefee25Smacallan  for arg
5865eefee25Smacallan  do
5875eefee25Smacallan    case $arg in
5885eefee25Smacallan    -o)
5895eefee25Smacallan      shift
5905eefee25Smacallan      ;;
5915eefee25Smacallan    $object)
5925eefee25Smacallan      shift
5935eefee25Smacallan      ;;
5945eefee25Smacallan    *)
5955eefee25Smacallan      set fnord "$@" "$arg"
5965eefee25Smacallan      shift # fnord
5975eefee25Smacallan      shift # $arg
5985eefee25Smacallan      ;;
5995eefee25Smacallan    esac
6005eefee25Smacallan  done
6015eefee25Smacallan
6025eefee25Smacallan  test -z "$dashmflag" && dashmflag=-M
603dc99b369Smrg  # Require at least two characters before searching for ':'
6045eefee25Smacallan  # in the target name.  This is to cope with DOS-style filenames:
605dc99b369Smrg  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
6065eefee25Smacallan  "$@" $dashmflag |
6075c30ecadSmrg    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
6085eefee25Smacallan  rm -f "$depfile"
6095eefee25Smacallan  cat < "$tmpdepfile" > "$depfile"
6105c30ecadSmrg  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6115c30ecadSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6125c30ecadSmrg  tr ' ' "$nl" < "$tmpdepfile" \
6135c30ecadSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6145c30ecadSmrg    | sed -e 's/$/ :/' >> "$depfile"
6155eefee25Smacallan  rm -f "$tmpdepfile"
6165eefee25Smacallan  ;;
6175eefee25Smacallan
6185eefee25SmacallandashXmstdout)
6195eefee25Smacallan  # This case only exists to satisfy depend.m4.  It is never actually
6205eefee25Smacallan  # run, as this mode is specially recognized in the preamble.
6215eefee25Smacallan  exit 1
6225eefee25Smacallan  ;;
6235eefee25Smacallan
6245eefee25Smacallanmakedepend)
6255eefee25Smacallan  "$@" || exit $?
6265eefee25Smacallan  # Remove any Libtool call
6275eefee25Smacallan  if test "$libtool" = yes; then
628dc99b369Smrg    while test "X$1" != 'X--mode=compile'; do
6295eefee25Smacallan      shift
6305eefee25Smacallan    done
6315eefee25Smacallan    shift
6325eefee25Smacallan  fi
6335eefee25Smacallan  # X makedepend
6345eefee25Smacallan  shift
635dc99b369Smrg  cleared=no eat=no
636dc99b369Smrg  for arg
637dc99b369Smrg  do
6385eefee25Smacallan    case $cleared in
6395eefee25Smacallan    no)
6405eefee25Smacallan      set ""; shift
6415eefee25Smacallan      cleared=yes ;;
6425eefee25Smacallan    esac
643dc99b369Smrg    if test $eat = yes; then
644dc99b369Smrg      eat=no
645dc99b369Smrg      continue
646dc99b369Smrg    fi
6475eefee25Smacallan    case "$arg" in
6485eefee25Smacallan    -D*|-I*)
6495eefee25Smacallan      set fnord "$@" "$arg"; shift ;;
6505eefee25Smacallan    # Strip any option that makedepend may not understand.  Remove
6515eefee25Smacallan    # the object too, otherwise makedepend will parse it as a source file.
652dc99b369Smrg    -arch)
653dc99b369Smrg      eat=yes ;;
6545eefee25Smacallan    -*|$object)
6555eefee25Smacallan      ;;
6565eefee25Smacallan    *)
6575eefee25Smacallan      set fnord "$@" "$arg"; shift ;;
6585eefee25Smacallan    esac
6595eefee25Smacallan  done
660dc99b369Smrg  obj_suffix=`echo "$object" | sed 's/^.*\././'`
6615eefee25Smacallan  touch "$tmpdepfile"
6625eefee25Smacallan  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
6635eefee25Smacallan  rm -f "$depfile"
664dc99b369Smrg  # makedepend may prepend the VPATH from the source file name to the object.
665dc99b369Smrg  # No need to regex-escape $object, excess matching of '.' is harmless.
666dc99b369Smrg  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6675c30ecadSmrg  # Some versions of the HPUX 10.20 sed can't process the last invocation
6685c30ecadSmrg  # correctly.  Breaking it into two sed invocations is a workaround.
6695c30ecadSmrg  sed '1,2d' "$tmpdepfile" \
6705c30ecadSmrg    | tr ' ' "$nl" \
6715c30ecadSmrg    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6725c30ecadSmrg    | sed -e 's/$/ :/' >> "$depfile"
6735eefee25Smacallan  rm -f "$tmpdepfile" "$tmpdepfile".bak
6745eefee25Smacallan  ;;
6755eefee25Smacallan
6765eefee25Smacallancpp)
6775eefee25Smacallan  # Important note: in order to support this mode, a compiler *must*
6785eefee25Smacallan  # always write the preprocessed file to stdout.
6795eefee25Smacallan  "$@" || exit $?
6805eefee25Smacallan
6815eefee25Smacallan  # Remove the call to Libtool.
6825eefee25Smacallan  if test "$libtool" = yes; then
683dc99b369Smrg    while test "X$1" != 'X--mode=compile'; do
6845eefee25Smacallan      shift
6855eefee25Smacallan    done
6865eefee25Smacallan    shift
6875eefee25Smacallan  fi
6885eefee25Smacallan
689dc99b369Smrg  # Remove '-o $object'.
6905eefee25Smacallan  IFS=" "
6915eefee25Smacallan  for arg
6925eefee25Smacallan  do
6935eefee25Smacallan    case $arg in
6945eefee25Smacallan    -o)
6955eefee25Smacallan      shift
6965eefee25Smacallan      ;;
6975eefee25Smacallan    $object)
6985eefee25Smacallan      shift
6995eefee25Smacallan      ;;
7005eefee25Smacallan    *)
7015eefee25Smacallan      set fnord "$@" "$arg"
7025eefee25Smacallan      shift # fnord
7035eefee25Smacallan      shift # $arg
7045eefee25Smacallan      ;;
7055eefee25Smacallan    esac
7065eefee25Smacallan  done
7075eefee25Smacallan
7085c30ecadSmrg  "$@" -E \
7095c30ecadSmrg    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7105c30ecadSmrg             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7115c30ecadSmrg    | sed '$ s: \\$::' > "$tmpdepfile"
7125eefee25Smacallan  rm -f "$depfile"
7135eefee25Smacallan  echo "$object : \\" > "$depfile"
7145eefee25Smacallan  cat < "$tmpdepfile" >> "$depfile"
7155eefee25Smacallan  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
7165eefee25Smacallan  rm -f "$tmpdepfile"
7175eefee25Smacallan  ;;
7185eefee25Smacallan
7195eefee25Smacallanmsvisualcpp)
7205eefee25Smacallan  # Important note: in order to support this mode, a compiler *must*
721dc99b369Smrg  # always write the preprocessed file to stdout.
7225eefee25Smacallan  "$@" || exit $?
723dc99b369Smrg
724dc99b369Smrg  # Remove the call to Libtool.
725dc99b369Smrg  if test "$libtool" = yes; then
726dc99b369Smrg    while test "X$1" != 'X--mode=compile'; do
727dc99b369Smrg      shift
728dc99b369Smrg    done
729dc99b369Smrg    shift
730dc99b369Smrg  fi
731dc99b369Smrg
7325eefee25Smacallan  IFS=" "
7335eefee25Smacallan  for arg
7345eefee25Smacallan  do
7355eefee25Smacallan    case "$arg" in
736dc99b369Smrg    -o)
737dc99b369Smrg      shift
738dc99b369Smrg      ;;
739dc99b369Smrg    $object)
740dc99b369Smrg      shift
741dc99b369Smrg      ;;
7425eefee25Smacallan    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
7435c30ecadSmrg        set fnord "$@"
7445c30ecadSmrg        shift
7455c30ecadSmrg        shift
7465c30ecadSmrg        ;;
7475eefee25Smacallan    *)
7485c30ecadSmrg        set fnord "$@" "$arg"
7495c30ecadSmrg        shift
7505c30ecadSmrg        shift
7515c30ecadSmrg        ;;
7525eefee25Smacallan    esac
7535eefee25Smacallan  done
754dc99b369Smrg  "$@" -E 2>/dev/null |
755dc99b369Smrg  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
7565eefee25Smacallan  rm -f "$depfile"
7575eefee25Smacallan  echo "$object : \\" > "$depfile"
758dc99b369Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
759dc99b369Smrg  echo "$tab" >> "$depfile"
760dc99b369Smrg  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
7615eefee25Smacallan  rm -f "$tmpdepfile"
7625eefee25Smacallan  ;;
7635eefee25Smacallan
764dc99b369Smrgmsvcmsys)
765dc99b369Smrg  # This case exists only to let depend.m4 do its work.  It works by
766dc99b369Smrg  # looking at the text of this script.  This case will never be run,
767dc99b369Smrg  # since it is checked for above.
768dc99b369Smrg  exit 1
769dc99b369Smrg  ;;
770dc99b369Smrg
7715eefee25Smacallannone)
7725eefee25Smacallan  exec "$@"
7735eefee25Smacallan  ;;
7745eefee25Smacallan
7755eefee25Smacallan*)
7765eefee25Smacallan  echo "Unknown depmode $depmode" 1>&2
7775eefee25Smacallan  exit 1
7785eefee25Smacallan  ;;
7795eefee25Smacallanesac
7805eefee25Smacallan
7815eefee25Smacallanexit 0
7825eefee25Smacallan
7835eefee25Smacallan# Local Variables:
7845eefee25Smacallan# mode: shell-script
7855eefee25Smacallan# sh-indentation: 2
7865c30ecadSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
7875eefee25Smacallan# time-stamp-start: "scriptversion="
7885eefee25Smacallan# time-stamp-format: "%:y-%02m-%02d.%02H"
7895c30ecadSmrg# time-stamp-time-zone: "UTC0"
790dc99b369Smrg# time-stamp-end: "; # UTC"
7915eefee25Smacallan# End:
792