#!/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

XORG_SRC="$PKG_BUILD/hw/xfree86"

get_graphicdrivers

if [ "$COMPOSITE_SUPPORT" = "yes" ]; then
  XORG_COMPOSITE="--enable-composite"
else
  XORG_COMPOSITE="--disable-composite"
fi

if [ "$XINERAMA_SUPPORT" = "yes" ]; then
  XORG_XINERAMA="--enable-xinerama"
else
  XORG_XINERAMA="--disable-xinerama"
fi

if [ "$OPENGL" = "Mesa" ]; then
  XORG_MESA="--enable-glx --enable-dri"
else
  XORG_MESA="--disable-glx --disable-dri"
fi

# hack to prevent a build error
  CFLAGS=`echo $CFLAGS | sed -e "s|-O3|-O2|" -e "s|-Ofast|-O2|"`
  LDFLAGS=`echo $LDFLAGS | sed -e "s|-O3|-O2|" -e "s|-Ofast|-O2|"`

cd $PKG_BUILD

./configure --host=$TARGET_NAME \
            --build=$HOST_NAME \
            --prefix=/usr \
            --sysconfdir=/etc \
            --localstatedir=/var \
            --datarootdir=/usr/share \
            --disable-static \
            --enable-shared \
            --disable-debug \
            --disable-silent-rules \
            --disable-strict-compilation \
            --enable-largefile \
            --enable-visibility \
            --disable-unit-tests \
            --disable-sparkle \
            --disable-install-libxf86config \
            --disable-xselinux \
            --enable-aiglx \
            --enable-glx-tls \
            --enable-registry \
            $XORG_COMPOSITE \
            $XORG_XINERAMA \
            --enable-mitshm \
            --disable-xres \
            --enable-record \
            --enable-xv \
            --disable-xvmc \
            --enable-dga \
            --disable-screensaver \
            --disable-xdmcp \
            --disable-xdm-auth-1 \
            $XORG_MESA \
            --enable-dri2 \
            --enable-xf86vidmode \
            --disable-xace \
            --disable-xcsecurity \
            --disable-tslib \
            --enable-dbe \
            --disable-xf86bigfont \
            --enable-dpms \
            --enable-config-udev \
            --disable-config-dbus \
            --disable-config-hal \
            --enable-xfree86-utils \
            --enable-xaa \
            --enable-vgahw \
            --enable-vbe \
            --enable-int10-module \
            --disable-windowswm \
            --enable-libdrm \
            --enable-xorg \
            --disable-dmx \
            --disable-xvfb \
            --disable-xnest \
            --disable-xquartz \
            --disable-standalone-xpbproxy \
            --disable-xwin \
            --disable-kdrive \
            --disable-xephyr \
            --disable-xfake \
            --disable-xfbdev \
            --enable-unix-transport \
            --disable-tcp-transport \
            --disable-local-transport \
            --disable-install-setuid \
            --disable-secure-rpc \
            --disable-docs \
            --disable-devel-docs \
            --with-int10=x86emu \
            --disable-ipv6 \
            --with-gnu-ld \
            --with-sha1=libcrypto \
            --with-os-vendor="OpenELEC.tv" \
            --with-module-dir=$XORG_PATH_MODULES \
            --with-xkb-path=$XORG_PATH_XKB \
            --with-xkb-output=/var/cache/xkb \
            --with-log-dir=/var/log \
            --with-fontrootdir=/usr/share/fonts \
            --with-default-font-path="/usr/share/fonts/misc,built-ins" \
            --with-serverconfig-path="/usr/lib/xserver" \
            --without-xmlto \
            --without-fop \

make
$MAKEINSTALL
