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