8.59. Libffi-3.4.7

The Libffi library provides a portable, high level programming interface to various calling conventions. This allows a programmer to call any function specified by a call interface description at run time.

FFI stands for Foreign Function Interface. An FFI allows a program written in one language to call a program written in another language. Specifically, Libffi can provide a bridge between an interpreter like Perl, or Python, and shared library subroutines written in C, or C++.

Approximate build time: 1.7 SBU
Required disk space: 11 MB

8.59.1. Installation of Libffi

[Note]

Note

Like GMP, Libffi builds with optimizations specific to the processor in use. If building for another system, change the value of the --with-gcc-arch= parameter in the following command to an architecture name fully implemented by both the host CPU and the CPU on that system. If this is not done, all applications that link to libffi will trigger Illegal Operation Errors. If you cannot figure out a value safe for both the CPUs, replace the parameter with --without-gcc-arch to produce a generic library.

Create the PKGBUILD for the Libffi package with the following commands:

mkdir /sources/libffi
cd /sources/libffi
cat > PKGBUILD << "REALEOF"
# Maintainer: Linux From Scratch <lfs-dev@lists.linuxfromscratch.org>

pkgname="libffi"
pkgver="3.4.7"
pkgrel="1"
pkgdesc="The Libffi library provides a portable, high level programming interface to various calling conventions."
arch=('x86'
      'x86_64')
url="https://sourceware.org/libffi/"
license=('custom'
         'GPLv2'
         'MIT')
groups=('core')
depends=('glibc'
         'rootfs')
makedepends=('bash'
             'binutils'
             'coreutils'
             'gcc'
             'make'
             'sed')
checkdepends=('dejagnu')
source=('https://github.com/libffi/libffi/releases/download/v3.4.7/libffi-3.4.7.tar.gz')
md5sums=('696a1d483a1174ce8a477575546a5284')

build(){
cd "${pkgdir}-${pkgver}"

  # Determine arch
  case $(uname -m) in
    x86_64)
      chost="x86-64"
    ;;
    *)
      chost="i686"
    ;;

  ./configure --prefix=/usr               \
              --disable-static            \
              --disable-exec-static-tramp \
              --with-gcc-arch="${chost}"
  make
}

check(){
  cd ${pkgname}-${pkgver}
  make check
}

package(){
  cd ${pkgname}-${pkgver}
  make DESTDIR=${pkgdir} install
}
REALEOF

The meaning of the configure option:

--with-gcc-arch=*

Ensure GCC optimizes for a generic arch. If this is not specified, the system is guessed and the code generated may not be correct. If the generated code will be copied from the native system to a less capable system, use the less capable system as a parameter. For details about alternative system types, see the x86 options in the GCC manual.

Prepare the build directory for the pacman user and build the package:

chown -R root:pacman .
chmod 2775 .
chmod 664 PKGBUILD
su pacman -c 'makepkg -L --nodeps'

Add the newly created package to the central package repository:

cp libffi-3.4.7-1-$(uname -m).pkg.tar.xz \
   /srv/pacman/repos/LFS/
repo-add /srv/pacman/repos/LFS/LFS.db.tar.xz \
         /srv/pacman/repos/LFS/libffi-3.4.7-1-$(uname -m).pkg.tar.xz

Update the local cache and install the Libffi package:

pacman -Syu
pacman -S libffi --overwrite \* -dd --noconfirm

Finally, copy the source files into the source repository and clean up the build directory:

mkdir /srv/pacman/source/LFS/libffi
cp PKGBUILD /srv/pacman/source/LFS/libffi
cd /sources
rm -rf libffi

8.59.2. Contents of Libffi

Installed library: libffi.so

Short Descriptions

libffi

Contains the foreign function interface API functions