xref: /netbsd-src/external/gpl3/binutils/dist/mkdep (revision 2a6b7db32dd0fcd096655620989789704fbe4a7d)
1*2a6b7db3Sskrll#!/bin/sh -
2*2a6b7db3Sskrll#
3*2a6b7db3Sskrll# Copyright (c) 1987 Regents of the University of California.
4*2a6b7db3Sskrll# All rights reserved.
5*2a6b7db3Sskrll#
6*2a6b7db3Sskrll# Redistribution and use in source and binary forms are permitted
7*2a6b7db3Sskrll# provided that the above copyright notice and this paragraph are
8*2a6b7db3Sskrll# duplicated in all such forms and that any documentation,
9*2a6b7db3Sskrll# advertising materials, and other materials related to such
10*2a6b7db3Sskrll# distribution and use acknowledge that the software was developed
11*2a6b7db3Sskrll# by the University of California, Berkeley.  The name of the
12*2a6b7db3Sskrll# University may not be used to endorse or promote products derived
13*2a6b7db3Sskrll# from this software without specific prior written permission.
14*2a6b7db3Sskrll# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15*2a6b7db3Sskrll# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16*2a6b7db3Sskrll# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17*2a6b7db3Sskrll#
18*2a6b7db3Sskrll#	@(#)mkdep.sh	5.12 (Berkeley) 6/30/88
19*2a6b7db3Sskrll#
20*2a6b7db3Sskrll
21*2a6b7db3SskrllMAKE=Makefile			# default makefile name is "Makefile"
22*2a6b7db3Sskrll
23*2a6b7db3Sskrllwhile :
24*2a6b7db3Sskrll	do case "$1" in
25*2a6b7db3Sskrll		# -f allows you to select a makefile name
26*2a6b7db3Sskrll		-f)
27*2a6b7db3Sskrll			MAKE=$2
28*2a6b7db3Sskrll			shift; shift ;;
29*2a6b7db3Sskrll
30*2a6b7db3Sskrll		# the -p flag produces "program: program.c" style dependencies
31*2a6b7db3Sskrll		# so .o's don't get produced
32*2a6b7db3Sskrll		-p)
33*2a6b7db3Sskrll			SED='s;\.o;;'
34*2a6b7db3Sskrll			shift ;;
35*2a6b7db3Sskrll		*)
36*2a6b7db3Sskrll			break ;;
37*2a6b7db3Sskrll	esac
38*2a6b7db3Sskrlldone
39*2a6b7db3Sskrll
40*2a6b7db3Sskrllif [ $# = 0 ] ; then
41*2a6b7db3Sskrll	echo 'usage: mkdep [-p] [-f makefile] [flags] file ...'
42*2a6b7db3Sskrll	exit 1
43*2a6b7db3Sskrllfi
44*2a6b7db3Sskrll
45*2a6b7db3Sskrllif [ ! -w $MAKE ]; then
46*2a6b7db3Sskrll	echo "mkdep: no writeable file \"$MAKE\""
47*2a6b7db3Sskrll	exit 1
48*2a6b7db3Sskrllfi
49*2a6b7db3Sskrll
50*2a6b7db3SskrllTMP=/tmp/mkdep$$
51*2a6b7db3Sskrll
52*2a6b7db3Sskrlltrap 'rm -f $TMP ; exit 1' 1 2 3 13 15
53*2a6b7db3Sskrll
54*2a6b7db3Sskrllcp $MAKE ${MAKE}.bak
55*2a6b7db3Sskrll
56*2a6b7db3Sskrllsed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
57*2a6b7db3Sskrll
58*2a6b7db3Sskrllcat << _EOF_ >> $TMP
59*2a6b7db3Sskrll# DO NOT DELETE THIS LINE -- mkdep uses it.
60*2a6b7db3Sskrll# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
61*2a6b7db3Sskrll
62*2a6b7db3Sskrll_EOF_
63*2a6b7db3Sskrll
64*2a6b7db3Sskrll# If your compiler doesn't have -M, add it.  If you can't, the next two
65*2a6b7db3Sskrll# lines will try and replace the "cc -M".  The real problem is that this
66*2a6b7db3Sskrll# hack can't deal with anything that requires a search path, and doesn't
67*2a6b7db3Sskrll# even try for anything using bracket (<>) syntax.
68*2a6b7db3Sskrll#
69*2a6b7db3Sskrll# egrep '^#include[ 	]*".*"' /dev/null $* |
70*2a6b7db3Sskrll# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
71*2a6b7db3Sskrll
72*2a6b7db3Sskrllgcc -MM $* |
73*2a6b7db3Sskrllsed "
74*2a6b7db3Sskrll	s; \./; ;g
75*2a6b7db3Sskrll	$SED" >> $TMP
76*2a6b7db3Sskrll
77*2a6b7db3Sskrllcat << _EOF_ >> $TMP
78*2a6b7db3Sskrll
79*2a6b7db3Sskrll# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
80*2a6b7db3Sskrll_EOF_
81*2a6b7db3Sskrll
82*2a6b7db3Sskrll# copy to preserve permissions
83*2a6b7db3Sskrllcp $TMP $MAKE
84*2a6b7db3Sskrllrm -f ${MAKE}.bak $TMP
85*2a6b7db3Sskrllexit 0
86*2a6b7db3Sskrll
87*2a6b7db3Sskrll
88