3 # Parameters <haiku sourcedir> <buildtools dir> <install dir>
4 # Influential environmental variable:
5 # * haikuRequiredLegacyGCCVersion: The required version of the gcc. Will be
6 # checked against the version in the buildtools directory.
8 # get and check the parameters
10 echo Usage
: $0 '<haiku sourcedir> <buildtools dir> <install dir>' >&2
15 buildToolsDir
=$2/legacy
19 # Note: The gcc 2 build has trouble with -jN N > 1, hence we only use the
20 # additional flags for the binutils build. Should there ever be any other
21 # flags than -jN, we need to handle this differently.
23 if [ `uname -s` = 'Haiku' ]; then
24 # force cross-build if building on Haiku:
25 buildhostMachine
=i586-pc-haiku_buildhost
26 buildHostSpec
="--build=$buildhostMachine --host=$buildhostMachine"
29 if [ ! -d $haikuSourceDir ]; then
30 echo "ERROR: No such directory: \"$haikuSourceDir\"" >&2
34 if [ ! -d $buildToolsDir ]; then
35 echo "ERROR: No such directory: \"$buildToolsDir\"" >&2
39 # verify or extract the gcc version
40 gccVersionDotC
="$buildToolsDir/gcc/gcc/version.c"
41 if [ -n "$haikuRequiredLegacyGCCVersion" ]; then
42 # haikuRequiredLegacyGCCVersion has been specified. Check whether the
43 # version of the gcc in the given build tools directory matches.
44 if ! grep "$haikuRequiredLegacyGCCVersion" \
45 "$gccVersionDotC" >/dev
/null
2>&1 ; then
46 echo "*** Mismatching compiler versions between configure script and" \
48 echo "*** $gccVersionDotC" >&2
49 echo "*** Did you perhaps update only one of haiku & buildtools?" >&2
53 # haikuRequiredLegacyGCCVersion wasn't specified. Extract the version string
54 # from the gcc's version.c.
55 haikuRequiredLegacyGCCVersion
=`grep "2.95.3-haiku-" "$gccVersionDotC" \
56 | sed 's@.*\"\(.*\)\".*@\1@'`
57 if [ -z "$haikuRequiredLegacyGCCVersion" ]; then
58 echo "ERROR: Failed to extract version string from $gccVersionDotC" >&2
64 # create the output dir
65 mkdir
-p $installDir ||
exit 1
84 # create the object and installation directories for the cross compilation tools
85 objDir
=${installDir}-build
86 binutilsObjDir
=$objDir/binutils
88 tmpIncludeDir
=$objDir/sysincludes
89 tmpLibDir
=$objDir/syslibs
91 rm -rf $installDir $objDir
93 mkdir
-p $installDir $objDir $binutilsObjDir $gccObjDir $tmpIncludeDir \
95 mkdir
-p $installDir/lib
/gcc-lib
/i586-pc-haiku
/$haikuRequiredLegacyGCCVersion
98 if [ -n "$SECONDARY_ARCH" ]; then
99 gccConfigureArgs
="$gccConfigureArgs --with-hybrid-secondary=$SECONDARY_ARCH"
102 # force the POSIX locale, as the build (makeinfo) might choke otherwise
105 # drop an multiple job arguments from MAKEFLAGS
106 if [ ! -z "$MAKEFLAGS" ]; then
107 export MAKEFLAGS
=$
(echo $MAKEFLAGS |
sed -e 's/-j\s*[0-9][0-9]*//g')
113 CFLAGS
="-O2" CXXFLAGS
="-O2" $buildToolsDir/binutils
/configure \
114 --prefix=$installDir $buildHostSpec --target=i586-pc-haiku \
115 --disable-nls --enable-shared=yes --disable-werror ||
exit 1
116 $MAKE $additionalMakeArgs ||
exit 1
117 $MAKE $additionalMakeArgs install ||
exit 1
119 PATH
=$PATH:$installDir/bin
125 # prepare the include files
131 headers
="`find $sourceDir -name \*\.h`"
132 headers
="`echo $headers | sed -e s@$sourceDir/@@g`"
133 for f
in $headers; do
134 headerTargetDir
=$targetDir/`dirname $f`
135 mkdir
-p $headerTargetDir
136 cp $sourceDir/$f $headerTargetDir
140 copy_headers
$haikuSourceDir/headers
/config
$tmpIncludeDir/config
141 copy_headers
$haikuSourceDir/headers
/os
$tmpIncludeDir/os
142 copy_headers
$haikuSourceDir/headers
/posix
$tmpIncludeDir/posix
144 # Touch some files generated by bison, so that bison won't run to update them.
145 # Fixes issues with newer bison versions.
146 # And while at it, touch gperf target, too (as gperf may not be installed)
147 (cd $buildToolsDir/gcc
/gcc
; touch c-parse.c c-parse.h cexp.c cp
/parse.c \
148 cp
/parse.h c-gperf.h
)
154 # GCC 2 compiled for x86_64 OS X is broken, compile for i386.
155 export CC
="gcc -arch i386"
158 CFLAGS
="-O2 -U_FORTIFY_SOURCE" CXXFLAGS
="-O2" $buildToolsDir/gcc
/configure \
159 --prefix=$installDir $buildHostSpec --target=i586-pc-haiku \
160 --disable-nls --enable-shared=yes --enable-languages=c
,c
++ \
161 --with-headers=$tmpIncludeDir --with-libs=$tmpLibDir $gccConfigureArgs \
165 # hack the Makefile to avoid trouble with stuff we don't need anyway
167 for toRemove
in libiberty libio libjava libobjc libstdc
++; do
168 sedExpr
="$sedExpr -e 's@^\(TARGET_CONFIGDIRS =.*\)$toRemove\(.*\)@\1\2@'"
170 echo sedExpr
: $sedExpr
171 mv Makefile Makefile.bak ||
exit 1
172 eval "sed $sedExpr Makefile.bak > Makefile" ||
exit 1
177 echo "ERROR: Building gcc failed." >&2
182 $MAKE install-gcc-cross ||
{
183 echo "ERROR: Installing the cross compiler failed." >&2
187 # Remove the math.h gcc header. It has been generated by fixincludes
188 # (unconditional hack: math_huge_val_ifndef) from ours and it is semantically
190 rm -f $installDir/lib
/gcc-lib
/i586-pc-haiku
/$haikuRequiredLegacyGCCVersion/include
/math.h
192 # Symlink the built-in C++ headers path to the sys-include directory. This is
193 # not actually needed for cross compiling Haiku itself, but simplifies using the
194 # cross compiler for building the bootstrap packages.
195 (cd $installDir/include
; ln -s ..
/i586-pc-haiku
/sys-include
/c
++/2.95.3 g
++)
200 # remove the system headers from the installation dir
201 # Only the ones from the source tree should be used.
202 rm -rf $installDir/i586-pc-haiku
/sys-include
204 # remove the objects dir
208 echo "binutils and gcc for cross compilation have been built successfully!"