# 
# Copyright (C) 2009 DrayTek Corp.
#
# This is not free software, 
#

include $(TOPDIR)/rules.mk

PKG_NAME:=madwimax
PKG_VERSION:=0.1.1
PKG_RELEASE:=1

include $(INCLUDE_DIR)/package.mk

define Package/madwimax
  SECTION:=driver
  CATEGORY:=Network
  TITLE:=Wimax Driver
  URL:=http://code.google.com/p/madwimax/
  PKG_BUILD_DEPENDS:=+libusb-1.0 +libopenssl
endef

define Package/madwimax/description
	madWiMAX is a reverse-engineered Linux driver for mobile WiMAX (802.16e) devices based on Samsung CMC-730 chip
endef

#
# copy the source code to build folder
#
define Build/Prepare
	@echo "Preparing...................." 
	mkdir -p $(PKG_BUILD_DIR)/src $(PKG_BUILD_DIR)/files
	$(CP) src/* $(PKG_BUILD_DIR)/src
	$(CP) files/* $(PKG_BUILD_DIR)/files
endef
 
EX_LIBS  = -L$(STAGING_DIR)/usr/lib -lpthread -lusb-1.0 -lcrypto -lssl
LDFLAGS += -L$(BUILD_DIR)openssl-0.9.8h
INCLUDES = -I$(STAGING_DIR)/usr/include
INCLUDES += -I$(STAGING_DIR)/usr/include/libusb-1.0
INCLUDES += -I$(BUILD_DIR)/openssl-0.9.8h -I$(BUILD_DIR)/openssl-0.9.8h/include
INCLUDES += -I$(TOPDIR)/package/madwimax/src

TARGET_CFLAGS += $(INCLUDES) -g
#TARGET_CFLAGS += $(INCLUDES)


define Build/Compile
	@echo "Compile..................."
	$(MAKE) -C $(PKG_BUILD_DIR)/src \
		CC="$(TARGET_CC)" \
		CFLAGS="$(TARGET_CFLAGS)"
endef

#
# $(1) = /build_dir/arm/madwimax-0.1.1/ipkg/madwimax
#
define Package/madwimax/install
	@echo "Install.................."
	$(INSTALL_DIR)  $(1)/usr/sbin $(1)/etc/init.d $(1)/etc/rc.d $(1)/dev/net
	$(INSTALL_BIN)  $(PKG_BUILD_DIR)/src/madwimax $(1)/usr/sbin
	$(INSTALL_BIN)  $(PKG_BUILD_DIR)/files/madwimax_init $(1)/etc/init.d
	ln -sf ../init.d/madwimax_init $(1)/etc/rc.d/S99madwimax_init
	chmod 777 $(1)/etc/rc.d/S99madwimax_init
	$(INSTALL_DIR) $(1)/lib/network
	$(INSTALL_DATA) ./files/Wimax.sh $(1)/lib/network/Wimax.sh
	$(INSTALL_DIR) $(1)/etc/hotplug.d/usb
	$(INSTALL_DATA) $(PKG_BUILD_DIR)/files/madwimax.usb $(1)/etc/hotplug.d/usb/05-madwimax
	$(INSTALL_DATA) ./files/run_wimax.sh $(1)/usr/sbin/run_wimax.sh
	chmod 777 $(1)/usr/sbin/run_wimax.sh
endef
 
$(eval $(call BuildPackage,madwimax))

