summaryrefslogtreecommitdiffstats
path: root/simple-build-script/build_tools
blob: 972c8e63af7ad2a600b6f1a00f5b67ac86e46a36 (plain) (blame)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#! /bin/sh
#
#  This script is a simple script to build and install rtems toolset
#  for the target you specify on the command line.  It should be of
#  the form <CPU>-rtems<VERSION>.  For example, sparc-rtems4.11
#
#  This can be used to build versions from CVS/SVN or released versions.
#  Please be sure to apply appropriate patches from
#  rtems/contrib/crossrpms/patches.
#
#  Currently only testing of non-RTEMS targets is supported.
#

### EDIT THESE AS NEEDED
AUTOCONF=autoconf-2.69
AUTOMAKE=automake-1.12.6
BINUTILS=binutils-cvs/src
GDB=gdb-cvs/src
GCC=gcc-svn
NEWLIB=newlib-cvs/src
LANGUAGES="c,c++"
### END OF EDIT THESE

BASE=`pwd`

#   log an error to stderr
prerr()
{
    echo "$*" >&2
}

fatal() {
    prerr "$USAGE"
    [ "$1" ] && (prerr ; prerr $*);
    exit 1
}

check_status()
{
  if [ $1 -ne 0 ] ; then
    shift
    echo "FAILED: " "$*" >&2
    exit 1
  fi
}

toggle()
{
  case $1 in
    no)  echo "yes" ;;
    yes) echo "no" ;;
    *)   fatal "Unknown value to toggle ($1)" ;;
  esac
}

usage()
{
cat <<EOF
  -v             verbose (default=no)
  -c             clean after building if OK (default=yes)
  -A             toggle building binutils, gcc, newlib, and gdb
  -a             toggle building autoconf (default=no)
  -m             toggle building automake (default=no)
  -b             toggle building binutils (default=no)
  -g             toggle building gcc/newlib (default=no)
  -d             toggle building gdb (default=no)
  -i INSTALL     specify install directory (required)
  -t TARGET      specify target (required)
  -B DIRECTORY   specify directory for build tree (default=pwd)
  -T             toggle running test (default=no)
  -M             toggle sending test results email (default=no)

EOF
exit 1
}

sourcedir=`pwd`
buildroot=`pwd`
do_clean=yes
do_autoconf=no
do_automake=no
do_binutils=no
do_gdb=no
do_gcc_newlib=no
verbose=no
TARGET=NOT_SET
INSTALL=NOT_SET
jobs=NOT_SET
do_tests=no
do_mail=no

while getopts cj:B:vTMAambgdi:t: OPT
do
  case "$OPT" in
    A) do_binutils=`toggle ${do_binutils}`
       do_gdb=`toggle ${do_gdb}`
       do_gcc_newlib=`toggle ${do_gcc_newlib}`
       ;;
    a) do_autoconf=`toggle ${do_autoconf}` ;;
    m) do_automake=`toggle ${do_automake}` ;;
    b) do_binutils=`toggle ${do_binutils}` ;;
    g) do_gcc_newlib=`toggle ${do_gcc_newlib}` ;;
    d) do_gdb=`toggle ${do_gdb}` ;;
    i) INSTALL="${OPTARG}" ;;
    t) TARGET="${OPTARG}" ;;
    j) jobs="${OPTARG}" ;;
    B) buildroot="${OPTARG}" ;;
    c) do_clean=`toggle ${do_clean}` ;;
    T) do_tests=`toggle ${do_tests}` ;;
    M) do_mail=`toggle ${do_mail}` ;;
    v) verbose=`toggle ${verbose}` ;;
    *) echo "Error ${OPT} is not a valid option" ; usage ; exit 1 ;;
  esac
done

# Specify the desired parallelism
if [ ${jobs} != "NOT_SET" ] ; then
  case ${jobs} in
    NOT_SET)
      JOBS=""
      ;;
    ''|*[!0-9]*)
      check_fatal 1 "Number of jobs (${jobs}) specified is not a number"
      ;;
    *)
      JOBS="-j ${jobs}"
      ;;
  esac
fi

if [ ${verbose} = "yes" ] ; then
  echo "Build autoconf:    " ${do_autoconf}
  echo "Build automake:    " ${do_automake}
  echo "Build binutils:    " ${do_binutils}
  echo "Build gdb:         " ${do_gdb}
  echo "Build gcc/newlib:  " ${do_gcc_newlib}
  echo "Clean as building: " ${do_clean}
  echo "Running Tests:     " ${do_tests}
  echo "  Mailing Results: " ${do_mail}
  echo "Parallel Jobs:     " ${jobs}
  echo "Install point:     " ${INSTALL}
  echo "Build root:        " ${buildroot}
  echo "Target:            " ${TARGET}
  echo
fi

### Validate arguments
test ${TARGET} != NOT_SET
check_status $? "TARGET not specified"

test ${INSTALL} != NOT_SET
check_status $? "INSTALL not specified"
  
if [ ! -d ${INSTALL} ] ; then
  mkdir ${INSTALL}
  check_status $? "failed to make ${INSTALL}"
fi

if [ ${do_autoconf} = yes ] ; then
  test -d ${AUTOCONF}
  check_status $? "No ${AUTOCONF} - You do not appear to be in src directory"
  TOBUILD="${TOBUILD} ${AUTOCONF}"
fi

if [ ${do_automake} = yes ] ; then
  test -d ${AUTOMAKE}
  check_status $? "No ${AUTOMAKE} - You do not appear to be in src directory"
  TOBUILD="${TOBUILD} ${AUTOMAKE}"
fi

if [ ${do_binutils} = yes ] ; then
  test -d ${BINUTILS}
  check_status $? "No ${BINUTILS} - You do not appear to be in src directory"
  TOBUILD="${TOBUILD} ${BINUTILS}"
fi

if [ ${do_gdb} = yes ] ; then
  test -d ${GDB}
  check_status $? "No ${GDB} - You do not appear to be in src directory"
  TOBUILD="${TOBUILD} ${GDB}"
fi

if [ ${do_gcc_newlib} = yes ] ; then
  test -d ${GCC}
  check_status $? "No ${GCC} - You do not appear to be in src directory"

  test -d ${NEWLIB}
  check_status $? "No ${NEWLIB} - You do not appear to be in src directory"

  if [ ! -d ${GCC}/newlib -o ! -d ${GCC}/libgloss ] ; then
    echo "Please ensure that ${GCC}/newlib and ${GCC}/libgloss are symbolic"
    echo "links into the newlib tree.  Use commands simiilar to the following:"
    echo ""
    echo "ln -s ${BASE}/${NEWLIB}/newlib ${BASE}/${GCC}/newlib"
    echo "ln -s ${BASE}/${NEWLIB}/libgloss ${BASE}/${GCC}/libgloss"
    exit 1
  fi

  TOBUILD="${TOBUILD} ${GCC}"
fi

test -d ${buildroot}
check_status $? "${buildroot} does not exist"

export PATH=${INSTALL}/bin:$PATH
### Build everything
for pkg in ${TOBUILD}
do
  cd ${buildroot}
  check_status $? "failed to cd ${buildroot}"

  BUILDDIR=`echo b-${TARGET}-${pkg} | sed -e 's/\//-/g'`

  rm -rf ${BUILDDIR}
  check_status $? "failed to rm ${BUILDDIR}"

  mkdir ${BUILDDIR}
  check_status $? "failed to make ${BUILDDIR}"

  cd ${BUILDDIR}
  check_status $? "failed to cd ${BUILDDIR}"

  echo "Configuring ${pkg} in ${BUILDDIR}..."
  case $pkg in
    auto*)                               # autotools are native
      ${sourcedir}/${pkg}/configure --prefix=${INSTALL} >c.log 2>&1
      check_status $? "failed to configure ${pkg}"
      ;;
    binutils*)
      ${sourcedir}/${pkg}/configure --target=${TARGET} \
        --prefix=${INSTALL} >c.log 2>&1
      check_status $? "failed to configure ${pkg}"
      ;;
    gdb*)
      ${sourcedir}/${pkg}/configure --target=${TARGET} \
        --prefix=${INSTALL} \
        --enable-sim --enable-sim-hardware \
        --enable-timebase --enable-sim-trace >c.log 2>&1
      check_status $? "failed to configure ${pkg}"
      ;;
    gcc*)
      ${sourcedir}/${GCC}/configure \
       --enable-threads=rtems  --with-gnu-as --enable-multilib \
       --enable-newlib-mb --enable-newlib-iconv \
       --with-gnu-ld --with-newlib  --verbose --with-system-zlib --disable-nls \
        --enable-version-specific-runtime-libs \
        --enable-languages=${LANGUAGES} --target=${TARGET} --prefix=${INSTALL} \
      >c.log 2>&1
      check_status $? "failed to configure ${pkg}"
      ;;
    *)
      prerr "UNKNOWN PACKAGE ${pkg}"
      exit 1
      ;;
  esac

  echo "Building ${pkg}..."
  make ${JOBS} >b.log 2>&1
  check_status $? "failed to make ${pkg}"

  echo "Installing ${pkg}..."
  make install >i.log 2>&1
  check_status $? "failed to install ${pkg}"

  # If testing the package, fall into this if
  if [ ${do_tests} = "yes" ] ; then
    echo "Testing ${pkg}..."
    case $pkg in
      auto*)
        # currently do not run test suite on autoconf and automake
        ;;
      binutils*)
        echo "Testing binutils for ${TARGET}"
        make check >check.log 2>&1
        ;;
      gdb*)
        # currently do not run test suite on gdb
        ;;
      gcc*)
        baseboard=NOT_SET
        case ${TARGET} in
          *-rtems*)
            echo "*** Currently do not support testing GCC with this script"
            ;;
          *-elf*|*-eabi*)
            cpu=`echo ${TARGET} | cut -d'-' -f1`
            case ${cpu} in
              arc*|arm*|basic*|cris*|d10v*|d30v*|fr30*|frv*|h8300*|i960*|iq2000*|jmr3904|\
              m32r*|m68hc11*|mcore*|mips*|mips64*|mips64vr4100*|mmixware*|mn10200|\
              mn10300*|powerpc*|powerpcle*|sh*|sparc*|sparc64*|sparclite*|tic80*|tx39|\
              v850*|vr4100*|vr4111*|vr4300*|xtensa*)
                baseboard=${cpu}-sim
                ;;
              *)
                ;;
            esac
            ;;
          *)
            ;;
          
        esac

        # now see if we found a configuration to test with
        if [ ${baseboard} = "NOT_SET" ] ; then
          echo "*** Do not know how to test gcc on ${target}"
          continue
        fi

        echo "Testing gcc for ${TARGET} on ${baseboard}"
        make check RUNTESTFLAGS="--target_board=${baseboard}" >check.log 2>&1

        if [ ${do_mail} = "yes" ] ; then
          echo "Sending ${language} test results to GCC community.."
          ${sourcedir}/${GCC}/contrib/test_summary -m gcc-testresults@gcc.gnu.org | sh
          check_status $? "Failed to email ${language} Test Results to GCC Community .. bailing"

          echo "Sending ${language} test results to RTEMS community.."
          ${sourcedir}/${GCC}/contrib/test_summary -o -m rtems-tooltestresults@rtems.org | sh
          check_status $? "Failed to email ${language} Test Results to RTEMS Community .. bailing"
        fi
        ;;
      *)
        prerr "UNKNOWN PACKAGE ${pkg}"
        exit 1
        ;;
    esac

  fi
  # END of if testing the package

  cd ..
  if [ ${do_clean} = "yes" ] ; then
    rm -rf ${BUILD}
  fi
done

exit 0