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