# $FreeWRT$
#-
# This file is part of the FreeWRT project. FreeWRT is copyrighted
# material, please see the LICENCE file in the top-level directory
# or at http://www.freewrt.org/licence for details.

include $(TOPDIR)/rules.mk

PKG_NAME:=		samba
PKG_VERSION:=		3.0.26a
PKG_RELEASE:=		1
PKG_MD5SUM:=		16b47e6add332e5ac4523fc88c381d06
PKG_INIT:=		80

PKG_SOURCE_URL:=	ftp://se.samba.org/pub/samba/stable \
			ftp://ftp.easynet.be/samba/stable

include $(TOPDIR)/mk/package.mk

ifeq ($(FWRT_SAMBA_CODEPAGE),)
PKG_CP:=ISO8859-1
else
PKG_CP:=$(FWRT_SAMBA_CODEPAGE)
endif

$(eval $(call PKG_template,SAMBA,samba,$(PKG_VERSION)-$(PKG_RELEASE),$(ARCH)))
$(eval $(call PKG_template,SAMBA_CLIENT,samba-client,$(PKG_VERSION)-$(PKG_RELEASE),$(ARCH)))
$(eval $(call PKG_template,SAMBA_PASSWD,samba-passwd,$(PKG_VERSION)-$(PKG_RELEASE),$(ARCH)))

$(WRKBUILD)/.configured:
	touch $@

$(WRKBUILD)/.built:
	(cd $(WRKBUILD)/source; rm -rf config.{cache,status}; \
		./autogen.sh; \
		$(TARGET_CONFIGURE_OPTS) \
		$(TARGET_CONFIGURE_ARGS) \
		samba_cv_HAVE_GETTIMEOFDAY_TZ=yes \
		samba_cv_USE_SETREUID=yes \
		samba_cv_HAVE_KERNEL_OPLOCKS_LINUX=yes \
		samba_cv_HAVE_KERNEL_OPLOCKS_LINUX=no \
		samba_cv_HAVE_IFACE_IFCONF=yes \
		SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=yes \
		libreplace_cv_READDIR_GETDIRENTRIES=no \
		libreplace_cv_READDIR_GETDENTS=no \
		linux_getgrouplist_ok=no \
		samba_cv_REPLACE_READDIR=no \
		samba_cv_HAVE_WRFILE_KEYTAB=no \
		./configure \
		--target=$(GNU_TARGET_NAME) \
		--host=$(GNU_TARGET_NAME) \
		--build=$(GNU_HOST_NAME) \
		--with-lockdir=/var/run/samba \
		--with-piddir=/var/run \
		--with-privatedir=/etc/samba \
		--with-logfilebase=/var/log/samba \
		--with-configdir=/etc/samba \
		--without-ldap \
		--without-libaddns \
		--with-included-popt \
		--with-included-iniparser \
		--with-smbmount \
		--disable-cups \
		--disable-static \
	);

	
	#$(MAKE) -C $(WRKBUILD)/source \
	#	bin/make_smbcodepage bin/make_unicodemap
	#(cd $(WRKBUILD)/source/bin ; \
	#	mv -f make_smbcodepage make_smbcodepage.old ; \
	#	mv -f make_unicodemap make_unicodemap.old ; \
	#);

	mkdir -p $(WRKBUILD)/usr/share/samba
	mkdir -p $(WRKBUILD)/var/log

	
	$(MAKE) -C $(WRKBUILD)/source
	$(MAKE) -C $(WRKBUILD)/source \
		prefix="$(WRKBUILD)/usr" \
		BASEDIR="$(WRKINST)/usr" \
		BINDIR="$(WRKINST)/usr/bin" \
		SBINDIR="$(WRKINST)/usr/bin" \
		LIBDIR="$(WRKINST)/usr/lib" \
		VARDIR="$(WRKINST)/var/log/samba" \
		MANDIR="$(WRKINST)/usr/share/man" \
		SWATDIR="$(WRKINST)/usr/swat" \
		LOCKDIR="$(WRKINST)/var/run/samba" \
		SAMBABOOK="$(WRKINST)/usr/swat/using_samba" \
		CODEPAGEDIR="$(WRKINST)/usr/share/samba" \
		installservers installbin installcifsmount

	touch $@

$(IPKG_SAMBA):
	install -d -m0755 $(IDIR_SAMBA)/etc/init.d
	install -m0755 ./files/samba.init $(IDIR_SAMBA)/etc/init.d/S$(PKG_INIT)samba
	install -d -m0755 $(IDIR_SAMBA)/etc/samba
	install -m0644 ./files/smb.conf $(IDIR_SAMBA)/etc/samba/smb.conf
	install -d -m0755 $(IDIR_SAMBA)/usr/sbin
	install -d -m0755 $(IDIR_SAMBA)/usr/share/samba
	$(INSTALL_BIN) $(WRKINST)/usr/bin/{nmbd,smbd} $(IDIR_SAMBA)/usr/sbin
#	install -m0644 $(WRKINST)/usr/share/samba/unicode_map.$(PKG_CP) \
#		$(IDIR_SAMBA)/usr/share/samba/
	$(RSTRIP) $(IDIR_SAMBA)
	$(IPKG_BUILD) $(IDIR_SAMBA) $(PACKAGE_DIR)

$(IPKG_SAMBA_PASSWD):
	install -d -m0755 $(IDIR_SAMBA_PASSWD)/usr/bin
	install -m0755 $(WRKINST)/usr/bin/smbpasswd $(IDIR_SAMBA_PASSWD)/usr/bin/
	$(RSTRIP) $(IDIR_SAMBA_PASSWD)
	$(IPKG_BUILD) $(IDIR_SAMBA_PASSWD) $(PACKAGE_DIR)

$(IPKG_SAMBA_CLIENT):
	install -d -m0755 $(IDIR_SAMBA_CLIENT)/usr/bin
	install -m0755 $(WRKINST)/usr/bin/smbclient $(IDIR_SAMBA_CLIENT)/usr/bin/
	$(RSTRIP) $(IDIR_SAMBA_CLIENT)
	$(IPKG_BUILD) $(IDIR_SAMBA_CLIENT) $(PACKAGE_DIR)
