#
# Copyright (C) 2020-2024 Iopsys
# Copyright (C) 2025 Genexis Sweden AB
#

include $(TOPDIR)/rules.mk

PKG_NAME:=wifimngr
PKG_VERSION:=20.1.9

LOCAL_DEV=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=479e4b737d7af8ec9d1c6088f7ae42871a61c601
PKG_SOURCE_URL:=https://dev.iopsys.eu/hal/wifimngr.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:=GPL-2.0-only
PKG_LICENSE_FILES:=
PKG_MAINTAINER:=Anjan Chanda <anjan.chanda@genexis.eu>

PKG_CONFIG_DEPENDS := \
		     CONFIG_PACKAGE_libwifiutils \
		     CONFIG_PACKAGE_libwifi

PKG_BUILD_DEPENDS := libwifi

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk

define Package/wifimngr
	SECTION:=utils
	CATEGORY:=Utilities
	TITLE:=WiFi status and configration utility
	DEPENDS:=+libwifiutils +libwifi +libuci +libubox +ubus +libnl-genl
endef

define Package/wifimngr/description
 This package can be used to configure and provide status about
 the WiFi modules through UBUS.
 It does this in an implementation agnostic manner through APIs
 exposed by the libwifi library.
endef

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

ifeq ($(CONFIG_WIFIMNGR_CACHE_SCANRESULTS),y)
TARGET_CFLAGS += -DWIFI_CACHE_SCANRESULTS
endif

define Package/wifimngr/install
	$(CP) ./files/* $(1)/
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/wifimngr $(1)/usr/sbin/
endef

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

$(eval $(call BuildPackage,wifimngr))
