#
# Copyright (C) 2008-2010 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.

include $(TOPDIR)/rules.mk

PKG_NAME:=samba3
PKG_VERSION:=3.0.24
PKG_RELEASE:=7
PKG_MD5SUM:=89273f67a6d8067cbbecefaa13747153

PKG_SOURCE_URL:=ftp://ftp.samba.org/pub/samba/old-versions/
PKG_SOURCE:=samba-$(PKG_VERSION).tar.gz
PKG_BUILD_DIR:=$(BUILD_DIR)/samba-$(PKG_VERSION)/

include $(INCLUDE_DIR)/package.mk

TARGET_CFLAGS+=$(if $(CONFIG_SAMBA3_DEBUG),-DSAMBA_DEBUG)

define Package/samba3
  SECTION:=net
  CATEGORY:=Network
  SUBMENU:=Filesystem
  TITLE:=samba3
  DEPENDS:=+libpthread
  URL:=http://www.samba.org/
endef

define Package/samba3/Description
  Samba3 - made small with patches taken from AVM GPL releases and freetz 
endef

define Package/samba3/conffiles
	/etc/config/samba
	/etc/samba/smb.conf.template
endef

define Package/samba3/config
	source "$(SOURCE)/Config.in"
endef

define Build/Prepare/LFS
endef

define Build/Prepare
	$(call Build/Prepare/Default)
	### ctc ###
	if [ -d ./src/ ] ; then \
		$(CP) ./src/*  $(PKG_BUILD_DIR)/. ; \
	fi
	###########
endef

define Build/Configure
	### ctc ###
#	[ -f "$(PKG_BUILD_DIR)/source/include/config.h.save" ] || \
#		$(CP) $(PKG_BUILD_DIR)/source/include/config.h \
#			$(PKG_BUILD_DIR)/source/include/config.h.save
#	cat \
#		$(PKG_BUILD_DIR)/source/include/config.h.save \
#		./files/config-lfs.h >> $(PKG_BUILD_DIR)/source/include/config.h
	###########
	$(Build/Configure/Default)
endef

define Build/Compile
	CC="$(TARGET_CC)" \
	CFLAGS="$(TARGET_CFLAGS)" \
	CPPFLAGS="$(TARGET_CPPFLAGS)" \
	LDFLAGS="$(TARGET_LDFLAGS)" \
	$(MAKE) -C $(PKG_BUILD_DIR)/source \
		$(TARGET_CONFIGURE_OPTS) \
		all bin/nmbd
endef

define Package/samba3/install
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) ./files/sambacfg.sh $(1)/usr/sbin/sambacfg.sh
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) ./files/samba_default_set.sh $(1)/usr/sbin/samba_default_set.sh
	$(INSTALL_DIR) $(1)/etc/{samba,init.d,config}
	$(INSTALL_BIN) ./files/samba.init $(1)/etc/init.d/samba
	$(INSTALL_DATA) ./files/samba.config $(1)/etc/config/samba
	$(INSTALL_DATA) ./files/smb.conf.template $(1)/etc/samba/
	$(INSTALL_DATA) ./files/smbpasswd.tmp $(1)/etc/samba/
	### ctc ###
	$(INSTALL_DATA) ./files/smb.conf.debug $(1)/etc/samba/
	cd $(1)/etc/samba; rm -f smb.conf; ln -sf /tmp/smb.conf; ln -sf /tmp/smbpasswd

#	touch $(1)/etc/samba/smbpasswd
	###########
	$(INSTALL_DIR) $(1)/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/source/bin/smbpasswd $(1)/bin/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/source/bin/smbd $(1)/bin/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/source/bin/nmbd $(1)/bin/
endef

$(eval $(call BuildPackage,samba3))
