mkdep 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/sh -
  2. #
  3. # Copyright (c) 1994, 1996
  4. # The Regents of the University of California. All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms are permitted
  7. # provided that this notice is preserved and that due credit is given
  8. # to the University of California at Berkeley. The name of the University
  9. # may not be used to endorse or promote products derived from this
  10. # software without specific prior written permission. This software
  11. # is provided ``as is'' without express or implied warranty.
  12. #
  13. # @(#)mkdep.sh 5.11 (Berkeley) 5/5/88
  14. #
  15. MAKE=Makefile # default makefile name is "Makefile"
  16. CC=cc # default C compiler is "cc"
  17. DEPENDENCY_CFLAG=-M # default dependency-generation flag is -M
  18. while :
  19. do case "$1" in
  20. # -c allows you to specify the C compiler
  21. -c)
  22. CC=$2
  23. shift; shift ;;
  24. # -f allows you to select a makefile name
  25. -f)
  26. MAKE=$2
  27. shift; shift ;;
  28. # -m allows you to specify the dependency-generation flag
  29. -m)
  30. DEPENDENCY_CFLAG=$2
  31. shift; shift ;;
  32. # the -p flag produces "program: program.c" style dependencies
  33. # so .o's don't get produced
  34. -p)
  35. SED='s;\.o;;'
  36. shift ;;
  37. *)
  38. break ;;
  39. esac
  40. done
  41. if [ $# = 0 ] ; then
  42. echo 'usage: mkdep [-p] [-c cc] [-f makefile] [-m dependency-cflag] [flags] file ...'
  43. exit 1
  44. fi
  45. if [ ! -w $MAKE ]; then
  46. echo "mkdep: no writeable file \"$MAKE\""
  47. exit 1
  48. fi
  49. TMP=/tmp/mkdep$$
  50. trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
  51. cp $MAKE ${MAKE}.bak
  52. sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
  53. cat << _EOF_ >> $TMP
  54. # DO NOT DELETE THIS LINE -- mkdep uses it.
  55. # DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
  56. _EOF_
  57. # If your compiler doesn't have -M, add it. If you can't, the next two
  58. # lines will try and replace the "cc -M". The real problem is that this
  59. # hack can't deal with anything that requires a search path, and doesn't
  60. # even try for anything using bracket (<>) syntax.
  61. #
  62. # egrep '^#include[ ]*".*"' /dev/null $* |
  63. # sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
  64. # XXX this doesn't work with things like "-DDECLWAITSTATUS=union\ wait"
  65. $CC $DEPENDENCY_CFLAG $* |
  66. sed "
  67. s; \./; ;g
  68. $SED" |
  69. awk '{
  70. if ($1 != prev) {
  71. if (rec != "")
  72. print rec;
  73. rec = $0;
  74. prev = $1;
  75. }
  76. else {
  77. if (length(rec $2) > 78) {
  78. print rec;
  79. rec = $0;
  80. }
  81. else
  82. rec = rec " " $2
  83. }
  84. }
  85. END {
  86. print rec
  87. }' >> $TMP
  88. cat << _EOF_ >> $TMP
  89. # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
  90. _EOF_
  91. # copy to preserve permissions
  92. cp $TMP $MAKE
  93. rm -f ${MAKE}.bak $TMP
  94. exit 0