perl 4.0 patch 31: patch #20, continued
[p5sagit/p5-mst-13.2.git] / makedepend.SH
CommitLineData
8d063cd8 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)
fe14fcc3 8 fi 2>/dev/null
378cc40b 9 . ./config.sh
8d063cd8 10 ;;
11esac
12case "$0" in
13*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
14esac
15echo "Extracting makedepend (with variable substitutions)"
7b0cd887 16rm -f makedepend
8d063cd8 17$spitshell >makedepend <<!GROK!THIS!
18$startsh
7b0cd887 19# $RCSfile: makedepend.SH,v $$Revision: 4.0.1.4 $$Date: 92/06/08 13:51:24 $
8d063cd8 20#
21# $Log: makedepend.SH,v $
7b0cd887 22# Revision 4.0.1.4 92/06/08 13:51:24 lwall
23# patch20: various and sundry fixes
24#
55204971 25# Revision 4.0.1.3 91/11/05 17:56:33 lwall
26# patch11: various portability fixes
27#
352d5a3a 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#
fe14fcc3 34# Revision 4.0 91/03/20 01:27:04 lwall
35# 4.0 baseline.
bf38876a 36#
8d063cd8 37#
38
39export PATH || (echo "OOPS, this isn't sh. Desperation time. I will feed myself to sh."; sh \$0; kill \$\$)
40
41cat='$cat'
bf38876a 42cppflags='$cppflags'
8d063cd8 43cp='$cp'
352d5a3a 44cppstdin='$cppstdin'
45cppminus='$cppminus'
8d063cd8 46echo='$echo'
47egrep='$egrep'
48expr='$expr'
49mv='$mv'
50rm='$rm'
51sed='$sed'
52sort='$sort'
53test='$test'
54tr='$tr'
55uniq='$uniq'
56!GROK!THIS!
57
58$spitshell >>makedepend <<'!NO!SUBS!'
59
7b0cd887 60PATH="$PATH:."
61export PATH
62
8d063cd8 63$cat /dev/null >.deptmp
64$rm -f *.c.c c/*.c.c
65if test -f Makefile; then
352d5a3a 66 cp Makefile makefile
8d063cd8 67fi
352d5a3a 68mf=makefile
8d063cd8 69if 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 '}'`
82fi
83case "$defrule" in
84'') defrule='$(CC) -c $(CFLAGS)' ;;
85esac
86
87make clist || ($echo "Searching for .c files..."; \
a687059c 88 $echo *.c | $tr ' ' '\012' | $egrep -v '\*' >.clist)
8d063cd8 89for file in `$cat .clist`; do
90# for file in `cat /dev/null`; do
91 case "$file" in
92 *.c) filebase=`basename $file .c` ;;
7b0cd887 93 *.y) filebase=`basename $file .y` ;;
94 esac
95 case "$file" in
96 */*) finc="-I`echo $file | sed 's#/[^/]*$##`" ;;
97 *) finc= ;;
8d063cd8 98 esac
99 $echo "Finding dependencies for $filebase.o."
7b0cd887 100 ( $echo "#line 1 \"$file\""; \
101 $sed -n <$file \
8d063cd8 102 -e "/^${filebase}_init(/q" \
103 -e '/^#/{' \
104 -e 's|/\*.*$||' \
105 -e 's|\\$||' \
106 -e p \
7b0cd887 107 -e '}' ) >$file.c
108 $cppstdin $finc -I/usr/local/include -I. $cppflags $cppminus <$file.c |
8d063cd8 109 $sed \
7b0cd887 110 -e 's#\.[0-9][0-9]*\.c#'"$file.c#" \
55204971 111 -e 's/^[ ]*#[ ]*line/#/' \
7b0cd887 112 -e '/^# *[0-9][0-9]* *[".\/]/!d' \
8d063cd8 113 -e 's/^.*"\(.*\)".*$/'$filebase'.o: \1/' \
7b0cd887 114 -e 's/^# *[0-9][0-9]* \(.*\)$/'$filebase'.o: \1/' \
8d063cd8 115 -e 's|: \./|: |' \
116 -e 's|\.c\.c|.c|' | \
117 $uniq | $sort | $uniq >> .deptmp
118done
119
352d5a3a 120$sed <$mf >$mf.new -e '1,/^# AUTOMATICALLY/!d'
8d063cd8 121
122make shlist || ($echo "Searching for .SH files..."; \
a687059c 123 $echo *.SH | $tr ' ' '\012' | $egrep -v '\*' >.shlist)
8d063cd8 124if $test -s .deptmp; then
125 for file in `cat .shlist`; do
352d5a3a 126 $echo `$expr X$file : 'X\(.*\).SH'`: $file config.sh \; \
8d063cd8 127 /bin/sh $file >> .deptmp
128 done
352d5a3a 129 $echo "Updating $mf..."
8d063cd8 130 $echo "# If this runs make out of memory, delete /usr/include lines." \
352d5a3a 131 >> $mf.new
8d063cd8 132 $sed 's|^\(.*\.o:\) *\(.*/.*\.c\) *$|\1 \2; '"$defrule \2|" .deptmp \
352d5a3a 133 >>$mf.new
8d063cd8 134else
135 make hlist || ($echo "Searching for .h files..."; \
a687059c 136 $echo *.h | $tr ' ' '\012' | $egrep -v '\*' >.hlist)
8d063cd8 137 $echo "You don't seem to have a proper C preprocessor. Using grep instead."
138 $egrep '^#include ' `cat .clist` `cat .hlist` >.deptmp
352d5a3a 139 $echo "Updating $mf..."
8d063cd8 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 '}' \
352d5a3a 145 -e 's|^\(.*\)\.c|\1.o: \1.c|p' >> $mf.new
8d063cd8 146 <.hlist $sed -n 's|\(.*/\)\(.*\)|s= \2= \1\2=|p' >.hsed
147 <.deptmp $sed -n 's|c:#include "\(.*\)".*$|o: \1|p' | \
148 $sed 's|^[^;]*/||' | \
352d5a3a 149 $sed -f .hsed >> $mf.new
8d063cd8 150 <.deptmp $sed -n 's|c:#include <\(.*\)>.*$|o: /usr/include/\1|p' \
352d5a3a 151 >> $mf.new
8d063cd8 152 <.deptmp $sed -n 's|h:#include "\(.*\)".*$|h: \1|p' | \
352d5a3a 153 $sed -f .hsed >> $mf.new
8d063cd8 154 <.deptmp $sed -n 's|h:#include <\(.*\)>.*$|h: /usr/include/\1|p' \
352d5a3a 155 >> $mf.new
8d063cd8 156 for file in `$cat .shlist`; do
352d5a3a 157 $echo `$expr X$file : 'X\(.*\).SH'`: $file config.sh \; \
158 /bin/sh $file >> $mf.new
8d063cd8 159 done
160fi
352d5a3a 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
8d063cd8 166$rm -f .deptmp `sed 's/\.c/.c.c/' .clist` .shlist .clist .hlist .hsed
167
168!NO!SUBS!
169$eunicefix makedepend
378cc40b 170chmod +x makedepend
8d063cd8 171case `pwd` in
172*SH)
173 $rm -f ../makedepend
174 ln makedepend ../makedepend
175 ;;
176esac