#
# Copyright (C) 2020-2022 IOPSYS Software Solutions AB
#
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=stunc
PKG_VERSION:=1.4.6
PKG_RELEASE:=1

LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/stunc.git
PKG_SOURCE_VERSION:=741ef6aa2f07e77bb4e5d12f3c3bc6cad8d04a61
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

MAKE_PATH:=src

define Package/stunc
  SECTION:=utils
  CATEGORY:=Utilities
  SUBMENU:=TRx69
  TITLE:=BBF STUN Client
  DEPENDS:=+libubus +libuci +libubox +libjson-c +libblobmsg-json +libopenssl
  DEPENDS+=+libbbfdm-api +libbbfdm-ubus +dm-service
endef

TARGET_CFLAGS += \
	-Wall -Werror

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

define Package/stunc/install
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_DIR) $(1)/etc/config
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_DIR) $(1)/etc/icwmpd/plugins
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/stunc $(1)/usr/sbin/
	$(INSTALL_BIN) ./files/etc/init.d/stunc $(1)/etc/init.d/stunc
	$(INSTALL_DATA) ./files/etc/config/stunc $(1)/etc/config/stunc
	$(BBFDM_INSTALL_MS_PLUGIN) $(PKG_BUILD_DIR)/src/libstunc.so $(1) icwmp 12
endef

$(eval $(call BuildPackage,stunc))
