#
# Copyright (C) 2022 OpenWrt.org
#

include $(TOPDIR)/rules.mk

PKG_NAME:=ssdpd
PKG_VERSION:=1.0.7

LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/miniupnp/miniupnp.git
PKG_SOURCE_VERSION:=207cf440a22c075cb55fb067a850be4f9c204e6e
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 ../bbfdm/bbfdm.mk

define Package/ssdpd/config
	if PACKAGE_ssdpd
	config SSDPD_UPNP_DEVICE
		bool "Enable Device.UPnP.Device Datamodel object"
		default n
	endif
endef

define Package/ssdpd
  SECTION:=net
  CATEGORY:=Network
  DEPENDS:=+libnfnetlink +libpthread +libubox +libubus +libblobmsg-json +libcurl +mxml +SSDPD_UPNP_DEVICE:miniupnpd-iptables
  DEPENDS+=+libbbfdm-api +libbbfdm-ubus +dm-service
  TITLE:=MiniSSDPd - SSDP Daemon
  URL:=https://miniupnp.tuxfamily.org/minissdpd.html
endef

TARGET_CFLAGS += \
	-D_GNU_SOURCE

TARGET_LDFLAGS += \
	-lpthread -lubox -lubus -lblobmsg_json -lcurl -lmxml

define Package/ssdpd/install
	$(INSTALL_DIR) $(1)/etc/config
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_CONF) ./files/etc/config/ssdpd $(1)/etc/config/ssdpd
	$(INSTALL_BIN) ./files/etc/init.d/ssdpd $(1)/etc/init.d/ssdpd
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/minissdpd/minissdpd $(1)/usr/sbin/ssdpd
	$(BBFDM_REGISTER_SERVICES) ./bbfdm_service.json $(1) $(PKG_NAME)
	$(BBFDM_INSTALL_MS_DM) $(PKG_BUILD_DIR)/upnpdm.so $(1) $(PKG_NAME)
endef

$(eval $(call BuildPackage,ssdpd))
