xref: /netbsd-src/external/bsd/openpam/dist/depcomp (revision 024a2e8c049a7132c2274c1f5271ae54063f3c4d)
144269bb5Schristos#! /bin/sh
244269bb5Schristos# depcomp - compile a program generating dependencies as side-effects
344269bb5Schristos
477513ecfSchristosscriptversion=2018-03-07.03; # UTC
544269bb5Schristos
6*024a2e8cSchristos# Copyright (C) 1999-2021 Free Software Foundation, Inc.
744269bb5Schristos
844269bb5Schristos# This program is free software; you can redistribute it and/or modify
944269bb5Schristos# it under the terms of the GNU General Public License as published by
1044269bb5Schristos# the Free Software Foundation; either version 2, or (at your option)
1144269bb5Schristos# any later version.
1244269bb5Schristos
1344269bb5Schristos# This program is distributed in the hope that it will be useful,
1444269bb5Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
1544269bb5Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1644269bb5Schristos# GNU General Public License for more details.
1744269bb5Schristos
1844269bb5Schristos# You should have received a copy of the GNU General Public License
1977513ecfSchristos# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2044269bb5Schristos
2144269bb5Schristos# As a special exception to the GNU General Public License, if you
2244269bb5Schristos# distribute this file as part of a program that contains a
2344269bb5Schristos# configuration script generated by Autoconf, you may include it under
2444269bb5Schristos# the same distribution terms that you use for the rest of that program.
2544269bb5Schristos
2644269bb5Schristos# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
2744269bb5Schristos
2844269bb5Schristoscase $1 in
2944269bb5Schristos  '')
300bbc3b9fSchristos    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
3144269bb5Schristos    exit 1;
3244269bb5Schristos    ;;
3344269bb5Schristos  -h | --h*)
3444269bb5Schristos    cat <<\EOF
3544269bb5SchristosUsage: depcomp [--help] [--version] PROGRAM [ARGS]
3644269bb5Schristos
3744269bb5SchristosRun PROGRAMS ARGS to compile a file, generating dependencies
3844269bb5Schristosas side-effects.
3944269bb5Schristos
4044269bb5SchristosEnvironment variables:
4144269bb5Schristos  depmode     Dependency tracking mode.
420bbc3b9fSchristos  source      Source file read by 'PROGRAMS ARGS'.
430bbc3b9fSchristos  object      Object file output by 'PROGRAMS ARGS'.
4444269bb5Schristos  DEPDIR      directory where to store dependencies.
4544269bb5Schristos  depfile     Dependency file to output.
460bbc3b9fSchristos  tmpdepfile  Temporary file to use when outputting dependencies.
4744269bb5Schristos  libtool     Whether libtool is used (yes/no).
4844269bb5Schristos
4944269bb5SchristosReport bugs to <bug-automake@gnu.org>.
5044269bb5SchristosEOF
5144269bb5Schristos    exit $?
5244269bb5Schristos    ;;
5344269bb5Schristos  -v | --v*)
5444269bb5Schristos    echo "depcomp $scriptversion"
5544269bb5Schristos    exit $?
5644269bb5Schristos    ;;
5744269bb5Schristosesac
5844269bb5Schristos
590bbc3b9fSchristos# Get the directory component of the given path, and save it in the
600bbc3b9fSchristos# global variables '$dir'.  Note that this directory component will
610bbc3b9fSchristos# be either empty or ending with a '/' character.  This is deliberate.
620bbc3b9fSchristosset_dir_from ()
630bbc3b9fSchristos{
640bbc3b9fSchristos  case $1 in
650bbc3b9fSchristos    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
660bbc3b9fSchristos      *) dir=;;
670bbc3b9fSchristos  esac
680bbc3b9fSchristos}
690bbc3b9fSchristos
700bbc3b9fSchristos# Get the suffix-stripped basename of the given path, and save it the
710bbc3b9fSchristos# global variable '$base'.
720bbc3b9fSchristosset_base_from ()
730bbc3b9fSchristos{
740bbc3b9fSchristos  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
750bbc3b9fSchristos}
760bbc3b9fSchristos
770bbc3b9fSchristos# If no dependency file was actually created by the compiler invocation,
780bbc3b9fSchristos# we still have to create a dummy depfile, to avoid errors with the
790bbc3b9fSchristos# Makefile "include basename.Plo" scheme.
800bbc3b9fSchristosmake_dummy_depfile ()
810bbc3b9fSchristos{
820bbc3b9fSchristos  echo "#dummy" > "$depfile"
830bbc3b9fSchristos}
840bbc3b9fSchristos
850bbc3b9fSchristos# Factor out some common post-processing of the generated depfile.
860bbc3b9fSchristos# Requires the auxiliary global variable '$tmpdepfile' to be set.
870bbc3b9fSchristosaix_post_process_depfile ()
880bbc3b9fSchristos{
890bbc3b9fSchristos  # If the compiler actually managed to produce a dependency file,
900bbc3b9fSchristos  # post-process it.
910bbc3b9fSchristos  if test -f "$tmpdepfile"; then
920bbc3b9fSchristos    # Each line is of the form 'foo.o: dependency.h'.
930bbc3b9fSchristos    # Do two passes, one to just change these to
940bbc3b9fSchristos    #   $object: dependency.h
950bbc3b9fSchristos    # and one to simply output
960bbc3b9fSchristos    #   dependency.h:
970bbc3b9fSchristos    # which is needed to avoid the deleted-header problem.
980bbc3b9fSchristos    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
990bbc3b9fSchristos      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
1000bbc3b9fSchristos    } > "$depfile"
1010bbc3b9fSchristos    rm -f "$tmpdepfile"
1020bbc3b9fSchristos  else
1030bbc3b9fSchristos    make_dummy_depfile
1040bbc3b9fSchristos  fi
1050bbc3b9fSchristos}
1060bbc3b9fSchristos
1070bbc3b9fSchristos# A tabulation character.
1080bbc3b9fSchristostab='	'
1090bbc3b9fSchristos# A newline character.
1100bbc3b9fSchristosnl='
1110bbc3b9fSchristos'
1120bbc3b9fSchristos# Character ranges might be problematic outside the C locale.
1130bbc3b9fSchristos# These definitions help.
1140bbc3b9fSchristosupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
1150bbc3b9fSchristoslower=abcdefghijklmnopqrstuvwxyz
1160bbc3b9fSchristosdigits=0123456789
1170bbc3b9fSchristosalpha=${upper}${lower}
1180bbc3b9fSchristos
11944269bb5Schristosif test -z "$depmode" || test -z "$source" || test -z "$object"; then
12044269bb5Schristos  echo "depcomp: Variables source, object and depmode must be set" 1>&2
12144269bb5Schristos  exit 1
12244269bb5Schristosfi
12344269bb5Schristos
12444269bb5Schristos# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
12544269bb5Schristosdepfile=${depfile-`echo "$object" |
12644269bb5Schristos  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
12744269bb5Schristostmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
12844269bb5Schristos
12944269bb5Schristosrm -f "$tmpdepfile"
13044269bb5Schristos
1310bbc3b9fSchristos# Avoid interferences from the environment.
1320bbc3b9fSchristosgccflag= dashmflag=
1330bbc3b9fSchristos
13444269bb5Schristos# Some modes work just like other modes, but use different flags.  We
13544269bb5Schristos# parameterize here, but still list the modes in the big case below,
13644269bb5Schristos# to make depend.m4 easier to write.  Note that we *cannot* use a case
13744269bb5Schristos# here, because this file can only contain one case statement.
13844269bb5Schristosif test "$depmode" = hp; then
13944269bb5Schristos  # HP compiler uses -M and no extra arg.
14044269bb5Schristos  gccflag=-M
14144269bb5Schristos  depmode=gcc
14244269bb5Schristosfi
14344269bb5Schristos
14444269bb5Schristosif test "$depmode" = dashXmstdout; then
14544269bb5Schristos  # This is just like dashmstdout with a different argument.
14644269bb5Schristos  dashmflag=-xM
14744269bb5Schristos  depmode=dashmstdout
14844269bb5Schristosfi
14944269bb5Schristos
15044269bb5Schristoscygpath_u="cygpath -u -f -"
15144269bb5Schristosif test "$depmode" = msvcmsys; then
15244269bb5Schristos  # This is just like msvisualcpp but w/o cygpath translation.
15344269bb5Schristos  # Just convert the backslash-escaped backslashes to single forward
15444269bb5Schristos  # slashes to satisfy depend.m4
1550bbc3b9fSchristos  cygpath_u='sed s,\\\\,/,g'
15644269bb5Schristos  depmode=msvisualcpp
15744269bb5Schristosfi
15844269bb5Schristos
1590bbc3b9fSchristosif test "$depmode" = msvc7msys; then
1600bbc3b9fSchristos  # This is just like msvc7 but w/o cygpath translation.
1610bbc3b9fSchristos  # Just convert the backslash-escaped backslashes to single forward
1620bbc3b9fSchristos  # slashes to satisfy depend.m4
1630bbc3b9fSchristos  cygpath_u='sed s,\\\\,/,g'
1640bbc3b9fSchristos  depmode=msvc7
1650bbc3b9fSchristosfi
1660bbc3b9fSchristos
1670bbc3b9fSchristosif test "$depmode" = xlc; then
1680bbc3b9fSchristos  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
1690bbc3b9fSchristos  gccflag=-qmakedep=gcc,-MF
1700bbc3b9fSchristos  depmode=gcc
1710bbc3b9fSchristosfi
1720bbc3b9fSchristos
17344269bb5Schristoscase "$depmode" in
17444269bb5Schristosgcc3)
17544269bb5Schristos## gcc 3 implements dependency tracking that does exactly what
17644269bb5Schristos## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
17744269bb5Schristos## it if -MD -MP comes after the -MF stuff.  Hmm.
17844269bb5Schristos## Unfortunately, FreeBSD c89 acceptance of flags depends upon
17944269bb5Schristos## the command line argument order; so add the flags where they
18044269bb5Schristos## appear in depend2.am.  Note that the slowdown incurred here
18144269bb5Schristos## affects only configure: in makefiles, %FASTDEP% shortcuts this.
18244269bb5Schristos  for arg
18344269bb5Schristos  do
18444269bb5Schristos    case $arg in
18544269bb5Schristos    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
18644269bb5Schristos    *)  set fnord "$@" "$arg" ;;
18744269bb5Schristos    esac
18844269bb5Schristos    shift # fnord
18944269bb5Schristos    shift # $arg
19044269bb5Schristos  done
19144269bb5Schristos  "$@"
19244269bb5Schristos  stat=$?
1930bbc3b9fSchristos  if test $stat -ne 0; then
19444269bb5Schristos    rm -f "$tmpdepfile"
19544269bb5Schristos    exit $stat
19644269bb5Schristos  fi
19744269bb5Schristos  mv "$tmpdepfile" "$depfile"
19844269bb5Schristos  ;;
19944269bb5Schristos
20044269bb5Schristosgcc)
2010bbc3b9fSchristos## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
2020bbc3b9fSchristos## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
2030bbc3b9fSchristos## (see the conditional assignment to $gccflag above).
20444269bb5Schristos## There are various ways to get dependency output from gcc.  Here's
20544269bb5Schristos## why we pick this rather obscure method:
20644269bb5Schristos## - Don't want to use -MD because we'd like the dependencies to end
20744269bb5Schristos##   up in a subdir.  Having to rename by hand is ugly.
20844269bb5Schristos##   (We might end up doing this anyway to support other compilers.)
20944269bb5Schristos## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
2100bbc3b9fSchristos##   -MM, not -M (despite what the docs say).  Also, it might not be
2110bbc3b9fSchristos##   supported by the other compilers which use the 'gcc' depmode.
21244269bb5Schristos## - Using -M directly means running the compiler twice (even worse
21344269bb5Schristos##   than renaming).
21444269bb5Schristos  if test -z "$gccflag"; then
21544269bb5Schristos    gccflag=-MD,
21644269bb5Schristos  fi
21744269bb5Schristos  "$@" -Wp,"$gccflag$tmpdepfile"
21844269bb5Schristos  stat=$?
2190bbc3b9fSchristos  if test $stat -ne 0; then
22044269bb5Schristos    rm -f "$tmpdepfile"
22144269bb5Schristos    exit $stat
22244269bb5Schristos  fi
22344269bb5Schristos  rm -f "$depfile"
22444269bb5Schristos  echo "$object : \\" > "$depfile"
2250bbc3b9fSchristos  # The second -e expression handles DOS-style file names with drive
2260bbc3b9fSchristos  # letters.
22744269bb5Schristos  sed -e 's/^[^:]*: / /' \
22844269bb5Schristos      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
2290bbc3b9fSchristos## This next piece of magic avoids the "deleted header file" problem.
23044269bb5Schristos## The problem is that when a header file which appears in a .P file
23144269bb5Schristos## is deleted, the dependency causes make to die (because there is
23244269bb5Schristos## typically no way to rebuild the header).  We avoid this by adding
23344269bb5Schristos## dummy dependencies for each header file.  Too bad gcc doesn't do
23444269bb5Schristos## this for us directly.
2350bbc3b9fSchristos## Some versions of gcc put a space before the ':'.  On the theory
23644269bb5Schristos## that the space means something, we add a space to the output as
2370bbc3b9fSchristos## well.  hp depmode also adds that space, but also prefixes the VPATH
2380bbc3b9fSchristos## to the object.  Take care to not repeat it in the output.
23944269bb5Schristos## Some versions of the HPUX 10.20 sed can't process this invocation
24044269bb5Schristos## correctly.  Breaking it into two sed invocations is a workaround.
2410bbc3b9fSchristos  tr ' ' "$nl" < "$tmpdepfile" \
2420bbc3b9fSchristos    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
2430bbc3b9fSchristos    | sed -e 's/$/ :/' >> "$depfile"
24444269bb5Schristos  rm -f "$tmpdepfile"
24544269bb5Schristos  ;;
24644269bb5Schristos
24744269bb5Schristoshp)
24844269bb5Schristos  # This case exists only to let depend.m4 do its work.  It works by
24944269bb5Schristos  # looking at the text of this script.  This case will never be run,
25044269bb5Schristos  # since it is checked for above.
25144269bb5Schristos  exit 1
25244269bb5Schristos  ;;
25344269bb5Schristos
25444269bb5Schristossgi)
25544269bb5Schristos  if test "$libtool" = yes; then
25644269bb5Schristos    "$@" "-Wp,-MDupdate,$tmpdepfile"
25744269bb5Schristos  else
25844269bb5Schristos    "$@" -MDupdate "$tmpdepfile"
25944269bb5Schristos  fi
26044269bb5Schristos  stat=$?
2610bbc3b9fSchristos  if test $stat -ne 0; then
26244269bb5Schristos    rm -f "$tmpdepfile"
26344269bb5Schristos    exit $stat
26444269bb5Schristos  fi
26544269bb5Schristos  rm -f "$depfile"
26644269bb5Schristos
26744269bb5Schristos  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
26844269bb5Schristos    echo "$object : \\" > "$depfile"
26944269bb5Schristos    # Clip off the initial element (the dependent).  Don't try to be
27044269bb5Schristos    # clever and replace this with sed code, as IRIX sed won't handle
27144269bb5Schristos    # lines with more than a fixed number of characters (4096 in
27244269bb5Schristos    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
2730bbc3b9fSchristos    # the IRIX cc adds comments like '#:fec' to the end of the
27444269bb5Schristos    # dependency line.
2750bbc3b9fSchristos    tr ' ' "$nl" < "$tmpdepfile" \
2760bbc3b9fSchristos      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
2770bbc3b9fSchristos      | tr "$nl" ' ' >> "$depfile"
27844269bb5Schristos    echo >> "$depfile"
27944269bb5Schristos    # The second pass generates a dummy entry for each header file.
2800bbc3b9fSchristos    tr ' ' "$nl" < "$tmpdepfile" \
28144269bb5Schristos      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
28244269bb5Schristos      >> "$depfile"
28344269bb5Schristos  else
2840bbc3b9fSchristos    make_dummy_depfile
28544269bb5Schristos  fi
28644269bb5Schristos  rm -f "$tmpdepfile"
28744269bb5Schristos  ;;
28844269bb5Schristos
2890bbc3b9fSchristosxlc)
2900bbc3b9fSchristos  # This case exists only to let depend.m4 do its work.  It works by
2910bbc3b9fSchristos  # looking at the text of this script.  This case will never be run,
2920bbc3b9fSchristos  # since it is checked for above.
2930bbc3b9fSchristos  exit 1
2940bbc3b9fSchristos  ;;
2950bbc3b9fSchristos
29644269bb5Schristosaix)
29744269bb5Schristos  # The C for AIX Compiler uses -M and outputs the dependencies
29844269bb5Schristos  # in a .u file.  In older versions, this file always lives in the
2990bbc3b9fSchristos  # current directory.  Also, the AIX compiler puts '$object:' at the
30044269bb5Schristos  # start of each line; $object doesn't have directory information.
30144269bb5Schristos  # Version 6 uses the directory in both cases.
3020bbc3b9fSchristos  set_dir_from "$object"
3030bbc3b9fSchristos  set_base_from "$object"
30444269bb5Schristos  if test "$libtool" = yes; then
30544269bb5Schristos    tmpdepfile1=$dir$base.u
30644269bb5Schristos    tmpdepfile2=$base.u
30744269bb5Schristos    tmpdepfile3=$dir.libs/$base.u
30844269bb5Schristos    "$@" -Wc,-M
30944269bb5Schristos  else
31044269bb5Schristos    tmpdepfile1=$dir$base.u
31144269bb5Schristos    tmpdepfile2=$dir$base.u
31244269bb5Schristos    tmpdepfile3=$dir$base.u
31344269bb5Schristos    "$@" -M
31444269bb5Schristos  fi
31544269bb5Schristos  stat=$?
3160bbc3b9fSchristos  if test $stat -ne 0; then
31744269bb5Schristos    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
31844269bb5Schristos    exit $stat
31944269bb5Schristos  fi
32044269bb5Schristos
32144269bb5Schristos  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
32244269bb5Schristos  do
32344269bb5Schristos    test -f "$tmpdepfile" && break
32444269bb5Schristos  done
3250bbc3b9fSchristos  aix_post_process_depfile
3260bbc3b9fSchristos  ;;
3270bbc3b9fSchristos
3280bbc3b9fSchristostcc)
3290bbc3b9fSchristos  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
3300bbc3b9fSchristos  # FIXME: That version still under development at the moment of writing.
3310bbc3b9fSchristos  #        Make that this statement remains true also for stable, released
3320bbc3b9fSchristos  #        versions.
3330bbc3b9fSchristos  # It will wrap lines (doesn't matter whether long or short) with a
3340bbc3b9fSchristos  # trailing '\', as in:
3350bbc3b9fSchristos  #
3360bbc3b9fSchristos  #   foo.o : \
3370bbc3b9fSchristos  #    foo.c \
3380bbc3b9fSchristos  #    foo.h \
3390bbc3b9fSchristos  #
3400bbc3b9fSchristos  # It will put a trailing '\' even on the last line, and will use leading
3410bbc3b9fSchristos  # spaces rather than leading tabs (at least since its commit 0394caf7
3420bbc3b9fSchristos  # "Emit spaces for -MD").
3430bbc3b9fSchristos  "$@" -MD -MF "$tmpdepfile"
3440bbc3b9fSchristos  stat=$?
3450bbc3b9fSchristos  if test $stat -ne 0; then
3460bbc3b9fSchristos    rm -f "$tmpdepfile"
3470bbc3b9fSchristos    exit $stat
34844269bb5Schristos  fi
3490bbc3b9fSchristos  rm -f "$depfile"
3500bbc3b9fSchristos  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
3510bbc3b9fSchristos  # We have to change lines of the first kind to '$object: \'.
3520bbc3b9fSchristos  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
3530bbc3b9fSchristos  # And for each line of the second kind, we have to emit a 'dep.h:'
3540bbc3b9fSchristos  # dummy dependency, to avoid the deleted-header problem.
3550bbc3b9fSchristos  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
35644269bb5Schristos  rm -f "$tmpdepfile"
35744269bb5Schristos  ;;
35844269bb5Schristos
3590bbc3b9fSchristos## The order of this option in the case statement is important, since the
3600bbc3b9fSchristos## shell code in configure will try each of these formats in the order
3610bbc3b9fSchristos## listed in this file.  A plain '-MD' option would be understood by many
3620bbc3b9fSchristos## compilers, so we must ensure this comes after the gcc and icc options.
3630bbc3b9fSchristospgcc)
3640bbc3b9fSchristos  # Portland's C compiler understands '-MD'.
3650bbc3b9fSchristos  # Will always output deps to 'file.d' where file is the root name of the
3660bbc3b9fSchristos  # source file under compilation, even if file resides in a subdirectory.
3670bbc3b9fSchristos  # The object file name does not affect the name of the '.d' file.
3680bbc3b9fSchristos  # pgcc 10.2 will output
36944269bb5Schristos  #    foo.o: sub/foo.c sub/foo.h
3700bbc3b9fSchristos  # and will wrap long lines using '\' :
37144269bb5Schristos  #    foo.o: sub/foo.c ... \
37244269bb5Schristos  #     sub/foo.h ... \
37344269bb5Schristos  #     ...
3740bbc3b9fSchristos  set_dir_from "$object"
3750bbc3b9fSchristos  # Use the source, not the object, to determine the base name, since
3760bbc3b9fSchristos  # that's sadly what pgcc will do too.
3770bbc3b9fSchristos  set_base_from "$source"
3780bbc3b9fSchristos  tmpdepfile=$base.d
37944269bb5Schristos
3800bbc3b9fSchristos  # For projects that build the same source file twice into different object
3810bbc3b9fSchristos  # files, the pgcc approach of using the *source* file root name can cause
3820bbc3b9fSchristos  # problems in parallel builds.  Use a locking strategy to avoid stomping on
3830bbc3b9fSchristos  # the same $tmpdepfile.
3840bbc3b9fSchristos  lockdir=$base.d-lock
3850bbc3b9fSchristos  trap "
3860bbc3b9fSchristos    echo '$0: caught signal, cleaning up...' >&2
3870bbc3b9fSchristos    rmdir '$lockdir'
3880bbc3b9fSchristos    exit 1
3890bbc3b9fSchristos  " 1 2 13 15
3900bbc3b9fSchristos  numtries=100
3910bbc3b9fSchristos  i=$numtries
3920bbc3b9fSchristos  while test $i -gt 0; do
3930bbc3b9fSchristos    # mkdir is a portable test-and-set.
3940bbc3b9fSchristos    if mkdir "$lockdir" 2>/dev/null; then
3950bbc3b9fSchristos      # This process acquired the lock.
3960bbc3b9fSchristos      "$@" -MD
39744269bb5Schristos      stat=$?
3980bbc3b9fSchristos      # Release the lock.
3990bbc3b9fSchristos      rmdir "$lockdir"
4000bbc3b9fSchristos      break
40144269bb5Schristos    else
4020bbc3b9fSchristos      # If the lock is being held by a different process, wait
4030bbc3b9fSchristos      # until the winning process is done or we timeout.
4040bbc3b9fSchristos      while test -d "$lockdir" && test $i -gt 0; do
4050bbc3b9fSchristos        sleep 1
4060bbc3b9fSchristos        i=`expr $i - 1`
4070bbc3b9fSchristos      done
4080bbc3b9fSchristos    fi
4090bbc3b9fSchristos    i=`expr $i - 1`
4100bbc3b9fSchristos  done
4110bbc3b9fSchristos  trap - 1 2 13 15
4120bbc3b9fSchristos  if test $i -le 0; then
4130bbc3b9fSchristos    echo "$0: failed to acquire lock after $numtries attempts" >&2
4140bbc3b9fSchristos    echo "$0: check lockdir '$lockdir'" >&2
4150bbc3b9fSchristos    exit 1
4160bbc3b9fSchristos  fi
4170bbc3b9fSchristos
4180bbc3b9fSchristos  if test $stat -ne 0; then
41944269bb5Schristos    rm -f "$tmpdepfile"
42044269bb5Schristos    exit $stat
42144269bb5Schristos  fi
42244269bb5Schristos  rm -f "$depfile"
42344269bb5Schristos  # Each line is of the form `foo.o: dependent.h',
42444269bb5Schristos  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
42544269bb5Schristos  # Do two passes, one to just change these to
42644269bb5Schristos  # `$object: dependent.h' and one to simply `dependent.h:'.
42744269bb5Schristos  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
42844269bb5Schristos  # Some versions of the HPUX 10.20 sed can't process this invocation
42944269bb5Schristos  # correctly.  Breaking it into two sed invocations is a workaround.
4300bbc3b9fSchristos  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
4310bbc3b9fSchristos    | sed -e 's/$/ :/' >> "$depfile"
43244269bb5Schristos  rm -f "$tmpdepfile"
43344269bb5Schristos  ;;
43444269bb5Schristos
43544269bb5Schristoshp2)
43644269bb5Schristos  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
43744269bb5Schristos  # compilers, which have integrated preprocessors.  The correct option
43844269bb5Schristos  # to use with these is +Maked; it writes dependencies to a file named
43944269bb5Schristos  # 'foo.d', which lands next to the object file, wherever that
44044269bb5Schristos  # happens to be.
44144269bb5Schristos  # Much of this is similar to the tru64 case; see comments there.
4420bbc3b9fSchristos  set_dir_from  "$object"
4430bbc3b9fSchristos  set_base_from "$object"
44444269bb5Schristos  if test "$libtool" = yes; then
44544269bb5Schristos    tmpdepfile1=$dir$base.d
44644269bb5Schristos    tmpdepfile2=$dir.libs/$base.d
44744269bb5Schristos    "$@" -Wc,+Maked
44844269bb5Schristos  else
44944269bb5Schristos    tmpdepfile1=$dir$base.d
45044269bb5Schristos    tmpdepfile2=$dir$base.d
45144269bb5Schristos    "$@" +Maked
45244269bb5Schristos  fi
45344269bb5Schristos  stat=$?
4540bbc3b9fSchristos  if test $stat -ne 0; then
45544269bb5Schristos     rm -f "$tmpdepfile1" "$tmpdepfile2"
45644269bb5Schristos     exit $stat
45744269bb5Schristos  fi
45844269bb5Schristos
45944269bb5Schristos  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
46044269bb5Schristos  do
46144269bb5Schristos    test -f "$tmpdepfile" && break
46244269bb5Schristos  done
46344269bb5Schristos  if test -f "$tmpdepfile"; then
4640bbc3b9fSchristos    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
4650bbc3b9fSchristos    # Add 'dependent.h:' lines.
46644269bb5Schristos    sed -ne '2,${
46744269bb5Schristos               s/^ *//
46844269bb5Schristos               s/ \\*$//
46944269bb5Schristos               s/$/:/
47044269bb5Schristos               p
47144269bb5Schristos             }' "$tmpdepfile" >> "$depfile"
47244269bb5Schristos  else
4730bbc3b9fSchristos    make_dummy_depfile
47444269bb5Schristos  fi
47544269bb5Schristos  rm -f "$tmpdepfile" "$tmpdepfile2"
47644269bb5Schristos  ;;
47744269bb5Schristos
47844269bb5Schristostru64)
47944269bb5Schristos  # The Tru64 compiler uses -MD to generate dependencies as a side
4800bbc3b9fSchristos  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
48144269bb5Schristos  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
4820bbc3b9fSchristos  # dependencies in 'foo.d' instead, so we check for that too.
48344269bb5Schristos  # Subdirectories are respected.
4840bbc3b9fSchristos  set_dir_from  "$object"
4850bbc3b9fSchristos  set_base_from "$object"
48644269bb5Schristos
48744269bb5Schristos  if test "$libtool" = yes; then
4880bbc3b9fSchristos    # Libtool generates 2 separate objects for the 2 libraries.  These
4890bbc3b9fSchristos    # two compilations output dependencies in $dir.libs/$base.o.d and
49044269bb5Schristos    # in $dir$base.o.d.  We have to check for both files, because
49144269bb5Schristos    # one of the two compilations can be disabled.  We should prefer
49244269bb5Schristos    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
49344269bb5Schristos    # automatically cleaned when .libs/ is deleted, while ignoring
49444269bb5Schristos    # the former would cause a distcleancheck panic.
4950bbc3b9fSchristos    tmpdepfile1=$dir$base.o.d          # libtool 1.5
4960bbc3b9fSchristos    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
4970bbc3b9fSchristos    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
49844269bb5Schristos    "$@" -Wc,-MD
49944269bb5Schristos  else
5000bbc3b9fSchristos    tmpdepfile1=$dir$base.d
50144269bb5Schristos    tmpdepfile2=$dir$base.d
50244269bb5Schristos    tmpdepfile3=$dir$base.d
50344269bb5Schristos    "$@" -MD
50444269bb5Schristos  fi
50544269bb5Schristos
50644269bb5Schristos  stat=$?
5070bbc3b9fSchristos  if test $stat -ne 0; then
5080bbc3b9fSchristos    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
50944269bb5Schristos    exit $stat
51044269bb5Schristos  fi
51144269bb5Schristos
5120bbc3b9fSchristos  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
51344269bb5Schristos  do
51444269bb5Schristos    test -f "$tmpdepfile" && break
51544269bb5Schristos  done
5160bbc3b9fSchristos  # Same post-processing that is required for AIX mode.
5170bbc3b9fSchristos  aix_post_process_depfile
5180bbc3b9fSchristos  ;;
5190bbc3b9fSchristos
5200bbc3b9fSchristosmsvc7)
5210bbc3b9fSchristos  if test "$libtool" = yes; then
5220bbc3b9fSchristos    showIncludes=-Wc,-showIncludes
52344269bb5Schristos  else
5240bbc3b9fSchristos    showIncludes=-showIncludes
52544269bb5Schristos  fi
5260bbc3b9fSchristos  "$@" $showIncludes > "$tmpdepfile"
5270bbc3b9fSchristos  stat=$?
5280bbc3b9fSchristos  grep -v '^Note: including file: ' "$tmpdepfile"
5290bbc3b9fSchristos  if test $stat -ne 0; then
53044269bb5Schristos    rm -f "$tmpdepfile"
5310bbc3b9fSchristos    exit $stat
5320bbc3b9fSchristos  fi
5330bbc3b9fSchristos  rm -f "$depfile"
5340bbc3b9fSchristos  echo "$object : \\" > "$depfile"
5350bbc3b9fSchristos  # The first sed program below extracts the file names and escapes
5360bbc3b9fSchristos  # backslashes for cygpath.  The second sed program outputs the file
5370bbc3b9fSchristos  # name when reading, but also accumulates all include files in the
5380bbc3b9fSchristos  # hold buffer in order to output them again at the end.  This only
5390bbc3b9fSchristos  # works with sed implementations that can handle large buffers.
5400bbc3b9fSchristos  sed < "$tmpdepfile" -n '
5410bbc3b9fSchristos/^Note: including file:  *\(.*\)/ {
5420bbc3b9fSchristos  s//\1/
5430bbc3b9fSchristos  s/\\/\\\\/g
5440bbc3b9fSchristos  p
5450bbc3b9fSchristos}' | $cygpath_u | sort -u | sed -n '
5460bbc3b9fSchristoss/ /\\ /g
5470bbc3b9fSchristoss/\(.*\)/'"$tab"'\1 \\/p
5480bbc3b9fSchristoss/.\(.*\) \\/\1:/
5490bbc3b9fSchristosH
5500bbc3b9fSchristos$ {
5510bbc3b9fSchristos  s/.*/'"$tab"'/
5520bbc3b9fSchristos  G
5530bbc3b9fSchristos  p
5540bbc3b9fSchristos}' >> "$depfile"
5550bbc3b9fSchristos  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
5560bbc3b9fSchristos  rm -f "$tmpdepfile"
5570bbc3b9fSchristos  ;;
5580bbc3b9fSchristos
5590bbc3b9fSchristosmsvc7msys)
5600bbc3b9fSchristos  # This case exists only to let depend.m4 do its work.  It works by
5610bbc3b9fSchristos  # looking at the text of this script.  This case will never be run,
5620bbc3b9fSchristos  # since it is checked for above.
5630bbc3b9fSchristos  exit 1
56444269bb5Schristos  ;;
56544269bb5Schristos
56644269bb5Schristos#nosideeffect)
56744269bb5Schristos  # This comment above is used by automake to tell side-effect
56844269bb5Schristos  # dependency tracking mechanisms from slower ones.
56944269bb5Schristos
57044269bb5Schristosdashmstdout)
57144269bb5Schristos  # Important note: in order to support this mode, a compiler *must*
57244269bb5Schristos  # always write the preprocessed file to stdout, regardless of -o.
57344269bb5Schristos  "$@" || exit $?
57444269bb5Schristos
57544269bb5Schristos  # Remove the call to Libtool.
57644269bb5Schristos  if test "$libtool" = yes; then
57744269bb5Schristos    while test "X$1" != 'X--mode=compile'; do
57844269bb5Schristos      shift
57944269bb5Schristos    done
58044269bb5Schristos    shift
58144269bb5Schristos  fi
58244269bb5Schristos
5830bbc3b9fSchristos  # Remove '-o $object'.
58444269bb5Schristos  IFS=" "
58544269bb5Schristos  for arg
58644269bb5Schristos  do
58744269bb5Schristos    case $arg in
58844269bb5Schristos    -o)
58944269bb5Schristos      shift
59044269bb5Schristos      ;;
59144269bb5Schristos    $object)
59244269bb5Schristos      shift
59344269bb5Schristos      ;;
59444269bb5Schristos    *)
59544269bb5Schristos      set fnord "$@" "$arg"
59644269bb5Schristos      shift # fnord
59744269bb5Schristos      shift # $arg
59844269bb5Schristos      ;;
59944269bb5Schristos    esac
60044269bb5Schristos  done
60144269bb5Schristos
60244269bb5Schristos  test -z "$dashmflag" && dashmflag=-M
6030bbc3b9fSchristos  # Require at least two characters before searching for ':'
60444269bb5Schristos  # in the target name.  This is to cope with DOS-style filenames:
6050bbc3b9fSchristos  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
60644269bb5Schristos  "$@" $dashmflag |
6070bbc3b9fSchristos    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
60844269bb5Schristos  rm -f "$depfile"
60944269bb5Schristos  cat < "$tmpdepfile" > "$depfile"
6100bbc3b9fSchristos  # Some versions of the HPUX 10.20 sed can't process this sed invocation
6110bbc3b9fSchristos  # correctly.  Breaking it into two sed invocations is a workaround.
6120bbc3b9fSchristos  tr ' ' "$nl" < "$tmpdepfile" \
6130bbc3b9fSchristos    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6140bbc3b9fSchristos    | sed -e 's/$/ :/' >> "$depfile"
61544269bb5Schristos  rm -f "$tmpdepfile"
61644269bb5Schristos  ;;
61744269bb5Schristos
61844269bb5SchristosdashXmstdout)
61944269bb5Schristos  # This case only exists to satisfy depend.m4.  It is never actually
62044269bb5Schristos  # run, as this mode is specially recognized in the preamble.
62144269bb5Schristos  exit 1
62244269bb5Schristos  ;;
62344269bb5Schristos
62444269bb5Schristosmakedepend)
62544269bb5Schristos  "$@" || exit $?
62644269bb5Schristos  # Remove any Libtool call
62744269bb5Schristos  if test "$libtool" = yes; then
62844269bb5Schristos    while test "X$1" != 'X--mode=compile'; do
62944269bb5Schristos      shift
63044269bb5Schristos    done
63144269bb5Schristos    shift
63244269bb5Schristos  fi
63344269bb5Schristos  # X makedepend
63444269bb5Schristos  shift
63544269bb5Schristos  cleared=no eat=no
63644269bb5Schristos  for arg
63744269bb5Schristos  do
63844269bb5Schristos    case $cleared in
63944269bb5Schristos    no)
64044269bb5Schristos      set ""; shift
64144269bb5Schristos      cleared=yes ;;
64244269bb5Schristos    esac
64344269bb5Schristos    if test $eat = yes; then
64444269bb5Schristos      eat=no
64544269bb5Schristos      continue
64644269bb5Schristos    fi
64744269bb5Schristos    case "$arg" in
64844269bb5Schristos    -D*|-I*)
64944269bb5Schristos      set fnord "$@" "$arg"; shift ;;
65044269bb5Schristos    # Strip any option that makedepend may not understand.  Remove
65144269bb5Schristos    # the object too, otherwise makedepend will parse it as a source file.
65244269bb5Schristos    -arch)
65344269bb5Schristos      eat=yes ;;
65444269bb5Schristos    -*|$object)
65544269bb5Schristos      ;;
65644269bb5Schristos    *)
65744269bb5Schristos      set fnord "$@" "$arg"; shift ;;
65844269bb5Schristos    esac
65944269bb5Schristos  done
66044269bb5Schristos  obj_suffix=`echo "$object" | sed 's/^.*\././'`
66144269bb5Schristos  touch "$tmpdepfile"
66244269bb5Schristos  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
66344269bb5Schristos  rm -f "$depfile"
6640bbc3b9fSchristos  # makedepend may prepend the VPATH from the source file name to the object.
6650bbc3b9fSchristos  # No need to regex-escape $object, excess matching of '.' is harmless.
6660bbc3b9fSchristos  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
6670bbc3b9fSchristos  # Some versions of the HPUX 10.20 sed can't process the last invocation
6680bbc3b9fSchristos  # correctly.  Breaking it into two sed invocations is a workaround.
6690bbc3b9fSchristos  sed '1,2d' "$tmpdepfile" \
6700bbc3b9fSchristos    | tr ' ' "$nl" \
6710bbc3b9fSchristos    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
6720bbc3b9fSchristos    | sed -e 's/$/ :/' >> "$depfile"
67344269bb5Schristos  rm -f "$tmpdepfile" "$tmpdepfile".bak
67444269bb5Schristos  ;;
67544269bb5Schristos
67644269bb5Schristoscpp)
67744269bb5Schristos  # Important note: in order to support this mode, a compiler *must*
67844269bb5Schristos  # always write the preprocessed file to stdout.
67944269bb5Schristos  "$@" || exit $?
68044269bb5Schristos
68144269bb5Schristos  # Remove the call to Libtool.
68244269bb5Schristos  if test "$libtool" = yes; then
68344269bb5Schristos    while test "X$1" != 'X--mode=compile'; do
68444269bb5Schristos      shift
68544269bb5Schristos    done
68644269bb5Schristos    shift
68744269bb5Schristos  fi
68844269bb5Schristos
6890bbc3b9fSchristos  # Remove '-o $object'.
69044269bb5Schristos  IFS=" "
69144269bb5Schristos  for arg
69244269bb5Schristos  do
69344269bb5Schristos    case $arg in
69444269bb5Schristos    -o)
69544269bb5Schristos      shift
69644269bb5Schristos      ;;
69744269bb5Schristos    $object)
69844269bb5Schristos      shift
69944269bb5Schristos      ;;
70044269bb5Schristos    *)
70144269bb5Schristos      set fnord "$@" "$arg"
70244269bb5Schristos      shift # fnord
70344269bb5Schristos      shift # $arg
70444269bb5Schristos      ;;
70544269bb5Schristos    esac
70644269bb5Schristos  done
70744269bb5Schristos
7080bbc3b9fSchristos  "$@" -E \
7090bbc3b9fSchristos    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7100bbc3b9fSchristos             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
7110bbc3b9fSchristos    | sed '$ s: \\$::' > "$tmpdepfile"
71244269bb5Schristos  rm -f "$depfile"
71344269bb5Schristos  echo "$object : \\" > "$depfile"
71444269bb5Schristos  cat < "$tmpdepfile" >> "$depfile"
71544269bb5Schristos  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
71644269bb5Schristos  rm -f "$tmpdepfile"
71744269bb5Schristos  ;;
71844269bb5Schristos
71944269bb5Schristosmsvisualcpp)
72044269bb5Schristos  # Important note: in order to support this mode, a compiler *must*
72144269bb5Schristos  # always write the preprocessed file to stdout.
72244269bb5Schristos  "$@" || exit $?
72344269bb5Schristos
72444269bb5Schristos  # Remove the call to Libtool.
72544269bb5Schristos  if test "$libtool" = yes; then
72644269bb5Schristos    while test "X$1" != 'X--mode=compile'; do
72744269bb5Schristos      shift
72844269bb5Schristos    done
72944269bb5Schristos    shift
73044269bb5Schristos  fi
73144269bb5Schristos
73244269bb5Schristos  IFS=" "
73344269bb5Schristos  for arg
73444269bb5Schristos  do
73544269bb5Schristos    case "$arg" in
73644269bb5Schristos    -o)
73744269bb5Schristos      shift
73844269bb5Schristos      ;;
73944269bb5Schristos    $object)
74044269bb5Schristos      shift
74144269bb5Schristos      ;;
74244269bb5Schristos    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
74344269bb5Schristos        set fnord "$@"
74444269bb5Schristos        shift
74544269bb5Schristos        shift
74644269bb5Schristos        ;;
74744269bb5Schristos    *)
74844269bb5Schristos        set fnord "$@" "$arg"
74944269bb5Schristos        shift
75044269bb5Schristos        shift
75144269bb5Schristos        ;;
75244269bb5Schristos    esac
75344269bb5Schristos  done
75444269bb5Schristos  "$@" -E 2>/dev/null |
75544269bb5Schristos  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
75644269bb5Schristos  rm -f "$depfile"
75744269bb5Schristos  echo "$object : \\" > "$depfile"
7580bbc3b9fSchristos  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
7590bbc3b9fSchristos  echo "$tab" >> "$depfile"
76044269bb5Schristos  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
76144269bb5Schristos  rm -f "$tmpdepfile"
76244269bb5Schristos  ;;
76344269bb5Schristos
76444269bb5Schristosmsvcmsys)
76544269bb5Schristos  # This case exists only to let depend.m4 do its work.  It works by
76644269bb5Schristos  # looking at the text of this script.  This case will never be run,
76744269bb5Schristos  # since it is checked for above.
76844269bb5Schristos  exit 1
76944269bb5Schristos  ;;
77044269bb5Schristos
77144269bb5Schristosnone)
77244269bb5Schristos  exec "$@"
77344269bb5Schristos  ;;
77444269bb5Schristos
77544269bb5Schristos*)
77644269bb5Schristos  echo "Unknown depmode $depmode" 1>&2
77744269bb5Schristos  exit 1
77844269bb5Schristos  ;;
77944269bb5Schristosesac
78044269bb5Schristos
78144269bb5Schristosexit 0
78244269bb5Schristos
78344269bb5Schristos# Local Variables:
78444269bb5Schristos# mode: shell-script
78544269bb5Schristos# sh-indentation: 2
78677513ecfSchristos# eval: (add-hook 'before-save-hook 'time-stamp)
78744269bb5Schristos# time-stamp-start: "scriptversion="
78844269bb5Schristos# time-stamp-format: "%:y-%02m-%02d.%02H"
78977513ecfSchristos# time-stamp-time-zone: "UTC0"
79044269bb5Schristos# time-stamp-end: "; # UTC"
79144269bb5Schristos# End:
792