117680Spst#!/bin/sh - 217680Spst# 317680Spst# Copyright (c) 1994, 1996 417680Spst# The Regents of the University of California. All rights reserved. 517680Spst# 617680Spst# Redistribution and use in source and binary forms are permitted 717680Spst# provided that this notice is preserved and that due credit is given 817680Spst# to the University of California at Berkeley. The name of the University 917680Spst# may not be used to endorse or promote products derived from this 1017680Spst# software without specific prior written permission. This software 1117680Spst# is provided ``as is'' without express or implied warranty. 1217680Spst# 1317680Spst# @(#)mkdep.sh 5.11 (Berkeley) 5/5/88 1417680Spst# 1517680Spst 1617680SpstPATH=/bin:/usr/bin:/usr/ucb:/usr/local:/usr/local/bin 1717680Spstexport PATH 1817680Spst 1917680SpstMAKE=Makefile # default makefile name is "Makefile" 2017680SpstCC=cc # default C compiler is "cc" 2117680Spst 2217680Spstwhile : 2317680Spst do case "$1" in 2417680Spst # -c allows you to specify the C compiler 2517680Spst -c) 2617680Spst CC=$2 2717680Spst shift; shift ;; 2817680Spst 2917680Spst # -f allows you to select a makefile name 3017680Spst -f) 3117680Spst MAKE=$2 3217680Spst shift; shift ;; 3317680Spst 3417680Spst # the -p flag produces "program: program.c" style dependencies 3517680Spst # so .o's don't get produced 3617680Spst -p) 3717680Spst SED='s;\.o;;' 3817680Spst shift ;; 3917680Spst *) 4017680Spst break ;; 4117680Spst esac 4217680Spstdone 4317680Spst 4417680Spstif [ $# = 0 ] ; then 4517680Spst echo 'usage: mkdep [-p] [-c cc] [-f makefile] [flags] file ...' 4617680Spst exit 1 4717680Spstfi 4817680Spst 4917680Spstif [ ! -w $MAKE ]; then 5017680Spst echo "mkdep: no writeable file \"$MAKE\"" 5117680Spst exit 1 5217680Spstfi 5317680Spst 5417680SpstTMP=/tmp/mkdep$$ 5517680Spst 5617680Spsttrap 'rm -f $TMP ; exit 1' 1 2 3 13 15 5717680Spst 5817680Spstcp $MAKE ${MAKE}.bak 5917680Spst 6017680Spstsed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP 6117680Spst 6217680Spstcat << _EOF_ >> $TMP 6317680Spst# DO NOT DELETE THIS LINE -- mkdep uses it. 6417680Spst# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. 6517680Spst 6617680Spst_EOF_ 6717680Spst 6817680Spst# If your compiler doesn't have -M, add it. If you can't, the next two 6917680Spst# lines will try and replace the "cc -M". The real problem is that this 7017680Spst# hack can't deal with anything that requires a search path, and doesn't 7117680Spst# even try for anything using bracket (<>) syntax. 7217680Spst# 7317680Spst# egrep '^#include[ ]*".*"' /dev/null $* | 7417680Spst# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' | 7517680Spst 7617680Spst# XXX this doesn't work with things like "-DDECLWAITSTATUS=union\ wait" 7717680Spst$CC -M $* | 7817680Spstsed " 7917680Spst s; \./; ;g 8017680Spst $SED" | 8117680Spstawk '{ 8217680Spst if ($1 != prev) { 8317680Spst if (rec != "") 8417680Spst print rec; 8517680Spst rec = $0; 8617680Spst prev = $1; 8717680Spst } 8817680Spst else { 8917680Spst if (length(rec $2) > 78) { 9017680Spst print rec; 9117680Spst rec = $0; 9217680Spst } 9317680Spst else 9417680Spst rec = rec " " $2 9517680Spst } 9617680Spst} 9717680SpstEND { 9817680Spst print rec 9917680Spst}' >> $TMP 10017680Spst 10117680Spstcat << _EOF_ >> $TMP 10217680Spst 10317680Spst# IF YOU PUT ANYTHING HERE IT WILL GO AWAY 10417680Spst_EOF_ 10517680Spst 10617680Spst# copy to preserve permissions 10717680Spstcp $TMP $MAKE 10817680Spstrm -f ${MAKE}.bak $TMP 10917680Spstexit 0 110