#
# Copyright (C) 2024-2025 iopsys
#

include $(TOPDIR)/rules.mk

PKG_NAME:=netmngr
PKG_VERSION:=1.2.2

LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/network/netmngr.git
PKG_SOURCE_VERSION:=6d269de378eac3b69276ae3abff37544508a30ed
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/netmngr
 CATEGORY:=Utilities
 TITLE:=Network Data Model Support
 DEPENDS:=+libuci +libubox +libubus +libblobmsg-json
 DEPENDS+=+libbbfdm-api +libbbfdm-ubus +dm-service
endef

define Package/netmngr/description
	Package to add Network data model support.
endef

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

MAKE_PATH:=src

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

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

ifeq ($(CONFIG_NETMNGR_GRE_OBJ),y)
MAKE_FLAGS += NETMNGR_GRE_OBJ=y
endif

ifeq ($(CONFIG_NETMNGR_IP_OBJ),y)
MAKE_FLAGS += NETMNGR_IP_OBJ=y
endif

ifeq ($(CONFIG_NETMNGR_ROUTING_OBJ),y)
MAKE_FLAGS += NETMNGR_ROUTING_OBJ=y
endif

ifeq ($(CONFIG_NETMNGR_PPP_OBJ),y)
MAKE_FLAGS += NETMNGR_PPP_OBJ=y
endif

ifeq ($(CONFIG_NETMNGR_ROUTER_ADVERTISEMENT_OBJ),y)
MAKE_FLAGS += NETMNGR_ROUTER_ADVERTISEMENT_OBJ=y
endif

ifeq ($(CONFIG_NETMNGR_IPV6RD_OBJ),y)
MAKE_FLAGS += NETMNGR_IPV6RD_OBJ=y
endif

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

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

$(eval $(call BuildPackage,netmngr))
