Home | History | Annotate | Line # | Download | only in dist
      1      1.1  christos #! /bin/sh
      2      1.1  christos # depcomp - compile a program generating dependencies as side-effects
      3      1.1  christos 
      4  1.1.1.2  christos scriptversion=2013-05-30.07; # UTC
      5      1.1  christos 
      6  1.1.1.2  christos # Copyright (C) 1999-2014 Free Software Foundation, Inc.
      7      1.1  christos 
      8      1.1  christos # This program is free software; you can redistribute it and/or modify
      9      1.1  christos # it under the terms of the GNU General Public License as published by
     10      1.1  christos # the Free Software Foundation; either version 2, or (at your option)
     11      1.1  christos # any later version.
     12      1.1  christos 
     13      1.1  christos # This program is distributed in the hope that it will be useful,
     14      1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     15      1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16      1.1  christos # GNU General Public License for more details.
     17      1.1  christos 
     18      1.1  christos # You should have received a copy of the GNU General Public License
     19      1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     20      1.1  christos 
     21      1.1  christos # As a special exception to the GNU General Public License, if you
     22      1.1  christos # distribute this file as part of a program that contains a
     23      1.1  christos # configuration script generated by Autoconf, you may include it under
     24      1.1  christos # the same distribution terms that you use for the rest of that program.
     25      1.1  christos 
     26      1.1  christos # Originally written by Alexandre Oliva <oliva (at] dcc.unicamp.br>.
     27      1.1  christos 
     28      1.1  christos case $1 in
     29      1.1  christos   '')
     30  1.1.1.2  christos     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
     31  1.1.1.2  christos     exit 1;
     32  1.1.1.2  christos     ;;
     33      1.1  christos   -h | --h*)
     34      1.1  christos     cat <<\EOF
     35      1.1  christos Usage: depcomp [--help] [--version] PROGRAM [ARGS]
     36      1.1  christos 
     37      1.1  christos Run PROGRAMS ARGS to compile a file, generating dependencies
     38      1.1  christos as side-effects.
     39      1.1  christos 
     40      1.1  christos Environment variables:
     41      1.1  christos   depmode     Dependency tracking mode.
     42  1.1.1.2  christos   source      Source file read by 'PROGRAMS ARGS'.
     43  1.1.1.2  christos   object      Object file output by 'PROGRAMS ARGS'.
     44      1.1  christos   DEPDIR      directory where to store dependencies.
     45      1.1  christos   depfile     Dependency file to output.
     46  1.1.1.2  christos   tmpdepfile  Temporary file to use when outputting dependencies.
     47      1.1  christos   libtool     Whether libtool is used (yes/no).
     48      1.1  christos 
     49      1.1  christos Report bugs to <bug-automake@gnu.org>.
     50      1.1  christos EOF
     51      1.1  christos     exit $?
     52      1.1  christos     ;;
     53      1.1  christos   -v | --v*)
     54      1.1  christos     echo "depcomp $scriptversion"
     55      1.1  christos     exit $?
     56      1.1  christos     ;;
     57      1.1  christos esac
     58      1.1  christos 
     59  1.1.1.2  christos # Get the directory component of the given path, and save it in the
     60  1.1.1.2  christos # global variables '$dir'.  Note that this directory component will
     61  1.1.1.2  christos # be either empty or ending with a '/' character.  This is deliberate.
     62  1.1.1.2  christos set_dir_from ()
     63  1.1.1.2  christos {
     64  1.1.1.2  christos   case $1 in
     65  1.1.1.2  christos     */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
     66  1.1.1.2  christos       *) dir=;;
     67  1.1.1.2  christos   esac
     68  1.1.1.2  christos }
     69  1.1.1.2  christos 
     70  1.1.1.2  christos # Get the suffix-stripped basename of the given path, and save it the
     71  1.1.1.2  christos # global variable '$base'.
     72  1.1.1.2  christos set_base_from ()
     73  1.1.1.2  christos {
     74  1.1.1.2  christos   base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
     75  1.1.1.2  christos }
     76  1.1.1.2  christos 
     77  1.1.1.2  christos # If no dependency file was actually created by the compiler invocation,
     78  1.1.1.2  christos # we still have to create a dummy depfile, to avoid errors with the
     79  1.1.1.2  christos # Makefile "include basename.Plo" scheme.
     80  1.1.1.2  christos make_dummy_depfile ()
     81  1.1.1.2  christos {
     82  1.1.1.2  christos   echo "#dummy" > "$depfile"
     83  1.1.1.2  christos }
     84  1.1.1.2  christos 
     85  1.1.1.2  christos # Factor out some common post-processing of the generated depfile.
     86  1.1.1.2  christos # Requires the auxiliary global variable '$tmpdepfile' to be set.
     87  1.1.1.2  christos aix_post_process_depfile ()
     88  1.1.1.2  christos {
     89  1.1.1.2  christos   # If the compiler actually managed to produce a dependency file,
     90  1.1.1.2  christos   # post-process it.
     91  1.1.1.2  christos   if test -f "$tmpdepfile"; then
     92  1.1.1.2  christos     # Each line is of the form 'foo.o: dependency.h'.
     93  1.1.1.2  christos     # Do two passes, one to just change these to
     94  1.1.1.2  christos     #   $object: dependency.h
     95  1.1.1.2  christos     # and one to simply output
     96  1.1.1.2  christos     #   dependency.h:
     97  1.1.1.2  christos     # which is needed to avoid the deleted-header problem.
     98  1.1.1.2  christos     { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
     99  1.1.1.2  christos       sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
    100  1.1.1.2  christos     } > "$depfile"
    101  1.1.1.2  christos     rm -f "$tmpdepfile"
    102  1.1.1.2  christos   else
    103  1.1.1.2  christos     make_dummy_depfile
    104  1.1.1.2  christos   fi
    105  1.1.1.2  christos }
    106  1.1.1.2  christos 
    107  1.1.1.2  christos # A tabulation character.
    108  1.1.1.2  christos tab='	'
    109  1.1.1.2  christos # A newline character.
    110  1.1.1.2  christos nl='
    111  1.1.1.2  christos '
    112  1.1.1.2  christos # Character ranges might be problematic outside the C locale.
    113  1.1.1.2  christos # These definitions help.
    114  1.1.1.2  christos upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
    115  1.1.1.2  christos lower=abcdefghijklmnopqrstuvwxyz
    116  1.1.1.2  christos digits=0123456789
    117  1.1.1.2  christos alpha=${upper}${lower}
    118  1.1.1.2  christos 
    119      1.1  christos if test -z "$depmode" || test -z "$source" || test -z "$object"; then
    120      1.1  christos   echo "depcomp: Variables source, object and depmode must be set" 1>&2
    121      1.1  christos   exit 1
    122      1.1  christos fi
    123      1.1  christos 
    124      1.1  christos # Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
    125      1.1  christos depfile=${depfile-`echo "$object" |
    126      1.1  christos   sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
    127      1.1  christos tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
    128      1.1  christos 
    129      1.1  christos rm -f "$tmpdepfile"
    130      1.1  christos 
    131  1.1.1.2  christos # Avoid interferences from the environment.
    132  1.1.1.2  christos gccflag= dashmflag=
    133  1.1.1.2  christos 
    134      1.1  christos # Some modes work just like other modes, but use different flags.  We
    135      1.1  christos # parameterize here, but still list the modes in the big case below,
    136      1.1  christos # to make depend.m4 easier to write.  Note that we *cannot* use a case
    137      1.1  christos # here, because this file can only contain one case statement.
    138      1.1  christos if test "$depmode" = hp; then
    139      1.1  christos   # HP compiler uses -M and no extra arg.
    140      1.1  christos   gccflag=-M
    141      1.1  christos   depmode=gcc
    142      1.1  christos fi
    143      1.1  christos 
    144      1.1  christos if test "$depmode" = dashXmstdout; then
    145  1.1.1.2  christos   # This is just like dashmstdout with a different argument.
    146  1.1.1.2  christos   dashmflag=-xM
    147  1.1.1.2  christos   depmode=dashmstdout
    148      1.1  christos fi
    149      1.1  christos 
    150      1.1  christos cygpath_u="cygpath -u -f -"
    151      1.1  christos if test "$depmode" = msvcmsys; then
    152  1.1.1.2  christos   # This is just like msvisualcpp but w/o cygpath translation.
    153  1.1.1.2  christos   # Just convert the backslash-escaped backslashes to single forward
    154  1.1.1.2  christos   # slashes to satisfy depend.m4
    155  1.1.1.2  christos   cygpath_u='sed s,\\\\,/,g'
    156  1.1.1.2  christos   depmode=msvisualcpp
    157  1.1.1.2  christos fi
    158  1.1.1.2  christos 
    159  1.1.1.2  christos if test "$depmode" = msvc7msys; then
    160  1.1.1.2  christos   # This is just like msvc7 but w/o cygpath translation.
    161  1.1.1.2  christos   # Just convert the backslash-escaped backslashes to single forward
    162  1.1.1.2  christos   # slashes to satisfy depend.m4
    163  1.1.1.2  christos   cygpath_u='sed s,\\\\,/,g'
    164  1.1.1.2  christos   depmode=msvc7
    165  1.1.1.2  christos fi
    166  1.1.1.2  christos 
    167  1.1.1.2  christos if test "$depmode" = xlc; then
    168  1.1.1.2  christos   # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
    169  1.1.1.2  christos   gccflag=-qmakedep=gcc,-MF
    170  1.1.1.2  christos   depmode=gcc
    171      1.1  christos fi
    172      1.1  christos 
    173      1.1  christos case "$depmode" in
    174      1.1  christos gcc3)
    175      1.1  christos ## gcc 3 implements dependency tracking that does exactly what
    176      1.1  christos ## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
    177      1.1  christos ## it if -MD -MP comes after the -MF stuff.  Hmm.
    178      1.1  christos ## Unfortunately, FreeBSD c89 acceptance of flags depends upon
    179      1.1  christos ## the command line argument order; so add the flags where they
    180      1.1  christos ## appear in depend2.am.  Note that the slowdown incurred here
    181      1.1  christos ## affects only configure: in makefiles, %FASTDEP% shortcuts this.
    182      1.1  christos   for arg
    183      1.1  christos   do
    184      1.1  christos     case $arg in
    185      1.1  christos     -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
    186      1.1  christos     *)  set fnord "$@" "$arg" ;;
    187      1.1  christos     esac
    188      1.1  christos     shift # fnord
    189      1.1  christos     shift # $arg
    190      1.1  christos   done
    191      1.1  christos   "$@"
    192      1.1  christos   stat=$?
    193  1.1.1.2  christos   if test $stat -ne 0; then
    194      1.1  christos     rm -f "$tmpdepfile"
    195      1.1  christos     exit $stat
    196      1.1  christos   fi
    197      1.1  christos   mv "$tmpdepfile" "$depfile"
    198      1.1  christos   ;;
    199      1.1  christos 
    200      1.1  christos gcc)
    201  1.1.1.2  christos ## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
    202  1.1.1.2  christos ## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
    203  1.1.1.2  christos ## (see the conditional assignment to $gccflag above).
    204      1.1  christos ## There are various ways to get dependency output from gcc.  Here's
    205      1.1  christos ## why we pick this rather obscure method:
    206      1.1  christos ## - Don't want to use -MD because we'd like the dependencies to end
    207      1.1  christos ##   up in a subdir.  Having to rename by hand is ugly.
    208      1.1  christos ##   (We might end up doing this anyway to support other compilers.)
    209      1.1  christos ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
    210  1.1.1.2  christos ##   -MM, not -M (despite what the docs say).  Also, it might not be
    211  1.1.1.2  christos ##   supported by the other compilers which use the 'gcc' depmode.
    212      1.1  christos ## - Using -M directly means running the compiler twice (even worse
    213      1.1  christos ##   than renaming).
    214      1.1  christos   if test -z "$gccflag"; then
    215      1.1  christos     gccflag=-MD,
    216      1.1  christos   fi
    217      1.1  christos   "$@" -Wp,"$gccflag$tmpdepfile"
    218      1.1  christos   stat=$?
    219  1.1.1.2  christos   if test $stat -ne 0; then
    220      1.1  christos     rm -f "$tmpdepfile"
    221      1.1  christos     exit $stat
    222      1.1  christos   fi
    223      1.1  christos   rm -f "$depfile"
    224      1.1  christos   echo "$object : \\" > "$depfile"
    225  1.1.1.2  christos   # The second -e expression handles DOS-style file names with drive
    226  1.1.1.2  christos   # letters.
    227      1.1  christos   sed -e 's/^[^:]*: / /' \
    228      1.1  christos       -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
    229  1.1.1.2  christos ## This next piece of magic avoids the "deleted header file" problem.
    230      1.1  christos ## The problem is that when a header file which appears in a .P file
    231      1.1  christos ## is deleted, the dependency causes make to die (because there is
    232      1.1  christos ## typically no way to rebuild the header).  We avoid this by adding
    233      1.1  christos ## dummy dependencies for each header file.  Too bad gcc doesn't do
    234      1.1  christos ## this for us directly.
    235  1.1.1.2  christos ## Some versions of gcc put a space before the ':'.  On the theory
    236      1.1  christos ## that the space means something, we add a space to the output as
    237  1.1.1.2  christos ## well.  hp depmode also adds that space, but also prefixes the VPATH
    238  1.1.1.2  christos ## to the object.  Take care to not repeat it in the output.
    239      1.1  christos ## Some versions of the HPUX 10.20 sed can't process this invocation
    240      1.1  christos ## correctly.  Breaking it into two sed invocations is a workaround.
    241  1.1.1.2  christos   tr ' ' "$nl" < "$tmpdepfile" \
    242  1.1.1.2  christos     | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
    243  1.1.1.2  christos     | sed -e 's/$/ :/' >> "$depfile"
    244      1.1  christos   rm -f "$tmpdepfile"
    245      1.1  christos   ;;
    246      1.1  christos 
    247      1.1  christos hp)
    248      1.1  christos   # This case exists only to let depend.m4 do its work.  It works by
    249      1.1  christos   # looking at the text of this script.  This case will never be run,
    250      1.1  christos   # since it is checked for above.
    251      1.1  christos   exit 1
    252      1.1  christos   ;;
    253      1.1  christos 
    254  1.1.1.2  christos xlc)
    255  1.1.1.2  christos   # This case exists only to let depend.m4 do its work.  It works by
    256  1.1.1.2  christos   # looking at the text of this script.  This case will never be run,
    257  1.1.1.2  christos   # since it is checked for above.
    258  1.1.1.2  christos   exit 1
    259      1.1  christos   ;;
    260      1.1  christos 
    261      1.1  christos aix)
    262      1.1  christos   # The C for AIX Compiler uses -M and outputs the dependencies
    263      1.1  christos   # in a .u file.  In older versions, this file always lives in the
    264  1.1.1.2  christos   # current directory.  Also, the AIX compiler puts '$object:' at the
    265      1.1  christos   # start of each line; $object doesn't have directory information.
    266      1.1  christos   # Version 6 uses the directory in both cases.
    267  1.1.1.2  christos   set_dir_from "$object"
    268  1.1.1.2  christos   set_base_from "$object"
    269      1.1  christos   if test "$libtool" = yes; then
    270      1.1  christos     tmpdepfile1=$dir$base.u
    271      1.1  christos     tmpdepfile2=$base.u
    272      1.1  christos     tmpdepfile3=$dir.libs/$base.u
    273      1.1  christos     "$@" -Wc,-M
    274      1.1  christos   else
    275      1.1  christos     tmpdepfile1=$dir$base.u
    276      1.1  christos     tmpdepfile2=$dir$base.u
    277      1.1  christos     tmpdepfile3=$dir$base.u
    278      1.1  christos     "$@" -M
    279      1.1  christos   fi
    280      1.1  christos   stat=$?
    281  1.1.1.2  christos   if test $stat -ne 0; then
    282      1.1  christos     rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
    283      1.1  christos     exit $stat
    284      1.1  christos   fi
    285      1.1  christos 
    286      1.1  christos   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
    287      1.1  christos   do
    288      1.1  christos     test -f "$tmpdepfile" && break
    289      1.1  christos   done
    290  1.1.1.2  christos   aix_post_process_depfile
    291  1.1.1.2  christos   ;;
    292  1.1.1.2  christos 
    293  1.1.1.2  christos tcc)
    294  1.1.1.2  christos   # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
    295  1.1.1.2  christos   # FIXME: That version still under development at the moment of writing.
    296  1.1.1.2  christos   #        Make that this statement remains true also for stable, released
    297  1.1.1.2  christos   #        versions.
    298  1.1.1.2  christos   # It will wrap lines (doesn't matter whether long or short) with a
    299  1.1.1.2  christos   # trailing '\', as in:
    300  1.1.1.2  christos   #
    301  1.1.1.2  christos   #   foo.o : \
    302  1.1.1.2  christos   #    foo.c \
    303  1.1.1.2  christos   #    foo.h \
    304  1.1.1.2  christos   #
    305  1.1.1.2  christos   # It will put a trailing '\' even on the last line, and will use leading
    306  1.1.1.2  christos   # spaces rather than leading tabs (at least since its commit 0394caf7
    307  1.1.1.2  christos   # "Emit spaces for -MD").
    308  1.1.1.2  christos   "$@" -MD -MF "$tmpdepfile"
    309  1.1.1.2  christos   stat=$?
    310  1.1.1.2  christos   if test $stat -ne 0; then
    311  1.1.1.2  christos     rm -f "$tmpdepfile"
    312  1.1.1.2  christos     exit $stat
    313      1.1  christos   fi
    314  1.1.1.2  christos   rm -f "$depfile"
    315  1.1.1.2  christos   # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
    316  1.1.1.2  christos   # We have to change lines of the first kind to '$object: \'.
    317  1.1.1.2  christos   sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
    318  1.1.1.2  christos   # And for each line of the second kind, we have to emit a 'dep.h:'
    319  1.1.1.2  christos   # dummy dependency, to avoid the deleted-header problem.
    320  1.1.1.2  christos   sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
    321      1.1  christos   rm -f "$tmpdepfile"
    322      1.1  christos   ;;
    323      1.1  christos 
    324  1.1.1.2  christos ## The order of this option in the case statement is important, since the
    325  1.1.1.2  christos ## shell code in configure will try each of these formats in the order
    326  1.1.1.2  christos ## listed in this file.  A plain '-MD' option would be understood by many
    327  1.1.1.2  christos ## compilers, so we must ensure this comes after the gcc and icc options.
    328  1.1.1.2  christos pgcc)
    329  1.1.1.2  christos   # Portland's C compiler understands '-MD'.
    330  1.1.1.2  christos   # Will always output deps to 'file.d' where file is the root name of the
    331  1.1.1.2  christos   # source file under compilation, even if file resides in a subdirectory.
    332  1.1.1.2  christos   # The object file name does not affect the name of the '.d' file.
    333  1.1.1.2  christos   # pgcc 10.2 will output
    334      1.1  christos   #    foo.o: sub/foo.c sub/foo.h
    335  1.1.1.2  christos   # and will wrap long lines using '\' :
    336      1.1  christos   #    foo.o: sub/foo.c ... \
    337      1.1  christos   #     sub/foo.h ... \
    338      1.1  christos   #     ...
    339  1.1.1.2  christos   set_dir_from "$object"
    340  1.1.1.2  christos   # Use the source, not the object, to determine the base name, since
    341  1.1.1.2  christos   # that's sadly what pgcc will do too.
    342  1.1.1.2  christos   set_base_from "$source"
    343  1.1.1.2  christos   tmpdepfile=$base.d
    344  1.1.1.2  christos 
    345  1.1.1.2  christos   # For projects that build the same source file twice into different object
    346  1.1.1.2  christos   # files, the pgcc approach of using the *source* file root name can cause
    347  1.1.1.2  christos   # problems in parallel builds.  Use a locking strategy to avoid stomping on
    348  1.1.1.2  christos   # the same $tmpdepfile.
    349  1.1.1.2  christos   lockdir=$base.d-lock
    350  1.1.1.2  christos   trap "
    351  1.1.1.2  christos     echo '$0: caught signal, cleaning up...' >&2
    352  1.1.1.2  christos     rmdir '$lockdir'
    353  1.1.1.2  christos     exit 1
    354  1.1.1.2  christos   " 1 2 13 15
    355  1.1.1.2  christos   numtries=100
    356  1.1.1.2  christos   i=$numtries
    357  1.1.1.2  christos   while test $i -gt 0; do
    358  1.1.1.2  christos     # mkdir is a portable test-and-set.
    359  1.1.1.2  christos     if mkdir "$lockdir" 2>/dev/null; then
    360  1.1.1.2  christos       # This process acquired the lock.
    361  1.1.1.2  christos       "$@" -MD
    362  1.1.1.2  christos       stat=$?
    363  1.1.1.2  christos       # Release the lock.
    364  1.1.1.2  christos       rmdir "$lockdir"
    365  1.1.1.2  christos       break
    366  1.1.1.2  christos     else
    367  1.1.1.2  christos       # If the lock is being held by a different process, wait
    368  1.1.1.2  christos       # until the winning process is done or we timeout.
    369  1.1.1.2  christos       while test -d "$lockdir" && test $i -gt 0; do
    370  1.1.1.2  christos         sleep 1
    371  1.1.1.2  christos         i=`expr $i - 1`
    372  1.1.1.2  christos       done
    373  1.1.1.2  christos     fi
    374  1.1.1.2  christos     i=`expr $i - 1`
    375  1.1.1.2  christos   done
    376  1.1.1.2  christos   trap - 1 2 13 15
    377  1.1.1.2  christos   if test $i -le 0; then
    378  1.1.1.2  christos     echo "$0: failed to acquire lock after $numtries attempts" >&2
    379  1.1.1.2  christos     echo "$0: check lockdir '$lockdir'" >&2
    380  1.1.1.2  christos     exit 1
    381  1.1.1.2  christos   fi
    382      1.1  christos 
    383  1.1.1.2  christos   if test $stat -ne 0; then
    384      1.1  christos     rm -f "$tmpdepfile"
    385      1.1  christos     exit $stat
    386      1.1  christos   fi
    387      1.1  christos   rm -f "$depfile"
    388      1.1  christos   # Each line is of the form `foo.o: dependent.h',
    389      1.1  christos   # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
    390      1.1  christos   # Do two passes, one to just change these to
    391      1.1  christos   # `$object: dependent.h' and one to simply `dependent.h:'.
    392      1.1  christos   sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
    393      1.1  christos   # Some versions of the HPUX 10.20 sed can't process this invocation
    394      1.1  christos   # correctly.  Breaking it into two sed invocations is a workaround.
    395  1.1.1.2  christos   sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
    396  1.1.1.2  christos     | sed -e 's/$/ :/' >> "$depfile"
    397      1.1  christos   rm -f "$tmpdepfile"
    398      1.1  christos   ;;
    399      1.1  christos 
    400      1.1  christos hp2)
    401      1.1  christos   # The "hp" stanza above does not work with aCC (C++) and HP's ia64
    402      1.1  christos   # compilers, which have integrated preprocessors.  The correct option
    403      1.1  christos   # to use with these is +Maked; it writes dependencies to a file named
    404      1.1  christos   # 'foo.d', which lands next to the object file, wherever that
    405      1.1  christos   # happens to be.
    406      1.1  christos   # Much of this is similar to the tru64 case; see comments there.
    407  1.1.1.2  christos   set_dir_from  "$object"
    408  1.1.1.2  christos   set_base_from "$object"
    409      1.1  christos   if test "$libtool" = yes; then
    410      1.1  christos     tmpdepfile1=$dir$base.d
    411      1.1  christos     tmpdepfile2=$dir.libs/$base.d
    412      1.1  christos     "$@" -Wc,+Maked
    413      1.1  christos   else
    414      1.1  christos     tmpdepfile1=$dir$base.d
    415      1.1  christos     tmpdepfile2=$dir$base.d
    416      1.1  christos     "$@" +Maked
    417      1.1  christos   fi
    418      1.1  christos   stat=$?
    419  1.1.1.2  christos   if test $stat -ne 0; then
    420      1.1  christos      rm -f "$tmpdepfile1" "$tmpdepfile2"
    421      1.1  christos      exit $stat
    422      1.1  christos   fi
    423      1.1  christos 
    424      1.1  christos   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
    425      1.1  christos   do
    426      1.1  christos     test -f "$tmpdepfile" && break
    427      1.1  christos   done
    428      1.1  christos   if test -f "$tmpdepfile"; then
    429  1.1.1.2  christos     sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
    430  1.1.1.2  christos     # Add 'dependent.h:' lines.
    431      1.1  christos     sed -ne '2,${
    432  1.1.1.2  christos                s/^ *//
    433  1.1.1.2  christos                s/ \\*$//
    434  1.1.1.2  christos                s/$/:/
    435  1.1.1.2  christos                p
    436  1.1.1.2  christos              }' "$tmpdepfile" >> "$depfile"
    437      1.1  christos   else
    438  1.1.1.2  christos     make_dummy_depfile
    439      1.1  christos   fi
    440      1.1  christos   rm -f "$tmpdepfile" "$tmpdepfile2"
    441      1.1  christos   ;;
    442      1.1  christos 
    443      1.1  christos tru64)
    444  1.1.1.2  christos   # The Tru64 compiler uses -MD to generate dependencies as a side
    445  1.1.1.2  christos   # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
    446  1.1.1.2  christos   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
    447  1.1.1.2  christos   # dependencies in 'foo.d' instead, so we check for that too.
    448  1.1.1.2  christos   # Subdirectories are respected.
    449  1.1.1.2  christos   set_dir_from  "$object"
    450  1.1.1.2  christos   set_base_from "$object"
    451  1.1.1.2  christos 
    452  1.1.1.2  christos   if test "$libtool" = yes; then
    453  1.1.1.2  christos     # Libtool generates 2 separate objects for the 2 libraries.  These
    454  1.1.1.2  christos     # two compilations output dependencies in $dir.libs/$base.o.d and
    455  1.1.1.2  christos     # in $dir$base.o.d.  We have to check for both files, because
    456  1.1.1.2  christos     # one of the two compilations can be disabled.  We should prefer
    457  1.1.1.2  christos     # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
    458  1.1.1.2  christos     # automatically cleaned when .libs/ is deleted, while ignoring
    459  1.1.1.2  christos     # the former would cause a distcleancheck panic.
    460  1.1.1.2  christos     tmpdepfile1=$dir$base.o.d          # libtool 1.5
    461  1.1.1.2  christos     tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
    462  1.1.1.2  christos     tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
    463  1.1.1.2  christos     "$@" -Wc,-MD
    464  1.1.1.2  christos   else
    465  1.1.1.2  christos     tmpdepfile1=$dir$base.d
    466  1.1.1.2  christos     tmpdepfile2=$dir$base.d
    467  1.1.1.2  christos     tmpdepfile3=$dir$base.d
    468  1.1.1.2  christos     "$@" -MD
    469  1.1.1.2  christos   fi
    470  1.1.1.2  christos 
    471  1.1.1.2  christos   stat=$?
    472  1.1.1.2  christos   if test $stat -ne 0; then
    473  1.1.1.2  christos     rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
    474  1.1.1.2  christos     exit $stat
    475  1.1.1.2  christos   fi
    476  1.1.1.2  christos 
    477  1.1.1.2  christos   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
    478  1.1.1.2  christos   do
    479  1.1.1.2  christos     test -f "$tmpdepfile" && break
    480  1.1.1.2  christos   done
    481  1.1.1.2  christos   # Same post-processing that is required for AIX mode.
    482  1.1.1.2  christos   aix_post_process_depfile
    483  1.1.1.2  christos   ;;
    484      1.1  christos 
    485  1.1.1.2  christos msvc7)
    486  1.1.1.2  christos   if test "$libtool" = yes; then
    487  1.1.1.2  christos     showIncludes=-Wc,-showIncludes
    488  1.1.1.2  christos   else
    489  1.1.1.2  christos     showIncludes=-showIncludes
    490  1.1.1.2  christos   fi
    491  1.1.1.2  christos   "$@" $showIncludes > "$tmpdepfile"
    492  1.1.1.2  christos   stat=$?
    493  1.1.1.2  christos   grep -v '^Note: including file: ' "$tmpdepfile"
    494  1.1.1.2  christos   if test $stat -ne 0; then
    495  1.1.1.2  christos     rm -f "$tmpdepfile"
    496  1.1.1.2  christos     exit $stat
    497  1.1.1.2  christos   fi
    498  1.1.1.2  christos   rm -f "$depfile"
    499  1.1.1.2  christos   echo "$object : \\" > "$depfile"
    500  1.1.1.2  christos   # The first sed program below extracts the file names and escapes
    501  1.1.1.2  christos   # backslashes for cygpath.  The second sed program outputs the file
    502  1.1.1.2  christos   # name when reading, but also accumulates all include files in the
    503  1.1.1.2  christos   # hold buffer in order to output them again at the end.  This only
    504  1.1.1.2  christos   # works with sed implementations that can handle large buffers.
    505  1.1.1.2  christos   sed < "$tmpdepfile" -n '
    506  1.1.1.2  christos /^Note: including file:  *\(.*\)/ {
    507  1.1.1.2  christos   s//\1/
    508  1.1.1.2  christos   s/\\/\\\\/g
    509  1.1.1.2  christos   p
    510  1.1.1.2  christos }' | $cygpath_u | sort -u | sed -n '
    511  1.1.1.2  christos s/ /\\ /g
    512  1.1.1.2  christos s/\(.*\)/'"$tab"'\1 \\/p
    513  1.1.1.2  christos s/.\(.*\) \\/\1:/
    514  1.1.1.2  christos H
    515  1.1.1.2  christos $ {
    516  1.1.1.2  christos   s/.*/'"$tab"'/
    517  1.1.1.2  christos   G
    518  1.1.1.2  christos   p
    519  1.1.1.2  christos }' >> "$depfile"
    520  1.1.1.2  christos   echo >> "$depfile" # make sure the fragment doesn't end with a backslash
    521  1.1.1.2  christos   rm -f "$tmpdepfile"
    522  1.1.1.2  christos   ;;
    523  1.1.1.2  christos 
    524  1.1.1.2  christos msvc7msys)
    525  1.1.1.2  christos   # This case exists only to let depend.m4 do its work.  It works by
    526  1.1.1.2  christos   # looking at the text of this script.  This case will never be run,
    527  1.1.1.2  christos   # since it is checked for above.
    528  1.1.1.2  christos   exit 1
    529  1.1.1.2  christos   ;;
    530      1.1  christos 
    531      1.1  christos #nosideeffect)
    532      1.1  christos   # This comment above is used by automake to tell side-effect
    533      1.1  christos   # dependency tracking mechanisms from slower ones.
    534      1.1  christos 
    535      1.1  christos dashmstdout)
    536      1.1  christos   # Important note: in order to support this mode, a compiler *must*
    537      1.1  christos   # always write the preprocessed file to stdout, regardless of -o.
    538      1.1  christos   "$@" || exit $?
    539      1.1  christos 
    540      1.1  christos   # Remove the call to Libtool.
    541      1.1  christos   if test "$libtool" = yes; then
    542      1.1  christos     while test "X$1" != 'X--mode=compile'; do
    543      1.1  christos       shift
    544      1.1  christos     done
    545      1.1  christos     shift
    546      1.1  christos   fi
    547      1.1  christos 
    548  1.1.1.2  christos   # Remove '-o $object'.
    549      1.1  christos   IFS=" "
    550      1.1  christos   for arg
    551      1.1  christos   do
    552      1.1  christos     case $arg in
    553      1.1  christos     -o)
    554      1.1  christos       shift
    555      1.1  christos       ;;
    556      1.1  christos     $object)
    557      1.1  christos       shift
    558      1.1  christos       ;;
    559      1.1  christos     *)
    560      1.1  christos       set fnord "$@" "$arg"
    561      1.1  christos       shift # fnord
    562      1.1  christos       shift # $arg
    563      1.1  christos       ;;
    564      1.1  christos     esac
    565      1.1  christos   done
    566      1.1  christos 
    567      1.1  christos   test -z "$dashmflag" && dashmflag=-M
    568  1.1.1.2  christos   # Require at least two characters before searching for ':'
    569      1.1  christos   # in the target name.  This is to cope with DOS-style filenames:
    570  1.1.1.2  christos   # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
    571      1.1  christos   "$@" $dashmflag |
    572  1.1.1.2  christos     sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
    573      1.1  christos   rm -f "$depfile"
    574      1.1  christos   cat < "$tmpdepfile" > "$depfile"
    575  1.1.1.2  christos   # Some versions of the HPUX 10.20 sed can't process this sed invocation
    576  1.1.1.2  christos   # correctly.  Breaking it into two sed invocations is a workaround.
    577  1.1.1.2  christos   tr ' ' "$nl" < "$tmpdepfile" \
    578  1.1.1.2  christos     | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
    579  1.1.1.2  christos     | sed -e 's/$/ :/' >> "$depfile"
    580      1.1  christos   rm -f "$tmpdepfile"
    581      1.1  christos   ;;
    582      1.1  christos 
    583      1.1  christos dashXmstdout)
    584      1.1  christos   # This case only exists to satisfy depend.m4.  It is never actually
    585      1.1  christos   # run, as this mode is specially recognized in the preamble.
    586      1.1  christos   exit 1
    587      1.1  christos   ;;
    588      1.1  christos 
    589      1.1  christos makedepend)
    590      1.1  christos   "$@" || exit $?
    591      1.1  christos   # Remove any Libtool call
    592      1.1  christos   if test "$libtool" = yes; then
    593      1.1  christos     while test "X$1" != 'X--mode=compile'; do
    594      1.1  christos       shift
    595      1.1  christos     done
    596      1.1  christos     shift
    597      1.1  christos   fi
    598      1.1  christos   # X makedepend
    599      1.1  christos   shift
    600      1.1  christos   cleared=no eat=no
    601      1.1  christos   for arg
    602      1.1  christos   do
    603      1.1  christos     case $cleared in
    604      1.1  christos     no)
    605      1.1  christos       set ""; shift
    606      1.1  christos       cleared=yes ;;
    607      1.1  christos     esac
    608      1.1  christos     if test $eat = yes; then
    609      1.1  christos       eat=no
    610      1.1  christos       continue
    611      1.1  christos     fi
    612      1.1  christos     case "$arg" in
    613      1.1  christos     -D*|-I*)
    614      1.1  christos       set fnord "$@" "$arg"; shift ;;
    615      1.1  christos     # Strip any option that makedepend may not understand.  Remove
    616      1.1  christos     # the object too, otherwise makedepend will parse it as a source file.
    617      1.1  christos     -arch)
    618      1.1  christos       eat=yes ;;
    619      1.1  christos     -*|$object)
    620      1.1  christos       ;;
    621      1.1  christos     *)
    622      1.1  christos       set fnord "$@" "$arg"; shift ;;
    623      1.1  christos     esac
    624      1.1  christos   done
    625      1.1  christos   obj_suffix=`echo "$object" | sed 's/^.*\././'`
    626      1.1  christos   touch "$tmpdepfile"
    627      1.1  christos   ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
    628      1.1  christos   rm -f "$depfile"
    629  1.1.1.2  christos   # makedepend may prepend the VPATH from the source file name to the object.
    630  1.1.1.2  christos   # No need to regex-escape $object, excess matching of '.' is harmless.
    631  1.1.1.2  christos   sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
    632  1.1.1.2  christos   # Some versions of the HPUX 10.20 sed can't process the last invocation
    633  1.1.1.2  christos   # correctly.  Breaking it into two sed invocations is a workaround.
    634  1.1.1.2  christos   sed '1,2d' "$tmpdepfile" \
    635  1.1.1.2  christos     | tr ' ' "$nl" \
    636  1.1.1.2  christos     | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
    637  1.1.1.2  christos     | sed -e 's/$/ :/' >> "$depfile"
    638      1.1  christos   rm -f "$tmpdepfile" "$tmpdepfile".bak
    639      1.1  christos   ;;
    640      1.1  christos 
    641      1.1  christos cpp)
    642      1.1  christos   # Important note: in order to support this mode, a compiler *must*
    643      1.1  christos   # always write the preprocessed file to stdout.
    644      1.1  christos   "$@" || exit $?
    645      1.1  christos 
    646      1.1  christos   # Remove the call to Libtool.
    647      1.1  christos   if test "$libtool" = yes; then
    648      1.1  christos     while test "X$1" != 'X--mode=compile'; do
    649      1.1  christos       shift
    650      1.1  christos     done
    651      1.1  christos     shift
    652      1.1  christos   fi
    653      1.1  christos 
    654  1.1.1.2  christos   # Remove '-o $object'.
    655      1.1  christos   IFS=" "
    656      1.1  christos   for arg
    657      1.1  christos   do
    658      1.1  christos     case $arg in
    659      1.1  christos     -o)
    660      1.1  christos       shift
    661      1.1  christos       ;;
    662      1.1  christos     $object)
    663      1.1  christos       shift
    664      1.1  christos       ;;
    665      1.1  christos     *)
    666      1.1  christos       set fnord "$@" "$arg"
    667      1.1  christos       shift # fnord
    668      1.1  christos       shift # $arg
    669      1.1  christos       ;;
    670      1.1  christos     esac
    671      1.1  christos   done
    672      1.1  christos 
    673  1.1.1.2  christos   "$@" -E \
    674  1.1.1.2  christos     | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
    675  1.1.1.2  christos              -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
    676  1.1.1.2  christos     | sed '$ s: \\$::' > "$tmpdepfile"
    677      1.1  christos   rm -f "$depfile"
    678      1.1  christos   echo "$object : \\" > "$depfile"
    679      1.1  christos   cat < "$tmpdepfile" >> "$depfile"
    680      1.1  christos   sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
    681      1.1  christos   rm -f "$tmpdepfile"
    682      1.1  christos   ;;
    683      1.1  christos 
    684      1.1  christos msvisualcpp)
    685      1.1  christos   # Important note: in order to support this mode, a compiler *must*
    686      1.1  christos   # always write the preprocessed file to stdout.
    687      1.1  christos   "$@" || exit $?
    688      1.1  christos 
    689      1.1  christos   # Remove the call to Libtool.
    690      1.1  christos   if test "$libtool" = yes; then
    691      1.1  christos     while test "X$1" != 'X--mode=compile'; do
    692      1.1  christos       shift
    693      1.1  christos     done
    694      1.1  christos     shift
    695      1.1  christos   fi
    696      1.1  christos 
    697      1.1  christos   IFS=" "
    698      1.1  christos   for arg
    699      1.1  christos   do
    700      1.1  christos     case "$arg" in
    701      1.1  christos     -o)
    702      1.1  christos       shift
    703      1.1  christos       ;;
    704      1.1  christos     $object)
    705      1.1  christos       shift
    706      1.1  christos       ;;
    707      1.1  christos     "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
    708  1.1.1.2  christos         set fnord "$@"
    709  1.1.1.2  christos         shift
    710  1.1.1.2  christos         shift
    711  1.1.1.2  christos         ;;
    712      1.1  christos     *)
    713  1.1.1.2  christos         set fnord "$@" "$arg"
    714  1.1.1.2  christos         shift
    715  1.1.1.2  christos         shift
    716  1.1.1.2  christos         ;;
    717      1.1  christos     esac
    718      1.1  christos   done
    719      1.1  christos   "$@" -E 2>/dev/null |
    720      1.1  christos   sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
    721      1.1  christos   rm -f "$depfile"
    722      1.1  christos   echo "$object : \\" > "$depfile"
    723  1.1.1.2  christos   sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
    724  1.1.1.2  christos   echo "$tab" >> "$depfile"
    725      1.1  christos   sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
    726      1.1  christos   rm -f "$tmpdepfile"
    727      1.1  christos   ;;
    728      1.1  christos 
    729      1.1  christos msvcmsys)
    730      1.1  christos   # This case exists only to let depend.m4 do its work.  It works by
    731      1.1  christos   # looking at the text of this script.  This case will never be run,
    732      1.1  christos   # since it is checked for above.
    733      1.1  christos   exit 1
    734      1.1  christos   ;;
    735      1.1  christos 
    736      1.1  christos none)
    737      1.1  christos   exec "$@"
    738      1.1  christos   ;;
    739      1.1  christos 
    740      1.1  christos *)
    741      1.1  christos   echo "Unknown depmode $depmode" 1>&2
    742      1.1  christos   exit 1
    743      1.1  christos   ;;
    744      1.1  christos esac
    745      1.1  christos 
    746      1.1  christos exit 0
    747      1.1  christos 
    748      1.1  christos # Local Variables:
    749      1.1  christos # mode: shell-script
    750      1.1  christos # sh-indentation: 2
    751      1.1  christos # eval: (add-hook 'write-file-hooks 'time-stamp)
    752      1.1  christos # time-stamp-start: "scriptversion="
    753      1.1  christos # time-stamp-format: "%:y-%02m-%02d.%02H"
    754      1.1  christos # time-stamp-time-zone: "UTC"
    755      1.1  christos # time-stamp-end: "; # UTC"
    756      1.1  christos # End:
    757