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