updated optional package build script for gcc4 to make a cross compiler.

* --arch sets the target arch, defaults to x86
* --source-dir sets the Haiku root directory for headers.
* tested with ppc.
This commit is contained in:
Jérôme Duval 2012-03-18 15:31:41 +01:00
parent a2012848e3
commit e9b8ca373a

88
build-gcc4-optional-package-Haiku.sh Executable file → Normal file
View File

@ -20,7 +20,10 @@ gccSources="$buildtoolsDir/gcc"
buildDir="$currentDir/gcc-objects"
binutilsBuildDir="$buildDir/binutils"
gccBuildDir="$buildDir/gcc"
targetArch=x86
gccMakeTarget=bootstrap
gccConfigureArgs="--enable-shared"
binutilsConfigureArgs="--enable-shared=true"
# parse the arguments
jobArgs=
@ -28,6 +31,29 @@ while [ $# -gt 0 ]; do
case "$1" in
-h|--help) usage; exit 0;;
-j*) jobArgs="$1"; shift 1;;
--arch)
case "$2" in
x86) HAIKU_GCC_MACHINE=i586-pc-haiku;;
x86_64) HAIKU_GCC_MACHINE=x86_64-pc-haiku; targetArch=x86_64;
gccMakeTarget= ;;
ppc) HAIKU_GCC_MACHINE=powerpc-apple-haiku; targetArch=ppc;
gccMakeTarget= gccConfigureArgs="--disable-shared --disable-multilib"
binutilsConfigureArgs="--disable-shared --disable-multilib" ;;
m68k) HAIKU_GCC_MACHINE=m68k-unknown-haiku; targetArch=m68k;
gccMakeTarget= gccConfigureArgs="--disable-shared --disable-multilib"
binutilsConfigureArgs="--disable-shared --disable-multilib" ;;
arm) HAIKU_GCC_MACHINE=arm-unknown-haiku; targetArch=arm;
gccMakeTarget= gccConfigureArgs="--disable-shared --disable-multilib"
binutilsConfigureArgs="--disable-shared --disable-multilib" ;;
mipsel) HAIKU_GCC_MACHINE=mipsel-unknown-haiku; targetArch=mips;
gccMakeTarget= gccConfigureArgs="--disable-shared --disable-multilib"
binutilsConfigureArgs="--disable-shared --disable-multilib" ;;
*) echo "Unsupported target architecture: $2"
exit 1;;
esac
shift 2
targetCrossToolsMachine="--target=${HAIKU_GCC_MACHINE}";;
--source-dir) haikuSourceDir="$2"; shift 2;;
*) break;;
esac
done
@ -57,16 +83,8 @@ fi
gccVersionedName=gcc-${gccVersion}-haiku-${gccDate}
# get the architecture
gccArch=`uname -m`
case $gccArch in
BePC) gccArch=x86;;
*) echo "Unsupported architecture: '$gccArch'" >&2; exit 1;;
esac
# check whether the installation dir does already exit
installDir=/boot/develop/abi/$gccArch/gcc4/tools/$gccVersionedName
installDir=/boot/develop/abi/$targetArch/gcc4/tools/$gccVersionedName
if [ -e "$installDir" ]; then
echo "The installation directory '$installDir' does already exist." >&2
echo "Remove it first." >&2
@ -78,6 +96,7 @@ fi
echo "Building binutils and gcc optional packages from the source."
echo "sources: $buildtoolsDir"
echo "build dir: $buildDir"
echo "target arch: $targetArch"
echo "GCC date: $gccDate"
echo "GCC version: $gccVersion"
echo "install dir: $installDir"
@ -98,19 +117,44 @@ mkdir -p "$binutilsBuildDir" "$gccBuildDir"
# build and install the binutils
cd "$binutilsBuildDir"
CFLAGS="-O2" CXXFLAGS="-O2" "$binutilsSources/configure" \
--prefix="$installDir" --disable-nls --enable-shared=yes \
--with-htmldir=html-docs
--prefix="$installDir" $targetCrossToolsMachine --disable-nls \
$binutilsConfigureArgs --with-htmldir=html-docs
make $jobArgs
make install install-html
# prepare the include files
copy_headers()
{
sourceDir=$1
targetDir=$2
headers="$(find $sourceDir -name \*\.h | grep -v /.svn)"
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
}
if [ -n "$haikuSourceDir" ]; then
tmpIncludeDir=$currentDir/sysincludes
tmpLibDir=$currentDir/syslibs
mkdir -p $tmpIncludeDir $tmpLibDir
copy_headers $haikuSourceDir/headers/config $tmpIncludeDir/config
copy_headers $haikuSourceDir/headers/os $tmpIncludeDir/os
copy_headers $haikuSourceDir/headers/posix $tmpIncludeDir/posix
headersLibsArgs="--with-headers=$tmpIncludeDir --with-libs=$tmpLibDir"
fi
# build and install gcc
cd "$gccBuildDir"
CFLAGS="-O2" CXXFLAGS="-O2" "$gccSources/configure" \
--prefix="$installDir" --enable-shared --enable-languages=c,c++ \
--disable-nls --without-libiconv-prefix --disable-libstdcxx-pch \
--with-htmldir=html-docs --enable-frame-pointer
make $jobArgs bootstrap
--prefix="$installDir" $gccConfigureArgs --enable-languages=c,c++ \
$targetCrossToolsMachine --disable-nls --without-libiconv-prefix \
--disable-libstdcxx-pch --with-htmldir=html-docs --enable-lto \
--enable-frame-pointer $headersLibsArgs
make $jobArgs $gccMakeTarget
make install-strip install-html
@ -134,7 +178,7 @@ ln -s c++/$gccVersion $installDir/include/g++
gccVersionYear=20$(echo $gccDate | cut -c1-2)
gccVersionMonth=$(echo $gccDate | cut -c3-4)
gccVersionDay=$(echo $gccDate | cut -c5-6)
packageFile="$currentDir/gcc-${gccVersion}-${gccArch}-gcc4-${gccVersionYear}-${gccVersionMonth}-${gccVersionDay}.zip"
packageFile="$currentDir/gcc-${gccVersion}-${targetArch}-gcc4-${gccVersionYear}-${gccVersionMonth}-${gccVersionDay}.zip"
cd /boot
zip -ry "$packageFile" `echo $installDir | cut -d/ -f3-`
@ -142,16 +186,16 @@ zip -ry "$packageFile" `echo $installDir | cut -d/ -f3-`
# add the "current" version symlink
cd "$buildDir"
mkdir -p develop/abi/x86/gcc4/tools/
ln -s $gccVersionedName develop/abi/x86/gcc4/tools/current
zip -y "$packageFile" develop/abi/x86/gcc4/tools/current
mkdir -p develop/abi/$targetArch/gcc4/tools/
ln -s $gccVersionedName develop/abi/$targetArch/gcc4/tools/current
zip -y "$packageFile" develop/abi/$targetArch/gcc4/tools/current
# add the optional package description
cd "$buildDir"
echo "Package: GCC
Version: ${gccVersion}-haiku-${gccDate}
Copyright: 1988-2011 Free Software Foundation, Inc.
Version: ${gccVersion}-${targetArch}-haiku-${gccDate}
Copyright: 1988-2012 Free Software Foundation, Inc.
License: GNU GPL v3
License: GNU LGPL v3
URL: http://www.gnu.org/software/gcc/