aboutsummaryrefslogtreecommitdiff
path: root/gdb/config.gdb
blob: c380fe45772d13ab849a2a42c733c17d1d488bd1 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/sh

# Shell script to do machine-dependent things in
# preparation for compiling gdb.
#
# Usage: config.gdb machine
#
# If config.gdb succeeds, it leaves its status in config.status.
# If config.gdb fails after disturbing the status quo, 
# 	config.status is removed.

progname=$0
host=
target=
list_hosts=
list_targets=
srcdir=

for arg in $*; do
  case $arg in
    -srcdir=*|+srcdir=*)
      srcdir=`echo $arg | sed 's/[+-]srcdir=//'`
      ;;
    -host|+host)
      list_hosts=true
      ;;
    -target|+target)
      list_targets=true
      ;;
    -host=*|+host=*)
      if [ "$host" = "" ]; then
        host=`echo $arg | sed 's/[+-]host=//'`
      else
        echo Error: Attempt to specify host machine twice
        bad=true
      fi
      ;;
    -target=*|+target=*)
      if [ "$target" = "" ]; then
        target=`echo $arg | sed 's/[+-]target=//'`
      else
        echo Error: Attempt to specify target machine twice
        bad=true
      fi
      ;;
    *)
      if [ "$host" = "" ]; then
	host=$arg
      else
        if [ "$target" = "" ]; then
          target=$arg
        else
          echo Error: More arguments than host and target machine names
	  bad=true
        fi
      fi
      ;;
  esac
done

if [ "$target" = "" ]; then target=$host; fi
if [ "$host" = "" ]; then bad=true; fi

# Find the source files, if location was not specified
if [ "$srcdir" = "" ]; then
  srcdirdefaulted=true
  srcdir=.
  if [ ! -r main.c ]; then
    srcdir=..
  fi
fi
if [ ! -r ${srcdir}/main.c ]; then
  if [ "$srcdirdefaulted" != "true" ]; then
    echo "$progname: Can't find debugger sources in \`${srcdir}'." 1>&2
  else
    echo "$progname: Can't find debugger sources in \`.' or \`..'." 1>&2
  fi
  exit 1
fi

if [ "$list_hosts" = "true" ]; then
  cd $srcdir/xconfig
  for i in * ; do
# The {} in ${i} are required or else /bin/sh in sony newsos 3.2 removes
# the quote after it.
  awk <$i "NR == 1 { lastchar = substr(\"${i}\", length(\"${i}\"), 1)
if (lastchar != \"~\" && lastchar != \"#\") \
printf \"%-12s %s\n\", \"${i}\", substr(\$0,2) }"
  done
fi

if [ "$list_targets" = "true" ]; then
  cd $srcdir/tconfig
  for i in * ; do
  awk <$i "NR == 1 { lastchar = substr(\"${i}\", length(\"${i}\"), 1)
if (lastchar != \"~\" && lastchar != \"#\") \
printf \"%-12s %s\n\", \"${i}\", substr(\$0,2) }"
  done
fi

if [ "$list_hosts" = "true" -o "$list_targets" = "true" ]; then
  exit 0
fi

if [ "$host" != "" -a ! -f $srcdir/xconfig/$host ]; then
  echo "No such host $host"
  bad=true
fi

if [ "$target" != "" -a ! -f $srcdir/tconfig/$target ]; then
  echo "No such target $target"
  bad=true
fi

if [ "$bad" = "true" ] ; then
  echo "Usage: "
  echo "  $progname [+srcdir=\`dir'] machine"
  echo "    For normal usage"
  echo "  $progname [+srcdir=\`dir'] \`host' \`target'"
  echo "  $progname [+srcdir=\`dir'] +host=\`host' +target=\`target'"
  echo "    If you are doing remote debugging between machines of two"
  echo "    different types (cross-debugging).  \`host' is the type of"
  echo "    machine on which GDB will be running.  \`target' is the"
  echo "    machine that the program you are debugging will be"
  echo "    running on."
  echo "  $progname +host"
  echo "    Print a list of valid host machine types."
  echo "  $progname +target"
  echo "    Print a list of valid target machine types."
  echo
  echo "  +srcdir=\`dir' means that the sources are in \`dir'.  For"
  echo "    example, \`cd /obj/hp300; config.gdb +srcdir=/src/gdb hp300'"
  echo "    If +srcdir is not specified, sources can either be in \`.'"
  echo "    or \`..'."
  echo

  if [ -r config.status ]
  then
    cat config.status
  fi
  exit 1
fi

rm -f tm.h xm.h

cat $srcdir/xconfig/$host $srcdir/tconfig/$target | awk '$1 == "#msg" {
  print substr($0,6)}'
paramfile=${srcdir}/`awk '
  $1 == "TM_FILE=" { print $2 }' <$srcdir/tconfig/$target`
if [ "$paramfile" != "${srcdir}/" ] ; then
  # Make a symlink if possible, otherwise try a hard link
  ln -s $paramfile tm.h 2>/dev/null || ln $paramfile tm.h
fi

paramfile=${srcdir}/`awk '
  $1 == "XM_FILE=" { print $2 }' <$srcdir/xconfig/$host`
if [ "$paramfile" != "${srcdir}/" ] ; then
  # Make a symlink if possible, otherwise try a hard link
  ln -s $paramfile xm.h 2>/dev/null || ln $paramfile xm.h
fi

rm -f config.status

case ${srcdir} in
  .)
    ;;
  *)
    echo "srcdir=${srcdir}" >./Makefile.sdir
    grep -s "source ${srcdir}/.gdbinit" .gdbinit 2>/dev/null || \
      echo "source ${srcdir}/.gdbinit" >> .gdbinit
esac

rm -f Makefile
make "srcdir=${srcdir}" \
  "M_MAKEFILE=$srcdir/tconfig/$target $srcdir/xconfig/$host" \
  -f $srcdir/Makefile.dist Makefile

echo "GDB is now set up for host machine $host and target machine $target." \
	| tee config.status
exit 0