summaryrefslogtreecommitdiff
path: root/mcon/U/mkdep.U
blob: 36e8f5b8fa7773323bf3e7b465d8fa840632cc65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
?RCS: $Id$
?RCS:
?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
?RCS: 
?RCS: You may redistribute only under the terms of the Artistic License,
?RCS: as specified in the README file that comes with the distribution.
?RCS: You may reuse parts of this distribution only within the terms of
?RCS: that same Artistic License; a copy of which may be found at the root
?RCS: of the source tree for dist 4.0.
?RCS:
?RCS: $Log: mkdep.U,v $
?RCS: Revision 3.0.1.4  1997/02/28  16:13:07  ram
?RCS: patch61: replaced .o with $_o all over the place
?RCS:
?RCS: Revision 3.0.1.3  1994/10/29  16:25:02  ram
?RCS: patch36: added ?F: line for metalint file checking
?RCS:
?RCS: Revision 3.0.1.2  1994/01/24  14:15:12  ram
?RCS: patch16: cppflags is now an optional dependency
?RCS:
?RCS: Revision 3.0.1.1  1993/12/15  08:22:39  ram
?RCS: patch15: force zero exit status in all mkdep scripts
?RCS:
?RCS: Revision 3.0  1993/08/18  12:09:16  ram
?RCS: Baseline for dist 3.0 netwide release.
?RCS:
?X:
?X: This unit generates the script 'mkdep' in the top-level directory.
?X:	It is up to the makefile to use it for automatic dependencies
?X: generation (usage: 'mkdep [cppflags] -- *.c').
?X:
?MAKE:mkdep: spitshell startsh cpp +cppflags grep contains rm sed sort uniq \
	Getfile Oldconfig eunicefix cat +cc cppminus test pkgsrc _o
?MAKE:	-pick add $@ %<
?S:mkdep:
?S:	This variable holds the name of a command to generate makefile
?S:	dependencies on the standard output. It is the pathname of the
?S:	generated mkdep script.
?S:.
?F:mkdep
?T:IFS arg flags takeflags srcfile toplev filebase inc dir files file dep c
?T:tmpdir
?LINT:extern TMPDIR
: find out how to generate dependencies
echo " "
echo "Checking how to generate makefile dependencies on your machine..." >&4
?X: We are in the UU directory
toplev=`cd ..;pwd`
$cat >dep.c <<'EOCP'
#include "dep.h"
EOCP
?X: Empty dep.h causes RIOS to barf
$cat >dep.h <<'EOCP'

EOCP
takeflags='flags=""
case "$@" in
*--*)
	for arg
	do
		shift
		case "$arg" in
		--) break;;
		*) flags="$flags $arg";;
		esac
	done;;
esac'
case "$mkdep" in
'')
	;;
*)
	if test -f "$mkdep" &&
		$mkdep dep.c >dep.out 2>/dev/null &&
		$contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1
	then
		echo "$mkdep works."
?X: If they copied a config.sh from some other place, they'll have a working
?X: mkdep script probably, but not located at the top of the sources.  And
?X: the Makefiles generated by jmake expect an mkdep script in the top dir.
		case "$mkdep" in
		"$pkgsrc/mkdep");;
		*)	echo "(copying it to $pkgsrc)"
			cp $mkdep $pkgsrc/mkdep 2>/dev/null
	   		if $pkgsrc/mkdep dep.c >dep.out 2>/dev/null &&
				$contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1; then
				mkdep=$pkgsrc/mkdep
			else
				echo "Hmm... The copy failed or something... Guessing again..."
				mkdep=
			fi
			;;
		esac
	else
		mkdep=
	fi
esac

case "$mkdep" in
'')
?X: have to figure something out: Try cpp
?X: have to pass source names one by one to cpp...
	$spitshell > ../mkdep <<EOM
$startsh
$takeflags
for srcfile
do
	$cpp -M $cppflags \$flags \$srcfile 2>/dev/null
done
exit 0
EOM
	mkdep=$toplev/mkdep
	chmod +x $mkdep
	$eunicefix $mkdep
	if $mkdep dep.c >dep.out 2>/dev/null &&
		$contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1
	then
		echo "Looks like we can use $cpp -M."
	else
		mkdep=
	fi
	;;
esac

case "$mkdep" in
'')
?X: have to figure something out: on NeXT, use cc -MM
?X: have to pass source names one by one to cc...
	$spitshell > ../mkdep <<EOM
$startsh
$takeflags
for srcfile
do
	$cc -MM $cppflags \$flags \$srcfile 2>/dev/null
done
exit 0
EOM
	mkdep=$toplev/mkdep
	chmod +x $mkdep
	$eunicefix $mkdep
	if $mkdep dep.c >dep.out 2>/dev/null &&
		$contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1
	then
		echo "Looks like we can use $cc -MM."
	else
		mkdep=
	fi
	;;
esac

case "$mkdep" in
'')
?X: still no luck -- try something fancier.
	$spitshell >../mkdep <<EOS
$startsh
$takeflags
for srcfile
do
	case "\$srcfile" in
	*.c) c='.c';;
	*.y) c='.y';;
	*.l) c='.l';;
	esac
	filebase=\`basename \$srcfile \$c\`
	<\$srcfile $cpp $cppminus $cppflags \$flags 2>/dev/null | \\
	$sed -e '/^# *[0-9]/!d' \\
		-e 's/^.*"\(.*\)".*\$/'\$filebase'$_o: \1/' \\
		-e 's|: \./|: |' \\
		-e 's|: *$|: '\$srcfile'|' | \\
	$grep -v '^#' | $sort | $uniq
done
exit 0
EOS
	mkdep=$toplev/mkdep
	chmod +x $mkdep
	$eunicefix $mkdep
	if $mkdep dep.c >dep.out 2>/dev/null &&
		$contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1
	then
		echo "A shell script using $cpp does the trick."
	else
		echo "$cpp doesn't seem to be any use at all."
		$spitshell >../mkdep <<EOS
$startsh
$takeflags
files="\$@"
set X \$flags
shift
inc='.'
while test \$# -gt 0
do
	case "\$1" in
	-I) 
		shift
		inc="\$inc:\$1"
		;;
	-I*)
		dir=\`echo \$1 | sed -e 's/^-I//'\`
		inc="\$inc:\$dir"
		;;
	esac
	shift
done
set X \$files
shift
tmpdir="${TMPDIR:-/tmp}"
trap "$rm -f "$tmpdir/mkdep\$\$"; exit 1" 1 2 3 15
for srcfile
do
	case "\$srcfile" in
	*.c) c='.c';;
	*.y) c='.y';;
	*.l) c='.l';;
	esac
	filebase=\`basename \$srcfile \$c\`
	echo \$filebase$_o: \$srcfile
	$grep '^#[  ]*include' \$srcfile /dev/null | \
	$sed -n -e 's/#[   ]*include[  ]*//' \\
		-e '/<\(.*\)>/ d' \\
		-e 's/:[^"]*"\([^"]*\)".*/: \1/' \\
		-e "s/\\.c:/$_o:/p" > "$tmpdir/mkdep\$\$"
?X: Deal with directories specified via -I requests to locate files
	IFS=': '
	while read file dep; do
		for dir in \$inc; do
			if $test -f "\$dir/\$dep"; then
				dep="\$dir/\$dep"
				break
			fi
		done
		echo "\$file: \$dep" | $sed -e 's,: \./,: ,'
	done <"$tmpdir/mkdep\$\$"
	IFS=' '
	$rm -f "$tmpdir/mkdep\$\$" 
done
exit 0
EOS
		mkdep=$toplev/mkdep
		chmod +x $mkdep
		$eunicefix $mkdep
		if $mkdep dep.c >dep.out 2>/dev/null &&
			$contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1
		then
			cat << EOM

I can use a script with grep instead, but it will make some incorrect
dependencies, since it doesn't understand about conditional compilation.
Moreover, some dependencies may be missing, because scanning won't be
a recursive process.
If you have a program which generates makefile dependencies, you may want
to use it.  If not, you can use the script and edit the Makefile by hand
if you need to.
EOM
		else
			mkdep=
			cat << EOM

I can't seem to generate makefile dependencies at all!  Perhaps you have a
program that does?  If you don't, you might look at the mkdep script to
see if you can create one which works.
EOM
		fi
	fi
esac
echo " "
dflt="$mkdep"
fn=f~/
rp="Name of program to make makefile dependencies?"
. ./getfile
mkdep="$ans"
$rm -f dep.c dep.h dep$_o dep.out