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