2005-11-07 12:43:46 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-07-26 01:52:11 +04:00
|
|
|
# Parameters <haiku sourcedir> <buildtools dir> <install dir>
|
2011-11-03 18:22:31 +04:00
|
|
|
# Influential environmental variable:
|
2011-11-22 17:12:23 +04:00
|
|
|
# * haikuRequiredLegacyGCCVersion: The required version of the gcc. Will be
|
2011-11-03 18:22:31 +04:00
|
|
|
# checked against the version in the buildtools directory.
|
2005-10-29 20:27:43 +04:00
|
|
|
|
|
|
|
# get and check the parameters
|
2009-11-23 22:34:55 +03:00
|
|
|
if [ $# -lt 3 ]; then
|
2013-07-26 01:52:11 +04:00
|
|
|
echo Usage: $0 '<haiku sourcedir> <buildtools dir> <install dir>' >&2
|
2005-10-29 20:27:43 +04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
haikuSourceDir=$1
|
2005-11-23 02:34:51 +03:00
|
|
|
buildToolsDir=$2/legacy
|
2013-07-26 01:52:11 +04:00
|
|
|
installDir=$3
|
2009-11-23 22:34:55 +03:00
|
|
|
shift 3
|
|
|
|
additionalMakeArgs=$*
|
2010-01-10 18:48:09 +03:00
|
|
|
# Note: The gcc 2 build has trouble with -jN N > 1, hence we only use the
|
|
|
|
# additional flags for the binutils build. Should there ever be any other
|
|
|
|
# flags than -jN, we need to handle this differently.
|
2005-10-29 20:27:43 +04:00
|
|
|
|
2013-09-14 22:55:53 +04:00
|
|
|
if [ `uname -s` = 'Haiku' ]; then
|
2013-06-14 18:04:26 +04:00
|
|
|
# force cross-build if building on Haiku:
|
|
|
|
buildhostMachine=i586-pc-haiku_buildhost
|
|
|
|
buildHostSpec="--build=$buildhostMachine --host=$buildhostMachine"
|
|
|
|
fi
|
2005-10-29 20:27:43 +04:00
|
|
|
|
|
|
|
if [ ! -d $haikuSourceDir ]; then
|
2011-11-03 18:22:31 +04:00
|
|
|
echo "ERROR: No such directory: \"$haikuSourceDir\"" >&2
|
2005-10-29 20:27:43 +04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d $buildToolsDir ]; then
|
2011-11-03 18:22:31 +04:00
|
|
|
echo "ERROR: No such directory: \"$buildToolsDir\"" >&2
|
2005-10-29 20:27:43 +04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-11-03 18:22:31 +04:00
|
|
|
# verify or extract the gcc version
|
|
|
|
gccVersionDotC="$buildToolsDir/gcc/gcc/version.c"
|
|
|
|
if [ -n "$haikuRequiredLegacyGCCVersion" ]; then
|
|
|
|
# haikuRequiredLegacyGCCVersion has been specified. Check whether the
|
|
|
|
# version of the gcc in the given build tools directory matches.
|
|
|
|
if ! grep "$haikuRequiredLegacyGCCVersion" \
|
|
|
|
"$gccVersionDotC" >/dev/null 2>&1 ; then
|
|
|
|
echo "*** Mismatching compiler versions between configure script and" \
|
|
|
|
>&2
|
|
|
|
echo "*** $gccVersionDotC" >&2
|
|
|
|
echo "*** Did you perhaps update only one of haiku & buildtools?" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# haikuRequiredLegacyGCCVersion wasn't specified. Extract the version string
|
|
|
|
# from the gcc's version.c.
|
|
|
|
haikuRequiredLegacyGCCVersion=`grep "2.95.3-haiku-" "$gccVersionDotC" \
|
|
|
|
| sed 's@.*\"\(.*\)\".*@\1@'`
|
|
|
|
if [ -z "$haikuRequiredLegacyGCCVersion" ]; then
|
|
|
|
echo "ERROR: Failed to extract version string from $gccVersionDotC" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2010-08-27 04:57:11 +04:00
|
|
|
fi
|
|
|
|
|
2005-10-29 20:27:43 +04:00
|
|
|
|
|
|
|
# create the output dir
|
2013-07-26 01:52:11 +04:00
|
|
|
mkdir -p $installDir || exit 1
|
2005-10-29 20:27:43 +04:00
|
|
|
|
|
|
|
|
|
|
|
# get absolute paths
|
2008-04-12 06:40:10 +04:00
|
|
|
currentDir=`pwd`
|
2005-10-29 20:27:43 +04:00
|
|
|
|
|
|
|
cd $haikuSourceDir
|
2008-04-12 06:40:10 +04:00
|
|
|
haikuSourceDir=`pwd`
|
2005-10-29 20:27:43 +04:00
|
|
|
cd $currentDir
|
|
|
|
|
|
|
|
cd $buildToolsDir
|
2008-04-12 06:40:10 +04:00
|
|
|
buildToolsDir=`pwd`
|
2005-10-29 20:27:43 +04:00
|
|
|
cd $currentDir
|
|
|
|
|
2013-07-26 01:52:11 +04:00
|
|
|
cd $installDir
|
|
|
|
installDir=`pwd`
|
|
|
|
cd $currentDir
|
2005-10-29 20:27:43 +04:00
|
|
|
|
|
|
|
|
|
|
|
# create the object and installation directories for the cross compilation tools
|
2013-07-26 01:52:11 +04:00
|
|
|
objDir=${installDir}-build
|
2005-10-29 20:27:43 +04:00
|
|
|
binutilsObjDir=$objDir/binutils
|
|
|
|
gccObjDir=$objDir/gcc
|
|
|
|
tmpIncludeDir=$objDir/sysincludes
|
|
|
|
tmpLibDir=$objDir/syslibs
|
|
|
|
|
|
|
|
rm -rf $installDir $objDir
|
|
|
|
|
|
|
|
mkdir -p $installDir $objDir $binutilsObjDir $gccObjDir $tmpIncludeDir \
|
|
|
|
$tmpLibDir || exit 1
|
2008-03-24 02:06:23 +03:00
|
|
|
mkdir -p $installDir/lib/gcc-lib/i586-pc-haiku/$haikuRequiredLegacyGCCVersion
|
2005-10-29 20:27:43 +04:00
|
|
|
|
2013-08-17 11:31:57 +04:00
|
|
|
gccConfigureArgs=
|
|
|
|
if [ -n "$SECONDARY_ARCH" ]; then
|
|
|
|
gccConfigureArgs="$gccConfigureArgs --with-hybrid-secondary=$SECONDARY_ARCH"
|
|
|
|
fi
|
|
|
|
|
2012-11-08 00:38:03 +04:00
|
|
|
# force the POSIX locale, as the build (makeinfo) might choke otherwise
|
|
|
|
export LC_ALL=POSIX
|
|
|
|
|
2012-11-24 00:10:24 +04:00
|
|
|
# drop an multiple job arguments from MAKEFLAGS
|
|
|
|
if [ ! -z "$MAKEFLAGS" ]; then
|
|
|
|
export MAKEFLAGS=$(echo $MAKEFLAGS | sed -e 's/-j\s*[0-9][0-9]*//g')
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2005-10-29 20:27:43 +04:00
|
|
|
# build binutils
|
|
|
|
cd $binutilsObjDir
|
|
|
|
CFLAGS="-O2" CXXFLAGS="-O2" $buildToolsDir/binutils/configure \
|
2013-06-14 18:04:26 +04:00
|
|
|
--prefix=$installDir $buildHostSpec --target=i586-pc-haiku \
|
|
|
|
--disable-nls --enable-shared=yes --disable-werror || exit 1
|
2013-08-22 14:31:48 +04:00
|
|
|
$MAKE $additionalMakeArgs || exit 1
|
|
|
|
$MAKE $additionalMakeArgs install || exit 1
|
2005-10-29 20:27:43 +04:00
|
|
|
|
2008-04-12 06:45:21 +04:00
|
|
|
PATH=$PATH:$installDir/bin
|
|
|
|
export PATH
|
2005-10-29 20:27:43 +04:00
|
|
|
|
|
|
|
|
|
|
|
# build gcc
|
|
|
|
|
|
|
|
# prepare the include files
|
|
|
|
copy_headers()
|
|
|
|
{
|
|
|
|
sourceDir=$1
|
|
|
|
targetDir=$2
|
|
|
|
|
2012-10-31 01:29:10 +04:00
|
|
|
headers="`find $sourceDir -name \*\.h`"
|
2008-04-12 06:40:10 +04:00
|
|
|
headers="`echo $headers | sed -e s@$sourceDir/@@g`"
|
2005-10-29 20:27:43 +04:00
|
|
|
for f in $headers; do
|
2008-04-12 06:40:10 +04:00
|
|
|
headerTargetDir=$targetDir/`dirname $f`
|
2005-10-29 20:27:43 +04:00
|
|
|
mkdir -p $headerTargetDir
|
|
|
|
cp $sourceDir/$f $headerTargetDir
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2009-11-24 22:44:07 +03:00
|
|
|
copy_headers $haikuSourceDir/headers/config $tmpIncludeDir/config
|
2009-07-07 14:30:09 +04:00
|
|
|
copy_headers $haikuSourceDir/headers/os $tmpIncludeDir/os
|
2005-10-29 20:27:43 +04:00
|
|
|
copy_headers $haikuSourceDir/headers/posix $tmpIncludeDir/posix
|
|
|
|
|
2011-11-15 22:45:48 +04:00
|
|
|
# Touch some files generated by bison, so that bison won't run to update them.
|
|
|
|
# Fixes issues with newer bison versions.
|
2011-11-23 01:28:09 +04:00
|
|
|
# And while at it, touch gperf target, too (as gperf may not be installed)
|
2011-11-15 23:22:23 +04:00
|
|
|
(cd $buildToolsDir/gcc/gcc; touch c-parse.c c-parse.h cexp.c cp/parse.c \
|
2011-11-23 01:28:09 +04:00
|
|
|
cp/parse.h c-gperf.h)
|
2011-11-15 22:45:48 +04:00
|
|
|
|
2005-10-29 20:27:43 +04:00
|
|
|
# configure gcc
|
|
|
|
cd $gccObjDir
|
2012-07-30 00:03:14 +04:00
|
|
|
case `uname` in
|
|
|
|
Darwin)
|
|
|
|
# GCC 2 compiled for x86_64 OS X is broken, compile for i386.
|
|
|
|
export CC="gcc -arch i386"
|
|
|
|
;;
|
|
|
|
esac
|
2008-10-31 15:46:49 +03:00
|
|
|
CFLAGS="-O2 -U_FORTIFY_SOURCE" CXXFLAGS="-O2" $buildToolsDir/gcc/configure \
|
2013-06-14 18:04:26 +04:00
|
|
|
--prefix=$installDir $buildHostSpec --target=i586-pc-haiku \
|
|
|
|
--disable-nls --enable-shared=yes --enable-languages=c,c++ \
|
2013-08-17 11:31:57 +04:00
|
|
|
--with-headers=$tmpIncludeDir --with-libs=$tmpLibDir $gccConfigureArgs \
|
2013-06-14 18:04:26 +04:00
|
|
|
|| exit 1
|
2012-07-30 00:03:14 +04:00
|
|
|
unset CC
|
2005-10-29 20:27:43 +04:00
|
|
|
|
|
|
|
# hack the Makefile to avoid trouble with stuff we don't need anyway
|
|
|
|
sedExpr=
|
|
|
|
for toRemove in libiberty libio libjava libobjc libstdc++; do
|
|
|
|
sedExpr="$sedExpr -e 's@^\(TARGET_CONFIGDIRS =.*\)$toRemove\(.*\)@\1\2@'"
|
|
|
|
done
|
|
|
|
echo sedExpr: $sedExpr
|
|
|
|
mv Makefile Makefile.bak || exit 1
|
|
|
|
eval "sed $sedExpr Makefile.bak > Makefile" || exit 1
|
|
|
|
rm Makefile.bak
|
|
|
|
|
|
|
|
# make gcc
|
2013-08-22 14:31:48 +04:00
|
|
|
$MAKE cross || {
|
2005-10-29 20:27:43 +04:00
|
|
|
echo "ERROR: Building gcc failed." >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# install gcc
|
2013-08-22 14:31:48 +04:00
|
|
|
$MAKE install-gcc-cross || {
|
2005-10-29 20:27:43 +04:00
|
|
|
echo "ERROR: Installing the cross compiler failed." >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2008-03-16 19:39:06 +03:00
|
|
|
# Remove the math.h gcc header. It has been generated by fixincludes
|
|
|
|
# (unconditional hack: math_huge_val_ifndef) from ours and it is semantically
|
|
|
|
# equivalent.
|
2011-11-23 20:02:23 +04:00
|
|
|
rm -f $installDir/lib/gcc-lib/i586-pc-haiku/$haikuRequiredLegacyGCCVersion/include/math.h
|
2008-03-16 19:39:06 +03:00
|
|
|
|
2013-07-17 03:02:40 +04:00
|
|
|
# Symlink the built-in C++ headers path to the sys-include directory. This is
|
|
|
|
# not actually needed for cross compiling Haiku itself, but simplifies using the
|
|
|
|
# cross compiler for building the bootstrap packages.
|
|
|
|
(cd $installDir/include; ln -s ../i586-pc-haiku/sys-include/c++/2.95.3 g++)
|
|
|
|
|
2005-10-29 20:27:43 +04:00
|
|
|
|
|
|
|
# cleanup
|
|
|
|
|
|
|
|
# remove the system headers from the installation dir
|
|
|
|
# Only the ones from the source tree should be used.
|
2013-06-14 18:07:06 +04:00
|
|
|
rm -rf $installDir/i586-pc-haiku/sys-include
|
2005-10-29 20:27:43 +04:00
|
|
|
|
|
|
|
# remove the objects dir
|
2010-08-27 04:58:34 +04:00
|
|
|
rm -rf $objDir
|
2005-10-29 20:27:43 +04:00
|
|
|
|
|
|
|
|
|
|
|
echo "binutils and gcc for cross compilation have been built successfully!"
|