#
# Copyright (C) 2022 iopsys Software Solutions AB
#
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=bulkdata
PKG_VERSION:=2.1.20

LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/bulkdata.git
PKG_SOURCE_VERSION:=a5e57962938ca143ede65d92be90b6e9fce66e15
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 $(TOPDIR)/feeds/iopsys/bbfdm/bbfdm.mk

define Package/bulkdata
  SECTION:=utils
  CATEGORY:=Utilities
  SUBMENU:=TRx69
  TITLE:=BBF BulkData Collection
  DEPENDS:=+ubus +libuci +libubox +libjson-c +libcurl +libblobmsg-json +zlib
  DEPENDS+=+libbbfdm-api +libbbfdm-ubus
endef

define Package/bulkdata/description
  BulkData daemon for TR069 with bbfdm backend.
endef

TARGET_CFLAGS += \
	-D_GNU_SOURCE \
	-Wall -Werror

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

define Package/bulkdata/install
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_DIR) $(1)/etc/config
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/bulkdatad $(1)/usr/sbin/
	$(INSTALL_DATA) ./files/etc/config/bulkdata $(1)/etc/config/
	$(INSTALL_BIN) ./files/etc/init.d/bulkdatad $(1)/etc/init.d/

	$(BBFDM_REGISTER_SERVICES) ./bbfdm_service.json $(1) $(PKG_NAME)
endef

$(eval $(call BuildPackage,bulkdata))
