mkdep.gcc.sh revision 50477
1164426Ssam#!/bin/sh - 2164426Ssam# 3164426Ssam# Copyright (c) 1991, 1993 4164426Ssam# The Regents of the University of California. All rights reserved. 5164426Ssam# 6164426Ssam# Redistribution and use in source and binary forms, with or without 7164426Ssam# modification, are permitted provided that the following conditions 8164426Ssam# are met: 9164426Ssam# 1. Redistributions of source code must retain the above copyright 10164426Ssam# notice, this list of conditions and the following disclaimer. 11164426Ssam# 2. Redistributions in binary form must reproduce the above copyright 12164426Ssam# notice, this list of conditions and the following disclaimer in the 13164426Ssam# documentation and/or other materials provided with the distribution. 14164426Ssam# 3. All advertising materials mentioning features or use of this software 15164426Ssam# must display the following acknowledgement: 16164426Ssam# This product includes software developed by the University of 17164426Ssam# California, Berkeley and its contributors. 18164426Ssam# 4. Neither the name of the University nor the names of its contributors 19164426Ssam# may be used to endorse or promote products derived from this software 20164426Ssam# without specific prior written permission. 21164426Ssam# 22164426Ssam# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23164426Ssam# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24164426Ssam# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25164426Ssam# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26164426Ssam# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27164426Ssam# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28164426Ssam# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29164426Ssam# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30164426Ssam# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31164426Ssam# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32164426Ssam# SUCH DAMAGE. 33164426Ssam# 34164426Ssam# @(#)mkdep.gcc.sh 8.1 (Berkeley) 6/6/93 35169954Ssam# $FreeBSD: head/usr.bin/mkdep/mkdep.gcc.sh 50477 1999-08-28 01:08:13Z peter $ 36164426Ssam 37169954SsamD=.depend # default dependency file is .depend 38169954Ssamappend=0 39169954Ssampflag= 40169954Ssam 41169954Ssamwhile : 42169954Ssam do case "$1" in 43169954Ssam # -a appends to the depend file 44169954Ssam -a) 45169954Ssam append=1 46169954Ssam shift ;; 47164426Ssam 48164426Ssam # -f allows you to select a makefile name 49164426Ssam -f) 50164426Ssam D=$2 51164426Ssam shift; shift ;; 52164426Ssam 53164426Ssam # the -p flag produces "program: program.c" style dependencies 54164426Ssam # so .o's don't get produced 55164426Ssam -p) 56164426Ssam pflag=p 57164426Ssam shift ;; 58164426Ssam *) 59164426Ssam break ;; 60164426Ssam esac 61164426Ssamdone 62164426Ssam 63164426Ssamcase $# in 0) 64164426Ssam echo 'usage: mkdep [-ap] [-f file] [flags] file ...' >&2 65164426Ssam exit 1;; 66164426Ssamesac 67164426Ssam 68164426SsamTMP=_mkdep$$ 69169954Ssamtrap 'rm -f $TMP ; trap 2 ; kill -2 $$' 1 2 3 13 15 70169954Ssamtrap 'rm -f $TMP' 0 71169954Ssam 72169954Ssam# For C sources, mkdep must use exactly the same cpp and predefined flags 73169954Ssam# as the compiler would. This is easily arranged by letting the compiler 74169954Ssam# pick the cpp. mkdep must be told the cpp to use for exceptional cases. 75169954SsamCC=${CC-"cc"} 76169954SsamMKDEP_CPP=${MKDEP_CPP-"${CC} -E"} 77169954SsamMKDEP_CPP_OPTS=${MKDEP_CPP_OPTS-"-M"}; 78164426Ssam 79164426Ssamecho "# $@" > $TMP # store arguments for debugging 80164426Ssam 81164426Ssamif $MKDEP_CPP $MKDEP_CPP_OPTS "$@" >> $TMP; then : 82164426Ssamelse 83164426Ssam echo 'mkdep: compile failed' >&2 84164426Ssam exit 1 85164426Ssamfi 86164426Ssam 87164426Ssamcase x$pflag in 88164426Ssam x) case $append in 89164426Ssam 0) sed -e 's; \./; ;g' < $TMP > $D;; 90164426Ssam *) sed -e 's; \./; ;g' < $TMP >> $D;; 91164426Ssam esac 92164426Ssam ;; 93164426Ssam *) case $append in 94164426Ssam 0) sed -e 's;\.o:;:;' -e 's; \./; ;g' < $TMP > $D;; 95164426Ssam *) sed -e 's;\.o:;:;' -e 's; \./; ;g' < $TMP >> $D;; 96164426Ssam esac 97164426Ssam ;; 98164426Ssamesac 99164426Ssam 100164426Ssamexit $? 101164426Ssam