summaryrefslogtreecommitdiff
path: root/bin/g++dep
blob: 226f7ef68d5ede5590ea10d5cc2a448b0838885a (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#! /bin/sh
# $Id$

# 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
#

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

DO_ACE_MAKE_DEPEND=0
MAKE=Makefile
STOPNOW=0
while [ $STOPNOW -eq 0 ]
do
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;$ACE_ROOT;\$(ACE_ROOT);g ${ACE_DEPEND_SED_CMD}"
      REL="-e s;${TAO_ROOT:=$ACE_ROOT/TAO};\$(TAO_ROOT);g "$REL
      shift ;;
  # -A uses relative pathnames and fixes the .obj line
  #    and it implies -r
  -A) REL="-e s;$ACE_ROOT;\$(ACE_ROOT);g ${ACE_DEPEND_SED_CMD}"
      REL="-e s;${TAO_ROOT:=$ACE_ROOT/TAO};\$(TAO_ROOT);g "$REL
      DO_ACE_MAKE_DEPEND=1
      shift ;;
  # -R VARNAME allows you to specify a variable which should be used
  #    to generate relative paths if it's defined.  You can use multiple
  #    -R options, but be careful if one of the values is a proper
  #    subset of a subsequent value, because I suspect that sed will
  #    substitute for the first value properly, but not for the second.  You might
  #    Be able to get around this by reordering and having the more specific
  #    values lead the less specific values.
  -R) varname=$2
      eval "echo \$${varname}" >/tmp/$$.vv
      varval=`eval cat /tmp/$$.vv`; rm /tmp/$$.vv
      if [ -n "$varval" ]; then
        REL="-e s;$varval;\$($varname);g "$REL
      fi
      shift; shift;;
  *) STOPNOW=1
esac
done

# Dependencies on local files are better expressed like that, instead
# of using $(TAO_ROOT) or $(ACE_ROOT).  This is specially important
# for IDL generated files.
REL="-e s;`pwd`/;;g "$REL

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_

g++ -MM -DACE_LACKS_PRAGMA_ONCE $* | \
  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

if [ $DO_ACE_MAKE_DEPEND -eq 1 ]
then
  SCRIPT=${TMP}_script
  echo "s;\([-a-zA-Z0-9._+]*\)\.o:;\\" > $SCRIPT
  echo ".obj/\1.o .obj/\1.${SOEXT} ${VSHDIR}\1.o ${VSHDIR}\1.${SOEXT}:;" >> $SCRIPT
  TMP2=${TMP}_2
  cat $TMP | \
  sed \
      -e '/$(ACE_ROOT)\/ace\/config[^\.]*\.h/d' \
      -e "s; /[-a-zA-Z0-9_./+]*\.h;;g" \
      -e 's/\\[ \t][ \t]*\\/\\/g' \
      -f $SCRIPT > $TMP2
  mv $TMP2 $TMP
  rm -f $TMP2
  rm -f $SCRIPT
fi

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