#!/bin/sh

################################################################################
#      This file is part of OpenELEC - http://www.openelec.tv
#      Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
#
#  This Program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2, or (at your option)
#  any later version.
#
#  This Program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with OpenELEC.tv; see the file COPYING.  If not, write to
#  the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
#  http://www.gnu.org/copyleft/gpl.html
################################################################################

. config/options $1

if [ "$TARGET_ARCH" = "x86_64" ]; then
  WITH_64B_BFD="--enable-64-bit-bfd"
fi

setup_toolchain host

CPPFLAGS=""
CFLAGS=""
CXXFLAGS=""
LDFLAGS=""

# Disable PPL version check as the PPL major version number has been bumped so the check fails.
  PPL_CHECK="--disable-ppl-version-check"

cd $PKG_BUILD
mkdir -p objdir && cd objdir
../configure --host=$HOST_NAME \
             --build=$HOST_NAME \
             --target=$TARGET_NAME \
             --prefix=$ROOT/$TOOLCHAIN \
             --with-sysroot=$SYSROOT_PREFIX \
             --with-lib-path="$SYSROOT_PREFIX/lib:$SYSROOT_PREFIX/usr/lib" \
             --with-gmp=$ROOT/$TOOLCHAIN \
             --with-mpfr=$ROOT/$TOOLCHAIN \
             --with-ppl=$ROOT/$TOOLCHAIN \
             --with-cloog=$ROOT/$TOOLCHAIN \
             --disable-werror \
             --disable-multilib \
             --disable-libada \
             --disable-libssp \
             $PPL_CHECK \
             --enable-cloog-backend=isl \
             --enable-version-specific-runtime-libs \
             $WITH_64B_BFD \
             --enable-plugins \
             --disable-gold \
             --enable-ld \
             --enable-lto \
             --disable-nls

make configure-host
make

cp -v ../include/libiberty.h $SYSROOT_PREFIX/usr/include

make install
