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:=can_mqtt_proxy

include $(INCLUDE_DIR)/package.mk

define Package/can_mqtt_proxy
	SECTION:=DYIOT
	CATEGORY:=DYIOT Software
	TITLE:=CAN Frame to MQTT convertor
	DEPENDS:=+libuci +libdyutils +libubox +libipc_session +libmosquitto-ssl
endef

define Package/can_mqtt_proxy/description
	convert CAN frame to MQTT message
endef

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


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

define Package/can_mqtt_proxy/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)/can_mqtt_proxy $(1)/app/
	$(INSTALL_BIN) ./files/can_mqtt_proxy $(1)/etc/init.d/
	$(INSTALL_BIN) ./files/can_mqtt_proxy_cfg.json $(1)/app/config
endef


$(eval $(call BuildPackage,can_mqtt_proxy))

