summaryrefslogtreecommitdiffstats
path: root/gcc/do_one
blob: 0c029e7bbdf4e10fab858f8db6ffbee24556e334 (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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
#! /usr/bin/env bash
#
# Execution Times (for sparc-rtems${RTEMS_VERSION})
#
#   - building native                      - ?
#   - building binutils                    - 1m31.310s
#   - building GDB                         - 1m39.318s
#   - building stage1 (multilib)           - 10m22.371s
#   - building RTEMS (multilib + BSP)      - 22m47.048s
#   - building Objective-C (multilib)      - 6m45.532s
#   - building Ada (multilib)              - ?
#   - building Go (multilib)               - ?
#   - building GCJ (multilib)              - ?
#   - Running GCC Test Suite (sis)         - 122m47.289s
#   - Running Objective-C Test Suite (sis) - ?
#   - Running ACAT           (sis)         - ?
#   - Running Go Test Suite  (sis)         - ?
#   - Running GCJ Test Suite  (sis)        - ?
#
# Computer Info
#   Fedora 14 on Intel Core2 Duo Q6600 (4 core) @ 2.40GHz w/ 4GB RAM

vfile=`dirname $0`/../VERSIONS
if [ ! -r ${vfile} ] ; then
  echo VERSIONS file not found
  exit 1
fi

source ${vfile}


######################## Set defaults #############################
# Remove Build Directories
do_cleanup=no
# Install Binutils
do_binutils=no
# Install GDB
do_gdb=no
# Build the native compiler?
do_native=no
  do_native_ada=yes
# Build the base level cross compiler. C++ and multilib are optional.
do_stage1=no
  do_cxx=yes
  do_multilib=yes
# Build the Objective-C language cross compiler.
do_objc=no
  do_native_objc=yes
# Build the Ada language cross compiler.
do_ada=no
  do_ada_multilib=yes
# Build the GCC Go language cross compiler.
do_gccgo=no
	do_gccgo_multilib=yes
# Build the GCC Java language cross compiler.
do_gcj=no
	do_gcj_multilib=yes
# Build the GCC FORTRAN language cross compiler.
do_fortran=no
	do_fortran_multilib=yes
# Build RTEMS for a particular CPU/BSP combination
do_rtems=no
# Which test suites do we attempt
run_gcctests=no
run_objctests=no
run_acats=no
run_gccgotests=no
run_libgotests=no
run_libjavatests=no
run_fortrantests=no
# Do we send email to gcc-testresults with the test results?
do_mail=yes
# Are we noisy when running?
verbose=no
######################## Parse arguments ###########################

usage()
{
cat <<EOF
do_one [options] CPU BSP
  -A   - binutils, stage 1, C++, C/C++ multilib, RTEMS
  -S   - enable secondary languages of Ada, GCC Go, ObjC, FORTRAN
  -T   - run GCC tests for languages enabled
  -B n - build jobs in parallel (e.g. make -j N)
  -n   - native compiler
  -d   - do not clean up (delete build directories) (default=no)
  -M   - do NOT email test results to gcc-testresults
  -v   - verbose (default=no)

  Cross Compilation Options (Base and Primary Languages)
  ======================================================
    -b   - install binutils
    -D   - install gdb
    -1   - stage 1 C/C++ compiler
    -c   -   do not include C++ 
    -m   -   do not build multilib
    -r   - build RTEMS
    -g   - run GCC C/C++ tests


  Cross Compilation Options (Secondary Languages)
  ===============================================
    -a   - enable stage 2 Ada compiler
    -G   - enable stage 2 GCC Go compiler
    -J   - enable stage 2 GCC Java compiler
    -f   - enable stage 2 GCC FORTRAN compiler
    -F   - run FORTRAN tests
    -C   - run ACATS
    -O   - Build Objective-C
    -P   - Run Objective-C Tests
    -o   - run GCC Go tests
    -t   - run libgo tests
    -j   - run libjava tests
EOF
}

fatal()
{
  usage
  exit 1
}

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

while getopts bdDnv1cmargiotB:CfFAJTMGOPS OPT
do
    case "$OPT" in
        A) do_binutils="yes"
           do_gdb="yes"
           do_stage1="yes"
           do_cxx="yes"
           do_multilib="yes"
           do_rtems="yes"
           ;;
        S) # Secondary languages need to be explicitly turned on
           do_ada="yes"
           do_gccgo="yes"
           do_gcj="yes"
           do_objc="yes"
           do_fortran="yes"
           ;;
        B) MAKEJOBS="-j$OPTARG" ;;
        d) do_cleanup=`toggle ${do_cleanup}` ;;
        D) do_gdb=`toggle ${do_gdb}` ;;
        T) run_gcctests="yes"
           run_objctests="yes"
           run_acats="yes"
           run_gccgotests="yes"
           run_fortrantests="yes"
           ;;
        b) do_binutils=`toggle ${do_binutils}` ;;
        # Build the native
        n) do_native=`toggle ${do_native}` ;;
        # Stage 1 arguments
        1) do_stage1=`toggle ${do_stage1}` ;;
        c) do_cxx=`toggle ${do_cxx}` ;;
        m) do_multilib=`toggle ${do_multilib}` ;;
        # Stage 2 arguments
        a) do_ada=`toggle ${do_ada}` ;;
        G) do_gccgo=`toggle ${do_gccgo}` ;;
        J) do_gcj=`toggle ${do_gcj}` ;;
        f) do_fortran=`toggle ${do_fortran}` ;;
        # Build RTEMS
        r) do_rtems=`toggle ${do_rtems}` ;;
        # Testsuites to run
        g) run_gcctests=`toggle ${run_gcctests}` ;;
        C) run_acats=`toggle ${run_acats}` ;;
        v) verbose=`toggle ${verbose}` ;;
        M) do_mail=`toggle ${do_mail}` ;;
        O) do_objc=`toggle ${do_objc}` ;;
        P) run_objctests=`toggle ${run_objctests}` ;;
        o) run_gccgotests=`toggle ${run_gccgotests}` ;;
        t) run_libgotests=`toggle ${run_libgotests}` ;;
        j) run_libjavatests=`toggle ${run_libjavatests}` ;;
        F) run_fortrantests=`toggle ${run_fortrantests}` ;;
        *) fatal ;;
    esac
done

run_libgotests=$run_gccgotests

########################### Grab CPU/BSP ###########################
shiftcount=`expr $OPTIND - 1`
shift $shiftcount
cpu=${1}
bsp=${2}

needBSP=no
needCPU=no

# If native or cross, check things differently
if [ ${do_native} = yes ] ; then
  if [ ${do_gccgo} = yes ] ; then
    echo "Warning! Go requires native C++ to build."
    do_cxx=yes
  fi

  if [ ${do_gcj} = yes ] ; then
    echo "Warning! GCJ requires native C++ to build."
    do_cxx=yes
  fi
else # NOT NATIVE - build for RTEMS
  # Should the user have specified a CPU and/or BSP?
  if [ ${do_binutils} = yes -o ${do_gdb} = yes -o \
       ${do_stage1} = yes -o ${do_ada} = yes -o \
       ${do_gccgo} = yes -o ${do_gcj} = yes -o \
       ${do_fortran} = yes ] ; then
    needCPU=yes
  fi

  if [ ${do_rtems} = yes -o ${run_gcctests} = yes -o \
       ${run_acats} = yes -o ${run_gccgotests} = yes -o \
       ${run_libjavatests} = yes ] ; then
    needBSP=yes
    needCPU=yes
    if [ x${bsp} = x ] ; then
      echo "BSP NOT SET"
      fatal
    fi
  fi

  if [ ${needCPU} = yes -a x${cpu} = x ] ; then
    echo "CPU NOT SET"
    fatal
  fi

  if [ ${needBSP} = yes -a x${bsp} = x ] ; then
    echo "BSP NOT SET"
    fatal
  fi

  TARGET=${cpu}-rtems${RTEMS_VERSION}

  # Which CPUs do not support C++
  if [ ${do_cxx} = "yes" ] ; then
    case ${cpu} in
      avr|h8300|m32c)
        do_cxx=no
        echo ${cpu} does not support C++
        ;;
      *);;
    esac
  fi

  # Which CPUs do not support Ada
  if [ ${do_ada} = "yes" ] ; then
    case ${cpu} in
      avr|h8300|m32c|sh)
        do_ada=no
        run_acats=no
        echo ${cpu} does not support Ada
        ;;
      *);;
    esac
  fi

  # Which CPUs do not support Go
  if [ ${do_gccgo} = "yes" ] ; then
    case ${cpu} in
      avr|h8300|m32c)
        do_gccgo=no
        echo ${cpu} does not support Go
        ;;
      *);;
    esac
  fi

  # Which CPUs do not support GCJ
  if [ ${do_gcj} = "yes" ] ; then
    case ${cpu} in
      avr|h8300|m32c)
        do_gcj=no
        echo ${cpu} does not support GCJ
        ;;
      *);;
    esac
  fi

  # Which CPUs do not support FORTRAN
  if [ ${do_fortran} = "yes" ] ; then
    case ${cpu} in
      arm|i386|m68k|mips|powerpc|sparc) ;;
      *)
        do_fortran=no
        echo ${cpu} does not support Ada
        ;;
    esac
  fi
fi

# When verbose, print settings
if [ ${verbose} = yes ] ; then
  echo "Target          : " ${cpu}
  echo "BSP             : " ${bsp}
  echo "Binutils        : " ${do_binutils}
  echo "GDB             : " ${do_gdb}
  echo "Make Jobs       : " ${MAKEJOBS}
  echo "Build Native    : " ${do_native}
  echo "Build C Stage 1 : " ${do_stage1} "(multilib=${do_multilib} test=${run_gcctests})"
  echo "  C++           : " ${do_cxx}
  echo "Build RTEMS     : " ${do_rtems}
  echo "Email Tests     : " ${do_mail}
  echo "Native GCC      : " `type gcc`
  echo "PATH            : " ${PATH}
  echo "Clean up        : " ${do_cleanup}
  echo
  echo "==================== Secondary Languages ======================"
  echo "  Ada         : " ${do_ada}     "(multilib=${do_ada_multilib} test=${run_acats})"
  echo "  FORTRAN     : " ${do_fortran} "(multilib=${do_gccgo_multilib} test=${run_fortrantests})"
  echo "  GCC Go      : " ${do_gccgo} \
       "(multilib=${do_gccgo_multilib} test=${run_gccgotests} libgotests=${run_libgotests})"
  echo "  GCJ         : " ${do_gcj} \
       "(multilib=${do_gcj_multilib} test=${run_gcjtests} libtests=${run_libjavatests})"
  echo "  Objective-C : " ${do_objc}   "(multilib=${do_ada_multilib} test=${run_objctests})"
fi

# Do we accept an alternate name for the BSP?
if [ x${bsp} = xqemu ] ; then
  BSP_BUILT=pc386
else
  BSP_BUILT=${bsp}
fi
  
######### Consistency check installation of source
if [ ! -d ${GCCDIR}/newlib ] ; then
  echo "${GCCDIR}/newlib not present"
  exit 1
fi

ADASCRIPTDIR=${SCRIPTDIR}/gcc/testsuite/ada/acats
for i in Makefile.rtems rtems_acats_reasons rtems_acats_status \
    rtems_generate_acats_email rtems_init.c run_all_rtems.sh
do
  if [ ! -r ${ADASCRIPTDIR}/${i} ] ; then
    echo "${ADASCRIPTDIR}/gcc/testsuite/ada/acats/${i} not present"
    echo "RTEMS ACATS support files not present"
    exit 1
  fi
done

if [ ${needCPU} = yes -a ${needBSP} = yes -a \
     ${run_gcctests} = yes -a ${run_acats} = yes ] ; then
  DEJADIR=${SCRIPTDIR}/dejagnu/boards 
  if [ ! -d ${DEJADIR} ] ; then
    echo "Missing DejaGNU configuration directory (${DEJADIR})"
    exit 1
  fi

  case ${cpu}-${bsp} in
    arm-edb7312)          dejacfg=rtems-arm-edb7312 ;;
    avr-avrtest)          dejacfg=rtems-avr-avrtest ;;
    bfin-eZKit533)        dejacfg=rtems-bfin-nosim ;;
    h8300-h8sim)          dejacfg=rtems-h8300-h8sim ;;
    i386-pc386|i386-qemu) dejacfg=rtems-i386-qemu ;;
    lm32-lm32_evr)        dejacfg=rtems-lm32-lm32_evr ;;
    m32c-m32csim)         dejacfg=rtems-m32c-m32csim ;;
    m32r-m32rsim)         dejacfg=rtems-m32r-m32rsim ;;
    m68k-uC5282)          dejacfg=rtems-m68k-uC5282 ;;
    microblaze-nosim)     dejacfg=rtems-microblaze-nosim ;;
    mips-jmr3904)         dejacfg=rtems-mips-jmr3904 ;;
    powerpc-psim)         dejacfg=rtems-powerpc-psim ;;
    sh-simsh1)            dejacfg=rtems-sh-simsh1 ;;
    sparc-sis)            dejacfg=rtems-sparc-sis ;;
    sparc64-niagara)      dejacfg=rtems-sparc64-nosim ;;
    v850-*v850*sim*)      dejacfg=rtems-v850-v850sim ;;
    *)
      echo "ERROR ${bsp} is not known to DegaGNU"
      exit 1
      ;;
  esac

  if [ ! -r ${DEJADIR}/${dejacfg}.exp ] ; then
    echo "Missing DejaGNU file for ${cpu}/${bsp}"
    exit 1
  fi
fi
######### END OF Consistency check installation of source

######### Log Directory
if [ ! -d ${LOGDIR} ] ; then
  mkdir ${LOGDIR}
fi
######### 

######### Install binutils
j_binutils()
{
  test -d ${INSTALL} || mkdir -p ${INSTALL}

  cd ${INSTALL}/..
  
  echo "Building Binutils from source"
  rm -rf ${BUILDDIR}/b-${cpu}-binutils
  mkdir ${BUILDDIR}/b-${cpu}-binutils
  cd ${BUILDDIR}/b-${cpu}-binutils
  (${BINUTILSDIR}/configure --target=${TARGET} --prefix=$INSTALL \
    --disable-werror && \
    make ${MAKEJOBS} && make install) >${LOGDIR}/${cpu}-binutils.log 2>&1
  if [ $? -ne 0 ] ; then
    echo "Failed to build Binutils from source"
    exit 1
  fi
  echo "Checking Binutils "
  make check >${LOGDIR}/${cpu}-binutils-check.log 2>&1
  grep ^FAIL ${LOGDIR}/${cpu}-binutils-check.log
  cd .. 
  test ${do_cleanup} = "yes" && rm -rf ${BUILDDIR}/b-${cpu}-binutils
}

if [ ${do_binutils} = yes ] ; then
  echo "Building binutils..."
  time j_binutils ${cpu}
fi

######### Install gdb
j_gdb()
{
  test -d ${INSTALL} || mkdir -p ${INSTALL}

  cd ${INSTALL}/..

  case ${cpu} in
    mips) GDBTARGET=${cpu}tx39-rtems${RTEMS_VERSION} ;;
    *)    GDBTARGET=${TARGET} ;;
  esac

  echo "Building GDB from source"
  cd ${BASEDIR}
  rm -rf ${BUILDDIR}/b-${cpu}-gdb
  mkdir ${BUILDDIR}/b-${cpu}-gdb
  cd ${BUILDDIR}/b-${cpu}-gdb
  (${GDBDIR}/configure --target=${GDBTARGET} \
    --enable-sim --enable-sim-hardware \
    --disable-werror \
    --enable-timebase --enable-sim-trace  --prefix=$INSTALL && \
    make ${MAKEJOBS} && make install) >${LOGDIR}/${cpu}-gdb.log 2>&1
  if [ $? -ne 0 ] ; then
    echo "Failed to build gdb from source"
    exit 1
  fi
  cd .. 
  test ${do_cleanup} = "yes" && rm -rf ${BUILDDIR}/b-${cpu}-gdb
}

if [ ${do_gdb} = yes ] ; then
  echo "Building gdb..."
  time j_gdb ${cpu}
fi

######### Build a native compiler
j_native()
{
  test ${do_native_ada} = "yes" && AdaArg=",ada"
  test ${do_native_objc} = "yes" && ObjCArg=",objc"
  ${GCCDIR}/configure \
    ${NATIVE_GCC_EXTRA_ARGS} \
    --disable-werror \
    --enable-languages=c,c++${AdaArg}${ObjCArg} --prefix=$INSTALL &&
  make ${MAKEJOBS} && make install
}

if [ ${do_native} = "yes" ] ; then
  echo "Building native compiler..."
  cd ${BASEDIR} && \
  rm -rf ${BUILDDIR}/b-native && \
  mkdir  ${BUILDDIR}/b-native && \
  cd ${BUILDDIR}/b-native
  time j_native >${LOGDIR}/native.log 2>&1
  if [ $? -ne 0 ] ; then
    echo "Failed to build native gcc"
    exit 1
  fi
  cd ..
  test ${do_cleanup} = "yes" && rm -rf ${BUILDDIR}/b-native
else
  echo Skipping native
fi
# END of build native compiler

######### Build Cross C/C++ baseline compiler
j_gcc()
{

  if [ X${1} = X ] ; then
    echo Usage: $0 TARGET_CPU
    exit 1
  fi

  if [ ! -d ${INSTALL} ] ; then
    echo ${INSTALL} does not exist
    exit 1
  fi

  if [ ${verbose} = yes ] ; then
    echo "Cross Assembler ==>" `type ${TARGET}-as`
  fi

  if [ ${do_cxx} = yes ] ; then
     cxx=",c++"
  fi
  if [ ${cpu} = avr ] ; then
    cxx=""
  fi

  if [ ${do_multilib} = yes ] ; then
     multilib="--enable-multilib"
  else
     multilib="--disable-multilib"
  fi

  ${GCCDIR}/configure \
    ${GCC_EXTRA_ARGS} \
    --disable-werror \
    --enable-threads=rtems  --with-gnu-as ${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=c${cxx} --target=$TARGET --prefix=$INSTALL
  if [ $? -ne 0 ] ; then
    echo "Failed to configure GCC C/C++ .. bailing"
    exit 1
  fi

  make ${MAKEJOBS}
  if [ $? -ne 0 ] ; then
    echo "Failed to build GCC C/C++ .. bailing"
    exit 1
  fi

  make install
  if [ $? -ne 0 ] ; then
    echo "Failed to install GCC C/C++ .. bailing"
    exit 1
  fi
}

if [ ${do_stage1} = "yes" ] ; then
  echo "Building Stage 1 compiler (C/C++)..."
  (cd ${BASEDIR} && \
   rm -rf ${BUILDDIR}/b-${cpu}-gcc && \
   mkdir  ${BUILDDIR}/b-${cpu}-gcc && \
   cd ${BUILDDIR}/b-${cpu}-gcc && \
     time j_gcc ${cpu} >${LOGDIR}/${cpu}-gcc.log 2>&1 && cd ..) || exit 1
else
  echo Skipping Stage 1 for ${cpu}
fi

#################### RTEMS

j_rtems()
{
  cpuArg=$1
  bspArg=$2
  bspdir=${BUILDDIR}/b-${cpuArg}-${bspArg}

  cd ${BASEDIR}
  rm -rf ${bspdir}
  mkdir  ${bspdir} || exit 1
  cd ${bspdir}     || exit 1

  ENABLE_BSP="--enable-rtemsbsp=${bspArg}"
  case $bspArg in
    multilib)
      ENABLE_BSP="--enable-multilib"
      MAKE_ARG="-k"
      ;;
      edb7312)    ENABLE_BSP="${ENABLE_BSP} ON_SKYEYE=1" ;;
      gumstix)    ENABLE_BSP="${ENABLE_BSP} ON_SKYEYE=1" ;;
    qemu|pc386)
      ENABLE_BSP="${ENABLE_BSP} USE_COM1_AS_CONSOLE=1"
      ENABLE_BSP="${ENABLE_BSP} BSP_PRESS_KEY_FOR_RESET=0"
      ENABLE_BSP="${ENABLE_BSP} BSP_RESET_BOARD_AT_EXIT=1"
      ;;
    *) ;;
  esac
  case ${cpu} in
    m32c|h8300)
      RTEMS_ARGS="--disable-ada --disable-posix --disable-networking" ;;
    *)
      RTEMS_ARGS="--enable-ada --enable-posix --enable-networking" ;;
  esac
  ${RTEMSDIR}/configure --target=${TARGET} ${ENABLE_BSP} \
  ${RTEMS_ARGS} --enable-maintainer-mode --disable-tests \
  --prefix=${BSP_INSTALL} && make ${MAKEJOBS} ${MAKE_ARG} && make install
  status=$?
  cd ..
  if [ $status -ne 0 ] ; then
    echo "Failed building RTEMS for ${cpuArg}/${bspArg}"
    if [ ${bspArg} != "multilib" ] ; then
      exit $status
    fi
  fi
}

if [ ${do_rtems} = "yes" ] ; then 
  echo "Building RTEMS for ${cpu} ${bsp} ..."
  time j_rtems ${cpu} multilib ${bsp} >${LOGDIR}/${cpu}-rtems-multilib.log 2>&1
  if [ $? -ne 0 ] ; then
    echo "Failed to build RTEMS multilib for ${cpu}"
    exit 1
  fi
  time j_rtems ${cpu} ${bsp} >${LOGDIR}/${cpu}-rtems-${bsp}.log 2>&1
  if [ $? -ne 0 ] ; then
    echo "Failed to build RTEMS for ${cpu}/${bsp}"
    exit 1
  fi
  test ${do_cleanup} = "yes" && \
      rm -rf ${BUILDDIR}/b-${cpu}-${bsp} ${BUILDDIR}/b-${cpu}-multilib
else
  echo Skipping RTEMS for ${cpu}/${bsp}
fi
pwd

j_process_results()
{
  language=$1

  shift

  RDIR=${RESULTSDIR}/${TARGET}-${bsp}/`date +%Y-%m-%d-%H-%M-%S`
  for results in `ls -1 gcc/testsuite/*/${*}.log gcc/testsuite/*/${*}.sum 2>/dev/null` 
  do
    test -d ${RDIR} || mkdir -p ${RDIR}
    cp ${results} ${RDIR}
  done

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

    echo "Sending ${language} test results to RTEMS community.."
    ${GCCDIR}/contrib/test_summary -o -m rtems-tooltestresults@rtems.org | sh
    if [ $? -ne 0 ] ; then
      echo "Failed to email ${language} Test Results to RTEMS Community .. bailing"
      exit 1
    fi
  fi
}

##### Do the gcc tests
if [ ${run_gcctests} = "yes" ] ; then 
  echo "Running GCC Tests..."
  cd ${BUILDDIR}/b-${cpu}-gcc || exit 1
  time sh -x ${SCRIPTDIR}/gcc/rundeja ${bsp} gcc \
    >${LOGDIR}/${cpu}-gcctests-${bsp}.log 2>&1
  
  if [ $? -eq 0 ] ; then
    j_process_results "C/C++" gcc/testsuite/gcc/gcc gcc/testsuite/g++/g++
  fi

  cd .. || exit 1
else
  echo Skipping GCC DejaGNU tests for ${cpu}/${bsp}
fi
test ${do_cleanup} = "yes" && rm -rf ${BUILDDIR}/b-${cpu}-gcc

##### Build an Objective-C compiler now that we have a cross installed
j_gccobjc()
{
  if [ X${1} = X ] ; then
    echo Usage: $0 TARGET_CPU
    exit 1
  fi
  TARGET=${1}-rtems${RTEMS_VERSION}

  if [ ! -d ${INSTALL} ] ; then
    echo ${INSTALL} does not exist
    exit 1
  fi

  if [ ${verbose} = yes ] ; then
    echo "Cross GCC for Objective-C ==>" `type ${TARGET}-gcc`
  fi

  ${GCCDIR}/configure \
   ${GCC_EXTRA_ARGS} \
   --enable-threads=rtems  --with-gnu-as  --enable-multilib \
   --with-gnu-ld --disable-newlib  --verbose --with-system-zlib --disable-nls \
    CFLAGS_FOR_TARGET=-B${BSP_INSTALL}/${TARGET}/${BSP_BUILT}/lib/ \
    --enable-version-specific-runtime-libs \
    --enable-languages=c,objc --target=$TARGET --prefix=$INSTALL &&
  make ${MAKEJOBS} &&
  make install
  status=$?
  if [ $status -ne 0 ] ; then
    echo "Failed building Objective-C"
  fi
}

objc_fail="no"
if [ ${do_objc} = "yes" ] ; then 
  echo "Building Stage 2 cross Objective-C compiler for ${1} ..."
  (cd ${BASEDIR} && \
   rm -rf ${BUILDDIR}/b-${cpu}-objc && \
   mkdir  ${BUILDDIR}/b-${cpu}-objc && \
   cd ${BUILDDIR}/b-${cpu}-objc && \
   time j_gccobjc ${cpu} >${LOGDIR}/${cpu}-objc.log 2>&1 && cd ..) || \
    objc_fail="yes"
else
  echo Skipping Stage 2 Objective-C for ${cpu}
fi

#### Run the Objective-C tests
if [ ${run_objctests} = "yes" -a \
     -d ${BUILDDIR}/b-${cpu}-objc -a ${objc_fail} = "no" ] ; then 
  echo "Running Objective-C Tests..."

  cd ${BUILDDIR}/b-${cpu}-objc || exit 1
  time sh -x ${SCRIPTDIR}/gcc/rundeja ${bsp} objc \
    >${LOGDIR}/${cpu}-gcctests-${bsp}.log 2>&1

  if [ $? -eq 0 ] ; then
    j_process_results "Objective-C" gcc/testsuite/objc/objc
  fi

  cd .. || exit 1
else
  echo Skipping Objective-C Tests for ${cpu}
fi

if [ ${do_ada} = "yes" ] ; then 
  test ${do_cleanup} = "yes" && rm -rf ${BUILDDIR}/b-${cpu}-ada
fi

##### Build an Ada compiler now that we have a cross installed
j_gccada()
{
  if [ X${1} = X ] ; then
    echo Usage: $0 TARGET_CPU
    exit 1
  fi
  TARGET=${1}-rtems${RTEMS_VERSION}

  if [ ! -d ${INSTALL} ] ; then
    echo ${INSTALL} does not exist
    exit 1
  fi

  if [ ${verbose} = yes ] ; then
    echo "Cross GCC for Ada ==>" `type ${TARGET}-gcc`
  fi

  if [ ${do_ada_multilib} = yes ] ; then
     ada_multilib="--enable-multilib"
  else
     ada_multilib="--disable-multilib"
  fi

#    CFLAGS_FOR_TARGET=-B${BSP_INSTALL}/${TARGET}/${BSP_BUILT}/lib/

  ${GCCDIR}/configure \
   ${GCC_EXTRA_ARGS} \
   --enable-threads=rtems  --with-gnu-as ${ada_multilib} \
   --with-gnu-ld --disable-newlib  --verbose --with-system-zlib --disable-nls \
    CFLAGS_FOR_TARGET=-B${BSP_INSTALL}/${TARGET}/${BSP_BUILT}/lib/ \
    --enable-version-specific-runtime-libs \
    --enable-languages=c,ada --target=$TARGET --prefix=$INSTALL &&
  make ${MAKEJOBS} &&
  make install
  status=$?
  if [ $status -ne 0 ] ; then
    echo "Failed building Ada - continuing to next secondary language"
  fi
  return $status
}

ada_fail="no"
if [ ${do_ada} = "yes" ] ; then 
  echo "Building Stage 2 cross Ada compiler for ${1} ..."
  (cd ${BASEDIR} && \
   rm -rf ${BUILDDIR}/b-${cpu}-ada && \
   mkdir  ${BUILDDIR}/b-${cpu}-ada && \
   cd ${BUILDDIR}/b-${cpu}-ada && \
   time j_gccada ${cpu} >${LOGDIR}/${cpu}-ada.log 2>&1 && cd ..) || \
    ada_fail="yes"
else
  echo Skipping Stage 2 Ada for ${cpu}
fi

#### Run the Ada ACATS tests
if [ ${run_acats} = "yes" -a \
     -d ${BUILDDIR}/b-${cpu}-ada -a ${ada_fail} = "no" ] ; then 
  echo "Running ACATS..."
  cd ${GCCDIR}/gcc/testsuite/ada/acats/ || exit 1

  time ${ADASCRIPTDIR}/run_all_rtems.sh ${INSTALL} ${BSP_INSTALL} \
    ${TARGET} ${bsp} >${LOGDIR}/${cpu}-acats-${bsp}-build.log 2>&1
  if [ $? -eq 0 ] ; then
    if [ -r work-${bsp}/acats.log ] ; then
      cp work-${bsp}/acats.log ${LOGDIR}/${cpu}-acats-${bsp}.log
    fi

    if [ ${do_mail} = "yes" ] ; then
      echo Sending ACATS test results to GCC community..
      ${ADASCRIPTDIR}/rtems_generate_acats_email ${cpu} ${bsp} yes
    fi
  fi

  cd ../../../../.. || exit 1
else
  echo Skipping ACATS for ${cpu}
fi

if [ ${do_ada} = "yes" ] ; then 
  test ${do_cleanup} = "yes" && rm -rf ${BUILDDIR}/b-${cpu}-ada
fi

##### Build a GCC Go compiler now that we have a cross installed
j_gccgo()
{
  if [ X${1} = X ] ; then
    echo Usage: $0 TARGET_CPU
    exit 1
  fi
  TARGET=${1}-rtems${RTEMS_VERSION}

  if [ ! -d ${INSTALL} ] ; then
    echo ${INSTALL} does not exist
    exit 1
  fi

  if [ ${verbose} = yes ] ; then
    echo "Cross GCC ==>" `type ${TARGET}-gcc`
  fi

  if [ ${do_gccgo_multilib} = yes ] ; then
     gccgo_multilib="--enable-multilib"
  else
     gccgo_multilib="--disable-multilib"
  fi

  case ${TARGET} in
    i386*) GOFLAGS="-march=i486" ;;
    *)     GOFLAGS="" ;;
  esac
#    CFLAGS_FOR_TARGET=-B${BSP_INSTALL}/${TARGET}/${BSP_BUILT}/lib/

  ${GCCDIR}/configure \
   ${GCC_EXTRA_ARGS} \
   CFLAGS_FOR_TARGET="-B${BSP_INSTALL}/${TARGET}/${BSP_BUILT}/lib/ ${GOFLAGS}" \
     --enable-threads=rtems --with-gnu-as ${gccgo_multilib} \
     --with-gnu-ld --disable-newlib  --verbose \
     --with-system-zlib --disable-nls \
     --enable-version-specific-runtime-libs \
     --with-host-libstdcxx=-static-libstdc++ \
     --enable-languages=c,go --target=$TARGET --prefix=$INSTALL &&
  make ${MAKEJOBS} &&
  make install
  status=$?
  if [ $status -ne 0 ] ; then
    echo "Failed building Go - continuing to next secondary language"
  fi
  return $status
}

go_fail="no"
if [ ${do_gccgo} = "yes" ] ; then 
  echo "Building Stage 2 cross GCC Go compiler for ${1} ..."
  (cd ${BASEDIR} && \
   rm -rf ${BUILDDIR}/b-${cpu}-go && \
   mkdir  ${BUILDDIR}/b-${cpu}-go && \
   cd ${BUILDDIR}/b-${cpu}-go && \
   time j_gccgo ${cpu} >${LOGDIR}/${cpu}-go.log 2>&1 && cd ..) || \
     go_fail="yes"
else
  echo Skipping GCC Go for ${cpu}
fi

##### Do the gccgo tests
if [ $a ${run_gccgotests} = "yes" -a \
     -d ${BUILDDIR}/b-${cpu}-go -a ${go_fail} = "no" ] ; then
  echo "Running GCC Go Tests..."
  cd ${BUILDDIR}/b-${cpu}-go/gcc || exit 1
  time sh -x ${SCRIPTDIR}/gcc/rundeja ${bsp} gccgo \
    >${LOGDIR}/${cpu}-gccgotests-${bsp}.log 2>&1

  if [ $? -eq 0 ] ; then
    j_process_results "Go" testsuite/go/go
  fi
  cd .. || exit 1
else
  echo Skipping GCC Go DejaGNU tests for ${cpu}/${bsp}
fi

##### Do the libgo tests
if [ $a ${run_libgotests} = "yes" -a \
     -d ${BUILDDIR}/b-${cpu}-go -a ${go_fail} = "no" ] ; then
  echo "Running libgo DejaGNU tests..."
  cd ${BUILDDIR}/b-${cpu}-go || exit 1
  time sh -x ${SCRIPTDIR}/gcc/rundeja ${bsp} libgo \
    >${LOGDIR}/${cpu}-libgotests-${bsp}.log 2>&1

  if [ $? -eq 0 ] ; then
    j_process_results "Go Library" ${TARGET}/libgo/testsuite/libgo-all
  fi
else
  echo Skipping libgo DejaGNU tests for ${cpu}/${bsp}
fi

if [ ${do_gccgo} = "yes" ] ; then 
  test ${do_cleanup} = "yes" && rm -rf ${BUILDDIR}/b-${cpu}-go
fi

##### Build a GCJ compiler now that we have a cross installed
j_gcj()
{
  if [ X${1} = X ] ; then
    echo Usage: $0 TARGET_CPU
    exit 1
  fi
  TARGET=${1}-rtems${RTEMS_VERSION}

  if [ ! -d ${INSTALL} ] ; then
    echo ${INSTALL} does not exist
    exit 1
  fi

  if [ ${verbose} = yes ] ; then
    echo "Cross GCC ==>" `type ${TARGET}-gcc`
  fi

  if [ ${do_gcj_multilib} = yes ] ; then
     gcj_multilib="--enable-multilib"
  else
     gcj_multilib="--disable-multilib"
  fi

  case ${TARGET} in
    i386*) GOFLAGS="-march=i486" ;;
    *)     GOFLAGS="" ;;
  esac
#    CFLAGS_FOR_TARGET=-B${BSP_INSTALL}/${TARGET}/${BSP_BUILT}/lib/

  ${GCCDIR}/configure \
   ${GCC_EXTRA_ARGS} \
   CFLAGS_FOR_TARGET="-B${BSP_INSTALL}/${TARGET}/${BSP_BUILT}/lib/ ${GOFLAGS}" \
     --enable-threads=rtems --with-gnu-as ${gcj_multilib} \
     --with-gnu-ld --disable-newlib  --verbose \
     --with-system-zlib --disable-nls \
     --enable-version-specific-runtime-libs \
     --with-host-libstdcxx=-static-libstdc++ \
     --enable-languages=c,c++,java --target=$TARGET --prefix=$INSTALL &&
  make ${MAKEJOBS} &&
  make install
  status=$?
  if [ $status -ne 0 ] ; then
    echo "Failed building GCJ - continuing to next secondary language"
  fi
  return $status
}

gcj_fail="no"
if [ ${do_gcj} = "yes" ] ; then 
  echo "Building Stage 2 cross GCC Java compiler for ${1} ..."
  (cd ${BASEDIR} && \
   rm -rf b-${cpu}-gcj && \
   mkdir  b-${cpu}-gcj && \
   cd b-${cpu}-gcj && \
   time j_gcj ${cpu} >${LOGDIR}/${cpu}-gcj.log 2>&1 && cd ..) || \
     gcj_fail="yes"
else
  echo Skipping GCC Java compiler for ${cpu}
fi

##### Do the libjava tests
if [ $a ${run_libjavatests} = "yes" -a \
     -d ${BASEDIR}/b-${cpu}-gcj -a ${gcj_fail} = "no" ] ; then
  echo "Running libjava DejaGNU tests..."
  cd ${BASEDIR}/b-${cpu}-gcj || exit 1
  time sh -x ${SCRIPTDIR}/gcc/rundeja ${bsp} java \
    >${LOGDIR}/${cpu}-libjavatests-${bsp}.log 2>&1

  if [ $? -eq 0 ] ; then
    j_process_results "GCJ" ${TARGET}-${bsp}/libjava/testsuite/libjava-all
  fi
else
  echo Skipping libjava DejaGNU tests for ${cpu}/${bsp}
fi

if [ ${do_gcj} = "yes" ] ; then 
  test ${do_cleanup} = "yes" && rm -rf b-${cpu}-gcj
fi

##### Build a FORTRAN compiler now that we have a cross installed
j_fortran()
{
  if [ X${1} = X ] ; then
    echo Usage: $0 TARGET_CPU
    exit 1
  fi
  TARGET=${1}-rtems${RTEMS_VERSION}

  if [ ! -d ${INSTALL} ] ; then
    echo ${INSTALL} does not exist
    exit 1
  fi

  ${GCCDIR}/configure \
   ${GCC_EXTRA_ARGS} \
   CFLAGS_FOR_TARGET="-B${BSP_INSTALL}/${TARGET}/${BSP_BUILT}/lib/ ${F_FLAGS}" \
     --with-ppl=/users/joel/test-gcc/install-svn/ \
     --enable-threads=rtems --with-gnu-as \
     --with-gnu-ld --disable-newlib  --verbose \
     --with-system-zlib --disable-nls \
     --enable-version-specific-runtime-libs \
     --enable-languages=c,fortran --target=$TARGET --prefix=$INSTALL && \
  make ${MAKEJOBS} &&
  make install
  status=$?
  if [ $status -ne 0 ] ; then
    echo "Failed building FORTRAN - continuing to next secondary language"
  fi
  return $status
}

fortran_fail="no"
if [ ${do_fortran} = "yes" ] ; then 
  echo "Building Stage 2 cross GCC FORTRAN compiler for ${1} ..."
  (cd ${BASEDIR} && \
   rm -rf b-${cpu}-fortran && \
   mkdir  b-${cpu}-fortran && \
   cd b-${cpu}-fortran && \
   time j_fortran ${cpu} >${LOGDIR}/${cpu}-fortran.log 2>&1 && cd ..) || \
     fortran_fail="yes"
else
  echo Skipping GCC FORTRAN compiler for ${cpu}
fi

##### Do the FORTRAN tests
if [ $a ${run_fortrantests} = "yes" -a \
     -d ${BASEDIR}/b-${cpu}-fortran -a ${fortran_fail} = "no" ] ; then
  echo "Running FORTRAN DejaGNU tests..."
  cd ${BASEDIR}/b-${cpu}-fortran || exit 1
  time sh -x ${SCRIPTDIR}/gcc/rundeja ${bsp} fortran \
    >${LOGDIR}/${cpu}-fortrantests-${bsp}.log 2>&1

  if [ $? -eq 0 ] ; then
    j_process_results "FORTRAN" gcc/testsuite/gfortran/gfortran
  fi
else
  echo Skipping FORTRAN DejaGNU tests for ${cpu}/${bsp}
fi

if [ ${do_fortran} = "yes" ] ; then 
  test ${do_cleanup} = "yes" && rm -rf b-${cpu}-fortran
fi



exit 0