-
Notifications
You must be signed in to change notification settings - Fork 1
/
tilera.sh
executable file
·221 lines (203 loc) · 7.05 KB
/
tilera.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
#
#Copyright: (C) 2012 Agustin Henze <[email protected]>
#
#License: GPL-3
#This package is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this package; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
set -a
# Directories
ROOT_DIR="${PWD}"
SOURCES="${ROOT_DIR}/sources"
UNPACKED="${ROOT_DIR}/unpacked"
BUILD="${ROOT_DIR}/build"
DESTDIR="${ROOT_DIR}/install"
STAMPS="${ROOT_DIR}/stamps"
mkdir -p "${SOURCES}"
mkdir -p "${UNPACKED}"
mkdir -p "${BUILD}"
mkdir -p "${DESTDIR}"
mkdir -p "${STAMPS}"
PREFIX=""
TARGET="tilepro-unknown-linux-gnu"
TILE_URL_TILEPRO=http://www.tilera.com/scm/tilepro-x86_64.tar.bz2
TILE_URL_BINUTILS=ftp://sourceware.org/pub/binutils/snapshots/binutils-2.22.90.tar.bz2
TILE_URL_LINUX_KERNEL=https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.32.tar.bz2
TILE_URL_GLIBC=ftp://ftp.gnu.org/gnu/libc/glibc-2.16.0.tar.xz
TILE_URL_GCC=ftp://ftp.gnu.org/gnu/gcc/gcc-4.7.2/gcc-4.7.2.tar.bz2
TILE_URL_GDB=ftp://ftp.gnu.org/gnu/gdb/gdb-7.5.tar.bz2
# How many cpus there
if [ "x${CPUS}" == "x" ]; then
if which getconf > /dev/null; then
CPUS=$(getconf _NPROCESSORS_ONLN)
else
CPUS=1
fi
MAKEFLAGS=-j$((CPUS + 1))
else
MAKEFLAGS=-j${CPUS}
fi
# Log a message out to the console
function log {
echo "******************************************************************"
echo "* $*"
echo "******************************************************************"
}
# Fetch a versioned file from a URL
function fetch {
if [ ! -e ${STAMPS}/$1.fetch ]; then
log "Downloading $1 sources..."
wget -c --no-passive-ftp --no-check-certificate -O $3 $2 && touch ${STAMPS}/$1.fetch
fi
}
function unpack {
if [ -e ${STAMPS}/$1.fetch ]; then
if [ ! -e ${STAMPS}/$1.unpacked ]; then
log "Unpacking $1 sources..."
if [ "x$3" == "x" ]; then
OUT=${UNPACKED}
else
OUT=$3
fi
tar -C ${OUT} -xvf $2 && touch ${STAMPS}/$1.unpacked
fi
fi
}
# Fetch all urls
for URL in $(set | grep TILE_URL_); do
VAR_ENV=$(echo "${URL}" | sed 's@=.*@@g')
TOOL_DIR=$(basename $(echo ${!VAR_ENV} | sed 's@\(.*\)\.tar\..*@\1@g'))
TOOL_NAME=$(echo "${VAR_ENV}" | sed 's@TILE_URL_\(.*\)@\1@g')
TOOL_VERSION=$(echo ${!VAR_ENV} | sed 's@.*\-\(.*\)\.tar\..*@\1@g')
URL=${!VAR_ENV}
OUT=${SOURCES}/$(basename $URL)
export ${TOOL_NAME}=${TOOL_DIR} ${TOOL_NAME}_VERSION=${TOOL_VERSION}
fetch ${TOOL_DIR} ${URL} ${OUT}
unpack ${TOOL_DIR} ${OUT}
done
# Vars env
export LDFLAGS="${LDFLAGS} -L${DESTDIR}/${TARGET}/lib"
export PATH=${DESTDIR}/bin:${PATH}
# Binutils
if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
log "Building ${BINUTILS}..."
rm -rf ${BUILD}/${BINUTILS} && mkdir -p ${BUILD}/${BINUTILS}
cd ${BUILD}/${BINUTILS}
${UNPACKED}/${BINUTILS}/configure \
--target=${TARGET} \
--with-sysroot=${DESTDIR} \
--prefix=${PREFIX}
make all
make install
cd ${ROOT_DIR}
touch ${STAMPS}/${BINUTILS}.build
fi
# Linux kernel
if [ ! -e ${STAMPS}/${LINUX_KERNEL}.headers ]; then
log "Installing ${LINUX_KERNEL} headers..."
rm -rf ${BUILD}/${LINUX_KERNEL} && mkdir -p ${BUILD}/${LINUX_KERNEL}
cd ${UNPACKED}/${LINUX_KERNEL}
make headers_install ARCH=tilepro O=${BUILD}/${LINUX_KERNEL}
mkdir -p ${DESTDIR}/tile/usr
cp -r ${BUILD}/${LINUX_KERNEL}/usr/include ${DESTDIR}/tile/usr/
mkdir -p ${DESTDIR}/lib/gcc/${TARGET}
ln -sf ../../tile ${DESTDIR}/lib/gcc/sysroot
cd ${ROOT_DIR}
touch ${STAMPS}/${LINUX_KERNEL}.headers
fi
# GCC 1st stage
if [ ! -e ${STAMPS}/${GCC}.build ]; then
log "Building ${GCC}..."
rm -rf ${BUILD}/${GCC} && mkdir -p ${BUILD}/${GCC}
cd ${BUILD}/${GCC}
${UNPACKED}/${GCC}/configure \
--target=${TARGET} \
--with-gas \
--disable-multilib \
--enable-languages=c,c++ \
--prefix=${PREFIX} \
--with-build-time-tools=${DESTDIR}/bin \
--with-sysroot=${UNPACKED}/${TILEPRO}/lib/gcc/sysroot \
--oldincludedir=${UNPACKED}/${TILEPRO}/tile/usr/include
make all
make install
cd ${ROOT_DIR}
touch ${STAMPS}/${GCC}.build
fi
# Glibc
if [ ! -e ${STAMPS}/${GLIBC}.build ]; then
log "Building ${GLIBC}..."
GLIBC_PORTS=glibc-ports-${GLIBC_VERSION}
fetch ${GLIBC_PORTS} ftp://ftp.gnu.org/gnu/libc/${GLIBC_PORTS}.tar.xz ${UNPACKED}/${GLIBC}/${GLIBC_PORTS}.tar.xz
unpack ${GLIBC_PORTS} ${UNPACKED}/${GLIBC}/${GLIBC_PORTS}.tar.xz ${UNPACKED}/${GLIBC}
rm -rf ${BUILD}/${GLIBC} && mkdir -p ${BUILD}/${GLIBC}
cd ${BUILD}/${GLIBC}
echo "install_root=${DESTDIR}/tile" > configparms
${UNPACKED}/${GLIBC}/configure \
--enable-adds-ons=ports,nptl,libidn \
--prefix=/usr \
--with-headers=${BUILD}/${LINUX_KERNEL}/usr/include \
--host=$TARGET \
libc_cv_z_relro=yes \
CC="${DESTDIR}/bin/${TARGET}-gcc" \
CXX="${DESTDIR}/bin/${TARGET}-g++" \
AR="${DESTDIR}/bin/${TARGET}-ar" \
AS="${DESTDIR}/bin/${TARGET}-as" \
LD="${DESTDIR}/bin/${TARGET}-ld" \
NM="${DESTDIR}/bin/${TARGET}-nm" \
RANLIB="${DESTDIR}/bin/${TARGET}-ranlib"
make all
make install
touch ${STAMPS}/${GLIBC}.build
fi
# Gdb
# The target tilepro-unknown-linux-gnu is not yet supported
#if [ ! -e ${STAMPS}/${GDB}.build ]; then
#log "Building ${GDB}..."
#rm -rf ${BUILD}/${GDB} && mkdir -p ${BUILD}/${GDB}
#cd ${BUILD}/${GDB}
#${UNPACKED}/${GDB}/configure \
#--target=${TARGET} \
#--prefix=${PREFIX} \
#--with-sysroot=${DESTDIR}/lib/gcc/sysroot
#make all
#make install
#touch ${STAMPS}/${GDB}.build
#fi
# GCC 2nd stage
if [ ! -e ${STAMPS}/${GCC}.2build ]; then
log "Building 2nd stage ${GCC}..."
mkdir -p ${DESTDIR}/lib/gcc/${TARGET}/${GCC_VERSION}/include
cat > ${DESTDIR}/lib/gcc/${TARGET}/${GCC_VERSION}/include/feedback.h << END
#define FEEDBACK_ENTER_EXPLICIT(FUNCNAME, SECNAME, SIZE)
#define FEEDBACK_ENTER(FUNCNAME)
#define FEEDBACK_REENTER(FUNCNAME)
#define FEEDBACK_ENTRY(FUNCNAME, SECNAME, SIZE)
END
rm -rf ${BUILD}/${GCC} && mkdir -p ${BUILD}/${GCC}
cd ${BUILD}/${GCC}
${UNPACKED}/${GCC}/configure \
--target=${TARGET} \
--with-gas \
--disable-multilib \
--enable-languages=c,c++ \
--prefix=${PREFIX} \
--with-build-time-tools=${DESTDIR}/bin \
--with-sysroot=${DESTDIR}/lib/gcc/sysroot \
--oldincludedir=${DESTDIR}/tile/usr/include
make all
make install
cd ${ROOT_DIR}
touch ${STAMPS}/${GCC}.2build
fi