3 # Compiles and installs a Linux/x86_64 -> Linux/ARM crosstool based on LLVM and
4 # LLVM-GCC-4.2 using SVN snapshots in provided tarballs.
9 echo -n "Welcome to LLVM Linux/X86_64 -> Linux/ARM crosstool "
10 echo "builder/installer; some steps will require sudo privileges."
12 readonly INSTALL_ROOT="${INSTALL_ROOT:-/usr/local}"
13 # Both $USER and root *must* have read/write access to this dir.
14 readonly SCRATCH_ROOT=$(mktemp -d "${TMPDIR:-/tmp}/llvm-project.XXXXXX")
15 readonly SRC_ROOT="${SCRATCH_ROOT}/src"
16 readonly OBJ_ROOT="${SCRATCH_ROOT}/obj"
18 readonly CROSS_HOST="x86_64-unknown-linux-gnu"
19 readonly CROSS_TARGET="arm-none-linux-gnueabi"
21 readonly CODE_SOURCERY="${INSTALL_ROOT}/codesourcery"
22 readonly CODE_SOURCERY_PKG_PATH="${CODE_SOURCERY_PKG_PATH:-${HOME}/codesourcery}"
23 readonly CODE_SOURCERY_HTTP="http://www.codesourcery.com/sgpp/lite/arm/portal/package1787/public"
24 readonly CODE_SOURCERY_PKG="arm-2007q3-51-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2"
25 readonly CODE_SOURCERY_ROOT="${CODE_SOURCERY}/arm-2007q3"
26 readonly CODE_SOURCERY_BIN="${CODE_SOURCERY_ROOT}/bin"
27 # Make sure ${CROSS_TARGET}-* binutils are in command path
28 export PATH="${CODE_SOURCERY_BIN}:${PATH}"
30 readonly CROSS_TARGET_AS="${CODE_SOURCERY_BIN}/${CROSS_TARGET}-as"
31 readonly CROSS_TARGET_LD="${CODE_SOURCERY_BIN}/${CROSS_TARGET}-ld"
33 readonly SYSROOT="${CODE_SOURCERY_ROOT}/${CROSS_TARGET}/libc"
35 readonly LLVM_PROJECT="${INSTALL_ROOT}/llvm-project"
36 readonly LLVM_INSTALL_ROOT="${LLVM_PROJECT}/${CROSS_HOST}/${CROSS_TARGET}"
37 readonly LLVM_PKG_PATH="${LLVM_PKG_PATH:-${HOME}/llvm-project/snapshots}"
39 # Latest SVN revision known to be working in this configuration.
40 readonly LLVM_DEFAULT_REV="70786"
42 readonly LLVM_PKG="llvm-${LLVM_SVN_REV:-${LLVM_DEFAULT_REV}}.tar.bz2"
43 readonly LLVM_SRC_DIR="${SRC_ROOT}/llvm"
44 readonly LLVM_OBJ_DIR="${OBJ_ROOT}/llvm"
45 readonly LLVM_INSTALL_DIR="${LLVM_INSTALL_ROOT}/llvm"
47 readonly LLVMGCC_PKG="llvm-gcc-4.2-${LLVMGCC_SVN_REV:-${LLVM_DEFAULT_REV}}.tar.bz2"
48 readonly LLVMGCC_SRC_DIR="${SRC_ROOT}/llvm-gcc-4.2"
49 readonly LLVMGCC_OBJ_DIR="${OBJ_ROOT}/llvm-gcc-4.2"
50 readonly LLVMGCC_INSTALL_DIR="${LLVM_INSTALL_ROOT}/llvm-gcc-4.2"
52 readonly MAKE_OPTS="-j2"
54 # Verify we aren't going to install into an existing directory as this might
55 # create problems as we won't have a clean install.
58 echo "Install dir $1 already exists; remove it to continue."
64 # $1: directory to be created
65 # $2: optional mkdir command prefix, e.g. "sudo"
67 if [[ ! -e $1 ]]; then
69 elif [[ -e $1 && ! -d $1 ]]; then
70 echo "$1 exists but is not a directory; exiting."
80 # Prints out and runs the command, but without logging -- intended for use with
81 # lightweight commands that don't have useful output to parse, e.g. mkdir, tar,
87 echo "==> Running: $*"
95 echo "=> $message; log in $log_file"
96 echo "==> Running: $*"
97 # Pop-up a terminal with the output of the current command?
98 # e.g.: xterm -e /bin/bash -c "$* >| tee $log_file"
100 if [[ $? != 0 ]]; then
101 echo "Error occurred: see most recent log file for details."
106 installCodeSourcery() {
107 # Create CodeSourcery dir, if necessary.
108 verifyNotDir ${CODE_SOURCERY}
109 sudoCreateDir ${CODE_SOURCERY}
111 # Unpack the tarball.
112 if [[ ! -d ${CODE_SOURCERY_ROOT} ]]; then
114 if [[ -e ${CODE_SOURCERY_PKG_PATH}/${CODE_SOURCERY_PKG} ]]; then
115 runCommand "Unpacking CodeSourcery in ${CODE_SOURCERY}" \
116 tar jxf ${CODE_SOURCERY_PKG_PATH}/${CODE_SOURCERY_PKG}
118 echo -n "CodeSourcery tarball not found in "
119 echo "${CODE_SOURCERY_PKG_PATH}/${CODE_SOURCERY_PKG}"
120 echo -n "Fix the path or download it from "
121 echo "${CODE_SOURCERY_HTTP}/${CROSS_TARGET}/${CODE_SOURCERY_PKG}"
125 echo "CodeSourcery install dir already exists."
128 # Verify our CodeSourcery toolchain installation.
129 if [[ ! -d "${SYSROOT}" ]]; then
130 echo -n "Error: CodeSourcery does not contain libc for ${CROSS_TARGET}: "
131 echo "${SYSROOT} not found."
135 for tool in ${CROSS_TARGET_AS} ${CROSS_TARGET_LD}; do
136 if [[ ! -e $tool ]]; then
137 echo "${tool} not found; exiting."
144 verifyNotDir ${LLVM_INSTALL_DIR}
145 sudoCreateDir ${LLVM_INSTALL_DIR}
147 # Unpack LLVM tarball; should create the directory "llvm".
149 runCommand "Unpacking LLVM" tar jxf ${LLVM_PKG_PATH}/${LLVM_PKG}
151 # Configure, build, and install LLVM.
152 createDir ${LLVM_OBJ_DIR}
154 runAndLog "Configuring LLVM" ${LLVM_OBJ_DIR}/llvm-configure.log \
155 ${LLVM_SRC_DIR}/configure \
158 --prefix=${LLVM_INSTALL_DIR} \
159 --target=${CROSS_TARGET} \
160 --with-llvmgccdir=${LLVMGCC_INSTALL_DIR}
161 runAndLog "Building LLVM" ${LLVM_OBJ_DIR}/llvm-build.log \
163 runAndLog "Installing LLVM" ${LLVM_OBJ_DIR}/llvm-install.log \
164 make ${MAKE_OPTS} install
168 verifyNotDir ${LLVMGCC_INSTALL_DIR}
169 sudoCreateDir ${LLVMGCC_INSTALL_DIR}
171 # Unpack LLVM-GCC tarball; should create the directory "llvm-gcc-4.2".
173 runCommand "Unpacking LLVM-GCC" tar jxf ${LLVM_PKG_PATH}/${LLVMGCC_PKG}
175 # Configure, build, and install LLVM-GCC.
176 createDir ${LLVMGCC_OBJ_DIR}
177 cd ${LLVMGCC_OBJ_DIR}
178 runAndLog "Configuring LLVM-GCC" ${LLVMGCC_OBJ_DIR}/llvmgcc-configure.log \
179 ${LLVMGCC_SRC_DIR}/configure \
180 --enable-languages=c,c++ \
181 --enable-llvm=${LLVM_INSTALL_DIR} \
182 --prefix=${LLVMGCC_INSTALL_DIR} \
183 --program-prefix=llvm- \
184 --target=${CROSS_TARGET} \
185 --with-gnu-as=${CROSS_TARGET_AS} \
186 --with-gnu-ld=${CROSS_TARGET_LD} \
187 --with-sysroot=${SYSROOT}
188 runAndLog "Building LLVM-GCC" ${LLVMGCC_OBJ_DIR}/llvmgcc-build.log \
190 runAndLog "Installing LLVM-GCC" ${LLVMGCC_OBJ_DIR}/llvmgcc-install.log \
194 echo "Building in ${SCRATCH_ROOT}; installing in ${INSTALL_ROOT}"
196 createDir ${SRC_ROOT}
197 createDir ${OBJ_ROOT}