forked from bazelment/lrte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_crosstool.sh
executable file
·164 lines (133 loc) · 5.77 KB
/
build_crosstool.sh
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
#!/bin/bash
# Take input from /dev/null.
exec < /dev/null
# stop on any error, echo commands.
set -ex
# Set locale to C, so that e.g., 'sort' will work consistently regardless
# of system and user environment settings.
LC_ALL=C
export LC_ALL
absname=`readlink -f "$0"`
absroot="${absname%/*}"
[ -f "${absroot}/grte/grte.cfg" ] || {
error "could not find ${absroot}/grte/grte.cfg"
}
. "${absroot}/grte/grte.cfg"
GRTEROOT="${1}/v${GRTEVERSION}"
tb=`readlink -f "${2}"`
GRTEBASENAME="${GRTE_PACKAGE_PREFIX}$(basename $1)v${GRTEVERSION}"
STAGING="${tb}/staging"
RESULTS="${tb}/results"
DEB_DIR=${RESULTS}/debs
# Directory that stores upstream sources
CROSSTOOL_SOURCES=$3
# Crosstool configuration
CROSSTOOL_VERSION="v2"
CROSSTOOL_GCC_VERSION="4.9"
# Assume the clang source code is checked out following
# http://clang.llvm.org/get_started.html
CROSSTOOL_CLANG_VERSION="4.0"
CROSSTOOL_ISPC_VERSION="1.9.2dev"
ISPC_GIT_COMMIT="d4a8afd"
: ${crosstool_rpmver:="1.0"}
# Update this each time new RPM's are built.
: ${crosstool_rpmrel:="8"}
export PARALLELMFLAGS="${JFLAGS:-j32}"
[ -z "${EMAIL}" ] && {
EMAIL="[email protected]"
export EMAIL
}
# Install the packages for GRTE, mostly GDE
for pkg in runtime headers gde; do
dpkg -i ${DEB_DIR}/${GRTEBASENAME}-${pkg}_${grte_rpmver}-${grte_rpmrel}_amd64.deb
done
# Use bash as shell, other "source" command inside rpm spec will fail.
ln -sf /bin/bash /bin/sh
# install packages that are needed by building binutils and clang
# ncurses is required by cmake 3.6 even if I don't want it linked into llvm (since it is not crosscompiled)
apt-get clean
apt-get update --fix-missing
apt-get install --fix-missing -y -q alien rpm
function build_rpm() {
local rpmrel=$1
local spec_file=$2
# avoid issues in rpmbuild within docker.
# rpmbuild is evoked by the default user account (root)
# when the files are mounted with a volume and do not have root permissions.
chown root:root /sources/*.tar.*
rpmbuild \
--dbpath /dev/null \
--define "_hash_empty_files 1" \
--define "_sourcedir ${CROSSTOOL_SOURCES}" \
--define "_topdir ${STAGING}" \
--define "_rpmtopdir ${STAGING}" \
--define 'disable_debuginfo t' \
--define "maintainer_email ${EMAIL}" \
--define "grte_basename ${GRTEBASENAME}" \
--define "grte_root ${GRTEROOT}" \
--define "grte_version ${GRTEVERSION}" \
--define "grte_gcc_version ${gcc_version}" \
--define "grte_glibc_version ${glibc_version}" \
--define "grte_rpmver ${grte_rpmver}" \
--define "grte_rpmrel ${grte_rpmrel}" \
--define "crosstool_scripts ${absroot}/crosstool/scripts" \
--define "crosstool_version ${CROSSTOOL_VERSION}" \
--define "crosstool_rpmver ${crosstool_rpmver}" \
--define "crosstool_rpmrel ${rpmrel}" \
--define "crosstool_gcc_version ${CROSSTOOL_GCC_VERSION}" \
--define "gcc_svn_version ${GCC_SVN_VERSION}" \
--define "crosstool_clang_version ${CROSSTOOL_CLANG_VERSION}" \
--define "clang_svn_version ${CLANG_SVN_VERSION}" \
--define "crosstool_ispc_version ${CROSSTOOL_ISPC_VERSION}" \
--define "ispc_git_commit ${ISPC_GIT_COMMIT}" \
-bb ${spec_file}
}
function package() {
local name=$1 # gcc, clang
local version=$2 # gcc version, or clang version
local svn_version=$3
local rpm_rel=${crosstool_rpmrel}.${svn_version}svn
build_rpm ${rpm_rel} crosstool/crosstool-grte-${name}.spec
local package_prefix="${GRTEBASENAME}-crosstool${CROSSTOOL_VERSION}-${name}-${version}"
local rpm="RPMS/x86_64/${package_prefix}-${crosstool_rpmver}-${rpm_rel}.x86_64.rpm"
pushd $STAGING
${absroot}/crosstool/scripts/rpm_to_deb "$rpm"
mv "${package_prefix}_${crosstool_rpmver}-${rpm_rel}_amd64.deb" \
"${package_prefix}_${crosstool_rpmver}-${rpm_rel}_amd64.changes" \
"${RESULTS}/debs/"
mv "$rpm" "${RESULTS}/rpms/"
popd
}
set -e
# For test rpm creation and deb conversion.
# package foo ${CROSSTOOL_GCC_VERSION} ${GCC_SVN_VERSION}
[ -z "${SKIP_CROSSTOOL_GCC}" ] && {
DEBIAN_FRONTEND=noninteractive apt-get install -y -q --fix-missing -y flex bison texinfo texi2html libxml2-dev make wget python python-dev subversion libedit-dev libncurses5-dev swig
package gcc ${CROSSTOOL_GCC_VERSION} ${GCC_SVN_VERSION}
}
[ -z "${SKIP_CROSSTOOL_CLANG}" ] && {
DEBIAN_FRONTEND=noninteractive apt-get install -y -q --fix-missing -y flex bison texinfo texi2html libxml2-dev make wget python python-dev subversion libedit-dev libncurses5-dev swig
# Install the crosstool gcc to build clang
dpkg -i ${DEB_DIR}/${GRTEBASENAME}-crosstool${CROSSTOOL_VERSION}-gcc-${CROSSTOOL_GCC_VERSION}_${crosstool_rpmver}-${crosstool_rpmrel}.${GCC_SVN_VERSION}svn_amd64.deb
# Build cmake because cmake in ubuntu 13 is too old
mkdir -p ${STAGING}/cmake
CMAKE_VERSION=3.6.1
if [ ! -e ${CROSSTOOL_SOURCES}/cmake-${CMAKE_VERSION}.tar.gz ]; then
pushd ${CROSSTOOL_SOURCES}
wget http://cmake.org/files/v3.6/cmake-${CMAKE_VERSION}.tar.gz
popd
fi
tar zxf ${CROSSTOOL_SOURCES}/cmake-${CMAKE_VERSION}.tar.gz -C ${STAGING}/cmake
pushd ${STAGING}/cmake/cmake-${CMAKE_VERSION}
./configure --parallel=${PARALLELMFLAGS}
make ${PARALLELMFLAGS}
make install
popd
package clang ${CROSSTOOL_CLANG_VERSION} ${CLANG_SVN_VERSION}
}
[ -z "${SKIP_CROSSTOOL_ISPC}" ] && {
DEBIAN_FRONTEND=noninteractive apt-get install -y -q flex bison make git python
dpkg -i ${DEB_DIR}/${GRTEBASENAME}-crosstool${CROSSTOOL_VERSION}-gcc-${CROSSTOOL_GCC_VERSION}_${crosstool_rpmver}-${crosstool_rpmrel}.${GCC_SVN_VERSION}svn_amd64.deb
dpkg -i ${DEB_DIR}/${GRTEBASENAME}-crosstool${CROSSTOOL_VERSION}-clang-${CROSSTOOL_CLANG_VERSION}_${crosstool_rpmver}-${crosstool_rpmrel}.${CLANG_SVN_VERSION}svn_amd64.deb
package ispc ${CROSSTOOL_ISPC_VERSION} ${ISPC_GIT_COMMIT}
}