1
0

depcomp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #! /bin/sh
  2. # depcomp - compile a program generating dependencies as side-effects
  3. # Copyright 1999, 2000 Free Software Foundation, Inc.
  4. if test -z "$depmode" || test -z "$source" || test -z "$object"; then
  5. echo "depcomp: Variables source, object and depmode must be set" 1>&2
  6. exit 1
  7. fi
  8. if test -z "$depfile"; then
  9. base=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'`
  10. dir=`echo "$object" | sed 's,/.*$,/,'`
  11. if test "$dir" = "$object"; then
  12. dir=
  13. fi
  14. depfile="$dir.deps/$base"
  15. fi
  16. tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
  17. rm -f "$tmpdepfile"
  18. # Some modes work just like other modes, but use different flags. We
  19. # parameterize here, but still list the modes in the big case below,
  20. # to make depend.m4 easier to write. Note that we *cannot* use a case
  21. # here, because this file can only contain one case statement.
  22. case "$depmode" in
  23. gcc3)
  24. ## gcc 3 implements dependency tracking that does exactly what
  25. ## we want. Yay! Note: for some reason libtool 1.4 doesn't like
  26. ## it if -MD -MP comes after the -MF stuff. Hmm.
  27. if test -z "$MM"; then
  28. "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
  29. else
  30. "$@" -MM "$object" -MD -MP -MF "$tmpdepfile"
  31. fi
  32. stat=$?
  33. if test $stat -eq 0; then :
  34. else
  35. rm -f "$tmpdepfile"
  36. exit $stat
  37. fi
  38. mv "$tmpdepfile" "$depfile"
  39. ;;
  40. gcc)
  41. ## There are various ways to get dependency output from gcc. Here's
  42. ## why we pick this rather obscure method:
  43. ## - Don't want to use -MD because we'd like the dependencies to end
  44. ## up in a subdir. Having to rename by hand is ugly.
  45. ## (We might end up doing this anyway to support other compilers.)
  46. ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
  47. ## -MM, not -M (despite what the docs say).
  48. ## - Using -M directly means running the compiler twice (even worse
  49. ## than renaming).
  50. if test -z "$gccflag"; then
  51. gccflag=-MD,
  52. fi
  53. "$@" -Wp,"$gccflag$tmpdepfile"
  54. stat=$?
  55. if test $stat -eq 0; then :
  56. else
  57. rm -f "$tmpdepfile"
  58. exit $stat
  59. fi
  60. rm -f "$depfile"
  61. echo "$object : \\" > "$depfile"
  62. alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
  63. ## The second -e expression handles DOS-style file names with drive letters.
  64. sed -e 's/^[^:]*: / /' \
  65. -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
  66. ## This next piece of magic avoids the `deleted header file' problem.
  67. ## The problem is that when a header file which appears in a .P file
  68. ## is deleted, the dependency causes make to die (because there is
  69. ## typically no way to rebuild the header). We avoid this by adding
  70. ## dummy dependencies for each header file. Too bad gcc doesn't do
  71. ## this for us directly.
  72. tr ' ' '
  73. ' < "$tmpdepfile" |
  74. ## Some versions of gcc put a space before the `:'. On the theory
  75. ## that the space means something, we add a space to the output as
  76. ## well.
  77. ## Some versions of the HPUX 10.20 sed can't process this invocation
  78. ## correctly. Breaking it into two sed invocations is a workaround.
  79. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  80. rm -f "$tmpdepfile"
  81. ;;
  82. #nosideeffect)
  83. # This comment above is used by automake to tell side-effect
  84. # dependency tracking mechanisms from slower ones.
  85. none)
  86. exec "$@"
  87. ;;
  88. *)
  89. echo "Unknown depmode $depmode" 1>&2
  90. exit 1
  91. ;;
  92. esac
  93. exit 0