home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Sound / LAME / WarpOS / src / frontend / depcomp < prev    next >
Encoding:
Text File  |  2001-03-12  |  10.3 KB  |  362 lines

  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. # 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. gcc3)
  52. ## gcc 3 implements dependency tracking that does exactly what
  53. ## we want.  Yay!
  54.    exec "$@" -MT "$object" -MF "$depfile" -MD -MP
  55.    ;;
  56.  
  57. gcc)
  58. ## There are various ways to get dependency output from gcc.  Here's
  59. ## why we pick this rather obscure method:
  60. ## - Don't want to use -MD because we'd like the dependencies to end
  61. ##   up in a subdir.  Having to rename by hand is ugly.
  62. ##   (We might end up doing this anyway to support other compilers.)
  63. ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
  64. ##   -MM, not -M (despite what the docs say).
  65. ## - Using -M directly means running the compiler twice (even worse
  66. ##   than renaming).
  67.   if test -z "$gccflag"; then
  68.     gccflag=-MD,
  69.   fi
  70.   if "$@" -Wp,"$gccflag$tmpdepfile"; then :
  71.   else
  72.     stat=$?
  73.     rm -f "$tmpdepfile"
  74.     exit $stat
  75.   fi
  76.   rm -f "$depfile"
  77.   echo "$object : \\" > "$depfile"
  78.   alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
  79. ## The second -e expression handles DOS-style file names with drive letters.
  80.   sed -e 's/^[^:]*: / /' \
  81.       -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
  82. ## This next piece of magic avoids the `deleted header file' problem.
  83. ## The problem is that when a header file which appears in a .P file
  84. ## is deleted, the dependency causes make to die (because there is
  85. ## typically no way to rebuild the header).  We avoid this by adding
  86. ## dummy dependencies for each header file.  Too bad gcc doesn't do
  87. ## this for us directly.
  88.   tr ' ' '
  89. ' < "$tmpdepfile" |
  90. ## Some versions of gcc put a space before the `:'.  On the theory
  91. ## that the space means something, we add a space to the output as
  92. ## well.
  93. ## Some versions of the HPUX 10.20 sed can't process this invocation
  94. ## correctly.  Breaking it into two sed invocations is a workaround.
  95.     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  96.   rm -f "$tmpdepfile"
  97.   ;;
  98.  
  99. hp)
  100.   # This case exists only to let depend.m4 do its work.  It works by
  101.   # looking at the text of this script.  This case will never be run,
  102.   # since it is checked for above.
  103.   exit 1
  104.   ;;
  105.  
  106. sgi)
  107.   if test "$libtool" = yes; then
  108.     "$@" "-Wp,-MDupdate,$tmpdepfile"
  109.   else
  110.     "$@" -MDupdate "$tmpdepfile"
  111.   fi
  112.   stat=$?
  113.   if test $stat -eq 0; then :
  114.   else
  115.     rm -f "$tmpdepfile"
  116.     exit $stat
  117.   fi
  118.   rm -f "$depfile"
  119.  
  120.   if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
  121.     echo "$object : \\" > "$depfile"
  122.  
  123.     # Clip off the initial element (the dependent). Don't try to be
  124.     # clever and replace this with sed code, as IRIX sed won't handle
  125.     # lines with more than a fixed number of characters (4096 in
  126.     # IRIX 6.2 sed, 8192 in IRIX 6.5).
  127.     tr ' ' '
  128. ' < "$tmpdepfile" | sed 's/^[^\.]*\.o://' | tr '
  129. ' ' ' >> $depfile
  130.  
  131.     tr ' ' '
  132. ' < "$tmpdepfile" | \
  133. ## Some versions of the HPUX 10.20 sed can't process this invocation
  134. ## correctly.  Breaking it into two sed invocations is a workaround.
  135.       sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  136.   else
  137.     # The sourcefile does not contain any dependencies, so just
  138.     # store a dummy comment line, to avoid errors with the Makefile
  139.     # "include basename.Plo" scheme.
  140.     echo "#dummy" > "$depfile"
  141.   fi
  142.   rm -f "$tmpdepfile"
  143.   ;;
  144.  
  145. aix)
  146.   # The C for AIX Compiler uses -M and outputs the dependencies
  147.   # in a .u file.
  148.   tmpdepfile=`echo "$object" | sed 's/\(.*\)\..*$/\1.u/'`
  149.   if test "$libtool" = yes; then
  150.     "$@" -Wc,-M
  151.   else
  152.     "$@" -M
  153.   fi
  154.  
  155.   stat=$?
  156.   if test $stat -eq 0; then :
  157.   else
  158.     rm -f "$tmpdepfile"
  159.     exit $stat
  160.   fi
  161.  
  162.   if test -f "$tmpdepfile"; then
  163.     echo "$object : \\" > "$depfile"
  164.  
  165.     # Clip off the initial element (the dependent). Don't try to be
  166.     # clever and replace this with sed code, as IRIX sed won't handle
  167.     # lines with more than a fixed number of characters (4096 in
  168.     # IRIX 6.2 sed, 8192 in IRIX 6.5).
  169.     tr ' ' '
  170. ' < "$tmpdepfile" | sed 's/^[^\.]*\.o://' | tr '
  171. ' ' ' >> $depfile
  172.  
  173.     tr ' ' '
  174. ' < "$tmpdepfile" | \
  175. ## Some versions of the HPUX 10.20 sed can't process this invocation
  176. ## correctly.  Breaking it into two sed invocations is a workaround.
  177.       sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  178.   else
  179.     # The sourcefile does not contain any dependencies, so just
  180.     # store a dummy comment line, to avoid errors with the Makefile
  181.     # "include basename.Plo" scheme.
  182.     echo "#dummy" > "$depfile"
  183.   fi
  184.   rm -f "$tmpdepfile"
  185.   ;;
  186.  
  187. #nosideeffect)
  188.   # This comment above is used by automake to tell side-effect
  189.   # dependency tracking mechanisms from slower ones.
  190.  
  191. dashmstdout)
  192.   # Important note: in order to support this mode, a compiler *must*
  193.   # always write the proprocessed file to stdout, regardless of -o,
  194.   # because we must use -o when running libtool.
  195.   test -z "$dashmflag" && dashmflag=-M
  196.   ( IFS=" "
  197.     case " $* " in
  198.     *" --mode=compile "*) # this is libtool, let us make it quiet
  199.       for arg
  200.       do # cycle over the arguments
  201.         case "$arg" in
  202.     "--mode=compile")
  203.       # insert --quiet before "--mode=compile"
  204.       set fnord "$@" --quiet
  205.       shift # fnord
  206.       ;;
  207.     esac
  208.     set fnord "$@" "$arg"
  209.     shift # fnord
  210.     shift # "$arg"
  211.       done
  212.       ;;
  213.     esac
  214.     "$@" $dashmflag | sed 's:^[^:]*\:[     ]*:'"$object"'\: :' > "$tmpdepfile"
  215.   ) &
  216.   proc=$!
  217.   "$@"
  218.   stat=$?
  219.   wait "$proc"
  220.   if test "$stat" != 0; then exit $stat; fi
  221.   rm -f "$depfile"
  222.   cat < "$tmpdepfile" > "$depfile"
  223.   tr ' ' '
  224. ' < "$tmpdepfile" | \
  225. ## Some versions of the HPUX 10.20 sed can't process this invocation
  226. ## correctly.  Breaking it into two sed invocations is a workaround.
  227.     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  228.   rm -f "$tmpdepfile"
  229.   ;;
  230.  
  231. dashXmstdout)
  232.   # This case only exists to satisfy depend.m4.  It is never actually
  233.   # run, as this mode is specially recognized in the preamble.
  234.   exit 1
  235.   ;;
  236.  
  237. makedepend)
  238.   # X makedepend
  239.   (
  240.     shift
  241.     cleared=no
  242.     for arg in "$@"; do
  243.       case $cleared in no)
  244.         set ""; shift
  245.     cleared=yes
  246.       esac
  247.       case "$arg" in
  248.         -D*|-I*)
  249.       set fnord "$@" "$arg"; shift;;
  250.     -*)
  251.       ;;
  252.     *)
  253.       set fnord "$@" "$arg"; shift;;
  254.       esac
  255.     done
  256.     obj_suffix="`echo $object | sed 's/^.*\././'`"
  257.     touch "$tmpdepfile"
  258.     ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
  259.   ) &
  260.   proc=$!
  261.   "$@"
  262.   stat=$?
  263.   wait "$proc"
  264.   if test "$stat" != 0; then exit $stat; fi
  265.   rm -f "$depfile"
  266.   cat < "$tmpdepfile" > "$depfile"
  267.   tail +3 "$tmpdepfile" | tr ' ' '
  268. ' | \
  269. ## Some versions of the HPUX 10.20 sed can't process this invocation
  270. ## correctly.  Breaking it into two sed invocations is a workaround.
  271.     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  272.   rm -f "$tmpdepfile" "$tmpdepfile".bak
  273.   ;;
  274.  
  275. cpp)
  276.   # Important note: in order to support this mode, a compiler *must*
  277.   # always write the proprocessed file to stdout, regardless of -o,
  278.   # because we must use -o when running libtool.
  279.   ( IFS=" "
  280.     case " $* " in
  281.     *" --mode=compile "*)
  282.       for arg
  283.       do # cycle over the arguments
  284.         case $arg in
  285.     "--mode=compile")
  286.       # insert --quiet before "--mode=compile"
  287.       set fnord "$@" --quiet
  288.       shift # fnord
  289.       ;;
  290.     esac
  291.     set fnord "$@" "$arg"
  292.     shift # fnord
  293.     shift # "$arg"
  294.       done
  295.       ;;
  296.     esac
  297.     "$@" -E |
  298.     sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
  299.     sed '$ s: \\$::' > "$tmpdepfile"
  300.   ) &
  301.   proc=$!
  302.   "$@"
  303.   stat=$?
  304.   wait "$proc"
  305.   if test "$stat" != 0; then exit $stat; fi
  306.   rm -f "$depfile"
  307.   echo "$object : \\" > "$depfile"
  308.   cat < "$tmpdepfile" >> "$depfile"
  309.   sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
  310.   rm -f "$tmpdepfile"
  311.   ;;
  312.  
  313. msvisualcpp)
  314.   # Important note: in order to support this mode, a compiler *must*
  315.   # always write the proprocessed file to stdout, regardless of -o,
  316.   # because we must use -o when running libtool.
  317.   ( IFS=" "
  318.     case " $* " in
  319.     *" --mode=compile "*)
  320.       for arg
  321.       do # cycle over the arguments
  322.         case $arg in
  323.     "--mode=compile")
  324.       # insert --quiet before "--mode=compile"
  325.       set fnord "$@" --quiet
  326.       shift # fnord
  327.       ;;
  328.     esac
  329.     set fnord "$@" "$arg"
  330.     shift # fnord
  331.     shift # "$arg"
  332.       done
  333.       ;;
  334.     esac
  335.     "$@" -E |
  336.     sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
  337.   ) &
  338.   proc=$!
  339.   "$@"
  340.   stat=$?
  341.   wait "$proc"
  342.   if test "$stat" != 0; then exit $stat; fi
  343.   rm -f "$depfile"
  344.   echo "$object : \\" > "$depfile"
  345.   . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::    \1 \\:p' >> "$depfile"
  346.   echo "    " >> "$depfile"
  347.   . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
  348.   rm -f "$tmpdepfile"
  349.   ;;
  350.  
  351. none)
  352.   exec "$@"
  353.   ;;
  354.  
  355. *)
  356.   echo "Unknown depmode $depmode" 1>&2
  357.   exit 1
  358.   ;;
  359. esac
  360.  
  361. exit 0
  362.