Skip to content

Instantly share code, notes, and snippets.

@royratcliffe
Last active October 11, 2023 04:03
Show Gist options
  • Save royratcliffe/4ff92962dcfb8417efb4a7afb010388a to your computer and use it in GitHub Desktop.
Save royratcliffe/4ff92962dcfb8417efb4a7afb010388a to your computer and use it in GitHub Desktop.
swipl-ffi-buildroot
config BR2_PACKAGE_SWIPL_FFI
bool "SWI-Prolog FFI"
depends on BR2_PACKAGE_SWIPL
depends on BR2_PACKAGE_LIBFFI
help
Dynamic calling C from Prolog.
This package deals with calling C functions from shared objects from Prolog without writing wrappers.
# Locally calculated
sha256 1d59b9240acb5c7992e8a1419b425889c4aa5299398dd013e0382af4aa50b494 swipl-ffi-master-br1.tar.gz
################################################################################
#
# swipl-ffi
#
################################################################################
SWIPL_FFI_VERSION = master
SWIPL_FFI_SITE = https://github.com/swipl/ffi
SWIPL_FFI_SITE_METHOD = git
SWIPL_FFI_AUTORECONF = YES
SWIPL_FFI_DEPENDENCIES = swipl
SWIPL_FFI_ARCH = $(CMAKE_SYSTEM_PROCESSOR)-linux
SWIPL_FFI_LDSOFLAGS = $(TARGET_CFLAGS)
SWIPL_FFI_LDSOFLAGS += -fPIC
SWIPL_FFI_LDSOFLAGS += -D_REENTRANT
SWIPL_FFI_LDSOFLAGS += -D__SWI_PROLOG__
SWIPL_FFI_LDSOFLAGS += -I$(TARGET_DIR)/usr/include
SWIPL_FFI_LDSOFLAGS += -I$(TARGET_DIR)/usr/lib
SWIPL_FFI_LDSOFLAGS += -I$(TARGET_DIR)/lib/swipl/include
SWIPL_FFI_LDSOFLAGS += -L$(TARGET_DIR)/lib/swipl/lib/$(SWIPL_FFI_ARCH)
SWIPL_FFI_LDSOFLAGS += -lswipl
SWIPL_FFI_LDSOFLAGS += -shared
SWIPL_FFI_MAKE_OPTS = \
SOEXT=so \
LD="$(TARGET_CROSS)gcc" \
LDSOFLAGS="$(SWIPL_FFI_LDSOFLAGS)"
# SWI-Prolog installs global packs using `pack_install(., [global(true),
# link(false)])` at `common_app_data(pack)`. On Linux, this translates to
# `/usr/share/swi-prolog/pack`. Note that the direction search predicates fail
# to find the common data folders if they do not exist. Ignoring installed
# tests, examples and documentation, the active Prolog source files and their
# foreign library install as:
# ```
# /usr/share/swi-prolog/pack/ffi/pack.pl
# /usr/share/swi-prolog/pack/ffi/prolog/clocations.pl
# /usr/share/swi-prolog/pack/ffi/prolog/cerror.pl
# /usr/share/swi-prolog/pack/ffi/prolog/cparser.pl
# /usr/share/swi-prolog/pack/ffi/prolog/ctokens.pl
# /usr/share/swi-prolog/pack/ffi/prolog/ffi.pl
# /usr/share/swi-prolog/pack/ffi/prolog/cdecls.pl
# /usr/share/swi-prolog/pack/ffi/lib/$(ARCH)-linux/ffi4pl.so
# ```
# The `$(ARCH)` term here identifies the CMake system processor designation.
define SWIPL_FFI_INSTALL_TARGET_CMDS
$(INSTALL) -D -t $(TARGET_DIR)/usr/share/swi-prolog/pack/ffi $(@D)/pack.pl
$(INSTALL) -D -t $(TARGET_DIR)/usr/share/swi-prolog/pack/ffi/prolog $(@D)/prolog/*
$(INSTALL) -D -t $(TARGET_DIR)/usr/share/swi-prolog/pack/ffi/lib/$(SWIPL_FFI_ARCH) $(@D)/lib/*
endef
$(eval $(autotools-package))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment