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.2 (Berkeley) 10/24/88 19# 20 21# This is a version of mkdep that works pretty well 22# with compilers that don't have -M. 23 24PATH=/bin:/usr/bin:/usr/ucb:/lib:/usr/lib 25 26INCL= 27D=.depend 28append=0 29 30while : 31 do case "$1" in 32 # -a appends to the depend file 33 -a) 34 append=1 35 shift ;; 36 37 # -f allows you to select a makefile name 38 -f) 39 D=$2 40 shift; shift ;; 41 42 # the -p flag produces "program: program.c" style dependencies 43 # so .o's don't get produced 44 -p) 45 SED='s;\.o;;' 46 shift ;; 47 *) 48 break ;; 49 esac 50done 51 52if [ $# = 0 ] ; then 53 echo 'usage: mkdep [-f depend_file] [cc_flags] file ...' 54 exit 1 55fi 56 57TMP=/tmp/mkdep$$ 58trap 'rm -f $TMP ; exit 1' 1 2 3 13 15 59 60for i do 61 case "$i" in 62 -c|-M) 63 ;; 64 -I*) 65 INCL="$INCL $i";; 66 -D*|-O|-U*) 67 FLAGS="$FLAGS $i";; 68 *) 69 # assume source file 70 # put '$dep' in front of dependencies 71 dep=`echo "$i" | sed -e 's,/,\\\\/,g' -e 's/\.c$/.o/'` 72 73 # Find includes, remove leading numerics, remove ./, 74 # remove double quotes, and remove trailing numerics. 75 # Sort that, discarding duplicates, and add '$dep'. 76 cpp $INCL $FLAGS "$i" | sed -e ' 77 /^#/!d 78 s/# [0-9]* // 79 s,"./,", 80 s/"\(.*\)"/\1/ 81 s/ [ 0-9]*$//' | 82 sort -u | sed -e "s/^/$dep: /";; 83 esac 84done | 85sed " 86 s; \./; ;g 87 /\.c:$/d 88 $SED" | 89awk '{ 90 if ($1 != prev) { 91 if (rec != "") 92 print rec; 93 rec = $0; 94 prev = $1; 95 } 96 else { 97 if (length(rec $2) > 78) { 98 print rec; 99 rec = $0; 100 } 101 else 102 rec = rec " " $2 103 } 104} 105END { 106 print rec 107}' > $TMP 108 109if [ $append = 1 ]; then 110 cat $TMP >> $D 111 rm -f $TMP 112else 113 mv $TMP $D 114fi 115exit 0 116