include $(TOPDIR)/rules.mk

PKG_NAME:=BLE_e104bt52
VERSION_YEAR=$(shell date +%Y)
VERSION_MAJOR=$(shell expr $(VERSION_YEAR) - 2018)
VERSION_MINOR=$(shell date +%V%u)
#VERSION_REVISION=$(shell date +%H%M)
VERSION_REVISION=0000
PKG_VERSION:=$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_REVISION)


include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)
	SECTION:=DYIOT
	CATEGORY:=DYIOT Software
	SUBMENU:=BLE
	TITLE:=E104 BT52 BLE chip support
	DEPENDS:=+libuci +libdyutils +libubox
endef

define Package/$(PKG_NAME)/description
	Support receive the broadcast BLE package in the air and send it out for E104-BT52 BLE chip
endef

define Package/$(PKG_NAME)/conffiles
	/app/config/e104bt52.json
endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Build/Compile
	CC="$(TARGET_CC)" \
	CFLAGS="$(TARGET_CFLAGS)" \
	LDFLAGS="$(TARGET_LDFLAGS)" \
	$(MAKE) $(PKG_MFLAGS) -C $(PKG_BUILD_DIR) \
		$(TARGET_CONFIGURE_OPTS) \
		all
endef

define Package/$(PKG_NAME)/install
	$(INSTALL_DIR) $(1)/app/
	$(INSTALL_DIR) $(1)/app/config
	$(INSTALL_DIR) $(1)/etc/
	$(INSTALL_DIR) $(1)/etc/init.d/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/e104bt52d $(1)/app/
	$(INSTALL_BIN) ./files/e104bt52.initd $(1)/etc/init.d/e104bt52
	$(INSTALL_CONF) ./files/e104bt52.json $(1)/app/config/
endef

$(eval $(call BuildPackage,$(PKG_NAME)))

