1#!/bin/sh - 2# 3# Copyright (c) 1988 The Regents of the University of California. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms are permitted 7# provided that the above copyright notice and this paragraph are 8# duplicated in all such forms and that any documentation, 9# advertising materials, and other materials related to such 10# distribution and use acknowledge that the software was developed 11# by the University of California, Berkeley. The name of the 12# University may not be used to endorse or promote products derived 13# from this software without specific prior written permission. 14# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 15# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 16# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 17# 18# @(#)mkdep.old.compiler 5.3 (Berkeley) 08/15/90 19# 20 21# This is a version of mkdep that works pretty well 22# with compilers that don't have -M. 23MAKE=Makefile # default makefile name is "Makefile" 24 25PATH=/bin:/usr/bin:/usr/ucb:/lib:/usr/lib 26 27INCL= 28 29while : 30 do case "$1" in 31 # -f allows you to select a makefile name 32 -f) 33 MAKE=$2 34 shift; shift ;; 35 36 # the -p flag produces "program: program.c" style dependencies 37 # so .o's don't get produced 38 -p) 39 SED='s;\.o;;' 40 shift ;; 41 *) 42 break ;; 43 esac 44done 45 46if [ $# = 0 ] ; then 47 echo 'usage: mkdep [-p] [-f makefile] [flags] file ...' 48 exit 1 49fi 50 51if [ ! -w $MAKE ]; then 52 echo "mkdep: no writeable file \"$MAKE\"" 53 exit 1 54fi 55 56TMP=/tmp/mkdep$$ 57 58trap 'rm -f $TMP ; exit 1' 1 2 3 13 15 59 60cp $MAKE ${MAKE}.bak 61sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP 62 63cat << _EOF_ >> $TMP 64# DO NOT DELETE THIS LINE -- mkdep uses it. 65# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. 66 67_EOF_ 68 69 70for i do 71 case "$i" in 72 -c|-M|-O) 73 ;; 74 -I*) 75 INCL="$INCL $i";; 76 -D*|-U*) 77 FLAGS="$FLAGS $i";; 78 *) 79 # assume source file 80 # put '$dep' in front of dependencies 81 dep=`echo "$i" | sed -e 's,/,\\\\/,g' -e 's/\.c$/.o/'` 82 83 # Find includes, remove leading numerics, remove ./, 84 # remove double quotes, and remove trailing numerics. 85 # Sort that, discarding duplicates, and add '$dep'. 86 cpp $INCL $FLAGS "$i" | sed -e ' 87 /^#/!d 88 s/# [0-9]* // 89 s,"./,", 90 s/"\(.*\)"/\1/ 91 s/ [ 0-9]*$//' | 92 sort -u | sed -e "s/^/$dep: /";; 93 esac 94done | 95sed " 96 s; \./; ;g 97 /\.c:$/d 98 $SED" | 99awk '{ 100 if ($1 != prev) { 101 if (rec != "") 102 print rec; 103 rec = $0; 104 prev = $1; 105 } 106 else { 107 if (length(rec $2) > 78) { 108 print rec; 109 rec = $0; 110 } 111 else 112 rec = rec " " $2 113 } 114} 115END { 116 print rec 117}' >> $TMP 118 119cat << _EOF_ >> $TMP 120 121# IF YOU PUT ANYTHING HERE IT WILL GO AWAY 122_EOF_ 123 124# copy to preserve permissions 125cp $TMP $MAKE 126rm -f $TMP 127exit 0 128