#!/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 [ "$AVAHI_DAEMON" = yes ]; then
  SMB_AVAHI="--enable-avahi"
else
  SMB_AVAHI="--disable-avahi"
fi

CFLAGS="$CFLAGS -fPIC -DPIC"

cd $PKG_BUILD/source3

sh autogen.sh

ac_cv_file__proc_sys_kernel_core_pattern=yes \
libreplace_cv_HAVE_C99_VSNPRINTF=yes \
libreplace_cv_HAVE_GETADDRINFO=yes \
libreplace_cv_HAVE_IFACE_IFCONF=yes \
LINUX_LFS_SUPPORT=yes \
samba_cv_CC_NEGATIVE_ENUM_VALUES=yes \
samba_cv_HAVE_GETTIMEOFDAY_TZ=yes \
samba_cv_HAVE_IFACE_IFCONF=yes \
samba_cv_HAVE_KERNEL_OPLOCKS_LINUX=yes \
samba_cv_HAVE_SECURE_MKSTEMP=yes \
samba_cv_HAVE_WRFILE_KEYTAB=no \
samba_cv_USE_SETREUID=yes \
samba_cv_USE_SETRESUID=yes \
samba_cv_have_setreuid=yes \
samba_cv_have_setresuid=yes \
./configure --host=$TARGET_NAME \
            --build=$HOST_NAME \
            --prefix=/usr \
            --localstatedir=/var \
            --sysconfdir=/etc \
            --with-configdir=/etc/samba \
            --with-privatedir=/var/run \
            --with-codepagedir=/etc/samba \
            --with-lockdir=/var/lock \
            --with-logfilebase=/var/log \
            --with-nmbdsocketdir=/var/nmbd \
            --with-piddir=/var/run \
            --enable-shared \
            --disable-static \
            --disable-shared-libs \
            --disable-debug \
            --with-libiconv="$SYSROOT_PREFIX/usr" \
            --disable-krb5developer \
            --disable-picky-developer \
            --enable-largefile \
            --with-pthreads \
            --disable-socket-wrapper \
            --disable-nss-wrapper \
            --disable-swat \
            --disable-cups \
            --disable-iprint \
            --disable-pie \
            --disable-relro \
            --disable-fam \
            --disable-dnssd \
            $SMB_AVAHI \
            --disable-pthreadpool \
            --enable-gnutls \
            --disable-netapi \
            --disable-dmalloc \
            --with-fhs \
            --without-libtalloc \
            --disable-external-libtalloc \
            --without-libtdb \
            --disable-external-libtdb \
            --without-libnetapi \
            --with-libsmbclient \
            --without-libsmbsharemodes \
            --without-libaddns \
            --without-afs \
            --without-fake-kaserver \
            --without-vfs-afsacl \
            --without-dce-dfs \
            --without-ldap \
            --without-ads \
            --without-dnsupdate \
            --without-automount \
            --without-cifsmount \
            --without-cifsumount \
            --without-cifsupcall \
            --without-krb5 \
            --without-pam \
            --without-pam_smbpass \
            --without-nisplus-home \
            --with-syslog \
            --without-quotas \
            --without-sys-quotas \
            --without-utmp \
            --without-cluster-support \
            --without-acl-support \
            --without-aio-support \
            --with-sendfile-support \
            --without-wbclient \
            --without-winbind \
            --with-included-popt \
            --with-included-iniparser \
            --without-sqlite3 \
            --without-setproctitle \

make bin/libtalloc.a
make bin/libwbclient.a
make bin/libtdb.a
make bin/libsmbclient.a

if [ "$SAMBA_SERVER" = "yes" ]; then
  make bin/samba_multicall
fi

mkdir -p $SYSROOT_PREFIX/usr/lib
  cp -P bin/*.a $SYSROOT_PREFIX/usr/lib

mkdir -p $SYSROOT_PREFIX/usr/include
  cp include/libsmbclient.h $SYSROOT_PREFIX/usr/include

mkdir -p $SYSROOT_PREFIX/usr/lib/pkgconfig
  cp pkgconfig/smbclient.pc $SYSROOT_PREFIX/usr/lib/pkgconfig
