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