1 ?RCS: $Id: mkdep.U,v 3.0.1.4 1997/02/28 16:13:07 ram Exp $
3 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
5 ?RCS: You may redistribute only under the terms of the Artistic Licence,
6 ?RCS: as specified in the README file that comes with the distribution.
7 ?RCS: You may reuse parts of this distribution only within the terms of
8 ?RCS: that same Artistic Licence; a copy of which may be found at the root
9 ?RCS: of the source tree for dist 3.0.
11 ?RCS: $Log: mkdep.U,v $
12 ?RCS: Revision 3.0.1.4 1997/02/28 16:13:07 ram
13 ?RCS: patch61: replaced .o with $_o all over the place
15 ?RCS: Revision 3.0.1.3 1994/10/29 16:25:02 ram
16 ?RCS: patch36: added ?F: line for metalint file checking
18 ?RCS: Revision 3.0.1.2 1994/01/24 14:15:12 ram
19 ?RCS: patch16: cppflags is now an optional dependency
21 ?RCS: Revision 3.0.1.1 1993/12/15 08:22:39 ram
22 ?RCS: patch15: force zero exit status in all mkdep scripts
24 ?RCS: Revision 3.0 1993/08/18 12:09:16 ram
25 ?RCS: Baseline for dist 3.0 netwide release.
28 ?X: This unit generates the script 'mkdep' in the top-level directory.
29 ?X: It is up to the makefile to use it for automatic dependencies
30 ?X: generation (usage: 'mkdep [cppflags] -- *.c').
32 ?MAKE:mkdep: spitshell startsh cpp +cppflags grep contains rm sed sort uniq \
33 Getfile Oldconfig eunicefix cat +cc cppminus test _o
34 ?MAKE: -pick add $@ %<
36 ?S: This variable holds the name of a command to generate makefile
37 ?S: dependencies on the standard output. It is the pathname of the
38 ?S: generated mkdep script.
41 ?T:IFS arg flags takeflags srcfile toplev filebase inc dir files file dep c
42 : find out how to generate dependencies
44 echo "Checking how to generate makefile dependencies on your machine..." >&4
45 ?X: We are in the UU directory
50 ?X: Empty dep.h causes RIOS to barf
62 *) flags="$flags $arg";;
70 if test -x "$mkdep" &&
71 $mkdep dep.c >dep.out 2>/dev/null &&
72 $contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1
82 ?X: have to figure something out: Try cpp
83 ?X: have to pass source names one by one to cpp...
84 $spitshell > ../mkdep <<EOM
89 $cpp -M -I. $cppflags \$flags \$srcfile 2>/dev/null
96 if $mkdep dep.c >dep.out 2>/dev/null &&
97 $contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1
99 echo "Looks like we can use $cpp -M."
108 ?X: have to figure something out: on NeXT, use cc -MM
109 ?X: have to pass source names one by one to cc...
110 $spitshell > ../mkdep <<EOM
115 $cc -MM -I. $cppflags \$flags \$srcfile 2>/dev/null
122 if $mkdep dep.c >dep.out 2>/dev/null &&
123 $contains "dep$_o: dep.h" dep.out >/dev/null 2>&1
125 echo "Looks like we can use $cc -MM."
134 ?X: still no luck -- try something fancier.
135 $spitshell >../mkdep <<EOS
145 filebase=\`basename \$srcfile \$c\`
146 <\$srcfile $cpp $cppminus $cppflags -I. \$flags 2>/dev/null | \\
147 $sed -e '/^# *[0-9]/!d' \\
148 -e 's/^.*"\(.*\)".*\$/'\$filebase'$_o: \1/' \\
150 -e 's|: *$|: '\$srcfile'|' | \\
151 $grep -v '^#' | $sort | $uniq
158 if $mkdep dep.c >dep.out 2>/dev/null &&
159 $contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1
161 echo "A shell script using $cpp does the trick."
163 echo "$cpp doesn't seem to be any use at all."
164 $spitshell >../mkdep <<EOS
179 dir=\`echo \$1 | sed -e 's/^-I//'\`
187 trap "$rm -f /tmp/mkdep\$\$; exit 1" 1 2 3 15
195 filebase=\`basename \$srcfile \$c\`
196 echo \$filebase$_o: \$srcfile
197 $grep '^#[ ]*include' \$srcfile /dev/null | \
198 $sed -n -e 's/#[ ]*include[ ]*//' \\
200 -e 's/:[^"]*"\([^"]*\)".*/: \1/' \\
201 -e "s/\\.c:/$_o:/p" > /tmp/mkdep\$\$
202 ?X: Deal with directories specified via -I requests to locate files
204 while read file dep; do
206 if $test -f "\$dir/\$dep"; then
211 echo "\$file: \$dep" | $sed -e 's,: \./,: ,'
214 $rm -f /tmp/mkdep\$\$
221 if $mkdep dep.c >dep.out 2>/dev/null &&
222 $contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1
226 I can use a script with grep instead, but it will make some incorrect
227 dependencies, since it doesn't understand about conditional compilation.
228 Moreover, some dependencies may be missing, because scanning won't be
230 If you have a program which generates makefile dependencies, you may want
231 to use it. If not, you can use the script and edit the Makefile by hand
238 I can't seem to generate makefile dependencies at all! Perhaps you have a
239 program that does? If you don't, you might look at the mkdep script to
240 see if you can create one which works.
247 rp="Name of program to make makefile dependencies?"
250 $rm -f dep.c dep.h dep$_o dep.out