1
|
#!/bin/sh
|
2
|
|
3
|
ROOT=`pwd`
|
4
|
SRCDIR=$ROOT/src
|
5
|
BUILDDIR=$ROOT/build
|
6
|
PREFIX=$ROOT/install
|
7
|
|
8
|
GCC_SRC=gcc-4.8.2.tar.bz2
|
9
|
GCC_VERSION=4.8.2
|
10
|
GCC_DIR=gcc-$GCC_VERSION
|
11
|
|
12
|
BINUTILS_SRC=binutils-2.21.1a.tar.bz2
|
13
|
BINUTILS_VERSION=2.21.1
|
14
|
BINUTILS_DIR=binutils-$BINUTILS_VERSION
|
15
|
|
16
|
NEWLIB_SRC=newlib-1.19.0.tar.gz
|
17
|
NEWLIB_VERSION=1.19.0
|
18
|
NEWLIB_DIR=newlib-$NEWLIB_VERSION
|
19
|
|
20
|
TARGET_TRIPLET=arm-none-eabi
|
21
|
|
22
|
#INSIGHT_SRC=insight-6.8-1.tar.bz2
|
23
|
#INSIGHT_VERSION=6.8-1
|
24
|
#INSIGHT_DIR=insight-$INSIGHT_VERSION
|
25
|
|
26
|
echo "I will build an $TARGET_TRIPLET cross-compiler:
|
27
|
|
28
|
Prefix: $PREFIX
|
29
|
Sources: $SRCDIR
|
30
|
Build files: $BUILDDIR
|
31
|
|
32
|
Press ^C now if you do NOT want to do this."
|
33
|
read IGNORE
|
34
|
|
35
|
#
|
36
|
# Helper functions.
|
37
|
#
|
38
|
unpack_source()
|
39
|
{
|
40
|
(
|
41
|
cd $SRCDIR
|
42
|
ARCHIVE_SUFFIX=${1##*.}
|
43
|
if [ "$ARCHIVE_SUFFIX" = "gz" ]; then
|
44
|
tar zxvf $1
|
45
|
elif [ "$ARCHIVE_SUFFIX" = "bz2" ]; then
|
46
|
tar jxvf $1
|
47
|
else
|
48
|
echo "Unknown archive format for $1"
|
49
|
exit 1
|
50
|
fi
|
51
|
)
|
52
|
}
|
53
|
|
54
|
# Create all the directories we need.
|
55
|
#mkdir -p $SRCDIR $BUILDDIR $PREFIX
|
56
|
|
57
|
(
|
58
|
cd $SRCDIR
|
59
|
|
60
|
# Unpack the sources.
|
61
|
unpack_source $(basename $GCC_SRC)
|
62
|
unpack_source $(basename $BINUTILS_SRC)
|
63
|
unpack_source $(basename $NEWLIB_SRC)
|
64
|
#unpack_source $(basename $INSIGHT_SRC)
|
65
|
)
|
66
|
|
67
|
# Set the PATH to include the binaries we're going to build.
|
68
|
OLD_PATH=$PATH
|
69
|
export PATH=$PREFIX/bin:$PATH
|
70
|
|
71
|
#
|
72
|
# Stage 1: Build binutils
|
73
|
#
|
74
|
(
|
75
|
(
|
76
|
# autoconf check.
|
77
|
cd $SRCDIR/$BINUTILS_DIR
|
78
|
|
79
|
) || exit 1
|
80
|
|
81
|
# Now, build it.
|
82
|
mkdir -p $BUILDDIR/$BINUTILS_DIR
|
83
|
cd $BUILDDIR/$BINUTILS_DIR
|
84
|
|
85
|
$SRCDIR/$BINUTILS_DIR/configure --target=$TARGET_TRIPLET --prefix=$PREFIX \
|
86
|
--enable-interwork --enable-threads=posix --enable-multilib --with-float=soft --disable-werror \
|
87
|
&& make all install
|
88
|
|
89
|
) || exit 1
|
90
|
|
91
|
#
|
92
|
# Stage 2: Patch the GCC multilib rules, then build the gcc compiler only
|
93
|
#
|
94
|
(
|
95
|
MULTILIB_CONFIG=$SRCDIR/$GCC_DIR/gcc/config/arm/t-$TARGET_TRIPLET
|
96
|
|
97
|
echo "
|
98
|
|
99
|
MULTILIB_OPTIONS += mno-thumb-interwork/mthumb-interwork
|
100
|
MULTILIB_DIRNAMES += normal interwork
|
101
|
|
102
|
" >> $MULTILIB_CONFIG
|
103
|
|
104
|
mkdir -p $BUILDDIR/$GCC_DIR
|
105
|
cd $BUILDDIR/$GCC_DIR
|
106
|
|
107
|
$SRCDIR/$GCC_DIR/configure --target=$TARGET_TRIPLET --prefix=$PREFIX \
|
108
|
--enable-interwork --enable-multilib --with-float=soft --disable-werror \
|
109
|
--enable-languages="c,c++" --with-newlib \
|
110
|
--with-headers=$SRCDIR/$NEWLIB_DIR/newlib/libc/include \
|
111
|
--with-system-zlib --disable-shared \
|
112
|
&& make all-gcc install-gcc
|
113
|
|
114
|
) || exit 1
|
115
|
|
116
|
#
|
117
|
# Stage 3: Build and install newlib
|
118
|
#
|
119
|
(
|
120
|
(
|
121
|
# Same issue, we have to patch to support makeinfo >= 4.11.
|
122
|
cd $SRCDIR/$NEWLIB_DIR
|
123
|
|
124
|
) || exit 1
|
125
|
|
126
|
# And now we can build it.
|
127
|
mkdir -p $BUILDDIR/$NEWLIB_DIR
|
128
|
cd $BUILDDIR/$NEWLIB_DIR
|
129
|
|
130
|
$SRCDIR/$NEWLIB_DIR/configure --target=$TARGET_TRIPLET --prefix=$PREFIX \
|
131
|
--enable-interwork --enable-multilib --with-float=soft --disable-werror \
|
132
|
&& make all install
|
133
|
|
134
|
) || exit 1
|
135
|
|
136
|
#
|
137
|
# Stage 4: Build and install the rest of GCC.
|
138
|
#
|
139
|
(
|
140
|
cd $BUILDDIR/$GCC_DIR
|
141
|
|
142
|
make all install
|
143
|
|
144
|
) || exit 1
|
145
|
|
146
|
#
|
147
|
# Stage 5: Build and install INSIGHT.
|
148
|
#
|
149
|
# edit: we currently don't need that for OsmocomBB
|
150
|
|
151
|
#(
|
152
|
# Now, build it.
|
153
|
#mkdir -p $BUILDDIR/$INSIGHT_DIR
|
154
|
|
155
|
#cd $BUILDDIR/$INSIGHT_DIR
|
156
|
|
157
|
#$SRCDIR/$INSIGHT_DIR/configure --target=$TARGET_TRIPLET --prefix=$PREFIX \
|
158
|
# --enable-interwork --enable-multilib --with-float=soft --disable-werror \
|
159
|
# && make all install
|
160
|
|
161
|
#) || exit 1
|
162
|
|
163
|
|
164
|
export PATH=$OLD_PATH
|
165
|
|
166
|
echo "
|
167
|
Build complete! Add $PREFIX/bin to your PATH to make $TARGET_TRIPLET-gcc and friends
|
168
|
accessible directly.
|
169
|
"
|