libroot/posix/stdio: Remove unused portions.
[haiku.git] / build / scripts / build_cross_tools_gcc4
blobcafdd3e071242722a56281fe36153714afb3bc46
1 #!/bin/sh
3 # parameters <machine> <haiku sourcedir> <buildtools dir> <install dir>
5 # get and check the parameters
6 if [ $# -lt 4 ]; then
7 echo Usage: $0 '<machine> <haiku sourcedir> <buildtools dir>' \
8 '<install dir>' >&2
9 exit 1
12 haikuMachine=$1
13 haikuSourceDir=$2
14 buildToolsDir=$3
15 installDir=$4
16 shift 4
17 additionalMakeArgs=$*
18 gdbSourceDir="$HAIKU_USE_GDB"
20 ccFlags="-O2"
21 cxxFlags="-O2"
22 binutilsTargets="$haikuMachine"
23 gdbTarget="$haikuMachine"
24 case $haikuMachine in
25 i586-*)
26 binutilsConfigureArgs="--disable-multilib"
27 gccConfigureArgs="--disable-multilib"
28 binutilsTargets="$binutilsTargets,i386-efi-pe,x86_64-efi-pe"
29 gdbConfigureArgs="--disable-multilib"
31 x86_64-*)
32 # GCC's default is to enable multilib, but there is a bug when
33 # explicitly using --enable-multilib that causes a build
34 # failure
35 binutilsConfigureArgs=""
36 binutilsTargets="$binutilsTargets,i386-efi-pe,x86_64-efi-pe"
37 gdbConfigureArgs="--disable-multilib"
39 m68k-*)
40 binutilsConfigureArgs="--enable-multilib"
41 gccConfigureArgs="--enable-multilib"
42 gdbConfigureArgs="--disable-multilib"
43 gdbTarget="m68k-unknown-elf"
45 arm-*)
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"
59 powerpc-*)
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"
71 esac
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
81 exit 1
84 if [ ! -d "$buildToolsDir" ]; then
85 echo "No such directory: \"$buildToolsDir\"" >&2
86 exit 1
89 if [ -n "$gdbSourceDir" -a ! -d "$gdbSourceDir" ]; then
90 echo "No such directory: \"$gdbSourceDir\"" >&2
91 exit 1
95 # create the output dir
96 mkdir -p "$installDir" || exit 1
99 # get absolute paths
100 currentDir=$(pwd)
102 cd "$haikuSourceDir"
103 haikuSourceDir=$(pwd)
104 cd "$currentDir"
106 cd "$buildToolsDir"
107 buildToolsDir=$(pwd)
108 cd "$currentDir"
110 cd "$installDir"
111 installDir=$(pwd)
112 cd "$currentDir"
114 if [ -n "$gdbSourceDir" ]; then
115 cd "$gdbSourceDir"
116 gdbSourceDir=$(pwd)
117 cd "$currentDir"
120 binutilsSourceDir="$buildToolsDir/binutils"
121 gccSourceDir="$buildToolsDir/gcc"
124 # get gcc version
125 gccVersion=$(cat "$gccSourceDir/gcc/BASE-VER")
127 if [ -z "$gccVersion" ]; then
128 echo "Failed to find out gcc version." >&2
129 exit 1
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
135 # to the VCS).
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
179 export LC_ALL=POSIX
181 # build gdb
182 if [ -n "$HAIKU_USE_GDB" ]; then
183 cd "$gdbObjDir"
184 "$gdbSourceDir/configure" \
185 --prefix="$installDir" --target=$gdbTarget \
186 $gdbConfigureArgs \
187 || exit 1
188 $MAKE $additionalMakeArgs || exit 1
189 $MAKE $additionalMakeArgs install || exit 1
192 # build binutils
193 cd "$binutilsObjDir"
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 \
200 || exit 1
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
207 # build gmp
208 cd "$gmpObjDir"
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
214 # build isl
215 cd "$islObjDir"
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
222 # build cloog
223 cd "$cloogObjDir"
224 CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$cloogSourceDir/configure" \
225 --prefix="$installDir" --disable-nls --disable-shared \
226 --with-gmp-prefix="$installDir" --with-isl-prefix=="$installDir" \
227 || exit 1
228 $MAKE $additionalMakeArgs || exit 1
229 $MAKE $additionalMakeArgs install || exit 1
232 # build gcc
234 # prepare the include files
235 copy_headers()
237 sourceDir=$1
238 targetDir=$2
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"
246 done
249 copy_headers "$haikuSourceDir/headers/config" "$tmpIncludeDir/config"
250 copy_headers "$haikuSourceDir/headers/os" "$tmpIncludeDir/os"
251 copy_headers "$haikuSourceDir/headers/posix" "$tmpIncludeDir/posix"
253 # configure gcc
254 cd "$gccObjDir"
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" \
262 $gccConfigureArgs \
263 || exit 1
265 # make gcc
266 $MAKE $additionalMakeArgs || {
267 echo "ERROR: Building gcc failed." >&2
268 exit 1
271 # install gcc
272 $MAKE $additionalMakeArgs install || {
273 echo "ERROR: Installing the cross compiler failed." >&2
274 exit 1
277 case $haikuMachine in
278 x86_64-*)
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
285 esac
287 # cleanup
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
294 rm -rf "$sysrootDir"
296 # remove the objects dir
297 rm -rf "$objDir"
300 echo "binutils and gcc for cross compilation have been built successfully!"