93 lines
3.0 KiB
Ruby
93 lines
3.0 KiB
Ruby
class Libffi < Formula
|
|
desc "Portable Foreign Function Interface library"
|
|
homepage "https://sourceware.org/libffi/"
|
|
url "https://sourceware.org/pub/libffi/libffi-3.3.tar.gz"
|
|
mirror "https://deb.debian.org/debian/pool/main/libf/libffi/libffi_3.3.orig.tar.gz"
|
|
mirror "https://github.com/libffi/libffi/releases/download/v3.3/libffi-3.3.tar.gz"
|
|
sha256 "72fba7922703ddfa7a028d513ac15a85c8d54c8d67f55fa5a4802885dc652056"
|
|
license "MIT"
|
|
|
|
bottle do
|
|
cellar :any
|
|
sha256 "dd94d39946f53a8f11f78e998f22e46be9666bb265f80bb4714d5d63c1e16a68" => :catalina
|
|
sha256 "d6e5efd7521676dfc58fcba567514b898091c8580df4d6253f5dd40a7ee67c82" => :mojave
|
|
sha256 "7065f0d426921fa069c2494beded9de61e8720954f3f346103c8f871daa4ff8b" => :high_sierra
|
|
end
|
|
|
|
head do
|
|
url "https://github.com/atgreen/libffi.git"
|
|
depends_on "autoconf" => :build
|
|
depends_on "automake" => :build
|
|
depends_on "libtool" => :build
|
|
end
|
|
|
|
keg_only :provided_by_macos
|
|
|
|
def install
|
|
# This can be removed in the future when libffi properly detects the CPU on ARM.
|
|
# https://github.com/libffi/libffi/issues/571#issuecomment-655223391
|
|
extra_args = []
|
|
extra_args << "--build=aarch64-apple-darwin#{`uname -r`.chomp}" if Hardware::CPU.arm?
|
|
|
|
system "./autogen.sh" if build.head?
|
|
system "./configure", "--disable-debug", "--disable-dependency-tracking",
|
|
"--prefix=#{prefix}", *extra_args
|
|
system "make", "install"
|
|
end
|
|
|
|
test do
|
|
(testpath/"closure.c").write <<~EOS
|
|
#include <stdio.h>
|
|
#include <ffi.h>
|
|
|
|
/* Acts like puts with the file given at time of enclosure. */
|
|
void puts_binding(ffi_cif *cif, unsigned int *ret, void* args[],
|
|
FILE *stream)
|
|
{
|
|
*ret = fputs(*(char **)args[0], stream);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
ffi_cif cif;
|
|
ffi_type *args[1];
|
|
ffi_closure *closure;
|
|
|
|
int (*bound_puts)(char *);
|
|
int rc;
|
|
|
|
/* Allocate closure and bound_puts */
|
|
closure = ffi_closure_alloc(sizeof(ffi_closure), &bound_puts);
|
|
|
|
if (closure)
|
|
{
|
|
/* Initialize the argument info vectors */
|
|
args[0] = &ffi_type_pointer;
|
|
|
|
/* Initialize the cif */
|
|
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
|
|
&ffi_type_uint, args) == FFI_OK)
|
|
{
|
|
/* Initialize the closure, setting stream to stdout */
|
|
if (ffi_prep_closure_loc(closure, &cif, puts_binding,
|
|
stdout, bound_puts) == FFI_OK)
|
|
{
|
|
rc = bound_puts("Hello World!");
|
|
/* rc now holds the result of the call to fputs */
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Deallocate both closure, and bound_puts */
|
|
ffi_closure_free(closure);
|
|
|
|
return 0;
|
|
}
|
|
EOS
|
|
|
|
flags = ["-L#{lib}", "-lffi", "-I#{include}"]
|
|
system ENV.cc, "-o", "closure", "closure.c", *(flags + ENV.cflags.to_s.split)
|
|
system "./closure"
|
|
end
|
|
end
|