mkdep.gcc.sh revision 39123
11590Srgrimes#!/bin/sh -
21590Srgrimes#
31590Srgrimes# Copyright (c) 1991, 1993
41590Srgrimes#	The Regents of the University of California.  All rights reserved.
51590Srgrimes#
61590Srgrimes# Redistribution and use in source and binary forms, with or without
71590Srgrimes# modification, are permitted provided that the following conditions
81590Srgrimes# are met:
91590Srgrimes# 1. Redistributions of source code must retain the above copyright
101590Srgrimes#    notice, this list of conditions and the following disclaimer.
111590Srgrimes# 2. Redistributions in binary form must reproduce the above copyright
121590Srgrimes#    notice, this list of conditions and the following disclaimer in the
131590Srgrimes#    documentation and/or other materials provided with the distribution.
141590Srgrimes# 3. All advertising materials mentioning features or use of this software
151590Srgrimes#    must display the following acknowledgement:
161590Srgrimes#	This product includes software developed by the University of
171590Srgrimes#	California, Berkeley and its contributors.
181590Srgrimes# 4. Neither the name of the University nor the names of its contributors
191590Srgrimes#    may be used to endorse or promote products derived from this software
201590Srgrimes#    without specific prior written permission.
211590Srgrimes#
221590Srgrimes# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231590Srgrimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241590Srgrimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251590Srgrimes# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261590Srgrimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271590Srgrimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281590Srgrimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291590Srgrimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301590Srgrimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311590Srgrimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321590Srgrimes# SUCH DAMAGE.
331590Srgrimes#
341590Srgrimes#	@(#)mkdep.gcc.sh	8.1 (Berkeley) 6/6/93
3539123Sobrien#	$Id: mkdep.gcc.sh,v 1.14 1998/08/24 10:16:39 cracauer Exp $
361590Srgrimes
371590SrgrimesD=.depend			# default dependency file is .depend
381590Srgrimesappend=0
391590Srgrimespflag=
401590Srgrimes
411590Srgrimeswhile :
421590Srgrimes	do case "$1" in
431590Srgrimes		# -a appends to the depend file
441590Srgrimes		-a)
451590Srgrimes			append=1
461590Srgrimes			shift ;;
471590Srgrimes
481590Srgrimes		# -f allows you to select a makefile name
491590Srgrimes		-f)
501590Srgrimes			D=$2
511590Srgrimes			shift; shift ;;
521590Srgrimes
531590Srgrimes		# the -p flag produces "program: program.c" style dependencies
541590Srgrimes		# so .o's don't get produced
551590Srgrimes		-p)
561590Srgrimes			pflag=p
571590Srgrimes			shift ;;
581590Srgrimes		*)
591590Srgrimes			break ;;
601590Srgrimes	esac
611590Srgrimesdone
621590Srgrimes
6315060Swoschcase $# in 0) 
6422641Sbde	echo 'usage: mkdep [-ap] [-f file] [flags] file ...' >&2
6515060Swosch	exit 1;;
6615060Swoschesac
671590Srgrimes
6822024SwoschTMP=_mkdep$$
6938520Scracauertrap 'rm -f $TMP ; trap 2 ; kill -2 $$' 1 2 3 13 15
7019208Swoschtrap 'rm -f $TMP' 0
711590Srgrimes
722406Sbde# For C sources, mkdep must use exactly the same cpp and predefined flags
732406Sbde# as the compiler would.  This is easily arranged by letting the compiler
742406Sbde# pick the cpp.  mkdep must be told the cpp to use for exceptional cases.
7539123SobrienCC=${CC-"cc"}
7639123SobrienMKDEP_CPP=${MKDEP_CPP-"${CC} -E"}
7739123SobrienMKDEP_CPP_OPTS=${MKDEP_CPP_OPTS-"-M"};
782406Sbde
7919208Swoschecho "# $@" > $TMP	# store arguments for debugging
8019208Swosch
8139123Sobrienif $MKDEP_CPP $MKDEP_CPP_OPTS "$@" >> $TMP; then :
821590Srgrimeselse
8322641Sbde	echo 'mkdep: compile failed' >&2
841590Srgrimes	exit 1
851590Srgrimesfi
861590Srgrimes
8715060Swoschcase x$pflag in
8815060Swosch	x) case $append in 
8915060Swosch		0) sed -e 's; \./; ;g' < $TMP >  $D;;
9015060Swosch		*) sed -e 's; \./; ;g' < $TMP >> $D;;
9115060Swosch	   esac
9215060Swosch	;;	
9315060Swosch	*) case $append in 
9415060Swosch		0) sed -e 's;\.o:;:;' -e 's; \./; ;g' < $TMP >  $D;;
9515060Swosch		*) sed -e 's;\.o:;:;' -e 's; \./; ;g' < $TMP >> $D;;
9615060Swosch	   esac
9715060Swosch	;;
9815060Swoschesac
9915060Swosch
10019208Swoschexit $?
101