home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / gnu / perl-4.036-src.lha / src / build / perl-4.036 / makedepend < prev    next >
Encoding:
Text File  |  1993-09-28  |  4.1 KB  |  148 lines

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