mkdep.sh revision 38520
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.sh	8.1 (Berkeley) 6/6/93
351590Srgrimes#
361590Srgrimes
371590SrgrimesPATH=/bin:/usr/bin:/usr/ucb:/usr/old/bin
381590Srgrimesexport PATH
391590Srgrimes
401590SrgrimesD=.depend			# default dependency file is .depend
411590Srgrimesappend=0
421590Srgrimes
431590Srgrimeswhile :
441590Srgrimes	do case "$1" in
451590Srgrimes		# -a appends to the depend file
461590Srgrimes		-a)
471590Srgrimes			append=1
481590Srgrimes			shift ;;
491590Srgrimes
501590Srgrimes		# -f allows you to select a makefile name
511590Srgrimes		-f)
521590Srgrimes			D=$2
531590Srgrimes			shift; shift ;;
541590Srgrimes
551590Srgrimes		# the -p flag produces "program: program.c" style dependencies
561590Srgrimes		# so .o's don't get produced
571590Srgrimes		-p)
581590Srgrimes			SED='s;\.o ; ;'
591590Srgrimes			shift ;;
601590Srgrimes		*)
611590Srgrimes			break ;;
621590Srgrimes	esac
631590Srgrimesdone
641590Srgrimes
651590Srgrimesif [ $# = 0 ] ; then
661590Srgrimes	echo 'usage: mkdep [-p] [-f depend_file] [cc_flags] file ...'
671590Srgrimes	exit 1
681590Srgrimesfi
691590Srgrimes
701590SrgrimesTMP=/tmp/mkdep$$
711590Srgrimes
7238520Scracauertrap 'rm -f $TMP ; trap 2 ; kill -2 $$' 1 2 3 13 15
731590Srgrimes
741590Srgrimescc -M $* |
751590Srgrimessed "
761590Srgrimes	s; \./; ;g
771590Srgrimes	/\.c:$/d
781590Srgrimes	$SED" |
791590Srgrimesawk '{
801590Srgrimes	if ($1 != prev) {
811590Srgrimes		if (rec != "")
821590Srgrimes			print rec;
831590Srgrimes		rec = $0;
841590Srgrimes		prev = $1;
851590Srgrimes	}
861590Srgrimes	else {
871590Srgrimes		if (length(rec $2) > 78) {
881590Srgrimes			print rec;
891590Srgrimes			rec = $0;
901590Srgrimes		}
911590Srgrimes		else
921590Srgrimes			rec = rec " " $2
931590Srgrimes	}
941590Srgrimes}
951590SrgrimesEND {
961590Srgrimes	print rec
971590Srgrimes}' > $TMP
981590Srgrimes
991590Srgrimesif [ $? != 0 ]; then
1001590Srgrimes	echo 'mkdep: compile failed.'
1011590Srgrimes	rm -f $TMP
1021590Srgrimes	exit 1
1031590Srgrimesfi
1041590Srgrimes
1051590Srgrimesif [ $append = 1 ]; then
1061590Srgrimes	cat $TMP >> $D
1071590Srgrimes	rm -f $TMP
1081590Srgrimeselse
1091590Srgrimes	mv $TMP $D
1101590Srgrimesfi
1111590Srgrimesexit 0
112