#
# Copyright (C) 2020-2023 IOPSYS Software Solutions AB
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=xmppc
PKG_VERSION:=2.2.13.1

LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/xmppc.git
PKG_SOURCE_VERSION:=5816db95f9b99efa1c0e10e16df35b6bc09cebde
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
endif

PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

PKG_LICENSE:=BSD-3-Clause
PKG_LICENSE_FILES:=LICENSE

MAKE_PATH:=src

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

define Package/$(PKG_NAME)
  SECTION:=utils
  CATEGORY:=Utilities
  SUBMENU:=TRx69
  TITLE:=BBF xmpp Client
  DEPENDS:=+libuci +libubox +libstrophe +libubus +@CONFIG_BUSYBOX_CONFIG_PIDOF
  DEPENDS+=+libbbfdm-api +libbbfdm-ubus +dm-service
endef

define Package/$(PKG_NAME)/description
	BBF XMPP Client
endef

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

TARGET_CFLAGS += \
	-D_GNU_SOURCE \
	-Wall -Werror

define Package/$(PKG_NAME)/install
	$(INSTALL_DIR) $(1)/etc/icwmpd/plugins
	$(INSTALL_DIR) $(1)/usr/sbin
	$(BBFDM_INSTALL_MS_PLUGIN) $(PKG_BUILD_DIR)/src/libxmppc.so $(1) icwmp
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/xmppc $(1)/usr/sbin/
	$(CP) ./files/* $(1)/
endef

$(eval $(call BuildPackage,$(PKG_NAME)))
