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