Added two scripts to aid with building Linux/x86 -> Linux/ARM crosstools, using

CodeSourcery's provided GCC-based crosstools, from which we use binutils.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73212 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Misha Brukman 2009-06-12 01:55:57 +00:00
parent 0b389b54c9
commit cb6f9c8aae
2 changed files with 235 additions and 0 deletions

View File

@ -0,0 +1,194 @@
#!/bin/bash
#
# Compiles and installs a Linux/x86_64 -> Linux/ARM crosstool based on LLVM and
# LLVM-GCC-4.2 using SVN snapshots in provided tarballs.
set -o nounset
set -o errexit
echo -n "Welcome to LLVM Linux/X86_64 -> Linux/ARM crosstool "
echo "builder/installer; some steps will require sudo privileges."
readonly INSTALL_ROOT="${INSTALL_ROOT:-/usr/local}"
# Both $USER and root *must* have read/write access to this dir.
readonly SCRATCH_ROOT=$(mktemp -d "${TMPDIR:-/tmp}/llvm-project.XXXXXX")
readonly SRC_ROOT="${SCRATCH_ROOT}/src"
readonly OBJ_ROOT="${SCRATCH_ROOT}/obj"
readonly CROSS_HOST="x86_64-unknown-linux-gnu"
readonly CROSS_TARGET="arm-none-linux-gnueabi"
readonly CODE_SOURCERY="${INSTALL_ROOT}/codesourcery"
readonly CODE_SOURCERY_PKG_PATH="${CODE_SOURCERY_PKG_PATH:-${HOME}/codesourcery}"
readonly CODE_SOURCERY_PKG="arm-2007q3-51-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2"
readonly CODE_SOURCERY_ROOT="${CODE_SOURCERY}/arm-2007q3"
readonly CODE_SOURCERY_BIN="${CODE_SOURCERY_ROOT}/bin"
# Make sure ${CROSS_TARGET}-* binutils are in command path
export PATH="${CODE_SOURCERY_BIN}:${PATH}"
readonly CROSS_TARGET_AS="${CODE_SOURCERY_BIN}/${CROSS_TARGET}-as"
readonly CROSS_TARGET_LD="${CODE_SOURCERY_BIN}/${CROSS_TARGET}-ld"
readonly SYSROOT="${CODE_SOURCERY_ROOT}/${CROSS_TARGET}/libc"
readonly LLVM_PROJECT="${INSTALL_ROOT}/llvm-project"
readonly LLVM_INSTALL_ROOT="${LLVM_PROJECT}/${CROSS_HOST}/${CROSS_TARGET}"
readonly LLVM_PKG_PATH="${LLVM_PKG_PATH:-${HOME}/llvm-project/snapshots}"
# Latest SVN revision known to be working in this configuration.
readonly LLVM_DEFAULT_REV="70786"
readonly LLVM_PKG="llvm-${LLVM_SVN_REV:-${LLVM_DEFAULT_REV}}.tar.bz2"
readonly LLVM_SRC_DIR="${SRC_ROOT}/llvm"
readonly LLVM_OBJ_DIR="${OBJ_ROOT}/llvm"
readonly LLVM_INSTALL_DIR="${LLVM_INSTALL_ROOT}/llvm"
readonly LLVMGCC_PKG="llvm-gcc-4.2-${LLVMGCC_SVN_REV:-${LLVM_DEFAULT_REV}}.tar.bz2"
readonly LLVMGCC_SRC_DIR="${SRC_ROOT}/llvm-gcc-4.2"
readonly LLVMGCC_OBJ_DIR="${OBJ_ROOT}/llvm-gcc-4.2"
readonly LLVMGCC_INSTALL_DIR="${LLVM_INSTALL_ROOT}/llvm-gcc-4.2"
readonly MAKE_OPTS="-j2"
# Verify we aren't going to install into an existing directory as this might
# create problems as we won't have a clean install.
verifyNotDir() {
if [[ -d $1 ]]; then
echo "Install dir $1 already exists; remove it to continue."
exit
fi
}
# Params:
# $1: directory to be created
# $2: optional mkdir command prefix, e.g. "sudo"
createDir() {
if [[ ! -e $1 ]]; then
${2:-} mkdir -p $1
elif [[ -e $1 && ! -d $1 ]]; then
echo "$1 exists but is not a directory; exiting."
exit 3
fi
}
sudoCreateDir() {
createDir $1 sudo
sudo chown ${USER} $1
}
# Prints out and runs the command, but without logging -- intended for use with
# lightweight commands that don't have useful output to parse, e.g. mkdir, tar,
# etc.
runCommand() {
local message="$1"
shift
echo "=> $message"
echo "==> Running: $*"
$*
}
runAndLog() {
local message="$1"
local log_file="$2"
shift 2
echo "=> $message; log in $log_file"
echo "==> Running: $*"
# Pop-up a terminal with the output of the current command?
# e.g.: xterm -e /bin/bash -c "$* >| tee $log_file"
$* &> $log_file
if [[ $? != 0 ]]; then
echo "Error occurred: see most recent log file for details."
exit
fi
}
installCodeSourcery() {
# Create CodeSourcery dir, if necessary.
verifyNotDir ${CODE_SOURCERY}
sudoCreateDir ${CODE_SOURCERY}
# Unpack the tarball.
if [[ ! -d ${CODE_SOURCERY_ROOT} ]]; then
cd ${CODE_SOURCERY}
runCommand "Unpacking CodeSourcery in ${CODE_SOURCERY}" \
tar jxf ${CODE_SOURCERY_PKG_PATH}/${CODE_SOURCERY_PKG}
else
echo "CodeSourcery install dir already exists."
fi
# Verify our CodeSourcery toolchain installation.
if [[ ! -d "${SYSROOT}" ]]; then
echo -n "Error: CodeSourcery does not contain libc for ${CROSS_TARGET}: "
echo "${SYSROOT} not found."
exit
fi
for tool in ${CROSS_TARGET_AS} ${CROSS_TARGET_LD}; do
if [[ ! -e $tool ]]; then
echo "${tool} not found; exiting."
exit
fi
done
}
installLLVM() {
verifyNotDir ${LLVM_INSTALL_DIR}
sudoCreateDir ${LLVM_INSTALL_DIR}
# Unpack LLVM tarball; should create the directory "llvm".
cd ${SRC_ROOT}
runCommand "Unpacking LLVM" tar jxf ${LLVM_PKG_PATH}/${LLVM_PKG}
# Configure, build, and install LLVM.
createDir ${LLVM_OBJ_DIR}
cd ${LLVM_OBJ_DIR}
runAndLog "Configuring LLVM" ${LLVM_OBJ_DIR}/llvm-configure.log \
${LLVM_SRC_DIR}/configure \
--disable-jit \
--enable-optimized \
--prefix=${LLVM_INSTALL_DIR} \
--target=${CROSS_TARGET} \
--with-llvmgccdir=${LLVMGCC_INSTALL_DIR}
runAndLog "Building LLVM" ${LLVM_OBJ_DIR}/llvm-build.log \
make ${MAKE_OPTS}
runAndLog "Installing LLVM" ${LLVM_OBJ_DIR}/llvm-install.log \
make ${MAKE_OPTS} install
}
installLLVMGCC() {
verifyNotDir ${LLVMGCC_INSTALL_DIR}
sudoCreateDir ${LLVMGCC_INSTALL_DIR}
# Unpack LLVM-GCC tarball; should create the directory "llvm-gcc-4.2".
cd ${SRC_ROOT}
runCommand "Unpacking LLVM-GCC" tar jxf ${LLVM_PKG_PATH}/${LLVMGCC_PKG}
# Configure, build, and install LLVM-GCC.
createDir ${LLVMGCC_OBJ_DIR}
cd ${LLVMGCC_OBJ_DIR}
runAndLog "Configuring LLVM-GCC" ${LLVMGCC_OBJ_DIR}/llvmgcc-configure.log \
${LLVMGCC_SRC_DIR}/configure \
--enable-languages=c,c++ \
--enable-llvm=${LLVM_INSTALL_DIR} \
--prefix=${LLVMGCC_INSTALL_DIR} \
--program-prefix=llvm- \
--target=${CROSS_TARGET} \
--with-gnu-as=${CROSS_TARGET_AS} \
--with-gnu-ld=${CROSS_TARGET_LD} \
--with-sysroot=${SYSROOT}
runAndLog "Building LLVM-GCC" ${LLVMGCC_OBJ_DIR}/llvmgcc-build.log \
make
runAndLog "Installing LLVM-GCC" ${LLVMGCC_OBJ_DIR}/llvmgcc-install.log \
make install
}
echo "Building in ${SCRATCH_ROOT}; installing in ${INSTALL_ROOT}"
createDir ${SRC_ROOT}
createDir ${OBJ_ROOT}
installCodeSourcery
installLLVM
installLLVMGCC
echo "Done."

View File

@ -0,0 +1,41 @@
#!/bin/bash
#
# Creates LLVM SVN snapshots: llvm-$REV.tar.bz2 and llvm-gcc-4.2-$REV.tar.bz2,
# where $REV is an SVN revision of LLVM. This is used for creating stable
# tarballs which can be used to build known-to-work crosstools.
#
# Syntax:
# $0 [REV] -- grabs the revision $REV from SVN; if not specified, grabs the
# latest SVN revision.
set -o nounset
set -o errexit
readonly REV="${1:-HEAD}"
runOnModule() {
local module=$1
local log="${module}.log"
echo "Running: svn co -r ${REV} ${module}; log in ${log}"
svn co -r ${REV} http://llvm.org/svn/llvm-project/${module}/trunk ${module} \
> ${log} 2>&1
# Delete all the ".svn" dirs; they take quite a lot of space.
echo "Cleaning up .svn dirs"
find ${module} -type d -name \.svn -print0 | xargs -0 /bin/rm -rf
# Create "module-revision.tar.bz2" packages from the SVN checkout dirs.
local revision=$(grep "Checked out revision" ${log} | \
sed 's/[^0-9]\+\([0-9]\+\)[^0-9]\+/\1/')
local tarball="${module}-${revision}.tar.bz2"
echo "Creating tarball: ${tarball}"
tar cjf ${tarball} ${module}
echo "Cleaning SVN checkout dir ${module}"
rm -rf ${module} ${log}
}
for module in "llvm" "llvm-gcc-4.2"; do
runOnModule ${module}
done