summaryrefslogtreecommitdiff
path: root/bin/g++dep
blob: a743b4630db5f319e753c566760a00c6cffbe158 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! /bin/sh

# This utility is a lightly editted version of the freed Berkeley
# script `mkdep'.  The current script is intended to work for GNU G++.

# Here is the original BSD header:
#	@(#)mkdep.sh	1.7	(Berkeley)	10/13/87
#

PATH=/bin:/usr/bin:/usr/ucb:/usr/gnu:/usr/gnu/bin:/opt/gnu/bin:/pkg/gnu/bin:$PATH
export PATH

if [ $# = 0 ] ; then
	echo 'usage: g++dep [-p] [-f makefile] [flags] file ...'
	exit 1
fi

MAKE=Makefile			# default makefile name is "Makefile"
case $1 in
	# -f allows you to select a makefile name
	-f)
		MAKE=$2
		shift; shift ;;

	# the -p flag produces "program: program.c" style dependencies
	# so .o's don't get produced
	-p)
		SED='-e s;\.o;;'
		shift ;;
	# -r allows the use of relative pathnames...
        -r)
		REL="-e s;$WRAPPER_ROOT;\$(WRAPPER_ROOT);g"
		shift ;;
esac

if [ ! -w $MAKE ]; then
	echo "g++dep: no writeable file \"$MAKE\""
	exit 1
fi

TMP=/tmp/g++dep$$

trap 'rm -f $TMP ; exit 1' 1 2 3 13 15

cp $MAKE ${MAKE}.bak

sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP

cat << _EOF_ >> $TMP
# DO NOT DELETE THIS LINE -- g++dep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.

_EOF_

gcc -MM $* | sed -e "s; \./; ;g" $SED $REL | \
	awk ' { \
		if ($1 != prev) { \
			if (rec != "") \
				print rec; rec = $0; prev = $1; \
		} \
		else { \
			if (length(rec $2) > 78) { \
				print rec; rec = $0; \
			} else \
				rec = rec " " $2 \
		} \
	} \
	END { \
		print rec \
	} ' >> $TMP

cat << _EOF_ >> $TMP

# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
_EOF_

# copy to preserve permissions
cp $TMP $MAKE
rm -f ${MAKE}.bak $TMP
exit 0