3 # parameters <machine> <haiku sourcedir> <buildtools dir> <install dir>
5 # get and check the parameters
7 echo Usage
: $0 '<machine> <haiku sourcedir> <buildtools dir>' \
18 gdbSourceDir
="$HAIKU_USE_GDB"
22 binutilsTargets
="$haikuMachine"
23 gdbTarget
="$haikuMachine"
26 binutilsConfigureArgs
="--disable-multilib"
27 gccConfigureArgs
="--disable-multilib"
28 binutilsTargets
="$binutilsTargets,i386-efi-pe,x86_64-efi-pe"
29 gdbConfigureArgs
="--disable-multilib"
32 # GCC's default is to enable multilib, but there is a bug when
33 # explicitly using --enable-multilib that causes a build
35 binutilsConfigureArgs
=""
36 binutilsTargets
="$binutilsTargets,i386-efi-pe,x86_64-efi-pe"
37 gdbConfigureArgs
="--disable-multilib"
40 binutilsConfigureArgs
="--enable-multilib"
41 gccConfigureArgs
="--enable-multilib"
42 gdbConfigureArgs
="--disable-multilib"
43 gdbTarget
="m68k-unknown-elf"
46 # Multilib creates a lot of confusion as the wrong libs end up being linked.
47 # For now, target Cortex-A8 devices.
48 binutilsConfigureArgs
="--disable-multilib --with-float=hard
49 --with-cpu=cortex-a8 --with-fpu=vfpv3"
50 gccConfigureArgs
="--disable-multilib --with-float=hard
51 --with-cpu=cortex-a8 --with-fpu=vfpv3"
53 # TODO: Disable building with TLS support for ARM until implemented.
54 binutilsConfigureArgs
="$binutilsConfigureArgs --disable-tls"
55 gccConfigureArgs
="$gccConfigureArgs --disable-tls"
56 gdbConfigureArgs
="--disable-multilib --disable-werror -enable-interwork"
57 gdbTarget
="arm-unknown-elf"
60 binutilsConfigureArgs
="--disable-multilib"
61 gccConfigureArgs
="--disable-multilib"
62 binutilsTargets
="$binutilsTargets,powerpc-apple-linux,powerpc-apple-freebsd,powerpc-apple-vxworks"
63 gdbConfigureArgs
="--disable-multilib --disable-werror"
64 gdbTarget
="powerpc-unknown-elf"
67 binutilsConfigureArgs
="--disable-multilib"
68 gccConfigureArgs
="--disable-multilib"
69 gdbConfigureArgs
="--disable-multilib"
73 if [ `uname -s` = 'Haiku' ]; then
74 # force cross-build if building on Haiku:
75 buildhostMachine
=${haikuMachine}_buildhost
76 buildHostSpec
="--build=$buildhostMachine --host=$buildhostMachine"
79 if [ ! -d "$haikuSourceDir" ]; then
80 echo "No such directory: \"$haikuSourceDir\"" >&2
84 if [ ! -d "$buildToolsDir" ]; then
85 echo "No such directory: \"$buildToolsDir\"" >&2
89 if [ -n "$gdbSourceDir" -a ! -d "$gdbSourceDir" ]; then
90 echo "No such directory: \"$gdbSourceDir\"" >&2
95 # create the output dir
96 mkdir
-p "$installDir" ||
exit 1
103 haikuSourceDir
=$
(pwd)
114 if [ -n "$gdbSourceDir" ]; then
120 binutilsSourceDir
="$buildToolsDir/binutils"
121 gccSourceDir
="$buildToolsDir/gcc"
125 gccVersion
=$
(cat "$gccSourceDir/gcc/BASE-VER")
127 if [ -z "$gccVersion" ]; then
128 echo "Failed to find out gcc version." >&2
132 # touch all info files in order to avoid the dependency on makeinfo
133 # (which apparently doesn't work reliably on all the different host
134 # configurations and changes files which in turn appear as local changes
136 find "$binutilsSourceDir" "$gccSourceDir" -name \
*.info
-print0 |
xargs -0 touch
138 # create the object and installation directories for the cross compilation tools
139 objDir
="${installDir}-build"
140 binutilsObjDir
="$objDir/binutils"
141 gccObjDir
="$objDir/gcc"
142 gdbObjDir
="$objDir/gdb"
143 stdcxxObjDir
="$objDir/stdcxx"
144 sysrootDir
="$installDir/sysroot"
145 tmpIncludeDir
="$sysrootDir/boot/system/develop/headers"
146 tmpLibDir
="$sysrootDir/boot/system/develop/lib"
148 rm -rf "$installDir" "$objDir"
150 mkdir
-p "$installDir" "$objDir" "$binutilsObjDir" "$gccObjDir" "$gdbObjDir" \
151 "$stdcxxObjDir" "$tmpIncludeDir" "$tmpLibDir" ||
exit 1
152 mkdir
-p "$installDir/lib/gcc/$haikuMachine/$gccVersion"
154 if [ "$HAIKU_USE_GCC_GRAPHITE" = 1 ]; then
155 cloogSourceDir
="$buildToolsDir/cloog"
156 gmpSourceDir
="$buildToolsDir/gcc/gmp"
157 islSourceDir
="$buildToolsDir/isl"
159 islObjDir
="$objDir/isl"
160 gmpObjDir
="$objDir/gmp"
161 cloogObjDir
="$objDir/cloog"
162 mkdir
-p "$islObjDir" "$gmpObjDir" "$cloogObjDir" ||
exit 1
164 gccConfigureArgs
="$gccConfigureArgs --with-cloog=$installDir \
165 --enable-cloog-backend=isl --with-isl=$installDir \
166 --with-gmp=$installDir \
167 --with-host-libstdcxx=\"-lstdc++\""
169 if [ "$HAIKU_USE_GCC_PIPE" = 1 ]; then
170 ccFlags
="$ccFlags -pipe"
171 cxxFlags
="$cxxFlags -pipe"
174 if [ -n "$SECONDARY_ARCH" ]; then
175 gccConfigureArgs
="$gccConfigureArgs --with-hybrid-secondary=$SECONDARY_ARCH"
178 # force the POSIX locale, as the build (makeinfo) might choke otherwise
182 if [ -n "$HAIKU_USE_GDB" ]; then
184 "$gdbSourceDir/configure" \
185 --prefix="$installDir" --target=$gdbTarget \
188 $MAKE $additionalMakeArgs ||
exit 1
189 $MAKE $additionalMakeArgs install ||
exit 1
194 CFLAGS
="$ccFlags" CXXFLAGS
="$cxxFlags" "$binutilsSourceDir/configure" \
195 --prefix="$installDir" $buildHostSpec --target=$haikuMachine \
196 --enable-targets=$binutilsTargets \
197 --disable-nls --disable-shared --disable-werror \
198 --with-sysroot="$sysrootDir" --disable-initfini-array \
199 $binutilsConfigureArgs \
201 $MAKE $additionalMakeArgs ||
exit 1
202 $MAKE $additionalMakeArgs install ||
exit 1
204 export PATH
=$PATH:"$installDir/bin"
206 if [ "$HAIKU_USE_GCC_GRAPHITE" = 1 ]; then
209 CFLAGS
="$ccFlags" CXXFLAGS
="$cxxFlags" "$gmpSourceDir/configure" \
210 --prefix="$installDir" --disable-shared --enable-cxx ||
exit 1
211 $MAKE $additionalMakeArgs ||
exit 1
212 $MAKE $additionalMakeArgs install ||
exit 1
216 CFLAGS
="$ccFlags" CXXFLAGS
="$cxxFlags" "$islSourceDir/configure" \
217 --prefix="$installDir" --disable-nls --disable-shared \
218 --with-gmp-prefix="$installDir" ||
exit 1
219 $MAKE $additionalMakeArgs ||
exit 1
220 $MAKE $additionalMakeArgs install ||
exit 1
224 CFLAGS
="$ccFlags" CXXFLAGS
="$cxxFlags" "$cloogSourceDir/configure" \
225 --prefix="$installDir" --disable-nls --disable-shared \
226 --with-gmp-prefix="$installDir" --with-isl-prefix=="$installDir" \
228 $MAKE $additionalMakeArgs ||
exit 1
229 $MAKE $additionalMakeArgs install ||
exit 1
234 # prepare the include files
240 headers
="$(find $sourceDir -name \*\.h)"
241 headers
="$(echo $headers | sed -e s@$sourceDir/@@g)"
242 for f
in $headers; do
243 headerTargetDir
="$targetDir/$(dirname $f)"
244 mkdir
-p "$headerTargetDir"
245 cp "$sourceDir/$f" "$headerTargetDir"
249 copy_headers
"$haikuSourceDir/headers/config" "$tmpIncludeDir/config"
250 copy_headers
"$haikuSourceDir/headers/os" "$tmpIncludeDir/os"
251 copy_headers
"$haikuSourceDir/headers/posix" "$tmpIncludeDir/posix"
255 CFLAGS
="$ccFlags" CXXFLAGS
="$cxxFlags" "$gccSourceDir/configure" \
256 --prefix="$installDir" $buildHostSpec --target=$haikuMachine \
257 --disable-nls --disable-shared --with-system-zlib \
258 --enable-languages=c
,c
++ --enable-lto --enable-frame-pointer \
259 --enable-__cxa-atexit --enable-threads=posix \
260 --with-default-libstdcxx-abi=gcc4-compatible \
261 --with-sysroot="$sysrootDir" \
266 $MAKE $additionalMakeArgs ||
{
267 echo "ERROR: Building gcc failed." >&2
272 $MAKE $additionalMakeArgs install ||
{
273 echo "ERROR: Installing the cross compiler failed." >&2
277 case $haikuMachine in
279 # pick up the 32-bit libraries for the bootloader
280 bootLibgcc
=`$installDir/bin/$haikuMachine-gcc -m32 -print-file-name=libgcc.a`
281 $installDir/bin
/$haikuMachine-strip --strip-debug $bootLibgcc
282 bootLibsupcxx
=`$installDir/bin/$haikuMachine-gcc -m32 -print-file-name=libsupc++.a`
283 $installDir/bin
/$haikuMachine-strip --strip-debug $bootLibsupcxx
289 # remove the system headers from the installation dir
290 # Only the ones from the source tree should be used.
291 rm -rf "$installDir/$haikuMachine/sys-include"
293 # remove the sysroot dir
296 # remove the objects dir
300 echo "binutils and gcc for cross compilation have been built successfully!"