iopsys-feed/dm-framework/dm-framework.mk
Xiaofeng Meng 5c514051a2 Add dm-framework for bridgemngr
Introduce dm-framework.mk providing reusable build macros for packages
that integrate with the DM Framework:

- Build/Compile/DM: Generates C code and shared libraries from JSON data
  models using json2code.js, compiles them, and creates package-specific
  .so files
- Build/Install/DM: Installs generated libraries, JS handlers,
  and data model files to the dm-framework directory(dmf)

Also adds bridgemngr as the first package utilizing these helpers to
implement bridge data model with dm-framework, which can be enabled
through flag CONFIG_BRIDGEMNGR_USE_DM_FRAMEWORK.

The commit also include changes in bbfdm dm-framework adaption.
2025-12-09 14:56:19 +01:00

33 lines
1.3 KiB
Makefile

# dm-framework.mk - Common rules for DM Framework
DM_SCRIPT_DIR ?= $(STAGING_DIR)/usr/lib/dm-framework/scripts
JSON2CODE = $(DM_SCRIPT_DIR)/json2code.js
# Macro to generate code
# $(1): Input directory (datamodels)
# $(2): Output directory (where generated files go)
# $(3): Vendor Prefix (optional)
define Build/Compile/DM
$(INSTALL_DIR) $(2)
@# Install npm dependencies if not already installed
@if [ ! -d "$(DM_SCRIPT_DIR)/node_modules" ]; then \
cd $(DM_SCRIPT_DIR) && npm install --production; \
fi
node $(JSON2CODE) -i $(1) -o $(2) $(if $(3),--vendor-prefix $(3))
$(TARGET_CC) $(TARGET_CFLAGS) -I$(2) -I$(STAGING_DIR)/usr/include/ -fPIC -c $(2)/dm.c -o $(2)/dm.o
$(TARGET_CC) $(TARGET_LDFLAGS) -shared -o $(2)/lib$(PKG_NAME).so $(2)/dm.o
endef
# Macro to install DM
# $(1): Input directory (datamodels)
# $(2): Output directory (build dir)
# $(3): Destination directory (rootfs)
# $(4): Package Name (subdir in /etc/bbfdm/dmf)
define Build/Install/DM
$(INSTALL_DIR) $(3)/etc/bbfdm/dmf/$(4)
$(CP) $(2)/lib$(PKG_NAME).so $(3)/etc/bbfdm/dmf/$(4)/
$(CP) $(1)/*.js $(3)/etc/bbfdm/dmf/$(4)/
$(CP) $(2)/default.db $(3)/etc/bbfdm/dmf/default_dm.db
$(CP) $(2)/exports.js $(3)/etc/bbfdm/dmf/$(4)/exports.js
$(CP) $(2)/dm_consts.js $(3)/etc/bbfdm/dmf/$(4)/dm_consts.js
endef