llvm.org GIT mirror llvm / cb6f9c8
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 Misha Brukman 10 years ago
2 changed file(s) with 235 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 #!/bin/bash
1 #
2 # Compiles and installs a Linux/x86_64 -> Linux/ARM crosstool based on LLVM and
3 # LLVM-GCC-4.2 using SVN snapshots in provided tarballs.
4
5 set -o nounset
6 set -o errexit
7
8 echo -n "Welcome to LLVM Linux/X86_64 -> Linux/ARM crosstool "
9 echo "builder/installer; some steps will require sudo privileges."
10
11 readonly INSTALL_ROOT="${INSTALL_ROOT:-/usr/local}"
12 # Both $USER and root *must* have read/write access to this dir.
13 readonly SCRATCH_ROOT=$(mktemp -d "${TMPDIR:-/tmp}/llvm-project.XXXXXX")
14 readonly SRC_ROOT="${SCRATCH_ROOT}/src"
15 readonly OBJ_ROOT="${SCRATCH_ROOT}/obj"
16
17 readonly CROSS_HOST="x86_64-unknown-linux-gnu"
18 readonly CROSS_TARGET="arm-none-linux-gnueabi"
19
20 readonly CODE_SOURCERY="${INSTALL_ROOT}/codesourcery"
21 readonly CODE_SOURCERY_PKG_PATH="${CODE_SOURCERY_PKG_PATH:-${HOME}/codesourcery}"
22 readonly CODE_SOURCERY_PKG="arm-2007q3-51-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2"
23 readonly CODE_SOURCERY_ROOT="${CODE_SOURCERY}/arm-2007q3"
24 readonly CODE_SOURCERY_BIN="${CODE_SOURCERY_ROOT}/bin"
25 # Make sure ${CROSS_TARGET}-* binutils are in command path
26 export PATH="${CODE_SOURCERY_BIN}:${PATH}"
27
28 readonly CROSS_TARGET_AS="${CODE_SOURCERY_BIN}/${CROSS_TARGET}-as"
29 readonly CROSS_TARGET_LD="${CODE_SOURCERY_BIN}/${CROSS_TARGET}-ld"
30
31 readonly SYSROOT="${CODE_SOURCERY_ROOT}/${CROSS_TARGET}/libc"
32
33 readonly LLVM_PROJECT="${INSTALL_ROOT}/llvm-project"
34 readonly LLVM_INSTALL_ROOT="${LLVM_PROJECT}/${CROSS_HOST}/${CROSS_TARGET}"
35 readonly LLVM_PKG_PATH="${LLVM_PKG_PATH:-${HOME}/llvm-project/snapshots}"
36
37 # Latest SVN revision known to be working in this configuration.
38 readonly LLVM_DEFAULT_REV="70786"
39
40 readonly LLVM_PKG="llvm-${LLVM_SVN_REV:-${LLVM_DEFAULT_REV}}.tar.bz2"
41 readonly LLVM_SRC_DIR="${SRC_ROOT}/llvm"
42 readonly LLVM_OBJ_DIR="${OBJ_ROOT}/llvm"
43 readonly LLVM_INSTALL_DIR="${LLVM_INSTALL_ROOT}/llvm"
44
45 readonly LLVMGCC_PKG="llvm-gcc-4.2-${LLVMGCC_SVN_REV:-${LLVM_DEFAULT_REV}}.tar.bz2"
46 readonly LLVMGCC_SRC_DIR="${SRC_ROOT}/llvm-gcc-4.2"
47 readonly LLVMGCC_OBJ_DIR="${OBJ_ROOT}/llvm-gcc-4.2"
48 readonly LLVMGCC_INSTALL_DIR="${LLVM_INSTALL_ROOT}/llvm-gcc-4.2"
49
50 readonly MAKE_OPTS="-j2"
51
52 # Verify we aren't going to install into an existing directory as this might
53 # create problems as we won't have a clean install.
54 verifyNotDir() {
55 if [[ -d $1 ]]; then
56 echo "Install dir $1 already exists; remove it to continue."
57 exit
58 fi
59 }
60
61 # Params:
62 # $1: directory to be created
63 # $2: optional mkdir command prefix, e.g. "sudo"
64 createDir() {
65 if [[ ! -e $1 ]]; then
66 ${2:-} mkdir -p $1
67 elif [[ -e $1 && ! -d $1 ]]; then
68 echo "$1 exists but is not a directory; exiting."
69 exit 3
70 fi
71 }
72
73 sudoCreateDir() {
74 createDir $1 sudo
75 sudo chown ${USER} $1
76 }
77
78 # Prints out and runs the command, but without logging -- intended for use with
79 # lightweight commands that don't have useful output to parse, e.g. mkdir, tar,
80 # etc.
81 runCommand() {
82 local message="$1"
83 shift
84 echo "=> $message"
85 echo "==> Running: $*"
86 $*
87 }
88
89 runAndLog() {
90 local message="$1"
91 local log_file="$2"
92 shift 2
93 echo "=> $message; log in $log_file"
94 echo "==> Running: $*"
95 # Pop-up a terminal with the output of the current command?
96 # e.g.: xterm -e /bin/bash -c "$* >| tee $log_file"
97 $* &> $log_file
98 if [[ $? != 0 ]]; then
99 echo "Error occurred: see most recent log file for details."
100 exit
101 fi
102 }
103
104 installCodeSourcery() {
105 # Create CodeSourcery dir, if necessary.
106 verifyNotDir ${CODE_SOURCERY}
107 sudoCreateDir ${CODE_SOURCERY}
108
109 # Unpack the tarball.
110 if [[ ! -d ${CODE_SOURCERY_ROOT} ]]; then
111 cd ${CODE_SOURCERY}
112 runCommand "Unpacking CodeSourcery in ${CODE_SOURCERY}" \
113 tar jxf ${CODE_SOURCERY_PKG_PATH}/${CODE_SOURCERY_PKG}
114 else
115 echo "CodeSourcery install dir already exists."
116 fi
117
118 # Verify our CodeSourcery toolchain installation.
119 if [[ ! -d "${SYSROOT}" ]]; then
120 echo -n "Error: CodeSourcery does not contain libc for ${CROSS_TARGET}: "
121 echo "${SYSROOT} not found."
122 exit
123 fi
124
125 for tool in ${CROSS_TARGET_AS} ${CROSS_TARGET_LD}; do
126 if [[ ! -e $tool ]]; then
127 echo "${tool} not found; exiting."
128 exit
129 fi
130 done
131 }
132
133 installLLVM() {
134 verifyNotDir ${LLVM_INSTALL_DIR}
135 sudoCreateDir ${LLVM_INSTALL_DIR}
136
137 # Unpack LLVM tarball; should create the directory "llvm".
138 cd ${SRC_ROOT}
139 runCommand "Unpacking LLVM" tar jxf ${LLVM_PKG_PATH}/${LLVM_PKG}
140
141 # Configure, build, and install LLVM.
142 createDir ${LLVM_OBJ_DIR}
143 cd ${LLVM_OBJ_DIR}
144 runAndLog "Configuring LLVM" ${LLVM_OBJ_DIR}/llvm-configure.log \
145 ${LLVM_SRC_DIR}/configure \
146 --disable-jit \
147 --enable-optimized \
148 --prefix=${LLVM_INSTALL_DIR} \
149 --target=${CROSS_TARGET} \
150 --with-llvmgccdir=${LLVMGCC_INSTALL_DIR}
151 runAndLog "Building LLVM" ${LLVM_OBJ_DIR}/llvm-build.log \
152 make ${MAKE_OPTS}
153 runAndLog "Installing LLVM" ${LLVM_OBJ_DIR}/llvm-install.log \
154 make ${MAKE_OPTS} install
155 }
156
157 installLLVMGCC() {
158 verifyNotDir ${LLVMGCC_INSTALL_DIR}
159 sudoCreateDir ${LLVMGCC_INSTALL_DIR}
160
161 # Unpack LLVM-GCC tarball; should create the directory "llvm-gcc-4.2".
162 cd ${SRC_ROOT}
163 runCommand "Unpacking LLVM-GCC" tar jxf ${LLVM_PKG_PATH}/${LLVMGCC_PKG}
164
165 # Configure, build, and install LLVM-GCC.
166 createDir ${LLVMGCC_OBJ_DIR}
167 cd ${LLVMGCC_OBJ_DIR}
168 runAndLog "Configuring LLVM-GCC" ${LLVMGCC_OBJ_DIR}/llvmgcc-configure.log \
169 ${LLVMGCC_SRC_DIR}/configure \
170 --enable-languages=c,c++ \
171 --enable-llvm=${LLVM_INSTALL_DIR} \
172 --prefix=${LLVMGCC_INSTALL_DIR} \
173 --program-prefix=llvm- \
174 --target=${CROSS_TARGET} \
175 --with-gnu-as=${CROSS_TARGET_AS} \
176 --with-gnu-ld=${CROSS_TARGET_LD} \
177 --with-sysroot=${SYSROOT}
178 runAndLog "Building LLVM-GCC" ${LLVMGCC_OBJ_DIR}/llvmgcc-build.log \
179 make
180 runAndLog "Installing LLVM-GCC" ${LLVMGCC_OBJ_DIR}/llvmgcc-install.log \
181 make install
182 }
183
184 echo "Building in ${SCRATCH_ROOT}; installing in ${INSTALL_ROOT}"
185
186 createDir ${SRC_ROOT}
187 createDir ${OBJ_ROOT}
188
189 installCodeSourcery
190 installLLVM
191 installLLVMGCC
192
193 echo "Done."
0 #!/bin/bash
1 #
2 # Creates LLVM SVN snapshots: llvm-$REV.tar.bz2 and llvm-gcc-4.2-$REV.tar.bz2,
3 # where $REV is an SVN revision of LLVM. This is used for creating stable
4 # tarballs which can be used to build known-to-work crosstools.
5 #
6 # Syntax:
7 # $0 [REV] -- grabs the revision $REV from SVN; if not specified, grabs the
8 # latest SVN revision.
9
10 set -o nounset
11 set -o errexit
12
13 readonly REV="${1:-HEAD}"
14
15 runOnModule() {
16 local module=$1
17 local log="${module}.log"
18 echo "Running: svn co -r ${REV} ${module}; log in ${log}"
19 svn co -r ${REV} http://llvm.org/svn/llvm-project/${module}/trunk ${module} \
20 > ${log} 2>&1
21
22 # Delete all the ".svn" dirs; they take quite a lot of space.
23 echo "Cleaning up .svn dirs"
24 find ${module} -type d -name \.svn -print0 | xargs -0 /bin/rm -rf
25
26 # Create "module-revision.tar.bz2" packages from the SVN checkout dirs.
27 local revision=$(grep "Checked out revision" ${log} | \
28 sed 's/[^0-9]\+\([0-9]\+\)[^0-9]\+/\1/')
29 local tarball="${module}-${revision}.tar.bz2"
30 echo "Creating tarball: ${tarball}"
31 tar cjf ${tarball} ${module}
32
33 echo "Cleaning SVN checkout dir ${module}"
34 rm -rf ${module} ${log}
35 }
36
37 for module in "llvm" "llvm-gcc-4.2"; do
38 runOnModule ${module}
39 done
40