This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
This is my patch patch.1i for perl5.001.
[perl5.git] / makedepend.SH
CommitLineData
8d063cd8
LW
1case $CONFIG in
2'')
a0d0e21e
LW
3 if test -f config.sh; then TOP=.;
4 elif test -f ../config.sh; then TOP=..;
5 elif test -f ../../config.sh; then TOP=../..;
6 elif test -f ../../../config.sh; then TOP=../../..;
7 elif test -f ../../../../config.sh; then TOP=../../../..;
8 else
9 echo "Can't find config.sh."; exit 1
10 fi
11 . $TOP/config.sh
12 ;;
8d063cd8 13esac
a0d0e21e
LW
14: This forces SH files to create target in same directory as SH file.
15: This is so that make depend always knows where to find SH derivatives.
8d063cd8
LW
16case "$0" in
17*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
18esac
19echo "Extracting makedepend (with variable substitutions)"
7b0cd887 20rm -f makedepend
75f92628
AD
21$spitshell >makedepend <<!GROK!THIS!
22$startsh
a0d0e21e 23# makedepend.SH
8d063cd8 24#
1aef975c
AD
25## To use an alternate make, set \$altmake in config.sh.
26MAKE=${altmake-make}
27!GROK!THIS!
28$spitshell >>makedepend <<'!NO!SUBS!'
8d063cd8
LW
29
30export PATH || (echo "OOPS, this isn't sh. Desperation time. I will feed myself to sh."; sh \$0; kill \$\$)
31
a0d0e21e
LW
32case $CONFIG in
33'')
34 if test -f config.sh; then TOP=.;
35 elif test -f ../config.sh; then TOP=..;
36 elif test -f ../../config.sh; then TOP=../..;
37 elif test -f ../../../config.sh; then TOP=../../..;
38 elif test -f ../../../../config.sh; then TOP=../../../..;
39 else
40 echo "Can't find config.sh."; exit 1
41 fi
42 . $TOP/config.sh
43 ;;
44esac
8d063cd8 45
16d20bd9
AD
46# We need .. when we are in the x2p directory if we are using the
47# cppstdin wrapper script.
48PATH="$PATH:.:.."
7b0cd887
LW
49export PATH
50
8d063cd8
LW
51$cat /dev/null >.deptmp
52$rm -f *.c.c c/*.c.c
53if test -f Makefile; then
352d5a3a 54 cp Makefile makefile
8d063cd8 55fi
352d5a3a 56mf=makefile
8d063cd8
LW
57if test -f $mf; then
58 defrule=`<$mf sed -n \
59 -e '/^\.c\.o:.*;/{' \
60 -e 's/\$\*\.c//' \
61 -e 's/^[^;]*;[ ]*//p' \
62 -e q \
63 -e '}' \
64 -e '/^\.c\.o: *$/{' \
65 -e N \
66 -e 's/\$\*\.c//' \
67 -e 's/^.*\n[ ]*//p' \
68 -e q \
69 -e '}'`
70fi
71case "$defrule" in
72'') defrule='$(CC) -c $(CFLAGS)' ;;
73esac
74
85e6fe83
LW
75: Create files in UU directory to avoid problems with long filenames
76: on systems with 14 character filename limits so file.c.c and file.c
77: might be identical
78$test -d UU || mkdir UU
79
1aef975c 80$MAKE clist || ($echo "Searching for .c files..."; \
a687059c 81 $echo *.c | $tr ' ' '\012' | $egrep -v '\*' >.clist)
8d063cd8
LW
82for file in `$cat .clist`; do
83# for file in `cat /dev/null`; do
84 case "$file" in
85 *.c) filebase=`basename $file .c` ;;
7b0cd887
LW
86 *.y) filebase=`basename $file .y` ;;
87 esac
88 case "$file" in
89 */*) finc="-I`echo $file | sed 's#/[^/]*$##`" ;;
90 *) finc= ;;
8d063cd8
LW
91 esac
92 $echo "Finding dependencies for $filebase.o."
7b0cd887
LW
93 ( $echo "#line 1 \"$file\""; \
94 $sed -n <$file \
8d063cd8 95 -e "/^${filebase}_init(/q" \
2304df62 96 -e '/^#line/d' \
8d063cd8
LW
97 -e '/^#/{' \
98 -e 's|/\*.*$||' \
99 -e 's|\\$||' \
100 -e p \
85e6fe83
LW
101 -e '}' ) >UU/$file.c
102 $cppstdin $finc -I/usr/local/include -I. $cppflags $cppminus <UU/$file.c |
8d063cd8 103 $sed \
75f92628 104 -e '/^#.*<stdin>/d' \
7b0cd887 105 -e 's#\.[0-9][0-9]*\.c#'"$file.c#" \
55204971 106 -e 's/^[ ]*#[ ]*line/#/' \
7b0cd887 107 -e '/^# *[0-9][0-9]* *[".\/]/!d' \
8d063cd8 108 -e 's/^.*"\(.*\)".*$/'$filebase'.o: \1/' \
7b0cd887 109 -e 's/^# *[0-9][0-9]* \(.*\)$/'$filebase'.o: \1/' \
8d063cd8
LW
110 -e 's|: \./|: |' \
111 -e 's|\.c\.c|.c|' | \
112 $uniq | $sort | $uniq >> .deptmp
113done
114
352d5a3a 115$sed <$mf >$mf.new -e '1,/^# AUTOMATICALLY/!d'
8d063cd8 116
1aef975c 117$MAKE shlist || ($echo "Searching for .SH files..."; \
a687059c 118 $echo *.SH | $tr ' ' '\012' | $egrep -v '\*' >.shlist)
8d063cd8
LW
119if $test -s .deptmp; then
120 for file in `cat .shlist`; do
a0d0e21e 121 $echo `$expr X$file : 'X\(.*\).SH'`: $file $TOP/config.sh \; \
8d063cd8
LW
122 /bin/sh $file >> .deptmp
123 done
352d5a3a 124 $echo "Updating $mf..."
8d063cd8 125 $echo "# If this runs make out of memory, delete /usr/include lines." \
352d5a3a 126 >> $mf.new
8d063cd8 127 $sed 's|^\(.*\.o:\) *\(.*/.*\.c\) *$|\1 \2; '"$defrule \2|" .deptmp \
352d5a3a 128 >>$mf.new
8d063cd8 129else
1aef975c 130 $MAKE hlist || ($echo "Searching for .h files..."; \
a687059c 131 $echo *.h | $tr ' ' '\012' | $egrep -v '\*' >.hlist)
8d063cd8
LW
132 $echo "You don't seem to have a proper C preprocessor. Using grep instead."
133 $egrep '^#include ' `cat .clist` `cat .hlist` >.deptmp
352d5a3a 134 $echo "Updating $mf..."
8d063cd8
LW
135 <.clist $sed -n \
136 -e '/\//{' \
137 -e 's|^\(.*\)/\(.*\)\.c|\2.o: \1/\2.c; '"$defrule \1/\2.c|p" \
138 -e d \
139 -e '}' \
352d5a3a 140 -e 's|^\(.*\)\.c|\1.o: \1.c|p' >> $mf.new
8d063cd8
LW
141 <.hlist $sed -n 's|\(.*/\)\(.*\)|s= \2= \1\2=|p' >.hsed
142 <.deptmp $sed -n 's|c:#include "\(.*\)".*$|o: \1|p' | \
143 $sed 's|^[^;]*/||' | \
352d5a3a 144 $sed -f .hsed >> $mf.new
8d063cd8 145 <.deptmp $sed -n 's|h:#include "\(.*\)".*$|h: \1|p' | \
352d5a3a 146 $sed -f .hsed >> $mf.new
8d063cd8 147 for file in `$cat .shlist`; do
a0d0e21e 148 $echo `$expr X$file : 'X\(.*\).SH'`: $file $TOP/config.sh \; \
352d5a3a 149 /bin/sh $file >> $mf.new
8d063cd8
LW
150 done
151fi
352d5a3a
LW
152$rm -f $mf.old
153$cp $mf $mf.old
154$cp $mf.new $mf
155$rm $mf.new
156$echo "# WARNING: Put nothing here or make depend will gobble it up!" >> $mf
85e6fe83 157$rm -rf .deptmp UU .shlist .clist .hlist .hsed
8d063cd8
LW
158
159!NO!SUBS!
160$eunicefix makedepend
378cc40b 161chmod +x makedepend
8d063cd8
LW
162case `pwd` in
163*SH)
164 $rm -f ../makedepend
165 ln makedepend ../makedepend
166 ;;
167esac