xref: /freebsd/usr.bin/mkdep/mkdep.gcc.sh (revision fbbd9655e5107c68e4e0146ff22b73d7350475bc)
19b50d902SRodney W. Grimes#!/bin/sh -
29b50d902SRodney W. Grimes#
39b50d902SRodney W. Grimes# Copyright (c) 1991, 1993
49b50d902SRodney W. Grimes#	The Regents of the University of California.  All rights reserved.
59b50d902SRodney W. Grimes#
69b50d902SRodney W. Grimes# Redistribution and use in source and binary forms, with or without
79b50d902SRodney W. Grimes# modification, are permitted provided that the following conditions
89b50d902SRodney W. Grimes# are met:
99b50d902SRodney W. Grimes# 1. Redistributions of source code must retain the above copyright
109b50d902SRodney W. Grimes#    notice, this list of conditions and the following disclaimer.
119b50d902SRodney W. Grimes# 2. Redistributions in binary form must reproduce the above copyright
129b50d902SRodney W. Grimes#    notice, this list of conditions and the following disclaimer in the
139b50d902SRodney W. Grimes#    documentation and/or other materials provided with the distribution.
14*fbbd9655SWarner Losh# 3. Neither the name of the University nor the names of its contributors
159b50d902SRodney W. Grimes#    may be used to endorse or promote products derived from this software
169b50d902SRodney W. Grimes#    without specific prior written permission.
179b50d902SRodney W. Grimes#
189b50d902SRodney W. Grimes# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
199b50d902SRodney W. Grimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
209b50d902SRodney W. Grimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
219b50d902SRodney W. Grimes# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
229b50d902SRodney W. Grimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
239b50d902SRodney W. Grimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
249b50d902SRodney W. Grimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
259b50d902SRodney W. Grimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
269b50d902SRodney W. Grimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
279b50d902SRodney W. Grimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
289b50d902SRodney W. Grimes# SUCH DAMAGE.
299b50d902SRodney W. Grimes#
309b50d902SRodney W. Grimes#	@(#)mkdep.gcc.sh	8.1 (Berkeley) 6/6/93
31c3aac50fSPeter Wemm# $FreeBSD$
329b50d902SRodney W. Grimes
339b50d902SRodney W. GrimesD=.depend			# default dependency file is .depend
349b50d902SRodney W. Grimesappend=0
359b50d902SRodney W. Grimespflag=
369b50d902SRodney W. Grimes
379b50d902SRodney W. Grimeswhile :
389b50d902SRodney W. Grimes	do case "$1" in
399b50d902SRodney W. Grimes		# -a appends to the depend file
409b50d902SRodney W. Grimes		-a)
419b50d902SRodney W. Grimes			append=1
429b50d902SRodney W. Grimes			shift ;;
439b50d902SRodney W. Grimes
449b50d902SRodney W. Grimes		# -f allows you to select a makefile name
459b50d902SRodney W. Grimes		-f)
469b50d902SRodney W. Grimes			D=$2
479b50d902SRodney W. Grimes			shift; shift ;;
489b50d902SRodney W. Grimes
499b50d902SRodney W. Grimes		# the -p flag produces "program: program.c" style dependencies
509b50d902SRodney W. Grimes		# so .o's don't get produced
519b50d902SRodney W. Grimes		-p)
529b50d902SRodney W. Grimes			pflag=p
539b50d902SRodney W. Grimes			shift ;;
549b50d902SRodney W. Grimes		*)
559b50d902SRodney W. Grimes			break ;;
569b50d902SRodney W. Grimes	esac
579b50d902SRodney W. Grimesdone
589b50d902SRodney W. Grimes
594c3dfdc3SWolfram Schneidercase $# in 0)
6030c218bfSBruce Evans	echo 'usage: mkdep [-ap] [-f file] [flags] file ...' >&2
614c3dfdc3SWolfram Schneider	exit 1;;
624c3dfdc3SWolfram Schneideresac
639b50d902SRodney W. Grimes
647f6f2e94SWolfram SchneiderTMP=_mkdep$$
659a4902a9SMartin Cracauertrap 'rm -f $TMP ; trap 2 ; kill -2 $$' 1 2 3 13 15
664a90dcebSWolfram Schneidertrap 'rm -f $TMP' 0
679b50d902SRodney W. Grimes
68207a4c99SBruce Evans# For C sources, mkdep must use exactly the same cpp and predefined flags
69207a4c99SBruce Evans# as the compiler would.  This is easily arranged by letting the compiler
70207a4c99SBruce Evans# pick the cpp.  mkdep must be told the cpp to use for exceptional cases.
712b147068SDavid E. O'BrienCC=${CC-"cc"}
722b147068SDavid E. O'BrienMKDEP_CPP=${MKDEP_CPP-"${CC} -E"}
732b147068SDavid E. O'BrienMKDEP_CPP_OPTS=${MKDEP_CPP_OPTS-"-M"};
74905a01acSDavid E. O'Brien
754a90dcebSWolfram Schneiderecho "# $@" > $TMP	# store arguments for debugging
764a90dcebSWolfram Schneider
772b147068SDavid E. O'Brienif $MKDEP_CPP $MKDEP_CPP_OPTS "$@" >> $TMP; then :
789b50d902SRodney W. Grimeselse
7930c218bfSBruce Evans	echo 'mkdep: compile failed' >&2
809b50d902SRodney W. Grimes	exit 1
819b50d902SRodney W. Grimesfi
829b50d902SRodney W. Grimes
834c3dfdc3SWolfram Schneidercase x$pflag in
844c3dfdc3SWolfram Schneider	x) case $append in
854c3dfdc3SWolfram Schneider		0) sed -e 's; \./; ;g' < $TMP >  $D;;
864c3dfdc3SWolfram Schneider		*) sed -e 's; \./; ;g' < $TMP >> $D;;
874c3dfdc3SWolfram Schneider	   esac
884c3dfdc3SWolfram Schneider	;;
894c3dfdc3SWolfram Schneider	*) case $append in
904c3dfdc3SWolfram Schneider		0) sed -e 's;\.o:;:;' -e 's; \./; ;g' < $TMP >  $D;;
914c3dfdc3SWolfram Schneider		*) sed -e 's;\.o:;:;' -e 's; \./; ;g' < $TMP >> $D;;
924c3dfdc3SWolfram Schneider	   esac
934c3dfdc3SWolfram Schneider	;;
944c3dfdc3SWolfram Schneideresac
954c3dfdc3SWolfram Schneider
964a90dcebSWolfram Schneiderexit $?
97