#
# Copyright (C) 2021-2023 IOPSYS Software Solutions AB
#

include $(TOPDIR)/rules.mk

PKG_NAME:=periodicstats
PKG_VERSION:=1.5.18

LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/periodicstats.git
PKG_SOURCE_VERSION:=2772d77bd477adfdf513499fda11397107996d21
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 $(TOPDIR)/feeds/iopsys/bbfdm/bbfdm.mk

define Package/periodicstats
  SECTION:=utils
  CATEGORY:=Utilities
  TITLE:=Periodic Statistics Daemon
  DEPENDS:=+ubus +libuci +libubox +libubus +libblobmsg-json
  DEPENDS+=+libbbfdm-api +libbbfdm-ubus +dm-service
endef

define Package/periodicstats/description
	Manage periodic statistics
endef

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

TARGET_CFLAGS += -DINTERNAL_SAMPLING_RATE=$(CONFIG_PERIODICSTAT_INTERNAL_SAMPLING_RATE)

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

define Package/periodicstats/install
	$(CP) ./files/* $(1)/
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/periodicstatsd $(1)/usr/sbin
	$(BBFDM_REGISTER_SERVICES) ./bbfdm_service.json $(1) $(PKG_NAME)
endef

$(eval $(call BuildPackage,periodicstats))
