136038Sbostic#!/bin/sh - 236038Sbostic# 336038Sbostic# Copyright (c) 1988 The Regents of the University of California. 436038Sbostic# All rights reserved. 536038Sbostic# 636038Sbostic# Redistribution and use in source and binary forms are permitted 736038Sbostic# provided that the above copyright notice and this paragraph are 836038Sbostic# duplicated in all such forms and that any documentation, 936038Sbostic# advertising materials, and other materials related to such 1036038Sbostic# distribution and use acknowledge that the software was developed 1136038Sbostic# by the University of California, Berkeley. The name of the 1236038Sbostic# University may not be used to endorse or promote products derived 1336038Sbostic# from this software without specific prior written permission. 1436038Sbostic# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1536038Sbostic# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1636038Sbostic# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1736038Sbostic# 18*45035Skarels# @(#)mkdep.old.compiler 5.3 (Berkeley) 08/15/90 1936038Sbostic# 2036038Sbostic 2136038Sbostic# This is a version of mkdep that works pretty well 2236038Sbostic# with compilers that don't have -M. 23*45035SkarelsMAKE=Makefile # default makefile name is "Makefile" 2436038Sbostic 2536038SbosticPATH=/bin:/usr/bin:/usr/ucb:/lib:/usr/lib 2636038Sbostic 2736038SbosticINCL= 2836097Sbostic 2936038Sbosticwhile : 3036038Sbostic do case "$1" in 3136038Sbostic # -f allows you to select a makefile name 3236038Sbostic -f) 33*45035Skarels MAKE=$2 3436038Sbostic shift; shift ;; 3536097Sbostic 3636038Sbostic # the -p flag produces "program: program.c" style dependencies 3736038Sbostic # so .o's don't get produced 3836038Sbostic -p) 3936038Sbostic SED='s;\.o;;' 4036038Sbostic shift ;; 4136038Sbostic *) 4236038Sbostic break ;; 4336038Sbostic esac 4436038Sbosticdone 4536038Sbostic 4636038Sbosticif [ $# = 0 ] ; then 47*45035Skarels echo 'usage: mkdep [-p] [-f makefile] [flags] file ...' 4836038Sbostic exit 1 4936038Sbosticfi 5036038Sbostic 51*45035Skarelsif [ ! -w $MAKE ]; then 52*45035Skarels echo "mkdep: no writeable file \"$MAKE\"" 53*45035Skarels exit 1 54*45035Skarelsfi 55*45035Skarels 5636038SbosticTMP=/tmp/mkdep$$ 57*45035Skarels 5836038Sbostictrap 'rm -f $TMP ; exit 1' 1 2 3 13 15 5936038Sbostic 60*45035Skarelscp $MAKE ${MAKE}.bak 61*45035Skarelssed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP 62*45035Skarels 63*45035Skarelscat << _EOF_ >> $TMP 64*45035Skarels# DO NOT DELETE THIS LINE -- mkdep uses it. 65*45035Skarels# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. 66*45035Skarels 67*45035Skarels_EOF_ 68*45035Skarels 69*45035Skarels 7036038Sbosticfor i do 7136038Sbostic case "$i" in 72*45035Skarels -c|-M|-O) 7336038Sbostic ;; 7436038Sbostic -I*) 7536038Sbostic INCL="$INCL $i";; 76*45035Skarels -D*|-U*) 7736038Sbostic FLAGS="$FLAGS $i";; 7836038Sbostic *) 7936038Sbostic # assume source file 8036038Sbostic # put '$dep' in front of dependencies 8136038Sbostic dep=`echo "$i" | sed -e 's,/,\\\\/,g' -e 's/\.c$/.o/'` 8236038Sbostic 8336038Sbostic # Find includes, remove leading numerics, remove ./, 8436038Sbostic # remove double quotes, and remove trailing numerics. 8536038Sbostic # Sort that, discarding duplicates, and add '$dep'. 8636038Sbostic cpp $INCL $FLAGS "$i" | sed -e ' 8736038Sbostic /^#/!d 8836038Sbostic s/# [0-9]* // 8936038Sbostic s,"./,", 9036038Sbostic s/"\(.*\)"/\1/ 9136038Sbostic s/ [ 0-9]*$//' | 9236038Sbostic sort -u | sed -e "s/^/$dep: /";; 9336038Sbostic esac 9436038Sbosticdone | 9536038Sbosticsed " 9636038Sbostic s; \./; ;g 9736038Sbostic /\.c:$/d 9836038Sbostic $SED" | 9936038Sbosticawk '{ 10036038Sbostic if ($1 != prev) { 10136038Sbostic if (rec != "") 10236038Sbostic print rec; 10336038Sbostic rec = $0; 10436038Sbostic prev = $1; 10536038Sbostic } 10636038Sbostic else { 10736038Sbostic if (length(rec $2) > 78) { 10836038Sbostic print rec; 10936038Sbostic rec = $0; 11036038Sbostic } 11136038Sbostic else 11236038Sbostic rec = rec " " $2 11336038Sbostic } 11436038Sbostic} 11536038SbosticEND { 11636038Sbostic print rec 117*45035Skarels}' >> $TMP 11836038Sbostic 119*45035Skarelscat << _EOF_ >> $TMP 120*45035Skarels 121*45035Skarels# IF YOU PUT ANYTHING HERE IT WILL GO AWAY 122*45035Skarels_EOF_ 123*45035Skarels 124*45035Skarels# copy to preserve permissions 125*45035Skarelscp $TMP $MAKE 126*45035Skarelsrm -f $TMP 12736038Sbosticexit 0 128