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

PKG_NAME:=protocol_parser

include $(INCLUDE_DIR)/package.mk

ifneq ($(CONFIG_PROTOCOL_PARSER_PYTHON3),y)
  PP_CFLAGS :=
  DEP_PYTHON :=
else
  DEP_PYTHON := 3-base
  PP_CFLAGS := PP_USE_PYTHON3=yes
endif

define Package/protocol_parser
	SECTION:=DYIOT
	CATEGORY:=DYIOT Software
	TITLE:=protocol parser
	DEPENDS:=+libuci +libdyutils +libubox +python$(DEP_PYTHON) +liblua +libsqlite3 +libipc_session +libubus +ubuslog
endef

define Package/protocol_parser/description
	protocol parser
endef

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

define Package/protocol_parser/config
	config PROTOCOL_PARSER_PYTHON3
	    bool "Link protocol_parser with python3 instead of python2"
	    help
		Protocol parser has python script support.
	    default n
endef

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

define Package/protocol_parser/install
	$(INSTALL_DIR) $(1)/app/
	$(INSTALL_DIR) $(1)/etc/
	$(INSTALL_DIR) $(1)/etc/init.d/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/dy_protocol_parser $(1)/app/
	$(INSTALL_BIN) ./files/protocol_parser $(1)/etc/init.d/
endef


$(eval $(call BuildPackage,protocol_parser))

