#
# Copyright (C) 2025 IOPSYS Software Solutions AB
#
# This is free software, licensed under the BSD-3-Clause
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=gateway-info
PKG_VERSION:=1.0.2

LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/gateway-info.git
PKG_SOURCE_VERSION:=dd15893a8291e556a8c49ff9e143c763db0379b5
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
endif

PKG_LICENSE:=BSD-3-Clause
PKG_LICENSE_FILES:=LICENSE

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

define Package/gateway-info
  CATEGORY:=Utilities
  TITLE:=GatewayInfo Data Model Support
  DEPENDS:=+libuci +libubox +libubus +libblobmsg-json +umdns
  DEPENDS+=+libbbfdm-api +libbbfdm-ubus +dm-service +iputils-arping
endef

define Package/gateway-info/description
	Package to add Device.GatewayInfo. data model support.
endef

MAKE_PATH:=src

ifeq ($(LOCAL_DEV),1)
define Build/Prepare
	$(CP) ~/git/gateway-info/* $(PKG_BUILD_DIR)/
endef
endif

define Package/gateway-info/install
	$(INSTALL_DIR) $(1)/etc/config
	$(INSTALL_DIR) $(1)/etc/uci-defaults
	$(INSTALL_DIR) $(1)/etc/udhcpc.user.d
	$(INSTALL_DIR) $(1)/etc/bbfdm/services
	$(INSTALL_DIR) $(1)/usr/share/bbfdm/micro_services
	$(INSTALL_DATA) ./files/etc/config/gateway $(1)/etc/config/gateway
	$(INSTALL_BIN) ./files/etc/udhcpc.user.d/udhcpc_gateway_info.user $(1)/etc/udhcpc.user.d/udhcpc_gateway_info.user
	$(INSTALL_BIN) ./files/etc/uci-defaults/86-set-gateway-device-info $(1)/etc/uci-defaults/
	$(BBFDM_REGISTER_SERVICES) ./files/bbfdm_service.json $(1) $(PKG_NAME)
	$(BBFDM_INSTALL_MS_DM) $(PKG_BUILD_DIR)/src/libgwinfo.so $(1) $(PKG_NAME)
endef

$(eval $(call BuildPackage,gateway-info))
