#
# Copyright (C) 2020-2024 iopsys
#

include $(TOPDIR)/rules.mk

PKG_NAME:=tr143
PKG_VERSION:=1.1.8

LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/tr143d.git
PKG_SOURCE_VERSION:=5f8404e01e5e4478de528027fa12717c1a2256f3
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 ../bbfdm/bbfdm.mk

define Package/tr143
 CATEGORY:=Utilities
 TITLE:=TR-143 Data Model Support
 DEPENDS:=+libuci +libubox +libubus +libblobmsg-json
 DEPENDS+=+libbbfdm-api +libbbfdm-ubus +dm-service +netmngr
endef

define Package/tr143/description
	Package to add Device.IP.Diagnostics. data model support.
endef

MAKE_PATH:=src

define Package/tr143/install
	$(BBFDM_INSTALL_MS_PLUGIN) $(PKG_BUILD_DIR)/src/libtr143d.so $(1) netmngr 11

ifeq ($(CONFIG_TARGET_SUBTARGET),"an7581")
	$(BBFDM_INSTALL_SCRIPT) $(PKG_BUILD_DIR)/airoha/scripts/download $(1)
else
	$(BBFDM_INSTALL_SCRIPT) $(PKG_BUILD_DIR)/scripts/download $(1)
endif

	$(BBFDM_INSTALL_SCRIPT) $(PKG_BUILD_DIR)/scripts/traceroute $(1)
	$(BBFDM_INSTALL_SCRIPT) $(PKG_BUILD_DIR)/scripts/upload $(1)
	$(BBFDM_INSTALL_SCRIPT) -d $(PKG_BUILD_DIR)/scripts/bbf_diag/ipping $(1)
	$(BBFDM_INSTALL_SCRIPT) -d $(PKG_BUILD_DIR)/scripts/bbf_diag/serverselection $(1)
	$(BBFDM_INSTALL_SCRIPT) -d $(PKG_BUILD_DIR)/scripts/bbf_diag/udpecho $(1)
endef

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

$(eval $(call BuildPackage,tr143))
