694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley#!/bin/sh -
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews##
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews## Modified to handle -vpath <path> option by Michael Graff, ISC.
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews## The purpose of this is to allow this script to run outside of the
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews## source directory, for instance when running configure with
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews## ../bind9-mainline/configure
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews## and still have "make depend" work.
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews##
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## ++Copyright++ 1987
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## -
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## Copyright (c) 1987 Regents of the University of California.
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## All rights reserved.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence##
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## Redistribution and use in source and binary forms, with or without
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## modification, are permitted provided that the following conditions
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## are met:
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## 1. Redistributions of source code must retain the above copyright
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## notice, this list of conditions and the following disclaimer.
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## 2. Redistributions in binary form must reproduce the above copyright
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## notice, this list of conditions and the following disclaimer in the
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## documentation and/or other materials provided with the distribution.
bff64bf12b58a6f80e740e94f2e42a32df18113aEvan Hunt## 3. Neither the name of the University nor the names of its contributors
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## may be used to endorse or promote products derived from this software
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## without specific prior written permission.
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## SUCH DAMAGE.
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## -
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## Portions Copyright (c) 1993 by Digital Equipment Corporation.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence##
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## Permission to use, copy, modify, and distribute this software for any
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## purpose with or without fee is hereby granted, provided that the above
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## copyright notice and this permission notice appear in all copies, and that
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## the name of Digital Equipment Corporation not be used in advertising or
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## publicity pertaining to distribution of the document or software without
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## specific, written prior permission.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence##
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## SOFTWARE.
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## -
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley## --Copyright--
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley#
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley# @(#)mkdep.sh 5.12 (Berkeley) 6/30/88
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley#
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob HalleyMAKE=Makefile # default makefile name is "Makefile"
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleywhile :
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley do case "$1" in
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews # -vpath allows one to select a virtual path for .c files
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews -vpath)
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews VPATH=$2;
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews shift; shift ;;
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley # -f allows you to select a makefile name
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley -f)
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley MAKE=$2
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley shift; shift ;;
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley # the -p flag produces "program: program.c" style dependencies
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley # so .o's don't get produced
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley -p)
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley SED='s;\.o;;'
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley shift ;;
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley *)
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley break ;;
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley esac
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleydone
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleyif [ $# = 0 ] ; then
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews echo 'usage: mkdep [-vpath path] [-p] [-f makefile] [flags] file ...'
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley exit 1
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleyfi
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleyif [ ! -w $MAKE ]; then
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley echo "mkdep: no writeable file \"$MAKE\""
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley exit 1
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleyfi
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob HalleyTMP=mkdep$$
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleytrap 'rm -f $TMP ; exit 1' 1 2 3 13 15
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleycp $MAKE ${MAKE}.bak
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleysed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleycat << _EOF_ >> $TMP
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley# DO NOT DELETE THIS LINE -- mkdep uses it.
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley_EOF_
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley# If your compiler doesn't have -M, add it. If you can't, the next two
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley# lines will try and replace the "cc -M". The real problem is that this
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley# hack can't deal with anything that requires a search path, and doesn't
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley# even try for anything using bracket (<>) syntax.
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley#
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley# egrep '^#include[ ]*".*"' /dev/null $* |
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsif [ X"${VPATH}" != X ] ; then
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews for arg in $* ; do
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews case "$arg" in
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews -*)
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews newargs="$newargs $arg"
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews ;;
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews *)
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews newargs="$newargs $VPATH/$arg"
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews ;;
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews esac
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews done
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewselse
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews newargs="$*";
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsfi
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob HalleyMKDEPPROG="@MKDEPPROG@"
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleyif [ X"${MKDEPPROG}" != X ]; then
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews @SHELL@ -c "${MKDEPPROG} ${newargs}"
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleyelse
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews @MKDEPCC@ @MKDEPCFLAGS@ ${newargs} |
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley sed "
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews s; \\./; ;g
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews s; \\\\; ;g
c64aeaf419a7ef156b4aabfa2a913831e773157eBob Halley @LIBTOOL_MKDEP_SED@
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley $SED" |
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews awk '$1 ~ /:$/ {
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley if (rec != "")
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews print rec;
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews if (NF == 1)
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews rec = $1;
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews else
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews rec = $1 " " $2;
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews for (i = 3; i <= NF; i++) {
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews if (length(rec $i) > 76) {
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews print rec " \\";
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews rec = " " $i;
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews } else {
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews rec = rec " " $i;
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews }
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews }
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews next;
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley }
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews {
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews for (i = 1; i <= NF; i++) {
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews if (length(rec $i) > 76) {
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews print rec, "\\";
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews rec = " " $i;
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews } else {
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews rec = rec " " $i;
b68dc65959cc38f997c365abed9f4e6c0415ecc7Mark Andrews }
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley }
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley }
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley END {
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley print rec
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley }' >> $TMP
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleyfi
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleycat << _EOF_ >> $TMP
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley_EOF_
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halley# copy to preserve permissions
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleycp $TMP $MAKE
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleyrm -f ${MAKE}.bak $TMP
694c897b20f06f8a5349fd9ac5df93947f6f5a2aBob Halleyexit 0