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