xref: /minix/external/bsd/bind/dist/make/mkdep.in (revision fb9c64b2)
1#!/bin/sh -
2
3##
4## Modified to handle -vpath <path> option by Michael Graff, ISC.
5## The purpose of this is to allow this script to run outside of the
6## source directory, for instance when running configure with
7##   ../bind9-mainline/configure
8## and still have "make depend" work.
9##
10
11## ++Copyright++ 1987
12## -
13## Copyright (c) 1987 Regents of the University of California.
14## All rights reserved.
15##
16## Redistribution and use in source and binary forms, with or without
17## modification, are permitted provided that the following conditions
18## are met:
19## 1. Redistributions of source code must retain the above copyright
20##    notice, this list of conditions and the following disclaimer.
21## 2. Redistributions in binary form must reproduce the above copyright
22##    notice, this list of conditions and the following disclaimer in the
23##    documentation and/or other materials provided with the distribution.
24## 3. Neither the name of the University nor the names of its contributors
25##    may be used to endorse or promote products derived from this software
26##    without specific prior written permission.
27## THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30## ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37## SUCH DAMAGE.
38## -
39## Portions Copyright (c) 1993 by Digital Equipment Corporation.
40##
41## Permission to use, copy, modify, and distribute this software for any
42## purpose with or without fee is hereby granted, provided that the above
43## copyright notice and this permission notice appear in all copies, and that
44## the name of Digital Equipment Corporation not be used in advertising or
45## publicity pertaining to distribution of the document or software without
46## specific, written prior permission.
47##
48## THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
49## WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
50## OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
51## CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
52## DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
53## PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
54## ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
55## SOFTWARE.
56## -
57## --Copyright--
58
59#
60#	@(#)mkdep.sh	5.12 (Berkeley) 6/30/88
61#
62
63MAKE=Makefile			# default makefile name is "Makefile"
64
65while :
66	do case "$1" in
67		# -vpath allows one to select a virtual path for .c files
68		-vpath)
69			VPATH=$2;
70			shift; shift ;;
71		# -f allows you to select a makefile name
72		-f)
73			MAKE=$2
74			shift; shift ;;
75
76		# the -p flag produces "program: program.c" style dependencies
77		# so .o's don't get produced
78		-p)
79			SED='s;\.o;;'
80			shift ;;
81		*)
82			break ;;
83	esac
84done
85
86if [ $# = 0 ] ; then
87	echo 'usage: mkdep [-vpath path] [-p] [-f makefile] [flags] file ...'
88	exit 1
89fi
90
91if [ ! -w $MAKE ]; then
92	echo "mkdep: no writeable file \"$MAKE\""
93	exit 1
94fi
95
96TMP=mkdep$$
97
98trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
99
100cp $MAKE ${MAKE}.bak
101
102sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
103
104cat << _EOF_ >> $TMP
105# DO NOT DELETE THIS LINE -- mkdep uses it.
106# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
107
108_EOF_
109
110# If your compiler doesn't have -M, add it.  If you can't, the next two
111# lines will try and replace the "cc -M".  The real problem is that this
112# hack can't deal with anything that requires a search path, and doesn't
113# even try for anything using bracket (<>) syntax.
114#
115# egrep '^#include[ 	]*".*"' /dev/null $* |
116# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
117
118if [ X"${VPATH}" != X ] ; then
119    for arg in $* ; do
120	case "$arg" in
121	    -*)
122		newargs="$newargs $arg"
123		;;
124	    *)
125		newargs="$newargs $VPATH/$arg"
126		;;
127	esac
128    done
129else
130    newargs="$*";
131fi
132
133MKDEPPROG="@MKDEPPROG@"
134if [ X"${MKDEPPROG}" != X ]; then
135    @SHELL@ -c "${MKDEPPROG} ${newargs}"
136else
137    @MKDEPCC@ @MKDEPCFLAGS@ ${newargs} |
138    sed "
139	s; \\./; ;g
140	s; \\\\; ;g
141	@LIBTOOL_MKDEP_SED@
142	$SED" |
143    awk '$1 ~ /:$/ {
144		if (rec != "")
145			 print rec;
146		if (NF == 1)
147			rec = $1;
148		else
149			rec = $1 " " $2;
150		for (i = 3; i <= NF; i++) {
151			if (length(rec $i) > 76) {
152				print rec " \\";
153				rec = "    " $i;
154			} else {
155				rec = rec " " $i;
156			}
157		}
158		next;
159	}
160	{
161		for (i = 1; i <= NF; i++) {
162			if (length(rec $i) > 76) {
163				print rec, "\\";
164				rec =  "    " $i;
165			} else {
166				rec = rec " " $i;
167			}
168		}
169	}
170    END {
171	print rec
172    }' >> $TMP
173fi
174
175cat << _EOF_ >> $TMP
176
177# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
178_EOF_
179
180# copy to preserve permissions
181cp $TMP $MAKE
182rm -f ${MAKE}.bak $TMP
183exit 0
184