#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:=ltedriver
PKG_VERSION:=1.0
#-------------------------------------------------------------------------------

include $(INCLUDE_DIR)/package.mk


# definition shared by all modules
define KernelPackage/ltedriver/Default
  SUBMENU:=Other modules
  TITLE:=LTE driver
  DEPENDS:=@LINUX_2_6 
endef

#definition of ltedrv.ko
define KernelPackage/ltedriver
$(call KernelPackage/ltedriver/Default)
  FILES:=$(PKG_BUILD_DIR)/lte_drv.$(LINUX_KMOD_SUFFIX)
  AUTOLOAD:=$(call AutoLoad,99,lte_drv)
endef

#install stuffs
define KernelPackage/ltedriver/install
	@echo "LTE Driver Install...................."
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) -m 755 ./files/ltedrvinit $(1)/etc/init.d
	$(INSTALL_DIR) $(1)/etc/rc.d
	ln -sf ../init.d/ltedrvinit  $(1)/etc/rc.d/S50ltedrvinit
	chmod 777 $(1)/etc/rc.d/S50ltedrvinit
endef



#
# variables to pass to make program, can be used by src/Makefile
# NOTE: do not have white space before and after "="
#
MY_EXTRA_KCONFIG:= 

#
#extra compile flags (-Ipath -Dflag ...) to be appended to $(CFLAGS)
#
#MY_EXTRA_CFLAGS:= -DBOARD_A5 -DCHIP_F4 -DADVANCE_API -DVIGOR_VDSL -DKERNEL_2_6 -DMODULE -DEXPORT_SYMTAB -D__KERNEL__ -D__linux__ -I$(LINUX_DIR)/include
MY_EXTRA_CFLAGS:=


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

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

#
# canned command sequence for building
#
define Build/Compile
	@echo "LTE Driver Compiling..................."
	$(MAKE) -C "$(LINUX_DIR)" \
		ARCH="$(LINUX_KARCH)" \
		CROSS_COMPILE="$(TARGET_CROSS)" \
		SUBDIRS="$(PKG_BUILD_DIR)" \
		EXTRA_CFLAGS="$(MY_EXTRA_CFLAGS)" \
		V="$(V)" \
		modules
endef

#
#evaluate all variables we defined 
#
$(eval $(call KernelPackage,ltedriver))

