Annotation of embedaddon/dhcping/depcomp, revision 1.1.1.1

1.1       misho       1: #! /bin/sh
                      2: 
                      3: # depcomp - compile a program generating dependencies as side-effects
                      4: # Copyright 1999, 2000 Free Software Foundation, Inc.
                      5: 
                      6: # This program is free software; you can redistribute it and/or modify
                      7: # it under the terms of the GNU General Public License as published by
                      8: # the Free Software Foundation; either version 2, or (at your option)
                      9: # any later version.
                     10: 
                     11: # This program is distributed in the hope that it will be useful,
                     12: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     13: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     14: # GNU General Public License for more details.
                     15: 
                     16: # You should have received a copy of the GNU General Public License
                     17: # along with this program; if not, write to the Free Software
                     18: # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
                     19: # 02111-1307, USA.
                     20: 
                     21: # As a special exception to the GNU General Public License, if you
                     22: # distribute this file as part of a program that contains a
                     23: # configuration script generated by Autoconf, you may include it under
                     24: # the same distribution terms that you use for the rest of that program.
                     25: 
                     26: # Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
                     27: 
                     28: if test -z "$depmode" || test -z "$source" || test -z "$object"; then
                     29:   echo "depcomp: Variables source, object and depmode must be set" 1>&2
                     30:   exit 1
                     31: fi
                     32: # `libtool' can also be set to `yes' or `no'.
                     33: 
                     34: depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`}
                     35: tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
                     36: 
                     37: rm -f "$tmpdepfile"
                     38: 
                     39: # Some modes work just like other modes, but use different flags.  We
                     40: # parameterize here, but still list the modes in the big case below,
                     41: # to make depend.m4 easier to write.  Note that we *cannot* use a case
                     42: # here, because this file can only contain one case statement.
                     43: if test "$depmode" = hp; then
                     44:   # HP compiler uses -M and no extra arg.
                     45:   gccflag=-M
                     46:   depmode=gcc
                     47: fi
                     48: 
                     49: if test "$depmode" = dashXmstdout; then
                     50:    # This is just like dashmstdout with a different argument.
                     51:    dashmflag=-xM
                     52:    depmode=dashmstdout
                     53: fi
                     54: 
                     55: case "$depmode" in
                     56: gcc3)
                     57: ## gcc 3 implements dependency tracking that does exactly what
                     58: ## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
                     59: ## it if -MD -MP comes after the -MF stuff.  Hmm.
                     60:   "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
                     61:   stat=$?
                     62:   if test $stat -eq 0; then :
                     63:   else
                     64:     rm -f "$tmpdepfile"
                     65:     exit $stat
                     66:   fi
                     67:   mv "$tmpdepfile" "$depfile"
                     68:   ;;
                     69: 
                     70: gcc)
                     71: ## There are various ways to get dependency output from gcc.  Here's
                     72: ## why we pick this rather obscure method:
                     73: ## - Don't want to use -MD because we'd like the dependencies to end
                     74: ##   up in a subdir.  Having to rename by hand is ugly.
                     75: ##   (We might end up doing this anyway to support other compilers.)
                     76: ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
                     77: ##   -MM, not -M (despite what the docs say).
                     78: ## - Using -M directly means running the compiler twice (even worse
                     79: ##   than renaming).
                     80:   if test -z "$gccflag"; then
                     81:     gccflag=-MD,
                     82:   fi
                     83:   "$@" -Wp,"$gccflag$tmpdepfile"
                     84:   stat=$?
                     85:   if test $stat -eq 0; then :
                     86:   else
                     87:     rm -f "$tmpdepfile"
                     88:     exit $stat
                     89:   fi
                     90:   rm -f "$depfile"
                     91:   echo "$object : \\" > "$depfile"
                     92:   alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
                     93: ## The second -e expression handles DOS-style file names with drive letters.
                     94:   sed -e 's/^[^:]*: / /' \
                     95:       -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
                     96: ## This next piece of magic avoids the `deleted header file' problem.
                     97: ## The problem is that when a header file which appears in a .P file
                     98: ## is deleted, the dependency causes make to die (because there is
                     99: ## typically no way to rebuild the header).  We avoid this by adding
                    100: ## dummy dependencies for each header file.  Too bad gcc doesn't do
                    101: ## this for us directly.
                    102:   tr ' ' '
                    103: ' < "$tmpdepfile" |
                    104: ## Some versions of gcc put a space before the `:'.  On the theory
                    105: ## that the space means something, we add a space to the output as
                    106: ## well.
                    107: ## Some versions of the HPUX 10.20 sed can't process this invocation
                    108: ## correctly.  Breaking it into two sed invocations is a workaround.
                    109:     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
                    110:   rm -f "$tmpdepfile"
                    111:   ;;
                    112: 
                    113: hp)
                    114:   # This case exists only to let depend.m4 do its work.  It works by
                    115:   # looking at the text of this script.  This case will never be run,
                    116:   # since it is checked for above.
                    117:   exit 1
                    118:   ;;
                    119: 
                    120: sgi)
                    121:   if test "$libtool" = yes; then
                    122:     "$@" "-Wp,-MDupdate,$tmpdepfile"
                    123:   else
                    124:     "$@" -MDupdate "$tmpdepfile"
                    125:   fi
                    126:   stat=$?
                    127:   if test $stat -eq 0; then :
                    128:   else
                    129:     rm -f "$tmpdepfile"
                    130:     exit $stat
                    131:   fi
                    132:   rm -f "$depfile"
                    133: 
                    134:   if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
                    135:     echo "$object : \\" > "$depfile"
                    136: 
                    137:     # Clip off the initial element (the dependent).  Don't try to be
                    138:     # clever and replace this with sed code, as IRIX sed won't handle
                    139:     # lines with more than a fixed number of characters (4096 in
                    140:     # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
                    141:     # the IRIX cc adds comments like `#:fec' to the end of the
                    142:     # dependency line.
                    143:     tr ' ' '
                    144: ' < "$tmpdepfile" \
                    145:     | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
                    146:     tr '
                    147: ' ' ' >> $depfile
                    148:     echo >> $depfile
                    149: 
                    150:     # The second pass generates a dummy entry for each header file.
                    151:     tr ' ' '
                    152: ' < "$tmpdepfile" \
                    153:    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
                    154:    >> $depfile
                    155:   else
                    156:     # The sourcefile does not contain any dependencies, so just
                    157:     # store a dummy comment line, to avoid errors with the Makefile
                    158:     # "include basename.Plo" scheme.
                    159:     echo "#dummy" > "$depfile"
                    160:   fi
                    161:   rm -f "$tmpdepfile"
                    162:   ;;
                    163: 
                    164: aix)
                    165:   # The C for AIX Compiler uses -M and outputs the dependencies
                    166:   # in a .u file.  This file always lives in the current directory.
                    167:   # Also, the AIX compiler puts `$object:' at the start of each line;
                    168:   # $object doesn't have directory information.
                    169:   stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'`
                    170:   tmpdepfile="$stripped.u"
                    171:   outname="$stripped.o"
                    172:   if test "$libtool" = yes; then
                    173:     "$@" -Wc,-M
                    174:   else
                    175:     "$@" -M
                    176:   fi
                    177: 
                    178:   stat=$?
                    179:   if test $stat -eq 0; then :
                    180:   else
                    181:     rm -f "$tmpdepfile"
                    182:     exit $stat
                    183:   fi
                    184: 
                    185:   if test -f "$tmpdepfile"; then
                    186:     # Each line is of the form `foo.o: dependent.h'.
                    187:     # Do two passes, one to just change these to
                    188:     # `$object: dependent.h' and one to simply `dependent.h:'.
                    189:     sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
                    190:     sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
                    191:   else
                    192:     # The sourcefile does not contain any dependencies, so just
                    193:     # store a dummy comment line, to avoid errors with the Makefile
                    194:     # "include basename.Plo" scheme.
                    195:     echo "#dummy" > "$depfile"
                    196:   fi
                    197:   rm -f "$tmpdepfile"
                    198:   ;;
                    199: 
                    200: tru64)
                    201:    # The Tru64 AIX compiler uses -MD to generate dependencies as a side
                    202:    # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
                    203:    # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 
                    204:    # dependencies in `foo.d' instead, so we check for that too.
                    205:    # Subdirectories are respected.
                    206: 
                    207:    tmpdepfile1="$object.d"
                    208:    tmpdepfile2=`echo "$object" | sed -e 's/.o$/.d/'` 
                    209:    if test "$libtool" = yes; then
                    210:       "$@" -Wc,-MD
                    211:    else
                    212:       "$@" -MD
                    213:    fi
                    214: 
                    215:    stat=$?
                    216:    if test $stat -eq 0; then :
                    217:    else
                    218:       rm -f "$tmpdepfile1" "$tmpdepfile2"
                    219:       exit $stat
                    220:    fi
                    221: 
                    222:    if test -f "$tmpdepfile1"; then
                    223:       tmpdepfile="$tmpdepfile1"
                    224:    else
                    225:       tmpdepfile="$tmpdepfile2"
                    226:    fi
                    227:    if test -f "$tmpdepfile"; then
                    228:       sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
                    229:       # That's a space and a tab in the [].
                    230:       sed -e 's,^.*\.[a-z]*:[  ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
                    231:    else
                    232:       echo "#dummy" > "$depfile"
                    233:    fi
                    234:    rm -f "$tmpdepfile"
                    235:    ;;
                    236: 
                    237: #nosideeffect)
                    238:   # This comment above is used by automake to tell side-effect
                    239:   # dependency tracking mechanisms from slower ones.
                    240: 
                    241: dashmstdout)
                    242:   # Important note: in order to support this mode, a compiler *must*
                    243:   # always write the proprocessed file to stdout, regardless of -o,
                    244:   # because we must use -o when running libtool.
                    245:   test -z "$dashmflag" && dashmflag=-M
                    246:   ( IFS=" "
                    247:     case " $* " in
                    248:     *" --mode=compile "*) # this is libtool, let us make it quiet
                    249:       for arg
                    250:       do # cycle over the arguments
                    251:         case "$arg" in
                    252:        "--mode=compile")
                    253:          # insert --quiet before "--mode=compile"
                    254:          set fnord "$@" --quiet
                    255:          shift # fnord
                    256:          ;;
                    257:        esac
                    258:        set fnord "$@" "$arg"
                    259:        shift # fnord
                    260:        shift # "$arg"
                    261:       done
                    262:       ;;
                    263:     esac
                    264:     "$@" $dashmflag | sed 's:^[^:]*\:[         ]*:'"$object"'\: :' > "$tmpdepfile"
                    265:   ) &
                    266:   proc=$!
                    267:   "$@"
                    268:   stat=$?
                    269:   wait "$proc"
                    270:   if test "$stat" != 0; then exit $stat; fi
                    271:   rm -f "$depfile"
                    272:   cat < "$tmpdepfile" > "$depfile"
                    273:   tr ' ' '
                    274: ' < "$tmpdepfile" | \
                    275: ## Some versions of the HPUX 10.20 sed can't process this invocation
                    276: ## correctly.  Breaking it into two sed invocations is a workaround.
                    277:     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
                    278:   rm -f "$tmpdepfile"
                    279:   ;;
                    280: 
                    281: dashXmstdout)
                    282:   # This case only exists to satisfy depend.m4.  It is never actually
                    283:   # run, as this mode is specially recognized in the preamble.
                    284:   exit 1
                    285:   ;;
                    286: 
                    287: makedepend)
                    288:   # X makedepend
                    289:   (
                    290:     shift
                    291:     cleared=no
                    292:     for arg in "$@"; do
                    293:       case $cleared in no)
                    294:         set ""; shift
                    295:        cleared=yes
                    296:       esac
                    297:       case "$arg" in
                    298:         -D*|-I*)
                    299:          set fnord "$@" "$arg"; shift;;
                    300:        -*)
                    301:          ;;
                    302:        *)
                    303:          set fnord "$@" "$arg"; shift;;
                    304:       esac
                    305:     done
                    306:     obj_suffix="`echo $object | sed 's/^.*\././'`"
                    307:     touch "$tmpdepfile"
                    308:     ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
                    309:   ) &
                    310:   proc=$!
                    311:   "$@"
                    312:   stat=$?
                    313:   wait "$proc"
                    314:   if test "$stat" != 0; then exit $stat; fi
                    315:   rm -f "$depfile"
                    316:   cat < "$tmpdepfile" > "$depfile"
                    317:   tail +3 "$tmpdepfile" | tr ' ' '
                    318: ' | \
                    319: ## Some versions of the HPUX 10.20 sed can't process this invocation
                    320: ## correctly.  Breaking it into two sed invocations is a workaround.
                    321:     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
                    322:   rm -f "$tmpdepfile" "$tmpdepfile".bak
                    323:   ;;
                    324: 
                    325: cpp)
                    326:   # Important note: in order to support this mode, a compiler *must*
                    327:   # always write the proprocessed file to stdout, regardless of -o,
                    328:   # because we must use -o when running libtool.
                    329:   ( IFS=" "
                    330:     case " $* " in
                    331:     *" --mode=compile "*)
                    332:       for arg
                    333:       do # cycle over the arguments
                    334:         case $arg in
                    335:        "--mode=compile")
                    336:          # insert --quiet before "--mode=compile"
                    337:          set fnord "$@" --quiet
                    338:          shift # fnord
                    339:          ;;
                    340:        esac
                    341:        set fnord "$@" "$arg"
                    342:        shift # fnord
                    343:        shift # "$arg"
                    344:       done
                    345:       ;;
                    346:     esac
                    347:     "$@" -E |
                    348:     sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
                    349:     sed '$ s: \\$::' > "$tmpdepfile"
                    350:   ) &
                    351:   proc=$!
                    352:   "$@"
                    353:   stat=$?
                    354:   wait "$proc"
                    355:   if test "$stat" != 0; then exit $stat; fi
                    356:   rm -f "$depfile"
                    357:   echo "$object : \\" > "$depfile"
                    358:   cat < "$tmpdepfile" >> "$depfile"
                    359:   sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
                    360:   rm -f "$tmpdepfile"
                    361:   ;;
                    362: 
                    363: msvisualcpp)
                    364:   # Important note: in order to support this mode, a compiler *must*
                    365:   # always write the proprocessed file to stdout, regardless of -o,
                    366:   # because we must use -o when running libtool.
                    367:   ( IFS=" "
                    368:     case " $* " in
                    369:     *" --mode=compile "*)
                    370:       for arg
                    371:       do # cycle over the arguments
                    372:         case $arg in
                    373:        "--mode=compile")
                    374:          # insert --quiet before "--mode=compile"
                    375:          set fnord "$@" --quiet
                    376:          shift # fnord
                    377:          ;;
                    378:        esac
                    379:        set fnord "$@" "$arg"
                    380:        shift # fnord
                    381:        shift # "$arg"
                    382:       done
                    383:       ;;
                    384:     esac
                    385:     "$@" -E |
                    386:     sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
                    387:   ) &
                    388:   proc=$!
                    389:   "$@"
                    390:   stat=$?
                    391:   wait "$proc"
                    392:   if test "$stat" != 0; then exit $stat; fi
                    393:   rm -f "$depfile"
                    394:   echo "$object : \\" > "$depfile"
                    395:   . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::   \1 \\:p' >> "$depfile"
                    396:   echo "       " >> "$depfile"
                    397:   . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
                    398:   rm -f "$tmpdepfile"
                    399:   ;;
                    400: 
                    401: none)
                    402:   exec "$@"
                    403:   ;;
                    404: 
                    405: *)
                    406:   echo "Unknown depmode $depmode" 1>&2
                    407:   exit 1
                    408:   ;;
                    409: esac
                    410: 
                    411: exit 0

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>