mkdep.gcc.sh revision 15060
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# 36164426Ssam 37169954SsamPATH=/bin:/usr/bin; export PATH 38169954Ssam 39169954SsamD=.depend # default dependency file is .depend 40169954Ssamappend=0 41169954Ssampflag= 42169954Ssam 43169954Ssamwhile : 44169954Ssam do case "$1" in 45169954Ssam # -a appends to the depend file 46169954Ssam -a) 47164426Ssam append=1 48164426Ssam shift ;; 49164426Ssam 50164426Ssam # -f allows you to select a makefile name 51164426Ssam -f) 52164426Ssam D=$2 53164426Ssam shift; shift ;; 54164426Ssam 55164426Ssam # the -p flag produces "program: program.c" style dependencies 56164426Ssam # so .o's don't get produced 57164426Ssam -p) 58164426Ssam pflag=p 59164426Ssam shift ;; 60164426Ssam *) 61164426Ssam break ;; 62164426Ssam esac 63164426Ssamdone 64164426Ssam 65164426Ssamcase $# in 0) 66164426Ssam echo 'usage: mkdep [-p] [-f depend_file] [cc_flags] file ...' 67164426Ssam exit 1;; 68164426Ssamesac 69169954Ssam 70169954SsamTMP=/tmp/mkdep$$ 71169954Ssamtrap 'rm -f $TMP ; exit 1' 1 2 3 13 15 72169954Ssam 73169954Ssam# For C sources, mkdep must use exactly the same cpp and predefined flags 74169954Ssam# as the compiler would. This is easily arranged by letting the compiler 75169954Ssam# pick the cpp. mkdep must be told the cpp to use for exceptional cases. 76169954SsamMKDEP_CPP=${MKDEP_CPP-"cc -E"} 77169954Ssam 78164426Ssamif $MKDEP_CPP -M $@ > $TMP; then : 79164426Ssamelse 80164426Ssam echo 'mkdep: compile failed.' 81164426Ssam rm -f $TMP 82164426Ssam exit 1 83164426Ssamfi 84164426Ssam 85164426Ssamcase x$pflag in 86164426Ssam x) case $append in 87164426Ssam 0) sed -e 's; \./; ;g' < $TMP > $D;; 88164426Ssam *) sed -e 's; \./; ;g' < $TMP >> $D;; 89164426Ssam esac 90164426Ssam ;; 91164426Ssam *) case $append in 92164426Ssam 0) sed -e 's;\.o:;:;' -e 's; \./; ;g' < $TMP > $D;; 93164426Ssam *) sed -e 's;\.o:;:;' -e 's; \./; ;g' < $TMP >> $D;; 94164426Ssam esac 95164426Ssam ;; 96164426Ssamesac 97164426Ssam 98164426Ssamrm -f $TMP 99164426Ssamexit 0 100164426Ssam