This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 4.0 patch 6: patch #4, continued
[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)
fe14fcc3 8 fi 2>/dev/null
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
fe14fcc3 18# $Header: makedepend.SH,v 4.0 91/03/20 01:27:04 lwall Locked $
8d063cd8
LW
19#
20# $Log: makedepend.SH,v $
fe14fcc3
LW
21# Revision 4.0 91/03/20 01:27:04 lwall
22# 4.0 baseline.
bf38876a 23#
8d063cd8
LW
24#
25
26export PATH || (echo "OOPS, this isn't sh. Desperation time. I will feed myself to sh."; sh \$0; kill \$\$)
27
28cat='$cat'
bf38876a 29cppflags='$cppflags'
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
46$cat /dev/null >.deptmp
47$rm -f *.c.c c/*.c.c
48if test -f Makefile; then
49 mf=Makefile
50else
51 mf=makefile
52fi
53if test -f $mf; then
54 defrule=`<$mf sed -n \
55 -e '/^\.c\.o:.*;/{' \
56 -e 's/\$\*\.c//' \
57 -e 's/^[^;]*;[ ]*//p' \
58 -e q \
59 -e '}' \
60 -e '/^\.c\.o: *$/{' \
61 -e N \
62 -e 's/\$\*\.c//' \
63 -e 's/^.*\n[ ]*//p' \
64 -e q \
65 -e '}'`
66fi
67case "$defrule" in
68'') defrule='$(CC) -c $(CFLAGS)' ;;
69esac
70
71make clist || ($echo "Searching for .c files..."; \
a687059c 72 $echo *.c | $tr ' ' '\012' | $egrep -v '\*' >.clist)
8d063cd8
LW
73for file in `$cat .clist`; do
74# for file in `cat /dev/null`; do
75 case "$file" in
76 *.c) filebase=`basename $file .c` ;;
77 *.y) filebase=`basename $file .c` ;;
78 esac
79 $echo "Finding dependencies for $filebase.o."
80 $sed -n <$file >$file.c \
81 -e "/^${filebase}_init(/q" \
82 -e '/^#/{' \
83 -e 's|/\*.*$||' \
84 -e 's|\\$||' \
85 -e p \
86 -e '}'
bf38876a 87 $cpp -I/usr/local/include -I. $cppflags $file.c | \
8d063cd8
LW
88 $sed \
89 -e '/^# *[0-9]/!d' \
90 -e 's/^.*"\(.*\)".*$/'$filebase'.o: \1/' \
91 -e 's|: \./|: |' \
92 -e 's|\.c\.c|.c|' | \
93 $uniq | $sort | $uniq >> .deptmp
94done
95
96$sed <Makefile >Makefile.new -e '1,/^# AUTOMATICALLY/!d'
97
98make shlist || ($echo "Searching for .SH files..."; \
a687059c 99 $echo *.SH | $tr ' ' '\012' | $egrep -v '\*' >.shlist)
8d063cd8
LW
100if $test -s .deptmp; then
101 for file in `cat .shlist`; do
102 $echo `$expr X$file : 'X\(.*\).SH`: $file config.sh \; \
103 /bin/sh $file >> .deptmp
104 done
105 $echo "Updating Makefile..."
106 $echo "# If this runs make out of memory, delete /usr/include lines." \
107 >> Makefile.new
108 $sed 's|^\(.*\.o:\) *\(.*/.*\.c\) *$|\1 \2; '"$defrule \2|" .deptmp \
109 >>Makefile.new
110else
111 make hlist || ($echo "Searching for .h files..."; \
a687059c 112 $echo *.h | $tr ' ' '\012' | $egrep -v '\*' >.hlist)
8d063cd8
LW
113 $echo "You don't seem to have a proper C preprocessor. Using grep instead."
114 $egrep '^#include ' `cat .clist` `cat .hlist` >.deptmp
115 $echo "Updating Makefile..."
116 <.clist $sed -n \
117 -e '/\//{' \
118 -e 's|^\(.*\)/\(.*\)\.c|\2.o: \1/\2.c; '"$defrule \1/\2.c|p" \
119 -e d \
120 -e '}' \
121 -e 's|^\(.*\)\.c|\1.o: \1.c|p' >> Makefile.new
122 <.hlist $sed -n 's|\(.*/\)\(.*\)|s= \2= \1\2=|p' >.hsed
123 <.deptmp $sed -n 's|c:#include "\(.*\)".*$|o: \1|p' | \
124 $sed 's|^[^;]*/||' | \
125 $sed -f .hsed >> Makefile.new
126 <.deptmp $sed -n 's|c:#include <\(.*\)>.*$|o: /usr/include/\1|p' \
127 >> Makefile.new
128 <.deptmp $sed -n 's|h:#include "\(.*\)".*$|h: \1|p' | \
129 $sed -f .hsed >> Makefile.new
130 <.deptmp $sed -n 's|h:#include <\(.*\)>.*$|h: /usr/include/\1|p' \
131 >> Makefile.new
132 for file in `$cat .shlist`; do
133 $echo `$expr X$file : 'X\(.*\).SH`: $file config.sh \; \
134 /bin/sh $file >> Makefile.new
135 done
136fi
137$rm -f Makefile.old
138$cp Makefile Makefile.old
139$cp Makefile.new Makefile
140$rm Makefile.new
141$echo "# WARNING: Put nothing here or make depend will gobble it up!" >> Makefile
142$rm -f .deptmp `sed 's/\.c/.c.c/' .clist` .shlist .clist .hlist .hsed
143
144!NO!SUBS!
145$eunicefix makedepend
378cc40b 146chmod +x makedepend
8d063cd8
LW
147case `pwd` in
148*SH)
149 $rm -f ../makedepend
150 ln makedepend ../makedepend
151 ;;
152esac