perl5.000 patch.0i: fix glaring mistakes in patches a-h
[p5sagit/p5-mst-13.2.git] / makedepend.SH
1 case $CONFIG in
2 '')
3         if test -f config.sh; then TOP=.;
4         elif test -f ../config.sh; then TOP=..;
5         elif test -f ../../config.sh; then TOP=../..;
6         elif test -f ../../../config.sh; then TOP=../../..;
7         elif test -f ../../../../config.sh; then TOP=../../../..;
8         else
9                 echo "Can't find config.sh."; exit 1
10         fi
11         . $TOP/config.sh
12         ;;
13 esac
14 : This forces SH files to create target in same directory as SH file.
15 : This is so that make depend always knows where to find SH derivatives.
16 case "$0" in
17 */*) cd `expr X$0 : 'X\(.*\)/'` ;;
18 esac
19 echo "Extracting makedepend (with variable substitutions)"
20 rm -f makedepend
21 $spitshell >makedepend <<!GROK!THIS!
22 $startsh
23 !GROK!THIS!
24 $spitshell >>makedepend <<'!NO!SUBS!'
25 # makedepend.SH
26 #
27
28 export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh \$0; kill \$\$)
29
30 case $CONFIG in
31 '')
32         if test -f config.sh; then TOP=.;
33         elif test -f ../config.sh; then TOP=..;
34         elif test -f ../../config.sh; then TOP=../..;
35         elif test -f ../../../config.sh; then TOP=../../..;
36         elif test -f ../../../../config.sh; then TOP=../../../..;
37         else
38                 echo "Can't find config.sh."; exit 1
39         fi
40         . $TOP/config.sh
41         ;;
42 esac
43
44 PATH="$PATH:."
45 export PATH
46
47 $cat /dev/null >.deptmp
48 $rm -f *.c.c c/*.c.c
49 if test -f Makefile; then
50     cp Makefile makefile
51 fi
52 mf=makefile
53 if test -f $mf; then
54     defrule=`<$mf sed -n                \
55         -e '/^\.c\.o:.*;/{'             \
56         -e    's/\$\*\.c//'             \
57         -e    's/^[^;]*;[        ]*//p' \
58         -e    q                         \
59         -e '}'                          \
60         -e '/^\.c\.o: *$/{'             \
61         -e    N                         \
62         -e    's/\$\*\.c//'             \
63         -e    's/^.*\n[  ]*//p'         \
64         -e    q                         \
65         -e '}'`
66 fi
67 case "$defrule" in
68 '') defrule='$(CC) -c $(CFLAGS)' ;;
69 esac
70
71 : Create files in UU directory to avoid problems with long filenames
72 : on systems with 14 character filename limits so file.c.c and file.c
73 : might be identical
74 $test -d UU || mkdir UU
75
76 make clist || ($echo "Searching for .c files..."; \
77         $echo *.c | $tr ' ' '\012' | $egrep -v '\*' >.clist)
78 for file in `$cat .clist`; do
79 # for file in `cat /dev/null`; do
80     case "$file" in
81     *.c) filebase=`basename $file .c` ;;
82     *.y) filebase=`basename $file .y` ;;
83     esac
84     case "$file" in
85     */*) finc="-I`echo $file | sed 's#/[^/]*$##`" ;;
86     *)   finc= ;;
87     esac
88     $echo "Finding dependencies for $filebase.o."
89     ( $echo "#line 1 \"$file\""; \
90       $sed -n <$file \
91         -e "/^${filebase}_init(/q" \
92         -e '/^#line/d' \
93         -e '/^#/{' \
94         -e 's|/\*.*$||' \
95         -e 's|\\$||' \
96         -e p \
97         -e '}' ) >UU/$file.c
98     $cppstdin $finc -I/usr/local/include -I. $cppflags $cppminus <UU/$file.c |
99     $sed \
100         -e '/^#.*<stdin>/d' \
101         -e 's#\.[0-9][0-9]*\.c#'"$file.c#" \
102         -e 's/^[         ]*#[    ]*line/#/' \
103         -e '/^# *[0-9][0-9]* *[".\/]/!d' \
104         -e 's/^.*"\(.*\)".*$/'$filebase'.o: \1/' \
105         -e 's/^# *[0-9][0-9]* \(.*\)$/'$filebase'.o: \1/' \
106         -e 's|: \./|: |' \
107         -e 's|\.c\.c|.c|' | \
108     $uniq | $sort | $uniq >> .deptmp
109 done
110
111 $sed <$mf >$mf.new -e '1,/^# AUTOMATICALLY/!d'
112
113 make shlist || ($echo "Searching for .SH files..."; \
114         $echo *.SH | $tr ' ' '\012' | $egrep -v '\*' >.shlist)
115 if $test -s .deptmp; then
116     for file in `cat .shlist`; do
117         $echo `$expr X$file : 'X\(.*\).SH'`: $file $TOP/config.sh \; \
118             /bin/sh $file >> .deptmp
119     done
120     $echo "Updating $mf..."
121     $echo "# If this runs make out of memory, delete /usr/include lines." \
122         >> $mf.new
123     $sed 's|^\(.*\.o:\) *\(.*/.*\.c\) *$|\1 \2; '"$defrule \2|" .deptmp \
124        >>$mf.new
125 else
126     make hlist || ($echo "Searching for .h files..."; \
127         $echo *.h | $tr ' ' '\012' | $egrep -v '\*' >.hlist)
128     $echo "You don't seem to have a proper C preprocessor.  Using grep instead."
129     $egrep '^#include ' `cat .clist` `cat .hlist`  >.deptmp
130     $echo "Updating $mf..."
131     <.clist $sed -n                                                     \
132         -e '/\//{'                                                      \
133         -e   's|^\(.*\)/\(.*\)\.c|\2.o: \1/\2.c; '"$defrule \1/\2.c|p"  \
134         -e   d                                                          \
135         -e '}'                                                          \
136         -e 's|^\(.*\)\.c|\1.o: \1.c|p' >> $mf.new
137     <.hlist $sed -n 's|\(.*/\)\(.*\)|s= \2= \1\2=|p' >.hsed
138     <.deptmp $sed -n 's|c:#include "\(.*\)".*$|o: \1|p' | \
139        $sed 's|^[^;]*/||' | \
140        $sed -f .hsed >> $mf.new
141     <.deptmp $sed -n 's|h:#include "\(.*\)".*$|h: \1|p' | \
142        $sed -f .hsed >> $mf.new
143     for file in `$cat .shlist`; do
144         $echo `$expr X$file : 'X\(.*\).SH'`: $file $TOP/config.sh \; \
145             /bin/sh $file >> $mf.new
146     done
147 fi
148 $rm -f $mf.old
149 $cp $mf $mf.old
150 $cp $mf.new $mf
151 $rm $mf.new
152 $echo "# WARNING: Put nothing here or make depend will gobble it up!" >> $mf
153 $rm -rf .deptmp UU .shlist .clist .hlist .hsed
154
155 !NO!SUBS!
156 $eunicefix makedepend
157 chmod +x makedepend
158 case `pwd` in
159 *SH)
160     $rm -f ../makedepend
161     ln makedepend ../makedepend
162     ;;
163 esac