include $(TOPDIR)/rules.mk

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=1000
PKG_VERSION:=$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_REVISION)

PKG_NAME:=sdb
include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)       # 会显示在menuconfig里
		SECTION:=DYIOT
		CATEGORY:=DYIOT Software
		TITLE:= smart distribute box
		#DEPENDS:=+libuci +libdyutils +libubox +lua
endef

define Package/$(PKG_NAME)/description
		smart distribute box
endef

define Build/Compile
endef

define Build/Configure
endef

define Package/$(PKG_NAME)/install         # 指定如何安装在rootfs里
		$(INSTALL_DIR) $(1)/app/
		$(INSTALL_DIR) $(1)/app/sdb
		$(INSTALL_DIR) $(1)/app/sdb_config 
		$(INSTALL_DIR) $(1)/etc/
		$(INSTALL_DIR) $(1)/etc/init.d/
		$(INSTALL_DIR) $(1)/etc/rc.d/
		$(CP) ./src/* $(1)/app/sdb
		$(CP) -rf ./sdb_config/* $(1)/app/sdb_config
		$(INSTALL_BIN) ./files/sdb $(1)/etc/init.d/
endef

define Package/$(PKG_NAME)/postinst
	#!/bin/sh
	# check if we are on real system
	if [ -z "$${IPKG_INSTROOT}" ]; then
		echo "Enabling rc.d symlink for $(PKG_NAME)"
		/etc/init.d/$(PKG_NAME) enable
	fi

	echo '$(PKG_NAME) installed successfully !'
	exit 0
endef

define Package/$(PKG_NAME)/prerm
	#!/bin/sh
	# check if we are on real system
	if [ -z "$${IPKG_INSTROOT}" ]; then
		echo "Removing rc.d symlink for $(PKG_NAME)"
		/etc/init.d/$(PKG_NAME) disable
	fi
	echo 'removeing $(PKG_NAME)'
	exit 0
endef

define Package/$(PKG_NAME)/postrm
	#!/bin/bash
	echo '$(PKG_NAME) removed successfully !'
endef

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