#
# Copyright (C) 2026 Teltonika
#

include $(TOPDIR)/rules.mk

PKG_NAME:=poeman

PKG_SOURCE_VERSION:=3.0

PKG_LICENSE:=Teltonika-closed

include $(INCLUDE_DIR)/package.mk

define Package/poeman
	SECTION:=base
	CATEGORY:=Base system
	TITLE:=POE manager
	DEPENDS:= +libubus +libubox +libuci +libgpiod +kmod-poe-core +kmod-poe-ip8008 +kmod-poe-ip80x +kmod-poe-xs2184
endef

define Package/rpcd-mod-fan-override
  SECTION:=libs
  CATEGORY:=Libraries
  TITLE:=fan override rpcd module
  DEPENDS:=+rpcd +libubox +kmod-poe-core
endef


define Package/poeman/install
	$(INSTALL_DIR) $(1)/etc/init.d $(1)/usr/bin $(1)/etc/uci-defaults/1.8
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/files/poeman.init $(1)/etc/init.d/poeman
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/poeman $(1)/usr/bin/poeman
	$(INSTALL_BIN) ./files/99_poe_update_config $(1)/etc/uci-defaults/1.8/
endef

define Package/rpcd-mod-fan-override/install
	$(if $(CONFIG_FAN_SUPPORT), \
		$(INSTALL_DIR) $(1)/usr/lib/rpcd/shared/; \
		$(INSTALL_BIN) $(PKG_BUILD_DIR)/fan_override.so $(1)/usr/lib/rpcd/shared/; \
	)
endef

$(eval $(call BuildPackage,poeman))
$(eval $(call BuildPackage,rpcd-mod-fan-override))
