forked from haiku/haiku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_cross_tools_gcc4
executable file
·309 lines (258 loc) · 8.5 KB
/
build_cross_tools_gcc4
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#!/bin/sh
#
# parameters <machine> <haiku sourcedir> <buildtools dir> <install dir>
# get and check the parameters
if [ $# -lt 4 ]; then
echo Usage: $0 '<machine> <haiku sourcedir> <buildtools dir>' \
'<install dir>' >&2
exit 1
fi
set -e
haikuMachine=$1
haikuSourceDir=$2
buildToolsDir=$3
installDir=$4
shift 4
additionalMakeArgs=$*
gdbSourceDir="$HAIKU_USE_GDB"
ccFlags="-O2"
cxxFlags="-O2"
binutilsTargets="$haikuMachine"
gdbTarget="$haikuMachine"
case $haikuMachine in
i586-*)
binutilsConfigureArgs="--disable-multilib"
gccConfigureArgs="--disable-multilib"
binutilsTargets="$binutilsTargets,i386-efi-pe,x86_64-efi-pe"
gdbConfigureArgs="--disable-multilib"
;;
x86_64-*)
# GCC's default is to enable multilib, but there is a bug when
# explicitly using --enable-multilib that causes a build
# failure
binutilsConfigureArgs=""
binutilsTargets="$binutilsTargets,i386-efi-pe,x86_64-efi-pe"
gdbConfigureArgs="--disable-multilib"
;;
m68k-*)
binutilsConfigureArgs="--enable-multilib"
gccConfigureArgs="--enable-multilib"
gdbConfigureArgs="--disable-multilib"
gdbTarget="m68k-unknown-elf"
;;
arm-*)
# Multilib creates a lot of confusion as the wrong libs end up being linked.
# For now, target Cortex-A8 devices.
binutilsConfigureArgs="--disable-multilib --with-float=hard
--with-cpu=cortex-a8 --with-fpu=vfpv3"
gccConfigureArgs="--disable-multilib --with-float=hard
--with-cpu=cortex-a8 --with-fpu=vfpv3"
# TODO: Disable building with TLS support for ARM until implemented.
binutilsConfigureArgs="$binutilsConfigureArgs --disable-tls"
gccConfigureArgs="$gccConfigureArgs --disable-tls"
gdbConfigureArgs="--disable-multilib --disable-werror -enable-interwork"
gdbTarget="arm-unknown-elf"
;;
powerpc-*)
binutilsConfigureArgs="--disable-multilib"
gccConfigureArgs="--disable-multilib"
binutilsTargets="$binutilsTargets,powerpc-apple-linux,powerpc-apple-freebsd,powerpc-apple-vxworks"
gdbConfigureArgs="--disable-multilib --disable-werror"
gdbTarget="powerpc-unknown-elf"
# TODO: Disable building with TLS support for PPC until implemented.
binutilsConfigureArgs="$binutilsConfigureArgs --disable-tls"
gccConfigureArgs="$gccConfigureArgs --disable-tls"
;;
*)
binutilsConfigureArgs="--disable-multilib"
gccConfigureArgs="--disable-multilib"
gdbConfigureArgs="--disable-multilib"
;;
esac
if [ `uname -s` = 'Haiku' ]; then
# force cross-build if building on Haiku:
buildhostMachine=${haikuMachine}_buildhost
buildHostSpec="--build=$buildhostMachine --host=$buildhostMachine"
fi
if [ ! -d "$haikuSourceDir" ]; then
echo "No such directory: \"$haikuSourceDir\"" >&2
exit 1
fi
if [ ! -d "$buildToolsDir" ]; then
echo "No such directory: \"$buildToolsDir\"" >&2
exit 1
fi
if [ -n "$gdbSourceDir" -a ! -d "$gdbSourceDir" ]; then
echo "No such directory: \"$gdbSourceDir\"" >&2
exit 1
fi
# create the output dir
mkdir -p "$installDir" || exit 1
# get absolute paths
currentDir=$(pwd)
cd "$haikuSourceDir"
haikuSourceDir=$(pwd)
cd "$currentDir"
cd "$buildToolsDir"
buildToolsDir=$(pwd)
cd "$currentDir"
cd "$installDir"
installDir=$(pwd)
cd "$currentDir"
if [ -n "$gdbSourceDir" ]; then
cd "$gdbSourceDir"
gdbSourceDir=$(pwd)
cd "$currentDir"
fi
binutilsSourceDir="$buildToolsDir/binutils"
gccSourceDir="$buildToolsDir/gcc"
# get gcc version
gccVersion=$(cat "$gccSourceDir/gcc/BASE-VER")
if [ -z "$gccVersion" ]; then
echo "Failed to find out gcc version." >&2
exit 1
fi
# clear out the "missing" scripts so that they don't cause errors on tools
# that are not installed, as we will have committed any files generated by
# them to the buildtools repo already.
echo "#!/bin/sh" >"$binutilsSourceDir"/missing
echo "#!/bin/sh" >"$gccSourceDir"/missing
echo "#!/bin/sh" >"$gccSourceDir"/isl/missing
# create the object and installation directories for the cross compilation tools
objDir="${installDir}-build"
binutilsObjDir="$objDir/binutils"
gccObjDir="$objDir/gcc"
gdbObjDir="$objDir/gdb"
stdcxxObjDir="$objDir/stdcxx"
sysrootDir="$installDir/sysroot"
tmpIncludeDir="$sysrootDir/boot/system/develop/headers"
tmpLibDir="$sysrootDir/boot/system/develop/lib"
rm -rf "$installDir" "$objDir"
mkdir -p "$installDir" "$objDir" "$binutilsObjDir" "$gccObjDir" "$gdbObjDir" \
"$stdcxxObjDir" "$tmpIncludeDir" "$tmpLibDir" || exit 1
mkdir -p "$installDir/lib/gcc/$haikuMachine/$gccVersion"
if [ "$HAIKU_USE_GCC_GRAPHITE" = 1 ]; then
cloogSourceDir="$buildToolsDir/cloog"
gmpSourceDir="$buildToolsDir/gcc/gmp"
islSourceDir="$buildToolsDir/isl"
islObjDir="$objDir/isl"
gmpObjDir="$objDir/gmp"
cloogObjDir="$objDir/cloog"
mkdir -p "$islObjDir" "$gmpObjDir" "$cloogObjDir" || exit 1
gccConfigureArgs="$gccConfigureArgs --with-cloog=$installDir \
--enable-cloog-backend=isl --with-isl=$installDir \
--with-gmp=$installDir \
--with-host-libstdcxx=\"-lstdc++\""
fi
if [ "$HAIKU_USE_GCC_PIPE" = 1 ]; then
ccFlags="$ccFlags -pipe"
cxxFlags="$cxxFlags -pipe"
fi
if [ -n "$SECONDARY_ARCH" ]; then
gccConfigureArgs="$gccConfigureArgs --with-hybrid-secondary=$SECONDARY_ARCH"
fi
# force the POSIX locale, as the build (makeinfo) might choke otherwise
export LC_ALL=POSIX
# build gdb
if [ -n "$HAIKU_USE_GDB" ]; then
cd "$gdbObjDir"
"$gdbSourceDir/configure" \
--prefix="$installDir" --target=$gdbTarget \
$gdbConfigureArgs \
|| exit 1
$MAKE $additionalMakeArgs || exit 1
$MAKE $additionalMakeArgs install || exit 1
fi
# build binutils
cd "$binutilsObjDir"
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$binutilsSourceDir/configure" \
--prefix="$installDir" $buildHostSpec --target=$haikuMachine \
--enable-targets=$binutilsTargets \
--disable-nls --disable-shared --disable-werror \
--with-sysroot="$sysrootDir" \
--disable-maintainer-mode \
$binutilsConfigureArgs \
|| exit 1
$MAKE $additionalMakeArgs || exit 1
$MAKE $additionalMakeArgs install || exit 1
export PATH="$PATH:$installDir/bin"
if [ "$HAIKU_USE_GCC_GRAPHITE" = 1 ]; then
# build gmp
cd "$gmpObjDir"
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$gmpSourceDir/configure" \
--prefix="$installDir" --disable-shared --enable-cxx || exit 1
$MAKE $additionalMakeArgs || exit 1
$MAKE $additionalMakeArgs install || exit 1
# build isl
cd "$islObjDir"
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$islSourceDir/configure" \
--prefix="$installDir" --disable-nls --disable-shared \
--with-gmp-prefix="$installDir" || exit 1
$MAKE $additionalMakeArgs || exit 1
$MAKE $additionalMakeArgs install || exit 1
# build cloog
cd "$cloogObjDir"
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$cloogSourceDir/configure" \
--prefix="$installDir" --disable-nls --disable-shared \
--with-gmp-prefix="$installDir" --with-isl-prefix=="$installDir" \
|| exit 1
$MAKE $additionalMakeArgs || exit 1
$MAKE $additionalMakeArgs install || exit 1
fi
# build gcc
# prepare the include files
copy_headers()
{
sourceDir=$1
targetDir=$2
headers="$(find $sourceDir -name \*\.h)"
headers="$(echo $headers | sed -e s@$sourceDir/@@g)"
for f in $headers; do
headerTargetDir="$targetDir/$(dirname $f)"
mkdir -p "$headerTargetDir"
cp "$sourceDir/$f" "$headerTargetDir"
done
}
copy_headers "$haikuSourceDir/headers/config" "$tmpIncludeDir/config"
copy_headers "$haikuSourceDir/headers/os" "$tmpIncludeDir/os"
copy_headers "$haikuSourceDir/headers/posix" "$tmpIncludeDir/posix"
# configure gcc
cd "$gccObjDir"
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$gccSourceDir/configure" \
--prefix="$installDir" $buildHostSpec --target=$haikuMachine \
--disable-nls --disable-shared --with-system-zlib \
--enable-languages=c,c++ --enable-lto --enable-frame-pointer \
--enable-__cxa-atexit --enable-threads=posix \
--with-default-libstdcxx-abi=gcc4-compatible \
--with-sysroot="$sysrootDir" \
--disable-maintainer-mode \
$gccConfigureArgs \
|| exit 1
# make gcc
$MAKE $additionalMakeArgs || {
echo "ERROR: Building gcc failed." >&2
exit 1
}
# install gcc
$MAKE $additionalMakeArgs install || {
echo "ERROR: Installing the cross compiler failed." >&2
exit 1
}
case $haikuMachine in
x86_64-*)
# pick up the 32-bit libraries for the bootloader
bootLibgcc=`$installDir/bin/$haikuMachine-gcc -m32 -print-file-name=libgcc.a`
$installDir/bin/$haikuMachine-strip --strip-debug $bootLibgcc
bootLibsupcxx=`$installDir/bin/$haikuMachine-gcc -m32 -print-file-name=libsupc++.a`
$installDir/bin/$haikuMachine-strip --strip-debug $bootLibsupcxx
;;
esac
# cleanup
# remove the system headers from the installation dir
# Only the ones from the source tree should be used.
rm -rf "$installDir/$haikuMachine/sys-include"
# remove the sysroot dir
rm -rf "$sysrootDir"
# remove the objects dir
rm -rf "$objDir"
echo "binutils and gcc for cross compilation have been built successfully!"