#
# Copyright (C) 2020-2025 iopsys
#

include $(TOPDIR)/rules.mk

PKG_NAME:=wifidmd
PKG_VERSION:=1.4.8

LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/wifidmd.git
PKG_SOURCE_VERSION:=f21247fb72f9cdcbaa63a7de6281b0b12a9d632f
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.zst
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/wifidmd
 CATEGORY:=Utilities
 TITLE:=WiFi Data Model Support
 DEPENDS:=+libuci +libubox +libubus +libblobmsg-json +libjson-c
 DEPENDS+=+libbbfdm-api +libbbfdm-ubus +dm-service
endef

define Package/wifidmd/config
	source "$(SOURCE)/Config.in"
endef

define Package/wifidmd/description
	Package to add Device.WiFi. data model support.
endef

MAKE_PATH:=src

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

ifeq ($(CONFIG_WIFIDMD_VENDOR_PREFIX),"")
VENDOR_PREFIX = $(CONFIG_BBF_VENDOR_PREFIX)
else
VENDOR_PREFIX = $(CONFIG_WIFIDMD_VENDOR_PREFIX)
endif

TARGET_CFLAGS += -DBBF_VENDOR_PREFIX=\\\"$(VENDOR_PREFIX)\\\"

define Package/wifidmd/install
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/wifidmd $(1)/usr/sbin/wifidmd

	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) ./files/etc/init.d/wifidmd $(1)/etc/init.d/wifidmd

	$(INSTALL_DIR) $(1)/etc/wifidmd
	$(INSTALL_BIN) ./files/etc/wifidmd/bbf_config_reload.sh $(1)/etc/wifidmd

	$(BBFDM_REGISTER_SERVICES) ./bbfdm_service.json $(1) $(PKG_NAME)
endef

$(eval $(call BuildPackage,wifidmd))
