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