#
# Copyright (C) 2013-2024 iopsys
#

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=mcastmngr
PKG_VERSION:=1.2.11

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/hal/mcastmngr.git
PKG_SOURCE_VERSION:=17d73b8f1947823a0d32ed589a240a2642904fe1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
endif

PKG_LICENSE:=GPL-2.0-only
PKG_LICENSE_FILES:=LICENSE

include $(INCLUDE_DIR)/package.mk
include ../bbfdm/bbfdm.mk

MAKE_PATH:=bbf_plugin

define Package/mcastmngr
 CATEGORY:=Utilities
 TITLE:=Multicast Proxy/Snooping Manager
 DEPENDS:=+libuci +libubox +libubus +libblobmsg-json
 DEPENDS+=+!TARGET_brcmbca:mcproxy +!TARGET_brcmbca:sipcalc
 DEPENDS+=+libbbfdm-api +libbbfdm-ubus +dm-service +!TARGET_brcmbca:kmod-ebt-igmpsnooping +!TARGET_brcmbca:kmod-ebt-mldsnooping
 DEPENDS+=+!TARGET_brcmbca:ebtables-legacy +bridgemngr
endef

define Package/mcastmngr/description
	Configures IGMP and MLD snooping and proxy
endef

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

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

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

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

define Package/mcastmngr/install
	$(CP) ./files/common/* $(1)/
ifneq ($(CONFIG_TARGET_brcmbca),)
	$(CP) ./files/broadcom/* $(1)/
else
	$(CP) ./files/linux/* $(1)/
endif
	$(BBFDM_REGISTER_SERVICES) -v ${VENDOR_PREFIX} ./bbfdm_service.json $(1) $(PKG_NAME)
	$(BBFDM_INSTALL_MS_DM) $(PKG_BUILD_DIR)/bbf_plugin/libmcast_bbf.so $(1) $(PKG_NAME)
endef

$(eval $(call BuildPackage,mcastmngr))
