mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
system/libffi: Add libffi package integration
Add Kconfig, build rules, and ignore entries required to build and package libffi as a standalone system component. Signed-off-by: Tiago Medicci <tiago.medicci@espressif.com>
This commit is contained in:
parent
c9c5c75d08
commit
965cddfa36
4 changed files with 191 additions and 0 deletions
4
system/libffi/.gitignore
vendored
Normal file
4
system/libffi/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
/*.zip
|
||||
/build/
|
||||
/install/
|
||||
/libffi/
|
||||
24
system/libffi/Kconfig
Normal file
24
system/libffi/Kconfig
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config LIB_LIBFFI
|
||||
bool "libffi"
|
||||
default n
|
||||
---help---
|
||||
Enable the libffi Foreign Function Interface library. libffi
|
||||
provides a portable way to call C functions with arguments
|
||||
determined at runtime. It is required by CPython's _ctypes module.
|
||||
|
||||
if LIB_LIBFFI
|
||||
|
||||
config LIB_LIBFFI_VERSION
|
||||
string "libffi commit hash"
|
||||
default "9760868682cc9a33008761f158d86481d56738aa"
|
||||
---help---
|
||||
Git commit hash of the libffi repository to download and build.
|
||||
The source is fetched from https://github.com/libffi/libffi at
|
||||
the specified commit.
|
||||
|
||||
endif # LIB_LIBFFI
|
||||
28
system/libffi/Make.defs
Normal file
28
system/libffi/Make.defs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
############################################################################
|
||||
# apps/system/libffi/Make.defs
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_LIB_LIBFFI),)
|
||||
CONFIGURED_APPS += $(APPDIR)/system/libffi
|
||||
|
||||
EXTRA_LIBPATHS += -L$(APPDIR)/system/libffi/install/lib
|
||||
EXTRA_LIBS += -lffi
|
||||
endif
|
||||
135
system/libffi/Makefile
Normal file
135
system/libffi/Makefile
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
############################################################################
|
||||
# apps/system/libffi/Makefile
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
LIBFFI_URL = https://github.com/libffi/libffi/archive
|
||||
LIBFFI_COMMIT = $(patsubst "%",%,$(strip $(CONFIG_LIB_LIBFFI_VERSION)))
|
||||
LIBFFI_ZIP = libffi-$(LIBFFI_COMMIT).zip
|
||||
LIBFFI_SRC = libffi
|
||||
LIBFFI_BUILDDIR = $(CURDIR)/build
|
||||
LIBFFI_INSTALLDIR = $(CURDIR)/install
|
||||
APPS_INCDIR = $(APPDIR)$(DELIM)include
|
||||
|
||||
UNPACK ?= unzip -q -o
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Derive the autotools --host triplet from the NuttX configuration.
|
||||
#
|
||||
# libffi's configure.host matches on patterns such as:
|
||||
# riscv*-*-* arm*-*-* aarch64*-*-* xtensa*-*-*
|
||||
# mips*-*-* i?86-*-* x86_64-*-*
|
||||
#
|
||||
# We map CONFIG_ARCH (and, for RISC-V, the word-size selectors) to the
|
||||
# CPU part that libffi expects, then append "-nuttx-elf" as vendor-os.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(CONFIG_ARCH),risc-v)
|
||||
ifeq ($(CONFIG_ARCH_RV64),y)
|
||||
LIBFFI_CPU = riscv64
|
||||
else
|
||||
LIBFFI_CPU = riscv32
|
||||
endif
|
||||
else ifeq ($(CONFIG_ARCH),arm64)
|
||||
LIBFFI_CPU = aarch64
|
||||
else ifeq ($(CONFIG_ARCH),arm)
|
||||
LIBFFI_CPU = arm
|
||||
else ifeq ($(CONFIG_ARCH),xtensa)
|
||||
LIBFFI_CPU = xtensa
|
||||
else ifeq ($(CONFIG_ARCH),mips)
|
||||
LIBFFI_CPU = mips
|
||||
else ifeq ($(CONFIG_ARCH),x86_64)
|
||||
LIBFFI_CPU = x86_64
|
||||
else ifeq ($(CONFIG_ARCH),x86)
|
||||
LIBFFI_CPU = i686
|
||||
else
|
||||
LIBFFI_CPU = $(subst -,,$(CONFIG_ARCH))
|
||||
endif
|
||||
|
||||
LIBFFI_HOST = $(LIBFFI_CPU)-nuttx-elf
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# CFLAGS for the libffi build itself.
|
||||
#
|
||||
# We start from the NuttX-provided CFLAGS (which already carry -march,
|
||||
# -mabi, -isystem paths, -D__NuttX__, etc.) and add a few flags that the
|
||||
# library needs. We deliberately strip -nostdlib because autoconf link
|
||||
# checks need the default startfiles/libs to succeed.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
LIBFFI_CFLAGS = $(filter-out -nostdlib -Werror -Werror=% -Wno-cpp,$(CFLAGS))
|
||||
LIBFFI_CFLAGS += -ffunction-sections -fdata-sections -O2
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Download, autoreconf, configure, build, install
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(wildcard $(LIBFFI_SRC)/.git),)
|
||||
|
||||
$(LIBFFI_ZIP):
|
||||
@echo "Downloading: $(LIBFFI_URL)/$(LIBFFI_COMMIT).zip"
|
||||
$(Q) curl -L $(LIBFFI_URL)/$(LIBFFI_COMMIT).zip -o $(LIBFFI_ZIP)
|
||||
|
||||
$(LIBFFI_SRC): $(LIBFFI_ZIP)
|
||||
@echo "Unpacking: $(LIBFFI_ZIP) -> $(LIBFFI_SRC)"
|
||||
$(Q) $(UNPACK) $(LIBFFI_ZIP)
|
||||
$(Q) mv libffi-$(LIBFFI_COMMIT) $(LIBFFI_SRC)
|
||||
|
||||
endif
|
||||
|
||||
$(LIBFFI_SRC)/configure: $(LIBFFI_SRC)
|
||||
@echo "Generating libffi configure script (autoreconf)"
|
||||
$(Q) (cd $(LIBFFI_SRC) && autoreconf -v -i)
|
||||
|
||||
$(LIBFFI_INSTALLDIR)/lib/libffi.a: $(LIBFFI_SRC)/configure
|
||||
$(Q) mkdir -p $(LIBFFI_BUILDDIR)
|
||||
$(Q) ( \
|
||||
cd $(LIBFFI_BUILDDIR) && \
|
||||
$(CURDIR)/$(LIBFFI_SRC)/configure \
|
||||
--host=$(LIBFFI_HOST) \
|
||||
--prefix=$(LIBFFI_INSTALLDIR) \
|
||||
--disable-shared \
|
||||
--enable-static \
|
||||
--disable-docs \
|
||||
--disable-exec-static-tramp \
|
||||
--disable-multi-os-directory \
|
||||
CC="$(CC)" \
|
||||
CFLAGS="$(LIBFFI_CFLAGS)" \
|
||||
AR="$(CROSSDEV)ar" \
|
||||
RANLIB="$(CROSSDEV)ranlib" \
|
||||
)
|
||||
$(MAKE) -C $(LIBFFI_BUILDDIR) -j$(shell nproc)
|
||||
$(MAKE) -C $(LIBFFI_BUILDDIR) install
|
||||
|
||||
context:: $(LIBFFI_INSTALLDIR)/lib/libffi.a
|
||||
$(Q) mkdir -p $(APPS_INCDIR)
|
||||
$(Q) cp $(LIBFFI_INSTALLDIR)/include/*.h $(APPS_INCDIR)
|
||||
|
||||
distclean::
|
||||
$(call DELDIR, $(LIBFFI_BUILDDIR))
|
||||
$(call DELDIR, $(LIBFFI_INSTALLDIR))
|
||||
$(call DELDIR, $(LIBFFI_SRC))
|
||||
$(call DELFILE, $(LIBFFI_ZIP))
|
||||
$(call DELFILE, $(APPS_INCDIR)/ffi.h)
|
||||
$(call DELFILE, $(APPS_INCDIR)/ffitarget.h)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
||||
Loading…
Add table
Add a link
Reference in a new issue