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