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