#
# Copyright (C) 2020-2022 iopsys Software Solutions AB
#


include $(TOPDIR)/rules.mk

PKG_NAME:=twamp
PKG_VERSION:=1.5.0

LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/twamp-light.git
PKG_SOURCE_VERSION:=53ad00d0b1bc99da83c3dfc650855024579a96b7
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/$(PKG_NAME)
  SECTION:=utils
  CATEGORY:=Utilities
  SUBMENU:=TRx69
  TITLE:=TWAMP Light Client(TR-390)
  DEPENDS:=+libuci +ubox +libubus
  DEPENDS+=+libbbfdm-api +libbbfdm-ubus +dm-service +netmngr
endef

define Package/$(PKG_NAME)/description
	TWAMP Client for Performance Measurement from IP Edge to Customer Equipment using TWAMP Light Protocol
endef

TARGET_CFLAGS += \
	-D_GNU_SOURCE \
	-Wall -Werror

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

define Package/$(PKG_NAME)/install
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_DIR) $(1)/etc/uci-defaults
	$(INSTALL_DIR) $(1)/etc/config
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/twampd $(1)/usr/sbin/
	$(INSTALL_DATA) ./files/etc/config/twamp $(1)/etc/config/twamp
	$(INSTALL_BIN) ./files/etc/init.d/twampd $(1)/etc/init.d/twampd
	$(INSTALL_BIN) ./files/etc/firewall.twamp $(1)/etc/firewall.twamp
	$(INSTALL_BIN) ./files/etc/uci-defaults/92-twampfirewall $(1)/etc/uci-defaults/92-twampfirewall
	$(INSTALL_BIN) ./files/etc/uci-defaults/93-twamp_fix_reflector $(1)/etc/uci-defaults/93-twamp_fix_reflector
	$(BBFDM_INSTALL_MS_PLUGIN) $(PKG_BUILD_DIR)/libtwamp.so $(1) netmngr 14
endef

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