133188Sbostic#!/bin/sh - 231322Sbostic# 3*62117Sbostic# Copyright (c) 1991, 1993 4*62117Sbostic# The Regents of the University of California. All rights reserved. 531322Sbostic# 647967Sbostic# %sccs.include.redist.sh% 733188Sbostic# 8*62117Sbostic# @(#)mkdep.sh 8.1 (Berkeley) 06/06/93 933188Sbostic# 1047967Sbostic 1151702SbosticPATH=/bin:/usr/bin:/usr/ucb:/usr/old/bin 1232390Sbosticexport PATH 1331406Sbostic 1435382SbosticD=.depend # default dependency file is .depend 1536096Sbosticappend=0 1633193Sbostic 1733193Sbosticwhile : 1833193Sbostic do case "$1" in 1936096Sbostic # -a appends to the depend file 2036096Sbostic -a) 2136096Sbostic append=1 2236096Sbostic shift ;; 2336096Sbostic 2433193Sbostic # -f allows you to select a makefile name 2533193Sbostic -f) 2635382Sbostic D=$2 2733193Sbostic shift; shift ;; 2833193Sbostic 2933193Sbostic # the -p flag produces "program: program.c" style dependencies 3033193Sbostic # so .o's don't get produced 3133193Sbostic -p) 3256182Sbostic SED='s;\.o ; ;' 3333193Sbostic shift ;; 3433193Sbostic *) 3533193Sbostic break ;; 3633193Sbostic esac 3733193Sbosticdone 3833193Sbostic 3931324Sbosticif [ $# = 0 ] ; then 4035382Sbostic echo 'usage: mkdep [-p] [-f depend_file] [cc_flags] file ...' 4131324Sbostic exit 1 4231324Sbosticfi 4331324Sbostic 4431322SbosticTMP=/tmp/mkdep$$ 4531322Sbostic 4631406Sbostictrap 'rm -f $TMP ; exit 1' 1 2 3 13 15 4731322Sbostic 4833353Sbosticcc -M $* | 4933353Sbosticsed " 5033353Sbostic s; \./; ;g 5135984Sbostic /\.c:$/d 5233353Sbostic $SED" | 5333353Sbosticawk '{ 5433353Sbostic if ($1 != prev) { 5533353Sbostic if (rec != "") 5633353Sbostic print rec; 5733353Sbostic rec = $0; 5833353Sbostic prev = $1; 5933353Sbostic } 6033353Sbostic else { 6133353Sbostic if (length(rec $2) > 78) { 6233353Sbostic print rec; 6333353Sbostic rec = $0; 6433353Sbostic } 6533353Sbostic else 6633353Sbostic rec = rec " " $2 6733353Sbostic } 6833353Sbostic} 6933353SbosticEND { 7033353Sbostic print rec 7135382Sbostic}' > $TMP 7231322Sbostic 7336958Sbosticif [ $? != 0 ]; then 7436958Sbostic echo 'mkdep: compile failed.' 7536958Sbostic rm -f $TMP 7636958Sbostic exit 1 7736958Sbosticfi 7836958Sbostic 7936096Sbosticif [ $append = 1 ]; then 8036096Sbostic cat $TMP >> $D 8136096Sbostic rm -f $TMP 8236096Sbosticelse 8336096Sbostic mv $TMP $D 8436096Sbosticfi 8531322Sbosticexit 0 86