mkdep.gcc.sh revision 39123
1234285Sdim#!/bin/sh - 2234285Sdim# 3234285Sdim# Copyright (c) 1991, 1993 4234285Sdim# The Regents of the University of California. All rights reserved. 5234285Sdim# 6234285Sdim# Redistribution and use in source and binary forms, with or without 7234285Sdim# modification, are permitted provided that the following conditions 8234285Sdim# are met: 9234285Sdim# 1. Redistributions of source code must retain the above copyright 10234285Sdim# notice, this list of conditions and the following disclaimer. 11234285Sdim# 2. Redistributions in binary form must reproduce the above copyright 12234285Sdim# notice, this list of conditions and the following disclaimer in the 13234285Sdim# documentation and/or other materials provided with the distribution. 14234285Sdim# 3. All advertising materials mentioning features or use of this software 15234285Sdim# must display the following acknowledgement: 16234285Sdim# This product includes software developed by the University of 17234285Sdim# California, Berkeley and its contributors. 18234285Sdim# 4. Neither the name of the University nor the names of its contributors 19234285Sdim# may be used to endorse or promote products derived from this software 20234285Sdim# without specific prior written permission. 21234285Sdim# 22249423Sdim# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23234285Sdim# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24249423Sdim# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25249423Sdim# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26249423Sdim# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27234285Sdim# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28234285Sdim# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29234285Sdim# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30234285Sdim# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31234285Sdim# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32234285Sdim# SUCH DAMAGE. 33249423Sdim# 34249423Sdim# @(#)mkdep.gcc.sh 8.1 (Berkeley) 6/6/93 35249423Sdim# $Id: mkdep.gcc.sh,v 1.14 1998/08/24 10:16:39 cracauer Exp $ 36249423Sdim 37249423SdimD=.depend # default dependency file is .depend 38234285Sdimappend=0 39234285Sdimpflag= 40234285Sdim 41234285Sdimwhile : 42234285Sdim do case "$1" in 43234285Sdim # -a appends to the depend file 44234285Sdim -a) 45234285Sdim append=1 46249423Sdim shift ;; 47234285Sdim 48234285Sdim # -f allows you to select a makefile name 49249423Sdim -f) 50249423Sdim D=$2 51234285Sdim shift; shift ;; 52234285Sdim 53249423Sdim # the -p flag produces "program: program.c" style dependencies 54234285Sdim # so .o's don't get produced 55249423Sdim -p) 56234285Sdim pflag=p 57234285Sdim shift ;; 58234285Sdim *) 59234285Sdim break ;; 60234285Sdim esac 61234285Sdimdone 62234285Sdim 63234285Sdimcase $# in 0) 64234285Sdim echo 'usage: mkdep [-ap] [-f file] [flags] file ...' >&2 65234285Sdim exit 1;; 66234285Sdimesac 67234285Sdim 68234285SdimTMP=_mkdep$$ 69234285Sdimtrap 'rm -f $TMP ; trap 2 ; kill -2 $$' 1 2 3 13 15 70234285Sdimtrap 'rm -f $TMP' 0 71234285Sdim 72234285Sdim# For C sources, mkdep must use exactly the same cpp and predefined flags 73234285Sdim# as the compiler would. This is easily arranged by letting the compiler 74234285Sdim# pick the cpp. mkdep must be told the cpp to use for exceptional cases. 75234285SdimCC=${CC-"cc"} 76234285SdimMKDEP_CPP=${MKDEP_CPP-"${CC} -E"} 77234285SdimMKDEP_CPP_OPTS=${MKDEP_CPP_OPTS-"-M"}; 78234285Sdim 79234285Sdimecho "# $@" > $TMP # store arguments for debugging 80239462Sdim 81234285Sdimif $MKDEP_CPP $MKDEP_CPP_OPTS "$@" >> $TMP; then : 82234285Sdimelse 83234285Sdim echo 'mkdep: compile failed' >&2 84234285Sdim exit 1 85234285Sdimfi 86234285Sdim 87234285Sdimcase x$pflag in 88234285Sdim x) case $append in 89234285Sdim 0) sed -e 's; \./; ;g' < $TMP > $D;; 90234285Sdim *) sed -e 's; \./; ;g' < $TMP >> $D;; 91234285Sdim esac 92234285Sdim ;; 93234285Sdim *) case $append in 94234285Sdim 0) sed -e 's;\.o:;:;' -e 's; \./; ;g' < $TMP > $D;; 95234285Sdim *) sed -e 's;\.o:;:;' -e 's; \./; ;g' < $TMP >> $D;; 96234285Sdim esac 97234285Sdim ;; 98234285Sdimesac 99234285Sdim 100234285Sdimexit $? 101234285Sdim