#
# Copyright (C) 2020-2024 IOPSYS Software Solutions AB
#

include $(TOPDIR)/rules.mk

PKG_NAME:=csmngr
PKG_VERSION:=1.0.2

LOCAL_DEV=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=5e50fe388fff29b08d895c1c580152cccfa290ad
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/csmngr.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_MAINTAINER:=Anjan Chanda <anjan.chanda@iopsys.eu>
PKG_LICENSE:=BSD-3-Clause
PKG_LICENSE_FILES:=LICENSE

PKG_CONFIG_DEPENDS := \
		     CONFIG_PACKAGE_libwifiutils \
		     CONFIG_PACKAGE_libwifi

PKG_BUILD_DEPENDS := libwifi

include $(INCLUDE_DIR)/package.mk


MAKE_PATH:=src

define Package/csmngr
  SECTION:=utils
  CATEGORY:=Utilities
  TITLE:=WiFi channel selection manager
  DEPENDS:=+libwifiutils +libwifi +libuci +libubox +ubus +libnl-genl
endef

define Package/csmngr/description
 WiFi Auto Channel Selection manager.
endef

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/csmngr/ $(PKG_BUILD_DIR)/
endef
endif

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

$(eval $(call BuildPackage,csmngr))
