#
# Copyright (C) 2025 Genexis Sweden AB
#

include $(TOPDIR)/rules.mk

PKG_NAME:=map-plugins
PKG_VERSION:=1.2.7

LOCAL_DEV=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=dd873ca4e2cb321302dae1955da24d1be271b2b1
PKG_SOURCE_URL:=https://dev.iopsys.eu/multi-ap/map-plugins.git
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)_$(PKG_SOURCE_VERSION).tar.xz
PKG_MIRROR_HASH:=skip
endif

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_LICENSE:=PROPRIETARY GENEXIS
PKG_LICENSE_FILES:=LICENSE

PKG_CONFIG_DEPENDS := CONFIG_PACKAGE_mapcontroller
PKG_BUILD_DEPENDS := map-controller

include $(INCLUDE_DIR)/package.mk

include $(wildcard plugins/*.mk)

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

MAKE_FLAGS += \
	CFLAGS="$(TARGET_CFLAGS) -Wall"

plugins := \
	$(if $(CONFIG_PACKAGE_map-plugins-steer-rate),steer-rate)   \
	$(if $(CONFIG_PACKAGE_map-plugins-bsteer),bsteer) \
	$(if $(CONFIG_PACKAGE_map-plugins-zero-touch),zero-touch)

ppkg:=$(patsubst plugins/%.mk,map-plugins-%,$(wildcard plugins/*.mk))

define Package/map-plugins/Default
	SECTION:=utils
	CATEGORY:=Utilities
	SUBMENU:=Multi-AP value added services
endef

define Package/map-plugins/config
  source "$(SOURCE)/Config.in"
endef

define Package/map-plugins
	$(call Package/map-plugins/Default)
	TITLE:=Multi-AP plugins modules
	DEPENDS+=+libeasy +libwifiutils +map-controller
endef

define Package/map-plugins/description
	Provides extra Multi-AP services viz. steering, channel-planning,
	self-organizing network, zero-touch onboarding etc.
endef

define Package/map-plugins/install
	:
endef

define Build/Compile
	$(foreach p,$(plugins),$(call Build/Compile/map-plugins-$(p), $(1)))
endef

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

$(eval $(call BuildPackage,map-plugins))
$(eval $(foreach p,$(ppkg),$(call BuildPackage,$(p))))
