#
# Copyright (C) 2020-2023 Iopsys
# Copyright (C) 2025 Genexis AB
#

include $(TOPDIR)/rules.mk

PKG_NAME:=wifimngr
PKG_VERSION:=17.7.8

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

PKG_CONFIG_DEPENDS := \
		     CONFIG_PACKAGE_libwifiutils \
		     CONFIG_PACKAGE_libwifi

PKG_BUILD_DEPENDS := libwifi

include $(INCLUDE_DIR)/package.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

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

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

ifeq ($(LOCAL_DEV),1)
define Build/Prepare
  rsync -r --exclude=.* ~/git/wifimngr/ $(PKG_BUILD_DIR)/
endef
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))
