#definition of system level variables BUILD_DIR, BIN_DIR, DL_DIR, PACKAGE_DIR......
     
include $(TOPDIR)/rules.mk

#definition of:
#   KernelPackage
#   AutoLoad
#   DownLoad
#   .....
include $(INCLUDE_DIR)/kernel.mk

#-------------------------------------------------------------------------------
#define your package name & version
#will create a folder in /build_dir/linux-vsc75xx/PKG_NAME-PKG_VERSION folder
#and copy source codes in /package/name/src to the folder for building the module
#the output will be a ipkg folder in the folder, package manager use the information
#in ipkg folder to create installation stuffs.
#PKG_NAME & PKG_VERSION must be defined before including pacakge.mk which references 
#them
#
PKG_NAME:=rt3070sta
PKG_VERSION:=0.99
#-------------------------------------------------------------------------------

include $(INCLUDE_DIR)/package.mk


#
# Define My Kernel Package
#
#

# definition shared by all modules
define KernelPackage/$(PKG_NAME)/Default
  SUBMENU:=Wireless Drivers
  TITLE:=$(PKG_NAME) package
  DEPENDS:=@LINUX_2_6 
endef

#definition of $(PKG_NAME).ko
define KernelPackage/$(PKG_NAME)
$(call KernelPackage/$(PKG_NAME)/Default)
  TITLE+= (Ralink RT3070 station mode driver)
  FILES:=$(PKG_BUILD_DIR)/rt3070sta.$(LINUX_KMOD_SUFFIX)
  AUTOLOAD:=$(call AutoLoad,50, rt3070sta)
endef

# mymod.ko installation stuffs
define KernelPackage/$(PKG_NAME)/install
	$(INSTALL_DIR) $(1)/etc/Wireless/RT3070STA
	$(INSTALL_BIN) -m 755 ./files/rt3070sta.dat $(1)/etc/Wireless/RT3070STA/rt3070sta.dat
#	$(INSTALL_DIR) $(1)/lib/wifi
#	$(INSTALL_BIN) -m 755 ./files/rt3070sta.sh $(1)/lib/wifi/rt3070sta.sh
	$(INSTALL_DIR) $(1)/etc/config
	$(INSTALL_BIN) -m 755 ./files/network $(1)/etc/config
	$(INSTALL_DIR) $(1)/etc/hotplug.d/usb
	$(INSTALL_BIN) -m 755 ./files/20-rt3070sta $(1)/etc/hotplug.d/usb/20-rt3070sta
#	$(INSTALL_DIR) $(1)/etc
#	$(INSTALL_BIN) -m 755 ./files/igmpproxy_with_wifi.conf $(1)/etc
#	$(INSTALL_BIN) -m 755 ./files/igmpproxy_without_wifi.conf $(1)/etc
#	$(INSTALL_BIN) -m 755 ./files/udhcpc.user $(1)/etc
#	$(INSTALL_DIR) $(1)/etc/hotplug.d/iface
#	$(INSTALL_BIN) -m 755 ./files/20-vtss_cgi_config $(1)/etc/hotplug.d/iface
endef


#
# canned command sequence for build preparation
#
define Build/Prepare
	$(call Build/Prepare/Default)
	$(CP) -R src/* $(PKG_BUILD_DIR)/
	@echo "Preparing...................."
endef

#
# canned command sequence for build configuration 
#
define Build/Configure
	@echo "Configuring..................."
endef

#
# canned command sequence for building
#
#MY_EXTRA_KCONFIG:= MY_KO_NAME=mymod

define Build/Compile
	@echo "Compiling..................."
	$(MAKE) -C "$(LINUX_DIR)" \
		ARCH="$(LINUX_KARCH)" \
		CROSS_COMPILE="$(TARGET_CROSS)" \
		SUBDIRS="$(PKG_BUILD_DIR)" \
		$(MY_EXTRA_KCONFIG) \
		EXTRA_CFLAGS="$(MY_EXTRA_CFLAGS)" \
		V="$(V)" \
		modules
endef

#
#evaluate all variables
#
$(eval $(call KernelPackage,$(PKG_NAME)))
