# Copyright (C) 2006-2009 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
# DANtes 03/21/10
include $(TOPDIR)/rules.mk   
	  
PKG_NAME:=accel-pptp
PKG_VERSION:=0.8.5-rc1
       
PKG_BUILD_DEPENDS=ppp
       
include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/package.mk
       
export PATH=$(TARGET_PATH):$PATH
       
define KernelPackage/accel-pptp
	SUBMENU:=Network Support
	DEPENDS:=@LINUX_2_6 +ppp-mod-pptp +pptpd-accl
	TITLE:=Accelerated PPTP
	FILES:= \
	$(PKG_BUILD_DIR)/kernel/driver/pptp.$(LINUX_KMOD_SUFFIX)
	AUTOLOAD:=$(call AutoLoad,41,pptp)
endef
       
define KernelPackage/accel-pptp/description
	A kernel based implementation of pptp.
endef

define Package/accel-pptp/Default
	SECTION:=net
	CATEGORY:=Network
	TITLE:=ACCEL-PPTP client
	URL:=http://accel-pptp.sourceforge.net/
	DEPENDS:=ppp
endef

       
define Package/accel-pptp/description
	This package contains a PPTP (Point-to-Point Tunneling Protocol) client.
endef
       
define Package/ppp-mod-pptp
	$(call Package/accel-pptp/Default)
	DEPENDS:=ppp +kmod-pppoe +kmod-ppp
	TITLE:=Accellerated PPTP plugin
endef

define Package/ppp-mod-pptp/description
	This package includes an accelerated PPTP (Point to point tunneling protocol) plugin for ppp
endef

define Package/pptpd-accl
	SECTION:=net
	CATEGORY:=Network
	DEPENDS:=+kmod-ppp +ppp @!PACKAGE_pptpd
	TITLE:=PopTop pptp server for ACCEL-PPTPD
	URL:=http://www.poptop.org/
	SUBMENU:=VPN
endef
       
define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	cp -f ./src/kernel/driver/if_pppox.h ./src/pptpd-1.3.3/if_pppox.h
	cp -f ./src/kernel/driver/if_pppox.h ./src/pppd_plugin/src/if_pppox.h	
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

      
define Build/Compile/kmod
	$(MAKE) -C $(LINUX_DIR) \
	CROSS_COMPILE="$(KERNEL_CROSS)" \
	ARCH="$(LINUX_KARCH)" \
	SUBDIRS="$(PKG_BUILD_DIR)/kernel/driver" \
	KDIR="$(LINUX_DIR)" \
	CC="$(TARGET_CC)" \
	EXTRA_CFLAGS="-I$(PKG_BUILD_DIR)/kernel/driver"
endef

define Build/Compile/pptpd-accl
	$(MAKE) -C "$(PKG_BUILD_DIR)/pptpd-1.3.3" \
	DESTDIR="$(PKG_INSTALL_DIR)" \
	INSTALL="install" \
	ARCH="$(LINUX_KARCH)" \
	CC="$(TARGET_CC)" \
	all install
endef

define Build/Compile/ppp-mod-pptp
	$(MAKE) -C $(PKG_BUILD_DIR)/pppd_plugin all
endef
       
define Build/Configure/ppp-mod-pptp
	$(call Build/Configure/Default, --enable-statics=no --enable-shared=yes,KDIR=$(LINUX_DIR) PPPD_VERSION=2.4.4,pppd_plugin )
endef

define Build/Configure/pptpd-accl
	$(call Build/Configure/Default, --enable-bcrelay, KDIR=$(LINUX_DIR) PPPD_VERSION=2.4.4,pptpd-1.3.3 )
endef
       
define Build/Configure
	$(Build/Configure/ppp-mod-pptp)
	$(Build/Configure/pptpd-accl)
endef

define Package/pptpd-accl/install
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/pptpd $(1)/usr/sbin/
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/pptpctrl $(1)/usr/sbin/
	$(INSTALL_DIR) $(1)/usr/lib/pptpd
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/pptpd/* $(1)/usr/lib/pptpd
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/* $(1)/usr/lib/
	$(INSTALL_DIR) $(1)/etc
	$(INSTALL_DATA) ./files/pptpd.conf $(1)/etc/
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) ./files/pptpd.init $(1)/etc/init.d/pptpd
	$(INSTALL_DIR) $(1)/etc/ppp
	$(INSTALL_DATA) ./files/options.pptpd $(1)/etc/ppp/
endef
       
define Package/ppp-mod-pptp/install
	$(INSTALL_DIR) $(1)/usr/lib/pppd/2.4.4
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/pppd_plugin/src/.libs/pptp.so.0.0.0 $(1)/usr/lib/pppd/2.4.4/pptp.so
endef
       
define Build/Compile
	$(Build/Compile/kmod)
	$(Build/Compile/ppp-mod-pptp)
	$(Build/Compile/pptpd-accl)
endef
       
$(eval $(call KernelPackage,accel-pptp))
$(eval $(call BuildPackage,ppp-mod-pptp))
$(eval $(call BuildPackage,pptpd-accl))
