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