#
# Copyright (C) 2022 IOPSYS
#
#

include $(TOPDIR)/rules.mk

PKG_NAME:=usp-js
PKG_VERSION:=1.2.10

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/websdk/usp-js.git
PKG_SOURCE_VERSION:=5faa585dff45ceba99f6e8a89a47b1ca34fa5bf3
PKG_MIRROR_HASH:=skip

PKG_LICENSE:=BSD-3-Clause
PKG_LICENSE_FILES:=LICENSE

include $(INCLUDE_DIR)/package.mk

define Package/usp-js
  SECTION:=libs
  CATEGORY:=Libraries
  TITLE:=A JS library for USP(TR369) protocol
  DEPENDS:=+quickjs +quickjs-websocket +@OBUSPA_LOCAL_MQTT_LISTENER
  EXTRA_DEPENDS:=obuspa mosquitto-ssl
endef

define Package/usp-js/description
  A JS library to provide USP(TR369) protocol functionality for an usp controller.
endef

define Build/Compile
	cd $(PKG_BUILD_DIR) && [ -d "./qjs" ] || (yarn install && yarn qjs)
endef

define Package/usp-js/install
	$(INSTALL_DIR) $(1)/usr/lib/usp-js
	$(CP) $(PKG_BUILD_DIR)/qjs/* $(1)/usr/lib/usp-js/
endef

$(eval $(call BuildPackage,usp-js))
