117683Spst#!/bin/sh - 217683Spst# 317683Spst# Copyright (c) 1994, 1996 417683Spst# The Regents of the University of California. All rights reserved. 517683Spst# 617683Spst# Redistribution and use in source and binary forms are permitted 717683Spst# provided that this notice is preserved and that due credit is given 817683Spst# to the University of California at Berkeley. The name of the University 917683Spst# may not be used to endorse or promote products derived from this 1017683Spst# software without specific prior written permission. This software 1117683Spst# is provided ``as is'' without express or implied warranty. 1217683Spst# 1317683Spst# @(#)mkdep.sh 5.11 (Berkeley) 5/5/88 1417683Spst# 1517683Spst 16190225SrpauloPATH=/bin:/usr/bin:/usr/ucb:/usr/local:/usr/local/bin:/usr/sfw/bin 1717683Spstexport PATH 1817683Spst 1917683SpstMAKE=Makefile # default makefile name is "Makefile" 2017683SpstCC=cc # default C compiler is "cc" 2117683Spst 2217683Spstwhile : 2317683Spst do case "$1" in 2417683Spst # -c allows you to specify the C compiler 2517683Spst -c) 2617683Spst CC=$2 2717683Spst shift; shift ;; 2817683Spst 2917683Spst # -f allows you to select a makefile name 3017683Spst -f) 3117683Spst MAKE=$2 3217683Spst shift; shift ;; 3317683Spst 3417683Spst # the -p flag produces "program: program.c" style dependencies 3517683Spst # so .o's don't get produced 3617683Spst -p) 3717683Spst SED='s;\.o;;' 3817683Spst shift ;; 3917683Spst *) 4017683Spst break ;; 4117683Spst esac 4217683Spstdone 4317683Spst 4417683Spstif [ $# = 0 ] ; then 4517683Spst echo 'usage: mkdep [-p] [-c cc] [-f makefile] [flags] file ...' 4617683Spst exit 1 4717683Spstfi 4817683Spst 4917683Spstif [ ! -w $MAKE ]; then 5017683Spst echo "mkdep: no writeable file \"$MAKE\"" 5117683Spst exit 1 5217683Spstfi 5317683Spst 5417683SpstTMP=/tmp/mkdep$$ 5517683Spst 5617683Spsttrap 'rm -f $TMP ; exit 1' 1 2 3 13 15 5717683Spst 5817683Spstcp $MAKE ${MAKE}.bak 5917683Spst 6017683Spstsed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP 6117683Spst 6217683Spstcat << _EOF_ >> $TMP 6317683Spst# DO NOT DELETE THIS LINE -- mkdep uses it. 6417683Spst# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. 6517683Spst 6617683Spst_EOF_ 6717683Spst 6817683Spst# If your compiler doesn't have -M, add it. If you can't, the next two 6917683Spst# lines will try and replace the "cc -M". The real problem is that this 7017683Spst# hack can't deal with anything that requires a search path, and doesn't 7117683Spst# even try for anything using bracket (<>) syntax. 7217683Spst# 7317683Spst# egrep '^#include[ ]*".*"' /dev/null $* | 7417683Spst# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' | 7517683Spst 7617683Spst# XXX this doesn't work with things like "-DDECLWAITSTATUS=union\ wait" 7717683Spst$CC -M $* | 7817683Spstsed " 7917683Spst s; \./; ;g 8017683Spst $SED" | 8117683Spstawk '{ 8217683Spst if ($1 != prev) { 8317683Spst if (rec != "") 8417683Spst print rec; 8517683Spst rec = $0; 8617683Spst prev = $1; 8717683Spst } 8817683Spst else { 8917683Spst if (length(rec $2) > 78) { 9017683Spst print rec; 9117683Spst rec = $0; 9217683Spst } 9317683Spst else 9417683Spst rec = rec " " $2 9517683Spst } 9617683Spst} 9717683SpstEND { 9817683Spst print rec 9917683Spst}' >> $TMP 10017683Spst 10117683Spstcat << _EOF_ >> $TMP 10217683Spst 10317683Spst# IF YOU PUT ANYTHING HERE IT WILL GO AWAY 10417683Spst_EOF_ 10517683Spst 10617683Spst# copy to preserve permissions 10717683Spstcp $TMP $MAKE 10817683Spstrm -f ${MAKE}.bak $TMP 10917683Spstexit 0 110