home *** CD-ROM | disk | FTP | other *** search
/ c't freeware shareware 2001 January / CT_SW0101.ISO / pc / software / kommunik / ftp / kmago112.tgz / kmago112.tar / kmago-1.1.2 / admin / depcomp < prev    next >
Text File  |  2001-01-17  |  8KB  |  270 lines

  1. #! /bin/sh
  2.  
  3. # depcomp - compile a program generating dependencies as side-effects
  4. # Copyright (C) 1999 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. # Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
  22.  
  23. if test -z "$depmode" || test -z "$source" || test -z "$object"; then
  24.   echo "depcomp: Variables source, object and depmode must be set" 1>&2
  25.   exit 1
  26. fi
  27. # `libtool' can also be set to `yes' or `no'.
  28.  
  29. depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`}
  30. tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
  31.  
  32. rm -f "$tmpdepfile"
  33.  
  34. # Some modes work just like other modes, but use different flags.  We
  35. # parameterize here, but still list the modes in the big case below,
  36. # to make depend.m4 easier to write.  Note that we *cannot* use a case
  37. # here, because this file can only contain one case statement.
  38. if test "$depmode" = hp; then
  39.   # HP compiler uses -M and no extra arg.
  40.   gccflag=-M
  41.   depmode=gcc
  42. fi
  43.  
  44. if test "$depmode" = dashXmstdout; then
  45.    # This is just like dashmstdout with a different argument.
  46.    dashmflag=-xM
  47.    depmode=dashmstdout
  48. fi
  49.  
  50. case "$depmode" in
  51. gcc)
  52. ## There are various ways to get dependency output from gcc.  Here's
  53. ## why we pick this rather obscure method:
  54. ## - Don't want to use -MD because we'd like the dependencies to end
  55. ##   up in a subdir.  Having to rename by hand is ugly.
  56. ##   (We might end up doing this anyway to support other compilers.)
  57. ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
  58. ##   -MM, not -M (despite what the docs say).
  59. ## - Using -M directly means running the compiler twice (even worse
  60. ##   than renaming).
  61.   if test -z "$gccflag"; then
  62.     gccflag=-MD,
  63.   fi
  64.   if "$@" -Wp,"$gccflag$tmpdepfile"; then :
  65.   else
  66.     stat=$?
  67.     rm -f "$tmpdepfile"
  68.     exit $stat
  69.   fi
  70.   rm -f "$depfile" 
  71.   echo "$object : \\" > "$depfile"
  72.   sed 's/^[^:]*: / /' < "$tmpdepfile" >> "$depfile"
  73. ## This next piece of magic avoids the `deleted header file' problem.
  74. ## The problem is that when a header file which appears in a .P file
  75. ## is deleted, the dependency causes make to die (because there is
  76. ## typically no way to rebuild the header).  We avoid this by adding
  77. ## dummy dependencies for each header file.  Too bad gcc doesn't do
  78. ## this for us directly.
  79.   tr ' ' '
  80. ' < "$tmpdepfile" |
  81. ## Some versions of gcc put a space before the `:'.  On the theory
  82. ## that the space means something, we add a space to the output as
  83. ## well.
  84. ## Some versions of the HPUX 10.20 sed can't process this invocation
  85. ## correctly.  Breaking it into two sed invocations is a workaround.
  86.     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  87.   rm -f "$tmpdepfile"
  88.   ;;
  89.  
  90. hp)
  91.   # This case exists only to let depend.m4 do its work.  It works by
  92.   # looking at the text of this script.  This case will never be run,
  93.   # since it is checked for above.
  94.   exit 1
  95.   ;;
  96.  
  97. dashmd)
  98.   # The Java front end to gcc doesn't run cpp, so we can't use the -Wp
  99.   # trick.  Instead we must use -M and then rename the resulting .d
  100.   # file.  This is also the case for older versions of gcc, which
  101.   # don't implement -Wp.
  102.   if "$@" -MD; then :
  103.   else
  104.     stat=$?
  105.     rm -f FIXME
  106.     exit $stat
  107.   fi
  108.   FIXME: rewrite the file
  109.   ;;
  110.  
  111. sgi)
  112.   if test "$libtool" = yes; then
  113.     "$@" "-Wc,-MDupdate,$tmpdepfile"
  114.   else
  115.     "$@" -MDupdate "$tmpdepfile"
  116.   fi
  117.   stat=$?
  118.   if test $stat -eq 0; then :
  119.   else
  120.     stat=$?
  121.     rm -f "$tmpdepfile"
  122.     exit $stat
  123.   fi
  124.   rm -f "$depfile" 
  125.   echo "$object : \\" > "$depfile"
  126.   sed 's/^[^:]*: / /' < "$tmpdepfile" >> "$depfile"
  127.   tr ' ' '
  128. ' < "$tmpdepfile" | \
  129. ## Some versions of the HPUX 10.20 sed can't process this invocation
  130. ## correctly.  Breaking it into two sed invocations is a workaround.
  131.     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  132.   rm -f "$tmpdepfile"
  133.   ;;
  134.  
  135. #nosideeffect)
  136.   # This comment above is used by automake to tell side-effect
  137.   # dependency tracking mechanisms from slower ones.
  138.  
  139. dashmstdout)
  140.   # Important note: in order to support this mode, a compiler *must*
  141.   # always write the proprocessed file to stdout, regardless of -o,
  142.   # because we must use -o when running libtool.
  143.   test -z "$dashmflag" && dashmflag=-M
  144.   ( IFS=" "
  145.     case " $* " in
  146.     *" --mode=compile "*) # this is libtool, let us make it quiet
  147.       for arg
  148.       do # cycle over the arguments
  149.         case "$arg" in
  150.     "--mode=compile")
  151.       # insert --quiet before "--mode=compile"
  152.       set fnord "$@" --quiet
  153.       shift # fnord
  154.       ;;
  155.     esac
  156.     set fnord "$@" "$arg"
  157.     shift # fnord
  158.     shift # "$arg"
  159.       done
  160.       ;;
  161.     esac
  162.     "$@" $dashmflag | sed 's:^[^:]*\:[     ]*:'"$object"'\: :' > "$tmpdepfile"
  163.   ) &
  164.   proc=$!
  165.   "$@"
  166.   stat=$?
  167.   wait "$proc"
  168.   if test "$stat" != 0; then exit $stat; fi
  169.   rm -f "$depfile" 
  170.   cat < "$tmpdepfile" > "$depfile"
  171.   tr ' ' '
  172. ' < "$tmpdepfile" | \
  173. ## Some versions of the HPUX 10.20 sed can't process this invocation
  174. ## correctly.  Breaking it into two sed invocations is a workaround.
  175.     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  176.   rm -f "$tmpdepfile"
  177.   ;;
  178.  
  179. dashXmstdout)
  180.   # This case only exists to satisfy depend.m4.  It is never actually
  181.   # run, as this mode is specially recognized in the preamble.
  182.   exit 1
  183.   ;;
  184.  
  185. makedepend)
  186.   # X makedepend
  187.   (
  188.     shift
  189.     cleared=no
  190.     for arg in "$@"; do
  191.       case $cleared in no)
  192.         set ""; shift
  193.     cleared=yes
  194.       esac
  195.       case "$arg" in
  196.         -D*|-I*)
  197.       set fnord "$@" "$arg"; shift;;
  198.     -*)
  199.       ;;
  200.     *)
  201.       set fnord "$@" "$arg"; shift;;
  202.       esac
  203.     done
  204.     obj_suffix="`echo $object | sed 's/^.*\././'`"
  205.     touch "$tmpdepfile"
  206.     ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
  207.   ) &
  208.   proc=$!
  209.   "$@"
  210.   stat=$?
  211.   wait "$proc"
  212.   if test "$stat" != 0; then exit $stat; fi
  213.   rm -f "$depfile" 
  214.   cat < "$tmpdepfile" > "$depfile"
  215.   tail +3 "$tmpdepfile" | tr ' ' '
  216. ' | \
  217. ## Some versions of the HPUX 10.20 sed can't process this invocation
  218. ## correctly.  Breaking it into two sed invocations is a workaround.
  219.     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  220.   rm -f "$tmpdepfile" "$tmpdepfile".bak
  221.   ;;
  222.  
  223. cpp)
  224.   # Important note: in order to support this mode, a compiler *must*
  225.   # always write the proprocessed file to stdout, regardless of -o,
  226.   # because we must use -o when running libtool.
  227.   ( IFS=" "
  228.     case " $* " in
  229.     *" --mode=compile "*)
  230.       for arg
  231.       do # cycle over the arguments
  232.         case "$arg" in
  233.     "--mode=compile")
  234.       # insert --quiet before "--mode=compile"
  235.       set fnord "$@" --quiet
  236.       shift # fnord
  237.       ;;
  238.     esac
  239.     set fnord "$@" "$arg"
  240.     shift # fnord
  241.     shift # "$arg"
  242.       done
  243.       ;;
  244.     esac
  245.     "$@" -E |
  246.     sed -n '/^# [0-9][0-9]* "\([^"]*\)"/ s::'"$object"'\: \1:p' > "$tmpdepfile"
  247.   ) &
  248.   proc=$!
  249.   "$@"
  250.   stat=$?
  251.   wait "$proc"
  252.   if test "$stat" != 0; then exit $stat; fi
  253.   rm -f "$depfile"
  254.   cat < "$tmpdepfile" > "$depfile"
  255.   sed < "$tmpdepfile" -e 's/^[^:]*: //' -e 's/$/ :/' >> "$depfile"
  256.   rm -f "$tmpdepfile"
  257.   ;;
  258.  
  259. none)
  260.   exec "$@"
  261.   ;;
  262.  
  263. *)
  264.   echo "Unknown depmode $depmode" 1>&2
  265.   exit 1
  266.   ;;
  267. esac
  268.  
  269. exit 0
  270.