include $(TOPDIR)/rules.mk

PKG_NAME:=jsonval
PKG_VERSION:=1.0.0
PKG_RELEASE:=1

PKG_LICENSE:=MIT
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk

define Package/jsonval
  SECTION:=utils
  CATEGORY:=Utilities
  TITLE:=Command-line JSON Schema Validator
  DEPENDS:=+nlohmann-json +json-schema-validator +libstdcpp
endef

define Package/jsonval/description
  A small CLI tool to validate JSON files against a schema using json-schema-validator and nlohmann/json.
endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	cp -r ./src/* $(PKG_BUILD_DIR)/
endef

define Build/Compile
	$(TARGET_CXX) \
		$(TARGET_CXXFLAGS) -std=c++17 \
		-I$(STAGING_DIR)/usr/include \
		-I$(STAGING_DIR)/usr/include/nlohmann \
		-L$(STAGING_DIR)/usr/lib \
		$(PKG_BUILD_DIR)/main.cpp \
		-o $(PKG_BUILD_DIR)/jsonval \
		-lnlohmann_json_schema_validator
endef

define Package/jsonval/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/jsonval $(1)/usr/bin/
endef

$(eval $(call BuildPackage,jsonval))
