#!/bin/sh

. config/options $1

if [ "$AVAHI_DAEMON" = yes ]; then
  SMB_AVAHI="--enable-avahi"
else
  SMB_AVAHI="--disable-avahi"
fi

export samba_cv_CC_NEGATIVE_ENUM_VALUES=no
export ac_cv_lib_avahi_client_avahi_client_new=yes

cd $PKG_BUILD/source3

sh autogen.sh
./configure --host=$TARGET_NAME \
            --build=$HOST_NAME \
            --prefix=/usr \
            --localstatedir=/var \
            --sysconfdir=/etc \
            --with-configdir=/etc/samba \
            --with-privatedir=/var/run \
            --enable-shared \
            --disable-static \
            --enable-shared-libs \
            --enable-debug \
            --disable-swat \
            --disable-cups \
            --disable-iprint \
            --with-fhs \
            --enable-pie \
            --with-pthreads \
            --with-sqlite3 \
            --enable-relro \
            --disable-dnssd \
            $SMB_AVAHI \
            --without-pam \
            --without-ads \
            --with-libtalloc \
            --without-libtdb \
            --without-libnetapi \
            --with-cifsmount \
            --with-cifsumount \
            --without-ldap \
            --without-acl-support \
            --with-winbind \
            --without-dnsupdate \
            --without-automount \
            --with-included-popt \
            --with-libsmbclient \
            --with-libsmbsharemodes \
            --without-quotas \
            --without-sys-quotas \
            --with-syslog \
            --without-utmp \
            --with-sendfile-support \

make bin/libsmbclient.so
make bin/mount.cifs
make bin/umount.cifs
make bin/smbtree

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

mkdir -p $SYSROOT_PREFIX/usr/lib
  cp -P bin/lib*client.so* $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
