This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.000 patch.0i: fix glaring mistakes in patches a-h
[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
23!GROK!THIS!
24$spitshell >>makedepend <<'!NO!SUBS!'
a0d0e21e 25# makedepend.SH
8d063cd8 26#
8d063cd8
LW
27
28export PATH || (echo "OOPS, this isn't sh. Desperation time. I will feed myself to sh."; sh \$0; kill \$\$)
29
a0d0e21e
LW
30case $CONFIG in
31'')
32 if test -f config.sh; then TOP=.;
33 elif test -f ../config.sh; then TOP=..;
34 elif test -f ../../config.sh; then TOP=../..;
35 elif test -f ../../../config.sh; then TOP=../../..;
36 elif test -f ../../../../config.sh; then TOP=../../../..;
37 else
38 echo "Can't find config.sh."; exit 1
39 fi
40 . $TOP/config.sh
41 ;;
42esac
8d063cd8 43
7b0cd887
LW
44PATH="$PATH:."
45export PATH
46
8d063cd8
LW
47$cat /dev/null >.deptmp
48$rm -f *.c.c c/*.c.c
49if test -f Makefile; then
352d5a3a 50 cp Makefile makefile
8d063cd8 51fi
352d5a3a 52mf=makefile
8d063cd8
LW
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
85e6fe83
LW
71: Create files in UU directory to avoid problems with long filenames
72: on systems with 14 character filename limits so file.c.c and file.c
73: might be identical
74$test -d UU || mkdir UU
75
8d063cd8 76make clist || ($echo "Searching for .c files..."; \
a687059c 77 $echo *.c | $tr ' ' '\012' | $egrep -v '\*' >.clist)
8d063cd8
LW
78for file in `$cat .clist`; do
79# for file in `cat /dev/null`; do
80 case "$file" in
81 *.c) filebase=`basename $file .c` ;;
7b0cd887
LW
82 *.y) filebase=`basename $file .y` ;;
83 esac
84 case "$file" in
85 */*) finc="-I`echo $file | sed 's#/[^/]*$##`" ;;
86 *) finc= ;;
8d063cd8
LW
87 esac
88 $echo "Finding dependencies for $filebase.o."
7b0cd887
LW
89 ( $echo "#line 1 \"$file\""; \
90 $sed -n <$file \
8d063cd8 91 -e "/^${filebase}_init(/q" \
2304df62 92 -e '/^#line/d' \
8d063cd8
LW
93 -e '/^#/{' \
94 -e 's|/\*.*$||' \
95 -e 's|\\$||' \
96 -e p \
85e6fe83
LW
97 -e '}' ) >UU/$file.c
98 $cppstdin $finc -I/usr/local/include -I. $cppflags $cppminus <UU/$file.c |
8d063cd8 99 $sed \
75f92628 100 -e '/^#.*<stdin>/d' \
7b0cd887 101 -e 's#\.[0-9][0-9]*\.c#'"$file.c#" \
55204971 102 -e 's/^[ ]*#[ ]*line/#/' \
7b0cd887 103 -e '/^# *[0-9][0-9]* *[".\/]/!d' \
8d063cd8 104 -e 's/^.*"\(.*\)".*$/'$filebase'.o: \1/' \
7b0cd887 105 -e 's/^# *[0-9][0-9]* \(.*\)$/'$filebase'.o: \1/' \
8d063cd8
LW
106 -e 's|: \./|: |' \
107 -e 's|\.c\.c|.c|' | \
108 $uniq | $sort | $uniq >> .deptmp
109done
110
352d5a3a 111$sed <$mf >$mf.new -e '1,/^# AUTOMATICALLY/!d'
8d063cd8
LW
112
113make shlist || ($echo "Searching for .SH files..."; \
a687059c 114 $echo *.SH | $tr ' ' '\012' | $egrep -v '\*' >.shlist)
8d063cd8
LW
115if $test -s .deptmp; then
116 for file in `cat .shlist`; do
a0d0e21e 117 $echo `$expr X$file : 'X\(.*\).SH'`: $file $TOP/config.sh \; \
8d063cd8
LW
118 /bin/sh $file >> .deptmp
119 done
352d5a3a 120 $echo "Updating $mf..."
8d063cd8 121 $echo "# If this runs make out of memory, delete /usr/include lines." \
352d5a3a 122 >> $mf.new
8d063cd8 123 $sed 's|^\(.*\.o:\) *\(.*/.*\.c\) *$|\1 \2; '"$defrule \2|" .deptmp \
352d5a3a 124 >>$mf.new
8d063cd8
LW
125else
126 make hlist || ($echo "Searching for .h files..."; \
a687059c 127 $echo *.h | $tr ' ' '\012' | $egrep -v '\*' >.hlist)
8d063cd8
LW
128 $echo "You don't seem to have a proper C preprocessor. Using grep instead."
129 $egrep '^#include ' `cat .clist` `cat .hlist` >.deptmp
352d5a3a 130 $echo "Updating $mf..."
8d063cd8
LW
131 <.clist $sed -n \
132 -e '/\//{' \
133 -e 's|^\(.*\)/\(.*\)\.c|\2.o: \1/\2.c; '"$defrule \1/\2.c|p" \
134 -e d \
135 -e '}' \
352d5a3a 136 -e 's|^\(.*\)\.c|\1.o: \1.c|p' >> $mf.new
8d063cd8
LW
137 <.hlist $sed -n 's|\(.*/\)\(.*\)|s= \2= \1\2=|p' >.hsed
138 <.deptmp $sed -n 's|c:#include "\(.*\)".*$|o: \1|p' | \
139 $sed 's|^[^;]*/||' | \
352d5a3a 140 $sed -f .hsed >> $mf.new
8d063cd8 141 <.deptmp $sed -n 's|h:#include "\(.*\)".*$|h: \1|p' | \
352d5a3a 142 $sed -f .hsed >> $mf.new
8d063cd8 143 for file in `$cat .shlist`; do
a0d0e21e 144 $echo `$expr X$file : 'X\(.*\).SH'`: $file $TOP/config.sh \; \
352d5a3a 145 /bin/sh $file >> $mf.new
8d063cd8
LW
146 done
147fi
352d5a3a
LW
148$rm -f $mf.old
149$cp $mf $mf.old
150$cp $mf.new $mf
151$rm $mf.new
152$echo "# WARNING: Put nothing here or make depend will gobble it up!" >> $mf
85e6fe83 153$rm -rf .deptmp UU .shlist .clist .hlist .hsed
8d063cd8
LW
154
155!NO!SUBS!
156$eunicefix makedepend
378cc40b 157chmod +x makedepend
8d063cd8
LW
158case `pwd` in
159*SH)
160 $rm -f ../makedepend
161 ln makedepend ../makedepend
162 ;;
163esac