#
# Copyright (C) 2021-2024 IOPSYS Software Solutions AB
# Copyright (C) 2025 Genexis AB
#

include $(TOPDIR)/rules.mk

PKG_NAME:=decollector
PKG_VERSION:=6.2.1.8

LOCAL_DEV=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=b7e294d7c610adfd80cf40a0628c189695dc5156
PKG_SOURCE_URL:=https://dev.iopsys.eu/multi-ap/decollector.git
PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
endif
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_MAINTAINER:=Anjan Chanda <anjan.chanda@genexis.eu>


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

include $(INCLUDE_DIR)/package.mk

define Package/decollector
  SECTION:=utils
  CATEGORY:=Utilities
  TITLE:=WiFi DataElements Collector Proxy
  DEPENDS:=+libuci +libubox +ubus +libpthread +libnl-genl \
	   +libeasy +libwifiutils +libieee1905 +ieee1905-map-plugin
endef

define Package/decollector/description
 It implements the WiFi DataElements Agent as defined in the Wi-Fi Alliance's
 DataElements specification.
endef


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

ifneq (,$(findstring ALPHA,$(CONFIG_VERSION_CODE)))
MAKE_FLAGS += DEBUG=1
endif

ifneq (,$(findstring BETA,$(CONFIG_VERSION_CODE)))
MAKE_FLAGS += DEBUG=1
endif

TARGET_CFLAGS += \
	-I$(STAGING_DIR)/usr/include \
	-I$(STAGING_DIR)/usr/include/libnl3 \
	-D_GNU_SOURCE

ifeq ($(LOCAL_DEV),1)
define Build/Prepare
  rsync -r --exclude=.* ~/git/decollector/ $(PKG_BUILD_DIR)/
endef
endif

MAKE_PATH:=src

TARGET_CFLAGS += -DEASYMESH_VERSION=$(CONFIG_DECOLLECTOR_EASYMESH_VERSION)

EXECS := \
	$(if $(CONFIG_PACKAGE_decollector),decollector)

MAKE_FLAGS += EXECS="$(EXECS)"

define Package/decollector/install
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) ./files/decollector.init $(1)/etc/init.d/decollector
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/decollector $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,decollector))
