#
# Copyright (C) 2024 IOPSYS
#

include $(TOPDIR)/rules.mk

PKG_NAME:=usbmngr
PKG_VERSION:=1.0.6

LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/system/usbmngr.git
PKG_SOURCE_VERSION:=387298c97e384502d1df786346ec6a96e98be057
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
endif

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

include $(INCLUDE_DIR)/package.mk
include $(TOPDIR)/feeds/iopsys/bbfdm/bbfdm.mk

define Package/$(PKG_NAME)
  SECTION:=utils
  CATEGORY:=Utilities
  SUBMENU:=TRx69
  TITLE:=USBManager
  DEPENDS:=+libbbfdm-api +libbbfdm-ubus +dm-service
  MENU:=1
endef

MAKE_PATH:=src

define Package/$(PKG_NAME)/description
	Manages Device.USB. datamodel
endef

ifeq ($(LOCAL_DEV),1)
define Build/Prepare
	$(CP) -rf ~/git/usbmngr/* $(PKG_BUILD_DIR)/
endef
endif

define Package/$(PKG_NAME)/install
	$(BBFDM_REGISTER_SERVICES) ./bbfdm_service.json $(1) $(PKG_NAME)
	$(BBFDM_INSTALL_MS_DM) $(PKG_BUILD_DIR)/src/dm_usb.so $(1) $(PKG_NAME)
endef


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