1495069e4df9785b1d6fb45971ca20479057b4558Bill Wendling#!/usr/bin/env bash
2b91c71299a819e2d20786b629376f119085e8b28Bill Wendling#===-- test-release.sh - Test the LLVM release candidates ------------------===#
3b91c71299a819e2d20786b629376f119085e8b28Bill Wendling#
4b91c71299a819e2d20786b629376f119085e8b28Bill Wendling#                     The LLVM Compiler Infrastructure
5b91c71299a819e2d20786b629376f119085e8b28Bill Wendling#
6b91c71299a819e2d20786b629376f119085e8b28Bill Wendling# This file is distributed under the University of Illinois Open Source
7b91c71299a819e2d20786b629376f119085e8b28Bill Wendling# License.
8b91c71299a819e2d20786b629376f119085e8b28Bill Wendling#
9b91c71299a819e2d20786b629376f119085e8b28Bill Wendling#===------------------------------------------------------------------------===#
10b91c71299a819e2d20786b629376f119085e8b28Bill Wendling#
11b91c71299a819e2d20786b629376f119085e8b28Bill Wendling# Download, build, and test the release candidate for an LLVM release.
12b91c71299a819e2d20786b629376f119085e8b28Bill Wendling#
13b91c71299a819e2d20786b629376f119085e8b28Bill Wendling#===------------------------------------------------------------------------===#
14b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
15783993e79502641d4f2ec82f3db78320b6837f4eBill Wendlingif [ `uname -s` = "FreeBSD" ]; then
16783993e79502641d4f2ec82f3db78320b6837f4eBill Wendling    MAKE=gmake
17783993e79502641d4f2ec82f3db78320b6837f4eBill Wendlingelse
18783993e79502641d4f2ec82f3db78320b6837f4eBill Wendling    MAKE=make
19783993e79502641d4f2ec82f3db78320b6837f4eBill Wendlingfi
20783993e79502641d4f2ec82f3db78320b6837f4eBill Wendling
2141adc5fb8bd0d81f07d93754868bd9f27b6fd9afBill Wendlingprojects="llvm cfe dragonegg test-suite"
221416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling
231416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling# Base SVN URL for the sources.
241416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill WendlingBase_url="http://llvm.org/svn/llvm-project"
251416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling
26b91c71299a819e2d20786b629376f119085e8b28Bill WendlingRelease=""
27b91c71299a819e2d20786b629376f119085e8b28Bill WendlingRelease_no_dot=""
28b91c71299a819e2d20786b629376f119085e8b28Bill WendlingRC=""
29b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingdo_checkout="yes"
30b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingdo_ada="no"
31c248bbab04cb674bde5de8d6e2b2736a574fa0f8Bill Wendlingdo_objc="yes"
321416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendlingdo_fortran="no"
33b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingdo_64bit="yes"
341416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendlingdo_debug="no"
35a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendlingdo_asserts="no"
36b91c71299a819e2d20786b629376f119085e8b28Bill WendlingBuildDir="`pwd`"
37b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
38b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingfunction usage() {
39b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo "usage: `basename $0` -release X.Y -rc NUM [OPTIONS]"
40b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo ""
41b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo " -release X.Y      The release number to test."
42b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo " -rc NUM           The pre-release candidate number."
43b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo " -j NUM            Number of compile jobs to run. [default: 3]"
44b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo " -build-dir DIR    Directory to perform testing in. [default: pwd]"
45b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo " -no-checkout      Don't checkout the sources from SVN."
46b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo " -no-64bit         Don't test the 64-bit version. [default: yes]"
47e7e9a60df6ea92460337569e24746f390cbd56e3Bill Wendling    echo " -enable-ada       Build Ada. [default: disable]"
481416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    echo " -enable-fortran   Enable Fortran build. [default: disable]"
49e7e9a60df6ea92460337569e24746f390cbd56e3Bill Wendling    echo " -disable-objc     Disable ObjC build. [default: enable]"
501416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    echo " -test-debug       Test the debug build. [default: no]"
51a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    echo " -test-asserts     Test with asserts on. [default: no]"
52b91c71299a819e2d20786b629376f119085e8b28Bill Wendling}
53b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
54b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingwhile [ $# -gt 0 ]; do
55b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    case $1 in
56b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        -release | --release )
57b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            shift
58b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            Release="$1"
59b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            Release_no_dot="`echo $1 | sed -e 's,\.,,'`"
60b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            ;;
61b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        -rc | --rc | -RC | --RC )
62b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            shift
63b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            RC=$1
64b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            ;;
65b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        -j* )
66b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
67b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            if [ -z "$NumJobs" ]; then
68b91c71299a819e2d20786b629376f119085e8b28Bill Wendling                shift
69b91c71299a819e2d20786b629376f119085e8b28Bill Wendling                NumJobs="$1"
70b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            fi
71b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            ;;
72b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        -build-dir | --build-dir | -builddir | --builddir )
73b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            shift
74b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            BuildDir="$1"
75b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            ;;
76b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        -no-checkout | --no-checkout )
77b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            do_checkout="no"
78b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            ;;
79b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        -no-64bit | --no-64bit )
80b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            do_64bit="no"
81b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            ;;
82e7e9a60df6ea92460337569e24746f390cbd56e3Bill Wendling        -enable-ada | --enable-ada )
83b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            do_ada="yes"
84b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            ;;
851416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        -enable-fortran | --enable-fortran )
861416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling            do_fortran="yes"
871416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling            ;;
88c248bbab04cb674bde5de8d6e2b2736a574fa0f8Bill Wendling        -disable-objc | --disable-objc )
89c248bbab04cb674bde5de8d6e2b2736a574fa0f8Bill Wendling            do_objc="no"
90c248bbab04cb674bde5de8d6e2b2736a574fa0f8Bill Wendling            ;;
911416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        -test-debug | --test-debug )
921416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling            do_debug="yes"
93b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            ;;
94a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling        -test-asserts | --test-asserts )
95a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling            do_asserts="yes"
96a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling            ;;
97b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        -help | --help | -h | --h | -\? )
98b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            usage
99b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            exit 0
100b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            ;;
101b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        * )
102b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            echo "unknown option: $1"
103b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            usage
104b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            exit 1
105b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            ;;
106b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    esac
107b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    shift
108b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingdone
109b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
110b91c71299a819e2d20786b629376f119085e8b28Bill Wendling# Check required arguments.
111b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingif [ -z "$Release" ]; then
1121416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    echo "error: no release number specified"
113b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    exit 1
114b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingfi
115b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingif [ -z "$RC" ]; then
1161416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    echo "error: no release candidate number specified"
117b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    exit 1
118b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingfi
119b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
120d357d747ded75c3eae9238f23e1c05d621d915e8Duncan Sands# Figure out how many make processes to run.
121d357d747ded75c3eae9238f23e1c05d621d915e8Duncan Sandsif [ -z "$NumJobs" ]; then
122d357d747ded75c3eae9238f23e1c05d621d915e8Duncan Sands    NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
123d357d747ded75c3eae9238f23e1c05d621d915e8Duncan Sandsfi
124d357d747ded75c3eae9238f23e1c05d621d915e8Duncan Sandsif [ -z "$NumJobs" ]; then
125d357d747ded75c3eae9238f23e1c05d621d915e8Duncan Sands    NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
126d357d747ded75c3eae9238f23e1c05d621d915e8Duncan Sandsfi
127d357d747ded75c3eae9238f23e1c05d621d915e8Duncan Sandsif [ -z "$NumJobs" ]; then
128d357d747ded75c3eae9238f23e1c05d621d915e8Duncan Sands    NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
129d357d747ded75c3eae9238f23e1c05d621d915e8Duncan Sandsfi
130b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingif [ -z "$NumJobs" ]; then
131b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    NumJobs=3
132b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingfi
133b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
1341416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling# Go to the build directory (may be different from CWD)
1351416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill WendlingBuildDir=$BuildDir/rc$RC
1361416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendlingmkdir -p $BuildDir
1371416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendlingcd $BuildDir
138b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
139f0bf9dfc1f7755a6233e41fd6f259c4ee08a40dcDuncan Sands# Location of log files.
1401416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill WendlingLogDir=$BuildDir/logs
141f0bf9dfc1f7755a6233e41fd6f259c4ee08a40dcDuncan Sandsmkdir -p $LogDir
142f0bf9dfc1f7755a6233e41fd6f259c4ee08a40dcDuncan Sands
1431416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling# Find a compilers.
144250c6801e4e16e4118fc130dff94dc89ea9332f1Bill Wendlingc_compiler="$CC"
145250c6801e4e16e4118fc130dff94dc89ea9332f1Bill Wendlingcxx_compiler="$CXX"
146b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
147b91c71299a819e2d20786b629376f119085e8b28Bill Wendling# Make sure that the URLs are valid.
148b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingfunction check_valid_urls() {
1491416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    for proj in $projects ; do
1501416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        echo "# Validating $proj SVN URL"
1511416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling
152540d5b7406a9aeb75492adfa58f0b5b4a2b9442aBill Wendling        if ! svn ls $Base_url/$proj/tags/RELEASE_$Release_no_dot/rc$RC > /dev/null 2>&1 ; then
1531416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling            echo "llvm $Release release candidate $RC doesn't exist!"
1541416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling            exit 1
1551416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        fi
1561416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    done
157b91c71299a819e2d20786b629376f119085e8b28Bill Wendling}
158b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
159b91c71299a819e2d20786b629376f119085e8b28Bill Wendling# Export sources to the the build directory.
160b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingfunction export_sources() {
161b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    check_valid_urls
162b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
1631416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    for proj in $projects ; do
1641416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        echo "# Exporting $proj $Release-RC$RC sources"
1651416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        if ! svn export -q $Base_url/$proj/tags/RELEASE_$Release_no_dot/rc$RC $proj.src ; then
1661416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling            echo "error: failed to export $proj project"
1671416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling            exit 1
1681416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        fi
1691416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    done
1701416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling
1711416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    echo "# Creating symlinks"
1721416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    cd $BuildDir/llvm.src/tools
1731416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    if [ ! -h clang ]; then
1741416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        ln -s $BuildDir/cfe.src clang
1751416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    fi
1761416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    cd $BuildDir/llvm.src/projects
1771416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    if [ ! -h llvm-test ]; then
1781416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        ln -s $BuildDir/test-suite.src llvm-test
1791416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    fi
1801416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    cd $BuildDir
181b91c71299a819e2d20786b629376f119085e8b28Bill Wendling}
182b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
183b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingfunction configure_llvmCore() {
184b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    Phase="$1"
185b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    Flavor="$2"
186b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    ObjDir="$3"
187b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    InstallDir="$4"
188b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
189b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    case $Flavor in
190b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        Release | Release-64 )
191b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            Optimized="yes"
1928a6e53e1162663dd2bc1da783fe2ff5947fba9e0Duncan Sands            Assertions="no"
193b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            ;;
1948a6e53e1162663dd2bc1da783fe2ff5947fba9e0Duncan Sands        Release+Asserts )
195b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            Optimized="yes"
1968a6e53e1162663dd2bc1da783fe2ff5947fba9e0Duncan Sands            Assertions="yes"
197b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            ;;
198b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        Debug )
199b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            Optimized="no"
200b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            Assertions="yes"
201b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            ;;
202b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        * )
2031416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling            echo "# Invalid flavor '$Flavor'"
204b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            echo ""
205b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            return
206b91c71299a819e2d20786b629376f119085e8b28Bill Wendling            ;;
207b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    esac
208b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
2091416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    echo "# Using C compiler: $c_compiler"
2101416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    echo "# Using C++ compiler: $cxx_compiler"
2111416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling
212b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    cd $ObjDir
213b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo "# Configuring llvm $Release-rc$RC $Flavor"
2141416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    echo "# $BuildDir/llvm.src/configure --prefix=$InstallDir \
215b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        --enable-optimized=$Optimized \
2161416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        --enable-assertions=$Assertions"
2171416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    env CC=$c_compiler CXX=$cxx_compiler \
2181416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    $BuildDir/llvm.src/configure --prefix=$InstallDir \
219b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        --enable-optimized=$Optimized \
220b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        --enable-assertions=$Assertions \
2211416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
2221416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    cd $BuildDir
223b91c71299a819e2d20786b629376f119085e8b28Bill Wendling}
224b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
225b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingfunction build_llvmCore() {
226b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    Phase="$1"
227b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    Flavor="$2"
228b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    ObjDir="$3"
229b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    ExtraOpts=""
230b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
231b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    if [ "$Flavor" = "Release-64" ]; then
232b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        ExtraOpts="EXTRA_OPTIONS=-m64"
233b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    fi
234b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
235b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    cd $ObjDir
236b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo "# Compiling llvm $Release-rc$RC $Flavor"
237783993e79502641d4f2ec82f3db78320b6837f4eBill Wendling    echo "# ${MAKE} -j $NumJobs VERBOSE=1 $ExtraOpts"
238783993e79502641d4f2ec82f3db78320b6837f4eBill Wendling    ${MAKE} -j $NumJobs VERBOSE=1 $ExtraOpts \
2391416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
240b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
241b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo "# Installing llvm $Release-rc$RC $Flavor"
242783993e79502641d4f2ec82f3db78320b6837f4eBill Wendling    echo "# ${MAKE} install"
243783993e79502641d4f2ec82f3db78320b6837f4eBill Wendling    ${MAKE} install \
2441416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
2451416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    cd $BuildDir
246b91c71299a819e2d20786b629376f119085e8b28Bill Wendling}
247b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
248b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingfunction test_llvmCore() {
249b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    Phase="$1"
250b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    Flavor="$2"
251b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    ObjDir="$3"
252b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
253b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    cd $ObjDir
254783993e79502641d4f2ec82f3db78320b6837f4eBill Wendling    ${MAKE} -k check-all \
2551416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log
256783993e79502641d4f2ec82f3db78320b6837f4eBill Wendling    ${MAKE} -k unittests \
25741adc5fb8bd0d81f07d93754868bd9f27b6fd9afBill Wendling        2>&1 | tee $LogDir/llvm.unittests-Phase$Phase-$Flavor.log
2581416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    cd $BuildDir
259b91c71299a819e2d20786b629376f119085e8b28Bill Wendling}
260b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
261630243a8c2d40df137b64246b7ed4363962fd9b4Bill Wendlingset -e                          # Exit if any command fails
262630243a8c2d40df137b64246b7ed4363962fd9b4Bill Wendling
263b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingif [ "$do_checkout" = "yes" ]; then
264b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    export_sources
265b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingfi
266b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
267f0bf9dfc1f7755a6233e41fd6f259c4ee08a40dcDuncan Sands(
268a854f5d6f9394212319f4e00b6396900f6e62864Bill WendlingFlavors="Release"
2691416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendlingif [ "$do_debug" = "yes" ]; then
2701416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    Flavors="Debug $Flavors"
2711416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendlingfi
272a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendlingif [ "$do_asserts" = "yes" ]; then
273a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    Flavors="$Flavors Release+Asserts"
274a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendlingfi
275b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingif [ "$do_64bit" = "yes" ]; then
276b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    Flavors="$Flavors Release-64"
277b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingfi
278b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
279b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingfor Flavor in $Flavors ; do
280b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo ""
281b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo ""
282b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo "********************************************************************************"
283b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo "  Release:     $Release-rc$RC"
284b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo "  Build:       $Flavor"
285b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo "  System Info: "
286b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo "    `uname -a`"
287b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo "********************************************************************************"
288b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo ""
289b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
290b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-rc$RC.obj
291b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    llvmCore_phase1_installdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-rc$RC.install
292b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
293b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-rc$RC.obj
294b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    llvmCore_phase2_installdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-rc$RC.install
295b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
296a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-rc$RC.obj
297a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    llvmCore_phase3_installdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-rc$RC.install
298a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling
299b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    rm -rf $llvmCore_phase1_objdir
300b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    rm -rf $llvmCore_phase1_installdir
301b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    rm -rf $llvmCore_phase2_objdir
302b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    rm -rf $llvmCore_phase2_installdir
303a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    rm -rf $llvmCore_phase3_objdir
304a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    rm -rf $llvmCore_phase3_installdir
305b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
306b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    mkdir -p $llvmCore_phase1_objdir
307b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    mkdir -p $llvmCore_phase1_installdir
308b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    mkdir -p $llvmCore_phase2_objdir
309b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    mkdir -p $llvmCore_phase2_installdir
310a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    mkdir -p $llvmCore_phase3_objdir
311a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    mkdir -p $llvmCore_phase3_installdir
312b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
313b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    ############################################################################
314b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    # Phase 1: Build llvmCore and llvmgcc42
315b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo "# Phase 1: Building llvmCore"
316b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    configure_llvmCore 1 $Flavor \
3171416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        $llvmCore_phase1_objdir $llvmCore_phase1_installdir
318b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    build_llvmCore 1 $Flavor \
319b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        $llvmCore_phase1_objdir
320b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
321b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    ############################################################################
3221416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    # Phase 2: Build llvmCore with newly built clang from phase 1.
3231416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    c_compiler=$llvmCore_phase1_installdir/bin/clang
3241416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    cxx_compiler=$llvmCore_phase1_installdir/bin/clang++
325b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    echo "# Phase 2: Building llvmCore"
326b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    configure_llvmCore 2 $Flavor \
3271416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling        $llvmCore_phase2_objdir $llvmCore_phase2_installdir
328b91c71299a819e2d20786b629376f119085e8b28Bill Wendling    build_llvmCore 2 $Flavor \
329b91c71299a819e2d20786b629376f119085e8b28Bill Wendling        $llvmCore_phase2_objdir
330b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
331a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    ############################################################################
332a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    # Phase 3: Build llvmCore with newly built clang from phase 2.
333a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    c_compiler=$llvmCore_phase2_installdir/bin/clang
334a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    cxx_compiler=$llvmCore_phase2_installdir/bin/clang++
335a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    echo "# Phase 3: Building llvmCore"
336a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    configure_llvmCore 3 $Flavor \
337a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling        $llvmCore_phase3_objdir $llvmCore_phase3_installdir
338a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    build_llvmCore 3 $Flavor \
339a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling        $llvmCore_phase3_objdir
340a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling
341a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    ############################################################################
342a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    # Testing: Test phase 3
3431416dc29d8573e58c8b2d7fe0715f3e289d03ab8Bill Wendling    echo "# Testing - built with clang"
344a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
345a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling
346a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    ############################################################################
347a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    # Compare .o files between Phase2 and Phase3 and report which ones differ.
348a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    echo
349a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    echo "# Comparing Phase 2 and Phase 3 files"
350a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    for o in `find $llvmCore_phase2_objdir -name '*.o'` ; do
351a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling        p3=`echo $o | sed -e 's,Phase2,Phase3,'`
352a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling        if ! cmp --ignore-initial=16 $o $p3 > /dev/null 2>&1 ; then
353a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling            echo "file `basename $o` differs between phase 2 and phase 3"
354a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling        fi
355a854f5d6f9394212319f4e00b6396900f6e62864Bill Wendling    done
356b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingdone
357f0bf9dfc1f7755a6233e41fd6f259c4ee08a40dcDuncan Sands) 2>&1 | tee $LogDir/testing.$Release-rc$RC.log
358b91c71299a819e2d20786b629376f119085e8b28Bill Wendling
359630243a8c2d40df137b64246b7ed4363962fd9b4Bill Wendlingset +e
360630243a8c2d40df137b64246b7ed4363962fd9b4Bill Wendling
361b91c71299a819e2d20786b629376f119085e8b28Bill Wendling# Woo hoo!
362b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingecho "### Testing Finished ###"
363f0bf9dfc1f7755a6233e41fd6f259c4ee08a40dcDuncan Sandsecho "### Logs: $LogDir"
364b91c71299a819e2d20786b629376f119085e8b28Bill Wendlingexit 0
365