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