1 ?RCS: $Id: mkdep.U 1 2006-08-24 12:32:52Z rmanfredi $
3 ?RCS: Copyright (c) 1991-1997, 2004-2006, 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 4.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 pkgsrc _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 -f "$mkdep" &&
71 $mkdep dep.c >dep.out 2>/dev/null &&
72 $contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1
75 ?X: If they copied a config.sh from some other place, they'll have a working
76 ?X: mkdep script probably, but not located at the top of the sources. And
77 ?X: the Makefiles generated by jmake expect an mkdep script in the top dir.
80 *) echo "(copying it to $pkgsrc)"
81 cp $mkdep $pkgsrc/mkdep 2>/dev/null
82 if $pkgsrc/mkdep dep.c >dep.out 2>/dev/null &&
83 $contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1; then
86 echo "Hmm... The copy failed or something... Guessing again..."
98 ?X: have to figure something out: Try cpp
99 ?X: have to pass source names one by one to cpp...
100 $spitshell > ../mkdep <<EOM
105 $cpp -M $cppflags \$flags \$srcfile 2>/dev/null
112 if $mkdep dep.c >dep.out 2>/dev/null &&
113 $contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1
115 echo "Looks like we can use $cpp -M."
124 ?X: have to figure something out: on NeXT, use cc -MM
125 ?X: have to pass source names one by one to cc...
126 $spitshell > ../mkdep <<EOM
131 $cc -MM $cppflags \$flags \$srcfile 2>/dev/null
138 if $mkdep dep.c >dep.out 2>/dev/null &&
139 $contains "dep$_o: dep.h" dep.out >/dev/null 2>&1
141 echo "Looks like we can use $cc -MM."
150 ?X: still no luck -- try something fancier.
151 $spitshell >../mkdep <<EOS
161 filebase=\`basename \$srcfile \$c\`
162 <\$srcfile $cpp $cppminus $cppflags \$flags 2>/dev/null | \\
163 $sed -e '/^# *[0-9]/!d' \\
164 -e 's/^.*"\(.*\)".*\$/'\$filebase'$_o: \1/' \\
166 -e 's|: *$|: '\$srcfile'|' | \\
167 $grep -v '^#' | $sort | $uniq
174 if $mkdep dep.c >dep.out 2>/dev/null &&
175 $contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1
177 echo "A shell script using $cpp does the trick."
179 echo "$cpp doesn't seem to be any use at all."
180 $spitshell >../mkdep <<EOS
195 dir=\`echo \$1 | sed -e 's/^-I//'\`
203 trap "$rm -f /tmp/mkdep\$\$; exit 1" 1 2 3 15
211 filebase=\`basename \$srcfile \$c\`
212 echo \$filebase$_o: \$srcfile
213 $grep '^#[ ]*include' \$srcfile /dev/null | \
214 $sed -n -e 's/#[ ]*include[ ]*//' \\
216 -e 's/:[^"]*"\([^"]*\)".*/: \1/' \\
217 -e "s/\\.c:/$_o:/p" > /tmp/mkdep\$\$
218 ?X: Deal with directories specified via -I requests to locate files
220 while read file dep; do
222 if $test -f "\$dir/\$dep"; then
227 echo "\$file: \$dep" | $sed -e 's,: \./,: ,'
230 $rm -f /tmp/mkdep\$\$
237 if $mkdep dep.c >dep.out 2>/dev/null &&
238 $contains "dep$_o:.*dep\.h" dep.out >/dev/null 2>&1
242 I can use a script with grep instead, but it will make some incorrect
243 dependencies, since it doesn't understand about conditional compilation.
244 Moreover, some dependencies may be missing, because scanning won't be
246 If you have a program which generates makefile dependencies, you may want
247 to use it. If not, you can use the script and edit the Makefile by hand
254 I can't seem to generate makefile dependencies at all! Perhaps you have a
255 program that does? If you don't, you might look at the mkdep script to
256 see if you can create one which works.
264 rp="Name of program to make makefile dependencies?"
267 $rm -f dep.c dep.h dep$_o dep.out