#
# Copyright (C) 2023 IOPSYS
#

MK_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
SULU_NAME?=$(notdir $(CURDIR))
SULU_URL?=https://dev.iopsys.eu/websdk
SULU_MAINTAINER?=IOPSYS SuLu team

SULU_PLUGIN_INSTALL?=0
SULU_MOD?=plugins

PKG_NAME?=$(SULU_NAME)
PKG_RELEASE?=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_LICENSE:=PROPRIETARY IOPSYS
PKG_LICENSE_FILES:=LICENSE

SULU_VERSION=$(shell grep -oP '(?<=^PKG_VERSION:=).*' ${MK_DIR}/Makefile)
PKG_BUILD_DIR:=$(BUILD_DIR)/sulu-$(SULU_VERSION)/$(SULU_MOD)/$(PKG_NAME)-$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)
  SECTION:=utils
  CATEGORY:=Utilities
  SUBMENU:=SULU
  TITLE:=$(if $(SULU_TITLE),$(SULU_TITLE),Sulu plugin or module $(SULU_NAME))
  EXTRA_DEPENDS:=sulu-builder
  URL:=$(SULU_URL)/$(SULU_NAME)
  MAINTAINER:=$(SULU_MAINTAINER)
endef

ifneq ($(SULU_DESCRIPTION),)
define Package/$(PKG_NAME)/description
   $(strip $(SULU_DESCRIPTION))
endef
endif

define Build/Compile
	# Skip compilation, will be build with sulu-builder
ifeq ($(SULU_MOD),core)
ifneq ($(CONFIG_SULU_ENV_DATA),)
	echo -e "$(CONFIG_SULU_ENV_DATA)" > $(PKG_BUILD_DIR)/.env
endif
endif
endef

ifeq ($(SULU_PLUGIN_INSTALL),0)
define Package/$(PKG_NAME)/install
	# Nothing to be install
endef
endif

$(eval $(call BuildPackage,$(PKG_NAME)))
