home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PERL4036.ZIP / makedepend.SH < prev    next >
Text File  |  1993-02-08  |  5KB  |  177 lines

  1. case $CONFIG in
  2. '')
  3.     if test ! -f config.sh; then
  4.     ln ../config.sh . || \
  5.     ln ../../config.sh . || \
  6.     ln ../../../config.sh . || \
  7.     (echo "Can't find config.sh."; exit 1)
  8.     fi 2>/dev/null
  9.     . ./config.sh
  10.     ;;
  11. esac
  12. case "$0" in
  13. */*) cd `expr X$0 : 'X\(.*\)/'` ;;
  14. esac
  15. echo "Extracting makedepend (with variable substitutions)"
  16. rm -f makedepend
  17. $spitshell >makedepend <<!GROK!THIS!
  18. $startsh
  19. # $RCSfile: makedepend.SH,v $$Revision: 4.0.1.4 $$Date: 92/06/08 13:51:24 $
  20. #
  21. # $Log:    makedepend.SH,v $
  22. # Revision 4.0.1.4  92/06/08  13:51:24  lwall
  23. # patch20: various and sundry fixes
  24. # Revision 4.0.1.3  91/11/05  17:56:33  lwall
  25. # patch11: various portability fixes
  26. # Revision 4.0.1.2  91/06/07  15:40:06  lwall
  27. # patch4: fixed cppstdin to run in the right directory
  28. # Revision 4.0.1.1  91/06/07  11:20:06  lwall
  29. # patch4: Makefile is no longer self-modifying code under makedepend
  30. # Revision 4.0  91/03/20  01:27:04  lwall
  31. # 4.0 baseline.
  32.  
  33. export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh \$0; kill \$\$)
  34.  
  35. cat='$cat'
  36. cppflags='$cppflags'
  37. cp='$cp'
  38. cppstdin='$cppstdin'
  39. cppminus='$cppminus'
  40. echo='$echo'
  41. egrep='$egrep'
  42. expr='$expr'
  43. mv='$mv'
  44. rm='$rm'
  45. sed='$sed'
  46. sort='$sort'
  47. test='$test'
  48. tr='$tr'
  49. uniq='$uniq'
  50. !GROK!THIS!
  51.  
  52. $spitshell >>makedepend <<'!NO!SUBS!'
  53.  
  54. PATH="$PATH:."
  55. export PATH
  56.  
  57. $cat /dev/null >.deptmp
  58. $rm -f *.c.c c/*.c.c
  59. if test -f Makefile; then
  60.     cp Makefile makefile
  61. fi
  62. mf=makefile
  63. if test -f $mf; then
  64.     defrule=`<$mf sed -n        \
  65.     -e '/^\.c\.o:.*;/{'        \
  66.     -e    's/\$\*\.c//'        \
  67.     -e    's/^[^;]*;[     ]*//p'    \
  68.     -e    q                \
  69.     -e '}'                \
  70.     -e '/^\.c\.o: *$/{'        \
  71.     -e    N                \
  72.     -e    's/\$\*\.c//'        \
  73.     -e    's/^.*\n[     ]*//p'        \
  74.     -e    q                \
  75.     -e '}'`
  76. fi
  77. case "$defrule" in
  78. '') defrule='$(CC) -c $(CFLAGS)' ;;
  79. esac
  80.  
  81. make clist || ($echo "Searching for .c files..."; \
  82.     $echo *.c | $tr ' ' '\012' | $egrep -v '\*' >.clist)
  83. for file in `$cat .clist`; do
  84. # for file in `cat /dev/null`; do
  85.     case "$file" in
  86.     *.c) filebase=`basename $file .c` ;;
  87.     *.y) filebase=`basename $file .y` ;;
  88.     esac
  89.     case "$file" in
  90.     */*) finc="-I`echo $file | sed 's#/[^/]*$##`" ;;
  91.     *)   finc= ;;
  92.     esac
  93.     $echo "Finding dependencies for $filebase.o."
  94.     ( $echo "#line 1 \"$file\""; \
  95.       $sed -n <$file \
  96.     -e "/^${filebase}_init(/q" \
  97.     -e '/^#/{' \
  98.     -e 's|/\*.*$||' \
  99.     -e 's|\\$||' \
  100.     -e p \
  101.     -e '}' ) >$file.c
  102.     $cppstdin $finc -I/usr/local/include -I. $cppflags $cppminus <$file.c |
  103.     $sed \
  104.     -e 's#\.[0-9][0-9]*\.c#'"$file.c#" \
  105.     -e 's/^[     ]*#[     ]*line/#/' \
  106.     -e '/^# *[0-9][0-9]* *[".\/]/!d' \
  107.     -e 's/^.*"\(.*\)".*$/'$filebase'.o: \1/' \
  108.     -e 's/^# *[0-9][0-9]* \(.*\)$/'$filebase'.o: \1/' \
  109.     -e 's|: \./|: |' \
  110.     -e 's|\.c\.c|.c|' | \
  111.     $uniq | $sort | $uniq >> .deptmp
  112. done
  113.  
  114. $sed <$mf >$mf.new -e '1,/^# AUTOMATICALLY/!d'
  115.  
  116. make shlist || ($echo "Searching for .SH files..."; \
  117.     $echo *.SH | $tr ' ' '\012' | $egrep -v '\*' >.shlist)
  118. if $test -s .deptmp; then
  119.     for file in `cat .shlist`; do
  120.     $echo `$expr X$file : 'X\(.*\).SH'`: $file config.sh \; \
  121.         /bin/sh $file >> .deptmp
  122.     done
  123.     $echo "Updating $mf..."
  124.     $echo "# If this runs make out of memory, delete /usr/include lines." \
  125.     >> $mf.new
  126.     $sed 's|^\(.*\.o:\) *\(.*/.*\.c\) *$|\1 \2; '"$defrule \2|" .deptmp \
  127.        >>$mf.new
  128. else
  129.     make hlist || ($echo "Searching for .h files..."; \
  130.     $echo *.h | $tr ' ' '\012' | $egrep -v '\*' >.hlist)
  131.     $echo "You don't seem to have a proper C preprocessor.  Using grep instead."
  132.     $egrep '^#include ' `cat .clist` `cat .hlist`  >.deptmp
  133.     $echo "Updating $mf..."
  134.     <.clist $sed -n                            \
  135.     -e '/\//{'                            \
  136.     -e   's|^\(.*\)/\(.*\)\.c|\2.o: \1/\2.c; '"$defrule \1/\2.c|p"    \
  137.     -e   d                                \
  138.     -e '}'                                \
  139.     -e 's|^\(.*\)\.c|\1.o: \1.c|p' >> $mf.new
  140.     <.hlist $sed -n 's|\(.*/\)\(.*\)|s= \2= \1\2=|p' >.hsed
  141.     <.deptmp $sed -n 's|c:#include "\(.*\)".*$|o: \1|p' | \
  142.        $sed 's|^[^;]*/||' | \
  143.        $sed -f .hsed >> $mf.new
  144.     <.deptmp $sed -n 's|c:#include <\(.*\)>.*$|o: /usr/include/\1|p' \
  145.        >> $mf.new
  146.     <.deptmp $sed -n 's|h:#include "\(.*\)".*$|h: \1|p' | \
  147.        $sed -f .hsed >> $mf.new
  148.     <.deptmp $sed -n 's|h:#include <\(.*\)>.*$|h: /usr/include/\1|p' \
  149.        >> $mf.new
  150.     for file in `$cat .shlist`; do
  151.     $echo `$expr X$file : 'X\(.*\).SH'`: $file config.sh \; \
  152.         /bin/sh $file >> $mf.new
  153.     done
  154. fi
  155. $rm -f $mf.old
  156. $cp $mf $mf.old
  157. $cp $mf.new $mf
  158. $rm $mf.new
  159. $echo "# WARNING: Put nothing here or make depend will gobble it up!" >> $mf
  160. $rm -f .deptmp `sed 's/\.c/.c.c/' .clist` .shlist .clist .hlist .hsed
  161.  
  162. !NO!SUBS!
  163. $eunicefix makedepend
  164. chmod +x makedepend
  165. case `pwd` in
  166. *SH)
  167.     $rm -f ../makedepend
  168.     ln makedepend ../makedepend
  169.     ;;
  170. esac
  171.