This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 3.0 patch #2 (combined patch)
[perl5.git] / makedepend.SH
CommitLineData
8d063cd8
LW
1case $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
378cc40b 9 . ./config.sh
8d063cd8
LW
10 ;;
11esac
12case "$0" in
13*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
14esac
15echo "Extracting makedepend (with variable substitutions)"
16$spitshell >makedepend <<!GROK!THIS!
17$startsh
a687059c 18# $Header: makedepend.SH,v 3.0 89/10/18 15:20:19 lwall Locked $
8d063cd8
LW
19#
20# $Log: makedepend.SH,v $
a687059c
LW
21# Revision 3.0 89/10/18 15:20:19 lwall
22# 3.0 baseline
8d063cd8
LW
23#
24
25export PATH || (echo "OOPS, this isn't sh. Desperation time. I will feed myself to sh."; sh \$0; kill \$\$)
26
27cat='$cat'
a687059c 28ccflags='$ccflags $sockethdr'
8d063cd8 29cp='$cp'
378cc40b 30cpp='$cppstdin'
8d063cd8
LW
31echo='$echo'
32egrep='$egrep'
33expr='$expr'
34mv='$mv'
35rm='$rm'
36sed='$sed'
37sort='$sort'
38test='$test'
39tr='$tr'
40uniq='$uniq'
41!GROK!THIS!
42
43$spitshell >>makedepend <<'!NO!SUBS!'
44
378cc40b
LW
45: the following weeds options from ccflags that are of no interest to cpp
46case "$ccflags" in
47'');;
48*) set X $ccflags
49 ccflags=''
50 for flag do
51 case $flag in
52 -D*|-I*) ccflags="$ccflags $flag";;
53 esac
54 done
55 ;;
56esac
57
8d063cd8
LW
58$cat /dev/null >.deptmp
59$rm -f *.c.c c/*.c.c
60if test -f Makefile; then
61 mf=Makefile
62else
63 mf=makefile
64fi
65if test -f $mf; then
66 defrule=`<$mf sed -n \
67 -e '/^\.c\.o:.*;/{' \
68 -e 's/\$\*\.c//' \
69 -e 's/^[^;]*;[ ]*//p' \
70 -e q \
71 -e '}' \
72 -e '/^\.c\.o: *$/{' \
73 -e N \
74 -e 's/\$\*\.c//' \
75 -e 's/^.*\n[ ]*//p' \
76 -e q \
77 -e '}'`
78fi
79case "$defrule" in
80'') defrule='$(CC) -c $(CFLAGS)' ;;
81esac
82
83make clist || ($echo "Searching for .c files..."; \
a687059c 84 $echo *.c | $tr ' ' '\012' | $egrep -v '\*' >.clist)
8d063cd8
LW
85for file in `$cat .clist`; do
86# for file in `cat /dev/null`; do
87 case "$file" in
88 *.c) filebase=`basename $file .c` ;;
89 *.y) filebase=`basename $file .c` ;;
90 esac
91 $echo "Finding dependencies for $filebase.o."
92 $sed -n <$file >$file.c \
93 -e "/^${filebase}_init(/q" \
94 -e '/^#/{' \
95 -e 's|/\*.*$||' \
96 -e 's|\\$||' \
97 -e p \
98 -e '}'
378cc40b 99 $cpp -I/usr/local/include -I. $ccflags $file.c | \
8d063cd8
LW
100 $sed \
101 -e '/^# *[0-9]/!d' \
102 -e 's/^.*"\(.*\)".*$/'$filebase'.o: \1/' \
103 -e 's|: \./|: |' \
104 -e 's|\.c\.c|.c|' | \
105 $uniq | $sort | $uniq >> .deptmp
106done
107
108$sed <Makefile >Makefile.new -e '1,/^# AUTOMATICALLY/!d'
109
110make shlist || ($echo "Searching for .SH files..."; \
a687059c 111 $echo *.SH | $tr ' ' '\012' | $egrep -v '\*' >.shlist)
8d063cd8
LW
112if $test -s .deptmp; then
113 for file in `cat .shlist`; do
114 $echo `$expr X$file : 'X\(.*\).SH`: $file config.sh \; \
115 /bin/sh $file >> .deptmp
116 done
117 $echo "Updating Makefile..."
118 $echo "# If this runs make out of memory, delete /usr/include lines." \
119 >> Makefile.new
120 $sed 's|^\(.*\.o:\) *\(.*/.*\.c\) *$|\1 \2; '"$defrule \2|" .deptmp \
121 >>Makefile.new
122else
123 make hlist || ($echo "Searching for .h files..."; \
a687059c 124 $echo *.h | $tr ' ' '\012' | $egrep -v '\*' >.hlist)
8d063cd8
LW
125 $echo "You don't seem to have a proper C preprocessor. Using grep instead."
126 $egrep '^#include ' `cat .clist` `cat .hlist` >.deptmp
127 $echo "Updating Makefile..."
128 <.clist $sed -n \
129 -e '/\//{' \
130 -e 's|^\(.*\)/\(.*\)\.c|\2.o: \1/\2.c; '"$defrule \1/\2.c|p" \
131 -e d \
132 -e '}' \
133 -e 's|^\(.*\)\.c|\1.o: \1.c|p' >> Makefile.new
134 <.hlist $sed -n 's|\(.*/\)\(.*\)|s= \2= \1\2=|p' >.hsed
135 <.deptmp $sed -n 's|c:#include "\(.*\)".*$|o: \1|p' | \
136 $sed 's|^[^;]*/||' | \
137 $sed -f .hsed >> Makefile.new
138 <.deptmp $sed -n 's|c:#include <\(.*\)>.*$|o: /usr/include/\1|p' \
139 >> Makefile.new
140 <.deptmp $sed -n 's|h:#include "\(.*\)".*$|h: \1|p' | \
141 $sed -f .hsed >> Makefile.new
142 <.deptmp $sed -n 's|h:#include <\(.*\)>.*$|h: /usr/include/\1|p' \
143 >> Makefile.new
144 for file in `$cat .shlist`; do
145 $echo `$expr X$file : 'X\(.*\).SH`: $file config.sh \; \
146 /bin/sh $file >> Makefile.new
147 done
148fi
149$rm -f Makefile.old
150$cp Makefile Makefile.old
151$cp Makefile.new Makefile
152$rm Makefile.new
153$echo "# WARNING: Put nothing here or make depend will gobble it up!" >> Makefile
154$rm -f .deptmp `sed 's/\.c/.c.c/' .clist` .shlist .clist .hlist .hsed
155
156!NO!SUBS!
157$eunicefix makedepend
378cc40b 158chmod +x makedepend
8d063cd8
LW
159case `pwd` in
160*SH)
161 $rm -f ../makedepend
162 ln makedepend ../makedepend
163 ;;
164esac