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